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

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: 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') | no next file » | 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 SkBitmap result;
281 result.setInfo(texture->surfacePriv().info());
282 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unre f();
283 return result;
284 }
285
277 void GrLayerHoister::FilterLayer(GrContext* context, 286 void GrLayerHoister::FilterLayer(GrContext* context,
278 SkGpuDevice* device, 287 SkGpuDevice* device,
279 const GrHoistedLayer& info) { 288 const GrHoistedLayer& info) {
280 GrCachedLayer* layer = info.fLayer; 289 GrCachedLayer* layer = info.fLayer;
281 290
282 SkASSERT(layer->filter()); 291 SkASSERT(layer->filter());
283 SkASSERT(layer->filter()->canFilterImageGPU());
284 292
285 static const int kDefaultCacheSize = 32 * 1024 * 1024; 293 static const int kDefaultCacheSize = 32 * 1024 * 1024;
286 294
287 SkBitmap filteredBitmap; 295 SkBitmap filteredBitmap;
288 SkIPoint offset = SkIPoint::Make(0, 0); 296 SkIPoint offset = SkIPoint::Make(0, 0);
289 297
290 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->sr cIR().fTop); 298 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->sr cIR().fTop);
291 299
292 SkMatrix totMat = SkMatrix::I(); 300 SkMatrix totMat = SkMatrix::I();
293 totMat.preConcat(info.fPreMat); 301 totMat.preConcat(info.fPreMat);
294 totMat.preConcat(info.fLocalMat); 302 totMat.preConcat(info.fLocalMat);
295 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterO ffset.fY)); 303 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterO ffset.fY));
296 304
297
298 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); 305 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop);
299 SkIRect clipBounds = layer->rect(); 306 SkIRect clipBounds = layer->rect();
300 307
301 // This cache is transient, and is freed (along with all its contained 308 // This cache is transient, and is freed (along with all its contained
302 // textures) when it goes out of scope. 309 // textures) when it goes out of scope.
303 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefau ltCacheSize)); 310 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefau ltCacheSize));
304 SkImageFilter::Context filterContext(totMat, clipBounds, cache); 311 SkImageFilter::Context filterContext(totMat, clipBounds, cache);
305 312
306 if (!device->filterTexture(context, layer->texture(), layer->filter(), 313 SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(0, kUnknown_SkPixelGeo metry));
bsalomon 2015/01/13 18:08:40 Is this still used anywhere? Otherwise, lgtm.
robertphillips 2015/01/13 18:28:24 SkImageFilter::filterImage actually loops back aro
307 filterContext, &filteredBitmap, &offset)) { 314 const SkBitmap src = wrap_texture(layer->texture());
308 // Filtering failed. Press on with the unfiltered version 315
316 if (!layer->filter()->filterImage(&proxy, src, filterContext, &filteredBitma p, &offset)) {
317 // Filtering failed. Press on with the unfiltered version.
309 return; 318 return;
310 } 319 }
311 320
312 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.hei ght()); 321 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.hei ght());
313 layer->setTexture(filteredBitmap.getTexture(), newRect); 322 layer->setTexture(filteredBitmap.getTexture(), newRect);
314 layer->setOffset(offset); 323 layer->setOffset(offset);
315 } 324 }
316 325
317 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay er>& layers) { 326 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay er>& layers) {
318 for (int i = 0; i < layers.count(); ++i) { 327 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) { 379 void GrLayerHoister::PurgeCache(GrContext* context) {
371 #if !GR_CACHE_HOISTED_LAYERS 380 #if !GR_CACHE_HOISTED_LAYERS
372 GrLayerCache* layerCache = context->getLayerCache(); 381 GrLayerCache* layerCache = context->getLayerCache();
373 382
374 // This code completely clears out the atlas. It is required when 383 // 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 384 // caching is disabled so the atlas doesn't fill up and force more
376 // free floating layers 385 // free floating layers
377 layerCache->purgeAll(); 386 layerCache->purgeAll();
378 #endif 387 #endif
379 } 388 }
OLDNEW
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698