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 14 matching lines...) Expand all Loading... |
25 uint16_t dc = *dst; | 25 uint16_t dc = *dst; |
26 unsigned sa = SkGetPackedA32(sc); | 26 unsigned sa = SkGetPackedA32(sc); |
27 unsigned dr, dg, db; | 27 unsigned dr, dg, db; |
28 | 28 |
29 if (255 == sa) { | 29 if (255 == sa) { |
30 dr = SkAlphaBlend(SkPacked32ToR16(sc), SkGetPackedR16(dc), src_scale); | 30 dr = SkAlphaBlend(SkPacked32ToR16(sc), SkGetPackedR16(dc), src_scale); |
31 dg = SkAlphaBlend(SkPacked32ToG16(sc), SkGetPackedG16(dc), src_scale); | 31 dg = SkAlphaBlend(SkPacked32ToG16(sc), SkGetPackedG16(dc), src_scale); |
32 db = SkAlphaBlend(SkPacked32ToB16(sc), SkGetPackedB16(dc), src_scale); | 32 db = SkAlphaBlend(SkPacked32ToB16(sc), SkGetPackedB16(dc), src_scale); |
33 } else { | 33 } else { |
34 unsigned dst_scale = 255 - SkAlphaMul(sa, src_scale); | 34 unsigned dst_scale = 255 - SkAlphaMul(sa, src_scale); |
35 dr = (SkPacked32ToR16(sc) * src_scale + | 35 dr = (SkPacked32ToR16(sc) * src_scale + SkGetPackedR16(dc) * dst_scale)
>> 8; |
36 SkGetPackedR16(dc) * dst_scale) >> 8; | 36 dg = (SkPacked32ToG16(sc) * src_scale + SkGetPackedG16(dc) * dst_scale)
>> 8; |
37 dg = (SkPacked32ToG16(sc) * src_scale + | 37 db = (SkPacked32ToB16(sc) * src_scale + SkGetPackedB16(dc) * dst_scale)
>> 8; |
38 SkGetPackedG16(dc) * dst_scale) >> 8; | |
39 db = (SkPacked32ToB16(sc) * src_scale + | |
40 SkGetPackedB16(dc) * dst_scale) >> 8; | |
41 } | 38 } |
42 *dst = SkPackRGB16(dr, dg, db); | 39 *dst = SkPackRGB16(dr, dg, db); |
43 } | 40 } |
44 | 41 |
45 #define D16_S32A_Blend_Pixel(dst, sc, src_scale) \ | 42 #define D16_S32A_Blend_Pixel(dst, sc, src_scale) \ |
46 do { if (sc) D16_S32A_Blend_Pixel_helper(dst, sc, src_scale); } while (0) | 43 do { if (sc) D16_S32A_Blend_Pixel_helper(dst, sc, src_scale); } while (0) |
47 | 44 |
48 | 45 |
49 /////////////////////////////////////////////////////////////////////////////// | 46 /////////////////////////////////////////////////////////////////////////////// |
50 | 47 |
51 class Sprite_D16_S16_Opaque : public SkSpriteBlitter { | 48 class Sprite_D16_S16_Opaque : public SkSpriteBlitter { |
52 public: | 49 public: |
53 Sprite_D16_S16_Opaque(const SkBitmap& source) | 50 Sprite_D16_S16_Opaque(const SkPixmap& source) : SkSpriteBlitter(source) {} |
54 : SkSpriteBlitter(source) {} | |
55 | 51 |
56 // overrides | 52 // overrides |
57 void blitRect(int x, int y, int width, int height) override { | 53 void blitRect(int x, int y, int width, int height) override { |
58 uint16_t* SK_RESTRICT dst = fDevice->getAddr16(x, y); | 54 uint16_t* SK_RESTRICT dst = fDevice->getAddr16(x, y); |
59 const uint16_t* SK_RESTRICT src = fSource->addr16(x - fLeft, y - fTop); | 55 const uint16_t* SK_RESTRICT src = fSource.addr16(x - fLeft, y - fTop); |
60 size_t dstRB = fDevice->rowBytes(); | 56 size_t dstRB = fDevice->rowBytes(); |
61 size_t srcRB = fSource->rowBytes(); | 57 size_t srcRB = fSource.rowBytes(); |
62 | 58 |
63 while (--height >= 0) { | 59 while (--height >= 0) { |
64 memcpy(dst, src, width << 1); | 60 memcpy(dst, src, width << 1); |
65 dst = (uint16_t*)((char*)dst + dstRB); | 61 dst = (uint16_t*)((char*)dst + dstRB); |
66 src = (const uint16_t*)((const char*)src + srcRB); | 62 src = (const uint16_t*)((const char*)src + srcRB); |
67 } | 63 } |
68 } | 64 } |
69 }; | 65 }; |
70 | 66 |
71 #define D16_S16_Blend_Pixel(dst, sc, scale) \ | 67 #define D16_S16_Blend_Pixel(dst, sc, scale) \ |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 #define SkSPRITE_PREAMBLE(srcBM, x, y) const uint16_t* ctable = srcBM.ctabl
e()->read16BitCache(); unsigned src_scale = SkAlpha255To256(fSrcAlpha); | 246 #define SkSPRITE_PREAMBLE(srcBM, x, y) const uint16_t* ctable = srcBM.ctabl
e()->read16BitCache(); unsigned src_scale = SkAlpha255To256(fSrcAlpha); |
251 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S16_Blend_Pixel(dst, ctable[src]
, src_scale) | 247 #define SkSPRITE_BLIT_PIXEL(dst, src) D16_S16_Blend_Pixel(dst, ctable[src]
, src_scale) |
252 #define SkSPRITE_NEXT_ROW | 248 #define SkSPRITE_NEXT_ROW |
253 #define SkSPRITE_POSTAMBLE(srcBM) | 249 #define SkSPRITE_POSTAMBLE(srcBM) |
254 #include "SkSpriteBlitterTemplate.h" | 250 #include "SkSpriteBlitterTemplate.h" |
255 | 251 |
256 /////////////////////////////////////////////////////////////////////////////// | 252 /////////////////////////////////////////////////////////////////////////////// |
257 | 253 |
258 class Sprite_D16_S32_BlitRowProc : public SkSpriteBlitter { | 254 class Sprite_D16_S32_BlitRowProc : public SkSpriteBlitter { |
259 public: | 255 public: |
260 Sprite_D16_S32_BlitRowProc(const SkBitmap& source) | 256 Sprite_D16_S32_BlitRowProc(const SkPixmap& source) : SkSpriteBlitter(source)
{} |
261 : SkSpriteBlitter(source) {} | |
262 | 257 |
263 bool setup(const SkBitmap& device, int left, int top, | 258 void setup(const SkBitmap& device, int left, int top, const SkPaint& paint)
override { |
264 const SkPaint& paint) override { | 259 this->INHERITED::setup(device, left, top, paint); |
265 if (!this->INHERITED::setup(device, left, top, paint)) { | |
266 return false; | |
267 } | |
268 | 260 |
269 unsigned flags = 0; | 261 unsigned flags = 0; |
270 | 262 |
271 if (paint.getAlpha() < 0xFF) { | 263 if (paint.getAlpha() < 0xFF) { |
272 flags |= SkBlitRow::kGlobalAlpha_Flag; | 264 flags |= SkBlitRow::kGlobalAlpha_Flag; |
273 } | 265 } |
274 if (!fSource->isOpaque()) { | 266 if (!fSource.isOpaque()) { |
275 flags |= SkBlitRow::kSrcPixelAlpha_Flag; | 267 flags |= SkBlitRow::kSrcPixelAlpha_Flag; |
276 } | 268 } |
277 if (paint.isDither()) { | 269 if (paint.isDither()) { |
278 flags |= SkBlitRow::kDither_Flag; | 270 flags |= SkBlitRow::kDither_Flag; |
279 } | 271 } |
280 fProc = SkBlitRow::Factory16(flags); | 272 fProc = SkBlitRow::Factory16(flags); |
281 return true; | |
282 } | 273 } |
283 | 274 |
284 void blitRect(int x, int y, int width, int height) override { | 275 void blitRect(int x, int y, int width, int height) override { |
285 uint16_t* SK_RESTRICT dst = fDevice->getAddr16(x, y); | 276 uint16_t* SK_RESTRICT dst = fDevice->getAddr16(x, y); |
286 const SkPMColor* SK_RESTRICT src = fSource->addr32(x - fLeft, y - fTop); | 277 const SkPMColor* SK_RESTRICT src = fSource.addr32(x - fLeft, y - fTop); |
287 size_t dstRB = fDevice->rowBytes(); | 278 size_t dstRB = fDevice->rowBytes(); |
288 size_t srcRB = fSource->rowBytes(); | 279 size_t srcRB = fSource.rowBytes(); |
289 SkBlitRow::Proc16 proc = fProc; | 280 SkBlitRow::Proc16 proc = fProc; |
290 U8CPU alpha = fPaint->getAlpha(); | 281 U8CPU alpha = fPaint->getAlpha(); |
291 | 282 |
292 while (--height >= 0) { | 283 while (--height >= 0) { |
293 proc(dst, src, width, alpha, x, y); | 284 proc(dst, src, width, alpha, x, y); |
294 y += 1; | 285 y += 1; |
295 dst = (uint16_t* SK_RESTRICT)((char*)dst + dstRB); | 286 dst = (uint16_t* SK_RESTRICT)((char*)dst + dstRB); |
296 src = (const SkPMColor* SK_RESTRICT)((const char*)src + srcRB); | 287 src = (const SkPMColor* SK_RESTRICT)((const char*)src + srcRB); |
297 } | 288 } |
298 } | 289 } |
299 | 290 |
300 private: | 291 private: |
301 SkBlitRow::Proc16 fProc; | 292 SkBlitRow::Proc16 fProc; |
302 | 293 |
303 typedef SkSpriteBlitter INHERITED; | 294 typedef SkSpriteBlitter INHERITED; |
304 }; | 295 }; |
305 | 296 |
306 /////////////////////////////////////////////////////////////////////////////// | 297 /////////////////////////////////////////////////////////////////////////////// |
307 | 298 |
308 SkSpriteBlitter* SkSpriteBlitter::ChooseD16(const SkBitmap& source, const SkPain
t& paint, | 299 SkSpriteBlitter* SkSpriteBlitter::ChooseD16(const SkPixmap& source, const SkPain
t& paint, |
309 SkTBlitterAllocator* allocator) { | 300 SkTBlitterAllocator* allocator) { |
310 | 301 |
311 SkASSERT(allocator != NULL); | 302 SkASSERT(allocator != NULL); |
312 | 303 |
313 if (paint.getMaskFilter() != NULL) { // may add cases for this | 304 if (paint.getMaskFilter() != NULL) { // may add cases for this |
314 return NULL; | 305 return NULL; |
315 } | 306 } |
316 if (paint.getXfermode() != NULL) { // may add cases for this | 307 if (paint.getXfermode() != NULL) { // may add cases for this |
317 return NULL; | 308 return NULL; |
318 } | 309 } |
319 if (paint.getColorFilter() != NULL) { // may add cases for this | 310 if (paint.getColorFilter() != NULL) { // may add cases for this |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 } else { | 361 } else { |
371 blitter = allocator->createT<Sprite_D16_SIndex8A_Blend>(sour
ce, alpha); | 362 blitter = allocator->createT<Sprite_D16_SIndex8A_Blend>(sour
ce, alpha); |
372 } | 363 } |
373 } | 364 } |
374 break; | 365 break; |
375 default: | 366 default: |
376 break; | 367 break; |
377 } | 368 } |
378 return blitter; | 369 return blitter; |
379 } | 370 } |
OLD | NEW |