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 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 return fDirection; | 747 return fDirection; |
748 }; | 748 }; |
749 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } | 749 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } |
750 LightType type() const override { return kDistant_LightType; } | 750 LightType type() const override { return kDistant_LightType; } |
751 const SkPoint3& direction() const { return fDirection; } | 751 const SkPoint3& direction() const { return fDirection; } |
752 GrGLLight* createGLLight() const override { | 752 GrGLLight* createGLLight() const override { |
753 #if SK_SUPPORT_GPU | 753 #if SK_SUPPORT_GPU |
754 return new GrGLDistantLight; | 754 return new GrGLDistantLight; |
755 #else | 755 #else |
756 SkDEBUGFAIL("Should not call in GPU-less build"); | 756 SkDEBUGFAIL("Should not call in GPU-less build"); |
757 return NULL; | 757 return nullptr; |
758 #endif | 758 #endif |
759 } | 759 } |
760 bool requiresFragmentPosition() const override { return false; } | 760 bool requiresFragmentPosition() const override { return false; } |
761 | 761 |
762 bool isEqual(const SkImageFilterLight& other) const override { | 762 bool isEqual(const SkImageFilterLight& other) const override { |
763 if (other.type() != kDistant_LightType) { | 763 if (other.type() != kDistant_LightType) { |
764 return false; | 764 return false; |
765 } | 765 } |
766 | 766 |
767 const SkDistantLight& o = static_cast<const SkDistantLight&>(other); | 767 const SkDistantLight& o = static_cast<const SkDistantLight&>(other); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 return direction; | 806 return direction; |
807 }; | 807 }; |
808 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } | 808 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } |
809 LightType type() const override { return kPoint_LightType; } | 809 LightType type() const override { return kPoint_LightType; } |
810 const SkPoint3& location() const { return fLocation; } | 810 const SkPoint3& location() const { return fLocation; } |
811 GrGLLight* createGLLight() const override { | 811 GrGLLight* createGLLight() const override { |
812 #if SK_SUPPORT_GPU | 812 #if SK_SUPPORT_GPU |
813 return new GrGLPointLight; | 813 return new GrGLPointLight; |
814 #else | 814 #else |
815 SkDEBUGFAIL("Should not call in GPU-less build"); | 815 SkDEBUGFAIL("Should not call in GPU-less build"); |
816 return NULL; | 816 return nullptr; |
817 #endif | 817 #endif |
818 } | 818 } |
819 bool requiresFragmentPosition() const override { return true; } | 819 bool requiresFragmentPosition() const override { return true; } |
820 bool isEqual(const SkImageFilterLight& other) const override { | 820 bool isEqual(const SkImageFilterLight& other) const override { |
821 if (other.type() != kPoint_LightType) { | 821 if (other.type() != kPoint_LightType) { |
822 return false; | 822 return false; |
823 } | 823 } |
824 const SkPointLight& o = static_cast<const SkPointLight&>(other); | 824 const SkPointLight& o = static_cast<const SkPointLight&>(other); |
825 return INHERITED::isEqual(other) && | 825 return INHERITED::isEqual(other) && |
826 fLocation == o.fLocation; | 826 fLocation == o.fLocation; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 scale *= fConeScale; | 920 scale *= fConeScale; |
921 } | 921 } |
922 } | 922 } |
923 return this->color().makeScale(scale); | 923 return this->color().makeScale(scale); |
924 } | 924 } |
925 GrGLLight* createGLLight() const override { | 925 GrGLLight* createGLLight() const override { |
926 #if SK_SUPPORT_GPU | 926 #if SK_SUPPORT_GPU |
927 return new GrGLSpotLight; | 927 return new GrGLSpotLight; |
928 #else | 928 #else |
929 SkDEBUGFAIL("Should not call in GPU-less build"); | 929 SkDEBUGFAIL("Should not call in GPU-less build"); |
930 return NULL; | 930 return nullptr; |
931 #endif | 931 #endif |
932 } | 932 } |
933 bool requiresFragmentPosition() const override { return true; } | 933 bool requiresFragmentPosition() const override { return true; } |
934 LightType type() const override { return kSpot_LightType; } | 934 LightType type() const override { return kSpot_LightType; } |
935 const SkPoint3& location() const { return fLocation; } | 935 const SkPoint3& location() const { return fLocation; } |
936 const SkPoint3& target() const { return fTarget; } | 936 const SkPoint3& target() const { return fTarget; } |
937 SkScalar specularExponent() const { return fSpecularExponent; } | 937 SkScalar specularExponent() const { return fSpecularExponent; } |
938 SkScalar cosInnerConeAngle() const { return fCosInnerConeAngle; } | 938 SkScalar cosInnerConeAngle() const { return fCosInnerConeAngle; } |
939 SkScalar cosOuterConeAngle() const { return fCosOuterConeAngle; } | 939 SkScalar cosOuterConeAngle() const { return fCosOuterConeAngle; } |
940 SkScalar coneScale() const { return fConeScale; } | 940 SkScalar coneScale() const { return fConeScale; } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 // then subclass, same order as flattenLight. | 1032 // then subclass, same order as flattenLight. |
1033 case SkImageFilterLight::kDistant_LightType: | 1033 case SkImageFilterLight::kDistant_LightType: |
1034 return new SkDistantLight(buffer); | 1034 return new SkDistantLight(buffer); |
1035 case SkImageFilterLight::kPoint_LightType: | 1035 case SkImageFilterLight::kPoint_LightType: |
1036 return new SkPointLight(buffer); | 1036 return new SkPointLight(buffer); |
1037 case SkImageFilterLight::kSpot_LightType: | 1037 case SkImageFilterLight::kSpot_LightType: |
1038 return new SkSpotLight(buffer); | 1038 return new SkSpotLight(buffer); |
1039 default: | 1039 default: |
1040 SkDEBUGFAIL("Unknown LightType."); | 1040 SkDEBUGFAIL("Unknown LightType."); |
1041 buffer.validate(false); | 1041 buffer.validate(false); |
1042 return NULL; | 1042 return nullptr; |
1043 } | 1043 } |
1044 } | 1044 } |
1045 /////////////////////////////////////////////////////////////////////////////// | 1045 /////////////////////////////////////////////////////////////////////////////// |
1046 | 1046 |
1047 SkLightingImageFilter::SkLightingImageFilter(SkImageFilterLight* light, SkScalar
surfaceScale, | 1047 SkLightingImageFilter::SkLightingImageFilter(SkImageFilterLight* light, SkScalar
surfaceScale, |
1048 SkImageFilter* input, const CropRec
t* cropRect) | 1048 SkImageFilter* input, const CropRec
t* cropRect) |
1049 : INHERITED(1, &input, cropRect) | 1049 : INHERITED(1, &input, cropRect) |
1050 , fLight(SkRef(light)) | 1050 , fLight(SkRef(light)) |
1051 , fSurfaceScale(surfaceScale / 255) | 1051 , fSurfaceScale(surfaceScale / 255) |
1052 {} | 1052 {} |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 buffer.writeScalar(fSurfaceScale * 255); | 1130 buffer.writeScalar(fSurfaceScale * 255); |
1131 } | 1131 } |
1132 | 1132 |
1133 /////////////////////////////////////////////////////////////////////////////// | 1133 /////////////////////////////////////////////////////////////////////////////// |
1134 | 1134 |
1135 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkImageFilterLight* light, | 1135 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkImageFilterLight* light, |
1136 SkScalar surfaceScale, | 1136 SkScalar surfaceScale, |
1137 SkScalar kd, | 1137 SkScalar kd, |
1138 SkImageFilter* input, | 1138 SkImageFilter* input, |
1139 const CropRect* cropRect) { | 1139 const CropRect* cropRect) { |
1140 if (NULL == light) { | 1140 if (nullptr == light) { |
1141 return NULL; | 1141 return nullptr; |
1142 } | 1142 } |
1143 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { | 1143 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { |
1144 return NULL; | 1144 return nullptr; |
1145 } | 1145 } |
1146 // According to the spec, kd can be any non-negative number : | 1146 // According to the spec, kd can be any non-negative number : |
1147 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement | 1147 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement |
1148 if (kd < 0) { | 1148 if (kd < 0) { |
1149 return NULL; | 1149 return nullptr; |
1150 } | 1150 } |
1151 return new SkDiffuseLightingImageFilter(light, surfaceScale, kd, input, crop
Rect); | 1151 return new SkDiffuseLightingImageFilter(light, surfaceScale, kd, input, crop
Rect); |
1152 } | 1152 } |
1153 | 1153 |
1154 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkImageFilterLight* l
ight, | 1154 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkImageFilterLight* l
ight, |
1155 SkScalar surfaceScale
, | 1155 SkScalar surfaceScale
, |
1156 SkScalar kd, | 1156 SkScalar kd, |
1157 SkImageFilter* input, | 1157 SkImageFilter* input, |
1158 const CropRect* cropR
ect) | 1158 const CropRect* cropR
ect) |
1159 : INHERITED(light, surfaceScale, input, cropRect), | 1159 : INHERITED(light, surfaceScale, input, cropRect), |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 #endif | 1268 #endif |
1269 | 1269 |
1270 /////////////////////////////////////////////////////////////////////////////// | 1270 /////////////////////////////////////////////////////////////////////////////// |
1271 | 1271 |
1272 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light, | 1272 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light, |
1273 SkScalar surfaceScale, | 1273 SkScalar surfaceScale, |
1274 SkScalar ks, | 1274 SkScalar ks, |
1275 SkScalar shininess, | 1275 SkScalar shininess, |
1276 SkImageFilter* input, | 1276 SkImageFilter* input, |
1277 const CropRect* cropRect) { | 1277 const CropRect* cropRect) { |
1278 if (NULL == light) { | 1278 if (nullptr == light) { |
1279 return NULL; | 1279 return nullptr; |
1280 } | 1280 } |
1281 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF
inite(shininess)) { | 1281 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF
inite(shininess)) { |
1282 return NULL; | 1282 return nullptr; |
1283 } | 1283 } |
1284 // According to the spec, ks can be any non-negative number : | 1284 // According to the spec, ks can be any non-negative number : |
1285 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement | 1285 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement |
1286 if (ks < 0) { | 1286 if (ks < 0) { |
1287 return NULL; | 1287 return nullptr; |
1288 } | 1288 } |
1289 return new SkSpecularLightingImageFilter(light, surfaceScale, ks, shininess,
input, cropRect); | 1289 return new SkSpecularLightingImageFilter(light, surfaceScale, ks, shininess,
input, cropRect); |
1290 } | 1290 } |
1291 | 1291 |
1292 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkImageFilterLight*
light, | 1292 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkImageFilterLight*
light, |
1293 SkScalar surfaceSca
le, | 1293 SkScalar surfaceSca
le, |
1294 SkScalar ks, | 1294 SkScalar ks, |
1295 SkScalar shininess, | 1295 SkScalar shininess, |
1296 SkImageFilter* inpu
t, | 1296 SkImageFilter* inpu
t, |
1297 const CropRect* cro
pRect) | 1297 const CropRect* cro
pRect) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1426 } | 1426 } |
1427 case 1: { | 1427 case 1: { |
1428 return new SkPointLight(random_point3(random), random->nextU()); | 1428 return new SkPointLight(random_point3(random), random->nextU()); |
1429 } | 1429 } |
1430 case 2: { | 1430 case 2: { |
1431 return new SkSpotLight(random_point3(random), random_point3(random), | 1431 return new SkSpotLight(random_point3(random), random_point3(random), |
1432 random->nextUScalar1(), random->nextUScalar1(
), random->nextU()); | 1432 random->nextUScalar1(), random->nextUScalar1(
), random->nextU()); |
1433 } | 1433 } |
1434 default: | 1434 default: |
1435 SkFAIL("Unexpected value."); | 1435 SkFAIL("Unexpected value."); |
1436 return NULL; | 1436 return nullptr; |
1437 } | 1437 } |
1438 } | 1438 } |
1439 | 1439 |
1440 SkString emitNormalFunc(BoundaryMode mode, | 1440 SkString emitNormalFunc(BoundaryMode mode, |
1441 const char* pointToNormalName, | 1441 const char* pointToNormalName, |
1442 const char* sobelFuncName) { | 1442 const char* sobelFuncName) { |
1443 SkString result; | 1443 SkString result; |
1444 switch (mode) { | 1444 switch (mode) { |
1445 case kTopLeft_BoundaryMode: | 1445 case kTopLeft_BoundaryMode: |
1446 result.printf("\treturn %s(%s(0.0, 0.0, m[4], m[5], m[7], m[8], %g),\n" | 1446 result.printf("\treturn %s(%s(0.0, 0.0, m[4], m[5], m[7], m[8], %g),\n" |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2025 | 2025 |
2026 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2026 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
2027 } | 2027 } |
2028 | 2028 |
2029 #endif | 2029 #endif |
2030 | 2030 |
2031 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2031 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
2032 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2032 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
2033 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2033 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
2034 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2034 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |