OLD | NEW |
| (Empty) |
1 #include "SkColorPriv.h" | |
2 #include "SkColor_opts_SSE2.h" | |
3 #include "SkMathPriv.h" | |
4 #include "SkXfermode.h" | |
5 #include "SkXfermode_opts_SSE2.h" | |
6 #include "SkXfermode_proccoeff.h" | |
7 | |
8 //////////////////////////////////////////////////////////////////////////////// | |
9 // 4 pixels SSE2 version functions | |
10 //////////////////////////////////////////////////////////////////////////////// | |
11 | |
12 static inline __m128i SkDiv255Round_SSE2(__m128i prod) { | |
13 prod = _mm_add_epi32(prod, _mm_set1_epi32(128)); // prod += 128; | |
14 prod = _mm_add_epi32(prod, _mm_srli_epi32(prod, 8)); // prod + (prod >> 8) | |
15 prod = _mm_srli_epi32(prod, 8); // >> 8 | |
16 | |
17 return prod; | |
18 } | |
19 | |
20 static inline __m128i clamp_div255round_SSE2(__m128i prod) { | |
21 // test if > 0 | |
22 __m128i cmp1 = _mm_cmpgt_epi32(prod, _mm_setzero_si128()); | |
23 // test if < 255*255 | |
24 __m128i cmp2 = _mm_cmplt_epi32(prod, _mm_set1_epi32(255*255)); | |
25 | |
26 __m128i ret = _mm_setzero_si128(); | |
27 | |
28 // if value >= 255*255, value = 255 | |
29 ret = _mm_andnot_si128(cmp2, _mm_set1_epi32(255)); | |
30 | |
31 __m128i div = SkDiv255Round_SSE2(prod); | |
32 | |
33 // test if > 0 && < 255*255 | |
34 __m128i cmp = _mm_and_si128(cmp1, cmp2); | |
35 | |
36 ret = _mm_or_si128(_mm_and_si128(cmp, div), _mm_andnot_si128(cmp, ret)); | |
37 | |
38 return ret; | |
39 } | |
40 | |
41 static inline __m128i srcover_byte_SSE2(__m128i a, __m128i b) { | |
42 // a + b - SkAlphaMulAlpha(a, b); | |
43 return _mm_sub_epi32(_mm_add_epi32(a, b), SkAlphaMulAlpha_SSE2(a, b)); | |
44 | |
45 } | |
46 | |
47 static inline __m128i blendfunc_multiply_byte_SSE2(__m128i sc, __m128i dc, | |
48 __m128i sa, __m128i da) { | |
49 // sc * (255 - da) | |
50 __m128i ret1 = _mm_sub_epi32(_mm_set1_epi32(255), da); | |
51 ret1 = _mm_mullo_epi16(sc, ret1); | |
52 | |
53 // dc * (255 - sa) | |
54 __m128i ret2 = _mm_sub_epi32(_mm_set1_epi32(255), sa); | |
55 ret2 = _mm_mullo_epi16(dc, ret2); | |
56 | |
57 // sc * dc | |
58 __m128i ret3 = _mm_mullo_epi16(sc, dc); | |
59 | |
60 __m128i ret = _mm_add_epi32(ret1, ret2); | |
61 ret = _mm_add_epi32(ret, ret3); | |
62 | |
63 return clamp_div255round_SSE2(ret); | |
64 } | |
65 | |
66 static __m128i multiply_modeproc_SSE2(__m128i src, __m128i dst) { | |
67 __m128i sa = SkGetPackedA32_SSE2(src); | |
68 __m128i da = SkGetPackedA32_SSE2(dst); | |
69 __m128i a = srcover_byte_SSE2(sa, da); | |
70 | |
71 __m128i sr = SkGetPackedR32_SSE2(src); | |
72 __m128i dr = SkGetPackedR32_SSE2(dst); | |
73 __m128i r = blendfunc_multiply_byte_SSE2(sr, dr, sa, da); | |
74 | |
75 __m128i sg = SkGetPackedG32_SSE2(src); | |
76 __m128i dg = SkGetPackedG32_SSE2(dst); | |
77 __m128i g = blendfunc_multiply_byte_SSE2(sg, dg, sa, da); | |
78 | |
79 | |
80 __m128i sb = SkGetPackedB32_SSE2(src); | |
81 __m128i db = SkGetPackedB32_SSE2(dst); | |
82 __m128i b = blendfunc_multiply_byte_SSE2(sb, db, sa, da); | |
83 | |
84 return SkPackARGB32_SSE2(a, r, g, b); | |
85 } | |
86 | |
87 //////////////////////////////////////////////////////////////////////////////// | |
88 | |
89 extern SkXfermodeProcSIMD gSSE2XfermodeProcs[]; | |
90 | |
91 SkSSE2ProcCoeffXfermode::SkSSE2ProcCoeffXfermode(SkReadBuffer& buffer) | |
92 : INHERITED(buffer) { | |
93 fProcSIMD = gSSE2XfermodeProcs[this->getMode()]; | |
94 } | |
95 | |
96 void SkSSE2ProcCoeffXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], | |
97 int count, const SkAlpha aa[]) const { | |
98 SkASSERT(dst && src && count >= 0); | |
99 | |
100 SkXfermodeProc proc = this->getProc(); | |
101 SkXfermodeProcSIMD procSIMD = fProcSIMD; | |
102 SkASSERT(procSIMD != NULL); | |
103 | |
104 if (NULL == aa) { | |
105 if (count >= 4) { | |
106 while (((size_t)dst & 0x0F) != 0) { | |
107 *dst = proc(*src, *dst); | |
108 dst++; | |
109 src++; | |
110 count--; | |
111 } | |
112 | |
113 const __m128i* s = reinterpret_cast<const __m128i*>(src); | |
114 __m128i* d = reinterpret_cast<__m128i*>(dst); | |
115 | |
116 while (count >= 4) { | |
117 __m128i src_pixel = _mm_loadu_si128(s++); | |
118 __m128i dst_pixel = _mm_load_si128(d); | |
119 | |
120 dst_pixel = procSIMD(src_pixel, dst_pixel); | |
121 _mm_store_si128(d++, dst_pixel); | |
122 count -= 4; | |
123 } | |
124 | |
125 src = reinterpret_cast<const SkPMColor*>(s); | |
126 dst = reinterpret_cast<SkPMColor*>(d); | |
127 } | |
128 | |
129 for (int i = count - 1; i >= 0; --i) { | |
130 *dst = proc(*src, *dst); | |
131 dst++; | |
132 src++; | |
133 } | |
134 } else { | |
135 for (int i = count - 1; i >= 0; --i) { | |
136 unsigned a = aa[i]; | |
137 if (0 != a) { | |
138 SkPMColor dstC = dst[i]; | |
139 SkPMColor C = proc(src[i], dstC); | |
140 if (a != 0xFF) { | |
141 C = SkFourByteInterp(C, dstC, a); | |
142 } | |
143 dst[i] = C; | |
144 } | |
145 } | |
146 } | |
147 } | |
148 | |
149 void SkSSE2ProcCoeffXfermode::xfer16(uint16_t* SK_RESTRICT dst, | |
150 const SkPMColor* SK_RESTRICT src, int count
, | |
151 const SkAlpha* SK_RESTRICT aa) const { | |
152 SkASSERT(dst && src && count >= 0); | |
153 | |
154 SkXfermodeProc proc = this->getProc(); | |
155 SkXfermodeProcSIMD procSIMD = fProcSIMD; | |
156 SkASSERT(procSIMD != NULL); | |
157 | |
158 if (NULL == aa) { | |
159 if (count >= 8) { | |
160 while (((size_t)dst & 0x0F) != 0) { | |
161 SkPMColor dstC = SkPixel16ToPixel32(*dst); | |
162 *dst = SkPixel32ToPixel16_ToU16(proc(*src, dstC)); | |
163 dst++; | |
164 src++; | |
165 count--; | |
166 } | |
167 | |
168 const __m128i* s = reinterpret_cast<const __m128i*>(src); | |
169 __m128i* d = reinterpret_cast<__m128i*>(dst); | |
170 | |
171 while (count >= 8) { | |
172 __m128i src_pixel1 = _mm_loadu_si128(s++); | |
173 __m128i src_pixel2 = _mm_loadu_si128(s++); | |
174 __m128i dst_pixel = _mm_load_si128(d); | |
175 | |
176 __m128i dst_pixel1 = _mm_unpacklo_epi16(dst_pixel, _mm_setzero_s
i128()); | |
177 __m128i dst_pixel2 = _mm_unpackhi_epi16(dst_pixel, _mm_setzero_s
i128()); | |
178 | |
179 __m128i dstC1 = SkPixel16ToPixel32_SSE2(dst_pixel1); | |
180 __m128i dstC2 = SkPixel16ToPixel32_SSE2(dst_pixel2); | |
181 | |
182 dst_pixel1 = procSIMD(src_pixel1, dstC1); | |
183 dst_pixel2 = procSIMD(src_pixel2, dstC2); | |
184 dst_pixel = SkPixel32ToPixel16_ToU16_SSE2(dst_pixel1, dst_pixel2
); | |
185 | |
186 _mm_store_si128(d++, dst_pixel); | |
187 count -= 8; | |
188 } | |
189 | |
190 src = reinterpret_cast<const SkPMColor*>(s); | |
191 dst = reinterpret_cast<uint16_t*>(d); | |
192 } | |
193 | |
194 for (int i = count - 1; i >= 0; --i) { | |
195 SkPMColor dstC = SkPixel16ToPixel32(*dst); | |
196 *dst = SkPixel32ToPixel16_ToU16(proc(*src, dstC)); | |
197 dst++; | |
198 src++; | |
199 } | |
200 } else { | |
201 for (int i = count - 1; i >= 0; --i) { | |
202 unsigned a = aa[i]; | |
203 if (0 != a) { | |
204 SkPMColor dstC = SkPixel16ToPixel32(dst[i]); | |
205 SkPMColor C = proc(src[i], dstC); | |
206 if (0xFF != a) { | |
207 C = SkFourByteInterp(C, dstC, a); | |
208 } | |
209 dst[i] = SkPixel32ToPixel16_ToU16(C); | |
210 } | |
211 } | |
212 } | |
213 } | |
214 | |
215 #ifndef SK_IGNORE_TO_STRING | |
216 void SkSSE2ProcCoeffXfermode::toString(SkString* str) const { | |
217 this->INHERITED::toString(str); | |
218 } | |
219 #endif | |
220 | |
221 //////////////////////////////////////////////////////////////////////////////// | |
222 | |
223 // 4 pixels modeprocs with SSE2 | |
224 SkXfermodeProcSIMD gSSE2XfermodeProcs[] = { | |
225 NULL, // kClear_Mode | |
226 NULL, // kSrc_Mode | |
227 NULL, // kDst_Mode | |
228 NULL, // kSrcOver_Mode | |
229 NULL, // kDstOver_Mode | |
230 NULL, // kSrcIn_Mode | |
231 NULL, // kDstIn_Mode | |
232 NULL, // kSrcOut_Mode | |
233 NULL, // kDstOut_Mode | |
234 NULL, // kSrcATop_Mode | |
235 NULL, // kDstATop_Mode | |
236 NULL, // kXor_Mode | |
237 NULL, // kPlus_Mode | |
238 NULL, // kModulate_Mode | |
239 NULL, // kScreen_Mode | |
240 | |
241 NULL, // kOverlay_Mode | |
242 NULL, // kDarken_Mode | |
243 NULL, // kLighten_Mode | |
244 NULL, // kColorDodge_Mode | |
245 NULL, // kColorBurn_Mode | |
246 NULL, // kHardLight_Mode | |
247 NULL, // kSoftLight_Mode | |
248 NULL, // kDifference_Mode | |
249 NULL, // kExclusion_Mode | |
250 multiply_modeproc_SSE2, | |
251 | |
252 NULL, // kHue_Mode | |
253 NULL, // kSaturation_Mode | |
254 NULL, // kColor_Mode | |
255 NULL, // kLuminosity_Mode | |
256 }; | |
257 | |
258 SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl_SSE2(const ProcCoeff& rec, | |
259 SkXfermode::Mode mode)
{ | |
260 SkXfermodeProcSIMD procSIMD = gSSE2XfermodeProcs[mode]; | |
261 | |
262 if (procSIMD != NULL) { | |
263 return SkNEW_ARGS(SkSSE2ProcCoeffXfermode, (rec, mode, procSIMD)); | |
264 } | |
265 return NULL; | |
266 } | |
OLD | NEW |