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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 SkDELETE(layer); | 116 SkDELETE(layer); |
117 } | 117 } |
118 fLayerHash.rewind(); | 118 fLayerHash.rewind(); |
119 | 119 |
120 // The atlas only lets go of its texture when the atlas is deleted. | 120 // The atlas only lets go of its texture when the atlas is deleted. |
121 fAtlas.free(); | 121 fAtlas.free(); |
122 } | 122 } |
123 | 123 |
124 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID, | 124 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID, |
125 int start, int stop, | 125 int start, int stop, |
126 const SkIRect& bounds, | 126 const SkIRect& srcIR, |
| 127 const SkIRect& dstIR, |
127 const SkMatrix& initialMat, | 128 const SkMatrix& initialMat, |
128 const unsigned* key, | 129 const unsigned* key, |
129 int keySize, | 130 int keySize, |
130 const SkPaint* paint) { | 131 const SkPaint* paint) { |
131 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); | 132 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); |
132 | 133 |
133 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, bo
unds, initialMat, | 134 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, |
| 135 srcIR, dstIR, initialMat, |
134 key, keySize, paint)); | 136 key, keySize, paint)); |
135 fLayerHash.add(layer); | 137 fLayerHash.add(layer); |
136 return layer; | 138 return layer; |
137 } | 139 } |
138 | 140 |
139 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, const SkMatrix& initi
alMat, | 141 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, const SkMatrix& initi
alMat, |
140 const unsigned* key, int keySize) { | 142 const unsigned* key, int keySize) { |
141 SkASSERT(pictureID != SK_InvalidGenID); | 143 SkASSERT(pictureID != SK_InvalidGenID); |
142 return fLayerHash.find(GrCachedLayer::Key(pictureID, initialMat, key, keySiz
e)); | 144 return fLayerHash.find(GrCachedLayer::Key(pictureID, initialMat, key, keySiz
e)); |
143 } | 145 } |
144 | 146 |
145 GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID, | 147 GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID, |
146 int start, int stop, | 148 int start, int stop, |
147 const SkIRect& bounds, | 149 const SkIRect& srcIR, |
| 150 const SkIRect& dstIR, |
148 const SkMatrix& initialMat, | 151 const SkMatrix& initialMat, |
149 const unsigned* key, | 152 const unsigned* key, |
150 int keySize, | 153 int keySize, |
151 const SkPaint* paint) { | 154 const SkPaint* paint) { |
152 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); | 155 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); |
153 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, initial
Mat, key, keySize)); | 156 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, initial
Mat, key, keySize)); |
154 if (NULL == layer) { | 157 if (NULL == layer) { |
155 layer = this->createLayer(pictureID, start, stop, bounds, initialMat, ke
y, keySize, paint); | 158 layer = this->createLayer(pictureID, start, stop, |
| 159 srcIR, dstIR, initialMat, |
| 160 key, keySize, paint); |
156 } | 161 } |
157 | 162 |
158 return layer; | 163 return layer; |
159 } | 164 } |
160 | 165 |
161 bool GrLayerCache::tryToAtlas(GrCachedLayer* layer, | 166 bool GrLayerCache::tryToAtlas(GrCachedLayer* layer, |
162 const GrSurfaceDesc& desc, | 167 const GrSurfaceDesc& desc, |
163 bool* needsRendering) { | 168 bool* needsRendering) { |
164 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, la
yer);) | 169 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, la
yer);) |
165 | 170 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 return false; | 240 return false; |
236 } | 241 } |
237 | 242 |
238 bool GrLayerCache::lock(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* n
eedsRendering) { | 243 bool GrLayerCache::lock(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* n
eedsRendering) { |
239 if (layer->locked()) { | 244 if (layer->locked()) { |
240 // This layer is already locked | 245 // This layer is already locked |
241 *needsRendering = false; | 246 *needsRendering = false; |
242 return true; | 247 return true; |
243 } | 248 } |
244 | 249 |
| 250 // TODO: make the test for exact match depend on the image filters themselve
s |
| 251 GrContext::ScratchTexMatch usage = GrContext::kApprox_ScratchTexMatch; |
| 252 if (layer->fFilter) { |
| 253 usage = GrContext::kExact_ScratchTexMatch; |
| 254 } |
| 255 |
245 SkAutoTUnref<GrTexture> tex( | 256 SkAutoTUnref<GrTexture> tex( |
246 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); | 257 fContext->refScratchTexture(desc, usage)); |
247 | 258 |
248 if (!tex) { | 259 if (!tex) { |
249 return false; | 260 return false; |
250 } | 261 } |
251 | 262 |
252 layer->setTexture(tex, SkIRect::MakeWH(desc.fWidth, desc.fHeight)); | 263 layer->setTexture(tex, SkIRect::MakeWH(desc.fWidth, desc.fHeight)); |
253 layer->setLocked(true); | 264 layer->setLocked(true); |
254 *needsRendering = true; | 265 *needsRendering = true; |
255 return true; | 266 return true; |
256 } | 267 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 fileName.appendf("\\%d", layer->fKey.pictureID()); | 505 fileName.appendf("\\%d", layer->fKey.pictureID()); |
495 for (int i = 0; i < layer->fKey.keySize(); ++i) { | 506 for (int i = 0; i < layer->fKey.keySize(); ++i) { |
496 fileName.appendf("-%d", layer->fKey.key()[i]); | 507 fileName.appendf("-%d", layer->fKey.key()[i]); |
497 } | 508 } |
498 fileName.appendf(".png"); | 509 fileName.appendf(".png"); |
499 | 510 |
500 layer->texture()->surfacePriv().savePixels(fileName.c_str()); | 511 layer->texture()->surfacePriv().savePixels(fileName.c_str()); |
501 } | 512 } |
502 } | 513 } |
503 #endif | 514 #endif |
OLD | NEW |