aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBlitRow_D32.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@google.com>2015-04-21 08:09:30 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-21 08:09:30 -0700
commita4a0aeb74808a0860f3e94588d0ceb0da9fed386 (patch)
treedf261cb8e23161abffe763002dfa0d650bbcc357 /src/core/SkBlitRow_D32.cpp
parent8672f4dffa4b298d4cabee6151590ae885d47263 (diff)
Revert of Convert Color32 code to perfect blend. (patchset #6 id:100001 of https://codereview.chromium.org/1098913002/)
Reason for revert: Xfermode_SrcOver not looking encouraging. Up to 50% regressions. https://perf.skia.org/#3242 Original issue's description: > Convert Color32 code to perfect blend. > > Before we commit to blend_256_round_alt, let's make sure blend_perfect is > really slower in practice (i.e. regresses on perf.skia.org). > > blend_perfect is really the most desirable algorithm if we can afford it. Not > only is it correct, but it's easy to think about and break into correct pieces: > for instance, its div255() doesn't require any coordination with the multiply. > > This looks like a 30% hit according to microbenches. That said, microbenches > said my previous change would be a 20-25% perf improvement, but it didn't end > up showing a significant effect at a high level. > > As for correctness, I see a bunch of off-by-1 compared to blend_256_round_alt > (exactly what we'd expect), and one off-by-3 in a GM that looks like it has a > bunch of overdraw. > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/61221e7f87a99765b0e034020e06bb018e2a08c2 TBR=reed@google.com,fmalita@chromium.org,mtklein@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1083923006
Diffstat (limited to 'src/core/SkBlitRow_D32.cpp')
-rw-r--r--src/core/SkBlitRow_D32.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/core/SkBlitRow_D32.cpp b/src/core/SkBlitRow_D32.cpp
index 36bfa54095..ac01e427bf 100644
--- a/src/core/SkBlitRow_D32.cpp
+++ b/src/core/SkBlitRow_D32.cpp
@@ -142,8 +142,11 @@ SkBlitRow::Proc32 SkBlitRow::ColorProcFactory() {
#define SK_SUPPORT_LEGACY_COLOR32_MATHx
-// Color32 and its SIMD specializations use the blend_perfect algorithm from tests/BlendTest.cpp.
-// An acceptable alternative is blend_256_round_alt, which is faster but not quite perfect.
+// Color32 and its SIMD specializations use the blend_256_round_alt algorithm
+// from tests/BlendTest.cpp. It's not quite perfect, but it's never wrong in the
+// interesting edge cases, and it's quite a bit faster than blend_perfect.
+//
+// blend_256_round_alt is our currently blessed algorithm. Please use it or an analogous one.
void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src,
int count, SkPMColor color) {
@@ -153,19 +156,19 @@ void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst,
}
unsigned invA = 255 - SkGetPackedA32(color);
+#ifdef SK_SUPPORT_LEGACY_COLOR32_MATH // blend_256_plus1_trunc, busted
+ unsigned round = 0;
+#else // blend_256_round_alt, good
+ invA += invA >> 7;
+ unsigned round = (128 << 16) + (128 << 0);
+#endif
+
while (count --> 0) {
// Our math is 16-bit, so we can do a little bit of SIMD in 32-bit registers.
const uint32_t mask = 0x00FF00FF;
- uint32_t rb = (((*src >> 0) & mask) * invA), // r_b_
- ag = (((*src >> 8) & mask) * invA); // a_g_
- #ifndef SK_SUPPORT_LEGACY_COLOR32_MATH
- uint32_t round = (128 << 16) + (128 << 0);
- rb += round;
- ag += round;
- rb += (rb & ~mask) >> 8;
- ag += (ag & ~mask) >> 8;
- #endif
- *dst = color + (((rb>>8) & mask) | ((ag>>0) & ~mask));
+ uint32_t rb = (((*src >> 0) & mask) * invA + round) >> 8, // _r_b
+ ag = (((*src >> 8) & mask) * invA + round) >> 0; // a_g_
+ *dst = color + ((rb & mask) | (ag & ~mask));
src++;
dst++;
}