diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-16 14:49:16 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-16 14:49:16 +0000 |
commit | 1f47f4f7325971dd53991e2bb02da94fa7c6d962 (patch) | |
tree | a5b5dc02a15a3f3d4edeb921bda4ea1895f4ce77 /include/gpu | |
parent | 71329d809a42889af8d2cadc4e43c60488a739a1 (diff) |
Replaced TextureCacheEntry with GrTexture* and a back pointer to GrResourceEntry (in GrTexture)
http://codereview.appspot.com/6460089/
git-svn-id: http://skia.googlecode.com/svn/trunk@5122 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/gpu')
-rw-r--r-- | include/gpu/GrContext.h | 90 | ||||
-rw-r--r-- | include/gpu/GrResource.h | 12 | ||||
-rw-r--r-- | include/gpu/SkGpuDevice.h | 6 | ||||
-rw-r--r-- | include/gpu/SkGr.h | 8 |
4 files changed, 54 insertions, 62 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 57f0aebd79..0c4d73c7fb 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -95,30 +95,8 @@ public: // Textures /** - * Token that refers to an entry in the texture cache. Returned by - * functions that lock textures. Passed to unlockTexture. - */ - class SK_API TextureCacheEntry { - public: - TextureCacheEntry() : fEntry(NULL) {} - TextureCacheEntry(const TextureCacheEntry& e) : fEntry(e.fEntry) {} - TextureCacheEntry& operator= (const TextureCacheEntry& e) { - fEntry = e.fEntry; - return *this; - } - GrTexture* texture() const; - void reset() { fEntry = NULL; } - GrResourceEntry* cacheEntry() { return fEntry; } - private: - explicit TextureCacheEntry(GrResourceEntry* entry) { fEntry = entry; } - void set(GrResourceEntry* entry) { fEntry = entry; } - GrResourceEntry* fEntry; - friend class GrContext; - }; - - /** * Create a new entry, based on the specified key and texture, and return - * its "locked" entry. Must call be balanced with an unlockTexture() call. + * a "locked" texture. Must call be balanced with an unlockTexture() call. * * @param params The tex params used to draw a texture may help determine * the cache entry used. (e.g. different versions may exist @@ -130,14 +108,14 @@ public: * @param rowBytes The number of bytes between rows of the texture. Zero * implies tightly packed rows. */ - TextureCacheEntry createAndLockTexture(const GrTextureParams* params, - const GrTextureDesc& desc, - const GrCacheData& cacheData, - void* srcData, size_t rowBytes); + GrTexture* createAndLockTexture(const GrTextureParams* params, + const GrTextureDesc& desc, + const GrCacheData& cacheData, + void* srcData, size_t rowBytes); /** * Search for an entry based on key and dimensions. If found, "lock" it and - * return it. The entry's texture() function will return NULL if not found. + * return it. The return value will be NULL if not found. * Must be balanced with an unlockTexture() call. * * @param desc Description of the texture properties. @@ -147,9 +125,9 @@ public: * for different wrap modes on GPUs with limited NPOT * texture support). NULL implies clamp wrap modes. */ - TextureCacheEntry findAndLockTexture(const GrTextureDesc& desc, - const GrCacheData& cacheData, - const GrTextureParams* params); + GrTexture* findAndLockTexture(const GrTextureDesc& desc, + const GrCacheData& cacheData, + const GrTextureParams* params); /** * Determines whether a texture is in the cache. If the texture is found it * will not be locked or returned. This call does not affect the priority of @@ -191,19 +169,25 @@ public: * such an API will create gaps in the tiling pattern. This includes clamp * mode. (This may be addressed in a future update.) */ - TextureCacheEntry lockScratchTexture(const GrTextureDesc& desc, - ScratchTexMatch match); + GrTexture* lockScratchTexture(const GrTextureDesc& desc, + ScratchTexMatch match); /** * When done with an entry, call unlockTexture(entry) on it, which returns * it to the cache, where it may be purged. */ - void unlockTexture(TextureCacheEntry entry); + void unlockTexture(GrTexture* texture); /** - * Free any data associated with the provided entry in the texture cache + * Free any data associated with the provided entry in the texture cache. + * Currently this entry point is only used when a scratch texture is + * detached from the cache. In this case the GrResourceEntry* associated + * with the texture needs to be freed since it will be re-allocated when + * the texture is re-added. This entry point will be removed soon since the + * texture can now carry around a pointer to its GrResourceEntry* (and + * will eventually take over its functionality). */ - void freeEntry(TextureCacheEntry entry); + void freeEntry(GrTexture* texture); /** * Creates a texture that is outside the cache. Does not count against @@ -753,8 +737,8 @@ public: * a SB that matching an RT's criteria. If a match is found that has been * unlocked (its attachment count has reached 0) then it will be relocked. */ - GrResourceEntry* addAndLockStencilBuffer(GrStencilBuffer* sb); - void unlockStencilBuffer(GrResourceEntry* sbEntry); + void addAndLockStencilBuffer(GrStencilBuffer* sb); + void unlockStencilBuffer(GrStencilBuffer* sb); GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt); GrPathRenderer* getPathRenderer(const SkPath& path, @@ -861,14 +845,16 @@ private: class GrAutoScratchTexture : ::GrNoncopyable { public: GrAutoScratchTexture() - : fContext(NULL) { + : fContext(NULL) + , fTexture(NULL) { } GrAutoScratchTexture(GrContext* context, const GrTextureDesc& desc, GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch) - : fContext(NULL) { + : fContext(NULL) + , fTexture(NULL) { this->set(context, desc, match); } @@ -877,9 +863,9 @@ public: } void reset() { - if (NULL != fContext && NULL != fEntry.cacheEntry()) { - fContext->unlockTexture(fEntry); - fEntry.reset(); + if (NULL != fContext && NULL != fTexture) { + fContext->unlockTexture(fTexture); + fTexture = NULL; } } @@ -896,14 +882,14 @@ public: * returned texture. */ GrTexture* detach() { - GrTexture* temp = this->texture(); + GrTexture* temp = fTexture; GrAssert(1 == temp->getRefCnt()); // freeEntry will remove the texture cache's ref temp->ref(); - fContext->freeEntry(fEntry); - fEntry.reset(); + fContext->freeEntry(fTexture); + fTexture = NULL; temp->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit); GrAssert(1 == temp->getRefCnt()); @@ -918,21 +904,21 @@ public: fContext = context; if (NULL != fContext) { - fEntry = fContext->lockScratchTexture(desc, match); - GrTexture* ret = fEntry.texture(); - if (NULL == ret) { + fTexture = fContext->lockScratchTexture(desc, match); + if (NULL == fTexture) { fContext = NULL; } - return ret; + return fTexture; } else { return NULL; } } - GrTexture* texture() { return fEntry.texture(); } + GrTexture* texture() { return fTexture; } + private: GrContext* fContext; - GrContext::TextureCacheEntry fEntry; + GrTexture* fTexture; }; #endif diff --git a/include/gpu/GrResource.h b/include/gpu/GrResource.h index 94d2173ec2..0f4b03d851 100644 --- a/include/gpu/GrResource.h +++ b/include/gpu/GrResource.h @@ -14,6 +14,7 @@ class GrGpu; class GrContext; +class GrResourceEntry; /** * Base class for the GPU resources created by a GrContext. @@ -52,7 +53,7 @@ public: * * @return the size of the buffer in bytes */ - virtual size_t sizeInBytes() const = 0; + virtual size_t sizeInBytes() const = 0; /** * Retrieves the context that owns the resource. Note that it is possible @@ -60,8 +61,11 @@ public: * abandon()ed they no longer have an owning context. Destroying a * GrContext automatically releases all its resources. */ - const GrContext* getContext() const; - GrContext* getContext(); + const GrContext* getContext() const; + GrContext* getContext(); + + void setCacheEntry(GrResourceEntry* cacheEntry) { fCacheEntry = cacheEntry; } + GrResourceEntry* getCacheEntry() { return fCacheEntry; } protected: explicit GrResource(GrGpu* gpu); @@ -83,6 +87,8 @@ private: GrResource* fNext; // dl-list of resources per-GrGpu GrResource* fPrevious; + GrResourceEntry* fCacheEntry; // NULL if not in cache + typedef GrRefCnt INHERITED; }; diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h index 539372a68f..c2fc186a95 100644 --- a/include/gpu/SkGpuDevice.h +++ b/include/gpu/SkGpuDevice.h @@ -116,7 +116,6 @@ public: class SkAutoCachedTexture; // used internally protected: - typedef GrContext::TextureCacheEntry TexCache; bool isBitmapInTextureCache(const SkBitmap& bitmap, const GrTextureParams& params) const; @@ -133,7 +132,8 @@ private: GrClipData fClipData; // state for our offscreen render-target - TexCache fCache; + // TODO: remove 'fCached' and let fTexture automatically return to the cache + bool fCached; // is fTexture in the cache GrTexture* fTexture; GrRenderTarget* fRenderTarget; bool fNeedClear; @@ -143,7 +143,7 @@ private: void initFromRenderTarget(GrContext*, GrRenderTarget*); // used by createCompatibleDevice - SkGpuDevice(GrContext*, GrTexture* texture, TexCache, bool needClear); + SkGpuDevice(GrContext*, GrTexture* texture, bool needClear); // override from SkDevice virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h index 35badfa528..88ca08a6fd 100644 --- a/include/gpu/SkGr.h +++ b/include/gpu/SkGr.h @@ -75,11 +75,11 @@ static inline GrColor SkColor2GrColor(SkColor c) { //////////////////////////////////////////////////////////////////////////////// -GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext*, - const SkBitmap&, - const GrTextureParams*); +GrTexture* GrLockCachedBitmapTexture(GrContext*, + const SkBitmap&, + const GrTextureParams*); -void GrUnlockCachedBitmapTexture(GrContext*, GrContext::TextureCacheEntry); +void GrUnlockCachedBitmapTexture(GrTexture*); //////////////////////////////////////////////////////////////////////////////// // Classes |