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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 | 273 |
274 void writePoint3(const SkPoint3& point, SkWriteBuffer& buffer) { | 274 void writePoint3(const SkPoint3& point, SkWriteBuffer& buffer) { |
275 buffer.writeScalar(point.fX); | 275 buffer.writeScalar(point.fX); |
276 buffer.writeScalar(point.fY); | 276 buffer.writeScalar(point.fY); |
277 buffer.writeScalar(point.fZ); | 277 buffer.writeScalar(point.fZ); |
278 }; | 278 }; |
279 | 279 |
280 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { | 280 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { |
281 public: | 281 public: |
282 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar kd, SkImageFilter*, | 282 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar kd, SkImageFilter*, |
283 const CropRect*, uint32_t uniqueID = 0); | 283 const CropRect*); |
284 | 284 |
285 SK_TO_STRING_OVERRIDE() | 285 SK_TO_STRING_OVERRIDE() |
286 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter) | 286 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter) |
287 SkScalar kd() const { return fKD; } | 287 SkScalar kd() const { return fKD; } |
288 | 288 |
289 protected: | 289 protected: |
290 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, | 290 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, |
291 SkScalar kd, SkImageFilter* input, const CropRe ct* cropRect, | 291 SkScalar kd, SkImageFilter* input, const CropRe ct* cropRect); |
292 uint32_t uniqueID); | |
293 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 292 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
294 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 293 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
295 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE; | 294 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE; |
296 #if SK_SUPPORT_GPU | 295 #if SK_SUPPORT_GPU |
297 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk Matrix&, | 296 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk Matrix&, |
298 const SkIRect& bounds) const SK_OVERRIDE; | 297 const SkIRect& bounds) const SK_OVERRIDE; |
299 #endif | 298 #endif |
300 | 299 |
301 private: | 300 private: |
302 friend class SkLightingImageFilter; | 301 friend class SkLightingImageFilter; |
303 typedef SkLightingImageFilter INHERITED; | 302 typedef SkLightingImageFilter INHERITED; |
304 SkScalar fKD; | 303 SkScalar fKD; |
305 }; | 304 }; |
306 | 305 |
307 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 306 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
308 public: | 307 public: |
309 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, | 308 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, |
310 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*, | 309 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*); |
311 uint32_t uniqueID = 0); | |
312 | 310 |
313 SK_TO_STRING_OVERRIDE() | 311 SK_TO_STRING_OVERRIDE() |
314 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter) | 312 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter) |
315 | 313 |
316 SkScalar ks() const { return fKS; } | 314 SkScalar ks() const { return fKS; } |
317 SkScalar shininess() const { return fShininess; } | 315 SkScalar shininess() const { return fShininess; } |
318 | 316 |
319 protected: | 317 protected: |
320 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala r ks, | 318 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala r ks, |
321 SkScalar shininess, SkImageFilter* input, cons t CropRect*, | 319 SkScalar shininess, SkImageFilter* input, cons t CropRect*); |
322 uint32_t uniqueID); | |
323 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 320 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
324 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 321 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
325 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE; | 322 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE; |
326 #if SK_SUPPORT_GPU | 323 #if SK_SUPPORT_GPU |
327 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk Matrix&, | 324 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk Matrix&, |
328 const SkIRect& bounds) const SK_OVERRIDE; | 325 const SkIRect& bounds) const SK_OVERRIDE; |
329 #endif | 326 #endif |
330 | 327 |
331 private: | 328 private: |
332 SkScalar fKS; | 329 SkScalar fKS; |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
853 case SkLight::kSpot_LightType: return SkNEW_ARGS(SkSpotLight, (buffer )); | 850 case SkLight::kSpot_LightType: return SkNEW_ARGS(SkSpotLight, (buffer )); |
854 default: | 851 default: |
855 SkDEBUGFAIL("Unknown LightType."); | 852 SkDEBUGFAIL("Unknown LightType."); |
856 buffer.validate(false); | 853 buffer.validate(false); |
857 return NULL; | 854 return NULL; |
858 } | 855 } |
859 } | 856 } |
860 /////////////////////////////////////////////////////////////////////////////// | 857 /////////////////////////////////////////////////////////////////////////////// |
861 | 858 |
862 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca le, | 859 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca le, |
863 SkImageFilter* input, const CropRec t* cropRect, | 860 SkImageFilter* input, const CropRec t* cropRect) |
864 uint32_t uniqueID) | 861 : INHERITED(1, &input, cropRect) |
865 : INHERITED(1, &input, cropRect, uniqueID) | |
866 , fLight(SkRef(light)) | 862 , fLight(SkRef(light)) |
867 , fSurfaceScale(surfaceScale / 255) | 863 , fSurfaceScale(surfaceScale / 255) |
868 {} | 864 {} |
869 | 865 |
870 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse(const SkPoint3& di rection, | 866 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse(const SkPoint3& di rection, |
871 SkColor lightColor , | 867 SkColor lightColor , |
872 SkScalar surfaceSc ale, | 868 SkScalar surfaceSc ale, |
873 SkScalar kd, | 869 SkScalar kd, |
874 SkImageFilter* inp ut, | 870 SkImageFilter* inp ut, |
875 const CropRect* cr opRect) { | 871 const CropRect* cr opRect) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
942 | 938 |
943 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 939 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
944 this->INHERITED::flatten(buffer); | 940 this->INHERITED::flatten(buffer); |
945 fLight->flattenLight(buffer); | 941 fLight->flattenLight(buffer); |
946 buffer.writeScalar(fSurfaceScale * 255); | 942 buffer.writeScalar(fSurfaceScale * 255); |
947 } | 943 } |
948 | 944 |
949 /////////////////////////////////////////////////////////////////////////////// | 945 /////////////////////////////////////////////////////////////////////////////// |
950 | 946 |
951 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkLight* light, SkScalar sur faceScale, | 947 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkLight* light, SkScalar sur faceScale, |
952 SkScalar kd, SkImageFilter* input, const Cro pRect* cropRect, uint32_t uniqueID) { | 948 SkScalar kd, SkImageFilter* input, const Cro pRect* cropRect) { |
953 if (NULL == light) { | 949 if (NULL == light) { |
954 return NULL; | 950 return NULL; |
955 } | 951 } |
956 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { | 952 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { |
957 return NULL; | 953 return NULL; |
958 } | 954 } |
959 // According to the spec, kd can be any non-negative number : | 955 // According to the spec, kd can be any non-negative number : |
960 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement | 956 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement |
961 if (kd < 0) { | 957 if (kd < 0) { |
962 return NULL; | 958 return NULL; |
963 } | 959 } |
964 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in put, cropRect, uniqueID)); | 960 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in put, cropRect)); |
965 } | 961 } |
966 | 962 |
967 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca lar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect, u int32_t uniqueID) | 963 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca lar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect = NULL) |
robertphillips
2015/03/18 16:51:43
Why add this "= NULL" here ?
Stephen White
2015/03/18 16:55:29
Bad revert. Fixed.
| |
968 : SkLightingImageFilter(light, surfaceScale, input, cropRect, uniqueID), | 964 : SkLightingImageFilter(light, surfaceScale, input, cropRect), |
969 fKD(kd) | 965 fKD(kd) |
970 { | 966 { |
971 } | 967 } |
972 | 968 |
973 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) { | 969 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) { |
974 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 970 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
975 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); | 971 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); |
976 SkScalar surfaceScale = buffer.readScalar(); | 972 SkScalar surfaceScale = buffer.readScalar(); |
977 SkScalar kd = buffer.readScalar(); | 973 SkScalar kd = buffer.readScalar(); |
978 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect( ), common.uniqueID()); | 974 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect( )); |
979 } | 975 } |
980 | 976 |
981 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 977 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
982 this->INHERITED::flatten(buffer); | 978 this->INHERITED::flatten(buffer); |
983 buffer.writeScalar(fKD); | 979 buffer.writeScalar(fKD); |
984 } | 980 } |
985 | 981 |
986 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, | 982 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, |
987 const SkBitmap& source, | 983 const SkBitmap& source, |
988 const Context& ctx, | 984 const Context& ctx, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1054 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 1050 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
1055 *fp = GrDiffuseLightingEffect::Create(texture, light(), scale, matrix, k d()); | 1051 *fp = GrDiffuseLightingEffect::Create(texture, light(), scale, matrix, k d()); |
1056 } | 1052 } |
1057 return true; | 1053 return true; |
1058 } | 1054 } |
1059 #endif | 1055 #endif |
1060 | 1056 |
1061 /////////////////////////////////////////////////////////////////////////////// | 1057 /////////////////////////////////////////////////////////////////////////////// |
1062 | 1058 |
1063 SkImageFilter* SkSpecularLightingImageFilter::Create(SkLight* light, SkScalar su rfaceScale, | 1059 SkImageFilter* SkSpecularLightingImageFilter::Create(SkLight* light, SkScalar su rfaceScale, |
1064 SkScalar ks, SkScalar shininess, SkImageFilter* input, const Cro pRect* cropRect, uint32_t uniqueID) { | 1060 SkScalar ks, SkScalar shininess, SkImageFilter* input, const Cro pRect* cropRect) { |
1065 if (NULL == light) { | 1061 if (NULL == light) { |
1066 return NULL; | 1062 return NULL; |
1067 } | 1063 } |
1068 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF inite(shininess)) { | 1064 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF inite(shininess)) { |
1069 return NULL; | 1065 return NULL; |
1070 } | 1066 } |
1071 // According to the spec, ks can be any non-negative number : | 1067 // According to the spec, ks can be any non-negative number : |
1072 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement | 1068 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement |
1073 if (ks < 0) { | 1069 if (ks < 0) { |
1074 return NULL; | 1070 return NULL; |
1075 } | 1071 } |
1076 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 1072 return SkNEW_ARGS(SkSpecularLightingImageFilter, |
1077 (light, surfaceScale, ks, shininess, input, cropRect, uniq ueID)); | 1073 (light, surfaceScale, ks, shininess, input, cropRect)); |
1078 } | 1074 } |
1079 | 1075 |
1080 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) | 1076 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect) |
1081 : SkLightingImageFilter(light, surfaceScale, input, cropRect, uniqueID), | 1077 : SkLightingImageFilter(light, surfaceScale, input, cropRect), |
1082 fKS(ks), | 1078 fKS(ks), |
1083 fShininess(shininess) | 1079 fShininess(shininess) |
1084 { | 1080 { |
1085 } | 1081 } |
1086 | 1082 |
1087 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) { | 1083 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) { |
1088 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 1084 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
1089 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); | 1085 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); |
1090 SkScalar surfaceScale = buffer.readScalar(); | 1086 SkScalar surfaceScale = buffer.readScalar(); |
1091 SkScalar ks = buffer.readScalar(); | 1087 SkScalar ks = buffer.readScalar(); |
1092 SkScalar shine = buffer.readScalar(); | 1088 SkScalar shine = buffer.readScalar(); |
1093 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr opRect(), common.uniqueID()); | 1089 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr opRect()); |
1094 } | 1090 } |
1095 | 1091 |
1096 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1092 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1097 this->INHERITED::flatten(buffer); | 1093 this->INHERITED::flatten(buffer); |
1098 buffer.writeScalar(fKS); | 1094 buffer.writeScalar(fKS); |
1099 buffer.writeScalar(fShininess); | 1095 buffer.writeScalar(fShininess); |
1100 } | 1096 } |
1101 | 1097 |
1102 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, | 1098 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, |
1103 const SkBitmap& source, | 1099 const SkBitmap& source, |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1716 | 1712 |
1717 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1713 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1718 } | 1714 } |
1719 | 1715 |
1720 #endif | 1716 #endif |
1721 | 1717 |
1722 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1718 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1723 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1719 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1724 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1720 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1725 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1721 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |