Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: src/effects/SkLightingImageFilter.cpp

Issue 768183002: Revert of Remove SK_SUPPORT_LEGACY_DEEPFLATTENING. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkLerpXfermode.cpp ('k') | src/effects/SkLumaColorFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
293 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; 296 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
294 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 297 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
295 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE; 298 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE;
296 #if SK_SUPPORT_GPU 299 #if SK_SUPPORT_GPU
297 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk Matrix&, 300 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk Matrix&,
298 const SkIRect& bounds) const SK_OVERRIDE; 301 const SkIRect& bounds) const SK_OVERRIDE;
299 #endif 302 #endif
300 303
301 private: 304 private:
302 friend class SkLightingImageFilter; 305 friend class SkLightingImageFilter;
303 typedef SkLightingImageFilter INHERITED; 306 typedef SkLightingImageFilter INHERITED;
304 SkScalar fKD; 307 SkScalar fKD;
305 }; 308 };
306 309
307 class SkSpecularLightingImageFilter : public SkLightingImageFilter { 310 class SkSpecularLightingImageFilter : public SkLightingImageFilter {
308 public: 311 public:
309 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, 312 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale,
310 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*, 313 SkScalar ks, SkScalar shininess, SkImageFilter* , const CropRect*,
311 uint32_t uniqueID = 0); 314 uint32_t uniqueID = 0);
312 315
313 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter) 316 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter)
314 317
315 SkScalar ks() const { return fKS; } 318 SkScalar ks() const { return fKS; }
316 SkScalar shininess() const { return fShininess; } 319 SkScalar shininess() const { return fShininess; }
317 320
318 protected: 321 protected:
319 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala r ks, 322 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala r ks,
320 SkScalar shininess, SkImageFilter* input, cons t CropRect*, 323 SkScalar shininess, SkImageFilter* input, cons t CropRect*,
321 uint32_t uniqueID); 324 uint32_t uniqueID);
325 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
326 explicit SkSpecularLightingImageFilter(SkReadBuffer& buffer);
327 #endif
322 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; 328 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
323 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 329 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
324 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE; 330 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE;
325 #if SK_SUPPORT_GPU 331 #if SK_SUPPORT_GPU
326 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk Matrix&, 332 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk Matrix&,
327 const SkIRect& bounds) const SK_OVERRIDE; 333 const SkIRect& bounds) const SK_OVERRIDE;
328 #endif 334 #endif
329 335
330 private: 336 private:
331 SkScalar fKS; 337 SkScalar fKS;
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 SkScalar shine, 935 SkScalar shine,
930 SkImageFilter* input , 936 SkImageFilter* input ,
931 const CropRect* crop Rect) { 937 const CropRect* crop Rect) {
932 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkSpotLight, (location, target, specu larExponent, 938 SkAutoTUnref<SkLight> light(SkNEW_ARGS(SkSpotLight, (location, target, specu larExponent,
933 cutoffAngle, lightColor ))); 939 cutoffAngle, lightColor )));
934 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect); 940 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect);
935 } 941 }
936 942
937 SkLightingImageFilter::~SkLightingImageFilter() {} 943 SkLightingImageFilter::~SkLightingImageFilter() {}
938 944
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
939 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { 954 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
940 this->INHERITED::flatten(buffer); 955 this->INHERITED::flatten(buffer);
941 fLight->flattenLight(buffer); 956 fLight->flattenLight(buffer);
942 buffer.writeScalar(fSurfaceScale * 255); 957 buffer.writeScalar(fSurfaceScale * 255);
943 } 958 }
944 959
945 /////////////////////////////////////////////////////////////////////////////// 960 ///////////////////////////////////////////////////////////////////////////////
946 961
947 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkLight* light, SkScalar sur faceScale, 962 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkLight* light, SkScalar sur faceScale,
948 SkScalar kd, SkImageFilter* input, const Cro pRect* cropRect, uint32_t uniqueID) { 963 SkScalar kd, SkImageFilter* input, const Cro pRect* cropRect, uint32_t uniqueID) {
(...skipping 10 matching lines...) Expand all
959 } 974 }
960 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in put, cropRect, uniqueID)); 975 return SkNEW_ARGS(SkDiffuseLightingImageFilter, (light, surfaceScale, kd, in put, cropRect, uniqueID));
961 } 976 }
962 977
963 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca lar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect, u int32_t uniqueID) 978 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca lar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect, u int32_t uniqueID)
964 : SkLightingImageFilter(light, surfaceScale, input, cropRect, uniqueID), 979 : SkLightingImageFilter(light, surfaceScale, input, cropRect, uniqueID),
965 fKD(kd) 980 fKD(kd)
966 { 981 {
967 } 982 }
968 983
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
969 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) { 993 SkFlattenable* SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) {
970 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 994 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
971 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); 995 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer));
972 SkScalar surfaceScale = buffer.readScalar(); 996 SkScalar surfaceScale = buffer.readScalar();
973 SkScalar kd = buffer.readScalar(); 997 SkScalar kd = buffer.readScalar();
974 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect( ), common.uniqueID()); 998 return Create(light, surfaceScale, kd, common.getInput(0), &common.cropRect( ), common.uniqueID());
975 } 999 }
976 1000
977 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { 1001 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
978 this->INHERITED::flatten(buffer); 1002 this->INHERITED::flatten(buffer);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 (light, surfaceScale, ks, shininess, input, cropRect, uniq ueID)); 1089 (light, surfaceScale, ks, shininess, input, cropRect, uniq ueID));
1066 } 1090 }
1067 1091
1068 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) 1092 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID)
1069 : SkLightingImageFilter(light, surfaceScale, input, cropRect, uniqueID), 1093 : SkLightingImageFilter(light, surfaceScale, input, cropRect, uniqueID),
1070 fKS(ks), 1094 fKS(ks),
1071 fShininess(shininess) 1095 fShininess(shininess)
1072 { 1096 {
1073 } 1097 }
1074 1098
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
1075 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) { 1110 SkFlattenable* SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) {
1076 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 1111 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
1077 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer)); 1112 SkAutoTUnref<SkLight> light(SkLight::UnflattenLight(buffer));
1078 SkScalar surfaceScale = buffer.readScalar(); 1113 SkScalar surfaceScale = buffer.readScalar();
1079 SkScalar ks = buffer.readScalar(); 1114 SkScalar ks = buffer.readScalar();
1080 SkScalar shine = buffer.readScalar(); 1115 SkScalar shine = buffer.readScalar();
1081 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr opRect(), common.uniqueID()); 1116 return Create(light, surfaceScale, ks, shine, common.getInput(0), &common.cr opRect(), common.uniqueID());
1082 } 1117 }
1083 1118
1084 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { 1119 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 1716
1682 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 1717 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
1683 } 1718 }
1684 1719
1685 #endif 1720 #endif
1686 1721
1687 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 1722 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
1688 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 1723 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
1689 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 1724 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
1690 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1725 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkLerpXfermode.cpp ('k') | src/effects/SkLumaColorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698