Index: src/gpu/GrLayerCache.h |
diff --git a/src/gpu/GrLayerCache.h b/src/gpu/GrLayerCache.h |
index a7ba2afb30f2a63969b5234d17b881a65b115189..27479193aa5102724efd4eace527fc51f0160135 100644 |
--- a/src/gpu/GrLayerCache.h |
+++ b/src/gpu/GrLayerCache.h |
@@ -8,6 +8,8 @@ |
#ifndef GrLayerCache_DEFINED |
#define GrLayerCache_DEFINED |
+#define USE_ATLAS 0 |
+ |
#include "GrAllocPool.h" |
#include "GrAtlas.h" |
#include "GrTHashTable.h" |
@@ -17,61 +19,38 @@ |
class GrGpu; |
class SkPicture; |
-// GrAtlasLocation captures an atlased item's position in the atlas. This |
-// means the plot in which it resides and its bounds inside the plot. |
-// TODO: Make GrGlyph use one of these? |
-class GrAtlasLocation { |
-public: |
- GrAtlasLocation() : fPlot(NULL) {} |
- |
- void set(GrPlot* plot, const GrIRect16& bounds) { |
- fPlot = plot; |
- fBounds = bounds; |
- } |
- |
- const GrPlot* plot() const { |
- return fPlot; |
- } |
- |
- const GrIRect16& bounds() const { |
- return fBounds; |
- } |
- |
-private: |
- GrPlot* fPlot; |
- GrIRect16 fBounds; // only valid is fPlot != NULL |
-}; |
- |
// 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. |
+// Atlased layers get a ref to their atlas GrTexture and 'fRect' contains |
+// their absolute location in the backing texture. |
+// |
+// Non-atlased layers get a ref to the GrTexture in which they reside. Their |
+// 'fRect' will be empty. |
// |
-// 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: |
- uint32_t pictureID() const { return fPictureID; } |
- int layerID() const { return fLayerID; } |
- |
- void init(uint32_t pictureID, int layerID) { |
+ GrCachedLayer(uint32_t pictureID, int layerID) { |
fPictureID = pictureID; |
- fLayerID = layerID; |
- fTexture = NULL; |
- fLocation.set(NULL, GrIRect16::MakeEmpty()); |
+ fLayerID = layerID; |
+ fTexture = NULL; |
+ fRect = GrIRect16::MakeEmpty(); |
} |
+ uint32_t pictureID() const { return fPictureID; } |
+ int layerID() const { return fLayerID; } |
+ |
// This call takes over the caller's ref |
- void setTexture(GrTexture* texture) { |
+ void setTexture(GrTexture* texture, const GrIRect16& rect) { |
if (NULL != fTexture) { |
fTexture->unref(); |
} |
fTexture = texture; // just take over caller's ref |
+ fRect = rect; |
} |
- GrTexture* getTexture() { return fTexture; } |
+ GrTexture* texture() { return fTexture; } |
+ const GrIRect16& rect() const { return fRect; } |
private: |
uint32_t fPictureID; |
@@ -84,7 +63,9 @@ private: |
// non-NULL, that means that the texture is locked in the texture cache. |
GrTexture* fTexture; |
- GrAtlasLocation fLocation; // only valid if the layer is atlased |
+ // For non-atlased layers 'fRect' is empty otherwise it is the bound of |
+ // the layer in the atlas. |
+ GrIRect16 fRect; |
}; |
// The GrLayerCache caches pre-computed saveLayers for later rendering. |
@@ -115,6 +96,9 @@ public: |
// Inform the cache that layer's cached image is not currently required |
void unlock(GrCachedLayer* layer); |
+ // Remove all the layers (and unlock any resources) associated with 'picture' |
+ void purge(const SkPicture* picture); |
+ |
private: |
GrContext* fContext; // pointer back to owning context |
SkAutoTDelete<GrAtlas> fAtlas; // TODO: could lazily allocate |
@@ -122,10 +106,13 @@ private: |
class PictureLayerKey; |
GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash; |
- GrTAllocPool<GrCachedLayer> fLayerPool; |
- void init(); |
+ void initAtlas(); |
GrCachedLayer* createLayer(const SkPicture* picture, int layerID); |
+ |
+ // for testing |
+ friend class GetNumLayers; |
+ int numLayers() const { return fLayerHash.count(); } |
}; |
#endif |