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

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

Issue 630173002: Fix some incorrect assumptions in GrLayerCache.cpp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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 | « no previous file | no next file » | 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.pictureID()); 16 SkASSERT(SK_InvalidGenID != fKey.pictureID());
17 SkASSERT(fKey.start() > 0); 17 SkASSERT(fKey.start() >= 0);
18 18
19 19
20 if (fTexture) { 20 if (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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::abandonContext or freeGpuResources. 115 // atlas here won't disrupt a GrContext::abandonContext or freeGpuResources.
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(uint32_t pictureID, 120 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID,
121 int start, int stop, 121 int start, int stop,
122 const SkMatrix& ctm, 122 const SkMatrix& ctm,
123 const SkPaint* paint) { 123 const SkPaint* paint) {
124 SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0); 124 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0);
125 125
126 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, ct m, paint)); 126 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, ct m, paint));
127 fLayerHash.add(layer); 127 fLayerHash.add(layer);
128 return layer; 128 return layer;
129 } 129 }
130 130
131 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, 131 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID,
132 int start, 132 int start,
133 const SkMatrix& ctm) { 133 const SkMatrix& ctm) {
134 SkASSERT(pictureID != SK_InvalidGenID && start > 0); 134 SkASSERT(pictureID != SK_InvalidGenID && start > 0);
135 return fLayerHash.find(GrCachedLayer::Key(pictureID, start, ctm)); 135 return fLayerHash.find(GrCachedLayer::Key(pictureID, start, ctm));
136 } 136 }
137 137
138 GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID, 138 GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID,
139 int start, int stop, 139 int start, int stop,
140 const SkMatrix& ctm, 140 const SkMatrix& ctm,
141 const SkPaint* paint) { 141 const SkPaint* paint) {
142 SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0); 142 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0);
143 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start, ctm)); 143 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start, ctm));
144 if (NULL == layer) { 144 if (NULL == layer) {
145 layer = this->createLayer(pictureID, start, stop, ctm, paint); 145 layer = this->createLayer(pictureID, start, stop, ctm, paint);
146 } 146 }
147 147
148 return layer; 148 return layer;
149 } 149 }
150 150
151 bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool do ntAtlas) { 151 bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool do ntAtlas) {
152 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);) 152 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);)
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); 362 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
363 for (; !iter.done(); ++iter) { 363 for (; !iter.done(); ++iter) {
364 if (plot == (*iter).plot()) { 364 if (plot == (*iter).plot()) {
365 *toBeRemoved.append() = &(*iter); 365 *toBeRemoved.append() = &(*iter);
366 } 366 }
367 } 367 }
368 368
369 for (int i = 0; i < toBeRemoved.count(); ++i) { 369 for (int i = 0; i < toBeRemoved.count(); ++i) {
370 SkASSERT(!toBeRemoved[i]->locked()); 370 SkASSERT(!toBeRemoved[i]->locked());
371 371
372 GrPictureInfo* pictInfo = fPictureHash.find(toBeRemoved[i]->pictureID()) ; 372 uint32_t pictureIDToRemove = toBeRemoved[i]->pictureID();
373 SkASSERT(pictInfo);
374 373
375 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, plot); 374 // Aggressively remove layers and, if it becomes totally uncached, delet e the picture info
376
377 // Aggressively remove layers and, if now totally uncached, picture info
378 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i])); 375 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i]));
379 SkDELETE(toBeRemoved[i]); 376 SkDELETE(toBeRemoved[i]);
380 377
381 if (pictInfo->fPlotUsage.isEmpty()) { 378 GrPictureInfo* pictInfo = fPictureHash.find(pictureIDToRemove);
382 fPictureHash.remove(pictInfo->fPictureID); 379 if (pictInfo) {
383 SkDELETE(pictInfo); 380 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, plot);
381
382 if (pictInfo->fPlotUsage.isEmpty()) {
383 fPictureHash.remove(pictInfo->fPictureID);
384 SkDELETE(pictInfo);
385 }
384 } 386 }
385 } 387 }
386 388
387 plot->resetRects(); 389 plot->resetRects();
388 } 390 }
389 391
390 void GrLayerCache::purgeAll() { 392 void GrLayerCache::purgeAll() {
391 GrAtlas::PlotIter iter; 393 GrAtlas::PlotIter iter;
392 GrPlot* plot; 394 GrPlot* plot;
393 for (plot = fAtlas->iterInit(&iter, GrAtlas::kLRUFirst_IterOrder); 395 for (plot = fAtlas->iterInit(&iter, GrAtlas::kLRUFirst_IterOrder);
(...skipping 22 matching lines...) Expand all
416 418
417 void GrLayerCache::processDeletedPictures() { 419 void GrLayerCache::processDeletedPictures() {
418 SkTDArray<GrPictureDeletedMessage> deletedPictures; 420 SkTDArray<GrPictureDeletedMessage> deletedPictures;
419 fPictDeletionInbox.poll(&deletedPictures); 421 fPictDeletionInbox.poll(&deletedPictures);
420 422
421 for (int i = 0; i < deletedPictures.count(); i++) { 423 for (int i = 0; i < deletedPictures.count(); i++) {
422 this->purge(deletedPictures[i].pictureID); 424 this->purge(deletedPictures[i].pictureID);
423 } 425 }
424 } 426 }
425 427
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698