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

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

Issue 1130283004: Revert of Sketch splitting SkPicture into an interface and SkBigPicture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months 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/core/SkRecords.h ('k') | src/gpu/GrRecordReplaceDraw.cpp » ('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 "GrLayerCache.h" 8 #include "GrLayerCache.h"
9 #include "GrLayerHoister.h" 9 #include "GrLayerHoister.h"
10 #include "GrRecordReplaceDraw.h" 10 #include "GrRecordReplaceDraw.h"
11 11
12 #include "SkBigPicture.h"
13 #include "SkCanvas.h" 12 #include "SkCanvas.h"
14 #include "SkDeviceImageFilterProxy.h" 13 #include "SkDeviceImageFilterProxy.h"
15 #include "SkDeviceProperties.h" 14 #include "SkDeviceProperties.h"
16 #include "SkGpuDevice.h" 15 #include "SkGpuDevice.h"
17 #include "SkGrPixelRef.h" 16 #include "SkGrPixelRef.h"
18 #include "SkLayerInfo.h" 17 #include "SkLayerInfo.h"
19 #include "SkRecordDraw.h" 18 #include "SkRecordDraw.h"
20 #include "SkSurface.h" 19 #include "SkSurface.h"
21 #include "SkSurface_Gpu.h" 20 #include "SkSurface_Gpu.h"
22 21
23 // Create the layer information for the hoisted layer and secure the 22 // Create the layer information for the hoisted layer and secure the
24 // required texture/render target resources. 23 // required texture/render target resources.
25 static void prepare_for_hoisting(GrLayerCache* layerCache, 24 static void prepare_for_hoisting(GrLayerCache* layerCache,
26 const SkPicture* topLevelPicture, 25 const SkPicture* topLevelPicture,
27 const SkMatrix& initialMat, 26 const SkMatrix& initialMat,
28 const SkLayerInfo::BlockInfo& info, 27 const SkLayerInfo::BlockInfo& info,
29 const SkIRect& srcIR, 28 const SkIRect& srcIR,
30 const SkIRect& dstIR, 29 const SkIRect& dstIR,
31 SkTDArray<GrHoistedLayer>* needRendering, 30 SkTDArray<GrHoistedLayer>* needRendering,
32 SkTDArray<GrHoistedLayer>* recycled, 31 SkTDArray<GrHoistedLayer>* recycled,
33 bool attemptToAtlas, 32 bool attemptToAtlas,
34 int numSamples) { 33 int numSamples) {
35 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture; 34 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 GrHoistedLayer* hl; 67 GrHoistedLayer* hl;
69 68
70 if (needsRendering) { 69 if (needsRendering) {
71 if (!attemptToAtlas) { 70 if (!attemptToAtlas) {
72 SkASSERT(!layer->isAtlased()); 71 SkASSERT(!layer->isAtlased());
73 } 72 }
74 hl = needRendering->append(); 73 hl = needRendering->append();
75 } else { 74 } else {
76 hl = recycled->append(); 75 hl = recycled->append();
77 } 76 }
78 77
79 layerCache->addUse(layer); 78 layerCache->addUse(layer);
80 hl->fLayer = layer; 79 hl->fLayer = layer;
81 hl->fPicture = pict; 80 hl->fPicture = pict;
82 hl->fLocalMat = info.fLocalMat; 81 hl->fLocalMat = info.fLocalMat;
83 hl->fInitialMat = initialMat; 82 hl->fInitialMat = initialMat;
84 hl->fPreMat = initialMat; 83 hl->fPreMat = initialMat;
85 hl->fPreMat.preConcat(info.fPreMat); 84 hl->fPreMat.preConcat(info.fPreMat);
86 } 85 }
87 86
88 // Compute the source rect and return false if it is empty. 87 // Compute the source rect and return false if it is empty.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 const SkRect& query, 122 const SkRect& query,
124 SkTDArray<GrHoistedLayer>* atlased, 123 SkTDArray<GrHoistedLayer>* atlased,
125 SkTDArray<GrHoistedLayer>* recycled, 124 SkTDArray<GrHoistedLayer>* recycled,
126 int numSamples) { 125 int numSamples) {
127 if (0 != numSamples) { 126 if (0 != numSamples) {
128 // MSAA layers are currently never atlased 127 // MSAA layers are currently never atlased
129 return; 128 return;
130 } 129 }
131 130
132 GrLayerCache* layerCache = context->getLayerCache(); 131 GrLayerCache* layerCache = context->getLayerCache();
132
133 layerCache->processDeletedPictures(); 133 layerCache->processDeletedPictures();
134 134
135 const SkBigPicture::AccelData* topLevelData = NULL; 135 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
136 if (const SkBigPicture* bp = topLevelPicture->asSkBigPicture()) { 136
137 topLevelData = bp->accelData(); 137 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get AccelData(key);
138 }
139 if (!topLevelData) { 138 if (!topLevelData) {
140 return; 139 return;
141 } 140 }
142 141
143 const SkLayerInfo *topLevelGPUData = static_cast<const SkLayerInfo*>(topLeve lData); 142 const SkLayerInfo *topLevelGPUData = static_cast<const SkLayerInfo*>(topLeve lData);
144 if (0 == topLevelGPUData->numBlocks()) { 143 if (0 == topLevelGPUData->numBlocks()) {
145 return; 144 return;
146 } 145 }
147 146
148 atlased->setReserve(atlased->count() + topLevelGPUData->numBlocks()); 147 atlased->setReserve(atlased->count() + topLevelGPUData->numBlocks());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 const SkPicture* topLevelPicture, 182 const SkPicture* topLevelPicture,
184 const SkMatrix& initialMat, 183 const SkMatrix& initialMat,
185 const SkRect& query, 184 const SkRect& query,
186 SkTDArray<GrHoistedLayer>* needRendering, 185 SkTDArray<GrHoistedLayer>* needRendering,
187 SkTDArray<GrHoistedLayer>* recycled, 186 SkTDArray<GrHoistedLayer>* recycled,
188 int numSamples) { 187 int numSamples) {
189 GrLayerCache* layerCache = context->getLayerCache(); 188 GrLayerCache* layerCache = context->getLayerCache();
190 189
191 layerCache->processDeletedPictures(); 190 layerCache->processDeletedPictures();
192 191
193 const SkBigPicture::AccelData* topLevelData = NULL; 192 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
194 if (const SkBigPicture* bp = topLevelPicture->asSkBigPicture()) { 193
195 topLevelData = bp->accelData(); 194 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get AccelData(key);
196 }
197 if (!topLevelData) { 195 if (!topLevelData) {
198 return; 196 return;
199 } 197 }
200 198
201 const SkLayerInfo *topLevelGPUData = static_cast<const SkLayerInfo*>(topLeve lData); 199 const SkLayerInfo *topLevelGPUData = static_cast<const SkLayerInfo*>(topLeve lData);
202 if (0 == topLevelGPUData->numBlocks()) { 200 if (0 == topLevelGPUData->numBlocks()) {
203 return; 201 return;
204 } 202 }
205 203
206 // Find and prepare for hoisting all the layers that intersect the query rec t 204 // Find and prepare for hoisting all the layers that intersect the query rec t
(...skipping 27 matching lines...) Expand all
234 if (atlased.count() > 0) { 232 if (atlased.count() > 0) {
235 // All the atlased layers are rendered into the same GrTexture 233 // All the atlased layers are rendered into the same GrTexture
236 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); 234 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
237 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( 235 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(
238 atlased[0].fLayer->texture()->asRenderTa rget(), &props)); 236 atlased[0].fLayer->texture()->asRenderTa rget(), &props));
239 237
240 SkCanvas* atlasCanvas = surface->getCanvas(); 238 SkCanvas* atlasCanvas = surface->getCanvas();
241 239
242 for (int i = 0; i < atlased.count(); ++i) { 240 for (int i = 0; i < atlased.count(); ++i) {
243 const GrCachedLayer* layer = atlased[i].fLayer; 241 const GrCachedLayer* layer = atlased[i].fLayer;
244 const SkBigPicture* pict = atlased[i].fPicture->asSkBigPicture(); 242 const SkPicture* pict = atlased[i].fPicture;
245 if (!pict) {
246 // TODO: can we assume / assert this?
247 continue;
248 }
249 const SkIPoint offset = SkIPoint::Make(layer->srcIR().fLeft, layer-> srcIR().fTop); 243 const SkIPoint offset = SkIPoint::Make(layer->srcIR().fLeft, layer-> srcIR().fTop);
250 SkDEBUGCODE(const SkPaint* layerPaint = layer->paint();) 244 SkDEBUGCODE(const SkPaint* layerPaint = layer->paint();)
251 245
252 SkASSERT(!layerPaint || !layerPaint->getImageFilter()); 246 SkASSERT(!layerPaint || !layerPaint->getImageFilter());
253 SkASSERT(!layer->filter()); 247 SkASSERT(!layer->filter());
254 248
255 atlasCanvas->save(); 249 atlasCanvas->save();
256 250
257 // Add a rect clip to make sure the rendering doesn't 251 // Add a rect clip to make sure the rendering doesn't
258 // extend beyond the boundaries of the atlased sub-rect 252 // extend beyond the boundaries of the atlased sub-rect
259 const SkRect bound = SkRect::Make(layer->rect()); 253 const SkRect bound = SkRect::Make(layer->rect());
260 atlasCanvas->clipRect(bound); 254 atlasCanvas->clipRect(bound);
261 atlasCanvas->clear(0); 255 atlasCanvas->clear(0);
262 256
263 // '-offset' maps the layer's top/left to the origin. 257 // '-offset' maps the layer's top/left to the origin.
264 // Since this layer is atlased, the top/left corner needs 258 // Since this layer is atlased, the top/left corner needs
265 // to be offset to the correct location in the backing texture. 259 // to be offset to the correct location in the backing texture.
266 SkMatrix initialCTM; 260 SkMatrix initialCTM;
267 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-of fset.fY)); 261 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-of fset.fY));
268 initialCTM.preTranslate(bound.fLeft, bound.fTop); 262 initialCTM.preTranslate(bound.fLeft, bound.fTop);
269 initialCTM.preConcat(atlased[i].fPreMat); 263 initialCTM.preConcat(atlased[i].fPreMat);
270 264
271 atlasCanvas->setMatrix(initialCTM); 265 atlasCanvas->setMatrix(initialCTM);
272 atlasCanvas->concat(atlased[i].fLocalMat); 266 atlasCanvas->concat(atlased[i].fLocalMat);
273 267
274 pict->partialPlayback(atlasCanvas, layer->start() + 1, layer->stop() , initialCTM); 268 SkRecordPartialDraw(*pict->fRecord.get(), atlasCanvas,
269 pict->drawablePicts(), pict->drawableCount(),
270 layer->start() + 1, layer->stop(), initialCTM);
271
275 atlasCanvas->restore(); 272 atlasCanvas->restore();
276 } 273 }
277 274
278 atlasCanvas->flush(); 275 atlasCanvas->flush();
279 } 276 }
280 } 277 }
281 278
282 SkBitmap wrap_texture(GrTexture* texture) { 279 SkBitmap wrap_texture(GrTexture* texture) {
283 SkASSERT(texture); 280 SkASSERT(texture);
284 281
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 321 }
325 322
326 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.hei ght()); 323 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.hei ght());
327 layer->setTexture(filteredBitmap.getTexture(), newRect); 324 layer->setTexture(filteredBitmap.getTexture(), newRect);
328 layer->setOffset(offset); 325 layer->setOffset(offset);
329 } 326 }
330 327
331 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay er>& layers) { 328 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay er>& layers) {
332 for (int i = 0; i < layers.count(); ++i) { 329 for (int i = 0; i < layers.count(); ++i) {
333 GrCachedLayer* layer = layers[i].fLayer; 330 GrCachedLayer* layer = layers[i].fLayer;
334 const SkBigPicture* pict = layers[i].fPicture->asSkBigPicture(); 331 const SkPicture* pict = layers[i].fPicture;
335 if (!pict) {
336 // TODO: can we assume / assert this?
337 continue;
338 }
339 const SkIPoint offset = SkIPoint::Make(layer->srcIR().fLeft, layer->srcI R().fTop); 332 const SkIPoint offset = SkIPoint::Make(layer->srcIR().fLeft, layer->srcI R().fTop);
340 333
341 // Each non-atlased layer has its own GrTexture 334 // Each non-atlased layer has its own GrTexture
342 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); 335 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
343 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( 336 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(
344 layer->texture()->asRenderTarget(), &pro ps)); 337 layer->texture()->asRenderTarget(), &pro ps));
345 338
346 SkCanvas* layerCanvas = surface->getCanvas(); 339 SkCanvas* layerCanvas = surface->getCanvas();
347 340
348 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); 341 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop);
349 342
350 // Add a rect clip to make sure the rendering doesn't 343 // Add a rect clip to make sure the rendering doesn't
351 // extend beyond the boundaries of the layer 344 // extend beyond the boundaries of the layer
352 const SkRect bound = SkRect::Make(layer->rect()); 345 const SkRect bound = SkRect::Make(layer->rect());
353 layerCanvas->clipRect(bound); 346 layerCanvas->clipRect(bound);
354 layerCanvas->clear(SK_ColorTRANSPARENT); 347 layerCanvas->clear(SK_ColorTRANSPARENT);
355 348
356 SkMatrix initialCTM; 349 SkMatrix initialCTM;
357 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-offset .fY)); 350 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-offset .fY));
358 initialCTM.preConcat(layers[i].fPreMat); 351 initialCTM.preConcat(layers[i].fPreMat);
359 352
360 layerCanvas->setMatrix(initialCTM); 353 layerCanvas->setMatrix(initialCTM);
361 layerCanvas->concat(layers[i].fLocalMat); 354 layerCanvas->concat(layers[i].fLocalMat);
362 355
363 pict->partialPlayback(layerCanvas, layer->start()+1, layer->stop(), init ialCTM); 356 SkRecordPartialDraw(*pict->fRecord.get(), layerCanvas,
357 pict->drawablePicts(), pict->drawableCount(),
358 layer->start()+1, layer->stop(), initialCTM);
359
364 layerCanvas->flush(); 360 layerCanvas->flush();
365 361
366 if (layer->filter()) { 362 if (layer->filter()) {
367 SkSurface_Gpu* gpuSurf = static_cast<SkSurface_Gpu*>(surface.get()); 363 SkSurface_Gpu* gpuSurf = static_cast<SkSurface_Gpu*>(surface.get());
368 364
369 FilterLayer(context, gpuSurf->getDevice(), layers[i]); 365 FilterLayer(context, gpuSurf->getDevice(), layers[i]);
370 } 366 }
371 } 367 }
372 } 368 }
373 369
(...skipping 11 matching lines...) Expand all
385 void GrLayerHoister::PurgeCache(GrContext* context) { 381 void GrLayerHoister::PurgeCache(GrContext* context) {
386 #if !GR_CACHE_HOISTED_LAYERS 382 #if !GR_CACHE_HOISTED_LAYERS
387 GrLayerCache* layerCache = context->getLayerCache(); 383 GrLayerCache* layerCache = context->getLayerCache();
388 384
389 // This code completely clears out the atlas. It is required when 385 // This code completely clears out the atlas. It is required when
390 // caching is disabled so the atlas doesn't fill up and force more 386 // caching is disabled so the atlas doesn't fill up and force more
391 // free floating layers 387 // free floating layers
392 layerCache->purgeAll(); 388 layerCache->purgeAll();
393 #endif 389 #endif
394 } 390 }
OLDNEW
« no previous file with comments | « src/core/SkRecords.h ('k') | src/gpu/GrRecordReplaceDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698