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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar
kd, SkImageFilter*, | 283 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar
kd, SkImageFilter*, |
284 const CropRect*, uint32_t uniqueID = 0); | 284 const CropRect*, uint32_t uniqueID = 0); |
285 | 285 |
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); | 292 uint32_t uniqueID); |
293 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | |
294 explicit SkDiffuseLightingImageFilter(SkReadBuffer& buffer); | |
295 #endif | |
296 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 293 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
297 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 294 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
298 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 295 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
299 #if SK_SUPPORT_GPU | 296 #if SK_SUPPORT_GPU |
300 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, | 297 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, |
301 const SkIRect& bounds) const SK_OVERRIDE; | 298 const SkIRect& bounds) const SK_OVERRIDE; |
302 #endif | 299 #endif |
303 | 300 |
304 private: | 301 private: |
305 friend class SkLightingImageFilter; | 302 friend class SkLightingImageFilter; |
306 typedef SkLightingImageFilter INHERITED; | 303 typedef SkLightingImageFilter INHERITED; |
307 SkScalar fKD; | 304 SkScalar fKD; |
308 }; | 305 }; |
309 | 306 |
310 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 307 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
311 public: | 308 public: |
312 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, | 309 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, |
313 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*, | 310 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*, |
314 uint32_t uniqueID = 0); | 311 uint32_t uniqueID = 0); |
315 | 312 |
316 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 313 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
317 | 314 |
318 SkScalar ks() const { return fKS; } | 315 SkScalar ks() const { return fKS; } |
319 SkScalar shininess() const { return fShininess; } | 316 SkScalar shininess() const { return fShininess; } |
320 | 317 |
321 protected: | 318 protected: |
322 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, | 319 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, |
323 SkScalar shininess, SkImageFilter* input, cons
t CropRect*, | 320 SkScalar shininess, SkImageFilter* input, cons
t CropRect*, |
324 uint32_t uniqueID); | 321 uint32_t uniqueID); |
325 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | |
326 explicit SkSpecularLightingImageFilter(SkReadBuffer& buffer); | |
327 #endif | |
328 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 322 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
329 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 323 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
330 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 324 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
331 #if SK_SUPPORT_GPU | 325 #if SK_SUPPORT_GPU |
332 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, | 326 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, |
333 const SkIRect& bounds) const SK_OVERRIDE; | 327 const SkIRect& bounds) const SK_OVERRIDE; |
334 #endif | 328 #endif |
335 | 329 |
336 private: | 330 private: |
337 SkScalar fKS; | 331 SkScalar fKS; |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 SkScalar shine, | 929 SkScalar shine, |
936 SkImageFilter* input
, | 930 SkImageFilter* input
, |
937 const CropRect* crop
Rect) { | 931 const CropRect* crop
Rect) { |
938 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkSpotLight, (location, target, specu
larExponent, | 932 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkSpotLight, (location, target, specu
larExponent, |
939 cutoffAngle, lightColor
))); | 933 cutoffAngle, lightColor
))); |
940 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); | 934 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); |
941 } | 935 } |
942 | 936 |
943 SkLightingImageFilter::~SkLightingImageFilter() {} | 937 SkLightingImageFilter::~SkLightingImageFilter() {} |
944 | 938 |
945 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | |
946 SkLightingImageFilter::SkLightingImageFilter(SkReadBuffer& buffer) | |
947 : INHERITED(1, buffer) { | |
948 fLight.reset(SkLight::UnflattenLight(buffer)); | |
949 fSurfaceScale = buffer.readScalar(); | |
950 buffer.validate(SkScalarIsFinite(fSurfaceScale)); | |
951 } | |
952 #endif | |
953 | |
954 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 939 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
955 this->INHERITED::flatten(buffer); | 940 this->INHERITED::flatten(buffer); |
956 fLight->flattenLight(buffer); | 941 fLight->flattenLight(buffer); |
957 buffer.writeScalar(fSurfaceScale * 255); | 942 buffer.writeScalar(fSurfaceScale * 255); |
958 } | 943 } |
959 | 944 |
960 /////////////////////////////////////////////////////////////////////////////// | 945 /////////////////////////////////////////////////////////////////////////////// |
961 | 946 |
962 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkLight* light, SkScalar sur
faceScale, | 947 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkLight* light, SkScalar sur
faceScale, |
963 SkScalar kd, SkImageFilter* input, const Cro
pRect* cropRect, uint32_t uniqueID) { | 948 SkScalar kd, SkImageFilter* input, const Cro
pRect* cropRect, uint32_t uniqueID) { |
(...skipping 10 matching lines...) Expand all Loading... |
974 } | 959 } |
975 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in
put, cropRect, uniqueID)); | 960 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in
put, cropRect, uniqueID)); |
976 } | 961 } |
977 | 962 |
978 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, u
int32_t uniqueID) |
979 : SkLightingImageFilter(light, surfaceScale, input, cropRect, uniqueID), | 964 : SkLightingImageFilter(light, surfaceScale, input, cropRect, uniqueID), |
980 fKD(kd) | 965 fKD(kd) |
981 { | 966 { |
982 } | 967 } |
983 | 968 |
984 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | |
985 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkReadBuffer& buffer) | |
986 : INHERITED(buffer) | |
987 { | |
988 fKD = buffer.readScalar(); | |
989 buffer.validate(SkScalarIsFinite(fKD) && (fKD >= 0)); | |
990 } | |
991 #endif | |
992 | |
993 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) { | 969 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) { |
994 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 970 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
995 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); | 971 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); |
996 SkScalar surfaceScale = buffer.readScalar(); | 972 SkScalar surfaceScale = buffer.readScalar(); |
997 SkScalar kd = buffer.readScalar(); | 973 SkScalar kd = buffer.readScalar(); |
998 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect(
), common.uniqueID()); | 974 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect(
), common.uniqueID()); |
999 } | 975 } |
1000 | 976 |
1001 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 977 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1002 this->INHERITED::flatten(buffer); | 978 this->INHERITED::flatten(buffer); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 (light, surfaceScale, ks, shininess, input, cropRect, uniq
ueID)); | 1065 (light, surfaceScale, ks, shininess, input, cropRect, uniq
ueID)); |
1090 } | 1066 } |
1091 | 1067 |
1092 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS
calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const
CropRect* cropRect, uint32_t uniqueID) | 1068 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS
calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const
CropRect* cropRect, uint32_t uniqueID) |
1093 : SkLightingImageFilter(light, surfaceScale, input, cropRect, uniqueID), | 1069 : SkLightingImageFilter(light, surfaceScale, input, cropRect, uniqueID), |
1094 fKS(ks), | 1070 fKS(ks), |
1095 fShininess(shininess) | 1071 fShininess(shininess) |
1096 { | 1072 { |
1097 } | 1073 } |
1098 | 1074 |
1099 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | |
1100 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkReadBuffer& buffe
r) | |
1101 : INHERITED(buffer) | |
1102 { | |
1103 fKS = buffer.readScalar(); | |
1104 fShininess = buffer.readScalar(); | |
1105 buffer.validate(SkScalarIsFinite(fKS) && (fKS >= 0) && | |
1106 SkScalarIsFinite(fShininess)); | |
1107 } | |
1108 #endif | |
1109 | |
1110 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) { | 1075 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) { |
1111 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 1076 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
1112 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); | 1077 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); |
1113 SkScalar surfaceScale = buffer.readScalar(); | 1078 SkScalar surfaceScale = buffer.readScalar(); |
1114 SkScalar ks = buffer.readScalar(); | 1079 SkScalar ks = buffer.readScalar(); |
1115 SkScalar shine = buffer.readScalar(); | 1080 SkScalar shine = buffer.readScalar(); |
1116 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr
opRect(), common.uniqueID()); | 1081 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr
opRect(), common.uniqueID()); |
1117 } | 1082 } |
1118 | 1083 |
1119 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1084 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1716 | 1681 |
1717 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1682 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1718 } | 1683 } |
1719 | 1684 |
1720 #endif | 1685 #endif |
1721 | 1686 |
1722 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1687 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1723 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1688 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1724 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1689 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1725 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1690 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |