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

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

Issue 751663002: Remove Picture deletion listeners. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: f Created 6 years 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/utils/SkPictureUtils.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 #include "GrSurfacePriv.h" 11 #include "GrSurfacePriv.h"
12 12
13 DECLARE_SKMESSAGEBUS_MESSAGE(GrPictureDeletedMessage);
14
15 #ifdef SK_DEBUG 13 #ifdef SK_DEBUG
16 void GrCachedLayer::validate(const GrTexture* backingTexture) const { 14 void GrCachedLayer::validate(const GrTexture* backingTexture) const {
17 SkASSERT(SK_InvalidGenID != fKey.pictureID()); 15 SkASSERT(SK_InvalidGenID != fKey.pictureID());
18 SkASSERT(fKey.start() >= 0); 16 SkASSERT(fKey.start() >= 0);
19 17
20 if (fTexture) { 18 if (fTexture) {
21 // If the layer is in some texture then it must occupy some rectangle 19 // If the layer is in some texture then it must occupy some rectangle
22 SkASSERT(!fRect.isEmpty()); 20 SkASSERT(!fRect.isEmpty());
23 if (!this->isAtlased()) { 21 if (!this->isAtlased()) {
24 // If it isn't atlased then the rectangle should start at the origin 22 // If it isn't atlased then the rectangle should start at the origin
(...skipping 24 matching lines...) Expand all
49 // invariant. 47 // invariant.
50 if (fUses > 0) { 48 if (fUses > 0) {
51 SkASSERT(fLocked); 49 SkASSERT(fLocked);
52 } else { 50 } else {
53 SkASSERT(0 == fUses); 51 SkASSERT(0 == fUses);
54 } 52 }
55 } 53 }
56 54
57 class GrAutoValidateLayer : ::SkNoncopyable { 55 class GrAutoValidateLayer : ::SkNoncopyable {
58 public: 56 public:
59 GrAutoValidateLayer(GrTexture* backingTexture, const GrCachedLayer* layer) 57 GrAutoValidateLayer(GrTexture* backingTexture, const GrCachedLayer* layer)
60 : fBackingTexture(backingTexture) 58 : fBackingTexture(backingTexture)
61 , fLayer(layer) { 59 , fLayer(layer) {
62 if (fLayer) { 60 if (fLayer) {
63 fLayer->validate(backingTexture); 61 fLayer->validate(backingTexture);
64 } 62 }
65 } 63 }
66 ~GrAutoValidateLayer() { 64 ~GrAutoValidateLayer() {
67 if (fLayer) { 65 if (fLayer) {
68 fLayer->validate(fBackingTexture); 66 fLayer->validate(fBackingTexture);
69 } 67 }
(...skipping 19 matching lines...) Expand all
89 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); 87 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
90 for (; !iter.done(); ++iter) { 88 for (; !iter.done(); ++iter) {
91 GrCachedLayer* layer = &(*iter); 89 GrCachedLayer* layer = &(*iter);
92 SkASSERT(0 == layer->uses()); 90 SkASSERT(0 == layer->uses());
93 this->unlock(layer); 91 this->unlock(layer);
94 SkDELETE(layer); 92 SkDELETE(layer);
95 } 93 }
96 94
97 SkASSERT(0 == fPictureHash.count()); 95 SkASSERT(0 == fPictureHash.count());
98 96
99 // The atlas only lets go of its texture when the atlas is deleted. 97 // The atlas only lets go of its texture when the atlas is deleted.
100 fAtlas.free(); 98 fAtlas.free();
101 } 99 }
102 100
103 void GrLayerCache::initAtlas() { 101 void GrLayerCache::initAtlas() {
104 SkASSERT(NULL == fAtlas.get()); 102 SkASSERT(NULL == fAtlas.get());
105 GR_STATIC_ASSERT(kNumPlotsX*kNumPlotsX == GrPictureInfo::kNumPlots); 103 GR_STATIC_ASSERT(kNumPlotsX*kNumPlotsX == GrPictureInfo::kNumPlots);
106 104
107 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight) ; 105 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight) ;
108 fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfi g, 106 fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfi g,
109 kRenderTarget_GrSurfaceFlag, 107 kRenderTarget_GrSurfaceFlag,
110 textureSize, kNumPlotsX, kNumPlotsY, false ))); 108 textureSize, kNumPlotsX, kNumPlotsY, false )));
111 } 109 }
112 110
113 void GrLayerCache::freeAll() { 111 void GrLayerCache::freeAll() {
114 112
115 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); 113 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
116 for (; !iter.done(); ++iter) { 114 for (; !iter.done(); ++iter) {
117 GrCachedLayer* layer = &(*iter); 115 GrCachedLayer* layer = &(*iter);
118 this->unlock(layer); 116 this->unlock(layer);
119 SkDELETE(layer); 117 SkDELETE(layer);
120 } 118 }
121 fLayerHash.rewind(); 119 fLayerHash.rewind();
122 120
123 // The atlas only lets go of its texture when the atlas is deleted. 121 // The atlas only lets go of its texture when the atlas is deleted.
124 fAtlas.free(); 122 fAtlas.free();
125 } 123 }
126 124
127 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID, 125 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID,
128 int start, int stop, 126 int start, int stop,
129 const SkIRect& bounds, 127 const SkIRect& bounds,
130 const SkMatrix& ctm, 128 const SkMatrix& ctm,
131 const SkPaint* paint) { 129 const SkPaint* paint) {
132 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); 130 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0);
133 131
134 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, bo unds, ctm, paint)); 132 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, bo unds, ctm, paint));
135 fLayerHash.add(layer); 133 fLayerHash.add(layer);
136 return layer; 134 return layer;
137 } 135 }
138 136
139 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, 137 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID,
140 int start, 138 int start,
141 const SkIRect& bounds, 139 const SkIRect& bounds,
142 const SkMatrix& ctm) { 140 const SkMatrix& ctm) {
143 SkASSERT(pictureID != SK_InvalidGenID && start > 0); 141 SkASSERT(pictureID != SK_InvalidGenID && start > 0);
144 return fLayerHash.find(GrCachedLayer::Key(pictureID, start, bounds, ctm)); 142 return fLayerHash.find(GrCachedLayer::Key(pictureID, start, bounds, ctm));
145 } 143 }
146 144
147 GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID, 145 GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID,
148 int start, int stop, 146 int start, int stop,
149 const SkIRect& bounds, 147 const SkIRect& bounds,
150 const SkMatrix& ctm, 148 const SkMatrix& ctm,
151 const SkPaint* paint) { 149 const SkPaint* paint) {
152 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); 150 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0);
153 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start, bounds, ctm)); 151 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start, bounds, ctm));
154 if (NULL == layer) { 152 if (NULL == layer) {
155 layer = this->createLayer(pictureID, start, stop, bounds, ctm, paint); 153 layer = this->createLayer(pictureID, start, stop, bounds, ctm, paint);
156 } 154 }
157 155
158 return layer; 156 return layer;
159 } 157 }
160 158
161 bool GrLayerCache::tryToAtlas(GrCachedLayer* layer, 159 bool GrLayerCache::tryToAtlas(GrCachedLayer* layer,
162 const GrSurfaceDesc& desc, 160 const GrSurfaceDesc& desc,
163 bool* needsRendering) { 161 bool* needsRendering) {
164 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, la yer);) 162 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, la yer);)
165 163
166 SkASSERT(PlausiblyAtlasable(desc.fWidth, desc.fHeight)); 164 SkASSERT(PlausiblyAtlasable(desc.fWidth, desc.fHeight));
167 SkASSERT(0 == desc.fSampleCnt); 165 SkASSERT(0 == desc.fSampleCnt);
168 166
169 if (layer->locked()) { 167 if (layer->locked()) {
170 // This layer is already locked 168 // This layer is already locked
171 SkASSERT(fAtlas); 169 SkASSERT(fAtlas);
172 SkASSERT(layer->isAtlased()); 170 SkASSERT(layer->isAtlased());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 SkToS16(desc.fWidth), 211 SkToS16(desc.fWidth),
214 SkToS16(desc.fHeight)); 212 SkToS16(desc.fHeight));
215 layer->setTexture(fAtlas->getTexture(), bounds); 213 layer->setTexture(fAtlas->getTexture(), bounds);
216 layer->setPlot(plot); 214 layer->setPlot(plot);
217 layer->setLocked(true); 215 layer->setLocked(true);
218 this->incPlotLock(layer->plot()->id()); 216 this->incPlotLock(layer->plot()->id());
219 *needsRendering = true; 217 *needsRendering = true;
220 return true; 218 return true;
221 } 219 }
222 220
223 // The layer was rejected by the atlas (even though we know it is 221 // The layer was rejected by the atlas (even though we know it is
224 // plausibly atlas-able). See if a plot can be purged and try again. 222 // plausibly atlas-able). See if a plot can be purged and try again.
225 if (!this->purgePlot()) { 223 if (!this->purgePlot()) {
226 break; // We weren't able to purge any plots 224 break; // We weren't able to purge any plots
227 } 225 }
228 } 226 }
229 } 227 }
230 228
231 return false; 229 return false;
232 } 230 }
233 231
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 pictInfo->decPlotUsage(plotID); 273 pictInfo->decPlotUsage(plotID);
276 274
277 if (0 == pictInfo->plotUsage(plotID)) { 275 if (0 == pictInfo->plotUsage(plotID)) {
278 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot()); 276 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot());
279 277
280 if (pictInfo->fPlotUsage.isEmpty()) { 278 if (pictInfo->fPlotUsage.isEmpty()) {
281 fPictureHash.remove(pictInfo->fPictureID); 279 fPictureHash.remove(pictInfo->fPictureID);
282 SkDELETE(pictInfo); 280 SkDELETE(pictInfo);
283 } 281 }
284 } 282 }
285 283
286 layer->setPlot(NULL); 284 layer->setPlot(NULL);
287 layer->setTexture(NULL, GrIRect16::MakeEmpty()); 285 layer->setTexture(NULL, GrIRect16::MakeEmpty());
288 #endif 286 #endif
289 287
290 } else { 288 } else {
291 layer->setTexture(NULL, GrIRect16::MakeEmpty()); 289 layer->setTexture(NULL, GrIRect16::MakeEmpty());
292 } 290 }
293 291
294 layer->setLocked(false); 292 layer->setLocked(false);
295 } 293 }
(...skipping 21 matching lines...) Expand all
317 SkASSERT(pictInfo->fPictureID == layer->pictureID()); 315 SkASSERT(pictInfo->fPictureID == layer->pictureID());
318 316
319 SkASSERT(pictInfo->fPlotUsage.contains(layer->plot())); 317 SkASSERT(pictInfo->fPlotUsage.contains(layer->plot()));
320 #if !GR_CACHE_HOISTED_LAYERS 318 #if !GR_CACHE_HOISTED_LAYERS
321 SkASSERT(pictInfo->plotUsage(layer->plot()->id()) > 0); 319 SkASSERT(pictInfo->plotUsage(layer->plot()->id()) > 0);
322 #endif 320 #endif
323 321
324 if (layer->locked()) { 322 if (layer->locked()) {
325 plotLocks[layer->plot()->id()]++; 323 plotLocks[layer->plot()->id()]++;
326 } 324 }
327 } 325 }
328 } 326 }
329 327
330 for (int i = 0; i < kNumPlotsX*kNumPlotsY; ++i) { 328 for (int i = 0; i < kNumPlotsX*kNumPlotsY; ++i) {
331 SkASSERT(plotLocks[i] == fPlotLocks[i]); 329 SkASSERT(plotLocks[i] == fPlotLocks[i]);
332 } 330 }
333 } 331 }
334 332
335 class GrAutoValidateCache : ::SkNoncopyable { 333 class GrAutoValidateCache : ::SkNoncopyable {
336 public: 334 public:
337 explicit GrAutoValidateCache(GrLayerCache* cache) 335 explicit GrAutoValidateCache(GrLayerCache* cache)
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 447
450 this->purgePlot(plot); 448 this->purgePlot(plot);
451 } 449 }
452 450
453 SkASSERT(0 == fPictureHash.count()); 451 SkASSERT(0 == fPictureHash.count());
454 452
455 fContext->discardRenderTarget(fAtlas->getTexture()->asRenderTarget()); 453 fContext->discardRenderTarget(fAtlas->getTexture()->asRenderTarget());
456 } 454 }
457 #endif 455 #endif
458 456
459 class GrPictureDeletionListener : public SkPicture::DeletionListener {
460 virtual void onDeletion(uint32_t pictureID) SK_OVERRIDE{
461 const GrPictureDeletedMessage message = { pictureID };
462 SkMessageBus<GrPictureDeletedMessage>::Post(message);
463 }
464 };
465
466 void GrLayerCache::trackPicture(const SkPicture* picture) {
467 if (NULL == fDeletionListener) {
468 fDeletionListener.reset(SkNEW(GrPictureDeletionListener));
469 }
470
471 picture->addDeletionListener(fDeletionListener);
472 }
473
474 void GrLayerCache::processDeletedPictures() { 457 void GrLayerCache::processDeletedPictures() {
475 SkTDArray<GrPictureDeletedMessage> deletedPictures; 458 SkTDArray<SkPicture::DeletionMessage> deletedPictures;
476 fPictDeletionInbox.poll(&deletedPictures); 459 fPictDeletionInbox.poll(&deletedPictures);
477 460
478 for (int i = 0; i < deletedPictures.count(); i++) { 461 for (int i = 0; i < deletedPictures.count(); i++) {
479 this->purge(deletedPictures[i].pictureID); 462 this->purge(deletedPictures[i].fUniqueID);
480 } 463 }
481 } 464 }
482 465
483 #ifdef SK_DEVELOPER 466 #ifdef SK_DEVELOPER
484 void GrLayerCache::writeLayersToDisk(const SkString& dirName) { 467 void GrLayerCache::writeLayersToDisk(const SkString& dirName) {
485 468
486 if (fAtlas) { 469 if (fAtlas) {
487 GrTexture* atlasTexture = fAtlas->getTexture(); 470 GrTexture* atlasTexture = fAtlas->getTexture();
488 if (NULL != atlasTexture) { 471 if (NULL != atlasTexture) {
489 SkString fileName(dirName); 472 SkString fileName(dirName);
(...skipping 11 matching lines...) Expand all
501 continue; 484 continue;
502 } 485 }
503 486
504 SkString fileName(dirName); 487 SkString fileName(dirName);
505 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta rt()); 488 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta rt());
506 489
507 layer->texture()->surfacePriv().savePixels(fileName.c_str()); 490 layer->texture()->surfacePriv().savePixels(fileName.c_str());
508 } 491 }
509 } 492 }
510 #endif 493 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/utils/SkPictureUtils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698