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

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

Issue 842323003: Switch to a more complete method of filtering hoisted layers (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix oversight w.r.t. SkPictureImageFilters Created 5 years, 11 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/gpu/GrLayerCache.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 "SkCanvas.h" 12 #include "SkCanvas.h"
13 #include "SkDeviceImageFilterProxy.h"
14 #include "SkDeviceProperties.h"
13 #include "SkGpuDevice.h" 15 #include "SkGpuDevice.h"
14 #include "SkGrPixelRef.h" 16 #include "SkGrPixelRef.h"
15 #include "SkLayerInfo.h" 17 #include "SkLayerInfo.h"
16 #include "SkRecordDraw.h" 18 #include "SkRecordDraw.h"
17 #include "SkSurface.h" 19 #include "SkSurface.h"
18 #include "SkSurface_Gpu.h" 20 #include "SkSurface_Gpu.h"
19 21
20 // Create the layer information for the hoisted layer and secure the 22 // Create the layer information for the hoisted layer and secure the
21 // required texture/render target resources. 23 // required texture/render target resources.
22 static void prepare_for_hoisting(GrLayerCache* layerCache, 24 static void prepare_for_hoisting(GrLayerCache* layerCache,
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 pict->drawablePicts(), pict->drawableCount(), 269 pict->drawablePicts(), pict->drawableCount(),
268 layer->start() + 1, layer->stop(), initialCTM); 270 layer->start() + 1, layer->stop(), initialCTM);
269 271
270 atlasCanvas->restore(); 272 atlasCanvas->restore();
271 } 273 }
272 274
273 atlasCanvas->flush(); 275 atlasCanvas->flush();
274 } 276 }
275 } 277 }
276 278
279 SkBitmap wrap_texture(GrTexture* texture) {
280 SkASSERT(texture);
281
282 SkBitmap result;
283 result.setInfo(texture->surfacePriv().info());
284 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unre f();
285 return result;
286 }
287
277 void GrLayerHoister::FilterLayer(GrContext* context, 288 void GrLayerHoister::FilterLayer(GrContext* context,
278 SkGpuDevice* device, 289 SkGpuDevice* device,
279 const GrHoistedLayer& info) { 290 const GrHoistedLayer& info) {
280 GrCachedLayer* layer = info.fLayer; 291 GrCachedLayer* layer = info.fLayer;
281 292
282 SkASSERT(layer->filter()); 293 SkASSERT(layer->filter());
283 SkASSERT(layer->filter()->canFilterImageGPU());
284 294
285 static const int kDefaultCacheSize = 32 * 1024 * 1024; 295 static const int kDefaultCacheSize = 32 * 1024 * 1024;
286 296
287 SkBitmap filteredBitmap; 297 SkBitmap filteredBitmap;
288 SkIPoint offset = SkIPoint::Make(0, 0); 298 SkIPoint offset = SkIPoint::Make(0, 0);
289 299
290 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->sr cIR().fTop); 300 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->sr cIR().fTop);
291 301
292 SkMatrix totMat = SkMatrix::I(); 302 SkMatrix totMat = SkMatrix::I();
293 totMat.preConcat(info.fPreMat); 303 totMat.preConcat(info.fPreMat);
294 totMat.preConcat(info.fLocalMat); 304 totMat.preConcat(info.fLocalMat);
295 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterO ffset.fY)); 305 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterO ffset.fY));
296 306
297
298 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); 307 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop);
299 SkIRect clipBounds = layer->rect(); 308 SkIRect clipBounds = layer->rect();
300 309
301 // This cache is transient, and is freed (along with all its contained 310 // This cache is transient, and is freed (along with all its contained
302 // textures) when it goes out of scope. 311 // textures) when it goes out of scope.
303 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefau ltCacheSize)); 312 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefau ltCacheSize));
304 SkImageFilter::Context filterContext(totMat, clipBounds, cache); 313 SkImageFilter::Context filterContext(totMat, clipBounds, cache);
305 314
306 if (!device->filterTexture(context, layer->texture(), layer->filter(), 315 SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(0, kUnknown_SkPixelGeo metry));
307 filterContext, &filteredBitmap, &offset)) { 316 const SkBitmap src = wrap_texture(layer->texture());
308 // Filtering failed. Press on with the unfiltered version 317
318 if (!layer->filter()->filterImage(&proxy, src, filterContext, &filteredBitma p, &offset)) {
319 // Filtering failed. Press on with the unfiltered version.
309 return; 320 return;
310 } 321 }
311 322
312 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.hei ght()); 323 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.hei ght());
313 layer->setTexture(filteredBitmap.getTexture(), newRect); 324 layer->setTexture(filteredBitmap.getTexture(), newRect);
314 layer->setOffset(offset); 325 layer->setOffset(offset);
315 } 326 }
316 327
317 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay er>& layers) { 328 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay er>& layers) {
318 for (int i = 0; i < layers.count(); ++i) { 329 for (int i = 0; i < layers.count(); ++i) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 void GrLayerHoister::PurgeCache(GrContext* context) { 381 void GrLayerHoister::PurgeCache(GrContext* context) {
371 #if !GR_CACHE_HOISTED_LAYERS 382 #if !GR_CACHE_HOISTED_LAYERS
372 GrLayerCache* layerCache = context->getLayerCache(); 383 GrLayerCache* layerCache = context->getLayerCache();
373 384
374 // This code completely clears out the atlas. It is required when 385 // This code completely clears out the atlas. It is required when
375 // 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
376 // free floating layers 387 // free floating layers
377 layerCache->purgeAll(); 388 layerCache->purgeAll();
378 #endif 389 #endif
379 } 390 }
OLDNEW
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/GrRecordReplaceDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698