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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 104 |
105 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight)
; | 105 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight)
; |
106 fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfi
g, | 106 fAtlas.reset(SkNEW_ARGS(GrAtlas, (fContext->getGpu(), kSkia8888_GrPixelConfi
g, |
107 kRenderTarget_GrTextureFlagBit, | 107 kRenderTarget_GrSurfaceFlag, |
108 textureSize, kNumPlotsX, kNumPlotsY, false
))); | 108 textureSize, kNumPlotsX, kNumPlotsY, false
))); |
109 } | 109 } |
110 | 110 |
111 void GrLayerCache::freeAll() { | 111 void GrLayerCache::freeAll() { |
112 | 112 |
113 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); | 113 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); |
114 for (; !iter.done(); ++iter) { | 114 for (; !iter.done(); ++iter) { |
115 GrCachedLayer* layer = &(*iter); | 115 GrCachedLayer* layer = &(*iter); |
116 this->unlock(layer); | 116 this->unlock(layer); |
117 SkDELETE(layer); | 117 SkDELETE(layer); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); | 155 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); |
156 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start,
bounds, ctm)); | 156 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start,
bounds, ctm)); |
157 if (NULL == layer) { | 157 if (NULL == layer) { |
158 layer = this->createLayer(pictureID, start, stop, bounds, ctm, paint); | 158 layer = this->createLayer(pictureID, start, stop, bounds, ctm, paint); |
159 } | 159 } |
160 | 160 |
161 return layer; | 161 return layer; |
162 } | 162 } |
163 | 163 |
164 bool GrLayerCache::tryToAtlas(GrCachedLayer* layer, | 164 bool GrLayerCache::tryToAtlas(GrCachedLayer* layer, |
165 const GrTextureDesc& desc, | 165 const GrSurfaceDesc& desc, |
166 bool* needsRendering) { | 166 bool* needsRendering) { |
167 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);) | 167 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);) |
168 | 168 |
169 SkASSERT(PlausiblyAtlasable(desc.fWidth, desc.fHeight)); | 169 SkASSERT(PlausiblyAtlasable(desc.fWidth, desc.fHeight)); |
170 | 170 |
171 if (layer->locked()) { | 171 if (layer->locked()) { |
172 // This layer is already locked | 172 // This layer is already locked |
173 SkASSERT(layer->isAtlased()); | 173 SkASSERT(layer->isAtlased()); |
174 SkASSERT(layer->rect().width() == desc.fWidth); | 174 SkASSERT(layer->rect().width() == desc.fWidth); |
175 SkASSERT(layer->rect().height() == desc.fHeight); | 175 SkASSERT(layer->rect().height() == desc.fHeight); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // plausibly atlas-able). See if a plot can be purged and try again. | 215 // plausibly atlas-able). See if a plot can be purged and try again. |
216 if (!this->purgePlot()) { | 216 if (!this->purgePlot()) { |
217 break; // We weren't able to purge any plots | 217 break; // We weren't able to purge any plots |
218 } | 218 } |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 return false; | 222 return false; |
223 } | 223 } |
224 | 224 |
225 bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool* n
eedsRendering) { | 225 bool GrLayerCache::lock(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* n
eedsRendering) { |
226 if (layer->locked()) { | 226 if (layer->locked()) { |
227 // This layer is already locked | 227 // This layer is already locked |
228 *needsRendering = false; | 228 *needsRendering = false; |
229 return true; | 229 return true; |
230 } | 230 } |
231 | 231 |
232 SkAutoTUnref<GrTexture> tex( | 232 SkAutoTUnref<GrTexture> tex( |
233 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); | 233 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); |
234 | 234 |
235 if (!tex) { | 235 if (!tex) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 continue; | 464 continue; |
465 } | 465 } |
466 | 466 |
467 SkString fileName(dirName); | 467 SkString fileName(dirName); |
468 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta
rt()); | 468 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta
rt()); |
469 | 469 |
470 layer->texture()->surfacePriv().savePixels(fileName.c_str()); | 470 layer->texture()->surfacePriv().savePixels(fileName.c_str()); |
471 } | 471 } |
472 } | 472 } |
473 #endif | 473 #endif |
OLD | NEW |