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 GrTexturePriv_DEFINED |
| 9 | #define GrTexturePriv_DEFINED |
| 10 | |
| 11 | #include "GrTexture.h" |
| 12 | |
| 13 | /** Class that adds methods to GrTexture that are only intended for use internal to Skia. |
| 14 | This class is purely a privileged window into GrTexture. 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 GrTexture with a inline public method here). */ |
| 18 | class GrTexturePriv { |
| 19 | public: |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 20 | void setFlag(GrSurfaceFlags flags) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 21 | fTexture->fDesc.fFlags = fTexture->fDesc.fFlags | flags; |
| 22 | } |
| 23 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 24 | void resetFlag(GrSurfaceFlags flags) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 25 | fTexture->fDesc.fFlags = fTexture->fDesc.fFlags & ~flags; |
| 26 | } |
| 27 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 28 | bool isSetFlag(GrSurfaceFlags flags) const { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 29 | return 0 != (fTexture->fDesc.fFlags & flags); |
| 30 | } |
| 31 | |
| 32 | void dirtyMipMaps(bool mipMapsDirty) { fTexture->dirtyMipMaps(mipMapsDirty); } |
| 33 | |
| 34 | bool mipMapsAreDirty() const { |
| 35 | return GrTexture::kValid_MipMapsStatus != fTexture->fMipMapsStatus; |
| 36 | } |
| 37 | |
| 38 | bool hasMipMaps() const { |
| 39 | return GrTexture::kNotAllocated_MipMapsStatus != fTexture->fMipMapsStatus; |
| 40 | } |
| 41 | |
bsalomon | 7775c85 | 2014-12-30 12:50:52 -0800 | [diff] [blame] | 42 | static void ComputeScratchKey(const GrSurfaceDesc&, GrScratchKey*); |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 43 | |
| 44 | // TODO: Move this logic and the shift values out of here and to the callers. |
| 45 | SkFixed normalizeFixedX(SkFixed x) const { |
| 46 | SkASSERT(SkIsPow2(fTexture->fDesc.fWidth)); |
| 47 | return x >> fTexture->fShiftFixedX; |
| 48 | } |
| 49 | |
| 50 | SkFixed normalizeFixedY(SkFixed y) const { |
| 51 | SkASSERT(SkIsPow2(fTexture->fDesc.fHeight)); |
| 52 | return y >> fTexture->fShiftFixedY; |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | GrTexturePriv(GrTexture* texture) : fTexture(texture) { } |
| 57 | GrTexturePriv(const GrTexturePriv& that) : fTexture(that.fTexture) { } |
| 58 | GrTexturePriv& operator=(const GrTexturePriv&); // unimpl |
| 59 | |
| 60 | // No taking addresses of this type. |
| 61 | const GrTexturePriv* operator&() const; |
| 62 | GrTexturePriv* operator&(); |
| 63 | |
| 64 | GrTexture* fTexture; |
| 65 | |
| 66 | friend class GrTexture; // to construct/copy this type. |
| 67 | }; |
| 68 | |
| 69 | inline GrTexturePriv GrTexture::texturePriv() { return GrTexturePriv(this); } |
| 70 | |
| 71 | inline const GrTexturePriv GrTexture::texturePriv () const { |
| 72 | return GrTexturePriv(const_cast<GrTexture*>(this)); |
| 73 | } |
| 74 | |
| 75 | #endif |