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

Unified Diff: src/core/SkXfermode4f.cpp

Issue 1707883002: lcd blits for sRGB (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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
« include/core/SkXfermode.h ('K') | « src/core/SkBlitter_PM4f.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 9aba0da04f3d63f341df5a6740f5d7c7a5f364fc..84a989623ebdcd76c4dbe74ed2c6ad06a8617990 100644
--- a/src/core/SkXfermode4f.cpp
+++ b/src/core/SkXfermode4f.cpp
@@ -422,3 +422,103 @@ SkXfermode::PM4fProcN SkXfermode::getPM4fProcN(uint32_t flags) const {
Mode mode;
return this->asMode(&mode) ? GetPM4fProcN(mode, flags) : xfer_pm4_proc_n;
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+#include "SkColorPriv.h"
+
+static Sk4f lcd16_to_unit_4f(uint16_t rgb) {
+ Sk4i rgbi = Sk4i(SkGetPackedR16(rgb), SkGetPackedG16(rgb)>>1, SkGetPackedB16(rgb), 0);
mtklein 2016/02/18 13:35:55 Why throw away a green bit? Sk4i rgbi = Sk4i(Sk
reed1 2016/02/18 15:11:35 Was wondering if a single value for the scale was
+ return SkNx_cast<float>(rgbi) * Sk4f(1.0f/31);
+}
+
+template <DstType D>
+void src_1_lcd(uint32_t dst[], const SkPM4f* src, int count, const uint16_t lcd[]) {
+ const Sk4f s4 = Sk4f::Load(src->fVec);
+
+ if (D == kLinear_Dst) {
+ // operate in bias-255 space for src and dst
+ const Sk4f& s4bias = s4 * Sk4f(255);
mtklein 2016/02/18 13:35:55 Seems odd (wrong?) to declare this as a const&.
reed1 2016/02/18 15:11:35 Yes, copy/paste error.
+ for (int i = 0; i < count; ++i) {
+ const unsigned rgb = lcd[i];
mtklein 2016/02/18 13:35:55 Somewhat weird to use unsigned here but pass it as
reed1 2016/02/18 15:11:35 Done. old habit of not wanting the register to be
+ if (0 == rgb) {
+ continue;
+ }
+ Sk4f d4bias = to_4f(dst[i]);
+ dst[i] = to_4b(lerp(s4bias, d4bias, lcd16_to_unit_4f(rgb))) | (SK_A32_MASK << SK_A32_SHIFT);
+ }
+ } else { // kSRGB
+ for (int i = 0; i < count; ++i) {
+ const unsigned rgb = lcd[i];
mtklein 2016/02/18 13:35:55 (here too)
reed1 2016/02/18 15:11:35 Done.
+ if (0 == rgb) {
+ continue;
+ }
+ Sk4f d4 = load_dst<D>(dst[i]);
+ dst[i] = store_dst<D>(lerp(s4, d4, lcd16_to_unit_4f(rgb))) | (SK_A32_MASK << SK_A32_SHIFT);
+ }
+ }
+}
+
+template <DstType D>
+void src_n_lcd(uint32_t dst[], const SkPM4f src[], int count, const uint16_t lcd[]) {
+ for (int i = 0; i < count; ++i) {
+ const unsigned rgb = lcd[i];
mtklein 2016/02/18 13:35:56 No 0 check?
reed1 2016/02/18 15:11:35 Done.
+ Sk4f s4 = Sk4f::Load(src[i].fVec);
+ Sk4f d4 = load_dst<D>(dst[i]);
+ dst[i] = store_dst<D>(lerp(s4, d4, lcd16_to_unit_4f(rgb))) | (SK_A32_MASK << SK_A32_SHIFT);
+ }
+}
+
+template <DstType D>
+void srcover_1_lcd(uint32_t dst[], const SkPM4f* src, int count, const uint16_t lcd[]) {
+ const Sk4f s4 = Sk4f::Load(src->fVec);
+ Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
+
+ for (int i = 0; i < count; ++i) {
+ for (int i = 0; i < count; ++i) {
mtklein 2016/02/18 13:35:55 Hmm... Compilers _hate_ him! One weird trick to s
reed1 2016/02/18 15:11:35 CLEARLY I haven't tested the N case yet :) fixed.
+ const unsigned rgb = lcd[i];
+ if (0 == rgb) {
+ continue;
+ }
+ Sk4f d4 = load_dst<D>(dst[i]);
+ Sk4f r4 = s4 + d4 * dst_scale;
+ if (0xFFFF != rgb) {
+ r4 = lerp(r4, d4, lcd16_to_unit_4f(rgb));
+ }
+ dst[i] = store_dst<D>(r4) | (SK_A32_MASK << SK_A32_SHIFT);
+ }
+ }
+}
+
+template <DstType D>
+void srcover_n_lcd(uint32_t dst[], const SkPM4f src[], int count, const uint16_t lcd[]) {
+ for (int i = 0; i < count; ++i) {
+ for (int i = 0; i < count; ++i) {
mtklein 2016/02/18 13:35:55 (ditto)
reed1 2016/02/18 15:11:35 Done.
+ const unsigned rgb = lcd[i];
+ if (0 == rgb) {
+ continue;
+ }
+ Sk4f s4 = Sk4f::Load(src[i].fVec);
+ Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
+ Sk4f d4 = load_dst<D>(dst[i]);
+ Sk4f r4 = s4 + d4 * dst_scale;
+ if (0xFFFF != rgb) {
+ r4 = lerp(r4, d4, lcd16_to_unit_4f(rgb));
+ }
+ dst[i] = store_dst<D>(r4) | (SK_A32_MASK << SK_A32_SHIFT);
+ }
+ }
+}
+
+SkXfermode::LCD32Proc SkXfermode::GetLCD32Proc(uint32_t flags) {
+ SkASSERT((flags & ~7) == 0);
+ flags &= 7;
+
+ const LCD32Proc procs[] = {
+ srcover_n_lcd<kSRGB_Dst>, src_n_lcd<kSRGB_Dst>,
+ srcover_1_lcd<kSRGB_Dst>, src_1_lcd<kSRGB_Dst>,
+
+ srcover_n_lcd<kLinear_Dst>, src_n_lcd<kLinear_Dst>,
+ srcover_1_lcd<kLinear_Dst>, src_1_lcd<kLinear_Dst>,
+ };
+ return procs[flags];
+}
« include/core/SkXfermode.h ('K') | « src/core/SkBlitter_PM4f.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698