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

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

Issue 414483003: Implement a persistent uniqueID-based cache for SkImageFilter. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Undo some unnecessary reformatting. Created 6 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkGpuDevice.h" 8 #include "SkGpuDevice.h"
9 9
10 #include "effects/GrBicubicEffect.h" 10 #include "effects/GrBicubicEffect.h"
(...skipping 22 matching lines...) Expand all
33 #include "SkPictureRangePlayback.h" 33 #include "SkPictureRangePlayback.h"
34 #include "SkPictureReplacementPlayback.h" 34 #include "SkPictureReplacementPlayback.h"
35 #include "SkRRect.h" 35 #include "SkRRect.h"
36 #include "SkStroke.h" 36 #include "SkStroke.h"
37 #include "SkSurface.h" 37 #include "SkSurface.h"
38 #include "SkTLazy.h" 38 #include "SkTLazy.h"
39 #include "SkUtils.h" 39 #include "SkUtils.h"
40 #include "SkVertState.h" 40 #include "SkVertState.h"
41 #include "SkErrorInternals.h" 41 #include "SkErrorInternals.h"
42 42
43 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 };
44
43 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 45 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1
44 46
45 #if 0 47 #if 0
46 extern bool (*gShouldDrawProc)(); 48 extern bool (*gShouldDrawProc)();
47 #define CHECK_SHOULD_DRAW(draw, forceI) \ 49 #define CHECK_SHOULD_DRAW(draw, forceI) \
48 do { \ 50 do { \
49 if (gShouldDrawProc && !gShouldDrawProc()) return; \ 51 if (gShouldDrawProc && !gShouldDrawProc()) return; \
50 this->prepareDraw(draw, forceI); \ 52 this->prepareDraw(draw, forceI); \
51 } while (0) 53 } while (0)
52 #else 54 #else
(...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 1419
1418 SkImageFilter* filter = paint.getImageFilter(); 1420 SkImageFilter* filter = paint.getImageFilter();
1419 // This bitmap will own the filtered result as a texture. 1421 // This bitmap will own the filtered result as a texture.
1420 SkBitmap filteredBitmap; 1422 SkBitmap filteredBitmap;
1421 1423
1422 if (NULL != filter) { 1424 if (NULL != filter) {
1423 SkIPoint offset = SkIPoint::Make(0, 0); 1425 SkIPoint offset = SkIPoint::Make(0, 0);
1424 SkMatrix matrix(*draw.fMatrix); 1426 SkMatrix matrix(*draw.fMatrix);
1425 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); 1427 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
1426 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); 1428 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
1427 SkImageFilter::Cache* cache = SkImageFilter::Cache::Create(); 1429 SkAutoTUnref<SkImageFilter::GenIDCache> cache(getImageFilterCache());
bsalomon 2014/07/25 14:11:58 A comment here about tossing the textures after fi
Stephen White 2014/07/25 17:34:17 Done. Also done in SkGpuDevice::drawDevice(), whic
1428 SkAutoUnref aur(cache);
1429 SkImageFilter::Context ctx(matrix, clipBounds, cache); 1430 SkImageFilter::Context ctx(matrix, clipBounds, cache);
1430 if (filter_texture(this, fContext, texture, filter, w, h, ctx, &filtered Bitmap, 1431 if (filter_texture(this, fContext, texture, filter, w, h, ctx, &filtered Bitmap,
1431 &offset)) { 1432 &offset)) {
1432 texture = (GrTexture*) filteredBitmap.getTexture(); 1433 texture = (GrTexture*) filteredBitmap.getTexture();
1433 w = filteredBitmap.width(); 1434 w = filteredBitmap.width();
1434 h = filteredBitmap.height(); 1435 h = filteredBitmap.height();
1435 left += offset.x(); 1436 left += offset.x();
1436 top += offset.y(); 1437 top += offset.y();
1437 } else { 1438 } else {
1438 return; 1439 return;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 1528
1528 SkImageFilter* filter = paint.getImageFilter(); 1529 SkImageFilter* filter = paint.getImageFilter();
1529 // This bitmap will own the filtered result as a texture. 1530 // This bitmap will own the filtered result as a texture.
1530 SkBitmap filteredBitmap; 1531 SkBitmap filteredBitmap;
1531 1532
1532 if (NULL != filter) { 1533 if (NULL != filter) {
1533 SkIPoint offset = SkIPoint::Make(0, 0); 1534 SkIPoint offset = SkIPoint::Make(0, 0);
1534 SkMatrix matrix(*draw.fMatrix); 1535 SkMatrix matrix(*draw.fMatrix);
1535 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); 1536 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
1536 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); 1537 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height());
1537 SkImageFilter::Cache* cache = SkImageFilter::Cache::Create(); 1538 SkImageFilter::Context ctx(matrix, clipBounds, getImageFilterCache());
1538 SkAutoUnref aur(cache);
1539 SkImageFilter::Context ctx(matrix, clipBounds, cache);
1540 if (filter_texture(this, fContext, devTex, filter, w, h, ctx, &filteredB itmap, 1539 if (filter_texture(this, fContext, devTex, filter, w, h, ctx, &filteredB itmap,
1541 &offset)) { 1540 &offset)) {
1542 devTex = filteredBitmap.getTexture(); 1541 devTex = filteredBitmap.getTexture();
1543 w = filteredBitmap.width(); 1542 w = filteredBitmap.width();
1544 h = filteredBitmap.height(); 1543 h = filteredBitmap.height();
1545 x += offset.fX; 1544 x += offset.fX;
1546 y += offset.fY; 1545 y += offset.fY;
1547 } else { 1546 } else {
1548 return; 1547 return;
1549 } 1548 }
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 playback.draw(canvas, NULL); 2050 playback.draw(canvas, NULL);
2052 2051
2053 // unlock the layers 2052 // unlock the layers
2054 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { 2053 for (int i = 0; i < gpuData->numSaveLayers(); ++i) {
2055 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); 2054 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i);
2056 fContext->getLayerCache()->unlock(layer); 2055 fContext->getLayerCache()->unlock(layer);
2057 } 2056 }
2058 2057
2059 return true; 2058 return true;
2060 } 2059 }
2060
2061 SkImageFilter::GenIDCache* SkGpuDevice::getImageFilterCache() {
2062 // We always return a transient cache, so it is freed after each
2063 // filter traversal.
2064 return SkImageFilter::GenIDCache::Create(kDefaultImageFilterCacheSize);
2065 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698