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

Issue 230653005: Implement intra-frame cacheing in image filters. (Closed)

Created:
6 years, 8 months ago by Stephen White
Modified:
6 years, 8 months ago
Reviewers:
bungeman-skia, reed1
CC:
skia-review_googlegroups.com
Visibility:
Public.

Description

Implement intra-frame cacheing in image filters. When image filters are processed within Skia, they simply do a blind recursion. This has the side-effect of turning the DAG into a tree. I.e., nodes visited more than once during the traversal will be processed more than once. This change implements a very simple cacheing scheme: a cache is created before traversing the DAG, and handed into the processing traversal. Before recursing into a child in SkImageFilter::filterImage(), the cache is checked for a hit, and early-out is performed. Otherwise, the node is processed, and its result bitmap and location (offset) are cached, but only if it contains two or more children and thus will be visited again during the traversal. Currently, the child count is approximated with the refcount. This is good enough in most cases (and exactly correct for the Chrome use case). We could add an exact child count to the image filter, but this will require violating the immutability of image filters slightly in order to bump the child count as nodes are connected. I leave it up to the reviewer to decide which is better. Committed: http://code.google.com/p/skia/source/detail?r=14160

Patch Set 1 #

Patch Set 2 : OCD tweak #

Total comments: 2

Patch Set 3 : Set minChildren to 2 by default; comment it. #

Total comments: 6
Unified diffs Side-by-side diffs Delta from patch set Stats (+139 lines, -19 lines) Patch
M gm/imagefiltersbase.cpp View 2 chunks +3 lines, -2 lines 0 comments Download
M include/core/SkImageFilter.h View 1 2 2 chunks +14 lines, -3 lines 0 comments Download
M src/core/SkCanvas.cpp View 1 2 2 chunks +6 lines, -2 lines 0 comments Download
M src/core/SkImageFilter.cpp View 1 2 3 chunks +92 lines, -2 lines 6 comments Download
M src/effects/SkDropShadowImageFilter.cpp View 4 chunks +10 lines, -4 lines 0 comments Download
M src/effects/SkTileImageFilter.cpp View 1 chunk +2 lines, -1 line 0 comments Download
M src/gpu/SkGpuDevice.cpp View 1 2 2 chunks +6 lines, -2 lines 0 comments Download
M tests/ImageFilterTest.cpp View 2 chunks +6 lines, -3 lines 0 comments Download

Messages

Total messages: 10 (0 generated)
Stephen White
reed@: PTAL. This is a version with the cache as a non-const-accessible member of the ...
6 years, 8 months ago (2014-04-10 20:58:06 UTC) #1
reed1
lgtm w/ request for documenting the call-site of '2' https://codereview.chromium.org/230653005/diff/10001/src/core/SkCanvas.cpp File src/core/SkCanvas.cpp (right): https://codereview.chromium.org/230653005/diff/10001/src/core/SkCanvas.cpp#newcode1261 src/core/SkCanvas.cpp:1261: ...
6 years, 8 months ago (2014-04-10 21:23:26 UTC) #2
Stephen White
https://codereview.chromium.org/230653005/diff/10001/src/core/SkCanvas.cpp File src/core/SkCanvas.cpp (right): https://codereview.chromium.org/230653005/diff/10001/src/core/SkCanvas.cpp#newcode1261 src/core/SkCanvas.cpp:1261: SkImageFilter::Cache* cache = SkImageFilter::Cache::Create(2); On 2014/04/10 21:23:26, reed1 wrote: ...
6 years, 8 months ago (2014-04-10 21:26:36 UTC) #3
Stephen White
New patch: give minChildren a default, and document it.
6 years, 8 months ago (2014-04-10 21:30:00 UTC) #4
Stephen White
The CQ bit was checked by senorblanco@chromium.org
6 years, 8 months ago (2014-04-11 17:58:54 UTC) #5
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://skia-tree-status.appspot.com/cq/senorblanco@chromium.org/230653005/30001
6 years, 8 months ago (2014-04-11 17:59:05 UTC) #6
commit-bot: I haz the power
Change committed as 14160
6 years, 8 months ago (2014-04-11 18:57:19 UTC) #7
bungeman-skia
https://codereview.chromium.org/230653005/diff/30001/src/core/SkImageFilter.cpp File src/core/SkImageFilter.cpp (right): https://codereview.chromium.org/230653005/diff/30001/src/core/SkImageFilter.cpp#newcode378 src/core/SkImageFilter.cpp:378: return compute_hash(reinterpret_cast<const uint32_t*>(&key), sizeof(Key) / sizeof(uint32_t)); You do realize ...
6 years, 8 months ago (2014-04-14 16:47:47 UTC) #8
Stephen White
Thanks for the drive-by review; I appreciate it! :) https://codereview.chromium.org/230653005/diff/30001/src/core/SkImageFilter.cpp File src/core/SkImageFilter.cpp (right): https://codereview.chromium.org/230653005/diff/30001/src/core/SkImageFilter.cpp#newcode378 src/core/SkImageFilter.cpp:378: ...
6 years, 8 months ago (2014-04-14 17:24:44 UTC) #9
bungeman-skia
6 years, 8 months ago (2014-04-14 18:05:10 UTC) #10
Message was sent while issue was closed.
I'm Skia sheriff this week, and I took a quick look at what I was rolling due to
other changes in Chromium. I just saw these changes and though I should comment.

https://codereview.chromium.org/230653005/diff/30001/src/core/SkImageFilter.cpp
File src/core/SkImageFilter.cpp (right):

https://codereview.chromium.org/230653005/diff/30001/src/core/SkImageFilter.c...
src/core/SkImageFilter.cpp:378: return compute_hash(reinterpret_cast<const
uint32_t*>(&key), sizeof(Key) / sizeof(uint32_t));
On 2014/04/14 17:24:45, Stephen White wrote:
> On 2014/04/14 16:47:48, bungeman1 wrote:
> > You do realize that this is computing a hash which includes the ref count
> right?
> 
> Unless I've messed up totally, this should just be a hash of the SkImageFilter
> pointer value, not its contents. (Key is a const SkImageFilter*, sizeof(Key)
> should be the size of a pointer, so 1 or 2 uint32_t's. We never deref the
> pointer; just use it as an opaque key (could probably be a void *).
> 

Ah, I see, the Key here is SkImageFilter*, so this is casting SkImageFilter** to
'const uint32_t*'. Changing the number of indirections in this cast is probably
what threw me off here (why it looks like you're hashing the SkImageFilter data
vs the SkImageFilter*).

> > Having keys which are modifiable is rather frightening. 
> 
> Agreed.

https://codereview.chromium.org/230653005/diff/30001/src/core/SkImageFilter.c...
src/core/SkImageFilter.cpp:396: if (key->getRefCnt() >= fMinChildren) {
On 2014/04/14 17:24:45, Stephen White wrote:
> On 2014/04/14 16:47:48, bungeman1 wrote:
> > This is somewhat crazy. 'getRefCnt' is marked 'Use only for debugging.' for
a
> > reason. I see why you think you can get away with this here, but it's really
> > iffy.
> 
> I think it would probably be better long-term to keep an actual child count. I
> just didn't like the idea of making SkImageFilter partly-mutable (see patch
> description).

Sure, although SkImageFilter, being SkRefCnt, is already partly mutable. I
understand why one would prefer to avoid that though. I just saw a non-debug use
of getRefCnt and alarm bells went off.

Powered by Google App Engine
This is Rietveld 408576698