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 "SkBlitter.h" | 10 #include "SkBlitter.h" |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 /** By analyzing the paint (with an xfermode), we may decide we can take | 805 /** By analyzing the paint (with an xfermode), we may decide we can take |
806 special action. This enum lists our possible actions | 806 special action. This enum lists our possible actions |
807 */ | 807 */ |
808 enum XferInterp { | 808 enum XferInterp { |
809 kNormal_XferInterp, // no special interpretation, draw normally | 809 kNormal_XferInterp, // no special interpretation, draw normally |
810 kSrcOver_XferInterp, // draw as if in srcover mode | 810 kSrcOver_XferInterp, // draw as if in srcover mode |
811 kSkipDrawing_XferInterp // draw nothing | 811 kSkipDrawing_XferInterp // draw nothing |
812 }; | 812 }; |
813 | 813 |
814 static XferInterp interpret_xfermode(const SkPaint& paint, SkXfermode* xfer, | 814 static XferInterp interpret_xfermode(const SkPaint& paint, SkXfermode* xfer, |
815 SkBitmap::Config deviceConfig) { | 815 SkColorType deviceCT) { |
816 SkXfermode::Mode mode; | 816 SkXfermode::Mode mode; |
817 | 817 |
818 if (SkXfermode::AsMode(xfer, &mode)) { | 818 if (SkXfermode::AsMode(xfer, &mode)) { |
819 switch (mode) { | 819 switch (mode) { |
820 case SkXfermode::kSrc_Mode: | 820 case SkXfermode::kSrc_Mode: |
821 if (just_solid_color(paint)) { | 821 if (just_solid_color(paint)) { |
822 return kSrcOver_XferInterp; | 822 return kSrcOver_XferInterp; |
823 } | 823 } |
824 break; | 824 break; |
825 case SkXfermode::kDst_Mode: | 825 case SkXfermode::kDst_Mode: |
826 return kSkipDrawing_XferInterp; | 826 return kSkipDrawing_XferInterp; |
827 case SkXfermode::kSrcOver_Mode: | 827 case SkXfermode::kSrcOver_Mode: |
828 return kSrcOver_XferInterp; | 828 return kSrcOver_XferInterp; |
829 case SkXfermode::kDstOver_Mode: | 829 case SkXfermode::kDstOver_Mode: |
830 if (SkBitmap::kRGB_565_Config == deviceConfig) { | 830 if (kRGB_565_SkColorType == deviceCT) { |
831 return kSkipDrawing_XferInterp; | 831 return kSkipDrawing_XferInterp; |
832 } | 832 } |
833 break; | 833 break; |
834 case SkXfermode::kSrcIn_Mode: | 834 case SkXfermode::kSrcIn_Mode: |
835 if (SkBitmap::kRGB_565_Config == deviceConfig && | 835 if (kRGB_565_SkColorType == deviceCT && |
836 just_solid_color(paint)) { | 836 just_solid_color(paint)) { |
837 return kSrcOver_XferInterp; | 837 return kSrcOver_XferInterp; |
838 } | 838 } |
839 break; | 839 break; |
840 case SkXfermode::kDstIn_Mode: | 840 case SkXfermode::kDstIn_Mode: |
841 if (just_solid_color(paint)) { | 841 if (just_solid_color(paint)) { |
842 return kSkipDrawing_XferInterp; | 842 return kSkipDrawing_XferInterp; |
843 } | 843 } |
844 break; | 844 break; |
845 default: | 845 default: |
846 break; | 846 break; |
847 } | 847 } |
848 } | 848 } |
849 return kNormal_XferInterp; | 849 return kNormal_XferInterp; |
850 } | 850 } |
851 | 851 |
852 SkBlitter* SkBlitter::Choose(const SkBitmap& device, | 852 SkBlitter* SkBlitter::Choose(const SkBitmap& device, |
853 const SkMatrix& matrix, | 853 const SkMatrix& matrix, |
854 const SkPaint& origPaint, | 854 const SkPaint& origPaint, |
855 void* storage, size_t storageSize, | 855 void* storage, size_t storageSize, |
856 bool drawCoverage) { | 856 bool drawCoverage) { |
857 SkASSERT(storageSize == 0 || storage != NULL); | 857 SkASSERT(storageSize == 0 || storage != NULL); |
858 | 858 |
859 SkBlitter* blitter = NULL; | 859 SkBlitter* blitter = NULL; |
860 | 860 |
861 // which check, in case we're being called by a client with a dummy device | 861 // which check, in case we're being called by a client with a dummy device |
862 // (e.g. they have a bounder that always aborts the draw) | 862 // (e.g. they have a bounder that always aborts the draw) |
863 if (SkBitmap::kNo_Config == device.config() || | 863 if (kUnknown_SkColorType == device.colorType() || |
864 (drawCoverage && (SkBitmap::kA8_Config != device.config()))) { | 864 (drawCoverage && (kAlpha_8_SkColorType != device.colorType()))) { |
865 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); | 865 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); |
866 return blitter; | 866 return blitter; |
867 } | 867 } |
868 | 868 |
869 SkShader* shader = origPaint.getShader(); | 869 SkShader* shader = origPaint.getShader(); |
870 SkColorFilter* cf = origPaint.getColorFilter(); | 870 SkColorFilter* cf = origPaint.getColorFilter(); |
871 SkXfermode* mode = origPaint.getXfermode(); | 871 SkXfermode* mode = origPaint.getXfermode(); |
872 Sk3DShader* shader3D = NULL; | 872 Sk3DShader* shader3D = NULL; |
873 | 873 |
874 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); | 874 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); |
875 | 875 |
876 if (origPaint.getMaskFilter() != NULL && | 876 if (origPaint.getMaskFilter() != NULL && |
877 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { | 877 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { |
878 shader3D = SkNEW_ARGS(Sk3DShader, (shader)); | 878 shader3D = SkNEW_ARGS(Sk3DShader, (shader)); |
879 // we know we haven't initialized lazyPaint yet, so just do it | 879 // we know we haven't initialized lazyPaint yet, so just do it |
880 paint.writable()->setShader(shader3D)->unref(); | 880 paint.writable()->setShader(shader3D)->unref(); |
881 shader = shader3D; | 881 shader = shader3D; |
882 } | 882 } |
883 | 883 |
884 if (NULL != mode) { | 884 if (NULL != mode) { |
885 switch (interpret_xfermode(*paint, mode, device.config())) { | 885 switch (interpret_xfermode(*paint, mode, device.colorType())) { |
886 case kSrcOver_XferInterp: | 886 case kSrcOver_XferInterp: |
887 mode = NULL; | 887 mode = NULL; |
888 paint.writable()->setXfermode(NULL); | 888 paint.writable()->setXfermode(NULL); |
889 break; | 889 break; |
890 case kSkipDrawing_XferInterp: | 890 case kSkipDrawing_XferInterp: |
891 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); | 891 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); |
892 return blitter; | 892 return blitter; |
893 default: | 893 default: |
894 break; | 894 break; |
895 } | 895 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 * We make the first call here, in case it fails we can abort the draw. | 938 * We make the first call here, in case it fails we can abort the draw. |
939 * The endContext() call is made by the blitter (assuming setContext did | 939 * The endContext() call is made by the blitter (assuming setContext did |
940 * not fail) in its destructor. | 940 * not fail) in its destructor. |
941 */ | 941 */ |
942 if (shader && !shader->setContext(device, *paint, matrix)) { | 942 if (shader && !shader->setContext(device, *paint, matrix)) { |
943 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); | 943 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); |
944 return blitter; | 944 return blitter; |
945 } | 945 } |
946 | 946 |
947 | 947 |
948 switch (device.config()) { | 948 switch (device.colorType()) { |
949 case SkBitmap::kA8_Config: | 949 case kAlpha_8_SkColorType: |
950 if (drawCoverage) { | 950 if (drawCoverage) { |
951 SkASSERT(NULL == shader); | 951 SkASSERT(NULL == shader); |
952 SkASSERT(NULL == paint->getXfermode()); | 952 SkASSERT(NULL == paint->getXfermode()); |
953 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Coverage_Blitter, | 953 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Coverage_Blitter, |
954 storage, storageSize, (device, *paint)); | 954 storage, storageSize, (device, *paint)); |
955 } else if (shader) { | 955 } else if (shader) { |
956 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Shader_Blitter, | 956 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Shader_Blitter, |
957 storage, storageSize, (device, *paint)); | 957 storage, storageSize, (device, *paint)); |
958 } else { | 958 } else { |
959 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Blitter, | 959 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Blitter, |
960 storage, storageSize, (device, *paint)); | 960 storage, storageSize, (device, *paint)); |
961 } | 961 } |
962 break; | 962 break; |
963 | 963 |
964 case SkBitmap::kRGB_565_Config: | 964 case kRGB_565_SkColorType: |
965 blitter = SkBlitter_ChooseD565(device, *paint, storage, storageSize)
; | 965 blitter = SkBlitter_ChooseD565(device, *paint, storage, storageSize)
; |
966 break; | 966 break; |
967 | 967 |
968 case SkBitmap::kARGB_8888_Config: | 968 case kPMColor_SkColorType: |
969 if (shader) { | 969 if (shader) { |
970 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Shader_Blitter, | 970 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Shader_Blitter, |
971 storage, storageSize, (device, *paint)); | 971 storage, storageSize, (device, *paint)); |
972 } else if (paint->getColor() == SK_ColorBLACK) { | 972 } else if (paint->getColor() == SK_ColorBLACK) { |
973 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Black_Blitter, | 973 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Black_Blitter, |
974 storage, storageSize, (device, *paint)); | 974 storage, storageSize, (device, *paint)); |
975 } else if (paint->getAlpha() == 0xFF) { | 975 } else if (paint->getAlpha() == 0xFF) { |
976 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Opaque_Blitter, | 976 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Opaque_Blitter, |
977 storage, storageSize, (device, *paint)); | 977 storage, storageSize, (device, *paint)); |
978 } else { | 978 } else { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 | 1012 |
1013 fShader->ref(); | 1013 fShader->ref(); |
1014 fShaderFlags = fShader->getFlags(); | 1014 fShaderFlags = fShader->getFlags(); |
1015 } | 1015 } |
1016 | 1016 |
1017 SkShaderBlitter::~SkShaderBlitter() { | 1017 SkShaderBlitter::~SkShaderBlitter() { |
1018 SkASSERT(fShader->setContextHasBeenCalled()); | 1018 SkASSERT(fShader->setContextHasBeenCalled()); |
1019 fShader->endContext(); | 1019 fShader->endContext(); |
1020 fShader->unref(); | 1020 fShader->unref(); |
1021 } | 1021 } |
OLD | NEW |