aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/opts/SkBlitRow_opts_SSE2.cpp
diff options
context:
space:
mode:
authorGravatar lsalzman <lsalzman@mozilla.com>2016-08-05 11:48:45 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-05 11:48:45 -0700
commit40254c2c2dc28a34f96294d5a1ad94a99b0be8a6 (patch)
treedbc9c6b38ca6be76f0011623f3a529a60ce1d570 /src/opts/SkBlitRow_opts_SSE2.cpp
parentf77c47b78217883e6f074dd7e3e5bed5f82e144d (diff)
SkBlendARGB32 and S32[A]_Blend_BlitRow32 are currently formulated as: SkAlphaMulQ(src, src_scale) + SkAlphaMulQ(dst, dst_scale), which boils down to ((src*src_scale)>>8) + ((dst*dst_scale)>>8). In particular, note that the intermediate precision is discarded before the two parts are added together, causing the final result to possibly inaccurate.
In Firefox, we use SkCanvas::saveLayer in combination with a backdrop that initializes the layer to the background. When this is blended back onto background using transparency, where the source and destination pixel colors are the same, the resulting color after the blend is not preserved due to the lost precision mentioned above. In cases where this operation is repeatedly performed, this causes substantially noticeable differences in color as evidenced in this downstream Firefox bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1200684 In the test-case in the downstream report, essentially it does blend(src=0xFF2E3338, dst=0xFF2E3338, scale=217), which gives the result 0xFF2E3237, while we would expect to get back 0xFF2E3338. This problem goes away if the blend is instead reformulated to effectively do (src*src_scale + dst*dst_scale)>>8, which keeps the intermediate precision during the addition before shifting it off. This modifies the blending operations thusly. The performance should remain mostly unchanged, or possibly improve slightly, so there should be no real downside to doing this, with the benefit of making the results more accurate. Without this, it is currently unsafe for Firefox to blend a layer back onto itself that was initialized with a copy of its background. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2097883002 CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot [mtklein adds...] No public API changes. TBR=reed@google.com Review-Url: https://codereview.chromium.org/2097883002
Diffstat (limited to 'src/opts/SkBlitRow_opts_SSE2.cpp')
-rw-r--r--src/opts/SkBlitRow_opts_SSE2.cpp11
1 files changed, 3 insertions, 8 deletions
diff --git a/src/opts/SkBlitRow_opts_SSE2.cpp b/src/opts/SkBlitRow_opts_SSE2.cpp
index a6fbc25958..7ce1fc9a80 100644
--- a/src/opts/SkBlitRow_opts_SSE2.cpp
+++ b/src/opts/SkBlitRow_opts_SSE2.cpp
@@ -26,12 +26,11 @@ void S32_Blend_BlitRow32_SSE2(SkPMColor* SK_RESTRICT dst,
}
uint32_t src_scale = SkAlpha255To256(alpha);
- uint32_t dst_scale = 256 - src_scale;
if (count >= 4) {
SkASSERT(((size_t)dst & 0x03) == 0);
while (((size_t)dst & 0x0F) != 0) {
- *dst = SkAlphaMulQ(*src, src_scale) + SkAlphaMulQ(*dst, dst_scale);
+ *dst = SkPMLerp(*src, *dst, src_scale);
src++;
dst++;
count--;
@@ -45,11 +44,7 @@ void S32_Blend_BlitRow32_SSE2(SkPMColor* SK_RESTRICT dst,
__m128i src_pixel = _mm_loadu_si128(s);
__m128i dst_pixel = _mm_load_si128(d);
- src_pixel = SkAlphaMulQ_SSE2(src_pixel, src_scale);
- dst_pixel = SkAlphaMulQ_SSE2(dst_pixel, dst_scale);
-
- // Add result
- __m128i result = _mm_add_epi8(src_pixel, dst_pixel);
+ __m128i result = SkPMLerp_SSE2(src_pixel, dst_pixel, src_scale);
_mm_store_si128(d, result);
s++;
d++;
@@ -60,7 +55,7 @@ void S32_Blend_BlitRow32_SSE2(SkPMColor* SK_RESTRICT dst,
}
while (count > 0) {
- *dst = SkAlphaMulQ(*src, src_scale) + SkAlphaMulQ(*dst, dst_scale);
+ *dst = SkPMLerp(*src, *dst, src_scale);
src++;
dst++;
count--;