blob: bff411edf3e0089d504daf9135a4b81592a0ef08 [file] [log] [blame]
bsalomonafbf2d62014-09-30 12:18:44 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrSurfacePriv_DEFINED
9#define GrSurfacePriv_DEFINED
10
11#include "GrSurface.h"
12
13/** Class that adds methods to GrSurface that are only intended for use internal to Skia.
14 This class is purely a privileged window into GrSurface. It should never have additional data
15 members or virtual methods.
16 Non-static methods that are not trivial inlines should be spring-boarded (e.g. declared and
17 implemented privately in GrSurface with a inline public method here). */
18class GrSurfacePriv {
19public:
bsalomone8d21e82015-07-16 08:23:13 -070020 /** Helpers used in read/write pixels implementations. The paramters are adjusted so that the
21 read/write respects the bounds of a surface. If the input *rowBytes is 0 it will be
22 the tight row bytes (based on width and bpp) on output. */
23 static bool AdjustReadPixelParams(int surfaceWidth,
24 int surfaceHeight,
25 size_t bpp,
26 int* left, int* top, int* width, int* height,
27 void** data,
28 size_t* rowBytes);
29 static bool AdjustWritePixelParams(int surfaceWidth,
30 int surfaceHeight,
31 size_t bpp,
32 int* left, int* top, int* width, int* height,
33 const void** data,
34 size_t* rowBytes);
bsalomonafbf2d62014-09-30 12:18:44 -070035 /**
bsalomon74f681d2015-06-23 14:38:48 -070036 * Derive a SkImageInfo from the surface's descriptor. The caller must provide the alpha type as
37 * GrSurface has no equivalent.
bsalomonafbf2d62014-09-30 12:18:44 -070038 */
bsalomon74f681d2015-06-23 14:38:48 -070039 SkImageInfo info(SkAlphaType alphaType) const { return fSurface->info(alphaType); }
bsalomonafbf2d62014-09-30 12:18:44 -070040
41 /**
bsalomonafbf2d62014-09-30 12:18:44 -070042 * Write the contents of the surface to a PNG. Returns true if successful.
43 * @param filename Full path to desired file
44 */
45 bool savePixels(const char* filename) { return fSurface->savePixels(filename); }
46
47 bool hasPendingRead() const { return fSurface->hasPendingRead(); }
48 bool hasPendingWrite() const { return fSurface->hasPendingWrite(); }
49 bool hasPendingIO() const { return fSurface->hasPendingIO(); }
50
51private:
bsalomon6bc1b5f2015-02-23 09:06:38 -080052 explicit GrSurfacePriv(GrSurface* surface) : fSurface(surface) {}
53 GrSurfacePriv(const GrSurfacePriv&); // unimpl
54 GrSurfacePriv& operator=(const GrSurfacePriv&); // unimpl
bsalomonafbf2d62014-09-30 12:18:44 -070055
56 // No taking addresses of this type.
57 const GrSurfacePriv* operator&() const;
58 GrSurfacePriv* operator&();
59
60 GrSurface* fSurface;
61
62 friend class GrSurface; // to construct/copy this type.
63};
64
65inline GrSurfacePriv GrSurface::surfacePriv() { return GrSurfacePriv(this); }
66
67inline const GrSurfacePriv GrSurface::surfacePriv() const {
68 return GrSurfacePriv(const_cast<GrSurface*>(this));
69}
70
71#endif