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); |
| 963 offset->fX = bounds.left(); |
| 964 offset->fY = bounds.top(); |
| 965 bounds.offset(-srcOffset); |
961 switch (transformedLight->type()) { | 966 switch (transformedLight->type()) { |
962 case SkLight::kDistant_LightType: | 967 case SkLight::kDistant_LightType: |
963 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, trans
formedLight, src, dst, surfaceScale(), bounds); | 968 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, trans
formedLight, src, dst, surfaceScale(), bounds); |
964 break; | 969 break; |
965 case SkLight::kPoint_LightType: | 970 case SkLight::kPoint_LightType: |
966 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); | 971 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); |
967 break; | 972 break; |
968 case SkLight::kSpot_LightType: | 973 case SkLight::kSpot_LightType: |
969 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transfor
medLight, src, dst, surfaceScale(), bounds); | 974 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, transfor
medLight, src, dst, surfaceScale(), bounds); |
970 break; | 975 break; |
971 } | 976 } |
972 | 977 |
973 offset->fX += bounds.left(); | |
974 offset->fY += bounds.top(); | |
975 return true; | 978 return true; |
976 } | 979 } |
977 | 980 |
978 #if SK_SUPPORT_GPU | 981 #if SK_SUPPORT_GPU |
979 bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkMatrix& matrix, const SkIRect&) const { | 982 bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkMatrix& matrix, const SkIRect&) const { |
980 if (effect) { | 983 if (effect) { |
981 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 984 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
982 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri
x, kd()); | 985 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri
x, kd()); |
983 } | 986 } |
984 return true; | 987 return true; |
(...skipping 26 matching lines...) Expand all Loading... |
1011 buffer.writeScalar(fShininess); | 1014 buffer.writeScalar(fShininess); |
1012 } | 1015 } |
1013 | 1016 |
1014 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, | 1017 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, |
1015 const SkBitmap& source, | 1018 const SkBitmap& source, |
1016 const SkMatrix& ctm, | 1019 const SkMatrix& ctm, |
1017 SkBitmap* dst, | 1020 SkBitmap* dst, |
1018 SkIPoint* offset) { | 1021 SkIPoint* offset) { |
1019 SkImageFilter* input = getInput(0); | 1022 SkImageFilter* input = getInput(0); |
1020 SkBitmap src = source; | 1023 SkBitmap src = source; |
1021 if (input && !input->filterImage(proxy, source, ctm, &src, offset)) { | 1024 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 1025 if (input && !input->filterImage(proxy, source, ctm, &src, &srcOffset)) { |
1022 return false; | 1026 return false; |
1023 } | 1027 } |
1024 | 1028 |
1025 if (src.config() != SkBitmap::kARGB_8888_Config) { | 1029 if (src.config() != SkBitmap::kARGB_8888_Config) { |
1026 return false; | 1030 return false; |
1027 } | 1031 } |
1028 SkAutoLockPixels alp(src); | 1032 SkAutoLockPixels alp(src); |
1029 if (!src.getPixels()) { | 1033 if (!src.getPixels()) { |
1030 return false; | 1034 return false; |
1031 } | 1035 } |
1032 | 1036 |
1033 SkIRect bounds; | 1037 SkIRect bounds; |
1034 src.getBounds(&bounds); | 1038 src.getBounds(&bounds); |
| 1039 bounds.offset(srcOffset); |
1035 if (!this->applyCropRect(&bounds, ctm)) { | 1040 if (!this->applyCropRect(&bounds, ctm)) { |
1036 return false; | 1041 return false; |
1037 } | 1042 } |
1038 | 1043 |
1039 if (bounds.width() < 2 || bounds.height() < 2) { | 1044 if (bounds.width() < 2 || bounds.height() < 2) { |
1040 return false; | 1045 return false; |
1041 } | 1046 } |
1042 | 1047 |
1043 dst->setConfig(src.config(), bounds.width(), bounds.height()); | 1048 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
1044 dst->allocPixels(); | 1049 dst->allocPixels(); |
1045 if (!dst->getPixels()) { | 1050 if (!dst->getPixels()) { |
1046 return false; | 1051 return false; |
1047 } | 1052 } |
1048 | 1053 |
1049 SpecularLightingType lightingType(fKS, fShininess); | 1054 SpecularLightingType lightingType(fKS, fShininess); |
| 1055 offset->fX = bounds.left(); |
| 1056 offset->fY = bounds.top(); |
| 1057 bounds.offset(-srcOffset); |
1050 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); | 1058 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); |
1051 switch (transformedLight->type()) { | 1059 switch (transformedLight->type()) { |
1052 case SkLight::kDistant_LightType: | 1060 case SkLight::kDistant_LightType: |
1053 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, tran
sformedLight, src, dst, surfaceScale(), bounds); | 1061 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, tran
sformedLight, src, dst, surfaceScale(), bounds); |
1054 break; | 1062 break; |
1055 case SkLight::kPoint_LightType: | 1063 case SkLight::kPoint_LightType: |
1056 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); | 1064 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); |
1057 break; | 1065 break; |
1058 case SkLight::kSpot_LightType: | 1066 case SkLight::kSpot_LightType: |
1059 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); | 1067 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); |
1060 break; | 1068 break; |
1061 } | 1069 } |
1062 offset->fX += bounds.left(); | |
1063 offset->fY += bounds.top(); | |
1064 return true; | 1070 return true; |
1065 } | 1071 } |
1066 | 1072 |
1067 #if SK_SUPPORT_GPU | 1073 #if SK_SUPPORT_GPU |
1068 bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkMatrix& matrix, const SkIRect&) const { | 1074 bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkMatrix& matrix, const SkIRect&) const { |
1069 if (effect) { | 1075 if (effect) { |
1070 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 1076 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
1071 *effect = GrSpecularLightingEffect::Create(texture, light(), scale, matr
ix, ks(), shininess()); | 1077 *effect = GrSpecularLightingEffect::Create(texture, light(), scale, matr
ix, ks(), shininess()); |
1072 } | 1078 } |
1073 return true; | 1079 return true; |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 | 1608 |
1603 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1609 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1604 } | 1610 } |
1605 | 1611 |
1606 #endif | 1612 #endif |
1607 | 1613 |
1608 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1614 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1609 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1615 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1610 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1616 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1611 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1617 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |