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

Unified Diff: src/core/SkXfermode4f.cpp

Issue 1653943002: unroll srcover_1 for blending a single color (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bench/Xfer4fBench.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkXfermode4f.cpp
diff --git a/src/core/SkXfermode4f.cpp b/src/core/SkXfermode4f.cpp
index 0485a5e6edd4c0c65f884eae88b27beb8c9cd637..98b73b527aae5952c7e52ee8b6e472a139b2eeee 100644
--- a/src/core/SkXfermode4f.cpp
+++ b/src/core/SkXfermode4f.cpp
@@ -35,6 +35,16 @@ template <DstType D> uint32_t store_dst(const Sk4f& x4) {
return (D == kSRGB_Dst) ? Sk4f_toS32(x4) : Sk4f_toL32(x4);
}
+template <DstType D> Sk4f linear_to_dst_255(const Sk4f& l4) {
mtklein 2016/02/01 21:55:32 Seems odd to template this on DstType if we're onl
reed1 2016/02/02 14:04:39 I had a bool, but it made reading profiles harder.
mtklein 2016/02/02 14:26:06 No no, I mean, it's weird to template at all. Onl
reed1 2016/02/02 14:45:58 Ah. It *was* being used more generically, until I
+ Sk4f x4;
+ if (D == kSRGB_Dst) {
+ x4 = linear_to_srgb(l4);
+ } else {
+ x4 = l4;
+ }
+ return x4 * Sk4f(255) + Sk4f(0.5f);
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
static Sk4f scale_255_round(const SkPM4f& pm4) {
@@ -276,10 +286,35 @@ template <DstType D> void srcover_1(const SkXfermode::PM4fState& state, uint32_t
dst[i] = store_dst<D>(r4);
}
} else {
+ if (D == kLinear_Dst) {
+ s4 = s4 * Sk4f(255) + Sk4f(0.5f);
mtklein 2016/02/01 21:55:32 I find it really confusing to mutate values condit
reed1 2016/02/02 14:04:39 Agreed. I will give them meaningful names
+ scale = scale * Sk4f(255);
+ }
mtklein 2016/02/01 21:58:44 I'm also curious to see if this hoisting can be do
+ while (count >= 4) {
+ Sk4f d0 = load_dst<D>(dst[0]);
+ Sk4f d1 = load_dst<D>(dst[1]);
+ Sk4f d2 = load_dst<D>(dst[2]);
+ Sk4f d3 = load_dst<D>(dst[3]);
+ if (D == kLinear_Dst) {
+ Sk4f_ToBytes((uint8_t*)dst,
+ s4 + d0 * scale, s4 + d1 * scale, s4 + d2 * scale, s4 + d3 * scale);
mtklein 2016/02/01 21:55:32 Might be nice to line-break after each comma here
reed1 2016/02/02 14:04:39 Agreed.
+ } else {
+ Sk4f_ToBytes((uint8_t*)dst,
+ linear_to_dst_255<D>(s4 + d0 * scale),
+ linear_to_dst_255<D>(s4 + d1 * scale),
+ linear_to_dst_255<D>(s4 + d2 * scale),
+ linear_to_dst_255<D>(s4 + d3 * scale));
+ }
+ dst += 4;
+ count -= 4;
+ }
for (int i = 0; i < count; ++i) {
- Sk4f d4 = load_dst<D>(dst[i]);
- Sk4f r4 = s4 + d4 * scale;
- dst[i] = store_dst<D>(r4);
+ Sk4f r4 = s4 + load_dst<D>(dst[i]) * scale;
+ if (D == kLinear_Dst) {
+ dst[i] = to_4b(r4);
+ } else {
+ dst[i] = store_dst<D>(r4);
+ }
}
}
}
« no previous file with comments | « bench/Xfer4fBench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698