OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkSpriteBlitter.h" | 10 #include "SkSpriteBlitter.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 /////////////////////////////////////////////////////////////////////////////// | 49 /////////////////////////////////////////////////////////////////////////////// |
50 | 50 |
51 class Sprite_D16_S16_Opaque : public SkSpriteBlitter { | 51 class Sprite_D16_S16_Opaque : public SkSpriteBlitter { |
52 public: | 52 public: |
53 Sprite_D16_S16_Opaque(const SkBitmap& source) | 53 Sprite_D16_S16_Opaque(const SkBitmap& source) |
54 : SkSpriteBlitter(source) {} | 54 : SkSpriteBlitter(source) {} |
55 | 55 |
56 // overrides | 56 // overrides |
57 void blitRect(int x, int y, int width, int height) override { | 57 void blitRect(int x, int y, int width, int height) override { |
58 uint16_t* SK_RESTRICT dst = fDevice->getAddr16(x, y); | 58 uint16_t* SK_RESTRICT dst = fDevice->getAddr16(x, y); |
59 const uint16_t* SK_RESTRICT src = fSource->getAddr16(x - fLeft, | 59 const uint16_t* SK_RESTRICT src = fSource->addr16(x - fLeft, y - fTop); |
60 y - fTop); | |
61 size_t dstRB = fDevice->rowBytes(); | 60 size_t dstRB = fDevice->rowBytes(); |
62 size_t srcRB = fSource->rowBytes(); | 61 size_t srcRB = fSource->rowBytes(); |
63 | 62 |
64 while (--height >= 0) { | 63 while (--height >= 0) { |
65 memcpy(dst, src, width << 1); | 64 memcpy(dst, src, width << 1); |
66 dst = (uint16_t*)((char*)dst + dstRB); | 65 dst = (uint16_t*)((char*)dst + dstRB); |
67 src = (const uint16_t*)((const char*)src + srcRB); | 66 src = (const uint16_t*)((const char*)src + srcRB); |
68 } | 67 } |
69 } | 68 } |
70 }; | 69 }; |
71 | 70 |
72 #define D16_S16_Blend_Pixel(dst, sc, scale) \ | 71 #define D16_S16_Blend_Pixel(dst, sc, scale) \ |
73 do { \ | 72 do { \ |
74 uint16_t dc = *dst; \ | 73 uint16_t dc = *dst; \ |
75 *dst = SkBlendRGB16(sc, dc, scale); \ | 74 *dst = SkBlendRGB16(sc, dc, scale); \ |
76 } while (0) | 75 } while (0) |
77 | 76 |
78 #define SkSPRITE_CLASSNAME Sprite_D16_S16_Blend | 77 #define SkSPRITE_CLASSNAME Sprite_D16_S16_Blend |
79 #define SkSPRITE_ARGS , uint8_t alpha | 78 #define SkSPRITE_ARGS , uint8_t alpha |
80 #define SkSPRITE_FIELDS uint8_t fSrcAlpha; | 79 #define SkSPRITE_FIELDS uint8_t fSrcAlpha; |
81 #define SkSPRITE_INIT fSrcAlpha = alpha; | 80 #define SkSPRITE_INIT fSrcAlpha = alpha; |
82 #define SkSPRITE_DST_TYPE uint16_t | 81 #define SkSPRITE_DST_TYPE uint16_t |
83 #define SkSPRITE_SRC_TYPE uint16_t | 82 #define SkSPRITE_SRC_TYPE uint16_t |
84 #define SkSPRITE_DST_GETADDR getAddr16 | 83 #define SkSPRITE_DST_GETADDR getAddr16 |
85 #define SkSPRITE_SRC_GETADDR getAddr16 | 84 #define SkSPRITE_SRC_GETADDR addr16 |
86 #define SkSPRITE_PREAMBLE(srcBM, x, y) int scale = SkAlpha255To256(fSrcAlph
a); | 85 #define SkSPRITE_PREAMBLE(srcBM, x, y) int scale = SkAlpha255To256(fSrcAlph
a); |
87 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S16_Blend_Pixel(dst, src, scale) | 86 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S16_Blend_Pixel(dst, src, scale) |
88 #define SkSPRITE_NEXT_ROW | 87 #define SkSPRITE_NEXT_ROW |
89 #define SkSPRITE_POSTAMBLE(srcBM) | 88 #define SkSPRITE_POSTAMBLE(srcBM) |
90 #include "SkSpriteBlitterTemplate.h" | 89 #include "SkSpriteBlitterTemplate.h" |
91 | 90 |
92 /////////////////////////////////////////////////////////////////////////////// | 91 /////////////////////////////////////////////////////////////////////////////// |
93 | 92 |
94 #define D16_S4444_Opaque(dst, sc) \ | 93 #define D16_S4444_Opaque(dst, sc) \ |
95 do { \ | 94 do { \ |
96 uint16_t dc = *dst; \ | 95 uint16_t dc = *dst; \ |
97 *dst = SkSrcOver4444To16(sc, dc); \ | 96 *dst = SkSrcOver4444To16(sc, dc); \ |
98 } while (0) | 97 } while (0) |
99 | 98 |
100 #define SkSPRITE_CLASSNAME Sprite_D16_S4444_Opaque | 99 #define SkSPRITE_CLASSNAME Sprite_D16_S4444_Opaque |
101 #define SkSPRITE_ARGS | 100 #define SkSPRITE_ARGS |
102 #define SkSPRITE_FIELDS | 101 #define SkSPRITE_FIELDS |
103 #define SkSPRITE_INIT | 102 #define SkSPRITE_INIT |
104 #define SkSPRITE_DST_TYPE uint16_t | 103 #define SkSPRITE_DST_TYPE uint16_t |
105 #define SkSPRITE_SRC_TYPE SkPMColor16 | 104 #define SkSPRITE_SRC_TYPE SkPMColor16 |
106 #define SkSPRITE_DST_GETADDR getAddr16 | 105 #define SkSPRITE_DST_GETADDR getAddr16 |
107 #define SkSPRITE_SRC_GETADDR getAddr16 | 106 #define SkSPRITE_SRC_GETADDR addr16 |
108 #define SkSPRITE_PREAMBLE(srcBM, x, y) | 107 #define SkSPRITE_PREAMBLE(srcBM, x, y) |
109 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S4444_Opaque(dst, src) | 108 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S4444_Opaque(dst, src) |
110 #define SkSPRITE_NEXT_ROW | 109 #define SkSPRITE_NEXT_ROW |
111 #define SkSPRITE_POSTAMBLE(srcBM) | 110 #define SkSPRITE_POSTAMBLE(srcBM) |
112 #include "SkSpriteBlitterTemplate.h" | 111 #include "SkSpriteBlitterTemplate.h" |
113 | 112 |
114 #define D16_S4444_Blend(dst, sc, scale16) \ | 113 #define D16_S4444_Blend(dst, sc, scale16) \ |
115 do { \ | 114 do { \ |
116 uint16_t dc = *dst; \ | 115 uint16_t dc = *dst; \ |
117 *dst = SkBlend4444To16(sc, dc, scale16); \ | 116 *dst = SkBlend4444To16(sc, dc, scale16); \ |
118 } while (0) | 117 } while (0) |
119 | 118 |
120 | 119 |
121 #define SkSPRITE_CLASSNAME Sprite_D16_S4444_Blend | 120 #define SkSPRITE_CLASSNAME Sprite_D16_S4444_Blend |
122 #define SkSPRITE_ARGS , uint8_t alpha | 121 #define SkSPRITE_ARGS , uint8_t alpha |
123 #define SkSPRITE_FIELDS uint8_t fSrcAlpha; | 122 #define SkSPRITE_FIELDS uint8_t fSrcAlpha; |
124 #define SkSPRITE_INIT fSrcAlpha = alpha; | 123 #define SkSPRITE_INIT fSrcAlpha = alpha; |
125 #define SkSPRITE_DST_TYPE uint16_t | 124 #define SkSPRITE_DST_TYPE uint16_t |
126 #define SkSPRITE_SRC_TYPE uint16_t | 125 #define SkSPRITE_SRC_TYPE uint16_t |
127 #define SkSPRITE_DST_GETADDR getAddr16 | 126 #define SkSPRITE_DST_GETADDR getAddr16 |
128 #define SkSPRITE_SRC_GETADDR getAddr16 | 127 #define SkSPRITE_SRC_GETADDR addr16 |
129 #define SkSPRITE_PREAMBLE(srcBM, x, y) int scale = SkAlpha15To16(fSrcAlpha)
; | 128 #define SkSPRITE_PREAMBLE(srcBM, x, y) int scale = SkAlpha15To16(fSrcAlpha)
; |
130 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S4444_Blend(dst, src, scale) | 129 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S4444_Blend(dst, src, scale) |
131 #define SkSPRITE_NEXT_ROW | 130 #define SkSPRITE_NEXT_ROW |
132 #define SkSPRITE_POSTAMBLE(srcBM) | 131 #define SkSPRITE_POSTAMBLE(srcBM) |
133 #include "SkSpriteBlitterTemplate.h" | 132 #include "SkSpriteBlitterTemplate.h" |
134 | 133 |
135 /////////////////////////////////////////////////////////////////////////////// | 134 /////////////////////////////////////////////////////////////////////////////// |
136 | 135 |
137 #define SkSPRITE_CLASSNAME Sprite_D16_SIndex8A_Opaque | 136 #define SkSPRITE_CLASSNAME Sprite_D16_SIndex8A_Opaque |
138 #define SkSPRITE_ARGS | 137 #define SkSPRITE_ARGS |
139 #define SkSPRITE_FIELDS | 138 #define SkSPRITE_FIELDS |
140 #define SkSPRITE_INIT | 139 #define SkSPRITE_INIT |
141 #define SkSPRITE_DST_TYPE uint16_t | 140 #define SkSPRITE_DST_TYPE uint16_t |
142 #define SkSPRITE_SRC_TYPE uint8_t | 141 #define SkSPRITE_SRC_TYPE uint8_t |
143 #define SkSPRITE_DST_GETADDR getAddr16 | 142 #define SkSPRITE_DST_GETADDR getAddr16 |
144 #define SkSPRITE_SRC_GETADDR getAddr8 | 143 #define SkSPRITE_SRC_GETADDR addr8 |
145 #define SkSPRITE_PREAMBLE(srcBM, x, y) const SkPMColor* ctable = srcBM.getC
olorTable()->readColors() | 144 #define SkSPRITE_PREAMBLE(srcBM, x, y) const SkPMColor* ctable = srcBM.ctab
le()->readColors() |
146 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S32A_Opaque_Pixel(dst, ctable[sr
c]) | 145 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S32A_Opaque_Pixel(dst, ctable[sr
c]) |
147 #define SkSPRITE_NEXT_ROW | 146 #define SkSPRITE_NEXT_ROW |
148 #define SkSPRITE_POSTAMBLE(srcBM) | 147 #define SkSPRITE_POSTAMBLE(srcBM) |
149 #include "SkSpriteBlitterTemplate.h" | 148 #include "SkSpriteBlitterTemplate.h" |
150 | 149 |
151 #define SkSPRITE_CLASSNAME Sprite_D16_SIndex8A_Blend | 150 #define SkSPRITE_CLASSNAME Sprite_D16_SIndex8A_Blend |
152 #define SkSPRITE_ARGS , uint8_t alpha | 151 #define SkSPRITE_ARGS , uint8_t alpha |
153 #define SkSPRITE_FIELDS uint8_t fSrcAlpha; | 152 #define SkSPRITE_FIELDS uint8_t fSrcAlpha; |
154 #define SkSPRITE_INIT fSrcAlpha = alpha; | 153 #define SkSPRITE_INIT fSrcAlpha = alpha; |
155 #define SkSPRITE_DST_TYPE uint16_t | 154 #define SkSPRITE_DST_TYPE uint16_t |
156 #define SkSPRITE_SRC_TYPE uint8_t | 155 #define SkSPRITE_SRC_TYPE uint8_t |
157 #define SkSPRITE_DST_GETADDR getAddr16 | 156 #define SkSPRITE_DST_GETADDR getAddr16 |
158 #define SkSPRITE_SRC_GETADDR getAddr8 | 157 #define SkSPRITE_SRC_GETADDR addr8 |
159 #define SkSPRITE_PREAMBLE(srcBM, x, y) const SkPMColor* ctable = srcBM.getC
olorTable()->readColors(); unsigned src_scale = SkAlpha255To256(fSrcAlpha); | 158 #define SkSPRITE_PREAMBLE(srcBM, x, y) const SkPMColor* ctable = srcBM.ctab
le()->readColors(); unsigned src_scale = SkAlpha255To256(fSrcAlpha); |
160 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S32A_Blend_Pixel(dst, ctable[src
], src_scale) | 159 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S32A_Blend_Pixel(dst, ctable[src
], src_scale) |
161 #define SkSPRITE_NEXT_ROW | 160 #define SkSPRITE_NEXT_ROW |
162 #define SkSPRITE_POSTAMBLE(srcBM) | 161 #define SkSPRITE_POSTAMBLE(srcBM) |
163 #include "SkSpriteBlitterTemplate.h" | 162 #include "SkSpriteBlitterTemplate.h" |
164 | 163 |
165 /////////////////////////////////////////////////////////////////////////////// | 164 /////////////////////////////////////////////////////////////////////////////// |
166 | 165 |
167 static intptr_t asint(const void* ptr) { | 166 static intptr_t asint(const void* ptr) { |
168 return reinterpret_cast<const char*>(ptr) - (const char*)0; | 167 return reinterpret_cast<const char*>(ptr) - (const char*)0; |
169 } | 168 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 225 |
227 #define SkSPRITE_ROW_PROC(d, s, n, x, y) blitrow_d16_si8(d, s, n, ctable) | 226 #define SkSPRITE_ROW_PROC(d, s, n, x, y) blitrow_d16_si8(d, s, n, ctable) |
228 | 227 |
229 #define SkSPRITE_CLASSNAME Sprite_D16_SIndex8_Opaque | 228 #define SkSPRITE_CLASSNAME Sprite_D16_SIndex8_Opaque |
230 #define SkSPRITE_ARGS | 229 #define SkSPRITE_ARGS |
231 #define SkSPRITE_FIELDS | 230 #define SkSPRITE_FIELDS |
232 #define SkSPRITE_INIT | 231 #define SkSPRITE_INIT |
233 #define SkSPRITE_DST_TYPE uint16_t | 232 #define SkSPRITE_DST_TYPE uint16_t |
234 #define SkSPRITE_SRC_TYPE uint8_t | 233 #define SkSPRITE_SRC_TYPE uint8_t |
235 #define SkSPRITE_DST_GETADDR getAddr16 | 234 #define SkSPRITE_DST_GETADDR getAddr16 |
236 #define SkSPRITE_SRC_GETADDR getAddr8 | 235 #define SkSPRITE_SRC_GETADDR addr8 |
237 #define SkSPRITE_PREAMBLE(srcBM, x, y) const uint16_t* ctable = srcBM.getCo
lorTable()->read16BitCache() | 236 #define SkSPRITE_PREAMBLE(srcBM, x, y) const uint16_t* ctable = srcBM.ctabl
e()->read16BitCache() |
238 #define SkSPRITE_BLIT_PIXEL(dst, src) *dst = ctable[src] | 237 #define SkSPRITE_BLIT_PIXEL(dst, src) *dst = ctable[src] |
239 #define SkSPRITE_NEXT_ROW | 238 #define SkSPRITE_NEXT_ROW |
240 #define SkSPRITE_POSTAMBLE(srcBM) | 239 #define SkSPRITE_POSTAMBLE(srcBM) |
241 #include "SkSpriteBlitterTemplate.h" | 240 #include "SkSpriteBlitterTemplate.h" |
242 | 241 |
243 #define SkSPRITE_CLASSNAME Sprite_D16_SIndex8_Blend | 242 #define SkSPRITE_CLASSNAME Sprite_D16_SIndex8_Blend |
244 #define SkSPRITE_ARGS , uint8_t alpha | 243 #define SkSPRITE_ARGS , uint8_t alpha |
245 #define SkSPRITE_FIELDS uint8_t fSrcAlpha; | 244 #define SkSPRITE_FIELDS uint8_t fSrcAlpha; |
246 #define SkSPRITE_INIT fSrcAlpha = alpha; | 245 #define SkSPRITE_INIT fSrcAlpha = alpha; |
247 #define SkSPRITE_DST_TYPE uint16_t | 246 #define SkSPRITE_DST_TYPE uint16_t |
248 #define SkSPRITE_SRC_TYPE uint8_t | 247 #define SkSPRITE_SRC_TYPE uint8_t |
249 #define SkSPRITE_DST_GETADDR getAddr16 | 248 #define SkSPRITE_DST_GETADDR getAddr16 |
250 #define SkSPRITE_SRC_GETADDR getAddr8 | 249 #define SkSPRITE_SRC_GETADDR addr8 |
251 #define SkSPRITE_PREAMBLE(srcBM, x, y) const uint16_t* ctable = srcBM.getCo
lorTable()->read16BitCache(); unsigned src_scale = SkAlpha255To256(fSrcAlpha); | 250 #define SkSPRITE_PREAMBLE(srcBM, x, y) const uint16_t* ctable = srcBM.ctabl
e()->read16BitCache(); unsigned src_scale = SkAlpha255To256(fSrcAlpha); |
252 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S16_Blend_Pixel(dst, ctable[src]
, src_scale) | 251 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S16_Blend_Pixel(dst, ctable[src]
, src_scale) |
253 #define SkSPRITE_NEXT_ROW | 252 #define SkSPRITE_NEXT_ROW |
254 #define SkSPRITE_POSTAMBLE(srcBM) | 253 #define SkSPRITE_POSTAMBLE(srcBM) |
255 #include "SkSpriteBlitterTemplate.h" | 254 #include "SkSpriteBlitterTemplate.h" |
256 | 255 |
257 /////////////////////////////////////////////////////////////////////////////// | 256 /////////////////////////////////////////////////////////////////////////////// |
258 | 257 |
259 class Sprite_D16_S32_BlitRowProc : public SkSpriteBlitter { | 258 class Sprite_D16_S32_BlitRowProc : public SkSpriteBlitter { |
260 public: | 259 public: |
261 Sprite_D16_S32_BlitRowProc(const SkBitmap& source) | 260 Sprite_D16_S32_BlitRowProc(const SkBitmap& source) |
262 : SkSpriteBlitter(source) {} | 261 : SkSpriteBlitter(source) {} |
263 | 262 |
264 // overrides | 263 bool setup(const SkBitmap& device, int left, int top, |
265 | |
266 virtual void setup(const SkBitmap& device, int left, int top, | |
267 const SkPaint& paint) override { | 264 const SkPaint& paint) override { |
268 this->INHERITED::setup(device, left, top, paint); | 265 if (!this->INHERITED::setup(device, left, top, paint)) { |
| 266 return false; |
| 267 } |
269 | 268 |
270 unsigned flags = 0; | 269 unsigned flags = 0; |
271 | 270 |
272 if (paint.getAlpha() < 0xFF) { | 271 if (paint.getAlpha() < 0xFF) { |
273 flags |= SkBlitRow::kGlobalAlpha_Flag; | 272 flags |= SkBlitRow::kGlobalAlpha_Flag; |
274 } | 273 } |
275 if (!fSource->isOpaque()) { | 274 if (!fSource->isOpaque()) { |
276 flags |= SkBlitRow::kSrcPixelAlpha_Flag; | 275 flags |= SkBlitRow::kSrcPixelAlpha_Flag; |
277 } | 276 } |
278 if (paint.isDither()) { | 277 if (paint.isDither()) { |
279 flags |= SkBlitRow::kDither_Flag; | 278 flags |= SkBlitRow::kDither_Flag; |
280 } | 279 } |
281 fProc = SkBlitRow::Factory16(flags); | 280 fProc = SkBlitRow::Factory16(flags); |
| 281 return true; |
282 } | 282 } |
283 | 283 |
284 void blitRect(int x, int y, int width, int height) override { | 284 void blitRect(int x, int y, int width, int height) override { |
285 uint16_t* SK_RESTRICT dst = fDevice->getAddr16(x, y); | 285 uint16_t* SK_RESTRICT dst = fDevice->getAddr16(x, y); |
286 const SkPMColor* SK_RESTRICT src = fSource->getAddr32(x - fLeft, | 286 const SkPMColor* SK_RESTRICT src = fSource->addr32(x - fLeft, y - fTop); |
287 y - fTop); | |
288 size_t dstRB = fDevice->rowBytes(); | 287 size_t dstRB = fDevice->rowBytes(); |
289 size_t srcRB = fSource->rowBytes(); | 288 size_t srcRB = fSource->rowBytes(); |
290 SkBlitRow::Proc16 proc = fProc; | 289 SkBlitRow::Proc16 proc = fProc; |
291 U8CPU alpha = fPaint->getAlpha(); | 290 U8CPU alpha = fPaint->getAlpha(); |
292 | 291 |
293 while (--height >= 0) { | 292 while (--height >= 0) { |
294 proc(dst, src, width, alpha, x, y); | 293 proc(dst, src, width, alpha, x, y); |
295 y += 1; | 294 y += 1; |
296 dst = (uint16_t* SK_RESTRICT)((char*)dst + dstRB); | 295 dst = (uint16_t* SK_RESTRICT)((char*)dst + dstRB); |
297 src = (const SkPMColor* SK_RESTRICT)((const char*)src + srcRB); | 296 src = (const SkPMColor* SK_RESTRICT)((const char*)src + srcRB); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } else { | 370 } else { |
372 blitter = allocator->createT<Sprite_D16_SIndex8A_Blend>(sour
ce, alpha); | 371 blitter = allocator->createT<Sprite_D16_SIndex8A_Blend>(sour
ce, alpha); |
373 } | 372 } |
374 } | 373 } |
375 break; | 374 break; |
376 default: | 375 default: |
377 break; | 376 break; |
378 } | 377 } |
379 return blitter; | 378 return blitter; |
380 } | 379 } |
OLD | NEW |