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

Side by Side Diff: src/gpu/GrLayerCache.cpp

Issue 433553002: Add CTM to the cached layers' key and reduce render target pingponging in layer pre-rendering (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix yet another bug 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 unified diff | Download patch
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrAtlas.h" 8 #include "GrAtlas.h"
9 #include "GrGpu.h" 9 #include "GrGpu.h"
10 #include "GrLayerCache.h" 10 #include "GrLayerCache.h"
11 11
12 DECLARE_SKMESSAGEBUS_MESSAGE(GrPictureDeletedMessage); 12 DECLARE_SKMESSAGEBUS_MESSAGE(GrPictureDeletedMessage);
13 13
14 #ifdef SK_DEBUG 14 #ifdef SK_DEBUG
15 void GrCachedLayer::validate(const GrTexture* backingTexture) const { 15 void GrCachedLayer::validate(const GrTexture* backingTexture) const {
16 SkASSERT(SK_InvalidGenID != fKey.getPictureID()); 16 SkASSERT(SK_InvalidGenID != fKey.pictureID());
17 SkASSERT(-1 != fKey.getLayerID()); 17 SkASSERT(fKey.start() > 0 && fKey.stop() > 0);
18 18
19 19
20 if (NULL != fTexture) { 20 if (NULL != fTexture) {
21 // If the layer is in some texture then it must occupy some rectangle 21 // If the layer is in some texture then it must occupy some rectangle
22 SkASSERT(!fRect.isEmpty()); 22 SkASSERT(!fRect.isEmpty());
23 if (!this->isAtlased()) { 23 if (!this->isAtlased()) {
24 // If it isn't atlased then the rectangle should start at the origin 24 // If it isn't atlased then the rectangle should start at the origin
25 SkASSERT(0.0f == fRect.fLeft && 0.0f == fRect.fTop); 25 SkASSERT(0.0f == fRect.fLeft && 0.0f == fRect.fTop);
26 } 26 }
27 } else { 27 } else {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 // The atlas only lets go of its texture when the atlas is deleted. 111 // The atlas only lets go of its texture when the atlas is deleted.
112 fAtlas.free(); 112 fAtlas.free();
113 // GrLayerCache always assumes an atlas exists so recreate it. The atlas 113 // GrLayerCache always assumes an atlas exists so recreate it. The atlas
114 // lazily allocates a replacement texture so reallocating a new 114 // lazily allocates a replacement texture so reallocating a new
115 // atlas here won't disrupt a GrContext::contextDestroyed or freeGpuResource s. 115 // atlas here won't disrupt a GrContext::contextDestroyed or freeGpuResource s.
116 // TODO: Make GrLayerCache lazily allocate the atlas manager? 116 // TODO: Make GrLayerCache lazily allocate the atlas manager?
117 this->initAtlas(); 117 this->initAtlas();
118 } 118 }
119 119
120 GrCachedLayer* GrLayerCache::createLayer(const SkPicture* picture, int layerID) { 120 GrCachedLayer* GrLayerCache::createLayer(const SkPicture* picture,
121 SkASSERT(picture->uniqueID() != SK_InvalidGenID && layerID >= 0); 121 int start, int stop,
122 const SkMatrix& ctm) {
123 SkASSERT(picture->uniqueID() != SK_InvalidGenID && start > 0 && stop > 0);
122 124
123 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (picture->uniqueID(), layer ID)); 125 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (picture->uniqueID(), start , stop, ctm));
124 fLayerHash.add(layer); 126 fLayerHash.add(layer);
125 return layer; 127 return layer;
126 } 128 }
127 129
128 GrCachedLayer* GrLayerCache::findLayer(const SkPicture* picture, int layerID) { 130 GrCachedLayer* GrLayerCache::findLayer(const SkPicture* picture,
129 SkASSERT(picture->uniqueID() != SK_InvalidGenID && layerID >= 0); 131 int start, int stop,
130 return fLayerHash.find(GrCachedLayer::Key(picture->uniqueID(), layerID)); 132 const SkMatrix& ctm) {
133 SkASSERT(picture->uniqueID() != SK_InvalidGenID && start > 0 && stop > 0);
134 return fLayerHash.find(GrCachedLayer::Key(picture->uniqueID(), start, stop, ctm));
131 } 135 }
132 136
133 GrCachedLayer* GrLayerCache::findLayerOrCreate(const SkPicture* picture, int lay erID) { 137 GrCachedLayer* GrLayerCache::findLayerOrCreate(const SkPicture* picture,
134 SkASSERT(picture->uniqueID() != SK_InvalidGenID && layerID >= 0); 138 int start, int stop,
135 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(picture->uniqueID( ), layerID)); 139 const SkMatrix& ctm) {
140 SkASSERT(picture->uniqueID() != SK_InvalidGenID && start > 0 && stop > 0);
141 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(picture->uniqueID( ),
142 start, stop, ctm)) ;
136 if (NULL == layer) { 143 if (NULL == layer) {
137 layer = this->createLayer(picture, layerID); 144 layer = this->createLayer(picture, start, stop, ctm);
138 } 145 }
139 146
140 return layer; 147 return layer;
141 } 148 }
142 149
143 bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc) { 150 bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc) {
144 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);) 151 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);)
145 152
146 if (layer->locked()) { 153 if (layer->locked()) {
147 // This layer is already locked 154 // This layer is already locked
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return; 221 return;
215 } 222 }
216 223
217 if (layer->isAtlased()) { 224 if (layer->isAtlased()) {
218 const int plotID = layer->plot()->id(); 225 const int plotID = layer->plot()->id();
219 226
220 SkASSERT(fPlotLocks[plotID] > 0); 227 SkASSERT(fPlotLocks[plotID] > 0);
221 fPlotLocks[plotID]--; 228 fPlotLocks[plotID]--;
222 // At this point we could aggressively clear out un-locked plots but 229 // At this point we could aggressively clear out un-locked plots but
223 // by delaying we may be able to reuse some of the atlased layers later. 230 // by delaying we may be able to reuse some of the atlased layers later.
231 #if 0
232 // This testing code aggressively removes the atlased layers. This
233 // can be used to separate the performance contribution of less
234 // render target pingponging from that due to the re-use of cached layer s
235 GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID());
236 SkASSERT(NULL != pictInfo);
237
238 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot());
239
240 layer->setPlot(NULL);
241 layer->setTexture(NULL, GrIRect16::MakeEmpty());
242 #endif
243
224 } else { 244 } else {
225 fContext->unlockScratchTexture(layer->texture()); 245 fContext->unlockScratchTexture(layer->texture());
226 layer->setTexture(NULL, GrIRect16::MakeEmpty()); 246 layer->setTexture(NULL, GrIRect16::MakeEmpty());
227 } 247 }
228 248
229 layer->setLocked(false); 249 layer->setLocked(false);
230 } 250 }
231 251
232 #ifdef SK_DEBUG 252 #ifdef SK_DEBUG
233 void GrLayerCache::validate() const { 253 void GrLayerCache::validate() const {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 393
374 void GrLayerCache::processDeletedPictures() { 394 void GrLayerCache::processDeletedPictures() {
375 SkTDArray<GrPictureDeletedMessage> deletedPictures; 395 SkTDArray<GrPictureDeletedMessage> deletedPictures;
376 fPictDeletionInbox.poll(&deletedPictures); 396 fPictDeletionInbox.poll(&deletedPictures);
377 397
378 for (int i = 0; i < deletedPictures.count(); i++) { 398 for (int i = 0; i < deletedPictures.count(); i++) {
379 this->purge(deletedPictures[i].pictureID); 399 this->purge(deletedPictures[i].pictureID);
380 } 400 }
381 } 401 }
382 402
OLDNEW
« 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