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 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 SkImageFilter* input = getInput(0); | 939 SkImageFilter* input = getInput(0); |
940 SkBitmap src = source; | 940 SkBitmap src = source; |
941 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 941 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
942 if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) { | 942 if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) { |
943 return false; | 943 return false; |
944 } | 944 } |
945 | 945 |
946 if (src.colorType() != kPMColor_SkColorType) { | 946 if (src.colorType() != kPMColor_SkColorType) { |
947 return false; | 947 return false; |
948 } | 948 } |
949 SkAutoLockPixels alp(src); | |
950 if (!src.getPixels()) { | |
951 return false; | |
952 } | |
953 | |
954 SkIRect bounds; | 949 SkIRect bounds; |
955 src.getBounds(&bounds); | 950 if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) { |
956 bounds.offset(srcOffset); | |
957 if (!this->applyCropRect(&bounds, ctx.ctm())) { | |
958 return false; | 951 return false; |
959 } | 952 } |
960 | 953 |
961 if (bounds.width() < 2 || bounds.height() < 2) { | 954 if (bounds.width() < 2 || bounds.height() < 2) { |
962 return false; | 955 return false; |
963 } | 956 } |
964 | 957 |
| 958 SkAutoLockPixels alp(src); |
| 959 if (!src.getPixels()) { |
| 960 return false; |
| 961 } |
| 962 |
965 dst->setConfig(src.config(), bounds.width(), bounds.height()); | 963 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
966 if (!dst->allocPixels()) { | 964 if (!dst->allocPixels()) { |
967 return false; | 965 return false; |
968 } | 966 } |
969 | 967 |
970 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm())); | 968 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm())); |
971 | 969 |
972 DiffuseLightingType lightingType(fKD); | 970 DiffuseLightingType lightingType(fKD); |
973 offset->fX = bounds.left(); | 971 offset->fX = bounds.left(); |
974 offset->fY = bounds.top(); | 972 offset->fY = bounds.top(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 SkImageFilter* input = getInput(0); | 1030 SkImageFilter* input = getInput(0); |
1033 SkBitmap src = source; | 1031 SkBitmap src = source; |
1034 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 1032 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
1035 if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) { | 1033 if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) { |
1036 return false; | 1034 return false; |
1037 } | 1035 } |
1038 | 1036 |
1039 if (src.colorType() != kPMColor_SkColorType) { | 1037 if (src.colorType() != kPMColor_SkColorType) { |
1040 return false; | 1038 return false; |
1041 } | 1039 } |
1042 SkAutoLockPixels alp(src); | |
1043 if (!src.getPixels()) { | |
1044 return false; | |
1045 } | |
1046 | 1040 |
1047 SkIRect bounds; | 1041 SkIRect bounds; |
1048 src.getBounds(&bounds); | 1042 if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) { |
1049 bounds.offset(srcOffset); | |
1050 if (!this->applyCropRect(&bounds, ctx.ctm())) { | |
1051 return false; | 1043 return false; |
1052 } | 1044 } |
1053 | 1045 |
1054 if (bounds.width() < 2 || bounds.height() < 2) { | 1046 if (bounds.width() < 2 || bounds.height() < 2) { |
1055 return false; | 1047 return false; |
1056 } | 1048 } |
1057 | 1049 |
| 1050 SkAutoLockPixels alp(src); |
| 1051 if (!src.getPixels()) { |
| 1052 return false; |
| 1053 } |
| 1054 |
1058 dst->setConfig(src.config(), bounds.width(), bounds.height()); | 1055 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
1059 dst->allocPixels(); | 1056 dst->allocPixels(); |
1060 if (!dst->getPixels()) { | 1057 if (!dst->getPixels()) { |
1061 return false; | 1058 return false; |
1062 } | 1059 } |
1063 | 1060 |
1064 SpecularLightingType lightingType(fKS, fShininess); | 1061 SpecularLightingType lightingType(fKS, fShininess); |
1065 offset->fX = bounds.left(); | 1062 offset->fX = bounds.left(); |
1066 offset->fY = bounds.top(); | 1063 offset->fY = bounds.top(); |
1067 bounds.offset(-srcOffset); | 1064 bounds.offset(-srcOffset); |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 | 1615 |
1619 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1616 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1620 } | 1617 } |
1621 | 1618 |
1622 #endif | 1619 #endif |
1623 | 1620 |
1624 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1621 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1625 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1622 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1626 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1623 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1627 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1624 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |