From bd465d141be875278d6bbc06becfdbb4acbbf557 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Fri, 9 May 2014 17:37:55 +0000 Subject: Factor GrTexture into public GrTexture and private GrTextureImpl. R=jvanverth@google.com, robertphillips@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/275903002 git-svn-id: http://skia.googlecode.com/svn/trunk@14680 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/gpu/GrContext.h | 2 +- include/gpu/GrTexture.h | 154 ++++++++++++++++++++++++------------------------ 2 files changed, 79 insertions(+), 77 deletions(-) (limited to 'include') diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 73a01b2098..b28c444edc 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -1098,7 +1098,7 @@ public: // lets go of the ref and the ref count goes to 0 internal_dispose will see this flag is // set and re-ref the texture, thereby restoring the cache's ref. SkASSERT(texture->getRefCnt() > 1); - texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit); + texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit); texture->unref(); SkASSERT(NULL != texture->getCacheEntry()); diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h index ac31f51b00..03ea058485 100644 --- a/include/gpu/GrTexture.h +++ b/include/gpu/GrTexture.h @@ -15,41 +15,10 @@ class GrResourceKey; class GrTextureParams; +class GrTextureImpl; class GrTexture : public GrSurface { - public: - SK_DECLARE_INST_COUNT(GrTexture) - // from GrResource - /** - * Informational texture flags - */ - enum FlagBits { - kFirstBit = (kLastPublic_GrTextureFlagBit << 1), - - /** - * This texture should be returned to the texture cache when - * it is no longer reffed - */ - kReturnToCache_FlagBit = kFirstBit, - }; - - void setFlag(GrTextureFlags flags) { - fDesc.fFlags = fDesc.fFlags | flags; - } - void resetFlag(GrTextureFlags flags) { - fDesc.fFlags = fDesc.fFlags & ~flags; - } - bool isSetFlag(GrTextureFlags flags) const { - return 0 != (fDesc.fFlags & flags); - } - - void dirtyMipMaps(bool mipMapsDirty); - - bool mipMapsAreDirty() const { - return kValid_MipMapsStatus != fMipMapsStatus; - } - /** * Approximate number of bytes used by the texture */ @@ -68,30 +37,14 @@ public: size_t rowBytes = 0, uint32_t pixelOpsFlags = 0) SK_OVERRIDE; - /** - * @return this texture - */ virtual GrTexture* asTexture() SK_OVERRIDE { return this; } virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; } + virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return fRenderTarget.get(); } + virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return fRenderTarget.get(); } /** - * Retrieves the render target underlying this texture that can be passed to - * GrGpu::setRenderTarget(). - * - * @return handle to render target or NULL if the texture is not a - * render target - */ - virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { - return fRenderTarget.get(); - } - virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { - return fRenderTarget.get(); - } - - // GrTexture - /** - * Convert from texels to normalized texture coords for POT textures - * only. + * Convert from texels to normalized texture coords for POT textures only. Please don't add + * new callsites for these functions. They are slated for removal. */ SkFixed normalizeFixedX(SkFixed x) const { SkASSERT(GrIsPow2(fDesc.fWidth)); @@ -108,12 +61,6 @@ public: */ virtual GrBackendObject getTextureHandle() const = 0; - /** - * Call this when the state of the native API texture object is - * altered directly, without being tracked by skia. - */ - virtual void invalidateCachedState() = 0; - #ifdef SK_DEBUG void validate() const { this->INHERITED::validate(); @@ -122,13 +69,8 @@ public: } #endif - static GrResourceKey ComputeKey(const GrGpu* gpu, - const GrTextureParams* params, - const GrTextureDesc& desc, - const GrCacheID& cacheID); - static GrResourceKey ComputeScratchKey(const GrTextureDesc& desc); - static bool NeedsResizing(const GrResourceKey& key); - static bool NeedsBilerp(const GrResourceKey& key); + GrTextureImpl* impl() { return reinterpret_cast(this); } + const GrTextureImpl* impl() const { return reinterpret_cast(this); } protected: // A texture refs its rt representation but not vice-versa. It is up to @@ -137,13 +79,12 @@ protected: GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) : INHERITED(gpu, isWrapped, desc) - , fRenderTarget(NULL) - , fMipMapsStatus(kNotAllocated_MipMapsStatus) { - + , fRenderTarget(NULL) { // only make sense if alloc size is pow2 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); } + virtual ~GrTexture(); // GrResource overrides @@ -153,22 +94,82 @@ protected: void validateDesc() const; private: - enum MipMapsStatus { - kNotAllocated_MipMapsStatus, - kAllocated_MipMapsStatus, - kValid_MipMapsStatus - }; + virtual void internal_dispose() const SK_OVERRIDE; // these two shift a fixed-point value into normalized coordinates // for this texture if the texture is power of two sized. int fShiftFixedX; int fShiftFixedY; - MipMapsStatus fMipMapsStatus; + typedef GrSurface INHERITED; +}; - virtual void internal_dispose() const SK_OVERRIDE; +class GrTextureImpl : public GrTexture { +public: + SK_DECLARE_INST_COUNT(GrTextureImpl) + /** + * Informational texture flags + */ + enum FlagBits { + kFirstBit = (kLastPublic_GrTextureFlagBit << 1), - typedef GrSurface INHERITED; + /** + * This texture should be returned to the texture cache when + * it is no longer reffed + */ + kReturnToCache_FlagBit = kFirstBit, + }; + + void setFlag(GrTextureFlags flags) { + fDesc.fFlags = fDesc.fFlags | flags; + } + void resetFlag(GrTextureFlags flags) { + fDesc.fFlags = fDesc.fFlags & ~flags; + } + bool isSetFlag(GrTextureFlags flags) const { + return 0 != (fDesc.fFlags & flags); + } + + void dirtyMipMaps(bool mipMapsDirty); + + bool mipMapsAreDirty() const { + return kValid_MipMapsStatus != fMipMapsStatus; + } + + bool hasMipMaps() const { + return kNotAllocated_MipMapsStatus != fMipMapsStatus; + } + + /** + * Call this when the state of the native API texture object is + * altered directly, without being tracked by skia. + */ + virtual void invalidateCachedState() = 0; + + static GrResourceKey ComputeKey(const GrGpu* gpu, + const GrTextureParams* params, + const GrTextureDesc& desc, + const GrCacheID& cacheID); + static GrResourceKey ComputeScratchKey(const GrTextureDesc& desc); + static bool NeedsResizing(const GrResourceKey& key); + static bool NeedsBilerp(const GrResourceKey& key); + +protected: + GrTextureImpl(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) + : INHERITED(gpu, isWrapped, desc) + , fMipMapsStatus(kNotAllocated_MipMapsStatus) { + } + +private: + enum MipMapsStatus { + kNotAllocated_MipMapsStatus, + kAllocated_MipMapsStatus, + kValid_MipMapsStatus + }; + + MipMapsStatus fMipMapsStatus; + + typedef GrTexture INHERITED; }; /** @@ -204,6 +205,7 @@ public: fTexture.reset(SkSafeRef(texture)); return texture; } + private: SkAutoTUnref fTexture; SkIPoint fOffset; -- cgit v1.2.3