diff options
author | Robert Phillips <robertphillips@google.com> | 2018-03-09 12:00:34 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-09 17:33:20 +0000 |
commit | 41a3b87846553e9d77e0e113bfaf4ec74a068e96 (patch) | |
tree | 1494d36c2b5704e5bb364100b06fa217a72527e4 /src/gpu/GrTextureStripAtlas.h | |
parent | afdc6b1ba9f5dba52916bd20b608f1f7c21c3160 (diff) |
Make GrTextureStripAtlas DDL friendly
Change-Id: If8fdd7a1c027bc2b2791cfe1af13f99c2561d93d
Reviewed-on: https://skia-review.googlesource.com/113268
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/GrTextureStripAtlas.h')
-rw-r--r-- | src/gpu/GrTextureStripAtlas.h | 98 |
1 files changed, 54 insertions, 44 deletions
diff --git a/src/gpu/GrTextureStripAtlas.h b/src/gpu/GrTextureStripAtlas.h index a67438bbe7..7a777b53ba 100644 --- a/src/gpu/GrTextureStripAtlas.h +++ b/src/gpu/GrTextureStripAtlas.h @@ -26,10 +26,9 @@ class GrTextureStripAtlas { public: /** * Descriptor struct which we'll use as a hash table key - **/ + */ struct Desc { Desc() { sk_bzero(this, sizeof(*this)); } - GrContext* fContext; GrPixelConfig fConfig; uint16_t fWidth, fHeight, fRowHeight; uint16_t fUnusedPadding; @@ -38,11 +37,6 @@ public: } }; - /** - * Try to find an atlas with the required parameters, creates a new one if necessary - */ - static GrTextureStripAtlas* GetAtlas(const Desc& desc); - ~GrTextureStripAtlas(); /** @@ -51,7 +45,8 @@ public: * @return The row index we inserted into, or -1 if we failed to find an open row. The caller * is responsible for calling unlockRow() with this row index when it's done with it. */ - int lockRow(const SkBitmap& data); + int lockRow(GrContext*, const SkBitmap&); + /** * This is intended to be used when cloning a processor that already holds a lock. It is * assumed that the row already has at least one lock. @@ -78,11 +73,12 @@ public: SkScalar getYOffset(int row) const { return SkIntToScalar(row) / fNumRows; } SkScalar getNormalizedTexelHeight() const { return fNormalizedYHeight; } - GrContext* getContext() const { return fDesc.fContext; } - sk_sp<GrTextureProxy> asTextureProxyRef() const; private: + friend class GrTextureStripAtlasManager; // for ctor + + static uint32_t CreateUniqueID(); // Key to indicate an atlas row without any meaningful data stored in it const static uint32_t kEmptyAtlasRowKey = 0xffffffff; @@ -103,11 +99,11 @@ private: }; /** - * We'll only allow construction via the static GrTextureStripAtlas::GetAtlas + * Only the GrTextureStripAtlasManager is allowed to create GrTextureStripAtlases */ - GrTextureStripAtlas(Desc desc); + GrTextureStripAtlas(const Desc& desc); - void lockTexture(); + void lockTexture(GrContext*); void unlockTexture(); /** @@ -116,7 +112,8 @@ private: void initLRU(); /** - * Grabs the least recently used free row out of the LRU list, returns nullptr if no rows are free. + * Grabs the least recently used free row out of the LRU list, returns nullptr if no rows + * are free. */ AtlasRow* getLRU(); @@ -140,37 +137,9 @@ private: void validate(); #endif - /** - * Clean up callback registered with GrContext. Allows this class to - * free up any allocated AtlasEntry and GrTextureStripAtlas objects - */ - static void CleanUp(const GrContext* context, void* info); - - // Hash table entry for atlases - class AtlasEntry : public ::SkNoncopyable { - public: - // for SkTDynamicHash - static const Desc& GetKey(const AtlasEntry& entry) { return entry.fDesc; } - static uint32_t Hash(const Desc& desc) { return SkOpts::hash(&desc, sizeof(Desc)); } - - // AtlasEntry proper - AtlasEntry() : fAtlas(nullptr) {} - ~AtlasEntry() { delete fAtlas; } - Desc fDesc; - GrTextureStripAtlas* fAtlas; - }; - - class Hash; - static Hash* gAtlasCache; - - static Hash* GetCache(); - - // We increment gCacheCount for each atlas - static int32_t gCacheCount; - - // A unique ID for this texture (formed with: gCacheCount++), so we can be sure that if we + // A unique ID for this atlas, so we can be sure that if we // get a texture back from the texture cache, that it's the same one we last used. - const int32_t fCacheKey; + const uint32_t fCacheKey; // Total locks on all rows (when this reaches zero, we can unlock our texture) int32_t fLockedRows; @@ -195,4 +164,45 @@ private: SkTDArray<AtlasRow*> fKeyTable; }; +class GrTextureStripAtlasManager { +public: + GrTextureStripAtlasManager() {} + ~GrTextureStripAtlasManager(); + + void abandon(); + + /** + * Try to find an atlas with the required parameters, creates a new one if necessary + */ + GrTextureStripAtlas* getAtlas(const GrTextureStripAtlas::Desc&); + +private: + void deleteAllAtlases(); + + // Hash table entry for atlases + class AtlasEntry : public ::SkNoncopyable { + public: + AtlasEntry(const GrTextureStripAtlas::Desc& desc, GrTextureStripAtlas* atlas) + : fDesc(desc) + , fAtlas(atlas) { + } + ~AtlasEntry() { delete fAtlas; } + + // for SkTDynamicHash + static const GrTextureStripAtlas::Desc& GetKey(const AtlasEntry& entry) { + return entry.fDesc; + } + static uint32_t Hash(const GrTextureStripAtlas::Desc& desc) { + return SkOpts::hash(&desc, sizeof(GrTextureStripAtlas::Desc)); + } + + const GrTextureStripAtlas::Desc fDesc; + GrTextureStripAtlas* fAtlas; + }; + + typedef SkTDynamicHash<AtlasEntry, GrTextureStripAtlas::Desc> AtlasHash; + + AtlasHash fAtlasCache; +}; + #endif |