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

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

Issue 1584933002: Refactor to use GrWrapTextureInBitmap more (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix no-gpu build Created 4 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/effects/SkXfermodeImageFilter.cpp ('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" 12 #include "SkBigPicture.h"
13 #include "SkCanvas.h" 13 #include "SkCanvas.h"
14 #include "SkGpuDevice.h" 14 #include "SkGpuDevice.h"
15 #include "SkGrPixelRef.h"
16 #include "SkLayerInfo.h" 15 #include "SkLayerInfo.h"
17 #include "SkRecordDraw.h" 16 #include "SkRecordDraw.h"
18 #include "SkSurface.h" 17 #include "SkSurface.h"
19 #include "SkSurface_Gpu.h" 18 #include "SkSurface_Gpu.h"
20 19
21 // Create the layer information for the hoisted layer and secure the 20 // Create the layer information for the hoisted layer and secure the
22 // required texture/render target resources. 21 // required texture/render target resources.
23 static void prepare_for_hoisting(GrLayerCache* layerCache, 22 static void prepare_for_hoisting(GrLayerCache* layerCache,
24 const SkPicture* topLevelPicture, 23 const SkPicture* topLevelPicture,
25 const SkMatrix& initialMat, 24 const SkMatrix& initialMat,
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 atlasCanvas->concat(atlased[i].fLocalMat); 269 atlasCanvas->concat(atlased[i].fLocalMat);
271 270
272 pict->partialPlayback(atlasCanvas, layer->start() + 1, layer->stop() , initialCTM); 271 pict->partialPlayback(atlasCanvas, layer->start() + 1, layer->stop() , initialCTM);
273 atlasCanvas->restore(); 272 atlasCanvas->restore();
274 } 273 }
275 274
276 atlasCanvas->flush(); 275 atlasCanvas->flush();
277 } 276 }
278 } 277 }
279 278
280 SkBitmap wrap_texture(GrTexture* texture) {
281 SkASSERT(texture);
282
283 SkBitmap result;
284 result.setInfo(texture->surfacePriv().info(kPremul_SkAlphaType));
285 result.setPixelRef(new SkGrPixelRef(result.info(), texture))->unref();
286 return result;
287 }
288
289 void GrLayerHoister::FilterLayer(GrContext* context, 279 void GrLayerHoister::FilterLayer(GrContext* context,
290 SkGpuDevice* device, 280 SkGpuDevice* device,
291 const GrHoistedLayer& info) { 281 const GrHoistedLayer& info) {
292 GrCachedLayer* layer = info.fLayer; 282 GrCachedLayer* layer = info.fLayer;
293 283
294 SkASSERT(layer->filter()); 284 SkASSERT(layer->filter());
295 285
296 static const int kDefaultCacheSize = 32 * 1024 * 1024; 286 static const int kDefaultCacheSize = 32 * 1024 * 1024;
297 287
298 SkBitmap filteredBitmap; 288 SkBitmap filteredBitmap;
299 SkIPoint offset = SkIPoint::Make(0, 0); 289 SkIPoint offset = SkIPoint::Make(0, 0);
300 290
301 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->sr cIR().fTop); 291 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->sr cIR().fTop);
302 292
303 SkMatrix totMat = SkMatrix::I(); 293 SkMatrix totMat = SkMatrix::I();
304 totMat.preConcat(info.fPreMat); 294 totMat.preConcat(info.fPreMat);
305 totMat.preConcat(info.fLocalMat); 295 totMat.preConcat(info.fLocalMat);
306 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterO ffset.fY)); 296 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterO ffset.fY));
307 297
308 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); 298 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop);
309 SkIRect clipBounds = layer->rect(); 299 SkIRect clipBounds = layer->rect();
310 300
311 // This cache is transient, and is freed (along with all its contained 301 // This cache is transient, and is freed (along with all its contained
312 // textures) when it goes out of scope. 302 // textures) when it goes out of scope.
313 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefau ltCacheSize)); 303 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefau ltCacheSize));
314 SkImageFilter::Context filterContext(totMat, clipBounds, cache); 304 SkImageFilter::Context filterContext(totMat, clipBounds, cache);
315 305
316 SkImageFilter::DeviceProxy proxy(device); 306 SkImageFilter::DeviceProxy proxy(device);
317 const SkBitmap src = wrap_texture(layer->texture()); 307 SkBitmap src;
308 GrWrapTextureInBitmap(layer->texture(), layer->texture()->width(), layer->te xture()->height(),
309 false, &src);
318 310
319 if (!layer->filter()->filterImage(&proxy, src, filterContext, &filteredBitma p, &offset)) { 311 if (!layer->filter()->filterImage(&proxy, src, filterContext, &filteredBitma p, &offset)) {
320 // Filtering failed. Press on with the unfiltered version. 312 // Filtering failed. Press on with the unfiltered version.
321 return; 313 return;
322 } 314 }
323 315
324 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.hei ght()); 316 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.hei ght());
325 layer->setTexture(filteredBitmap.getTexture(), newRect, false); 317 layer->setTexture(filteredBitmap.getTexture(), newRect, false);
326 layer->setOffset(offset); 318 layer->setOffset(offset);
327 } 319 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 #if !GR_CACHE_HOISTED_LAYERS 384 #if !GR_CACHE_HOISTED_LAYERS
393 385
394 // This code completely clears out the atlas. It is required when 386 // This code completely clears out the atlas. It is required when
395 // caching is disabled so the atlas doesn't fill up and force more 387 // caching is disabled so the atlas doesn't fill up and force more
396 // free floating layers 388 // free floating layers
397 layerCache->purgeAll(); 389 layerCache->purgeAll();
398 #endif 390 #endif
399 391
400 layerCache->end(); 392 layerCache->end();
401 } 393 }
OLDNEW
« no previous file with comments | « src/effects/SkXfermodeImageFilter.cpp ('k') | src/gpu/GrRecordReplaceDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698