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

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

Issue 1316123003: Style Change: SkNEW->new; SkDELETE->delete (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-26 (Wednesday) 15:59:00 EDT Created 5 years, 3 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/GrLayerHoister.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 "GrContext.h" 9 #include "GrContext.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 memset(fPlotLocks, 0, sizeof(fPlotLocks)); 83 memset(fPlotLocks, 0, sizeof(fPlotLocks));
84 } 84 }
85 85
86 GrLayerCache::~GrLayerCache() { 86 GrLayerCache::~GrLayerCache() {
87 87
88 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); 88 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
89 for (; !iter.done(); ++iter) { 89 for (; !iter.done(); ++iter) {
90 GrCachedLayer* layer = &(*iter); 90 GrCachedLayer* layer = &(*iter);
91 SkASSERT(0 == layer->uses()); 91 SkASSERT(0 == layer->uses());
92 this->unlock(layer); 92 this->unlock(layer);
93 SkDELETE(layer); 93 delete layer;
94 } 94 }
95 95
96 SkASSERT(0 == fPictureHash.count()); 96 SkASSERT(0 == fPictureHash.count());
97 97
98 // The atlas only lets go of its texture when the atlas is deleted. 98 // The atlas only lets go of its texture when the atlas is deleted.
99 fAtlas.free(); 99 fAtlas.free();
100 } 100 }
101 101
102 void GrLayerCache::initAtlas() { 102 void GrLayerCache::initAtlas() {
103 SkASSERT(NULL == fAtlas.get()); 103 SkASSERT(NULL == fAtlas.get());
104 GR_STATIC_ASSERT(kNumPlotsX*kNumPlotsX == GrPictureInfo::kNumPlots); 104 GR_STATIC_ASSERT(kNumPlotsX*kNumPlotsX == GrPictureInfo::kNumPlots);
105 105
106 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight) ; 106 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight) ;
107 fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfi g, 107 fAtlas.reset(new GrAtlas(fContext->getGpu(), kSkia8888_GrPixelConfig,
108 kRenderTarget_GrSurfaceFlag, 108 kRenderTarget_GrSurfaceFlag, textureSize, kNumPlots X, kNumPlotsY,
109 textureSize, kNumPlotsX, kNumPlotsY, false ))); 109 false));
110 } 110 }
111 111
112 void GrLayerCache::freeAll() { 112 void GrLayerCache::freeAll() {
113 113
114 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); 114 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
115 for (; !iter.done(); ++iter) { 115 for (; !iter.done(); ++iter) {
116 GrCachedLayer* layer = &(*iter); 116 GrCachedLayer* layer = &(*iter);
117 this->unlock(layer); 117 this->unlock(layer);
118 SkDELETE(layer); 118 delete layer;
119 } 119 }
120 fLayerHash.rewind(); 120 fLayerHash.rewind();
121 121
122 // The atlas only lets go of its texture when the atlas is deleted. 122 // The atlas only lets go of its texture when the atlas is deleted.
123 fAtlas.free(); 123 fAtlas.free();
124 } 124 }
125 125
126 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID, 126 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID,
127 int start, int stop, 127 int start, int stop,
128 const SkIRect& srcIR, 128 const SkIRect& srcIR,
129 const SkIRect& dstIR, 129 const SkIRect& dstIR,
130 const SkMatrix& initialMat, 130 const SkMatrix& initialMat,
131 const int* key, 131 const int* key,
132 int keySize, 132 int keySize,
133 const SkPaint* paint) { 133 const SkPaint* paint) {
134 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); 134 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0);
135 135
136 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, 136 GrCachedLayer* layer = new GrCachedLayer(pictureID, start, stop, srcIR, dstI R, initialMat, key,
137 srcIR, dstIR, initialMat, 137 keySize, paint);
138 key, keySize, paint));
139 fLayerHash.add(layer); 138 fLayerHash.add(layer);
140 return layer; 139 return layer;
141 } 140 }
142 141
143 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, const SkMatrix& initi alMat, 142 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, const SkMatrix& initi alMat,
144 const int* key, int keySize) { 143 const int* key, int keySize) {
145 SkASSERT(pictureID != SK_InvalidGenID); 144 SkASSERT(pictureID != SK_InvalidGenID);
146 return fLayerHash.find(GrCachedLayer::Key(pictureID, initialMat, key, keySiz e)); 145 return fLayerHash.find(GrCachedLayer::Key(pictureID, initialMat, key, keySiz e));
147 } 146 }
148 147
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } else { 192 } else {
194 if (!fAtlas) { 193 if (!fAtlas) {
195 this->initAtlas(); 194 this->initAtlas();
196 if (!fAtlas) { 195 if (!fAtlas) {
197 return false; 196 return false;
198 } 197 }
199 } 198 }
200 // Not in the atlas - will it fit? 199 // Not in the atlas - will it fit?
201 GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID()); 200 GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID());
202 if (NULL == pictInfo) { 201 if (NULL == pictInfo) {
203 pictInfo = SkNEW_ARGS(GrPictureInfo, (layer->pictureID())); 202 pictInfo = new GrPictureInfo(layer->pictureID());
204 fPictureHash.add(pictInfo); 203 fPictureHash.add(pictInfo);
205 } 204 }
206 205
207 SkIPoint16 loc; 206 SkIPoint16 loc;
208 for (int i = 0; i < 2; ++i) { // extra pass in case we fail to add but a re able to purge 207 for (int i = 0; i < 2; ++i) { // extra pass in case we fail to add but a re able to purge
209 GrPlot* plot = fAtlas->addToAtlas(&pictInfo->fPlotUsage, 208 GrPlot* plot = fAtlas->addToAtlas(&pictInfo->fPlotUsage,
210 desc.fWidth, desc.fHeight, 209 desc.fWidth, desc.fHeight,
211 NULL, &loc); 210 NULL, &loc);
212 // addToAtlas can allocate the backing texture 211 // addToAtlas can allocate the backing texture
213 SkDEBUGCODE(avl.setBackingTexture(fAtlas->getTexture())); 212 SkDEBUGCODE(avl.setBackingTexture(fAtlas->getTexture()));
(...skipping 14 matching lines...) Expand all
228 227
229 // The layer was rejected by the atlas (even though we know it is 228 // The layer was rejected by the atlas (even though we know it is
230 // plausibly atlas-able). See if a plot can be purged and try again. 229 // plausibly atlas-able). See if a plot can be purged and try again.
231 if (!this->purgePlot()) { 230 if (!this->purgePlot()) {
232 break; // We weren't able to purge any plots 231 break; // We weren't able to purge any plots
233 } 232 }
234 } 233 }
235 234
236 if (pictInfo->fPlotUsage.isEmpty()) { 235 if (pictInfo->fPlotUsage.isEmpty()) {
237 fPictureHash.remove(pictInfo->fPictureID); 236 fPictureHash.remove(pictInfo->fPictureID);
238 SkDELETE(pictInfo); 237 delete pictInfo;
239 } 238 }
240 } 239 }
241 240
242 return false; 241 return false;
243 } 242 }
244 243
245 bool GrLayerCache::lock(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* n eedsRendering) { 244 bool GrLayerCache::lock(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* n eedsRendering) {
246 if (layer->locked()) { 245 if (layer->locked()) {
247 // This layer is already locked 246 // This layer is already locked
248 *needsRendering = false; 247 *needsRendering = false;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID()); 287 GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID());
289 SkASSERT(pictInfo); 288 SkASSERT(pictInfo);
290 289
291 pictInfo->decPlotUsage(plotID); 290 pictInfo->decPlotUsage(plotID);
292 291
293 if (0 == pictInfo->plotUsage(plotID)) { 292 if (0 == pictInfo->plotUsage(plotID)) {
294 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot()); 293 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot());
295 294
296 if (pictInfo->fPlotUsage.isEmpty()) { 295 if (pictInfo->fPlotUsage.isEmpty()) {
297 fPictureHash.remove(pictInfo->fPictureID); 296 fPictureHash.remove(pictInfo->fPictureID);
298 SkDELETE(pictInfo); 297 delete pictInfo;
299 } 298 }
300 } 299 }
301 300
302 layer->setPlot(NULL); 301 layer->setPlot(NULL);
303 layer->setTexture(NULL, SkIRect::MakeEmpty()); 302 layer->setTexture(NULL, SkIRect::MakeEmpty());
304 #endif 303 #endif
305 304
306 } else { 305 } else {
307 layer->setTexture(NULL, SkIRect::MakeEmpty()); 306 layer->setTexture(NULL, SkIRect::MakeEmpty());
308 } 307 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 for (; !iter.done(); ++iter) { 372 for (; !iter.done(); ++iter) {
374 if (pictureID == (*iter).pictureID()) { 373 if (pictureID == (*iter).pictureID()) {
375 *toBeRemoved.append() = &(*iter); 374 *toBeRemoved.append() = &(*iter);
376 } 375 }
377 } 376 }
378 377
379 for (int i = 0; i < toBeRemoved.count(); ++i) { 378 for (int i = 0; i < toBeRemoved.count(); ++i) {
380 SkASSERT(0 == toBeRemoved[i]->uses()); 379 SkASSERT(0 == toBeRemoved[i]->uses());
381 this->unlock(toBeRemoved[i]); 380 this->unlock(toBeRemoved[i]);
382 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i])); 381 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i]));
383 SkDELETE(toBeRemoved[i]); 382 delete toBeRemoved[i];
384 } 383 }
385 384
386 GrPictureInfo* pictInfo = fPictureHash.find(pictureID); 385 GrPictureInfo* pictInfo = fPictureHash.find(pictureID);
387 if (pictInfo) { 386 if (pictInfo) {
388 fPictureHash.remove(pictureID); 387 fPictureHash.remove(pictureID);
389 SkDELETE(pictInfo); 388 delete pictInfo;
390 } 389 }
391 } 390 }
392 391
393 bool GrLayerCache::purgePlot() { 392 bool GrLayerCache::purgePlot() {
394 SkDEBUGCODE(GrAutoValidateCache avc(this);) 393 SkDEBUGCODE(GrAutoValidateCache avc(this);)
395 SkASSERT(fAtlas); 394 SkASSERT(fAtlas);
396 395
397 GrAtlas::PlotIter iter; 396 GrAtlas::PlotIter iter;
398 GrPlot* plot; 397 GrPlot* plot;
399 for (plot = fAtlas->iterInit(&iter, GrAtlas::kLRUFirst_IterOrder); 398 for (plot = fAtlas->iterInit(&iter, GrAtlas::kLRUFirst_IterOrder);
(...skipping 24 matching lines...) Expand all
424 } 423 }
425 424
426 for (int i = 0; i < toBeRemoved.count(); ++i) { 425 for (int i = 0; i < toBeRemoved.count(); ++i) {
427 SkASSERT(0 == toBeRemoved[i]->uses()); 426 SkASSERT(0 == toBeRemoved[i]->uses());
428 SkASSERT(!toBeRemoved[i]->locked()); 427 SkASSERT(!toBeRemoved[i]->locked());
429 428
430 uint32_t pictureIDToRemove = toBeRemoved[i]->pictureID(); 429 uint32_t pictureIDToRemove = toBeRemoved[i]->pictureID();
431 430
432 // Aggressively remove layers and, if it becomes totally uncached, delet e the picture info 431 // Aggressively remove layers and, if it becomes totally uncached, delet e the picture info
433 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i])); 432 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i]));
434 SkDELETE(toBeRemoved[i]); 433 delete toBeRemoved[i];
435 434
436 GrPictureInfo* pictInfo = fPictureHash.find(pictureIDToRemove); 435 GrPictureInfo* pictInfo = fPictureHash.find(pictureIDToRemove);
437 if (pictInfo) { 436 if (pictInfo) {
438 #if !GR_CACHE_HOISTED_LAYERS 437 #if !GR_CACHE_HOISTED_LAYERS
439 SkASSERT(0 == pictInfo->plotUsage(plot->id())); 438 SkASSERT(0 == pictInfo->plotUsage(plot->id()));
440 #endif 439 #endif
441 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, plot); 440 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, plot);
442 441
443 if (pictInfo->fPlotUsage.isEmpty()) { 442 if (pictInfo->fPlotUsage.isEmpty()) {
444 fPictureHash.remove(pictInfo->fPictureID); 443 fPictureHash.remove(pictInfo->fPictureID);
445 SkDELETE(pictInfo); 444 delete pictInfo;
446 } 445 }
447 } 446 }
448 } 447 }
449 448
450 plot->resetRects(); 449 plot->resetRects();
451 } 450 }
452 451
453 #if !GR_CACHE_HOISTED_LAYERS 452 #if !GR_CACHE_HOISTED_LAYERS
454 void GrLayerCache::purgeAll() { 453 void GrLayerCache::purgeAll() {
455 if (!fAtlas) { 454 if (!fAtlas) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 fileName.appendf("\\%d", layer->fKey.pictureID()); 509 fileName.appendf("\\%d", layer->fKey.pictureID());
511 for (int i = 0; i < layer->fKey.keySize(); ++i) { 510 for (int i = 0; i < layer->fKey.keySize(); ++i) {
512 fileName.appendf("-%d", layer->fKey.key()[i]); 511 fileName.appendf("-%d", layer->fKey.key()[i]);
513 } 512 }
514 fileName.appendf(".png"); 513 fileName.appendf(".png");
515 514
516 layer->texture()->surfacePriv().savePixels(fileName.c_str()); 515 layer->texture()->surfacePriv().savePixels(fileName.c_str());
517 } 516 }
518 } 517 }
519 #endif 518 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/GrLayerHoister.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698