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