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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 // Read type first. | 807 // Read type first. |
808 const SkLight::LightType type = (SkLight::LightType)buffer.readInt(); | 808 const SkLight::LightType type = (SkLight::LightType)buffer.readInt(); |
809 switch (type) { | 809 switch (type) { |
810 // Each of these constructors must first call SkLight's, so we'll read t
he baseclass | 810 // Each of these constructors must first call SkLight's, so we'll read t
he baseclass |
811 // then subclass, same order as flattenLight. | 811 // then subclass, same order as flattenLight. |
812 case SkLight::kDistant_LightType: return SkNEW_ARGS(SkDistantLight, (buf
fer)); | 812 case SkLight::kDistant_LightType: return SkNEW_ARGS(SkDistantLight, (buf
fer)); |
813 case SkLight::kPoint_LightType: return SkNEW_ARGS(SkPointLight, (buffe
r)); | 813 case SkLight::kPoint_LightType: return SkNEW_ARGS(SkPointLight, (buffe
r)); |
814 case SkLight::kSpot_LightType: return SkNEW_ARGS(SkSpotLight, (buffer
)); | 814 case SkLight::kSpot_LightType: return SkNEW_ARGS(SkSpotLight, (buffer
)); |
815 default: | 815 default: |
816 SkDEBUGFAIL("Unknown LightType."); | 816 SkDEBUGFAIL("Unknown LightType."); |
| 817 buffer.validate(false); |
817 return NULL; | 818 return NULL; |
818 } | 819 } |
819 } | 820 } |
820 /////////////////////////////////////////////////////////////////////////////// | 821 /////////////////////////////////////////////////////////////////////////////// |
821 | 822 |
822 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca
le, SkImageFilter* input, const CropRect* cropRect) | 823 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca
le, SkImageFilter* input, const CropRect* cropRect) |
823 : INHERITED(input, cropRect), | 824 : INHERITED(input, cropRect), |
824 fLight(light), | 825 fLight(light), |
825 fSurfaceScale(SkScalarDiv(surfaceScale, SkIntToScalar(255))) | 826 fSurfaceScale(SkScalarDiv(surfaceScale, SkIntToScalar(255))) |
826 { | 827 { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 if (!this->applyCropRect(&bounds, ctm)) { | 946 if (!this->applyCropRect(&bounds, ctm)) { |
946 return false; | 947 return false; |
947 } | 948 } |
948 | 949 |
949 if (bounds.width() < 2 || bounds.height() < 2) { | 950 if (bounds.width() < 2 || bounds.height() < 2) { |
950 return false; | 951 return false; |
951 } | 952 } |
952 | 953 |
953 dst->setConfig(src.config(), bounds.width(), bounds.height()); | 954 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
954 dst->allocPixels(); | 955 dst->allocPixels(); |
| 956 if (!dst->getPixels()) { |
| 957 return false; |
| 958 } |
955 | 959 |
956 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); | 960 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); |
957 | 961 |
958 DiffuseLightingType lightingType(fKD); | 962 DiffuseLightingType lightingType(fKD); |
959 switch (transformedLight->type()) { | 963 switch (transformedLight->type()) { |
960 case SkLight::kDistant_LightType: | 964 case SkLight::kDistant_LightType: |
961 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, trans
formedLight, src, dst, surfaceScale(), bounds); | 965 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, trans
formedLight, src, dst, surfaceScale(), bounds); |
962 break; | 966 break; |
963 case SkLight::kPoint_LightType: | 967 case SkLight::kPoint_LightType: |
964 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); | 968 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 if (!this->applyCropRect(&bounds, ctm)) { | 1037 if (!this->applyCropRect(&bounds, ctm)) { |
1034 return false; | 1038 return false; |
1035 } | 1039 } |
1036 | 1040 |
1037 if (bounds.width() < 2 || bounds.height() < 2) { | 1041 if (bounds.width() < 2 || bounds.height() < 2) { |
1038 return false; | 1042 return false; |
1039 } | 1043 } |
1040 | 1044 |
1041 dst->setConfig(src.config(), bounds.width(), bounds.height()); | 1045 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
1042 dst->allocPixels(); | 1046 dst->allocPixels(); |
| 1047 if (!dst->getPixels()) { |
| 1048 return false; |
| 1049 } |
1043 | 1050 |
1044 SpecularLightingType lightingType(fKS, fShininess); | 1051 SpecularLightingType lightingType(fKS, fShininess); |
1045 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); | 1052 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); |
1046 switch (transformedLight->type()) { | 1053 switch (transformedLight->type()) { |
1047 case SkLight::kDistant_LightType: | 1054 case SkLight::kDistant_LightType: |
1048 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, tran
sformedLight, src, dst, surfaceScale(), bounds); | 1055 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, tran
sformedLight, src, dst, surfaceScale(), bounds); |
1049 break; | 1056 break; |
1050 case SkLight::kPoint_LightType: | 1057 case SkLight::kPoint_LightType: |
1051 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); | 1058 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); |
1052 break; | 1059 break; |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1597 | 1604 |
1598 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1605 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1599 } | 1606 } |
1600 | 1607 |
1601 #endif | 1608 #endif |
1602 | 1609 |
1603 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1610 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1604 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1611 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1605 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1612 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1606 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1613 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |