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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 }; | 257 }; |
258 | 258 |
259 void writePoint3(const SkPoint3& point, SkWriteBuffer& buffer) { | 259 void writePoint3(const SkPoint3& point, SkWriteBuffer& buffer) { |
260 buffer.writeScalar(point.fX); | 260 buffer.writeScalar(point.fX); |
261 buffer.writeScalar(point.fY); | 261 buffer.writeScalar(point.fY); |
262 buffer.writeScalar(point.fZ); | 262 buffer.writeScalar(point.fZ); |
263 }; | 263 }; |
264 | 264 |
265 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { | 265 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { |
266 public: | 266 public: |
267 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, | 267 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar
kd, SkImageFilter*, |
268 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); | 268 const CropRect*); |
| 269 |
269 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 270 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
270 SkScalar kd() const { return fKD; } | 271 SkScalar kd() const { return fKD; } |
271 | 272 |
272 protected: | 273 protected: |
| 274 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, |
| 275 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); |
| 276 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
273 explicit SkDiffuseLightingImageFilter(SkReadBuffer& buffer); | 277 explicit SkDiffuseLightingImageFilter(SkReadBuffer& buffer); |
| 278 #endif |
274 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 279 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
275 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 280 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
276 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 281 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
277 #if SK_SUPPORT_GPU | 282 #if SK_SUPPORT_GPU |
278 virtual bool asNewEffect(GrEffect** effect, GrTexture*, const SkMatrix& matr
ix, | 283 virtual bool asNewEffect(GrEffect** effect, GrTexture*, const SkMatrix& matr
ix, |
279 const SkIRect& bounds) const SK_OVERRIDE; | 284 const SkIRect& bounds) const SK_OVERRIDE; |
280 #endif | 285 #endif |
281 | 286 |
282 private: | 287 private: |
| 288 friend class SkLightingImageFilter; |
283 typedef SkLightingImageFilter INHERITED; | 289 typedef SkLightingImageFilter INHERITED; |
284 SkScalar fKD; | 290 SkScalar fKD; |
285 }; | 291 }; |
286 | 292 |
287 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 293 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
288 public: | 294 public: |
289 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect); | 295 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, |
| 296 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*); |
| 297 |
290 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 298 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
291 | 299 |
292 SkScalar ks() const { return fKS; } | 300 SkScalar ks() const { return fKS; } |
293 SkScalar shininess() const { return fShininess; } | 301 SkScalar shininess() const { return fShininess; } |
294 | 302 |
295 protected: | 303 protected: |
| 304 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, |
| 305 SkScalar shininess, SkImageFilter* input, cons
t CropRect*); |
| 306 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
296 explicit SkSpecularLightingImageFilter(SkReadBuffer& buffer); | 307 explicit SkSpecularLightingImageFilter(SkReadBuffer& buffer); |
| 308 #endif |
297 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 309 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
298 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 310 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
299 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 311 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
300 #if SK_SUPPORT_GPU | 312 #if SK_SUPPORT_GPU |
301 virtual bool asNewEffect(GrEffect** effect, GrTexture*, const SkMatrix& matr
ix, | 313 virtual bool asNewEffect(GrEffect** effect, GrTexture*, const SkMatrix& matr
ix, |
302 const SkIRect& bounds) const SK_OVERRIDE; | 314 const SkIRect& bounds) const SK_OVERRIDE; |
303 #endif | 315 #endif |
304 | 316 |
305 private: | 317 private: |
306 typedef SkLightingImageFilter INHERITED; | |
307 SkScalar fKS; | 318 SkScalar fKS; |
308 SkScalar fShininess; | 319 SkScalar fShininess; |
| 320 friend class SkLightingImageFilter; |
| 321 typedef SkLightingImageFilter INHERITED; |
309 }; | 322 }; |
310 | 323 |
311 #if SK_SUPPORT_GPU | 324 #if SK_SUPPORT_GPU |
312 | 325 |
313 class GrLightingEffect : public GrSingleTextureEffect { | 326 class GrLightingEffect : public GrSingleTextureEffect { |
314 public: | 327 public: |
315 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkMatrix& matrix); | 328 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkMatrix& matrix); |
316 virtual ~GrLightingEffect(); | 329 virtual ~GrLightingEffect(); |
317 | 330 |
318 const SkLight* light() const { return fLight; } | 331 const SkLight* light() const { return fLight; } |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 default: | 838 default: |
826 SkDEBUGFAIL("Unknown LightType."); | 839 SkDEBUGFAIL("Unknown LightType."); |
827 buffer.validate(false); | 840 buffer.validate(false); |
828 return NULL; | 841 return NULL; |
829 } | 842 } |
830 } | 843 } |
831 /////////////////////////////////////////////////////////////////////////////// | 844 /////////////////////////////////////////////////////////////////////////////// |
832 | 845 |
833 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca
le, | 846 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca
le, |
834 SkImageFilter* input, const CropRec
t* cropRect) | 847 SkImageFilter* input, const CropRec
t* cropRect) |
835 : INHERITED(1, &input, cropRect), | 848 : INHERITED(1, &input, cropRect) |
836 fLight(light), | 849 , fLight(SkRef(light)) |
837 fSurfaceScale(SkScalarDiv(surfaceScale, SkIntToScalar(255))) | 850 , fSurfaceScale(surfaceScale / 255) |
838 { | 851 {} |
839 SkASSERT(fLight); | 852 |
840 // our caller knows that we take ownership of the light, so we don't | 853 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse(const SkPoint3& di
rection, |
841 // need to call ref() here. | 854 SkColor lightColor
, |
| 855 SkScalar surfaceSc
ale, |
| 856 SkScalar kd, |
| 857 SkImageFilter* inp
ut, |
| 858 const CropRect* cr
opRect) { |
| 859 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkDistantLight, (direction, lightColo
r))); |
| 860 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); |
842 } | 861 } |
843 | 862 |
844 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse( | 863 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse(const SkPoint3& loca
tion, |
845 const SkPoint3& direction, SkColor lightColor, SkScalar surfaceScale, | 864 SkColor lightColor, |
846 SkScalar kd, SkImageFilter* input, const CropRect* cropRect) { | 865 SkScalar surfaceScal
e, |
847 return SkNEW_ARGS(SkDiffuseLightingImageFilter, | 866 SkScalar kd, |
848 (SkNEW_ARGS(SkDistantLight, (direction, lightColor)), surfaceScale, kd, | 867 SkImageFilter* input
, |
849 input, cropRect)); | 868 const CropRect* crop
Rect) { |
| 869 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkPointLight, (location, lightColor))
); |
| 870 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); |
850 } | 871 } |
851 | 872 |
852 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse( | 873 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse(const SkPoint3& locat
ion, |
853 const SkPoint3& location, SkColor lightColor, SkScalar surfaceScale, | 874 const SkPoint3& targe
t, |
854 SkScalar kd, SkImageFilter* input, const CropRect* cropRect) { | 875 SkScalar specularExpo
nent, |
855 return SkNEW_ARGS(SkDiffuseLightingImageFilter, | 876 SkScalar cutoffAngle, |
856 (SkNEW_ARGS(SkPointLight, (location, lightColor)), surfaceScale, kd, | 877 SkColor lightColor, |
857 input, cropRect)); | 878 SkScalar surfaceScale
, |
| 879 SkScalar kd, |
| 880 SkImageFilter* input, |
| 881 const CropRect* cropR
ect) { |
| 882 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkSpotLight, (location, target, specu
larExponent, |
| 883 cutoffAngle, lightColor
))); |
| 884 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); |
858 } | 885 } |
859 | 886 |
860 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse( | 887 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular(const SkPoint3& d
irection, |
861 const SkPoint3& location, const SkPoint3& target, | 888 SkColor lightColo
r, |
862 SkScalar specularExponent, SkScalar cutoffAngle, | 889 SkScalar surfaceS
cale, |
863 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, | 890 SkScalar ks, |
864 SkImageFilter* input, const CropRect* cropRect) { | 891 SkScalar shine, |
865 return SkNEW_ARGS(SkDiffuseLightingImageFilter, | 892 SkImageFilter* in
put, |
866 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, | 893 const CropRect* c
ropRect) { |
867 cutoffAngle, lightColor)), | 894 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkDistantLight, (direction, lightColo
r))); |
868 surfaceScale, kd, input, cropRect)); | 895 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); |
869 } | 896 } |
870 | 897 |
871 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular( | 898 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular(const SkPoint3& loc
ation, |
872 const SkPoint3& direction, SkColor lightColor, SkScalar surfaceScale, | 899 SkColor lightColor, |
873 SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropR
ect) { | 900 SkScalar surfaceSca
le, |
874 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 901 SkScalar ks, |
875 (SkNEW_ARGS(SkDistantLight, (direction, lightColor)), | 902 SkScalar shine, |
876 surfaceScale, ks, shininess, input, cropRect)); | 903 SkImageFilter* inpu
t, |
| 904 const CropRect* cro
pRect) { |
| 905 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkPointLight, (location, lightColor))
); |
| 906 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); |
877 } | 907 } |
878 | 908 |
879 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular( | 909 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular(const SkPoint3& loca
tion, |
880 const SkPoint3& location, SkColor lightColor, SkScalar surfaceScale, | 910 const SkPoint3& targ
et, |
881 SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropR
ect) { | 911 SkScalar specularExp
onent, |
882 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 912 SkScalar cutoffAngle
, |
883 (SkNEW_ARGS(SkPointLight, (location, lightColor)), | 913 SkColor lightColor, |
884 surfaceScale, ks, shininess, input, cropRect)); | 914 SkScalar surfaceScal
e, |
| 915 SkScalar ks, |
| 916 SkScalar shine, |
| 917 SkImageFilter* input
, |
| 918 const CropRect* crop
Rect) { |
| 919 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkSpotLight, (location, target, specu
larExponent, |
| 920 cutoffAngle, lightColor
))); |
| 921 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); |
885 } | 922 } |
886 | 923 |
887 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular( | 924 SkLightingImageFilter::~SkLightingImageFilter() {} |
888 const SkPoint3& location, const SkPoint3& target, | |
889 SkScalar specularExponent, SkScalar cutoffAngle, | |
890 SkColor lightColor, SkScalar surfaceScale, | |
891 SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropR
ect) { | |
892 return SkNEW_ARGS(SkSpecularLightingImageFilter, | |
893 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, cutoffAngl
e, lightColor)), | |
894 surfaceScale, ks, shininess, input, cropRect)); | |
895 } | |
896 | 925 |
897 SkLightingImageFilter::~SkLightingImageFilter() { | 926 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
898 SkSafeUnref(fLight); | |
899 } | |
900 | |
901 SkLightingImageFilter::SkLightingImageFilter(SkReadBuffer& buffer) | 927 SkLightingImageFilter::SkLightingImageFilter(SkReadBuffer& buffer) |
902 : INHERITED(1, buffer) { | 928 : INHERITED(1, buffer) { |
903 fLight = SkLight::UnflattenLight(buffer); | 929 fLight.reset(SkLight::UnflattenLight(buffer)); |
904 fSurfaceScale = buffer.readScalar(); | 930 fSurfaceScale = buffer.readScalar(); |
905 buffer.validate(SkScalarIsFinite(fSurfaceScale)); | 931 buffer.validate(SkScalarIsFinite(fSurfaceScale)); |
906 } | 932 } |
| 933 #endif |
907 | 934 |
908 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 935 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
909 this->INHERITED::flatten(buffer); | 936 this->INHERITED::flatten(buffer); |
910 fLight->flattenLight(buffer); | 937 fLight->flattenLight(buffer); |
911 buffer.writeScalar(fSurfaceScale); | 938 buffer.writeScalar(fSurfaceScale * 255); |
912 } | 939 } |
913 | 940 |
914 /////////////////////////////////////////////////////////////////////////////// | 941 /////////////////////////////////////////////////////////////////////////////// |
915 | 942 |
| 943 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkLight* light, SkScalar sur
faceScale, |
| 944 SkScalar kd, SkImageFilter* input, const Cro
pRect* cropRect) { |
| 945 if (NULL == light) { |
| 946 return NULL; |
| 947 } |
| 948 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { |
| 949 return NULL; |
| 950 } |
| 951 // According to the spec, kd can be any non-negative number : |
| 952 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement |
| 953 if (kd < 0) { |
| 954 return NULL; |
| 955 } |
| 956 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in
put, cropRect)); |
| 957 } |
| 958 |
916 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca
lar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect =
NULL) | 959 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca
lar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect =
NULL) |
917 : SkLightingImageFilter(light, surfaceScale, input, cropRect), | 960 : SkLightingImageFilter(light, surfaceScale, input, cropRect), |
918 // According to the spec, kd can be any non-negative number : | 961 fKD(kd) |
919 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement | |
920 fKD(kd < 0 ? 0 : kd) | |
921 { | 962 { |
922 } | 963 } |
923 | 964 |
| 965 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
924 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkReadBuffer& buffer) | 966 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkReadBuffer& buffer) |
925 : INHERITED(buffer) | 967 : INHERITED(buffer) |
926 { | 968 { |
927 fKD = buffer.readScalar(); | 969 fKD = buffer.readScalar(); |
928 buffer.validate(SkScalarIsFinite(fKD) && (fKD >= 0)); | 970 buffer.validate(SkScalarIsFinite(fKD) && (fKD >= 0)); |
929 } | 971 } |
| 972 #endif |
| 973 |
| 974 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 975 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 976 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); |
| 977 SkScalar surfaceScale = buffer.readScalar(); |
| 978 SkScalar kd = buffer.readScalar(); |
| 979 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect(
)); |
| 980 } |
930 | 981 |
931 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 982 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
932 this->INHERITED::flatten(buffer); | 983 this->INHERITED::flatten(buffer); |
933 buffer.writeScalar(fKD); | 984 buffer.writeScalar(fKD); |
934 } | 985 } |
935 | 986 |
936 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, | 987 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, |
937 const SkBitmap& source, | 988 const SkBitmap& source, |
938 const Context& ctx, | 989 const Context& ctx, |
939 SkBitmap* dst, | 990 SkBitmap* dst, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 if (effect) { | 1044 if (effect) { |
994 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 1045 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
995 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri
x, kd()); | 1046 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri
x, kd()); |
996 } | 1047 } |
997 return true; | 1048 return true; |
998 } | 1049 } |
999 #endif | 1050 #endif |
1000 | 1051 |
1001 /////////////////////////////////////////////////////////////////////////////// | 1052 /////////////////////////////////////////////////////////////////////////////// |
1002 | 1053 |
| 1054 SkImageFilter* SkSpecularLightingImageFilter::Create(SkLight* light, SkScalar su
rfaceScale, |
| 1055 SkScalar ks, SkScalar shininess, SkImageFilter* input, const Cro
pRect* cropRect) { |
| 1056 if (NULL == light) { |
| 1057 return NULL; |
| 1058 } |
| 1059 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF
inite(shininess)) { |
| 1060 return NULL; |
| 1061 } |
| 1062 // According to the spec, ks can be any non-negative number : |
| 1063 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement |
| 1064 if (ks < 0) { |
| 1065 return NULL; |
| 1066 } |
| 1067 return SkNEW_ARGS(SkSpecularLightingImageFilter, |
| 1068 (light, surfaceScale, ks, shininess, input, cropRect)); |
| 1069 } |
| 1070 |
1003 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS
calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const
CropRect* cropRect) | 1071 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS
calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const
CropRect* cropRect) |
1004 : SkLightingImageFilter(light, surfaceScale, input, cropRect), | 1072 : SkLightingImageFilter(light, surfaceScale, input, cropRect), |
1005 // According to the spec, ks can be any non-negative number : | 1073 fKS(ks), |
1006 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement | |
1007 fKS(ks < 0 ? 0 : ks), | |
1008 fShininess(shininess) | 1074 fShininess(shininess) |
1009 { | 1075 { |
1010 } | 1076 } |
1011 | 1077 |
| 1078 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
1012 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkReadBuffer& buffe
r) | 1079 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkReadBuffer& buffe
r) |
1013 : INHERITED(buffer) | 1080 : INHERITED(buffer) |
1014 { | 1081 { |
1015 fKS = buffer.readScalar(); | 1082 fKS = buffer.readScalar(); |
1016 fShininess = buffer.readScalar(); | 1083 fShininess = buffer.readScalar(); |
1017 buffer.validate(SkScalarIsFinite(fKS) && (fKS >= 0) && | 1084 buffer.validate(SkScalarIsFinite(fKS) && (fKS >= 0) && |
1018 SkScalarIsFinite(fShininess)); | 1085 SkScalarIsFinite(fShininess)); |
1019 } | 1086 } |
| 1087 #endif |
| 1088 |
| 1089 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 1090 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 1091 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); |
| 1092 SkScalar surfaceScale = buffer.readScalar(); |
| 1093 SkScalar ks = buffer.readScalar(); |
| 1094 SkScalar shine = buffer.readScalar(); |
| 1095 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr
opRect()); |
| 1096 } |
1020 | 1097 |
1021 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1098 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1022 this->INHERITED::flatten(buffer); | 1099 this->INHERITED::flatten(buffer); |
1023 buffer.writeScalar(fKS); | 1100 buffer.writeScalar(fKS); |
1024 buffer.writeScalar(fShininess); | 1101 buffer.writeScalar(fShininess); |
1025 } | 1102 } |
1026 | 1103 |
1027 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, | 1104 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, |
1028 const SkBitmap& source, | 1105 const SkBitmap& source, |
1029 const Context& ctx, | 1106 const Context& ctx, |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 | 1693 |
1617 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1694 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1618 } | 1695 } |
1619 | 1696 |
1620 #endif | 1697 #endif |
1621 | 1698 |
1622 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1699 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1623 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1700 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1624 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1701 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1625 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1702 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |