OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBlitRow.h" | 8 #include "SkBlitRow.h" |
9 #include "SkBlitMask.h" | 9 #include "SkBlitMask.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
11 #include "SkUtils.h" | 11 #include "SkUtils.h" |
12 | 12 |
13 #define UNROLL | 13 #define UNROLL |
14 | 14 |
15 SkBlitRow::ColorRectProc PlatformColorRectProcFactory(); | |
16 | |
17 static void S32_Opaque_BlitRow32(SkPMColor* SK_RESTRICT dst, | 15 static void S32_Opaque_BlitRow32(SkPMColor* SK_RESTRICT dst, |
18 const SkPMColor* SK_RESTRICT src, | 16 const SkPMColor* SK_RESTRICT src, |
19 int count, U8CPU alpha) { | 17 int count, U8CPU alpha) { |
20 SkASSERT(255 == alpha); | 18 SkASSERT(255 == alpha); |
21 sk_memcpy32(dst, src, count); | 19 sk_memcpy32(dst, src, count); |
22 } | 20 } |
23 | 21 |
24 static void S32_Blend_BlitRow32(SkPMColor* SK_RESTRICT dst, | 22 static void S32_Blend_BlitRow32(SkPMColor* SK_RESTRICT dst, |
25 const SkPMColor* SK_RESTRICT src, | 23 const SkPMColor* SK_RESTRICT src, |
26 int count, U8CPU alpha) { | 24 int count, U8CPU alpha) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 unsigned scale = 256 - SkAlpha255To256(colorA); | 157 unsigned scale = 256 - SkAlpha255To256(colorA); |
160 do { | 158 do { |
161 *dst = color + SkAlphaMulQ(*src, scale); | 159 *dst = color + SkAlphaMulQ(*src, scale); |
162 src += 1; | 160 src += 1; |
163 dst += 1; | 161 dst += 1; |
164 } while (--count); | 162 } while (--count); |
165 } | 163 } |
166 } | 164 } |
167 } | 165 } |
168 | 166 |
169 template <size_t N> void assignLoop(SkPMColor* dst, SkPMColor color) { | |
170 for (size_t i = 0; i < N; ++i) { | |
171 *dst++ = color; | |
172 } | |
173 } | |
174 | |
175 static inline void assignLoop(SkPMColor dst[], SkPMColor color, int count) { | |
176 while (count >= 4) { | |
177 *dst++ = color; | |
178 *dst++ = color; | |
179 *dst++ = color; | |
180 *dst++ = color; | |
181 count -= 4; | |
182 } | |
183 if (count >= 2) { | |
184 *dst++ = color; | |
185 *dst++ = color; | |
186 count -= 2; | |
187 } | |
188 if (count > 0) { | |
189 *dst++ = color; | |
190 } | |
191 } | |
192 | |
193 void SkBlitRow::ColorRect32(SkPMColor* dst, int width, int height, | |
194 size_t rowBytes, SkPMColor color) { | |
195 if (width <= 0 || height <= 0 || 0 == color) { | |
196 return; | |
197 } | |
198 | |
199 // Just made up this value, since I saw it once in a SSE2 file. | |
200 // We should consider writing some tests to find the optimimal break-point | |
201 // (or query the Platform proc?) | |
202 static const int MIN_WIDTH_FOR_SCANLINE_PROC = 32; | |
203 | |
204 bool isOpaque = (0xFF == SkGetPackedA32(color)); | |
205 | |
206 if (!isOpaque || width >= MIN_WIDTH_FOR_SCANLINE_PROC) { | |
207 SkBlitRow::ColorProc proc = SkBlitRow::ColorProcFactory(); | |
208 while (--height >= 0) { | |
209 (*proc)(dst, dst, width, color); | |
210 dst = (SkPMColor*) ((char*)dst + rowBytes); | |
211 } | |
212 } else { | |
213 switch (width) { | |
214 case 1: | |
215 while (--height >= 0) { | |
216 assignLoop<1>(dst, color); | |
217 dst = (SkPMColor*) ((char*)dst + rowBytes); | |
218 } | |
219 break; | |
220 case 2: | |
221 while (--height >= 0) { | |
222 assignLoop<2>(dst, color); | |
223 dst = (SkPMColor*) ((char*)dst + rowBytes); | |
224 } | |
225 break; | |
226 case 3: | |
227 while (--height >= 0) { | |
228 assignLoop<3>(dst, color); | |
229 dst = (SkPMColor*) ((char*)dst + rowBytes); | |
230 } | |
231 break; | |
232 default: | |
233 while (--height >= 0) { | |
234 assignLoop(dst, color, width); | |
235 dst = (SkPMColor*) ((char*)dst + rowBytes); | |
236 } | |
237 break; | |
238 } | |
239 } | |
240 } | |
241 | |
242 SkBlitRow::ColorRectProc SkBlitRow::ColorRectProcFactory() { | |
243 SkBlitRow::ColorRectProc proc = PlatformColorRectProcFactory(); | |
244 if (NULL == proc) { | |
245 proc = ColorRect32; | |
246 } | |
247 SkASSERT(proc); | |
248 return proc; | |
249 } | |
OLD | NEW |