Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: src/gpu/GrLayerCache.cpp

Issue 769533004: Fuse GrReplacements and GrLayerCache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clang Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/GrLayerHoister.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
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& bounds,
127 const SkMatrix& initialMat, 127 const SkMatrix& initialMat,
128 const int* key, 128 const unsigned* key,
129 int keySize, 129 int keySize,
130 const SkPaint* paint) { 130 const SkPaint* paint) {
131 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); 131 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0);
132 132
133 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, bo unds, initialMat, 133 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, bo unds, initialMat,
134 key, keySize, paint)); 134 key, keySize, paint));
135 fLayerHash.add(layer); 135 fLayerHash.add(layer);
136 return layer; 136 return layer;
137 } 137 }
138 138
139 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, const SkMatrix& initi alMat, 139 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, const SkMatrix& initi alMat,
140 const int* key, int keySize) { 140 const unsigned* key, int keySize) {
141 SkASSERT(pictureID != SK_InvalidGenID); 141 SkASSERT(pictureID != SK_InvalidGenID);
142 return fLayerHash.find(GrCachedLayer::Key(pictureID, initialMat, key, keySiz e)); 142 return fLayerHash.find(GrCachedLayer::Key(pictureID, initialMat, key, keySiz e));
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& initialMat, 148 const SkMatrix& initialMat,
149 const int* key, 149 const unsigned* key,
150 int keySize, 150 int keySize,
151 const SkPaint* paint) { 151 const SkPaint* paint) {
152 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); 152 SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0);
153 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, initial Mat, key, keySize)); 153 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, initial Mat, key, keySize));
154 if (NULL == layer) { 154 if (NULL == layer) {
155 layer = this->createLayer(pictureID, start, stop, bounds, initialMat, ke y, keySize, paint); 155 layer = this->createLayer(pictureID, start, stop, bounds, initialMat, ke y, keySize, paint);
156 } 156 }
157 157
158 return layer; 158 return layer;
159 } 159 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 GrPlot* plot = fAtlas->addToAtlas(&pictInfo->fPlotUsage, 202 GrPlot* plot = fAtlas->addToAtlas(&pictInfo->fPlotUsage,
203 desc.fWidth, desc.fHeight, 203 desc.fWidth, desc.fHeight,
204 NULL, &loc); 204 NULL, &loc);
205 // addToAtlas can allocate the backing texture 205 // addToAtlas can allocate the backing texture
206 SkDEBUGCODE(avl.setBackingTexture(fAtlas->getTexture())); 206 SkDEBUGCODE(avl.setBackingTexture(fAtlas->getTexture()));
207 if (plot) { 207 if (plot) {
208 #if !GR_CACHE_HOISTED_LAYERS 208 #if !GR_CACHE_HOISTED_LAYERS
209 pictInfo->incPlotUsage(plot->id()); 209 pictInfo->incPlotUsage(plot->id());
210 #endif 210 #endif
211 // The layer was successfully added to the atlas 211 // The layer was successfully added to the atlas
212 GrIRect16 bounds = GrIRect16::MakeXYWH(loc.fX, loc.fY, 212 const SkIRect bounds = SkIRect::MakeXYWH(loc.fX, loc.fY,
213 SkToS16(desc.fWidth), 213 desc.fWidth, desc.fHeig ht);
214 SkToS16(desc.fHeight));
215 layer->setTexture(fAtlas->getTexture(), bounds); 214 layer->setTexture(fAtlas->getTexture(), bounds);
216 layer->setPlot(plot); 215 layer->setPlot(plot);
217 layer->setLocked(true); 216 layer->setLocked(true);
218 this->incPlotLock(layer->plot()->id()); 217 this->incPlotLock(layer->plot()->id());
219 *needsRendering = true; 218 *needsRendering = true;
220 return true; 219 return true;
221 } 220 }
222 221
223 // The layer was rejected by the atlas (even though we know it is 222 // The layer was rejected by the atlas (even though we know it is
224 // plausibly atlas-able). See if a plot can be purged and try again. 223 // plausibly atlas-able). See if a plot can be purged and try again.
(...skipping 18 matching lines...) Expand all
243 return true; 242 return true;
244 } 243 }
245 244
246 SkAutoTUnref<GrTexture> tex( 245 SkAutoTUnref<GrTexture> tex(
247 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); 246 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
248 247
249 if (!tex) { 248 if (!tex) {
250 return false; 249 return false;
251 } 250 }
252 251
253 layer->setTexture(tex, GrIRect16::MakeWH(SkToS16(desc.fWidth), SkToS16(desc. fHeight))); 252 layer->setTexture(tex, SkIRect::MakeWH(desc.fWidth, desc.fHeight));
254 layer->setLocked(true); 253 layer->setLocked(true);
255 *needsRendering = true; 254 *needsRendering = true;
256 return true; 255 return true;
257 } 256 }
258 257
259 void GrLayerCache::unlock(GrCachedLayer* layer) { 258 void GrLayerCache::unlock(GrCachedLayer* layer) {
260 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, la yer);) 259 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, la yer);)
261 260
262 if (NULL == layer || !layer->locked()) { 261 if (NULL == layer || !layer->locked()) {
263 // invalid or not locked 262 // invalid or not locked
(...skipping 18 matching lines...) Expand all
282 if (0 == pictInfo->plotUsage(plotID)) { 281 if (0 == pictInfo->plotUsage(plotID)) {
283 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot()); 282 GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot());
284 283
285 if (pictInfo->fPlotUsage.isEmpty()) { 284 if (pictInfo->fPlotUsage.isEmpty()) {
286 fPictureHash.remove(pictInfo->fPictureID); 285 fPictureHash.remove(pictInfo->fPictureID);
287 SkDELETE(pictInfo); 286 SkDELETE(pictInfo);
288 } 287 }
289 } 288 }
290 289
291 layer->setPlot(NULL); 290 layer->setPlot(NULL);
292 layer->setTexture(NULL, GrIRect16::MakeEmpty()); 291 layer->setTexture(NULL, SkIRect::MakeEmpty());
293 #endif 292 #endif
294 293
295 } else { 294 } else {
296 layer->setTexture(NULL, GrIRect16::MakeEmpty()); 295 layer->setTexture(NULL, SkIRect::MakeEmpty());
297 } 296 }
298 297
299 layer->setLocked(false); 298 layer->setLocked(false);
300 } 299 }
301 300
302 #ifdef SK_DEBUG 301 #ifdef SK_DEBUG
303 void GrLayerCache::validate() const { 302 void GrLayerCache::validate() const {
304 int plotLocks[kNumPlotsX * kNumPlotsY]; 303 int plotLocks[kNumPlotsX * kNumPlotsY];
305 memset(plotLocks, 0, sizeof(plotLocks)); 304 memset(plotLocks, 0, sizeof(plotLocks));
306 305
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 fileName.appendf("\\%d", layer->fKey.pictureID()); 494 fileName.appendf("\\%d", layer->fKey.pictureID());
496 for (int i = 0; i < layer->fKey.keySize(); ++i) { 495 for (int i = 0; i < layer->fKey.keySize(); ++i) {
497 fileName.appendf("-%d", layer->fKey.key()[i]); 496 fileName.appendf("-%d", layer->fKey.key()[i]);
498 } 497 }
499 fileName.appendf(".png"); 498 fileName.appendf(".png");
500 499
501 layer->texture()->surfacePriv().savePixels(fileName.c_str()); 500 layer->texture()->surfacePriv().savePixels(fileName.c_str());
502 } 501 }
503 } 502 }
504 #endif 503 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/GrLayerHoister.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698