GrTexturePriv.h revision afbf2d6273cd22c683f20a7e5773843876af3085
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). */ 18class GrTexturePriv { 19public: 20 void setFlag(GrTextureFlags flags) { 21 fTexture->fDesc.fFlags = fTexture->fDesc.fFlags | flags; 22 } 23 24 void resetFlag(GrTextureFlags flags) { 25 fTexture->fDesc.fFlags = fTexture->fDesc.fFlags & ~flags; 26 } 27 28 bool isSetFlag(GrTextureFlags flags) const { 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 42 static GrResourceKey ComputeKey(const GrGpu* gpu, 43 const GrTextureParams* params, 44 const GrTextureDesc& desc, 45 const GrCacheID& cacheID); 46 static GrResourceKey ComputeScratchKey(const GrTextureDesc& desc); 47 static bool NeedsResizing(const GrResourceKey& key); 48 static bool NeedsBilerp(const GrResourceKey& key); 49 50 51 // TODO: Move this logic and the shift values out of here and to the callers. 52 SkFixed normalizeFixedX(SkFixed x) const { 53 SkASSERT(SkIsPow2(fTexture->fDesc.fWidth)); 54 return x >> fTexture->fShiftFixedX; 55 } 56 57 SkFixed normalizeFixedY(SkFixed y) const { 58 SkASSERT(SkIsPow2(fTexture->fDesc.fHeight)); 59 return y >> fTexture->fShiftFixedY; 60 } 61 62private: 63 GrTexturePriv(GrTexture* texture) : fTexture(texture) { } 64 GrTexturePriv(const GrTexturePriv& that) : fTexture(that.fTexture) { } 65 GrTexturePriv& operator=(const GrTexturePriv&); // unimpl 66 67 // No taking addresses of this type. 68 const GrTexturePriv* operator&() const; 69 GrTexturePriv* operator&(); 70 71 GrTexture* fTexture; 72 73 friend class GrTexture; // to construct/copy this type. 74}; 75 76inline GrTexturePriv GrTexture::texturePriv() { return GrTexturePriv(this); } 77 78inline const GrTexturePriv GrTexture::texturePriv () const { 79 return GrTexturePriv(const_cast<GrTexture*>(this)); 80} 81 82#endif 83