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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 virtual void blitAntiH(int x, int y, const SkAlpha* antialias, | 100 virtual void blitAntiH(int x, int y, const SkAlpha* antialias, |
101 const int16_t* runs); | 101 const int16_t* runs); |
102 | 102 |
103 private: | 103 private: |
104 typedef SkRGB16_Opaque_Blitter INHERITED; | 104 typedef SkRGB16_Opaque_Blitter INHERITED; |
105 }; | 105 }; |
106 #endif | 106 #endif |
107 | 107 |
108 class SkRGB16_Shader_Blitter : public SkShaderBlitter { | 108 class SkRGB16_Shader_Blitter : public SkShaderBlitter { |
109 public: | 109 public: |
110 SkRGB16_Shader_Blitter(const SkBitmap& device, const SkPaint& paint); | 110 SkRGB16_Shader_Blitter(const SkBitmap& device, const SkPaint& paint, |
| 111 SkShader::Context* shaderContext); |
111 virtual ~SkRGB16_Shader_Blitter(); | 112 virtual ~SkRGB16_Shader_Blitter(); |
112 virtual void blitH(int x, int y, int width); | 113 virtual void blitH(int x, int y, int width); |
113 virtual void blitAntiH(int x, int y, const SkAlpha* antialias, | 114 virtual void blitAntiH(int x, int y, const SkAlpha* antialias, |
114 const int16_t* runs); | 115 const int16_t* runs); |
115 virtual void blitRect(int x, int y, int width, int height); | 116 virtual void blitRect(int x, int y, int width, int height); |
116 | 117 |
117 protected: | 118 protected: |
118 SkPMColor* fBuffer; | 119 SkPMColor* fBuffer; |
119 SkBlitRow::Proc fOpaqueProc; | 120 SkBlitRow::Proc fOpaqueProc; |
120 SkBlitRow::Proc fAlphaProc; | 121 SkBlitRow::Proc fAlphaProc; |
121 | 122 |
122 private: | 123 private: |
123 // illegal | 124 // illegal |
124 SkRGB16_Shader_Blitter& operator=(const SkRGB16_Shader_Blitter&); | 125 SkRGB16_Shader_Blitter& operator=(const SkRGB16_Shader_Blitter&); |
125 | 126 |
126 typedef SkShaderBlitter INHERITED; | 127 typedef SkShaderBlitter INHERITED; |
127 }; | 128 }; |
128 | 129 |
129 // used only if the shader can perform shadSpan16 | 130 // used only if the shader can perform shadSpan16 |
130 class SkRGB16_Shader16_Blitter : public SkRGB16_Shader_Blitter { | 131 class SkRGB16_Shader16_Blitter : public SkRGB16_Shader_Blitter { |
131 public: | 132 public: |
132 SkRGB16_Shader16_Blitter(const SkBitmap& device, const SkPaint& paint); | 133 SkRGB16_Shader16_Blitter(const SkBitmap& device, const SkPaint& paint, |
| 134 SkShader::Context* shaderContext); |
133 virtual void blitH(int x, int y, int width); | 135 virtual void blitH(int x, int y, int width); |
134 virtual void blitAntiH(int x, int y, const SkAlpha* antialias, | 136 virtual void blitAntiH(int x, int y, const SkAlpha* antialias, |
135 const int16_t* runs); | 137 const int16_t* runs); |
136 virtual void blitRect(int x, int y, int width, int height); | 138 virtual void blitRect(int x, int y, int width, int height); |
137 | 139 |
138 private: | 140 private: |
139 typedef SkRGB16_Shader_Blitter INHERITED; | 141 typedef SkRGB16_Shader_Blitter INHERITED; |
140 }; | 142 }; |
141 | 143 |
142 class SkRGB16_Shader_Xfermode_Blitter : public SkShaderBlitter { | 144 class SkRGB16_Shader_Xfermode_Blitter : public SkShaderBlitter { |
143 public: | 145 public: |
144 SkRGB16_Shader_Xfermode_Blitter(const SkBitmap& device, const SkPaint& paint
); | 146 SkRGB16_Shader_Xfermode_Blitter(const SkBitmap& device, const SkPaint& paint
, |
| 147 SkShader::Context* shaderContext); |
145 virtual ~SkRGB16_Shader_Xfermode_Blitter(); | 148 virtual ~SkRGB16_Shader_Xfermode_Blitter(); |
146 virtual void blitH(int x, int y, int width); | 149 virtual void blitH(int x, int y, int width); |
147 virtual void blitAntiH(int x, int y, const SkAlpha* antialias, | 150 virtual void blitAntiH(int x, int y, const SkAlpha* antialias, |
148 const int16_t* runs); | 151 const int16_t* runs); |
149 | 152 |
150 private: | 153 private: |
151 SkXfermode* fXfermode; | 154 SkXfermode* fXfermode; |
152 SkPMColor* fBuffer; | 155 SkPMColor* fBuffer; |
153 uint8_t* fAAExpand; | 156 uint8_t* fAAExpand; |
154 | 157 |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 | 675 |
673 while (--height >= 0) { | 676 while (--height >= 0) { |
674 blend32_16_row(src32, device, width); | 677 blend32_16_row(src32, device, width); |
675 device = (uint16_t*)((char*)device + deviceRB); | 678 device = (uint16_t*)((char*)device + deviceRB); |
676 } | 679 } |
677 } | 680 } |
678 | 681 |
679 /////////////////////////////////////////////////////////////////////////////// | 682 /////////////////////////////////////////////////////////////////////////////// |
680 | 683 |
681 SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, | 684 SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, |
682 const SkPaint& paint) | 685 const SkPaint& paint, |
683 : SkRGB16_Shader_Blitter(device, paint) { | 686 SkShader::Context* shaderCont
ext) |
| 687 : SkRGB16_Shader_Blitter(device, paint, shaderContext) { |
684 SkASSERT(SkShader::CanCallShadeSpan16(fShaderFlags)); | 688 SkASSERT(SkShader::CanCallShadeSpan16(fShaderFlags)); |
685 } | 689 } |
686 | 690 |
687 void SkRGB16_Shader16_Blitter::blitH(int x, int y, int width) { | 691 void SkRGB16_Shader16_Blitter::blitH(int x, int y, int width) { |
688 SkASSERT(x + width <= fDevice.width()); | 692 SkASSERT(x + width <= fDevice.width()); |
689 | 693 |
690 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 694 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
691 SkShader* shader = fShader; | 695 SkShader::Context* shaderContext = fShaderContext; |
692 | 696 |
693 int alpha = shader->getSpan16Alpha(); | 697 int alpha = shaderContext->getSpan16Alpha(); |
694 if (0xFF == alpha) { | 698 if (0xFF == alpha) { |
695 shader->shadeSpan16(x, y, device, width); | 699 shaderContext->shadeSpan16(x, y, device, width); |
696 } else { | 700 } else { |
697 uint16_t* span16 = (uint16_t*)fBuffer; | 701 uint16_t* span16 = (uint16_t*)fBuffer; |
698 shader->shadeSpan16(x, y, span16, width); | 702 shaderContext->shadeSpan16(x, y, span16, width); |
699 SkBlendRGB16(span16, device, SkAlpha255To256(alpha), width); | 703 SkBlendRGB16(span16, device, SkAlpha255To256(alpha), width); |
700 } | 704 } |
701 } | 705 } |
702 | 706 |
703 void SkRGB16_Shader16_Blitter::blitRect(int x, int y, int width, int height) { | 707 void SkRGB16_Shader16_Blitter::blitRect(int x, int y, int width, int height) { |
704 SkShader* shader = fShader; | 708 SkShader::Context* shaderContext = fShaderContext; |
705 uint16_t* dst = fDevice.getAddr16(x, y); | 709 uint16_t* dst = fDevice.getAddr16(x, y); |
706 size_t dstRB = fDevice.rowBytes(); | 710 size_t dstRB = fDevice.rowBytes(); |
707 int alpha = shader->getSpan16Alpha(); | 711 int alpha = shaderContext->getSpan16Alpha(); |
708 | 712 |
709 if (0xFF == alpha) { | 713 if (0xFF == alpha) { |
710 if (fShaderFlags & SkShader::kConstInY16_Flag) { | 714 if (fShaderFlags & SkShader::kConstInY16_Flag) { |
711 // have the shader blit directly into the device the first time | 715 // have the shader blit directly into the device the first time |
712 shader->shadeSpan16(x, y, dst, width); | 716 shaderContext->shadeSpan16(x, y, dst, width); |
713 // and now just memcpy that line on the subsequent lines | 717 // and now just memcpy that line on the subsequent lines |
714 if (--height > 0) { | 718 if (--height > 0) { |
715 const uint16_t* orig = dst; | 719 const uint16_t* orig = dst; |
716 do { | 720 do { |
717 dst = (uint16_t*)((char*)dst + dstRB); | 721 dst = (uint16_t*)((char*)dst + dstRB); |
718 memcpy(dst, orig, width << 1); | 722 memcpy(dst, orig, width << 1); |
719 } while (--height); | 723 } while (--height); |
720 } | 724 } |
721 } else { // need to call shadeSpan16 for every line | 725 } else { // need to call shadeSpan16 for every line |
722 do { | 726 do { |
723 shader->shadeSpan16(x, y, dst, width); | 727 shaderContext->shadeSpan16(x, y, dst, width); |
724 y += 1; | 728 y += 1; |
725 dst = (uint16_t*)((char*)dst + dstRB); | 729 dst = (uint16_t*)((char*)dst + dstRB); |
726 } while (--height); | 730 } while (--height); |
727 } | 731 } |
728 } else { | 732 } else { |
729 int scale = SkAlpha255To256(alpha); | 733 int scale = SkAlpha255To256(alpha); |
730 uint16_t* span16 = (uint16_t*)fBuffer; | 734 uint16_t* span16 = (uint16_t*)fBuffer; |
731 if (fShaderFlags & SkShader::kConstInY16_Flag) { | 735 if (fShaderFlags & SkShader::kConstInY16_Flag) { |
732 shader->shadeSpan16(x, y, span16, width); | 736 shaderContext->shadeSpan16(x, y, span16, width); |
733 do { | 737 do { |
734 SkBlendRGB16(span16, dst, scale, width); | 738 SkBlendRGB16(span16, dst, scale, width); |
735 dst = (uint16_t*)((char*)dst + dstRB); | 739 dst = (uint16_t*)((char*)dst + dstRB); |
736 } while (--height); | 740 } while (--height); |
737 } else { | 741 } else { |
738 do { | 742 do { |
739 shader->shadeSpan16(x, y, span16, width); | 743 shaderContext->shadeSpan16(x, y, span16, width); |
740 SkBlendRGB16(span16, dst, scale, width); | 744 SkBlendRGB16(span16, dst, scale, width); |
741 y += 1; | 745 y += 1; |
742 dst = (uint16_t*)((char*)dst + dstRB); | 746 dst = (uint16_t*)((char*)dst + dstRB); |
743 } while (--height); | 747 } while (--height); |
744 } | 748 } |
745 } | 749 } |
746 } | 750 } |
747 | 751 |
748 void SkRGB16_Shader16_Blitter::blitAntiH(int x, int y, | 752 void SkRGB16_Shader16_Blitter::blitAntiH(int x, int y, |
749 const SkAlpha* SK_RESTRICT antialias, | 753 const SkAlpha* SK_RESTRICT antialias, |
750 const int16_t* SK_RESTRICT runs) { | 754 const int16_t* SK_RESTRICT runs) { |
751 SkShader* shader = fShader; | 755 SkShader::Context* shaderContext = fShaderContext; |
752 SkPMColor* SK_RESTRICT span = fBuffer; | 756 SkPMColor* SK_RESTRICT span = fBuffer; |
753 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 757 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
754 | 758 |
755 int alpha = shader->getSpan16Alpha(); | 759 int alpha = shaderContext->getSpan16Alpha(); |
756 uint16_t* span16 = (uint16_t*)span; | 760 uint16_t* span16 = (uint16_t*)span; |
757 | 761 |
758 if (0xFF == alpha) { | 762 if (0xFF == alpha) { |
759 for (;;) { | 763 for (;;) { |
760 int count = *runs; | 764 int count = *runs; |
761 if (count <= 0) { | 765 if (count <= 0) { |
762 break; | 766 break; |
763 } | 767 } |
764 SkASSERT(count <= fDevice.width()); // don't overrun fBuffer | 768 SkASSERT(count <= fDevice.width()); // don't overrun fBuffer |
765 | 769 |
766 int aa = *antialias; | 770 int aa = *antialias; |
767 if (aa == 255) { | 771 if (aa == 255) { |
768 // go direct to the device! | 772 // go direct to the device! |
769 shader->shadeSpan16(x, y, device, count); | 773 shaderContext->shadeSpan16(x, y, device, count); |
770 } else if (aa) { | 774 } else if (aa) { |
771 shader->shadeSpan16(x, y, span16, count); | 775 shaderContext->shadeSpan16(x, y, span16, count); |
772 SkBlendRGB16(span16, device, SkAlpha255To256(aa), count); | 776 SkBlendRGB16(span16, device, SkAlpha255To256(aa), count); |
773 } | 777 } |
774 device += count; | 778 device += count; |
775 runs += count; | 779 runs += count; |
776 antialias += count; | 780 antialias += count; |
777 x += count; | 781 x += count; |
778 } | 782 } |
779 } else { // span alpha is < 255 | 783 } else { // span alpha is < 255 |
780 alpha = SkAlpha255To256(alpha); | 784 alpha = SkAlpha255To256(alpha); |
781 for (;;) { | 785 for (;;) { |
782 int count = *runs; | 786 int count = *runs; |
783 if (count <= 0) { | 787 if (count <= 0) { |
784 break; | 788 break; |
785 } | 789 } |
786 SkASSERT(count <= fDevice.width()); // don't overrun fBuffer | 790 SkASSERT(count <= fDevice.width()); // don't overrun fBuffer |
787 | 791 |
788 int aa = SkAlphaMul(*antialias, alpha); | 792 int aa = SkAlphaMul(*antialias, alpha); |
789 if (aa) { | 793 if (aa) { |
790 shader->shadeSpan16(x, y, span16, count); | 794 shaderContext->shadeSpan16(x, y, span16, count); |
791 SkBlendRGB16(span16, device, SkAlpha255To256(aa), count); | 795 SkBlendRGB16(span16, device, SkAlpha255To256(aa), count); |
792 } | 796 } |
793 | 797 |
794 device += count; | 798 device += count; |
795 runs += count; | 799 runs += count; |
796 antialias += count; | 800 antialias += count; |
797 x += count; | 801 x += count; |
798 } | 802 } |
799 } | 803 } |
800 } | 804 } |
801 | 805 |
802 /////////////////////////////////////////////////////////////////////////////// | 806 /////////////////////////////////////////////////////////////////////////////// |
803 | 807 |
804 SkRGB16_Shader_Blitter::SkRGB16_Shader_Blitter(const SkBitmap& device, | 808 SkRGB16_Shader_Blitter::SkRGB16_Shader_Blitter(const SkBitmap& device, |
805 const SkPaint& paint) | 809 const SkPaint& paint, |
806 : INHERITED(device, paint) { | 810 SkShader::Context* shaderContext) |
| 811 : INHERITED(device, paint, shaderContext) { |
807 SkASSERT(paint.getXfermode() == NULL); | 812 SkASSERT(paint.getXfermode() == NULL); |
808 | 813 |
809 fBuffer = (SkPMColor*)sk_malloc_throw(device.width() * sizeof(SkPMColor)); | 814 fBuffer = (SkPMColor*)sk_malloc_throw(device.width() * sizeof(SkPMColor)); |
810 | 815 |
811 // compute SkBlitRow::Procs | 816 // compute SkBlitRow::Procs |
812 unsigned flags = 0; | 817 unsigned flags = 0; |
813 | 818 |
814 uint32_t shaderFlags = fShaderFlags; | 819 uint32_t shaderFlags = fShaderFlags; |
815 // shaders take care of global alpha, so we never set it in SkBlitRow | 820 // shaders take care of global alpha, so we never set it in SkBlitRow |
816 if (!(shaderFlags & SkShader::kOpaqueAlpha_Flag)) { | 821 if (!(shaderFlags & SkShader::kOpaqueAlpha_Flag)) { |
(...skipping 10 matching lines...) Expand all Loading... |
827 SkBitmap::kRGB_565_Config); | 832 SkBitmap::kRGB_565_Config); |
828 } | 833 } |
829 | 834 |
830 SkRGB16_Shader_Blitter::~SkRGB16_Shader_Blitter() { | 835 SkRGB16_Shader_Blitter::~SkRGB16_Shader_Blitter() { |
831 sk_free(fBuffer); | 836 sk_free(fBuffer); |
832 } | 837 } |
833 | 838 |
834 void SkRGB16_Shader_Blitter::blitH(int x, int y, int width) { | 839 void SkRGB16_Shader_Blitter::blitH(int x, int y, int width) { |
835 SkASSERT(x + width <= fDevice.width()); | 840 SkASSERT(x + width <= fDevice.width()); |
836 | 841 |
837 fShader->shadeSpan(x, y, fBuffer, width); | 842 fShaderContext->shadeSpan(x, y, fBuffer, width); |
838 // shaders take care of global alpha, so we pass 0xFF (should be ignored) | 843 // shaders take care of global alpha, so we pass 0xFF (should be ignored) |
839 fOpaqueProc(fDevice.getAddr16(x, y), fBuffer, width, 0xFF, x, y); | 844 fOpaqueProc(fDevice.getAddr16(x, y), fBuffer, width, 0xFF, x, y); |
840 } | 845 } |
841 | 846 |
842 void SkRGB16_Shader_Blitter::blitRect(int x, int y, int width, int height) { | 847 void SkRGB16_Shader_Blitter::blitRect(int x, int y, int width, int height) { |
843 SkShader* shader = fShader; | 848 SkShader::Context* shaderContext = fShaderContext; |
844 SkBlitRow::Proc proc = fOpaqueProc; | 849 SkBlitRow::Proc proc = fOpaqueProc; |
845 SkPMColor* buffer = fBuffer; | 850 SkPMColor* buffer = fBuffer; |
846 uint16_t* dst = fDevice.getAddr16(x, y); | 851 uint16_t* dst = fDevice.getAddr16(x, y); |
847 size_t dstRB = fDevice.rowBytes(); | 852 size_t dstRB = fDevice.rowBytes(); |
848 | 853 |
849 if (fShaderFlags & SkShader::kConstInY32_Flag) { | 854 if (fShaderFlags & SkShader::kConstInY32_Flag) { |
850 shader->shadeSpan(x, y, buffer, width); | 855 shaderContext->shadeSpan(x, y, buffer, width); |
851 do { | 856 do { |
852 proc(dst, buffer, width, 0xFF, x, y); | 857 proc(dst, buffer, width, 0xFF, x, y); |
853 y += 1; | 858 y += 1; |
854 dst = (uint16_t*)((char*)dst + dstRB); | 859 dst = (uint16_t*)((char*)dst + dstRB); |
855 } while (--height); | 860 } while (--height); |
856 } else { | 861 } else { |
857 do { | 862 do { |
858 shader->shadeSpan(x, y, buffer, width); | 863 shaderContext->shadeSpan(x, y, buffer, width); |
859 proc(dst, buffer, width, 0xFF, x, y); | 864 proc(dst, buffer, width, 0xFF, x, y); |
860 y += 1; | 865 y += 1; |
861 dst = (uint16_t*)((char*)dst + dstRB); | 866 dst = (uint16_t*)((char*)dst + dstRB); |
862 } while (--height); | 867 } while (--height); |
863 } | 868 } |
864 } | 869 } |
865 | 870 |
866 static inline int count_nonzero_span(const int16_t runs[], const SkAlpha aa[]) { | 871 static inline int count_nonzero_span(const int16_t runs[], const SkAlpha aa[]) { |
867 int count = 0; | 872 int count = 0; |
868 for (;;) { | 873 for (;;) { |
869 int n = *runs; | 874 int n = *runs; |
870 if (n == 0 || *aa == 0) { | 875 if (n == 0 || *aa == 0) { |
871 break; | 876 break; |
872 } | 877 } |
873 runs += n; | 878 runs += n; |
874 aa += n; | 879 aa += n; |
875 count += n; | 880 count += n; |
876 } | 881 } |
877 return count; | 882 return count; |
878 } | 883 } |
879 | 884 |
880 void SkRGB16_Shader_Blitter::blitAntiH(int x, int y, | 885 void SkRGB16_Shader_Blitter::blitAntiH(int x, int y, |
881 const SkAlpha* SK_RESTRICT antialias, | 886 const SkAlpha* SK_RESTRICT antialias, |
882 const int16_t* SK_RESTRICT runs) { | 887 const int16_t* SK_RESTRICT runs) { |
883 SkShader* shader = fShader; | 888 SkShader::Context* shaderContext = fShaderContext; |
884 SkPMColor* SK_RESTRICT span = fBuffer; | 889 SkPMColor* SK_RESTRICT span = fBuffer; |
885 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 890 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
886 | 891 |
887 for (;;) { | 892 for (;;) { |
888 int count = *runs; | 893 int count = *runs; |
889 if (count <= 0) { | 894 if (count <= 0) { |
890 break; | 895 break; |
891 } | 896 } |
892 int aa = *antialias; | 897 int aa = *antialias; |
893 if (0 == aa) { | 898 if (0 == aa) { |
894 device += count; | 899 device += count; |
895 runs += count; | 900 runs += count; |
896 antialias += count; | 901 antialias += count; |
897 x += count; | 902 x += count; |
898 continue; | 903 continue; |
899 } | 904 } |
900 | 905 |
901 int nonZeroCount = count + count_nonzero_span(runs + count, antialias +
count); | 906 int nonZeroCount = count + count_nonzero_span(runs + count, antialias +
count); |
902 | 907 |
903 SkASSERT(nonZeroCount <= fDevice.width()); // don't overrun fBuffer | 908 SkASSERT(nonZeroCount <= fDevice.width()); // don't overrun fBuffer |
904 shader->shadeSpan(x, y, span, nonZeroCount); | 909 shaderContext->shadeSpan(x, y, span, nonZeroCount); |
905 | 910 |
906 SkPMColor* localSpan = span; | 911 SkPMColor* localSpan = span; |
907 for (;;) { | 912 for (;;) { |
908 SkBlitRow::Proc proc = (aa == 0xFF) ? fOpaqueProc : fAlphaProc; | 913 SkBlitRow::Proc proc = (aa == 0xFF) ? fOpaqueProc : fAlphaProc; |
909 proc(device, localSpan, count, aa, x, y); | 914 proc(device, localSpan, count, aa, x, y); |
910 | 915 |
911 x += count; | 916 x += count; |
912 device += count; | 917 device += count; |
913 runs += count; | 918 runs += count; |
914 antialias += count; | 919 antialias += count; |
915 nonZeroCount -= count; | 920 nonZeroCount -= count; |
916 if (nonZeroCount == 0) { | 921 if (nonZeroCount == 0) { |
917 break; | 922 break; |
918 } | 923 } |
919 localSpan += count; | 924 localSpan += count; |
920 SkASSERT(nonZeroCount > 0); | 925 SkASSERT(nonZeroCount > 0); |
921 count = *runs; | 926 count = *runs; |
922 SkASSERT(count > 0); | 927 SkASSERT(count > 0); |
923 aa = *antialias; | 928 aa = *antialias; |
924 } | 929 } |
925 } | 930 } |
926 } | 931 } |
927 | 932 |
928 /////////////////////////////////////////////////////////////////////// | 933 /////////////////////////////////////////////////////////////////////// |
929 | 934 |
930 SkRGB16_Shader_Xfermode_Blitter::SkRGB16_Shader_Xfermode_Blitter( | 935 SkRGB16_Shader_Xfermode_Blitter::SkRGB16_Shader_Xfermode_Blitter( |
931 const SkBitmap& device, const SkPaint& paint) | 936 const SkBitmap& device, const SkPaint& paint, |
932 : INHERITED(device, paint) { | 937 SkShader::Context* shaderContext) |
| 938 : INHERITED(device, paint, shaderContext) { |
933 fXfermode = paint.getXfermode(); | 939 fXfermode = paint.getXfermode(); |
934 SkASSERT(fXfermode); | 940 SkASSERT(fXfermode); |
935 fXfermode->ref(); | 941 fXfermode->ref(); |
936 | 942 |
937 int width = device.width(); | 943 int width = device.width(); |
938 fBuffer = (SkPMColor*)sk_malloc_throw((width + (SkAlign4(width) >> 2)) * siz
eof(SkPMColor)); | 944 fBuffer = (SkPMColor*)sk_malloc_throw((width + (SkAlign4(width) >> 2)) * siz
eof(SkPMColor)); |
939 fAAExpand = (uint8_t*)(fBuffer + width); | 945 fAAExpand = (uint8_t*)(fBuffer + width); |
940 } | 946 } |
941 | 947 |
942 SkRGB16_Shader_Xfermode_Blitter::~SkRGB16_Shader_Xfermode_Blitter() { | 948 SkRGB16_Shader_Xfermode_Blitter::~SkRGB16_Shader_Xfermode_Blitter() { |
943 fXfermode->unref(); | 949 fXfermode->unref(); |
944 sk_free(fBuffer); | 950 sk_free(fBuffer); |
945 } | 951 } |
946 | 952 |
947 void SkRGB16_Shader_Xfermode_Blitter::blitH(int x, int y, int width) { | 953 void SkRGB16_Shader_Xfermode_Blitter::blitH(int x, int y, int width) { |
948 SkASSERT(x + width <= fDevice.width()); | 954 SkASSERT(x + width <= fDevice.width()); |
949 | 955 |
950 uint16_t* device = fDevice.getAddr16(x, y); | 956 uint16_t* device = fDevice.getAddr16(x, y); |
951 SkPMColor* span = fBuffer; | 957 SkPMColor* span = fBuffer; |
952 | 958 |
953 fShader->shadeSpan(x, y, span, width); | 959 fShaderContext->shadeSpan(x, y, span, width); |
954 fXfermode->xfer16(device, span, width, NULL); | 960 fXfermode->xfer16(device, span, width, NULL); |
955 } | 961 } |
956 | 962 |
957 void SkRGB16_Shader_Xfermode_Blitter::blitAntiH(int x, int y, | 963 void SkRGB16_Shader_Xfermode_Blitter::blitAntiH(int x, int y, |
958 const SkAlpha* SK_RESTRICT antialias, | 964 const SkAlpha* SK_RESTRICT antialias, |
959 const int16_t* SK_RESTRICT runs) { | 965 const int16_t* SK_RESTRICT runs) { |
960 SkShader* shader = fShader; | 966 SkShader::Context* shaderContext = fShaderContext; |
961 SkXfermode* mode = fXfermode; | 967 SkXfermode* mode = fXfermode; |
962 SkPMColor* SK_RESTRICT span = fBuffer; | 968 SkPMColor* SK_RESTRICT span = fBuffer; |
963 uint8_t* SK_RESTRICT aaExpand = fAAExpand; | 969 uint8_t* SK_RESTRICT aaExpand = fAAExpand; |
964 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 970 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
965 | 971 |
966 for (;;) { | 972 for (;;) { |
967 int count = *runs; | 973 int count = *runs; |
968 if (count <= 0) { | 974 if (count <= 0) { |
969 break; | 975 break; |
970 } | 976 } |
971 int aa = *antialias; | 977 int aa = *antialias; |
972 if (0 == aa) { | 978 if (0 == aa) { |
973 device += count; | 979 device += count; |
974 runs += count; | 980 runs += count; |
975 antialias += count; | 981 antialias += count; |
976 x += count; | 982 x += count; |
977 continue; | 983 continue; |
978 } | 984 } |
979 | 985 |
980 int nonZeroCount = count + count_nonzero_span(runs + count, | 986 int nonZeroCount = count + count_nonzero_span(runs + count, |
981 antialias + count); | 987 antialias + count); |
982 | 988 |
983 SkASSERT(nonZeroCount <= fDevice.width()); // don't overrun fBuffer | 989 SkASSERT(nonZeroCount <= fDevice.width()); // don't overrun fBuffer |
984 shader->shadeSpan(x, y, span, nonZeroCount); | 990 shaderContext->shadeSpan(x, y, span, nonZeroCount); |
985 | 991 |
986 x += nonZeroCount; | 992 x += nonZeroCount; |
987 SkPMColor* localSpan = span; | 993 SkPMColor* localSpan = span; |
988 for (;;) { | 994 for (;;) { |
989 if (aa == 0xFF) { | 995 if (aa == 0xFF) { |
990 mode->xfer16(device, localSpan, count, NULL); | 996 mode->xfer16(device, localSpan, count, NULL); |
991 } else { | 997 } else { |
992 SkASSERT(aa); | 998 SkASSERT(aa); |
993 memset(aaExpand, aa, count); | 999 memset(aaExpand, aa, count); |
994 mode->xfer16(device, localSpan, count, aaExpand); | 1000 mode->xfer16(device, localSpan, count, aaExpand); |
(...skipping 10 matching lines...) Expand all Loading... |
1005 count = *runs; | 1011 count = *runs; |
1006 SkASSERT(count > 0); | 1012 SkASSERT(count > 0); |
1007 aa = *antialias; | 1013 aa = *antialias; |
1008 } | 1014 } |
1009 } | 1015 } |
1010 } | 1016 } |
1011 | 1017 |
1012 /////////////////////////////////////////////////////////////////////////////// | 1018 /////////////////////////////////////////////////////////////////////////////// |
1013 | 1019 |
1014 SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint, | 1020 SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint, |
| 1021 SkShader::Context* shaderContext, |
1015 SkTBlitterAllocator* allocator) { | 1022 SkTBlitterAllocator* allocator) { |
1016 SkASSERT(allocator != NULL); | 1023 SkASSERT(allocator != NULL); |
1017 | 1024 |
1018 SkBlitter* blitter; | 1025 SkBlitter* blitter; |
1019 SkShader* shader = paint.getShader(); | 1026 SkShader* shader = paint.getShader(); |
1020 SkXfermode* mode = paint.getXfermode(); | 1027 SkXfermode* mode = paint.getXfermode(); |
1021 | 1028 |
1022 // we require a shader if there is an xfermode, handled by our caller | 1029 // we require a shader if there is an xfermode, handled by our caller |
1023 SkASSERT(NULL == mode || NULL != shader); | 1030 SkASSERT(NULL == mode || NULL != shader); |
1024 | 1031 |
1025 if (shader) { | 1032 if (shader) { |
| 1033 SkASSERT(shaderContext != NULL); |
1026 if (mode) { | 1034 if (mode) { |
1027 blitter = allocator->createT<SkRGB16_Shader_Xfermode_Blitter>(device
, paint); | 1035 blitter = allocator->createT<SkRGB16_Shader_Xfermode_Blitter>(device
, paint, |
1028 } else if (shader->canCallShadeSpan16()) { | 1036 shader
Context); |
1029 blitter = allocator->createT<SkRGB16_Shader16_Blitter>(device, paint
); | 1037 } else if (shaderContext->canCallShadeSpan16()) { |
| 1038 blitter = allocator->createT<SkRGB16_Shader16_Blitter>(device, paint
, shaderContext); |
1030 } else { | 1039 } else { |
1031 blitter = allocator->createT<SkRGB16_Shader_Blitter>(device, paint); | 1040 blitter = allocator->createT<SkRGB16_Shader_Blitter>(device, paint,
shaderContext); |
1032 } | 1041 } |
1033 } else { | 1042 } else { |
1034 // no shader, no xfermode, (and we always ignore colorfilter) | 1043 // no shader, no xfermode, (and we always ignore colorfilter) |
1035 SkColor color = paint.getColor(); | 1044 SkColor color = paint.getColor(); |
1036 if (0 == SkColorGetA(color)) { | 1045 if (0 == SkColorGetA(color)) { |
1037 blitter = allocator->createT<SkNullBlitter>(); | 1046 blitter = allocator->createT<SkNullBlitter>(); |
1038 #ifdef USE_BLACK_BLITTER | 1047 #ifdef USE_BLACK_BLITTER |
1039 } else if (SK_ColorBLACK == color) { | 1048 } else if (SK_ColorBLACK == color) { |
1040 blitter = allocator->createT<SkRGB16_Black_Blitter>(device, paint); | 1049 blitter = allocator->createT<SkRGB16_Black_Blitter>(device, paint); |
1041 #endif | 1050 #endif |
1042 } else if (0xFF == SkColorGetA(color)) { | 1051 } else if (0xFF == SkColorGetA(color)) { |
1043 blitter = allocator->createT<SkRGB16_Opaque_Blitter>(device, paint); | 1052 blitter = allocator->createT<SkRGB16_Opaque_Blitter>(device, paint); |
1044 } else { | 1053 } else { |
1045 blitter = allocator->createT<SkRGB16_Blitter>(device, paint); | 1054 blitter = allocator->createT<SkRGB16_Blitter>(device, paint); |
1046 } | 1055 } |
1047 } | 1056 } |
1048 | 1057 |
1049 return blitter; | 1058 return blitter; |
1050 } | 1059 } |
OLD | NEW |