diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-11 15:53:47 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-11 15:53:47 +0000 |
commit | 365cd31a65f7dff9947693cd1eab790ada753ed5 (patch) | |
tree | 1a0078f573eaafc8e82d61062f5fc5cde0043506 /src | |
parent | ba73d28bef9b3b2210cd2c2a1754636e78eba1c0 (diff) |
Rename GrAtlasedLayer to GrCachedLayer (since not all cached layers are atlased)
This is mainly a renaming CL but it does add a ref-counted ptr to the backing GrTexture for non-atlased layers (the only kind working right now)
R=jvanverth@google.com
Author: robertphillips@google.com
Review URL: https://codereview.chromium.org/233703003
git-svn-id: http://skia.googlecode.com/svn/trunk@14152 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrLayerCache.cpp | 12 | ||||
-rw-r--r-- | src/gpu/GrLayerCache.h | 51 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 2 |
3 files changed, 46 insertions, 19 deletions
diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp index 9305d1a2dd..d1346c5e50 100644 --- a/src/gpu/GrLayerCache.cpp +++ b/src/gpu/GrLayerCache.cpp @@ -24,7 +24,7 @@ public: uint32_t getHash() const { return (fPictureID << 16) | fLayerID; } - static bool LessThan(const GrAtlasedLayer& layer, const PictureLayerKey& key) { + static bool LessThan(const GrCachedLayer& layer, const PictureLayerKey& key) { if (layer.pictureID() == key.pictureID()) { return layer.layerID() < key.layerID(); } @@ -32,7 +32,7 @@ public: return layer.pictureID() < key.pictureID(); } - static bool Equals(const GrAtlasedLayer& layer, const PictureLayerKey& key) { + static bool Equals(const GrCachedLayer& layer, const PictureLayerKey& key) { return layer.pictureID() == key.pictureID() && layer.layerID() == key.layerID(); } @@ -66,8 +66,8 @@ void GrLayerCache::freeAll() { fAtlasMgr.free(); } -GrAtlasedLayer* GrLayerCache::createLayer(SkPicture* picture, int layerID) { - GrAtlasedLayer* layer = fLayerPool.alloc(); +GrCachedLayer* GrLayerCache::createLayer(SkPicture* picture, int layerID) { + GrCachedLayer* layer = fLayerPool.alloc(); SkASSERT(picture->uniqueID() != SK_InvalidGenID); layer->init(picture->uniqueID(), layerID); @@ -76,9 +76,9 @@ GrAtlasedLayer* GrLayerCache::createLayer(SkPicture* picture, int layerID) { } -const GrAtlasedLayer* GrLayerCache::findLayerOrCreate(SkPicture* picture, int layerID) { +GrCachedLayer* GrLayerCache::findLayerOrCreate(SkPicture* picture, int layerID) { SkASSERT(picture->uniqueID() != SK_InvalidGenID); - GrAtlasedLayer* layer = fLayerHash.find(PictureLayerKey(picture->uniqueID(), layerID)); + GrCachedLayer* layer = fLayerHash.find(PictureLayerKey(picture->uniqueID(), layerID)); if (NULL == layer) { layer = this->createLayer(picture, layerID); } diff --git a/src/gpu/GrLayerCache.h b/src/gpu/GrLayerCache.h index 0624736338..f671195b35 100644 --- a/src/gpu/GrLayerCache.h +++ b/src/gpu/GrLayerCache.h @@ -43,28 +43,55 @@ private: GrIRect16 fBounds; // only valid is fPlot != NULL }; -// A GrAtlasedLayer encapsulates the atlasing information for a single saveLayer. -// It is roughly equivalent to a GrGlyph in the font caching system -class GrAtlasedLayer { +// GrCachedLayer encapsulates the caching information for a single saveLayer. +// +// Atlased layers get a ref to their atlas GrTexture and their GrAtlasLocation +// is filled in. +// In this case GrCachedLayer is roughly equivalent to a GrGlyph in the font +// caching system. +// +// Non-atlased layers get a ref to the GrTexture in which they reside. +// TODO: can we easily reuse the empty space in the non-atlased GrTexture's? +struct GrCachedLayer { public: - GrAtlasedLayer() : fPictureID(SK_InvalidGenID) { } - uint32_t pictureID() const { return fPictureID; } int layerID() const { return fLayerID; } void init(uint32_t pictureID, int layerID) { fPictureID = pictureID; fLayerID = layerID; + fTexture = NULL; + fLocation.set(NULL, GrIRect16::MakeEmpty()); + } + + // This call takes over the caller's ref + void setTexture(GrTexture* texture) { + if (NULL != fTexture) { + fTexture->unref(); + } + + fTexture = texture; // just take over caller's ref } + GrTexture* getTexture() { return fTexture; } private: uint32_t fPictureID; - int fLayerID; // only valid if fPicture != kInvalidGenID - GrAtlasLocation fLocation; + // fLayerID is only valid when fPicture != kInvalidGenID in which case it + // is the index of this layer in the picture (one of 0 .. #layers). + int fLayerID; + + // fTexture is a ref on the atlasing texture for atlased layers and a + // ref on a GrTexture for non-atlased textures. In both cases, if this is + // non-NULL, that means that the texture is locked in the texture cache. + GrTexture* fTexture; + + GrAtlasLocation fLocation; // only valid if the layer is atlased }; // The GrLayerCache caches pre-computed saveLayers for later rendering. -// Unlike the GrFontCache, this cache only has one GrAtlasMgr (for 8888) +// Non-atlased layers are stored in their own GrTexture while the atlased +// layers share a single GrTexture. +// Unlike the GrFontCache, the GrTexture atlas only has one GrAtlasMgr (for 8888) // and one GrPlot (for the entire atlas). As such, the GrLayerCache // roughly combines the functionality of the GrFontCache and GrTextStrike // classes. @@ -75,18 +102,18 @@ public: void freeAll(); - const GrAtlasedLayer* findLayerOrCreate(SkPicture* picture, int id); + GrCachedLayer* findLayerOrCreate(SkPicture* picture, int id); private: SkAutoTUnref<GrGpu> fGpu; SkAutoTDelete<GrAtlasMgr> fAtlasMgr; // TODO: could lazily allocate class PictureLayerKey; - GrTHashTable<GrAtlasedLayer, PictureLayerKey, 7> fLayerHash; - GrTAllocPool<GrAtlasedLayer> fLayerPool; + GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash; + GrTAllocPool<GrCachedLayer> fLayerPool; void init(); - GrAtlasedLayer* createLayer(SkPicture* picture, int id); + GrCachedLayer* createLayer(SkPicture* picture, int id); }; diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index d66006e91c..911ac5a235 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1988,7 +1988,7 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkPicture* picture) { SkDebugf("Need SaveLayers: "); for (int i = 0; i < gpuData->numSaveLayers(); ++i) { if (pullForward[i]) { - const GrAtlasedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(picture, i); + const GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(picture, i); SkDebugf("%d (%d), ", i, layer->layerID()); } |