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" |
11 #include "GrSurfacePriv.h" | 11 #include "GrSurfacePriv.h" |
12 | 12 |
13 #ifdef SK_DEBUG | 13 #ifdef SK_DEBUG |
14 void GrCachedLayer::validate(const GrTexture* backingTexture) const { | 14 void GrCachedLayer::validate(const GrTexture* backingTexture) const { |
15 SkASSERT(SK_InvalidGenID != fKey.pictureID()); | 15 SkASSERT(SK_InvalidGenID != fKey.pictureID()); |
16 SkASSERT(fKey.start() >= 0); | |
17 | 16 |
18 if (fTexture) { | 17 if (fTexture) { |
19 // If the layer is in some texture then it must occupy some rectangle | 18 // If the layer is in some texture then it must occupy some rectangle |
20 SkASSERT(!fRect.isEmpty()); | 19 SkASSERT(!fRect.isEmpty()); |
21 if (!this->isAtlased()) { | 20 if (!this->isAtlased()) { |
22 // If it isn't atlased then the rectangle should start at the origin | 21 // If it isn't atlased then the rectangle should start at the origin |
23 SkASSERT(0.0f == fRect.fLeft && 0.0f == fRect.fTop); | 22 SkASSERT(0.0f == fRect.fLeft && 0.0f == fRect.fTop); |
24 } | 23 } |
25 } else { | 24 } else { |
26 SkASSERT(fRect.isEmpty()); | 25 SkASSERT(fRect.isEmpty()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 117 } |
119 fLayerHash.rewind(); | 118 fLayerHash.rewind(); |
120 | 119 |
121 // 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. |
122 fAtlas.free(); | 121 fAtlas.free(); |
123 } | 122 } |
124 | 123 |
125 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID, | 124 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID, |
126 int start, int stop, | 125 int start, int stop, |
127 const SkIRect& bounds, | 126 const SkIRect& bounds, |
128 const SkMatrix& ctm, | 127 const SkMatrix& initialMat, |
| 128 const int* key, |
| 129 int keySize, |
129 const SkPaint* paint) { | 130 const SkPaint* paint) { |
130 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); | 131 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); |
131 | 132 |
132 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, bo
unds, ctm, paint)); | 133 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, bo
unds, initialMat, |
| 134 key, keySize, paint)); |
133 fLayerHash.add(layer); | 135 fLayerHash.add(layer); |
134 return layer; | 136 return layer; |
135 } | 137 } |
136 | 138 |
137 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, | 139 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, const SkMatrix& initi
alMat, |
138 int start, | 140 const int* key, int keySize) { |
139 const SkIRect& bounds, | 141 SkASSERT(pictureID != SK_InvalidGenID); |
140 const SkMatrix& ctm) { | 142 return fLayerHash.find(GrCachedLayer::Key(pictureID, initialMat, key, keySiz
e)); |
141 SkASSERT(pictureID != SK_InvalidGenID && start > 0); | |
142 return fLayerHash.find(GrCachedLayer::Key(pictureID, start, bounds, ctm)); | |
143 } | 143 } |
144 | 144 |
145 GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID, | 145 GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID, |
146 int start, int stop, | 146 int start, int stop, |
147 const SkIRect& bounds, | 147 const SkIRect& bounds, |
148 const SkMatrix& ctm, | 148 const SkMatrix& initialMat, |
| 149 const int* key, |
| 150 int keySize, |
149 const SkPaint* paint) { | 151 const SkPaint* paint) { |
150 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); | 152 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); |
151 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start,
bounds, ctm)); | 153 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, initial
Mat, key, keySize)); |
152 if (NULL == layer) { | 154 if (NULL == layer) { |
153 layer = this->createLayer(pictureID, start, stop, bounds, ctm, paint); | 155 layer = this->createLayer(pictureID, start, stop, bounds, initialMat, ke
y, keySize, paint); |
154 } | 156 } |
155 | 157 |
156 return layer; | 158 return layer; |
157 } | 159 } |
158 | 160 |
159 bool GrLayerCache::tryToAtlas(GrCachedLayer* layer, | 161 bool GrLayerCache::tryToAtlas(GrCachedLayer* layer, |
160 const GrSurfaceDesc& desc, | 162 const GrSurfaceDesc& desc, |
161 bool* needsRendering) { | 163 bool* needsRendering) { |
162 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, la
yer);) | 164 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, la
yer);) |
163 | 165 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 | 480 |
479 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); | 481 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); |
480 for (; !iter.done(); ++iter) { | 482 for (; !iter.done(); ++iter) { |
481 GrCachedLayer* layer = &(*iter); | 483 GrCachedLayer* layer = &(*iter); |
482 | 484 |
483 if (layer->isAtlased() || !layer->texture()) { | 485 if (layer->isAtlased() || !layer->texture()) { |
484 continue; | 486 continue; |
485 } | 487 } |
486 | 488 |
487 SkString fileName(dirName); | 489 SkString fileName(dirName); |
488 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta
rt()); | 490 fileName.appendf("\\%d", layer->fKey.pictureID()); |
| 491 for (int i = 0; i < layer->fKey.keySize(); ++i) { |
| 492 fileName.appendf("-%d", layer->fKey.key()[i]); |
| 493 } |
| 494 fileName.appendf(".png"); |
489 | 495 |
490 layer->texture()->surfacePriv().savePixels(fileName.c_str()); | 496 layer->texture()->surfacePriv().savePixels(fileName.c_str()); |
491 } | 497 } |
492 } | 498 } |
493 #endif | 499 #endif |
OLD | NEW |