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

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

Issue 2145663003: Expand _01 half<->float limitation to _finite. Simplify. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: drop _mm_packus_epi32 for now. Created 4 years, 5 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') | src/effects/gradients/Sk4fGradientPriv.h » ('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 "SkHalf.h" 8 #include "SkHalf.h"
9 #include "SkPM4fPriv.h" 9 #include "SkPM4fPriv.h"
10 #include "SkUtils.h" 10 #include "SkUtils.h"
11 #include "SkXfermode.h" 11 #include "SkXfermode.h"
12 12
13 static Sk4f lerp_by_coverage(const Sk4f& src, const Sk4f& dst, uint8_t srcCovera ge) { 13 static Sk4f lerp_by_coverage(const Sk4f& src, const Sk4f& dst, uint8_t srcCovera ge) {
14 return dst + (src - dst) * Sk4f(srcCoverage * (1/255.0f)); 14 return dst + (src - dst) * Sk4f(srcCoverage * (1/255.0f));
15 } 15 }
16 16
17 //////////////////////////////////////////////////////////////////////////////// /////////////////// 17 //////////////////////////////////////////////////////////////////////////////// ///////////////////
18 18
19 static void xfer_1(const SkXfermode* xfer, uint64_t dst[], const SkPM4f* src, in t count, 19 static void xfer_1(const SkXfermode* xfer, uint64_t dst[], const SkPM4f* src, in t count,
20 const SkAlpha aa[]) { 20 const SkAlpha aa[]) {
21 SkXfermodeProc4f proc = xfer->getProc4f(); 21 SkXfermodeProc4f proc = xfer->getProc4f();
22 SkPM4f d; 22 SkPM4f d;
23 if (aa) { 23 if (aa) {
24 for (int i = 0; i < count; ++i) { 24 for (int i = 0; i < count; ++i) {
25 Sk4f d4 = SkHalfToFloat_01(dst[i]); 25 Sk4f d4 = SkHalfToFloat_finite(dst[i]);
26 d4.store(d.fVec); 26 d4.store(d.fVec);
27 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec); 27 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec);
28 dst[i] = SkFloatToHalf_01(lerp_by_coverage(r4, d4, aa[i])); 28 dst[i] = SkFloatToHalf_finite(lerp_by_coverage(r4, d4, aa[i]));
29 } 29 }
30 } else { 30 } else {
31 for (int i = 0; i < count; ++i) { 31 for (int i = 0; i < count; ++i) {
32 SkHalfToFloat_01(dst[i]).store(d.fVec); 32 SkHalfToFloat_finite(dst[i]).store(d.fVec);
33 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec); 33 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec);
34 dst[i] = SkFloatToHalf_01(r4); 34 dst[i] = SkFloatToHalf_finite(r4);
35 } 35 }
36 } 36 }
37 } 37 }
38 38
39 static void xfer_n(const SkXfermode* xfer, uint64_t dst[], const SkPM4f src[], i nt count, 39 static void xfer_n(const SkXfermode* xfer, uint64_t dst[], const SkPM4f src[], i nt count,
40 const SkAlpha aa[]) { 40 const SkAlpha aa[]) {
41 SkXfermodeProc4f proc = xfer->getProc4f(); 41 SkXfermodeProc4f proc = xfer->getProc4f();
42 SkPM4f d; 42 SkPM4f d;
43 if (aa) { 43 if (aa) {
44 for (int i = 0; i < count; ++i) { 44 for (int i = 0; i < count; ++i) {
45 Sk4f d4 = SkHalfToFloat_01(dst[i]); 45 Sk4f d4 = SkHalfToFloat_finite(dst[i]);
46 d4.store(d.fVec); 46 d4.store(d.fVec);
47 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec); 47 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec);
48 dst[i] = SkFloatToHalf_01(lerp_by_coverage(r4, d4, aa[i])); 48 dst[i] = SkFloatToHalf_finite(lerp_by_coverage(r4, d4, aa[i]));
49 } 49 }
50 } else { 50 } else {
51 for (int i = 0; i < count; ++i) { 51 for (int i = 0; i < count; ++i) {
52 SkHalfToFloat_01(dst[i]).store(d.fVec); 52 SkHalfToFloat_finite(dst[i]).store(d.fVec);
53 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec); 53 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec);
54 dst[i] = SkFloatToHalf_01(r4); 54 dst[i] = SkFloatToHalf_finite(r4);
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 const SkXfermode::F16Proc gProcs_General[] = { xfer_n, xfer_n, xfer_1, xfer_1 }; 59 const SkXfermode::F16Proc gProcs_General[] = { xfer_n, xfer_n, xfer_1, xfer_1 };
60 60
61 //////////////////////////////////////////////////////////////////////////////// /////////////////// 61 //////////////////////////////////////////////////////////////////////////////// ///////////////////
62 62
63 static void clear(const SkXfermode*, uint64_t dst[], const SkPM4f*, int count, c onst SkAlpha aa[]) { 63 static void clear(const SkXfermode*, uint64_t dst[], const SkPM4f*, int count, c onst SkAlpha aa[]) {
64 if (aa) { 64 if (aa) {
65 for (int i = 0; i < count; ++i) { 65 for (int i = 0; i < count; ++i) {
66 if (aa[i]) { 66 if (aa[i]) {
67 const Sk4f d4 = SkHalfToFloat_01(dst[i]); 67 const Sk4f d4 = SkHalfToFloat_finite(dst[i]);
68 dst[i] = SkFloatToHalf_01(d4 * Sk4f((255 - aa[i]) * 1.0f/255)); 68 dst[i] = SkFloatToHalf_finite(d4 * Sk4f((255 - aa[i]) * 1.0f/255 ));
69 } 69 }
70 } 70 }
71 } else { 71 } else {
72 sk_memset64(dst, 0, count); 72 sk_memset64(dst, 0, count);
73 } 73 }
74 } 74 }
75 75
76 const SkXfermode::F16Proc gProcs_Clear[] = { clear, clear, clear, clear }; 76 const SkXfermode::F16Proc gProcs_Clear[] = { clear, clear, clear, clear };
77 77
78 //////////////////////////////////////////////////////////////////////////////// /////////////////// 78 //////////////////////////////////////////////////////////////////////////////// ///////////////////
79 79
80 static void src_1(const SkXfermode*, uint64_t dst[], const SkPM4f* src, int coun t, 80 static void src_1(const SkXfermode*, uint64_t dst[], const SkPM4f* src, int coun t,
81 const SkAlpha aa[]) { 81 const SkAlpha aa[]) {
82 const Sk4f s4 = Sk4f::Load(src->fVec); 82 const Sk4f s4 = Sk4f::Load(src->fVec);
83 if (aa) { 83 if (aa) {
84 for (int i = 0; i < count; ++i) { 84 for (int i = 0; i < count; ++i) {
85 const Sk4f d4 = SkHalfToFloat_01(dst[i]); 85 const Sk4f d4 = SkHalfToFloat_finite(dst[i]);
86 dst[i] = SkFloatToHalf_01(lerp_by_coverage(s4, d4, aa[i])); 86 dst[i] = SkFloatToHalf_finite(lerp_by_coverage(s4, d4, aa[i]));
87 } 87 }
88 } else { 88 } else {
89 sk_memset64(dst, SkFloatToHalf_01(s4), count); 89 sk_memset64(dst, SkFloatToHalf_finite(s4), count);
90 } 90 }
91 } 91 }
92 92
93 static void src_n(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int cou nt, 93 static void src_n(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int cou nt,
94 const SkAlpha aa[]) { 94 const SkAlpha aa[]) {
95 if (aa) { 95 if (aa) {
96 for (int i = 0; i < count; ++i) { 96 for (int i = 0; i < count; ++i) {
97 const Sk4f s4 = Sk4f::Load(src[i].fVec); 97 const Sk4f s4 = Sk4f::Load(src[i].fVec);
98 const Sk4f d4 = SkHalfToFloat_01(dst[i]); 98 const Sk4f d4 = SkHalfToFloat_finite(dst[i]);
99 dst[i] = SkFloatToHalf_01(lerp_by_coverage(s4, d4, aa[i])); 99 dst[i] = SkFloatToHalf_finite(lerp_by_coverage(s4, d4, aa[i]));
100 } 100 }
101 } else { 101 } else {
102 for (int i = 0; i < count; ++i) { 102 for (int i = 0; i < count; ++i) {
103 const Sk4f s4 = Sk4f::Load(src[i].fVec); 103 const Sk4f s4 = Sk4f::Load(src[i].fVec);
104 dst[i] = SkFloatToHalf_01(s4); 104 dst[i] = SkFloatToHalf_finite(s4);
105 } 105 }
106 } 106 }
107 } 107 }
108 108
109 const SkXfermode::F16Proc gProcs_Src[] = { src_n, src_n, src_1, src_1 }; 109 const SkXfermode::F16Proc gProcs_Src[] = { src_n, src_n, src_1, src_1 };
110 110
111 //////////////////////////////////////////////////////////////////////////////// /////////////////// 111 //////////////////////////////////////////////////////////////////////////////// ///////////////////
112 112
113 static void dst(const SkXfermode*, uint64_t*, const SkPM4f*, int count, const Sk Alpha[]) {} 113 static void dst(const SkXfermode*, uint64_t*, const SkPM4f*, int count, const Sk Alpha[]) {}
114 114
115 const SkXfermode::F16Proc gProcs_Dst[] = { dst, dst, dst, dst }; 115 const SkXfermode::F16Proc gProcs_Dst[] = { dst, dst, dst, dst };
116 116
117 //////////////////////////////////////////////////////////////////////////////// /////////////////// 117 //////////////////////////////////////////////////////////////////////////////// ///////////////////
118 118
119 static void srcover_1(const SkXfermode*, uint64_t dst[], const SkPM4f* src, int count, 119 static void srcover_1(const SkXfermode*, uint64_t dst[], const SkPM4f* src, int count,
120 const SkAlpha aa[]) { 120 const SkAlpha aa[]) {
121 const Sk4f s4 = Sk4f::Load(src->fVec); 121 const Sk4f s4 = Sk4f::Load(src->fVec);
122 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); 122 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
123 for (int i = 0; i < count; ++i) { 123 for (int i = 0; i < count; ++i) {
124 const Sk4f d4 = SkHalfToFloat_01(dst[i]); 124 const Sk4f d4 = SkHalfToFloat_finite(dst[i]);
125 const Sk4f r4 = s4 + d4 * dst_scale; 125 const Sk4f r4 = s4 + d4 * dst_scale;
126 if (aa) { 126 if (aa) {
127 dst[i] = SkFloatToHalf_01(lerp_by_coverage(r4, d4, aa[i])); 127 dst[i] = SkFloatToHalf_finite(lerp_by_coverage(r4, d4, aa[i]));
128 } else { 128 } else {
129 dst[i] = SkFloatToHalf_01(r4); 129 dst[i] = SkFloatToHalf_finite(r4);
130 } 130 }
131 } 131 }
132 } 132 }
133 133
134 static void srcover_n(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int count, 134 static void srcover_n(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int count,
135 const SkAlpha aa[]) { 135 const SkAlpha aa[]) {
136 for (int i = 0; i < count; ++i) { 136 for (int i = 0; i < count; ++i) {
137 Sk4f s = Sk4f::Load(src+i), 137 Sk4f s = Sk4f::Load(src+i),
138 d = SkHalfToFloat_01(dst[i]), 138 d = SkHalfToFloat_finite(dst[i]),
139 r = s + d*(1.0f - SkNx_shuffle<3,3,3,3>(s)); 139 r = s + d*(1.0f - SkNx_shuffle<3,3,3,3>(s));
140 if (aa) { 140 if (aa) {
141 r = lerp_by_coverage(r, d, aa[i]); 141 r = lerp_by_coverage(r, d, aa[i]);
142 } 142 }
143 dst[i] = SkFloatToHalf_01(r); 143 dst[i] = SkFloatToHalf_finite(r);
144 } 144 }
145 } 145 }
146 146
147 const SkXfermode::F16Proc gProcs_SrcOver[] = { srcover_n, src_n, srcover_1, src_ 1 }; 147 const SkXfermode::F16Proc gProcs_SrcOver[] = { srcover_n, src_n, srcover_1, src_ 1 };
148 148
149 //////////////////////////////////////////////////////////////////////////////// /////////////////// 149 //////////////////////////////////////////////////////////////////////////////// ///////////////////
150 150
151 static SkXfermode::F16Proc find_proc(SkXfermode::Mode mode, uint32_t flags) { 151 static SkXfermode::F16Proc find_proc(SkXfermode::Mode mode, uint32_t flags) {
152 SkASSERT(0 == (flags & ~3)); 152 SkASSERT(0 == (flags & ~3));
153 flags &= 3; 153 flags &= 3;
(...skipping 13 matching lines...) Expand all
167 SkASSERT(0 == (flags & ~3)); 167 SkASSERT(0 == (flags & ~3));
168 flags &= 3; 168 flags &= 3;
169 169
170 Mode mode; 170 Mode mode;
171 return this->asMode(&mode) ? find_proc(mode, flags) : gProcs_General[flags]; 171 return this->asMode(&mode) ? find_proc(mode, flags) : gProcs_General[flags];
172 } 172 }
173 173
174 SkXfermode::F16Proc SkXfermode::GetF16Proc(SkXfermode* xfer, uint32_t flags) { 174 SkXfermode::F16Proc SkXfermode::GetF16Proc(SkXfermode* xfer, uint32_t flags) {
175 return xfer ? xfer->onGetF16Proc(flags) : find_proc(SkXfermode::kSrcOver_Mod e, flags); 175 return xfer ? xfer->onGetF16Proc(flags) : find_proc(SkXfermode::kSrcOver_Mod e, flags);
176 } 176 }
OLDNEW
« no previous file with comments | « src/core/SkSpanProcs.cpp ('k') | src/effects/gradients/Sk4fGradientPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698