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