Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Unified Diff: src/gpu/GrLayerCache.cpp

Issue 476833004: Refactor GrLayerCache for new API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add DISABLE_CACHING guard Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrLayerCache.cpp
diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp
index 5fb76d7392dbdda6bec1e3461ca4f93b0235dd47..c0510c0365873f6a2d753ac755275a0487b4744a 100644
--- a/src/gpu/GrLayerCache.cpp
+++ b/src/gpu/GrLayerCache.cpp
@@ -117,37 +117,36 @@ void GrLayerCache::freeAll() {
this->initAtlas();
}
-GrCachedLayer* GrLayerCache::createLayer(const SkPicture* picture,
+GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID,
int start, int stop,
const SkMatrix& ctm) {
- SkASSERT(picture->uniqueID() != SK_InvalidGenID && start > 0 && stop > 0);
+ SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0);
- GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (picture->uniqueID(), start, stop, ctm));
+ GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, ctm));
fLayerHash.add(layer);
return layer;
}
-GrCachedLayer* GrLayerCache::findLayer(const SkPicture* picture,
+GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID,
int start, int stop,
const SkMatrix& ctm) {
- SkASSERT(picture->uniqueID() != SK_InvalidGenID && start > 0 && stop > 0);
- return fLayerHash.find(GrCachedLayer::Key(picture->uniqueID(), start, stop, ctm));
+ SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0);
+ return fLayerHash.find(GrCachedLayer::Key(pictureID, start, stop, ctm));
}
-GrCachedLayer* GrLayerCache::findLayerOrCreate(const SkPicture* picture,
+GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID,
int start, int stop,
const SkMatrix& ctm) {
- SkASSERT(picture->uniqueID() != SK_InvalidGenID && start > 0 && stop > 0);
- GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(picture->uniqueID(),
- start, stop, ctm));
+ SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0);
+ GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start, stop, ctm));
if (NULL == layer) {
- layer = this->createLayer(picture, start, stop, ctm);
+ layer = this->createLayer(pictureID, start, stop, ctm);
}
return layer;
}
-bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc) {
+bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool dontAtlas) {
SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);)
if (layer->locked()) {
@@ -155,19 +154,21 @@ bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc) {
#ifdef SK_DEBUG
if (layer->isAtlased()) {
// It claims to be atlased
+ SkASSERT(!dontAtlas);
SkASSERT(layer->rect().width() == desc.fWidth);
SkASSERT(layer->rect().height() == desc.fHeight);
}
#endif
- return true;
+ return false;
}
if (layer->isAtlased()) {
// Hooray it is still in the atlas - make sure it stays there
+ SkASSERT(!dontAtlas);
layer->setLocked(true);
fPlotLocks[layer->plot()->id()]++;
- return true;
- } else if (PlausiblyAtlasable(desc.fWidth, desc.fHeight)) {
+ return false;
+ } else if (!dontAtlas && PlausiblyAtlasable(desc.fWidth, desc.fHeight)) {
// Not in the atlas - will it fit?
GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID());
if (NULL == pictInfo) {
@@ -185,13 +186,13 @@ bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc) {
if (NULL != plot) {
// The layer was successfully added to the atlas
GrIRect16 bounds = GrIRect16::MakeXYWH(loc.fX, loc.fY,
- SkToS16(desc.fWidth),
+ SkToS16(desc.fWidth),
SkToS16(desc.fHeight));
layer->setTexture(fAtlas->getTexture(), bounds);
layer->setPlot(plot);
layer->setLocked(true);
fPlotLocks[layer->plot()->id()]++;
- return false;
+ return true;
}
// The layer was rejected by the atlas (even though we know it is
@@ -210,7 +211,7 @@ bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc) {
layer->setTexture(tex, GrIRect16::MakeWH(SkToS16(desc.fWidth), SkToS16(desc.fHeight)));
layer->setLocked(true);
- return false;
+ return true;
}
void GrLayerCache::unlock(GrCachedLayer* layer) {
@@ -228,7 +229,7 @@ void GrLayerCache::unlock(GrCachedLayer* layer) {
fPlotLocks[plotID]--;
// At this point we could aggressively clear out un-locked plots but
// by delaying we may be able to reuse some of the atlased layers later.
-#if 0
+#if DISABLE_CACHING
// This testing code aggressively removes the atlased layers. This
// can be used to separate the performance contribution of less
// render target pingponging from that due to the re-use of cached layers
@@ -264,7 +265,9 @@ void GrLayerCache::validate() const {
if (NULL != pictInfo) {
// In aggressive cleanup mode a picture info should only exist if
// it has some atlased layers
+#if !DISABLE_CACHING
SkASSERT(!pictInfo->fPlotUsage.isEmpty());
+#endif
} else {
// If there is no picture info for this layer then all of its
// layers should be non-atlased.
@@ -341,39 +344,57 @@ bool GrLayerCache::purgePlot() {
continue;
}
- // We need to find all the layers in 'plot' and remove them.
- SkTDArray<GrCachedLayer*> toBeRemoved;
+ this->purgePlot(plot);
+ return true;
+ }
- SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
- for (; !iter.done(); ++iter) {
- if (plot == (*iter).plot()) {
- *toBeRemoved.append() = &(*iter);
- }
+ return false;
+}
+
+void GrLayerCache::purgePlot(GrPlot* plot) {
+ SkASSERT(0 == fPlotLocks[plot->id()]);
+
+ // We need to find all the layers in 'plot' and remove them.
+ SkTDArray<GrCachedLayer*> toBeRemoved;
+
+ SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
+ for (; !iter.done(); ++iter) {
+ if (plot == (*iter).plot()) {
+ *toBeRemoved.append() = &(*iter);
}
+ }
- for (int i = 0; i < toBeRemoved.count(); ++i) {
- SkASSERT(!toBeRemoved[i]->locked());
+ for (int i = 0; i < toBeRemoved.count(); ++i) {
+ SkASSERT(!toBeRemoved[i]->locked());
- GrPictureInfo* pictInfo = fPictureHash.find(toBeRemoved[i]->pictureID());
- SkASSERT(NULL != pictInfo);
+ GrPictureInfo* pictInfo = fPictureHash.find(toBeRemoved[i]->pictureID());
+ SkASSERT(NULL != pictInfo);
- GrAtlas::RemovePlot(&pictInfo->fPlotUsage, plot);
+ GrAtlas::RemovePlot(&pictInfo->fPlotUsage, plot);
- // Aggressively remove layers and, if now totally uncached, picture info
- fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i]));
- SkDELETE(toBeRemoved[i]);
+ // Aggressively remove layers and, if now totally uncached, picture info
+ fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i]));
+ SkDELETE(toBeRemoved[i]);
- if (pictInfo->fPlotUsage.isEmpty()) {
- fPictureHash.remove(pictInfo->fPictureID);
- SkDELETE(pictInfo);
- }
+ if (pictInfo->fPlotUsage.isEmpty()) {
+ fPictureHash.remove(pictInfo->fPictureID);
+ SkDELETE(pictInfo);
}
-
- plot->resetRects();
- return true;
}
- return false;
+ plot->resetRects();
+}
+
+void GrLayerCache::purgeAll() {
+ GrAtlas::PlotIter iter;
+ GrPlot* plot;
+ for (plot = fAtlas->iterInit(&iter, GrAtlas::kLRUFirst_IterOrder);
+ NULL != plot;
+ plot = iter.prev()) {
+ SkASSERT(0 == fPlotLocks[plot->id()]);
+
+ this->purgePlot(plot);
+ }
}
class GrPictureDeletionListener : public SkPicture::DeletionListener {
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698