aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/opts/SkBlend_opts.h
diff options
context:
space:
mode:
authorGravatar herb <herb@google.com>2016-07-12 15:00:46 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-12 15:00:46 -0700
commit2edf0c6a719b8dff4365628cf3b4481c5035f07a (patch)
tree63fa587c2ed531dac43652d94bb098bdedf1afb4 /src/opts/SkBlend_opts.h
parent7d3ff7142360f456be4e21e64c6c014cc919785e (diff)
Remove bloat from SkBlend_opts.
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2130183003 CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot Review-Url: https://codereview.chromium.org/2130183003
Diffstat (limited to 'src/opts/SkBlend_opts.h')
-rw-r--r--src/opts/SkBlend_opts.h101
1 files changed, 16 insertions, 85 deletions
diff --git a/src/opts/SkBlend_opts.h b/src/opts/SkBlend_opts.h
index 2dcdcc7aaf..39cbbe8d7e 100644
--- a/src/opts/SkBlend_opts.h
+++ b/src/opts/SkBlend_opts.h
@@ -21,95 +21,19 @@ ninja -C out/Release dm nanobench ; and ./out/Release/dm --match Blend_opts ; an
namespace SK_OPTS_NS {
-// An implementation of SrcOver from bytes to bytes in linear space that takes advantage of the
-// observation that the 255's cancel.
-// invA = 1 - (As / 255);
-//
-// R = 255 * sqrt((Rs/255)^2 + (Rd/255)^2 * invA)
-// => R = 255 * sqrt((Rs^2 + Rd^2 * invA)/255^2)
-// => R = sqrt(Rs^2 + Rd^2 * invA)
-static inline void blend_srgb_srgb_1(uint32_t* dst, const uint32_t pixel) {
- Sk4f s = srgb_to_linear(to_4f(pixel));
- Sk4f d = srgb_to_linear(to_4f(*dst));
- Sk4f invAlpha = 1.0f - Sk4f{s[SkPM4f::A]} * (1.0f / 255.0f);
- Sk4f r = linear_to_srgb(s + d * invAlpha) + 0.5f;
- *dst = to_4b(r);
-}
-
-static inline void srcover_srgb_srgb_1(uint32_t* dst, const uint32_t pixel) {
+static inline void srcover_srgb8888_srgb_1(uint32_t* dst, const uint32_t pixel) {
if ((~pixel & 0xFF000000) == 0) {
*dst = pixel;
} else if ((pixel & 0xFF000000) != 0) {
- blend_srgb_srgb_1(dst, pixel);
+ srcover_blend_srgb8888_srgb_1(dst, srgb_to_linear(to_4f(pixel)));
}
}
-static inline void srcover_srgb_srgb_2(uint32_t* dst, const uint32_t* src) {
- srcover_srgb_srgb_1(dst++, *src++);
- srcover_srgb_srgb_1(dst, *src);
-}
-
static inline void srcover_srgb_srgb_4(uint32_t* dst, const uint32_t* src) {
- srcover_srgb_srgb_1(dst++, *src++);
- srcover_srgb_srgb_1(dst++, *src++);
- srcover_srgb_srgb_1(dst++, *src++);
- srcover_srgb_srgb_1(dst, *src);
-}
-
-void best_non_simd_srcover_srgb_srgb(
- uint32_t* dst, const uint32_t* const src, int ndst, const int nsrc) {
- uint64_t* ddst = reinterpret_cast<uint64_t*>(dst);
-
- while (ndst >0) {
- int count = SkTMin(ndst, nsrc);
- ndst -= count;
- const uint64_t* dsrc = reinterpret_cast<const uint64_t*>(src);
- const uint64_t* end = dsrc + (count >> 1);
- do {
- if ((~*dsrc & 0xFF000000FF000000) == 0) {
- do {
- *ddst++ = *dsrc++;
- } while (dsrc < end && (~*dsrc & 0xFF000000FF000000) == 0);
- } else if ((*dsrc & 0xFF000000FF000000) == 0) {
- do {
- dsrc++;
- ddst++;
- } while (dsrc < end && (*dsrc & 0xFF000000FF000000) == 0);
- } else {
- srcover_srgb_srgb_2(reinterpret_cast<uint32_t*>(ddst++),
- reinterpret_cast<const uint32_t*>(dsrc++));
- }
- } while (dsrc < end);
-
- if ((count & 1) != 0) {
- srcover_srgb_srgb_1(reinterpret_cast<uint32_t*>(ddst),
- *reinterpret_cast<const uint32_t*>(dsrc));
- }
- }
-}
-
-void brute_force_srcover_srgb_srgb(
- uint32_t* dst, const uint32_t* const src, int ndst, const int nsrc) {
- while (ndst > 0) {
- int n = SkTMin(ndst, nsrc);
-
- for (int i = 0; i < n; i++) {
- blend_srgb_srgb_1(dst++, src[i]);
- }
- ndst -= n;
- }
-}
-
-void trivial_srcover_srgb_srgb(
- uint32_t* dst, const uint32_t* const src, int ndst, const int nsrc) {
- while (ndst > 0) {
- int n = SkTMin(ndst, nsrc);
-
- for (int i = 0; i < n; i++) {
- srcover_srgb_srgb_1(dst++, src[i]);
- }
- ndst -= n;
- }
+ srcover_srgb8888_srgb_1(dst++, *src++);
+ srcover_srgb8888_srgb_1(dst++, *src++);
+ srcover_srgb8888_srgb_1(dst++, *src++);
+ srcover_srgb8888_srgb_1(dst, *src);
}
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
@@ -163,7 +87,7 @@ void trivial_srcover_srgb_srgb(
count = count & 3;
while (count-- > 0) {
- srcover_srgb_srgb_1(dst++, *src++);
+ srcover_srgb8888_srgb_1(dst++, *src++);
}
}
}
@@ -235,7 +159,7 @@ void trivial_srcover_srgb_srgb(
count = count & 3;
while (count-- > 0) {
- srcover_srgb_srgb_1(dst++, *src++);
+ srcover_srgb8888_srgb_1(dst++, *src++);
}
}
}
@@ -244,7 +168,14 @@ void trivial_srcover_srgb_srgb(
void srcover_srgb_srgb(
uint32_t* dst, const uint32_t* const src, int ndst, const int nsrc) {
- trivial_srcover_srgb_srgb(dst, src, ndst, nsrc);
+ while (ndst > 0) {
+ int n = SkTMin(ndst, nsrc);
+
+ for (int i = 0; i < n; i++) {
+ srcover_srgb8888_srgb_1(dst++, src[i]);
+ }
+ ndst -= n;
+ }
}
#endif