bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 1 | /* |
| 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). */ |
| 18 | class GrSurfacePriv { |
| 19 | public: |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 20 | /** Helpers used in read/write pixels implementations. The parameters are adjusted so that the |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 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); |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 35 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 36 | bool hasPendingRead() const { return fSurface->hasPendingRead(); } |
| 37 | bool hasPendingWrite() const { return fSurface->hasPendingWrite(); } |
| 38 | bool hasPendingIO() const { return fSurface->hasPendingIO(); } |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 39 | bool hasUniqueRef() const { return fSurface->internalHasUniqueRef(); } |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 40 | |
| 41 | private: |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 42 | explicit GrSurfacePriv(GrSurface* surface) : fSurface(surface) {} |
| 43 | GrSurfacePriv(const GrSurfacePriv&); // unimpl |
| 44 | GrSurfacePriv& operator=(const GrSurfacePriv&); // unimpl |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 45 | |
| 46 | // No taking addresses of this type. |
| 47 | const GrSurfacePriv* operator&() const; |
| 48 | GrSurfacePriv* operator&(); |
| 49 | |
| 50 | GrSurface* fSurface; |
| 51 | |
| 52 | friend class GrSurface; // to construct/copy this type. |
| 53 | }; |
| 54 | |
| 55 | inline GrSurfacePriv GrSurface::surfacePriv() { return GrSurfacePriv(this); } |
| 56 | |
| 57 | inline const GrSurfacePriv GrSurface::surfacePriv() const { |
| 58 | return GrSurfacePriv(const_cast<GrSurface*>(this)); |
| 59 | } |
| 60 | |
| 61 | #endif |