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

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

Issue 1889753002: remove U16 support, just support F16 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address reviewer comments, mostly fixing class/function names Created 4 years, 8 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/SkSpriteBlitter4f.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
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkHalf.h"
9 #include "SkPM4fPriv.h"
10 #include "SkUtils.h"
11 #include "SkXfermode.h"
12
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));
15 }
16
17 //////////////////////////////////////////////////////////////////////////////// ///////////////////
18
19 static void xfer_1(const SkXfermode* xfer, uint64_t dst[], const SkPM4f* src, in t count,
20 const SkAlpha aa[]) {
21 SkXfermodeProc4f proc = xfer->getProc4f();
22 SkPM4f d;
23 if (aa) {
24 for (int i = 0; i < count; ++i) {
25 Sk4f d4 = SkHalfToFloat_01(dst[i]);
26 d4.store(d.fVec);
27 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec);
28 dst[i] = SkFloatToHalf_01(lerp_by_coverage(r4, d4, aa[i]));
29 }
30 } else {
31 for (int i = 0; i < count; ++i) {
32 SkHalfToFloat_01(dst[i]).store(d.fVec);
33 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec);
34 dst[i] = SkFloatToHalf_01(r4);
35 }
36 }
37 }
38
39 static void xfer_n(const SkXfermode* xfer, uint64_t dst[], const SkPM4f src[], i nt count,
40 const SkAlpha aa[]) {
41 SkXfermodeProc4f proc = xfer->getProc4f();
42 SkPM4f d;
43 if (aa) {
44 for (int i = 0; i < count; ++i) {
45 Sk4f d4 = SkHalfToFloat_01(dst[i]);
46 d4.store(d.fVec);
47 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec);
48 dst[i] = SkFloatToHalf_01(lerp_by_coverage(r4, d4, aa[i]));
49 }
50 } else {
51 for (int i = 0; i < count; ++i) {
52 SkHalfToFloat_01(dst[i]).store(d.fVec);
53 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec);
54 dst[i] = SkFloatToHalf_01(r4);
55 }
56 }
57 }
58
59 const SkXfermode::F16Proc gProcs_General[] = { xfer_n, xfer_n, xfer_1, xfer_1 };
60
61 //////////////////////////////////////////////////////////////////////////////// ///////////////////
62
63 static void clear(const SkXfermode*, uint64_t dst[], const SkPM4f*, int count, c onst SkAlpha aa[]) {
64 if (aa) {
65 for (int i = 0; i < count; ++i) {
66 if (aa[i]) {
67 const Sk4f d4 = SkHalfToFloat_01(dst[i]);
68 dst[i] = SkFloatToHalf_01(d4 * Sk4f((255 - aa[i]) * 1.0f/255));
69 }
70 }
71 } else {
72 sk_memset64(dst, 0, count);
73 }
74 }
75
76 const SkXfermode::F16Proc gProcs_Clear[] = { clear, clear, clear, clear };
77
78 //////////////////////////////////////////////////////////////////////////////// ///////////////////
79
80 static void src_1(const SkXfermode*, uint64_t dst[], const SkPM4f* src, int coun t,
81 const SkAlpha aa[]) {
82 const Sk4f s4 = Sk4f::Load(src->fVec);
83 if (aa) {
84 for (int i = 0; i < count; ++i) {
85 const Sk4f d4 = SkHalfToFloat_01(dst[i]);
86 dst[i] = SkFloatToHalf_01(lerp_by_coverage(s4, d4, aa[i]));
87 }
88 } else {
89 sk_memset64(dst, SkFloatToHalf_01(s4), count);
90 }
91 }
92
93 static void src_n(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int cou nt,
94 const SkAlpha aa[]) {
95 if (aa) {
96 for (int i = 0; i < count; ++i) {
97 const Sk4f s4 = Sk4f::Load(src[i].fVec);
98 const Sk4f d4 = SkHalfToFloat_01(dst[i]);
99 dst[i] = SkFloatToHalf_01(lerp_by_coverage(s4, d4, aa[i]));
100 }
101 } else {
102 for (int i = 0; i < count; ++i) {
103 const Sk4f s4 = Sk4f::Load(src[i].fVec);
104 dst[i] = SkFloatToHalf_01(s4);
105 }
106 }
107 }
108
109 const SkXfermode::F16Proc gProcs_Src[] = { src_n, src_n, src_1, src_1 };
110
111 //////////////////////////////////////////////////////////////////////////////// ///////////////////
112
113 static void dst(const SkXfermode*, uint64_t*, const SkPM4f*, int count, const Sk Alpha[]) {}
114
115 const SkXfermode::F16Proc gProcs_Dst[] = { dst, dst, dst, dst };
116
117 //////////////////////////////////////////////////////////////////////////////// ///////////////////
118
119 static void srcover_1(const SkXfermode*, uint64_t dst[], const SkPM4f* src, int count,
120 const SkAlpha aa[]) {
121 const Sk4f s4 = Sk4f::Load(src->fVec);
122 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
123 for (int i = 0; i < count; ++i) {
124 const Sk4f d4 = SkHalfToFloat_01(dst[i]);
125 const Sk4f r4 = s4 + d4 * dst_scale;
126 if (aa) {
127 dst[i] = SkFloatToHalf_01(lerp_by_coverage(r4, d4, aa[i]));
128 } else {
129 dst[i] = SkFloatToHalf_01(r4);
130 }
131 }
132 }
133
134 static void srcover_n(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int count,
135 const SkAlpha aa[]) {
136 for (int i = 0; i < count; ++i) {
137 const Sk4f s4 = Sk4f::Load(src[i].fVec);
138 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
139 const Sk4f d4 = SkHalfToFloat_01(dst[i]);
140 const Sk4f r4 = s4 + d4 * dst_scale;
141 if (aa) {
142 dst[i] = SkFloatToHalf_01(lerp_by_coverage(r4, d4, aa[i]));
143 } else {
144 dst[i] = SkFloatToHalf_01(r4);
145 }
146 }
147 }
148
149 const SkXfermode::F16Proc gProcs_SrcOver[] = { srcover_n, src_n, srcover_1, src_ 1 };
150
151 //////////////////////////////////////////////////////////////////////////////// ///////////////////
152
153 static SkXfermode::F16Proc find_proc(SkXfermode::Mode mode, uint32_t flags) {
154 SkASSERT(0 == (flags & ~3));
155 flags &= 3;
156
157 switch (mode) {
158 case SkXfermode::kClear_Mode: return gProcs_Clear[flags];
159 case SkXfermode::kSrc_Mode: return gProcs_Src[flags];
160 case SkXfermode::kDst_Mode: return gProcs_Dst[flags];
161 case SkXfermode::kSrcOver_Mode: return gProcs_SrcOver[flags];
162 default:
163 break;
164 }
165 return gProcs_General[flags];
166 }
167
168 SkXfermode::F16Proc SkXfermode::onGetF16Proc(uint32_t flags) const {
169 SkASSERT(0 == (flags & ~3));
170 flags &= 3;
171
172 Mode mode;
173 return this->asMode(&mode) ? find_proc(mode, flags) : gProcs_General[flags];
174 }
175
176 SkXfermode::F16Proc SkXfermode::GetF16Proc(SkXfermode* xfer, uint32_t flags) {
177 return xfer ? xfer->onGetF16Proc(flags) : find_proc(SkXfermode::kSrcOver_Mod e, flags);
178 }
OLDNEW
« no previous file with comments | « src/core/SkSpriteBlitter4f.cpp ('k') | src/core/SkXfermodeU64.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698