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

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

Issue 83343003: Adding more validation (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixed comments Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/effects/SkDropShadowImageFilter.cpp ('k') | src/effects/SkMagnifierImageFilter.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 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 return SkNEW_ARGS(SkSpecularLightingImageFilter, 880 return SkNEW_ARGS(SkSpecularLightingImageFilter,
881 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, cutoffAngl e, lightColor)), 881 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, cutoffAngl e, lightColor)),
882 surfaceScale, ks, shininess, input, cropRect)); 882 surfaceScale, ks, shininess, input, cropRect));
883 } 883 }
884 884
885 SkLightingImageFilter::~SkLightingImageFilter() { 885 SkLightingImageFilter::~SkLightingImageFilter() {
886 SkSafeUnref(fLight); 886 SkSafeUnref(fLight);
887 } 887 }
888 888
889 SkLightingImageFilter::SkLightingImageFilter(SkFlattenableReadBuffer& buffer) 889 SkLightingImageFilter::SkLightingImageFilter(SkFlattenableReadBuffer& buffer)
890 : INHERITED(buffer) { 890 : INHERITED(1, buffer) {
891 fLight = SkLight::UnflattenLight(buffer); 891 fLight = SkLight::UnflattenLight(buffer);
892 fSurfaceScale = buffer.readScalar(); 892 fSurfaceScale = buffer.readScalar();
893 buffer.validate(SkScalarIsFinite(fSurfaceScale)); 893 buffer.validate(SkScalarIsFinite(fSurfaceScale));
894 } 894 }
895 895
896 void SkLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { 896 void SkLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
897 this->INHERITED::flatten(buffer); 897 this->INHERITED::flatten(buffer);
898 fLight->flattenLight(buffer); 898 fLight->flattenLight(buffer);
899 buffer.writeScalar(fSurfaceScale); 899 buffer.writeScalar(fSurfaceScale);
900 } 900 }
901 901
902 /////////////////////////////////////////////////////////////////////////////// 902 ///////////////////////////////////////////////////////////////////////////////
903 903
904 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca lar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect = NULL) 904 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca lar surfaceScale, SkScalar kd, SkImageFilter* input, const CropRect* cropRect = NULL)
905 : SkLightingImageFilter(light, surfaceScale, input, cropRect), 905 : SkLightingImageFilter(light, surfaceScale, input, cropRect),
906 fKD(kd) 906 // According to the spec, kd can be any non-negative number :
907 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement
908 fKD(kd < 0 ? 0 : kd)
907 { 909 {
908 } 910 }
909 911
910 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkFlattenableReadBuff er& buffer) 912 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkFlattenableReadBuff er& buffer)
911 : INHERITED(buffer) 913 : INHERITED(buffer)
912 { 914 {
913 fKD = buffer.readScalar(); 915 fKD = buffer.readScalar();
914 buffer.validate(SkScalarIsFinite(fKD)); 916 buffer.validate(SkScalarIsFinite(fKD) && (fKD >= 0));
915 } 917 }
916 918
917 void SkDiffuseLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) con st { 919 void SkDiffuseLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) con st {
918 this->INHERITED::flatten(buffer); 920 this->INHERITED::flatten(buffer);
919 buffer.writeScalar(fKD); 921 buffer.writeScalar(fKD);
920 } 922 }
921 923
922 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, 924 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy,
923 const SkBitmap& source, 925 const SkBitmap& source,
924 const SkMatrix& ctm, 926 const SkMatrix& ctm,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri x, kd()); 980 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, matri x, kd());
979 } 981 }
980 return true; 982 return true;
981 } 983 }
982 #endif 984 #endif
983 985
984 /////////////////////////////////////////////////////////////////////////////// 986 ///////////////////////////////////////////////////////////////////////////////
985 987
986 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect) 988 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect)
987 : SkLightingImageFilter(light, surfaceScale, input, cropRect), 989 : SkLightingImageFilter(light, surfaceScale, input, cropRect),
988 fKS(ks), 990 // According to the spec, ks can be any non-negative number :
991 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement
992 fKS(ks < 0 ? 0 : ks),
989 fShininess(shininess) 993 fShininess(shininess)
990 { 994 {
991 } 995 }
992 996
993 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkFlattenableReadBu ffer& buffer) 997 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkFlattenableReadBu ffer& buffer)
994 : INHERITED(buffer) 998 : INHERITED(buffer)
995 { 999 {
996 fKS = buffer.readScalar(); 1000 fKS = buffer.readScalar();
997 fShininess = buffer.readScalar(); 1001 fShininess = buffer.readScalar();
998 buffer.validate(SkScalarIsFinite(fKS) && 1002 buffer.validate(SkScalarIsFinite(fKS) && (fKS >= 0) &&
999 SkScalarIsFinite(fShininess)); 1003 SkScalarIsFinite(fShininess));
1000 } 1004 }
1001 1005
1002 void SkSpecularLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) co nst { 1006 void SkSpecularLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) co nst {
1003 this->INHERITED::flatten(buffer); 1007 this->INHERITED::flatten(buffer);
1004 buffer.writeScalar(fKS); 1008 buffer.writeScalar(fKS);
1005 buffer.writeScalar(fShininess); 1009 buffer.writeScalar(fShininess);
1006 } 1010 }
1007 1011
1008 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, 1012 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy,
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 1597
1594 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 1598 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
1595 } 1599 }
1596 1600
1597 #endif 1601 #endif
1598 1602
1599 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 1603 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
1600 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 1604 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
1601 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 1605 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
1602 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1606 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkDropShadowImageFilter.cpp ('k') | src/effects/SkMagnifierImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698