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

Side by Side Diff: src/core/SkXfermode4f.cpp

Issue 1774523002: make pm4f be RGBA always, not pmcolor order (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « src/core/SkSpanProcs.cpp ('k') | tests/SkColor4fTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPM4fPriv.h" 8 #include "SkPM4fPriv.h"
9 #include "SkUtils.h" 9 #include "SkUtils.h"
10 #include "SkXfermode.h" 10 #include "SkXfermode.h"
11 11
12 static SkPM4f rgba_to_pmcolor_order(const SkPM4f& x) {
13 #ifdef SK_PMCOLOR_IS_BGRA
14 return {{ x.fVec[2], x.fVec[1], x.fVec[0], x.fVec[3] }};
15 #else
16 return x;
17 #endif
18 }
19
12 enum DstType { 20 enum DstType {
13 kLinear_Dst, 21 kLinear_Dst,
14 kSRGB_Dst, 22 kSRGB_Dst,
15 }; 23 };
16 24
17 static Sk4f scale_by_coverage(const Sk4f& x4, uint8_t coverage) { 25 static Sk4f scale_by_coverage(const Sk4f& x4, uint8_t coverage) {
18 return x4 * Sk4f(coverage * (1/255.0f)); 26 return x4 * Sk4f(coverage * (1/255.0f));
19 } 27 }
20 28
21 static Sk4f lerp(const Sk4f& src, const Sk4f& dst, uint8_t srcCoverage) { 29 static Sk4f lerp(const Sk4f& src, const Sk4f& dst, uint8_t srcCoverage) {
(...skipping 13 matching lines...) Expand all
35 } 43 }
36 44
37 static Sk4f linear_unit_to_srgb_255f(const Sk4f& l4) { 45 static Sk4f linear_unit_to_srgb_255f(const Sk4f& l4) {
38 return linear_to_srgb(l4) * Sk4f(255) + Sk4f(0.5f); 46 return linear_to_srgb(l4) * Sk4f(255) + Sk4f(0.5f);
39 } 47 }
40 48
41 //////////////////////////////////////////////////////////////////////////////// /////////////////// 49 //////////////////////////////////////////////////////////////////////////////// ///////////////////
42 50
43 template <DstType D> void general_1(const SkXfermode* xfer, uint32_t dst[], 51 template <DstType D> void general_1(const SkXfermode* xfer, uint32_t dst[],
44 const SkPM4f* src, int count, const SkAlpha aa[]) { 52 const SkPM4f* src, int count, const SkAlpha aa[]) {
53 const SkPM4f s = rgba_to_pmcolor_order(*src);
45 SkXfermodeProc4f proc = xfer->getProc4f(); 54 SkXfermodeProc4f proc = xfer->getProc4f();
46 SkPM4f d; 55 SkPM4f d;
47 if (aa) { 56 if (aa) {
48 for (int i = 0; i < count; ++i) { 57 for (int i = 0; i < count; ++i) {
49 Sk4f d4 = load_dst<D>(dst[i]); 58 Sk4f d4 = load_dst<D>(dst[i]);
50 d4.store(d.fVec); 59 d4.store(d.fVec);
51 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec); 60 Sk4f r4 = Sk4f::Load(proc(s, d).fVec);
52 dst[i] = store_dst<D>(lerp(r4, d4, aa[i])); 61 dst[i] = store_dst<D>(lerp(r4, d4, aa[i]));
53 } 62 }
54 } else { 63 } else {
55 for (int i = 0; i < count; ++i) { 64 for (int i = 0; i < count; ++i) {
56 load_dst<D>(dst[i]).store(d.fVec); 65 load_dst<D>(dst[i]).store(d.fVec);
57 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec); 66 Sk4f r4 = Sk4f::Load(proc(s, d).fVec);
58 dst[i] = store_dst<D>(r4); 67 dst[i] = store_dst<D>(r4);
59 } 68 }
60 } 69 }
61 } 70 }
62 71
63 template <DstType D> void general_n(const SkXfermode* xfer, uint32_t dst[], 72 template <DstType D> void general_n(const SkXfermode* xfer, uint32_t dst[],
64 const SkPM4f src[], int count, const SkAlpha aa[]) { 73 const SkPM4f src[], int count, const SkAlpha aa[]) {
65 SkXfermodeProc4f proc = xfer->getProc4f(); 74 SkXfermodeProc4f proc = xfer->getProc4f();
66 SkPM4f d; 75 SkPM4f d;
67 if (aa) { 76 if (aa) {
68 for (int i = 0; i < count; ++i) { 77 for (int i = 0; i < count; ++i) {
69 Sk4f d4 = load_dst<D>(dst[i]); 78 Sk4f d4 = load_dst<D>(dst[i]);
70 d4.store(d.fVec); 79 d4.store(d.fVec);
71 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec); 80 Sk4f r4 = Sk4f::Load(proc(rgba_to_pmcolor_order(src[i]), d).fVec);
72 dst[i] = store_dst<D>(lerp(r4, d4, aa[i])); 81 dst[i] = store_dst<D>(lerp(r4, d4, aa[i]));
73 } 82 }
74 } else { 83 } else {
75 for (int i = 0; i < count; ++i) { 84 for (int i = 0; i < count; ++i) {
76 load_dst<D>(dst[i]).store(d.fVec); 85 load_dst<D>(dst[i]).store(d.fVec);
77 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec); 86 Sk4f r4 = Sk4f::Load(proc(rgba_to_pmcolor_order(src[i]), d).fVec);
78 dst[i] = store_dst<D>(r4); 87 dst[i] = store_dst<D>(r4);
79 } 88 }
80 } 89 }
81 } 90 }
82 91
83 const SkXfermode::D32Proc gProcs_General[] = { 92 const SkXfermode::D32Proc gProcs_General[] = {
84 general_n<kLinear_Dst>, general_n<kLinear_Dst>, 93 general_n<kLinear_Dst>, general_n<kLinear_Dst>,
85 general_1<kLinear_Dst>, general_1<kLinear_Dst>, 94 general_1<kLinear_Dst>, general_1<kLinear_Dst>,
86 general_n<kSRGB_Dst>, general_n<kSRGB_Dst>, 95 general_n<kSRGB_Dst>, general_n<kSRGB_Dst>,
87 general_1<kSRGB_Dst>, general_1<kSRGB_Dst>, 96 general_1<kSRGB_Dst>, general_1<kSRGB_Dst>,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 template <DstType D> void src_n(const SkXfermode*, uint32_t dst[], 143 template <DstType D> void src_n(const SkXfermode*, uint32_t dst[],
135 const SkPM4f src[], int count, const SkAlpha aa[ ]) { 144 const SkPM4f src[], int count, const SkAlpha aa[ ]) {
136 for (int i = 0; i < count; ++i) { 145 for (int i = 0; i < count; ++i) {
137 unsigned a = 0xFF; 146 unsigned a = 0xFF;
138 if (aa) { 147 if (aa) {
139 a = aa[i]; 148 a = aa[i];
140 if (0 == a) { 149 if (0 == a) {
141 continue; 150 continue;
142 } 151 }
143 } 152 }
144 Sk4f r4 = Sk4f::Load(src[i].fVec); // src always overrides dst 153 Sk4f r4 = src[i].to4f_pmorder();
145 if (a != 0xFF) { 154 if (a != 0xFF) {
146 Sk4f d4 = load_dst<D>(dst[i]); 155 Sk4f d4 = load_dst<D>(dst[i]);
147 r4 = lerp(r4, d4, a); 156 r4 = lerp(r4, d4, a);
148 } 157 }
149 dst[i] = store_dst<D>(r4); 158 dst[i] = store_dst<D>(r4);
150 } 159 }
151 } 160 }
152 161
153 static Sk4f lerp(const Sk4f& src, const Sk4f& dst, const Sk4f& src_scale) { 162 static Sk4f lerp(const Sk4f& src, const Sk4f& dst, const Sk4f& src_scale) {
154 return dst + (src - dst) * src_scale; 163 return dst + (src - dst) * src_scale;
155 } 164 }
156 165
157 template <DstType D> void src_1(const SkXfermode*, uint32_t dst[], 166 template <DstType D> void src_1(const SkXfermode*, uint32_t dst[],
158 const SkPM4f* src, int count, const SkAlpha aa[] ) { 167 const SkPM4f* src, int count, const SkAlpha aa[] ) {
159 const Sk4f s4 = Sk4f::Load(src->fVec); 168 const Sk4f s4 = src->to4f_pmorder();
160 169
161 if (aa) { 170 if (aa) {
162 if (D == kLinear_Dst) { 171 if (D == kLinear_Dst) {
163 // operate in bias-255 space for src and dst 172 // operate in bias-255 space for src and dst
164 const Sk4f& s4_255 = s4 * Sk4f(255); 173 const Sk4f& s4_255 = s4 * Sk4f(255);
165 while (count >= 4) { 174 while (count >= 4) {
166 Sk4f aa4 = SkNx_cast<float>(Sk4b::Load(aa)) * Sk4f(1/255.f); 175 Sk4f aa4 = SkNx_cast<float>(Sk4b::Load(aa)) * Sk4f(1/255.f);
167 Sk4f r0 = lerp(s4_255, to_4f(dst[0]), Sk4f(aa4[0])) + Sk4f(0.5f) ; 176 Sk4f r0 = lerp(s4_255, to_4f(dst[0]), Sk4f(aa4[0])) + Sk4f(0.5f) ;
168 Sk4f r1 = lerp(s4_255, to_4f(dst[1]), Sk4f(aa4[1])) + Sk4f(0.5f) ; 177 Sk4f r1 = lerp(s4_255, to_4f(dst[1]), Sk4f(aa4[1])) + Sk4f(0.5f) ;
169 Sk4f r2 = lerp(s4_255, to_4f(dst[2]), Sk4f(aa4[2])) + Sk4f(0.5f) ; 178 Sk4f r2 = lerp(s4_255, to_4f(dst[2]), Sk4f(aa4[2])) + Sk4f(0.5f) ;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 //////////////////////////////////////////////////////////////////////////////// /////////////////// 234 //////////////////////////////////////////////////////////////////////////////// ///////////////////
226 235
227 template <DstType D> void srcover_n(const SkXfermode*, uint32_t dst[], 236 template <DstType D> void srcover_n(const SkXfermode*, uint32_t dst[],
228 const SkPM4f src[], int count, const SkAlpha aa[]) { 237 const SkPM4f src[], int count, const SkAlpha aa[]) {
229 if (aa) { 238 if (aa) {
230 for (int i = 0; i < count; ++i) { 239 for (int i = 0; i < count; ++i) {
231 unsigned a = aa[i]; 240 unsigned a = aa[i];
232 if (0 == a) { 241 if (0 == a) {
233 continue; 242 continue;
234 } 243 }
235 Sk4f s4 = Sk4f::Load(src[i].fVec); 244 Sk4f s4 = src[i].to4f_pmorder();
236 Sk4f d4 = load_dst<D>(dst[i]); 245 Sk4f d4 = load_dst<D>(dst[i]);
237 if (a != 0xFF) { 246 if (a != 0xFF) {
238 s4 = scale_by_coverage(s4, a); 247 s4 = scale_by_coverage(s4, a);
239 } 248 }
240 Sk4f r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); 249 Sk4f r4 = s4 + d4 * Sk4f(1 - get_alpha(s4));
241 dst[i] = store_dst<D>(r4); 250 dst[i] = store_dst<D>(r4);
242 } 251 }
243 } else { 252 } else {
244 for (int i = 0; i < count; ++i) { 253 for (int i = 0; i < count; ++i) {
245 Sk4f s4 = Sk4f::Load(src[i].fVec); 254 Sk4f s4 = src[i].to4f_pmorder();
246 Sk4f d4 = load_dst<D>(dst[i]); 255 Sk4f d4 = load_dst<D>(dst[i]);
247 Sk4f r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); 256 Sk4f r4 = s4 + d4 * Sk4f(1 - get_alpha(s4));
248 dst[i] = store_dst<D>(r4); 257 dst[i] = store_dst<D>(r4);
249 } 258 }
250 } 259 }
251 } 260 }
252 261
253 static void srcover_linear_dst_1(const SkXfermode*, uint32_t dst[], 262 static void srcover_linear_dst_1(const SkXfermode*, uint32_t dst[],
254 const SkPM4f* src, int count, const SkAlpha aa[ ]) { 263 const SkPM4f* src, int count, const SkAlpha aa[ ]) {
255 const Sk4f s4 = Sk4f::Load(src->fVec); 264 const Sk4f s4 = src->to4f_pmorder();
256 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); 265 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
257 266
258 if (aa) { 267 if (aa) {
259 for (int i = 0; i < count; ++i) { 268 for (int i = 0; i < count; ++i) {
260 unsigned a = aa[i]; 269 unsigned a = aa[i];
261 if (0 == a) { 270 if (0 == a) {
262 continue; 271 continue;
263 } 272 }
264 Sk4f d4 = Sk4f_fromL32(dst[i]); 273 Sk4f d4 = Sk4f_fromL32(dst[i]);
265 Sk4f r4; 274 Sk4f r4;
(...skipping 22 matching lines...) Expand all
288 } 297 }
289 for (int i = 0; i < count; ++i) { 298 for (int i = 0; i < count; ++i) {
290 Sk4f d4 = to_4f(dst[i]); 299 Sk4f d4 = to_4f(dst[i]);
291 dst[i] = to_4b(s4_255 + d4 * dst_scale); 300 dst[i] = to_4b(s4_255 + d4 * dst_scale);
292 } 301 }
293 } 302 }
294 } 303 }
295 304
296 static void srcover_srgb_dst_1(const SkXfermode*, uint32_t dst[], 305 static void srcover_srgb_dst_1(const SkXfermode*, uint32_t dst[],
297 const SkPM4f* src, int count, const SkAlpha aa[]) { 306 const SkPM4f* src, int count, const SkAlpha aa[]) {
298 Sk4f s4 = Sk4f::Load(src->fVec); 307 Sk4f s4 = src->to4f_pmorder();
299 Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); 308 Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
300 309
301 if (aa) { 310 if (aa) {
302 for (int i = 0; i < count; ++i) { 311 for (int i = 0; i < count; ++i) {
303 unsigned a = aa[i]; 312 unsigned a = aa[i];
304 if (0 == a) { 313 if (0 == a) {
305 continue; 314 continue;
306 } 315 }
307 Sk4f d4 = srgb_4b_to_linear_unit(dst[i]); 316 Sk4f d4 = srgb_4b_to_linear_unit(dst[i]);
308 Sk4f r4; 317 Sk4f r4;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 472
464 const LCD32Proc procs[] = { 473 const LCD32Proc procs[] = {
465 srcover_n_lcd<kSRGB_Dst>, src_n_lcd<kSRGB_Dst>, 474 srcover_n_lcd<kSRGB_Dst>, src_n_lcd<kSRGB_Dst>,
466 srcover_1_lcd<kSRGB_Dst>, src_1_lcd<kSRGB_Dst>, 475 srcover_1_lcd<kSRGB_Dst>, src_1_lcd<kSRGB_Dst>,
467 476
468 srcover_n_lcd<kLinear_Dst>, src_n_lcd<kLinear_Dst>, 477 srcover_n_lcd<kLinear_Dst>, src_n_lcd<kLinear_Dst>,
469 srcover_1_lcd<kLinear_Dst>, src_1_lcd<kLinear_Dst>, 478 srcover_1_lcd<kLinear_Dst>, src_1_lcd<kLinear_Dst>,
470 }; 479 };
471 return procs[flags]; 480 return procs[flags];
472 } 481 }
OLDNEW
« no previous file with comments | « src/core/SkSpanProcs.cpp ('k') | tests/SkColor4fTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698