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

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

Issue 1685203002: lots of sRGB and F16 blits (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use SkAutoTMalloc 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 unified diff | Download patch
« no previous file with comments | « src/core/SkXfermode.cpp ('k') | src/core/SkXfermodeU64.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"
(...skipping 27 matching lines...) Expand all
38 template <DstType D> uint32_t store_dst(const Sk4f& x4) { 38 template <DstType D> uint32_t store_dst(const Sk4f& x4) {
39 return (D == kSRGB_Dst) ? Sk4f_toS32(x4) : Sk4f_toL32(x4); 39 return (D == kSRGB_Dst) ? Sk4f_toS32(x4) : Sk4f_toL32(x4);
40 } 40 }
41 41
42 static Sk4f linear_unit_to_srgb_255f(const Sk4f& l4) { 42 static Sk4f linear_unit_to_srgb_255f(const Sk4f& l4) {
43 return linear_to_srgb(l4) * Sk4f(255) + Sk4f(0.5f); 43 return linear_to_srgb(l4) * Sk4f(255) + Sk4f(0.5f);
44 } 44 }
45 45
46 //////////////////////////////////////////////////////////////////////////////// /////////////////// 46 //////////////////////////////////////////////////////////////////////////////// ///////////////////
47 47
48 static Sk4f scale_255_round(const SkPM4f& pm4) { 48 template <DstType D> void general_1(const SkXfermode::PM4fState& state, uint32_t dst[],
49 return Sk4f::Load(pm4.fVec) * Sk4f(255) + Sk4f(0.5f); 49 const SkPM4f& src, int count, const SkAlpha aa[]) {
50 } 50 SkXfermodeProc4f proc = state.fXfer->getProc4f();
51 51 SkPM4f d;
52 static void pm4f_to_linear_32(SkPMColor dst[], const SkPM4f src[], int count) { 52 if (aa) {
53 while (count >= 4) { 53 for (int i = 0; i < count; ++i) {
54 src[0].assertIsUnit(); 54 Sk4f d4 = load_dst<D>(dst[i]);
55 src[1].assertIsUnit(); 55 d4.store(d.fVec);
56 src[2].assertIsUnit(); 56 Sk4f r4 = Sk4f::Load(proc(src, d).fVec);
57 src[3].assertIsUnit(); 57 dst[i] = store_dst<D>(lerp(r4, d4, aa[i]));
58 Sk4f_ToBytes((uint8_t*)dst, 58 }
59 scale_255_round(src[0]), scale_255_round(src[1]), 59 } else {
60 scale_255_round(src[2]), scale_255_round(src[3])); 60 for (int i = 0; i < count; ++i) {
61 src += 4; 61 load_dst<D>(dst[i]).store(d.fVec);
62 dst += 4; 62 Sk4f r4 = Sk4f::Load(proc(src, d).fVec);
63 count -= 4; 63 dst[i] = store_dst<D>(r4);
64 } 64 }
65 for (int i = 0; i < count; ++i) {
66 src[i].assertIsUnit();
67 SkNx_cast<uint8_t>(scale_255_round(src[i])).store((uint8_t*)&dst[i]);
68 } 65 }
69 } 66 }
70 67
71 //////////////////////////////////////////////////////////////////////////////// /////////////////// 68 template <DstType D> void general_n(const SkXfermode::PM4fState& state, uint32_t dst[],
72 // These are our fallback impl for the SkPM4f procs... 69 const SkPM4f src[], int count, const SkAlpha aa[]) {
73 // 70 SkXfermodeProc4f proc = state.fXfer->getProc4f();
74 // They just convert the src color(s) into a linear SkPMColor value(s), and then 71 SkPM4f d;
75 // call the existing virtual xfer32. This clear throws away data (converting flo ats to bytes) 72 if (aa) {
76 // in the src, and ignores the sRGB flag, but should draw about the same as if t he caller 73 for (int i = 0; i < count; ++i) {
77 // had passed in SkPMColor values directly. 74 Sk4f d4 = load_dst<D>(dst[i]);
78 // 75 d4.store(d.fVec);
79 76 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec);
80 void xfer_pm4_proc_1(const SkXfermode::PM4fState& state, uint32_t dst[], const S kPM4f& src, 77 dst[i] = store_dst<D>(lerp(r4, d4, aa[i]));
81 int count, const SkAlpha aa[]) {
82 uint32_t pm;
83 pm4f_to_linear_32(&pm, &src, 1);
84
85 const int N = 128;
86 SkPMColor tmp[N];
87 sk_memset32(tmp, pm, SkMin32(count, N));
88 while (count > 0) {
89 const int n = SkMin32(count, N);
90 state.fXfer->xfer32(dst, tmp, n, aa);
91
92 dst += n;
93 if (aa) {
94 aa += n;
95 } 78 }
96 count -= n; 79 } else {
80 for (int i = 0; i < count; ++i) {
81 load_dst<D>(dst[i]).store(d.fVec);
82 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec);
83 dst[i] = store_dst<D>(r4);
84 }
97 } 85 }
98 } 86 }
99 87
100 void xfer_pm4_proc_n(const SkXfermode::PM4fState& state, uint32_t dst[], const S kPM4f src[], 88 const XferProcPair gProcs_General[] = {
101 int count, const SkAlpha aa[]) { 89 { general_1<kLinear_Dst>, general_n<kLinear_Dst> }, // linear alpha
102 const int N = 128; 90 { general_1<kLinear_Dst>, general_n<kLinear_Dst> }, // linear opaque
103 SkPMColor tmp[N]; 91 { general_1<kSRGB_Dst>, general_n<kSRGB_Dst> }, // srgb alpha
104 while (count > 0) { 92 { general_1<kSRGB_Dst>, general_n<kSRGB_Dst> }, // srgb opaque
105 const int n = SkMin32(count, N); 93 };
106 pm4f_to_linear_32(tmp, src, n);
107 state.fXfer->xfer32(dst, tmp, n, aa);
108
109 src += n;
110 dst += n;
111 if (aa) {
112 aa += n;
113 }
114 count -= n;
115 }
116 }
117 94
118 //////////////////////////////////////////////////////////////////////////////// /////////////////// 95 //////////////////////////////////////////////////////////////////////////////// ///////////////////
119 96
120 static void clear_linear_n(const SkXfermode::PM4fState& state, uint32_t dst[], c onst SkPM4f[], 97 static void clear_linear_n(const SkXfermode::PM4fState& state, uint32_t dst[], c onst SkPM4f[],
121 int count, const SkAlpha aa[]) { 98 int count, const SkAlpha aa[]) {
122 if (aa) { 99 if (aa) {
123 for (int i = 0; i < count; ++i) { 100 for (int i = 0; i < count; ++i) {
124 unsigned a = aa[i]; 101 unsigned a = aa[i];
125 if (a) { 102 if (a) {
126 SkPMColor dstC = dst[i]; 103 SkPMColor dstC = dst[i];
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 flags &= 3; 372 flags &= 3;
396 373
397 switch (mode) { 374 switch (mode) {
398 case SkXfermode::kClear_Mode: return gProcs_Clear[flags]; 375 case SkXfermode::kClear_Mode: return gProcs_Clear[flags];
399 case SkXfermode::kSrc_Mode: return gProcs_Src[flags]; 376 case SkXfermode::kSrc_Mode: return gProcs_Src[flags];
400 case SkXfermode::kDst_Mode: return gProcs_Dst[flags]; 377 case SkXfermode::kDst_Mode: return gProcs_Dst[flags];
401 case SkXfermode::kSrcOver_Mode: return gProcs_SrcOver[flags]; 378 case SkXfermode::kSrcOver_Mode: return gProcs_SrcOver[flags];
402 default: 379 default:
403 break; 380 break;
404 } 381 }
405 return { xfer_pm4_proc_1, xfer_pm4_proc_n }; 382 return gProcs_General[flags];
406 } 383 }
407 384
408 SkXfermode::PM4fProc1 SkXfermode::GetPM4fProc1(Mode mode, uint32_t flags) { 385 SkXfermode::PM4fProc1 SkXfermode::GetPM4fProc1(Mode mode, uint32_t flags) {
409 return find_procs(mode, flags).fP1; 386 return find_procs(mode, flags).fP1;
410 } 387 }
411 388
412 SkXfermode::PM4fProcN SkXfermode::GetPM4fProcN(Mode mode, uint32_t flags) { 389 SkXfermode::PM4fProcN SkXfermode::GetPM4fProcN(Mode mode, uint32_t flags) {
413 return find_procs(mode, flags).fPN; 390 return find_procs(mode, flags).fPN;
414 } 391 }
415 392
416 SkXfermode::PM4fProc1 SkXfermode::getPM4fProc1(uint32_t flags) const { 393 SkXfermode::PM4fProc1 SkXfermode::getPM4fProc1(uint32_t flags) const {
394 SkASSERT(0 == (flags & ~3));
395 flags &= 3;
396
417 Mode mode; 397 Mode mode;
418 return this->asMode(&mode) ? GetPM4fProc1(mode, flags) : xfer_pm4_proc_1; 398 return this->asMode(&mode) ? GetPM4fProc1(mode, flags) : gProcs_General[flag s].fP1;
419 } 399 }
420 400
421 SkXfermode::PM4fProcN SkXfermode::getPM4fProcN(uint32_t flags) const { 401 SkXfermode::PM4fProcN SkXfermode::getPM4fProcN(uint32_t flags) const {
402 SkASSERT(0 == (flags & ~3));
403 flags &= 3;
404
422 Mode mode; 405 Mode mode;
423 return this->asMode(&mode) ? GetPM4fProcN(mode, flags) : xfer_pm4_proc_n; 406 return this->asMode(&mode) ? GetPM4fProcN(mode, flags) : gProcs_General[flag s].fPN;
424 } 407 }
425 408
426 //////////////////////////////////////////////////////////////////////////////// /////////////////// 409 //////////////////////////////////////////////////////////////////////////////// ///////////////////
427 #include "SkColorPriv.h" 410 #include "SkColorPriv.h"
428 411
429 static Sk4f lcd16_to_unit_4f(uint16_t rgb) { 412 static Sk4f lcd16_to_unit_4f(uint16_t rgb) {
430 #ifdef SK_PMCOLOR_IS_RGBA 413 #ifdef SK_PMCOLOR_IS_RGBA
431 Sk4i rgbi = Sk4i(SkGetPackedR16(rgb), SkGetPackedG16(rgb), SkGetPackedB16(rg b), 0); 414 Sk4i rgbi = Sk4i(SkGetPackedR16(rgb), SkGetPackedG16(rgb), SkGetPackedB16(rg b), 0);
432 #else 415 #else
433 Sk4i rgbi = Sk4i(SkGetPackedB16(rgb), SkGetPackedG16(rgb), SkGetPackedR16(rg b), 0); 416 Sk4i rgbi = Sk4i(SkGetPackedB16(rgb), SkGetPackedG16(rgb), SkGetPackedR16(rg b), 0);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 497
515 const LCD32Proc procs[] = { 498 const LCD32Proc procs[] = {
516 srcover_n_lcd<kSRGB_Dst>, src_n_lcd<kSRGB_Dst>, 499 srcover_n_lcd<kSRGB_Dst>, src_n_lcd<kSRGB_Dst>,
517 srcover_1_lcd<kSRGB_Dst>, src_1_lcd<kSRGB_Dst>, 500 srcover_1_lcd<kSRGB_Dst>, src_1_lcd<kSRGB_Dst>,
518 501
519 srcover_n_lcd<kLinear_Dst>, src_n_lcd<kLinear_Dst>, 502 srcover_n_lcd<kLinear_Dst>, src_n_lcd<kLinear_Dst>,
520 srcover_1_lcd<kLinear_Dst>, src_1_lcd<kLinear_Dst>, 503 srcover_1_lcd<kLinear_Dst>, src_1_lcd<kLinear_Dst>,
521 }; 504 };
522 return procs[flags]; 505 return procs[flags];
523 } 506 }
OLDNEW
« no previous file with comments | « src/core/SkXfermode.cpp ('k') | src/core/SkXfermodeU64.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698