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 "SkBlitRow.h" | 10 #include "SkBlitRow.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 virtual void blitAntiH(int x, int y, const SkAlpha* antialias, | 63 virtual void blitAntiH(int x, int y, const SkAlpha* antialias, |
64 const int16_t* runs) SK_OVERRIDE; | 64 const int16_t* runs) SK_OVERRIDE; |
65 void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; | 65 void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; |
66 void blitRect(int x, int y, int width, int height) SK_OVERRIDE; | 66 void blitRect(int x, int y, int width, int height) SK_OVERRIDE; |
67 virtual void blitMask(const SkMask&, | 67 virtual void blitMask(const SkMask&, |
68 const SkIRect&) SK_OVERRIDE; | 68 const SkIRect&) SK_OVERRIDE; |
69 const SkBitmap* justAnOpaqueColor(uint32_t*) SK_OVERRIDE; | 69 const SkBitmap* justAnOpaqueColor(uint32_t*) SK_OVERRIDE; |
70 | 70 |
71 protected: | 71 protected: |
72 SkPMColor fSrcColor32; | 72 SkPMColor fSrcColor32; |
| 73 SkPMColor fSrcColors32[8]; |
73 uint32_t fExpandedRaw16; | 74 uint32_t fExpandedRaw16; |
74 unsigned fScale; | 75 unsigned fScale; |
75 uint16_t fColor16; // already scaled by fScale | 76 uint16_t fColor16; // already scaled by fScale |
76 uint16_t fRawColor16; // unscaled | 77 uint16_t fRawColor16; // unscaled |
77 uint16_t fRawDither16; // unscaled | 78 uint16_t fRawDither16; // unscaled |
78 SkBool8 fDoDither; | 79 SkBool8 fDoDither; |
79 | 80 |
| 81 SkBlitRow::Blend32_16_row_Proc blendS32D16Row_Proc; |
| 82 |
80 // illegal | 83 // illegal |
81 SkRGB16_Blitter& operator=(const SkRGB16_Blitter&); | 84 SkRGB16_Blitter& operator=(const SkRGB16_Blitter&); |
82 | 85 |
83 typedef SkRasterBlitter INHERITED; | 86 typedef SkRasterBlitter INHERITED; |
84 }; | 87 }; |
85 | 88 |
86 class SkRGB16_Opaque_Blitter : public SkRGB16_Blitter { | 89 class SkRGB16_Opaque_Blitter : public SkRGB16_Blitter { |
87 public: | 90 public: |
88 SkRGB16_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint); | 91 SkRGB16_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint); |
89 void blitH(int x, int y, int width) SK_OVERRIDE; | 92 void blitH(int x, int y, int width) SK_OVERRIDE; |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 } | 523 } |
521 } | 524 } |
522 | 525 |
523 /////////////////////////////////////////////////////////////////////////////// | 526 /////////////////////////////////////////////////////////////////////////////// |
524 | 527 |
525 SkRGB16_Blitter::SkRGB16_Blitter(const SkBitmap& device, const SkPaint& paint) | 528 SkRGB16_Blitter::SkRGB16_Blitter(const SkBitmap& device, const SkPaint& paint) |
526 : INHERITED(device) { | 529 : INHERITED(device) { |
527 SkColor color = paint.getColor(); | 530 SkColor color = paint.getColor(); |
528 | 531 |
529 fSrcColor32 = SkPreMultiplyColor(color); | 532 fSrcColor32 = SkPreMultiplyColor(color); |
| 533 for (int count = 0; count < 8; count++) { |
| 534 fSrcColors32[count] = fSrcColor32; |
| 535 } |
| 536 |
530 fScale = SkAlpha255To256(SkColorGetA(color)); | 537 fScale = SkAlpha255To256(SkColorGetA(color)); |
531 | 538 |
532 int r = SkColorGetR(color); | 539 int r = SkColorGetR(color); |
533 int g = SkColorGetG(color); | 540 int g = SkColorGetG(color); |
534 int b = SkColorGetB(color); | 541 int b = SkColorGetB(color); |
535 | 542 |
536 fRawColor16 = fRawDither16 = SkPack888ToRGB16(r, g, b); | 543 fRawColor16 = fRawDither16 = SkPack888ToRGB16(r, g, b); |
537 // if we're dithered, use fRawDither16 to hold that. | 544 // if we're dithered, use fRawDither16 to hold that. |
538 if ((fDoDither = paint.isDither()) != false) { | 545 if ((fDoDither = paint.isDither()) != false) { |
539 fRawDither16 = SkDitherPack888ToRGB16(r, g, b); | 546 fRawDither16 = SkDitherPack888ToRGB16(r, g, b); |
540 } | 547 } |
541 | 548 |
542 fExpandedRaw16 = SkExpand_rgb_16(fRawColor16); | 549 fExpandedRaw16 = SkExpand_rgb_16(fRawColor16); |
543 | 550 |
544 fColor16 = SkPackRGB16( SkAlphaMul(r, fScale) >> (8 - SK_R16_BITS), | 551 fColor16 = SkPackRGB16( SkAlphaMul(r, fScale) >> (8 - SK_R16_BITS), |
545 SkAlphaMul(g, fScale) >> (8 - SK_G16_BITS), | 552 SkAlphaMul(g, fScale) >> (8 - SK_G16_BITS), |
546 SkAlphaMul(b, fScale) >> (8 - SK_B16_BITS)); | 553 SkAlphaMul(b, fScale) >> (8 - SK_B16_BITS)); |
| 554 |
| 555 blendS32D16Row_Proc = SkBlitRow::Blend32_16_rowProcFactory(); |
547 } | 556 } |
548 | 557 |
549 const SkBitmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { | 558 const SkBitmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { |
550 if (!fDoDither && 256 == fScale) { | 559 if (!fDoDither && 256 == fScale) { |
551 *value = fRawColor16; | 560 *value = fRawColor16; |
552 return &fDevice; | 561 return &fDevice; |
553 } | 562 } |
554 return NULL; | 563 return NULL; |
555 } | 564 } |
556 | 565 |
557 static uint32_t pmcolor_to_expand16(SkPMColor c) { | 566 static uint32_t pmcolor_to_expand16(SkPMColor c) { |
558 unsigned r = SkGetPackedR32(c); | 567 unsigned r = SkGetPackedR32(c); |
559 unsigned g = SkGetPackedG32(c); | 568 unsigned g = SkGetPackedG32(c); |
560 unsigned b = SkGetPackedB32(c); | 569 unsigned b = SkGetPackedB32(c); |
561 return (g << 24) | (r << 13) | (b << 2); | 570 return (g << 24) | (r << 13) | (b << 2); |
562 } | 571 } |
563 | 572 |
564 static inline void blend32_16_row(SkPMColor src, uint16_t dst[], int count) { | 573 static inline void blend32_16_row(const SkPMColor* SK_RESTRICT src, |
| 574 uint16_t dst[], int count) { |
565 SkASSERT(count > 0); | 575 SkASSERT(count > 0); |
566 uint32_t src_expand = pmcolor_to_expand16(src); | 576 uint32_t src_expand = pmcolor_to_expand16(*src); |
567 unsigned scale = SkAlpha255To256(0xFF - SkGetPackedA32(src)) >> 3; | 577 unsigned scale = SkAlpha255To256(0xFF - SkGetPackedA32(*src)) >> 3; |
568 do { | 578 do { |
569 uint32_t dst_expand = SkExpand_rgb_16(*dst) * scale; | 579 uint32_t dst_expand = SkExpand_rgb_16(*dst) * scale; |
570 *dst = SkCompact_rgb_16((src_expand + dst_expand) >> 5); | 580 *dst = SkCompact_rgb_16((src_expand + dst_expand) >> 5); |
571 dst += 1; | 581 dst += 1; |
572 } while (--count != 0); | 582 } while (--count != 0); |
573 } | 583 } |
574 | 584 |
| 585 SkBlitRow::Blend32_16_row_Proc SkBlitRow::Blend32_16_rowProcFactory() { |
| 586 SkBlitRow::Blend32_16_row_Proc proc = NULL; |
| 587 proc = PlatformBlend32_16_rowProc(); |
| 588 if (proc == NULL) { |
| 589 proc = blend32_16_row; |
| 590 } |
| 591 return proc; |
| 592 }; |
| 593 |
575 void SkRGB16_Blitter::blitH(int x, int y, int width) { | 594 void SkRGB16_Blitter::blitH(int x, int y, int width) { |
576 SkASSERT(width > 0); | 595 SkASSERT(width > 0); |
577 SkASSERT(x + width <= fDevice.width()); | 596 SkASSERT(x + width <= fDevice.width()); |
578 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 597 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
579 | 598 |
580 // TODO: respect fDoDither | 599 // TODO: respect fDoDither |
581 blend32_16_row(fSrcColor32, device, width); | 600 blendS32D16Row_Proc(fSrcColors32, device, width); |
582 } | 601 } |
583 | 602 |
584 void SkRGB16_Blitter::blitAntiH(int x, int y, | 603 void SkRGB16_Blitter::blitAntiH(int x, int y, |
585 const SkAlpha* SK_RESTRICT antialias, | 604 const SkAlpha* SK_RESTRICT antialias, |
586 const int16_t* SK_RESTRICT runs) { | 605 const int16_t* SK_RESTRICT runs) { |
587 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 606 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
588 uint32_t srcExpanded = fExpandedRaw16; | 607 uint32_t srcExpanded = fExpandedRaw16; |
589 unsigned scale = fScale; | 608 unsigned scale = fScale; |
590 | 609 |
591 // TODO: respect fDoDither | 610 // TODO: respect fDoDither |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 uint32_t dst32 = SkExpand_rgb_16(*device) * scale5; | 693 uint32_t dst32 = SkExpand_rgb_16(*device) * scale5; |
675 *device = SkCompact_rgb_16((src32 + dst32) >> 5); | 694 *device = SkCompact_rgb_16((src32 + dst32) >> 5); |
676 device = (uint16_t*)((char*)device + deviceRB); | 695 device = (uint16_t*)((char*)device + deviceRB); |
677 } while (--height != 0); | 696 } while (--height != 0); |
678 } | 697 } |
679 | 698 |
680 void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) { | 699 void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) { |
681 SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height()); | 700 SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height()); |
682 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 701 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
683 size_t deviceRB = fDevice.rowBytes(); | 702 size_t deviceRB = fDevice.rowBytes(); |
684 SkPMColor src32 = fSrcColor32; | |
685 | 703 |
686 while (--height >= 0) { | 704 while (--height >= 0) { |
687 blend32_16_row(src32, device, width); | 705 blendS32D16Row_Proc(fSrcColors32, device, width); |
688 device = (uint16_t*)((char*)device + deviceRB); | 706 device = (uint16_t*)((char*)device + deviceRB); |
689 } | 707 } |
690 } | 708 } |
691 | 709 |
692 /////////////////////////////////////////////////////////////////////////////// | 710 /////////////////////////////////////////////////////////////////////////////// |
693 | 711 |
694 SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, | 712 SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, |
695 const SkPaint& paint, | 713 const SkPaint& paint, |
696 SkShader::Context* shaderCont
ext) | 714 SkShader::Context* shaderCont
ext) |
697 : SkRGB16_Shader_Blitter(device, paint, shaderContext) { | 715 : SkRGB16_Shader_Blitter(device, paint, shaderContext) { |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 #endif | 1078 #endif |
1061 } else if (0xFF == SkColorGetA(color)) { | 1079 } else if (0xFF == SkColorGetA(color)) { |
1062 blitter = allocator->createT<SkRGB16_Opaque_Blitter>(device, paint); | 1080 blitter = allocator->createT<SkRGB16_Opaque_Blitter>(device, paint); |
1063 } else { | 1081 } else { |
1064 blitter = allocator->createT<SkRGB16_Blitter>(device, paint); | 1082 blitter = allocator->createT<SkRGB16_Blitter>(device, paint); |
1065 } | 1083 } |
1066 } | 1084 } |
1067 | 1085 |
1068 return blitter; | 1086 return blitter; |
1069 } | 1087 } |
OLD | NEW |