From 59e7d238522145e00357c54d71a4216b279faf1c Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Fri, 9 May 2014 18:02:51 +0000 Subject: [PATCH] Revert of Factor GrTexture into public GrTexture and private GrTextureImpl. (https://codereview.chromium.org/275903002/) Reason for revert: Breaks chrome build. Original issue's description: > Factor GrTexture into public GrTexture and private GrTextureImpl. > > Committed: http://code.google.com/p/skia/source/detail?r=14680 R=jvanverth@google.com, robertphillips@google.com TBR=jvanverth@google.com, robertphillips@google.com NOTREECHECKS=true NOTRY=true Author: bsalomon@google.com Review URL: https://codereview.chromium.org/278073002 git-svn-id: http://skia.googlecode.com/svn/trunk@14681 2bbb7eff-a529-9590-31e7-b0007b416f81 --- bench/GrResourceCacheBench.cpp | 2 +- include/gpu/GrContext.h | 2 +- include/gpu/GrTexture.h | 154 ++++++++++++++++++++--------------------- src/gpu/GrContext.cpp | 16 ++--- src/gpu/GrTexture.cpp | 23 +++--- src/gpu/gl/GrGLTexture.h | 4 +- src/gpu/gl/GrGpuGL.cpp | 6 +- 7 files changed, 101 insertions(+), 106 deletions(-) diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp index b2a5d1e..6767ca1 100644 --- a/bench/GrResourceCacheBench.cpp +++ b/bench/GrResourceCacheBench.cpp @@ -62,7 +62,7 @@ public: } static GrResourceKey ComputeKey(const GrTextureDesc& desc) { - return GrTextureImpl::ComputeScratchKey(desc); + return GrTexture::ComputeScratchKey(desc); } int fID; diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index b28c444..73a01b2 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->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit); + texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit); texture->unref(); SkASSERT(NULL != texture->getCacheEntry()); diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h index 03ea058..ac31f51 100644 --- a/include/gpu/GrTexture.h +++ b/include/gpu/GrTexture.h @@ -15,10 +15,41 @@ 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 */ @@ -37,14 +68,30 @@ 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(); } /** - * 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. + * 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. */ SkFixed normalizeFixedX(SkFixed x) const { SkASSERT(GrIsPow2(fDesc.fWidth)); @@ -61,6 +108,12 @@ 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(); @@ -69,8 +122,13 @@ public: } #endif - GrTextureImpl* impl() { return reinterpret_cast(this); } - const GrTextureImpl* impl() const { return reinterpret_cast(this); } + 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: // A texture refs its rt representation but not vice-versa. It is up to @@ -79,12 +137,13 @@ protected: GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) : INHERITED(gpu, isWrapped, desc) - , fRenderTarget(NULL) { + , fRenderTarget(NULL) + , fMipMapsStatus(kNotAllocated_MipMapsStatus) { + // only make sense if alloc size is pow2 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); } - virtual ~GrTexture(); // GrResource overrides @@ -94,82 +153,22 @@ protected: void validateDesc() const; private: - 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; - - typedef GrSurface INHERITED; -}; - -class GrTextureImpl : public GrTexture { -public: - SK_DECLARE_INST_COUNT(GrTextureImpl) - /** - * 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; - } - - 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 }; + // 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 GrTexture INHERITED; + virtual void internal_dispose() const SK_OVERRIDE; + + typedef GrSurface INHERITED; }; /** @@ -205,7 +204,6 @@ public: fTexture.reset(SkSafeRef(texture)); return texture; } - private: SkAutoTUnref fTexture; SkIPoint fOffset; diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 4b37c60..cd96def 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -237,7 +237,7 @@ void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc, const GrCacheID& cacheID, const GrTextureParams* params) { - GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, cacheID); + GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheID); GrCacheable* resource = fResourceCache->find(resourceKey); SkSafeRef(resource); return static_cast(resource); @@ -246,7 +246,7 @@ GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc, bool GrContext::isTextureInCache(const GrTextureDesc& desc, const GrCacheID& cacheID, const GrTextureParams* params) const { - GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, cacheID); + GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheID); return fResourceCache->hasKey(resourceKey); } @@ -383,13 +383,13 @@ GrTexture* GrContext::createTexture(const GrTextureParams* params, void* srcData, size_t rowBytes, GrResourceKey* cacheKey) { - GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, cacheID); + GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheID); GrTexture* texture; - if (GrTextureImpl::NeedsResizing(resourceKey)) { + if (GrTexture::NeedsResizing(resourceKey)) { texture = this->createResizedTexture(desc, cacheID, srcData, rowBytes, - GrTextureImpl::NeedsBilerp(resourceKey)); + GrTexture::NeedsBilerp(resourceKey)); } else { texture= fGpu->createTexture(desc, srcData, rowBytes); } @@ -413,7 +413,7 @@ static GrTexture* create_scratch_texture(GrGpu* gpu, const GrTextureDesc& desc) { GrTexture* texture = gpu->createTexture(desc, NULL, 0); if (NULL != texture) { - GrResourceKey key = GrTextureImpl::ComputeScratchKey(texture->desc()); + GrResourceKey key = GrTexture::ComputeScratchKey(texture->desc()); // Adding a resource could put us overbudget. Try to free up the // necessary space before adding it. resourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); @@ -453,7 +453,7 @@ GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra int origHeight = desc.fHeight; do { - GrResourceKey key = GrTextureImpl::ComputeScratchKey(desc); + GrResourceKey key = GrTexture::ComputeScratchKey(desc); // Ensure we have exclusive access to the texture so future 'find' calls don't return it resource = fResourceCache->find(key, GrResourceCache::kHide_OwnershipFlag); if (NULL != resource) { @@ -543,7 +543,7 @@ void GrContext::unlockScratchTexture(GrTexture* texture) { // Instead, give up the cache's ref and leave the decision up to // addExistingTextureToCache once its ref count reaches 0. For // this to work we need to leave it in the exclusive list. - texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit); + texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit); // Give up the cache's ref to the texture texture->unref(); } diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp index 8651d10..3186d89 100644 --- a/src/gpu/GrTexture.cpp +++ b/src/gpu/GrTexture.cpp @@ -26,12 +26,13 @@ GrTexture::~GrTexture() { * textures back in the texture cache when their ref count goes to zero. */ void GrTexture::internal_dispose() const { - if (this->impl()->isSetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit) && + + if (this->isSetFlag((GrTextureFlags) kReturnToCache_FlagBit) && NULL != this->INHERITED::getContext()) { GrTexture* nonConstThis = const_cast(this); this->fRefCnt = 1; // restore ref count to initial setting - nonConstThis->impl()->resetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit); + nonConstThis->resetFlag((GrTextureFlags) kReturnToCache_FlagBit); nonConstThis->INHERITED::getContext()->addExistingTextureToCache(nonConstThis); // Note: "this" texture might be freed inside addExistingTextureToCache @@ -43,7 +44,7 @@ void GrTexture::internal_dispose() const { this->INHERITED::internal_dispose(); } -void GrTextureImpl::dirtyMipMaps(bool mipMapsDirty) { +void GrTexture::dirtyMipMaps(bool mipMapsDirty) { if (mipMapsDirty) { if (kValid_MipMapsStatus == fMipMapsStatus) { fMipMapsStatus = kAllocated_MipMapsStatus; @@ -62,7 +63,7 @@ size_t GrTexture::gpuMemorySize() const { size_t textureSize = (size_t) fDesc.fWidth * fDesc.fHeight * GrBytesPerPixel(fDesc.fConfig); - if (this->impl()->hasMipMaps()) { + if (kNotAllocated_MipMapsStatus != fMipMapsStatus) { // We don't have to worry about the mipmaps being a different size than // we'd expect because we never change fDesc.fWidth/fHeight. textureSize *= 2; @@ -99,7 +100,7 @@ void GrTexture::writePixels(int left, int top, int width, int height, } void GrTexture::onRelease() { - SkASSERT(!this->impl()->isSetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit)); + SkASSERT(!this->isSetFlag((GrTextureFlags) kReturnToCache_FlagBit)); INHERITED::onRelease(); } @@ -129,8 +130,6 @@ void GrTexture::validateDesc() const { } } -////////////////////////////////////////////////////////////////////////////// - // These flags need to fit in a GrResourceKey::ResourceFlags so they can be folded into the texture // key enum TextureFlags { @@ -187,9 +186,7 @@ GrSurfaceOrigin resolve_origin(const GrTextureDesc& desc) { } } -////////////////////////////////////////////////////////////////////////////// - -GrResourceKey GrTextureImpl::ComputeKey(const GrGpu* gpu, +GrResourceKey GrTexture::ComputeKey(const GrGpu* gpu, const GrTextureParams* params, const GrTextureDesc& desc, const GrCacheID& cacheID) { @@ -197,7 +194,7 @@ GrResourceKey GrTextureImpl::ComputeKey(const GrGpu* gpu, return GrResourceKey(cacheID, texture_resource_type(), flags); } -GrResourceKey GrTextureImpl::ComputeScratchKey(const GrTextureDesc& desc) { +GrResourceKey GrTexture::ComputeScratchKey(const GrTextureDesc& desc) { GrCacheID::Key idKey; // Instead of a client-provided key of the texture contents we create a key from the // descriptor. @@ -216,10 +213,10 @@ GrResourceKey GrTextureImpl::ComputeScratchKey(const GrTextureDesc& desc) { return GrResourceKey(cacheID, texture_resource_type(), 0); } -bool GrTextureImpl::NeedsResizing(const GrResourceKey& key) { +bool GrTexture::NeedsResizing(const GrResourceKey& key) { return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); } -bool GrTextureImpl::NeedsBilerp(const GrResourceKey& key) { +bool GrTexture::NeedsBilerp(const GrResourceKey& key) { return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); } diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h index 0b364ac..62052fd 100644 --- a/src/gpu/gl/GrGLTexture.h +++ b/src/gpu/gl/GrGLTexture.h @@ -45,7 +45,7 @@ private: //////////////////////////////////////////////////////////////////////////////// -class GrGLTexture : public GrTextureImpl { +class GrGLTexture : public GrTexture { public: struct TexParams { @@ -105,7 +105,7 @@ private: const Desc& textureDesc, const GrGLRenderTarget::Desc* rtDesc); - typedef GrTextureImpl INHERITED; + typedef GrTexture INHERITED; }; #endif diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index a670eae..1a1bad7 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -479,7 +479,7 @@ bool GrGpuGL::onWriteTexturePixels(GrTexture* texture, if (this->uploadTexData(desc, false, left, top, width, height, config, buffer, rowBytes)) { - texture->impl()->dirtyMipMaps(true); + texture->dirtyMipMaps(true); return true; } else { return false; @@ -1583,8 +1583,8 @@ void GrGpuGL::flushRenderTarget(const SkIRect* bound) { } GrTexture *texture = rt->asTexture(); - if (NULL != texture) { - texture->impl()->dirtyMipMaps(true); + if (texture) { + texture->dirtyMipMaps(true); } } -- 2.7.4