From 228f761111ea4c914dc11fc5523bdabc5eca7ffc Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Mon, 14 Aug 2017 08:49:54 -0400 Subject: Simplify difference and exclusion. We can fold through some math in these two modes. $ out/ok bench:samples=100 rp filter:search="Difference|Exclusion" serial Before: [blendmode_rect_Exclusion] 4.94ms @0 6.13ms @99 6.25ms @100 [blendmode_mask_Exclusion] 10.9ms @0 12.8ms @99 12.9ms @100 [blendmode_rect_Difference] 5.56ms @0 6.79ms @99 6.8ms @100 [blendmode_mask_Difference] 11.4ms @0 13.8ms @99 14.1ms @100 After: [blendmode_rect_Exclusion] 3.5ms @0 4.12ms @99 4.59ms @100 [blendmode_mask_Exclusion] 9.27ms @0 11.2ms @99 11.6ms @100 [blendmode_rect_Difference] 5.37ms @0 6.58ms @99 6.6ms @100 [blendmode_mask_Difference] 11ms @0 12.1ms @99 12.6ms @100 Change-Id: I03f32368244d4f979cfee83723fd78dfbc7d5fc1 Reviewed-on: https://skia-review.googlesource.com/33980 Commit-Queue: Florin Malita Reviewed-by: Florin Malita --- src/jumper/SkJumper_stages_8bit.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/jumper/SkJumper_stages_8bit.cpp') diff --git a/src/jumper/SkJumper_stages_8bit.cpp b/src/jumper/SkJumper_stages_8bit.cpp index cf037b0209..3d9fec0dbb 100644 --- a/src/jumper/SkJumper_stages_8bit.cpp +++ b/src/jumper/SkJumper_stages_8bit.cpp @@ -421,14 +421,24 @@ SI V srcover_alpha(V src, V dst, V rgb) { STAGE(darken) { src = srcover_alpha(src, dst, src + (dst - max(src*alpha(dst), dst*alpha(src)))); } STAGE(lighten) { src = srcover_alpha(src, dst, src + (dst - min(src*alpha(dst), dst*alpha(src)))); } -STAGE(difference) { - V min_ = min(src*alpha(dst), dst*alpha(src)); - src = srcover_alpha(src, dst, (src - min_) + (dst - min_)); -} +SI V zero_alpha(V rgba) { return rgba.u32 & 0x00ffffff; } STAGE(exclusion) { + // We could do exclusion with srcover_alpha(), but can fold a little more math through: + // rgb = Sc + Dc - 2*Sc*Dc + // alpha = Sa + Da - Sa*Da + // So we just subtract two sd from rgb, and one from alpha. V sd = src*dst; - src = srcover_alpha(src, dst, (src - sd) + (dst - sd)); + src = (src - sd) + (dst - zero_alpha(sd)); +} +STAGE(difference) { + // Like exclusion, we can fold math through with the same trick: + // rgb = Sc + Dc - 2*min(Sc*Da, Dc*Sa) + // alpha = Sa + Da - Sa*Da + // Here notice (Sa*Da) == min(Sa*Da, Da*Sa) for alpha, + // so again we subtract two from rgb, one from alpha. + V min_ = min(src*alpha(dst), dst*alpha(src)); + src = (src - min_) + (dst - zero_alpha(min_)); } #undef BLEND_MODE -- cgit v1.2.3