OLD | NEW |
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" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 this->unlock(layer); | 93 this->unlock(layer); |
94 SkDELETE(layer); | 94 SkDELETE(layer); |
95 } | 95 } |
96 | 96 |
97 // 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. |
98 fAtlas.free(); | 98 fAtlas.free(); |
99 } | 99 } |
100 | 100 |
101 void GrLayerCache::initAtlas() { | 101 void GrLayerCache::initAtlas() { |
102 SkASSERT(NULL == fAtlas.get()); | 102 SkASSERT(NULL == fAtlas.get()); |
| 103 GR_STATIC_ASSERT(kNumPlotsX*kNumPlotsX == GrPictureInfo::kNumPlots); |
103 | 104 |
104 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight)
; | 105 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight)
; |
105 fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfi
g, | 106 fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfi
g, |
106 kRenderTarget_GrSurfaceFlag, | 107 kRenderTarget_GrSurfaceFlag, |
107 textureSize, kNumPlotsX, kNumPlotsY, false
))); | 108 textureSize, kNumPlotsX, kNumPlotsY, false
))); |
108 } | 109 } |
109 | 110 |
110 void GrLayerCache::freeAll() { | 111 void GrLayerCache::freeAll() { |
111 | 112 |
112 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); | 113 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 195 } |
195 | 196 |
196 SkIPoint16 loc; | 197 SkIPoint16 loc; |
197 for (int i = 0; i < 2; ++i) { // extra pass in case we fail to add but a
re able to purge | 198 for (int i = 0; i < 2; ++i) { // extra pass in case we fail to add but a
re able to purge |
198 GrPlot* plot = fAtlas->addToAtlas(&pictInfo->fPlotUsage, | 199 GrPlot* plot = fAtlas->addToAtlas(&pictInfo->fPlotUsage, |
199 desc.fWidth, desc.fHeight, | 200 desc.fWidth, desc.fHeight, |
200 NULL, &loc); | 201 NULL, &loc); |
201 // addToAtlas can allocate the backing texture | 202 // addToAtlas can allocate the backing texture |
202 SkDEBUGCODE(avl.setBackingTexture(fAtlas->getTexture())); | 203 SkDEBUGCODE(avl.setBackingTexture(fAtlas->getTexture())); |
203 if (plot) { | 204 if (plot) { |
| 205 #if !GR_CACHE_HOISTED_LAYERS |
| 206 pictInfo->incPlotUsage(plot->id()); |
| 207 #endif |
204 // The layer was successfully added to the atlas | 208 // The layer was successfully added to the atlas |
205 GrIRect16 bounds = GrIRect16::MakeXYWH(loc.fX, loc.fY, | 209 GrIRect16 bounds = GrIRect16::MakeXYWH(loc.fX, loc.fY, |
206 SkToS16(desc.fWidth), | 210 SkToS16(desc.fWidth), |
207 SkToS16(desc.fHeight)); | 211 SkToS16(desc.fHeight)); |
208 layer->setTexture(fAtlas->getTexture(), bounds); | 212 layer->setTexture(fAtlas->getTexture(), bounds); |
209 layer->setPlot(plot); | 213 layer->setPlot(plot); |
210 layer->setLocked(true); | 214 layer->setLocked(true); |
211 this->incPlotLock(layer->plot()->id()); | 215 this->incPlotLock(layer->plot()->id()); |
212 *needsRendering = true; | 216 *needsRendering = true; |
213 return true; | 217 return true; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 261 |
258 this->decPlotLock(plotID); | 262 this->decPlotLock(plotID); |
259 // At this point we could aggressively clear out un-locked plots but | 263 // At this point we could aggressively clear out un-locked plots but |
260 // by delaying we may be able to reuse some of the atlased layers later. | 264 // by delaying we may be able to reuse some of the atlased layers later. |
261 #if !GR_CACHE_HOISTED_LAYERS | 265 #if !GR_CACHE_HOISTED_LAYERS |
262 // This testing code aggressively removes the atlased layers. This | 266 // This testing code aggressively removes the atlased layers. This |
263 // can be used to separate the performance contribution of less | 267 // can be used to separate the performance contribution of less |
264 // render target pingponging from that due to the re-use of cached layer
s | 268 // render target pingponging from that due to the re-use of cached layer
s |
265 GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID()); | 269 GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID()); |
266 SkASSERT(pictInfo); | 270 SkASSERT(pictInfo); |
267 | 271 |
268 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot()); | 272 pictInfo->decPlotUsage(plotID); |
| 273 |
| 274 if (0 == pictInfo->plotUsage(plotID)) { |
| 275 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot()); |
| 276 } |
269 | 277 |
270 layer->setPlot(NULL); | 278 layer->setPlot(NULL); |
271 layer->setTexture(NULL, GrIRect16::MakeEmpty()); | 279 layer->setTexture(NULL, GrIRect16::MakeEmpty()); |
272 #endif | 280 #endif |
273 | 281 |
274 } else { | 282 } else { |
275 layer->setTexture(NULL, GrIRect16::MakeEmpty()); | 283 layer->setTexture(NULL, GrIRect16::MakeEmpty()); |
276 } | 284 } |
277 | 285 |
278 layer->setLocked(false); | 286 layer->setLocked(false); |
(...skipping 15 matching lines...) Expand all Loading... |
294 // If there is no picture info for this picture then all of its | 302 // If there is no picture info for this picture then all of its |
295 // layers should be non-atlased. | 303 // layers should be non-atlased. |
296 SkASSERT(!layer->isAtlased()); | 304 SkASSERT(!layer->isAtlased()); |
297 } | 305 } |
298 | 306 |
299 if (layer->plot()) { | 307 if (layer->plot()) { |
300 SkASSERT(pictInfo); | 308 SkASSERT(pictInfo); |
301 SkASSERT(pictInfo->fPictureID == layer->pictureID()); | 309 SkASSERT(pictInfo->fPictureID == layer->pictureID()); |
302 | 310 |
303 SkASSERT(pictInfo->fPlotUsage.contains(layer->plot())); | 311 SkASSERT(pictInfo->fPlotUsage.contains(layer->plot())); |
| 312 #if !GR_CACHE_HOISTED_LAYERS |
| 313 SkASSERT(pictInfo->plotUsage(layer->plot()->id()) > 0); |
| 314 #endif |
304 | 315 |
305 if (layer->locked()) { | 316 if (layer->locked()) { |
306 plotLocks[layer->plot()->id()]++; | 317 plotLocks[layer->plot()->id()]++; |
307 } | 318 } |
308 } | 319 } |
309 } | 320 } |
310 | 321 |
311 for (int i = 0; i < kNumPlotsX*kNumPlotsY; ++i) { | 322 for (int i = 0; i < kNumPlotsX*kNumPlotsY; ++i) { |
312 SkASSERT(plotLocks[i] == fPlotLocks[i]); | 323 SkASSERT(plotLocks[i] == fPlotLocks[i]); |
313 } | 324 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 SkASSERT(!toBeRemoved[i]->locked()); | 404 SkASSERT(!toBeRemoved[i]->locked()); |
394 | 405 |
395 uint32_t pictureIDToRemove = toBeRemoved[i]->pictureID(); | 406 uint32_t pictureIDToRemove = toBeRemoved[i]->pictureID(); |
396 | 407 |
397 // Aggressively remove layers and, if it becomes totally uncached, delet
e the picture info | 408 // Aggressively remove layers and, if it becomes totally uncached, delet
e the picture info |
398 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i])); | 409 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i])); |
399 SkDELETE(toBeRemoved[i]); | 410 SkDELETE(toBeRemoved[i]); |
400 | 411 |
401 GrPictureInfo* pictInfo = fPictureHash.find(pictureIDToRemove); | 412 GrPictureInfo* pictInfo = fPictureHash.find(pictureIDToRemove); |
402 if (pictInfo) { | 413 if (pictInfo) { |
| 414 #if !GR_CACHE_HOISTED_LAYERS |
| 415 SkASSERT(0 == pictInfo->plotUsage(plot->id())); |
| 416 #endif |
403 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, plot); | 417 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, plot); |
404 | 418 |
405 if (pictInfo->fPlotUsage.isEmpty()) { | 419 if (pictInfo->fPlotUsage.isEmpty()) { |
406 fPictureHash.remove(pictInfo->fPictureID); | 420 fPictureHash.remove(pictInfo->fPictureID); |
407 SkDELETE(pictInfo); | 421 SkDELETE(pictInfo); |
408 } | 422 } |
409 } | 423 } |
410 } | 424 } |
411 | 425 |
412 plot->resetRects(); | 426 plot->resetRects(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 continue; | 491 continue; |
478 } | 492 } |
479 | 493 |
480 SkString fileName(dirName); | 494 SkString fileName(dirName); |
481 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta
rt()); | 495 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta
rt()); |
482 | 496 |
483 layer->texture()->surfacePriv().savePixels(fileName.c_str()); | 497 layer->texture()->surfacePriv().savePixels(fileName.c_str()); |
484 } | 498 } |
485 } | 499 } |
486 #endif | 500 #endif |
OLD | NEW |