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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 | 520 |
521 class GrDiffuseLightingEffect : public GrLightingEffect { | 521 class GrDiffuseLightingEffect : public GrLightingEffect { |
522 public: | 522 public: |
523 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, | 523 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, |
524 GrTexture* texture, | 524 GrTexture* texture, |
525 const SkImageFilterLight* light, | 525 const SkImageFilterLight* light, |
526 SkScalar surfaceScale, | 526 SkScalar surfaceScale, |
527 const SkMatrix& matrix, | 527 const SkMatrix& matrix, |
528 SkScalar kd, | 528 SkScalar kd, |
529 BoundaryMode boundaryMode) { | 529 BoundaryMode boundaryMode) { |
530 return SkNEW_ARGS(GrDiffuseLightingEffect, (procDataManager, | 530 return new GrDiffuseLightingEffect(procDataManager, texture, light, surf
aceScale, matrix, |
531 texture, | 531 kd, boundaryMode); |
532 light, | |
533 surfaceScale, | |
534 matrix, | |
535 kd, | |
536 boundaryMode)); | |
537 } | 532 } |
538 | 533 |
539 const char* name() const override { return "DiffuseLighting"; } | 534 const char* name() const override { return "DiffuseLighting"; } |
540 | 535 |
541 SkScalar kd() const { return fKD; } | 536 SkScalar kd() const { return fKD; } |
542 | 537 |
543 private: | 538 private: |
544 GrGLFragmentProcessor* onCreateGLInstance() const override; | 539 GrGLFragmentProcessor* onCreateGLInstance() const override; |
545 | 540 |
546 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 541 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
(...skipping 16 matching lines...) Expand all Loading... |
563 class GrSpecularLightingEffect : public GrLightingEffect { | 558 class GrSpecularLightingEffect : public GrLightingEffect { |
564 public: | 559 public: |
565 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, | 560 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, |
566 GrTexture* texture, | 561 GrTexture* texture, |
567 const SkImageFilterLight* light, | 562 const SkImageFilterLight* light, |
568 SkScalar surfaceScale, | 563 SkScalar surfaceScale, |
569 const SkMatrix& matrix, | 564 const SkMatrix& matrix, |
570 SkScalar ks, | 565 SkScalar ks, |
571 SkScalar shininess, | 566 SkScalar shininess, |
572 BoundaryMode boundaryMode) { | 567 BoundaryMode boundaryMode) { |
573 return SkNEW_ARGS(GrSpecularLightingEffect, (procDataManager, | 568 return new GrSpecularLightingEffect(procDataManager, texture, light, sur
faceScale, matrix, |
574 texture, | 569 ks, shininess, boundaryMode); |
575 light, | |
576 surfaceScale, | |
577 matrix, | |
578 ks, | |
579 shininess, | |
580 boundaryMode)); | |
581 } | 570 } |
582 | 571 |
583 const char* name() const override { return "SpecularLighting"; } | 572 const char* name() const override { return "SpecularLighting"; } |
584 | 573 |
585 GrGLFragmentProcessor* onCreateGLInstance() const override; | 574 GrGLFragmentProcessor* onCreateGLInstance() const override; |
586 | 575 |
587 SkScalar ks() const { return fKS; } | 576 SkScalar ks() const { return fKS; } |
588 SkScalar shininess() const { return fShininess; } | 577 SkScalar shininess() const { return fShininess; } |
589 | 578 |
590 private: | 579 private: |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 } | 744 } |
756 | 745 |
757 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 746 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
758 return fDirection; | 747 return fDirection; |
759 }; | 748 }; |
760 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } | 749 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } |
761 LightType type() const override { return kDistant_LightType; } | 750 LightType type() const override { return kDistant_LightType; } |
762 const SkPoint3& direction() const { return fDirection; } | 751 const SkPoint3& direction() const { return fDirection; } |
763 GrGLLight* createGLLight() const override { | 752 GrGLLight* createGLLight() const override { |
764 #if SK_SUPPORT_GPU | 753 #if SK_SUPPORT_GPU |
765 return SkNEW(GrGLDistantLight); | 754 return new GrGLDistantLight; |
766 #else | 755 #else |
767 SkDEBUGFAIL("Should not call in GPU-less build"); | 756 SkDEBUGFAIL("Should not call in GPU-less build"); |
768 return NULL; | 757 return NULL; |
769 #endif | 758 #endif |
770 } | 759 } |
771 bool requiresFragmentPosition() const override { return false; } | 760 bool requiresFragmentPosition() const override { return false; } |
772 | 761 |
773 bool isEqual(const SkImageFilterLight& other) const override { | 762 bool isEqual(const SkImageFilterLight& other) const override { |
774 if (other.type() != kDistant_LightType) { | 763 if (other.type() != kDistant_LightType) { |
775 return false; | 764 return false; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 fLocation.fZ - SkScalarMul(SkIntToSc
alar(z), | 803 fLocation.fZ - SkScalarMul(SkIntToSc
alar(z), |
815 surfaceSc
ale)); | 804 surfaceSc
ale)); |
816 fast_normalize(&direction); | 805 fast_normalize(&direction); |
817 return direction; | 806 return direction; |
818 }; | 807 }; |
819 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } | 808 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } |
820 LightType type() const override { return kPoint_LightType; } | 809 LightType type() const override { return kPoint_LightType; } |
821 const SkPoint3& location() const { return fLocation; } | 810 const SkPoint3& location() const { return fLocation; } |
822 GrGLLight* createGLLight() const override { | 811 GrGLLight* createGLLight() const override { |
823 #if SK_SUPPORT_GPU | 812 #if SK_SUPPORT_GPU |
824 return SkNEW(GrGLPointLight); | 813 return new GrGLPointLight; |
825 #else | 814 #else |
826 SkDEBUGFAIL("Should not call in GPU-less build"); | 815 SkDEBUGFAIL("Should not call in GPU-less build"); |
827 return NULL; | 816 return NULL; |
828 #endif | 817 #endif |
829 } | 818 } |
830 bool requiresFragmentPosition() const override { return true; } | 819 bool requiresFragmentPosition() const override { return true; } |
831 bool isEqual(const SkImageFilterLight& other) const override { | 820 bool isEqual(const SkImageFilterLight& other) const override { |
832 if (other.type() != kPoint_LightType) { | 821 if (other.type() != kPoint_LightType) { |
833 return false; | 822 return false; |
834 } | 823 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 scale = SkScalarPow(cosAngle, fSpecularExponent); | 917 scale = SkScalarPow(cosAngle, fSpecularExponent); |
929 if (cosAngle < fCosInnerConeAngle) { | 918 if (cosAngle < fCosInnerConeAngle) { |
930 scale = SkScalarMul(scale, cosAngle - fCosOuterConeAngle); | 919 scale = SkScalarMul(scale, cosAngle - fCosOuterConeAngle); |
931 scale *= fConeScale; | 920 scale *= fConeScale; |
932 } | 921 } |
933 } | 922 } |
934 return this->color().makeScale(scale); | 923 return this->color().makeScale(scale); |
935 } | 924 } |
936 GrGLLight* createGLLight() const override { | 925 GrGLLight* createGLLight() const override { |
937 #if SK_SUPPORT_GPU | 926 #if SK_SUPPORT_GPU |
938 return SkNEW(GrGLSpotLight); | 927 return new GrGLSpotLight; |
939 #else | 928 #else |
940 SkDEBUGFAIL("Should not call in GPU-less build"); | 929 SkDEBUGFAIL("Should not call in GPU-less build"); |
941 return NULL; | 930 return NULL; |
942 #endif | 931 #endif |
943 } | 932 } |
944 bool requiresFragmentPosition() const override { return true; } | 933 bool requiresFragmentPosition() const override { return true; } |
945 LightType type() const override { return kSpot_LightType; } | 934 LightType type() const override { return kSpot_LightType; } |
946 const SkPoint3& location() const { return fLocation; } | 935 const SkPoint3& location() const { return fLocation; } |
947 const SkPoint3& target() const { return fTarget; } | 936 const SkPoint3& target() const { return fTarget; } |
948 SkScalar specularExponent() const { return fSpecularExponent; } | 937 SkScalar specularExponent() const { return fSpecularExponent; } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 writePoint3(fColor, buffer); | 1023 writePoint3(fColor, buffer); |
1035 this->onFlattenLight(buffer); | 1024 this->onFlattenLight(buffer); |
1036 } | 1025 } |
1037 | 1026 |
1038 /*static*/ SkImageFilterLight* SkImageFilterLight::UnflattenLight(SkReadBuffer&
buffer) { | 1027 /*static*/ SkImageFilterLight* SkImageFilterLight::UnflattenLight(SkReadBuffer&
buffer) { |
1039 // Read type first. | 1028 // Read type first. |
1040 const SkImageFilterLight::LightType type = (SkImageFilterLight::LightType)bu
ffer.readInt(); | 1029 const SkImageFilterLight::LightType type = (SkImageFilterLight::LightType)bu
ffer.readInt(); |
1041 switch (type) { | 1030 switch (type) { |
1042 // Each of these constructors must first call SkLight's, so we'll read t
he baseclass | 1031 // Each of these constructors must first call SkLight's, so we'll read t
he baseclass |
1043 // then subclass, same order as flattenLight. | 1032 // then subclass, same order as flattenLight. |
1044 case SkImageFilterLight::kDistant_LightType: return SkNEW_ARGS(SkDistant
Light, (buffer)); | 1033 case SkImageFilterLight::kDistant_LightType: |
1045 case SkImageFilterLight::kPoint_LightType: return SkNEW_ARGS(SkPointLi
ght, (buffer)); | 1034 return new SkDistantLight(buffer); |
1046 case SkImageFilterLight::kSpot_LightType: return SkNEW_ARGS(SkSpotLig
ht, (buffer)); | 1035 case SkImageFilterLight::kPoint_LightType: |
| 1036 return new SkPointLight(buffer); |
| 1037 case SkImageFilterLight::kSpot_LightType: |
| 1038 return new SkSpotLight(buffer); |
1047 default: | 1039 default: |
1048 SkDEBUGFAIL("Unknown LightType."); | 1040 SkDEBUGFAIL("Unknown LightType."); |
1049 buffer.validate(false); | 1041 buffer.validate(false); |
1050 return NULL; | 1042 return NULL; |
1051 } | 1043 } |
1052 } | 1044 } |
1053 /////////////////////////////////////////////////////////////////////////////// | 1045 /////////////////////////////////////////////////////////////////////////////// |
1054 | 1046 |
1055 SkLightingImageFilter::SkLightingImageFilter(SkImageFilterLight* light, SkScalar
surfaceScale, | 1047 SkLightingImageFilter::SkLightingImageFilter(SkImageFilterLight* light, SkScalar
surfaceScale, |
1056 SkImageFilter* input, const CropRec
t* cropRect) | 1048 SkImageFilter* input, const CropRec
t* cropRect) |
1057 : INHERITED(1, &input, cropRect) | 1049 : INHERITED(1, &input, cropRect) |
1058 , fLight(SkRef(light)) | 1050 , fLight(SkRef(light)) |
1059 , fSurfaceScale(surfaceScale / 255) | 1051 , fSurfaceScale(surfaceScale / 255) |
1060 {} | 1052 {} |
1061 | 1053 |
1062 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse(const SkPoint3& di
rection, | 1054 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse(const SkPoint3& di
rection, |
1063 SkColor lightColor
, | 1055 SkColor lightColor
, |
1064 SkScalar surfaceSc
ale, | 1056 SkScalar surfaceSc
ale, |
1065 SkScalar kd, | 1057 SkScalar kd, |
1066 SkImageFilter* inp
ut, | 1058 SkImageFilter* inp
ut, |
1067 const CropRect* cr
opRect) { | 1059 const CropRect* cr
opRect) { |
1068 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkDistantLight, (direction
, lightColor))); | 1060 SkAutoTUnref<SkImageFilterLight> light(new SkDistantLight(direction, lightCo
lor)); |
1069 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); | 1061 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); |
1070 } | 1062 } |
1071 | 1063 |
1072 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse(const SkPoint3& loca
tion, | 1064 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse(const SkPoint3& loca
tion, |
1073 SkColor lightColor, | 1065 SkColor lightColor, |
1074 SkScalar surfaceScal
e, | 1066 SkScalar surfaceScal
e, |
1075 SkScalar kd, | 1067 SkScalar kd, |
1076 SkImageFilter* input
, | 1068 SkImageFilter* input
, |
1077 const CropRect* crop
Rect) { | 1069 const CropRect* crop
Rect) { |
1078 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkPointLight, (location, l
ightColor))); | 1070 SkAutoTUnref<SkImageFilterLight> light(new SkPointLight(location, lightColor
)); |
1079 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); | 1071 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); |
1080 } | 1072 } |
1081 | 1073 |
1082 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse(const SkPoint3& locat
ion, | 1074 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse(const SkPoint3& locat
ion, |
1083 const SkPoint3& targe
t, | 1075 const SkPoint3& targe
t, |
1084 SkScalar specularExpo
nent, | 1076 SkScalar specularExpo
nent, |
1085 SkScalar cutoffAngle, | 1077 SkScalar cutoffAngle, |
1086 SkColor lightColor, | 1078 SkColor lightColor, |
1087 SkScalar surfaceScale
, | 1079 SkScalar surfaceScale
, |
1088 SkScalar kd, | 1080 SkScalar kd, |
1089 SkImageFilter* input, | 1081 SkImageFilter* input, |
1090 const CropRect* cropR
ect) { | 1082 const CropRect* cropR
ect) { |
1091 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkSpotLight, (location, ta
rget, | 1083 SkAutoTUnref<SkImageFilterLight> light( |
1092 specularExpo
nent, | 1084 new SkSpotLight(location, target, specularExponent, cutoffAngle, lig
htColor)); |
1093 cutoffAngle,
lightColor))); | |
1094 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); | 1085 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); |
1095 } | 1086 } |
1096 | 1087 |
1097 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular(const SkPoint3& d
irection, | 1088 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular(const SkPoint3& d
irection, |
1098 SkColor lightColo
r, | 1089 SkColor lightColo
r, |
1099 SkScalar surfaceS
cale, | 1090 SkScalar surfaceS
cale, |
1100 SkScalar ks, | 1091 SkScalar ks, |
1101 SkScalar shine, | 1092 SkScalar shine, |
1102 SkImageFilter* in
put, | 1093 SkImageFilter* in
put, |
1103 const CropRect* c
ropRect) { | 1094 const CropRect* c
ropRect) { |
1104 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkDistantLight, (direction
, lightColor))); | 1095 SkAutoTUnref<SkImageFilterLight> light(new SkDistantLight(direction, lightCo
lor)); |
1105 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); | 1096 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); |
1106 } | 1097 } |
1107 | 1098 |
1108 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular(const SkPoint3& loc
ation, | 1099 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular(const SkPoint3& loc
ation, |
1109 SkColor lightColor, | 1100 SkColor lightColor, |
1110 SkScalar surfaceSca
le, | 1101 SkScalar surfaceSca
le, |
1111 SkScalar ks, | 1102 SkScalar ks, |
1112 SkScalar shine, | 1103 SkScalar shine, |
1113 SkImageFilter* inpu
t, | 1104 SkImageFilter* inpu
t, |
1114 const CropRect* cro
pRect) { | 1105 const CropRect* cro
pRect) { |
1115 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkPointLight, (location, l
ightColor))); | 1106 SkAutoTUnref<SkImageFilterLight> light(new SkPointLight(location, lightColor
)); |
1116 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); | 1107 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); |
1117 } | 1108 } |
1118 | 1109 |
1119 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular(const SkPoint3& loca
tion, | 1110 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular(const SkPoint3& loca
tion, |
1120 const SkPoint3& targ
et, | 1111 const SkPoint3& targ
et, |
1121 SkScalar specularExp
onent, | 1112 SkScalar specularExp
onent, |
1122 SkScalar cutoffAngle
, | 1113 SkScalar cutoffAngle
, |
1123 SkColor lightColor, | 1114 SkColor lightColor, |
1124 SkScalar surfaceScal
e, | 1115 SkScalar surfaceScal
e, |
1125 SkScalar ks, | 1116 SkScalar ks, |
1126 SkScalar shine, | 1117 SkScalar shine, |
1127 SkImageFilter* input
, | 1118 SkImageFilter* input
, |
1128 const CropRect* crop
Rect) { | 1119 const CropRect* crop
Rect) { |
1129 SkAutoTUnref<SkImageFilterLight> light(SkNEW_ARGS(SkSpotLight, (location, ta
rget, | 1120 SkAutoTUnref<SkImageFilterLight> light( |
1130 specularExpo
nent, | 1121 new SkSpotLight(location, target, specularExponent, cutoffAngle, lig
htColor)); |
1131 cutoffAngle,
lightColor))); | |
1132 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); | 1122 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); |
1133 } | 1123 } |
1134 | 1124 |
1135 SkLightingImageFilter::~SkLightingImageFilter() {} | 1125 SkLightingImageFilter::~SkLightingImageFilter() {} |
1136 | 1126 |
1137 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1127 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1138 this->INHERITED::flatten(buffer); | 1128 this->INHERITED::flatten(buffer); |
1139 fLight->flattenLight(buffer); | 1129 fLight->flattenLight(buffer); |
1140 buffer.writeScalar(fSurfaceScale * 255); | 1130 buffer.writeScalar(fSurfaceScale * 255); |
1141 } | 1131 } |
1142 | 1132 |
1143 /////////////////////////////////////////////////////////////////////////////// | 1133 /////////////////////////////////////////////////////////////////////////////// |
1144 | 1134 |
1145 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkImageFilterLight* light, | 1135 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkImageFilterLight* light, |
1146 SkScalar surfaceScale, | 1136 SkScalar surfaceScale, |
1147 SkScalar kd, | 1137 SkScalar kd, |
1148 SkImageFilter* input, | 1138 SkImageFilter* input, |
1149 const CropRect* cropRect) { | 1139 const CropRect* cropRect) { |
1150 if (NULL == light) { | 1140 if (NULL == light) { |
1151 return NULL; | 1141 return NULL; |
1152 } | 1142 } |
1153 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { | 1143 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { |
1154 return NULL; | 1144 return NULL; |
1155 } | 1145 } |
1156 // According to the spec, kd can be any non-negative number : | 1146 // According to the spec, kd can be any non-negative number : |
1157 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement | 1147 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement |
1158 if (kd < 0) { | 1148 if (kd < 0) { |
1159 return NULL; | 1149 return NULL; |
1160 } | 1150 } |
1161 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in
put, cropRect)); | 1151 return new SkDiffuseLightingImageFilter(light, surfaceScale, kd, input, crop
Rect); |
1162 } | 1152 } |
1163 | 1153 |
1164 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkImageFilterLight* l
ight, | 1154 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkImageFilterLight* l
ight, |
1165 SkScalar surfaceScale
, | 1155 SkScalar surfaceScale
, |
1166 SkScalar kd, | 1156 SkScalar kd, |
1167 SkImageFilter* input, | 1157 SkImageFilter* input, |
1168 const CropRect* cropR
ect) | 1158 const CropRect* cropR
ect) |
1169 : INHERITED(light, surfaceScale, input, cropRect), | 1159 : INHERITED(light, surfaceScale, input, cropRect), |
1170 fKD(kd) | 1160 fKD(kd) |
1171 { | 1161 { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 return NULL; | 1277 return NULL; |
1288 } | 1278 } |
1289 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF
inite(shininess)) { | 1279 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF
inite(shininess)) { |
1290 return NULL; | 1280 return NULL; |
1291 } | 1281 } |
1292 // According to the spec, ks can be any non-negative number : | 1282 // According to the spec, ks can be any non-negative number : |
1293 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement | 1283 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement |
1294 if (ks < 0) { | 1284 if (ks < 0) { |
1295 return NULL; | 1285 return NULL; |
1296 } | 1286 } |
1297 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 1287 return new SkSpecularLightingImageFilter(light, surfaceScale, ks, shininess,
input, cropRect); |
1298 (light, surfaceScale, ks, shininess, input, cropRect)); | |
1299 } | 1288 } |
1300 | 1289 |
1301 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkImageFilterLight*
light, | 1290 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkImageFilterLight*
light, |
1302 SkScalar surfaceSca
le, | 1291 SkScalar surfaceSca
le, |
1303 SkScalar ks, | 1292 SkScalar ks, |
1304 SkScalar shininess, | 1293 SkScalar shininess, |
1305 SkImageFilter* inpu
t, | 1294 SkImageFilter* inpu
t, |
1306 const CropRect* cro
pRect) | 1295 const CropRect* cro
pRect) |
1307 : INHERITED(light, surfaceScale, input, cropRect), | 1296 : INHERITED(light, surfaceScale, input, cropRect), |
1308 fKS(ks), | 1297 fKS(ks), |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 SkPoint3 random_point3(SkRandom* random) { | 1411 SkPoint3 random_point3(SkRandom* random) { |
1423 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()), | 1412 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()), |
1424 SkScalarToFloat(random->nextSScalar1()), | 1413 SkScalarToFloat(random->nextSScalar1()), |
1425 SkScalarToFloat(random->nextSScalar1())); | 1414 SkScalarToFloat(random->nextSScalar1())); |
1426 } | 1415 } |
1427 | 1416 |
1428 SkImageFilterLight* create_random_light(SkRandom* random) { | 1417 SkImageFilterLight* create_random_light(SkRandom* random) { |
1429 int type = random->nextULessThan(3); | 1418 int type = random->nextULessThan(3); |
1430 switch (type) { | 1419 switch (type) { |
1431 case 0: { | 1420 case 0: { |
1432 return SkNEW_ARGS(SkDistantLight, (random_point3(random), random->ne
xtU())); | 1421 return new SkDistantLight(random_point3(random), random->nextU()); |
1433 } | 1422 } |
1434 case 1: { | 1423 case 1: { |
1435 return SkNEW_ARGS(SkPointLight, (random_point3(random), random->next
U())); | 1424 return new SkPointLight(random_point3(random), random->nextU()); |
1436 } | 1425 } |
1437 case 2: { | 1426 case 2: { |
1438 return SkNEW_ARGS(SkSpotLight, (random_point3(random), | 1427 return new SkSpotLight(random_point3(random), random_point3(random), |
1439 random_point3(random), | 1428 random->nextUScalar1(), random->nextUScalar1(
), random->nextU()); |
1440 random->nextUScalar1(), | |
1441 random->nextUScalar1(), | |
1442 random->nextU())); | |
1443 } | 1429 } |
1444 default: | 1430 default: |
1445 SkFAIL("Unexpected value."); | 1431 SkFAIL("Unexpected value."); |
1446 return NULL; | 1432 return NULL; |
1447 } | 1433 } |
1448 } | 1434 } |
1449 | 1435 |
1450 SkString emitNormalFunc(BoundaryMode mode, | 1436 SkString emitNormalFunc(BoundaryMode mode, |
1451 const char* pointToNormalName, | 1437 const char* pointToNormalName, |
1452 const char* sobelFuncName) { | 1438 const char* sobelFuncName) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 return INHERITED::onIsEqual(sBase) && | 1617 return INHERITED::onIsEqual(sBase) && |
1632 this->kd() == s.kd(); | 1618 this->kd() == s.kd(); |
1633 } | 1619 } |
1634 | 1620 |
1635 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 1621 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
1636 GrProcessorKeyBuilder* b) const
{ | 1622 GrProcessorKeyBuilder* b) const
{ |
1637 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); | 1623 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); |
1638 } | 1624 } |
1639 | 1625 |
1640 GrGLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLInstance() const { | 1626 GrGLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLInstance() const { |
1641 return SkNEW_ARGS(GrGLDiffuseLightingEffect, (*this)); | 1627 return new GrGLDiffuseLightingEffect(*this); |
1642 } | 1628 } |
1643 | 1629 |
1644 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); | 1630 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); |
1645 | 1631 |
1646 GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d)
{ | 1632 GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d)
{ |
1647 SkScalar surfaceScale = d->fRandom->nextSScalar1(); | 1633 SkScalar surfaceScale = d->fRandom->nextSScalar1(); |
1648 SkScalar kd = d->fRandom->nextUScalar1(); | 1634 SkScalar kd = d->fRandom->nextUScalar1(); |
1649 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); | 1635 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); |
1650 SkMatrix matrix; | 1636 SkMatrix matrix; |
1651 for (int i = 0; i < 9; i++) { | 1637 for (int i = 0; i < 9; i++) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 this->ks() == s.ks() && | 1820 this->ks() == s.ks() && |
1835 this->shininess() == s.shininess(); | 1821 this->shininess() == s.shininess(); |
1836 } | 1822 } |
1837 | 1823 |
1838 void GrSpecularLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 1824 void GrSpecularLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
1839 GrProcessorKeyBuilder* b) const
{ | 1825 GrProcessorKeyBuilder* b) const
{ |
1840 GrGLSpecularLightingEffect::GenKey(*this, caps, b); | 1826 GrGLSpecularLightingEffect::GenKey(*this, caps, b); |
1841 } | 1827 } |
1842 | 1828 |
1843 GrGLFragmentProcessor* GrSpecularLightingEffect::onCreateGLInstance() const { | 1829 GrGLFragmentProcessor* GrSpecularLightingEffect::onCreateGLInstance() const { |
1844 return SkNEW_ARGS(GrGLSpecularLightingEffect, (*this)); | 1830 return new GrGLSpecularLightingEffect(*this); |
1845 } | 1831 } |
1846 | 1832 |
1847 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); | 1833 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); |
1848 | 1834 |
1849 GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d
) { | 1835 GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d
) { |
1850 SkScalar surfaceScale = d->fRandom->nextSScalar1(); | 1836 SkScalar surfaceScale = d->fRandom->nextSScalar1(); |
1851 SkScalar ks = d->fRandom->nextUScalar1(); | 1837 SkScalar ks = d->fRandom->nextUScalar1(); |
1852 SkScalar shininess = d->fRandom->nextUScalar1(); | 1838 SkScalar shininess = d->fRandom->nextUScalar1(); |
1853 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); | 1839 SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); |
1854 SkMatrix matrix; | 1840 SkMatrix matrix; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2035 | 2021 |
2036 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2022 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
2037 } | 2023 } |
2038 | 2024 |
2039 #endif | 2025 #endif |
2040 | 2026 |
2041 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2027 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
2042 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2028 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
2043 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2029 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
2044 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2030 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |