OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkLightingImageFilter.h" | 8 #include "SkLightingImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 buffer.writeScalar(fKD); | 920 buffer.writeScalar(fKD); |
921 } | 921 } |
922 | 922 |
923 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, | 923 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, |
924 const SkBitmap& source, | 924 const SkBitmap& source, |
925 const SkMatrix& ctm, | 925 const SkMatrix& ctm, |
926 SkBitmap* dst, | 926 SkBitmap* dst, |
927 SkIPoint* offset) { | 927 SkIPoint* offset) { |
928 SkImageFilter* input = getInput(0); | 928 SkImageFilter* input = getInput(0); |
929 SkBitmap src = source; | 929 SkBitmap src = source; |
930 if (input && !input->filterImage(proxy, source, ctm, &src, offset)) { | 930 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 931 if (input && !input->filterImage(proxy, source, ctm, &src, &srcOffset)) { |
931 return false; | 932 return false; |
932 } | 933 } |
933 | 934 |
934 if (src.config() != SkBitmap::kARGB_8888_Config) { | 935 if (src.config() != SkBitmap::kARGB_8888_Config) { |
935 return false; | 936 return false; |
936 } | 937 } |
937 SkAutoLockPixels alp(src); | 938 SkAutoLockPixels alp(src); |
938 if (!src.getPixels()) { | 939 if (!src.getPixels()) { |
939 return false; | 940 return false; |
940 } | 941 } |
941 | 942 |
942 SkIRect bounds; | 943 SkIRect bounds; |
943 src.getBounds(&bounds); | 944 src.getBounds(&bounds); |
| 945 bounds.offset(srcOffset); |
944 if (!this->applyCropRect(&bounds, ctm)) { | 946 if (!this->applyCropRect(&bounds, ctm)) { |
945 return false; | 947 return false; |
946 } | 948 } |
947 | 949 |
948 if (bounds.width() < 2 || bounds.height() < 2) { | 950 if (bounds.width() < 2 || bounds.height() < 2) { |
949 return false; | 951 return false; |
950 } | 952 } |
951 | 953 |
952 dst->setConfig(src.config(), bounds.width(), bounds.height()); | 954 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
953 dst->allocPixels(); | 955 dst->allocPixels(); |
954 if (!dst->getPixels()) { | 956 if (!dst->getPixels()) { |
955 return false; | 957 return false; |
956 } | 958 } |
957 | 959 |
958 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); | 960 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); |
959 | 961 |
960 DiffuseLightingType lightingType(fKD); | 962 DiffuseLightingType lightingType(fKD); |
961 switch (transformedLight->type()) { | 963 switch (transformedLight->type()) { |
962 case SkLight::kDistant_LightType: | 964 case SkLight::kDistant_LightType: |
963 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, trans
formedLight, src, dst, surfaceScale(), bounds); | 965 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, trans
formedLight, src, dst, surfaceScale(), bounds); |
964 break; | 966 break; |
965 case SkLight::kPoint_LightType: | 967 case SkLight::kPoint_LightType: |
966 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); | 968 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); |
967 break; | 969 break; |
968 case SkLight::kSpot_LightType: | 970 case SkLight::kSpot_LightType: |
969 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transfor
medLight, src, dst, surfaceScale(), bounds); | 971 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transfor
medLight, src, dst, surfaceScale(), bounds); |
970 break; | 972 break; |
971 } | 973 } |
972 | 974 |
973 offset->fX += bounds.left(); | 975 offset->fX = bounds.left(); |
974 offset->fY += bounds.top(); | 976 offset->fY = bounds.top(); |
975 return true; | 977 return true; |
976 } | 978 } |
977 | 979 |
978 #if SK_SUPPORT_GPU | 980 #if SK_SUPPORT_GPU |
979 bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkMatrix& matrix, const SkIRect&) const { | 981 bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkMatrix& matrix, const SkIRect&) const { |
980 if (effect) { | 982 if (effect) { |
981 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 983 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
982 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri
x, kd()); | 984 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri
x, kd()); |
983 } | 985 } |
984 return true; | 986 return true; |
(...skipping 26 matching lines...) Expand all Loading... |
1011 buffer.writeScalar(fShininess); | 1013 buffer.writeScalar(fShininess); |
1012 } | 1014 } |
1013 | 1015 |
1014 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, | 1016 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, |
1015 const SkBitmap& source, | 1017 const SkBitmap& source, |
1016 const SkMatrix& ctm, | 1018 const SkMatrix& ctm, |
1017 SkBitmap* dst, | 1019 SkBitmap* dst, |
1018 SkIPoint* offset) { | 1020 SkIPoint* offset) { |
1019 SkImageFilter* input = getInput(0); | 1021 SkImageFilter* input = getInput(0); |
1020 SkBitmap src = source; | 1022 SkBitmap src = source; |
1021 if (input && !input->filterImage(proxy, source, ctm, &src, offset)) { | 1023 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 1024 if (input && !input->filterImage(proxy, source, ctm, &src, &srcOffset)) { |
1022 return false; | 1025 return false; |
1023 } | 1026 } |
1024 | 1027 |
1025 if (src.config() != SkBitmap::kARGB_8888_Config) { | 1028 if (src.config() != SkBitmap::kARGB_8888_Config) { |
1026 return false; | 1029 return false; |
1027 } | 1030 } |
1028 SkAutoLockPixels alp(src); | 1031 SkAutoLockPixels alp(src); |
1029 if (!src.getPixels()) { | 1032 if (!src.getPixels()) { |
1030 return false; | 1033 return false; |
1031 } | 1034 } |
1032 | 1035 |
1033 SkIRect bounds; | 1036 SkIRect bounds; |
1034 src.getBounds(&bounds); | 1037 src.getBounds(&bounds); |
| 1038 bounds.offset(srcOffset); |
1035 if (!this->applyCropRect(&bounds, ctm)) { | 1039 if (!this->applyCropRect(&bounds, ctm)) { |
1036 return false; | 1040 return false; |
1037 } | 1041 } |
1038 | 1042 |
1039 if (bounds.width() < 2 || bounds.height() < 2) { | 1043 if (bounds.width() < 2 || bounds.height() < 2) { |
1040 return false; | 1044 return false; |
1041 } | 1045 } |
1042 | 1046 |
1043 dst->setConfig(src.config(), bounds.width(), bounds.height()); | 1047 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
1044 dst->allocPixels(); | 1048 dst->allocPixels(); |
1045 if (!dst->getPixels()) { | 1049 if (!dst->getPixels()) { |
1046 return false; | 1050 return false; |
1047 } | 1051 } |
1048 | 1052 |
1049 SpecularLightingType lightingType(fKS, fShininess); | 1053 SpecularLightingType lightingType(fKS, fShininess); |
1050 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); | 1054 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); |
1051 switch (transformedLight->type()) { | 1055 switch (transformedLight->type()) { |
1052 case SkLight::kDistant_LightType: | 1056 case SkLight::kDistant_LightType: |
1053 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, tran
sformedLight, src, dst, surfaceScale(), bounds); | 1057 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, tran
sformedLight, src, dst, surfaceScale(), bounds); |
1054 break; | 1058 break; |
1055 case SkLight::kPoint_LightType: | 1059 case SkLight::kPoint_LightType: |
1056 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); | 1060 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); |
1057 break; | 1061 break; |
1058 case SkLight::kSpot_LightType: | 1062 case SkLight::kSpot_LightType: |
1059 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); | 1063 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); |
1060 break; | 1064 break; |
1061 } | 1065 } |
1062 offset->fX += bounds.left(); | 1066 offset->fX = bounds.left(); |
1063 offset->fY += bounds.top(); | 1067 offset->fY = bounds.top(); |
1064 return true; | 1068 return true; |
1065 } | 1069 } |
1066 | 1070 |
1067 #if SK_SUPPORT_GPU | 1071 #if SK_SUPPORT_GPU |
1068 bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkMatrix& matrix, const SkIRect&) const { | 1072 bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkMatrix& matrix, const SkIRect&) const { |
1069 if (effect) { | 1073 if (effect) { |
1070 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 1074 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
1071 *effect = GrSpecularLightingEffect::Create(texture, light(), scale, matr
ix, ks(), shininess()); | 1075 *effect = GrSpecularLightingEffect::Create(texture, light(), scale, matr
ix, ks(), shininess()); |
1072 } | 1076 } |
1073 return true; | 1077 return true; |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 | 1606 |
1603 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1607 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1604 } | 1608 } |
1605 | 1609 |
1606 #endif | 1610 #endif |
1607 | 1611 |
1608 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1612 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1609 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1613 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1610 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1614 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1611 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1615 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |