Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(762)

Side by Side Diff: src/core/SkBlitter_RGB16.cpp

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

Powered by Google App Engine
This is Rietveld 408576698