Changeset 59220 in webkit
- Timestamp:
- May 12, 2010 3:18:00 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r59214 r59220 1 2010-05-12 Zoltan Herczeg <zherczeg@webkit.org> 2 3 Reviewed by Nikolas Zimmermann. 4 5 Updating the pixel tests for feDiffuseLighting and feSpecularLighting 6 https://bugs.webkit.org/show_bug.cgi?id=32197 7 https://bugs.webkit.org/show_bug.cgi?id=32199 8 9 No new test were added, since SVG expected values cover 10 the features of the implementation 11 12 * platform/mac/svg/W3C-SVG-1.1/filters-diffuse-01-f-expected.checksum: 13 * platform/mac/svg/W3C-SVG-1.1/filters-diffuse-01-f-expected.png: 14 * platform/mac/svg/W3C-SVG-1.1/filters-light-01-f-expected.checksum: 15 * platform/mac/svg/W3C-SVG-1.1/filters-light-01-f-expected.png: 16 * platform/mac/svg/W3C-SVG-1.1/filters-specular-01-f-expected.checksum: 17 * platform/mac/svg/W3C-SVG-1.1/filters-specular-01-f-expected.png: 18 1 19 2010-05-12 Csaba Osztrogonác <ossy@webkit.org> 2 20 -
trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/filters-diffuse-01-f-expected.checksum
r51800 r59220 1 6ee9ab81b1ac19dd038277e7aa1279b2 1 9a4aa2ceea5110c8983ece9488b29d64 -
trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/filters-light-01-f-expected.checksum
r51800 r59220 1 fa5f87c2370b77dc0e4c0559d5473760 1 b59839285201b39c68fbe5fd8ff644fe -
trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/filters-specular-01-f-expected.checksum
r51800 r59220 1 7e5b6aaf5eac391cf8b5649677485618 1 971950a557cecf04016f415711a3a415 -
trunk/WebCore/ChangeLog
r59219 r59220 1 2010-05-12 Zoltan Herczeg <zherczeg@webkit.org> 2 3 Reviewed by Nikolas Zimmermann. 4 5 Implementing SVG filters: feDiffuseLighting and feSpecularLighting 6 https://bugs.webkit.org/show_bug.cgi?id=32197 7 https://bugs.webkit.org/show_bug.cgi?id=32199 8 9 The patch implements the SVG filters feDiffuseLighting and 10 feSpecularLighting including the impementation of their possible 11 light sources according to the Scalable Vector Graphics (SVG) 12 1.1 Specification. Only two features are missing: supporting images 13 with height or width set to 1, and kernelUnitLength other than (1,1). 14 Since the two lighting filters have a similar body, a common base 15 class called FELighting is introduced, and contains the code for 16 both filters. The implementation employs single precision floating 17 point arithmetic (fixed precision integer arithmetic seemed too difficult). 18 19 Indentation is removed of the modified header files in svg/graphics/filters 20 21 * GNUmakefile.am: 22 * WebCore.pro: 23 * WebCore.xcodeproj/project.pbxproj: 24 * platform/graphics/FloatPoint3D.cpp: 25 * platform/graphics/FloatPoint3D.h: 26 (WebCore::FloatPoint3D::FloatPoint3D): constructors changed to inline 27 (WebCore::operator*): dot product 28 * svg/SVGFESpotLightElement.cpp: 29 (WebCore::SVGFESpotLightElement::lightSource): 30 * svg/graphics/filters/SVGDistantLightSource.h: 31 (WebCore::DistantLightSource::create): 32 (WebCore::DistantLightSource::azimuth): 33 (WebCore::DistantLightSource::elevation): 34 (WebCore::DistantLightSource::DistantLightSource): 35 * svg/graphics/filters/SVGFEDiffuseLighting.cpp: 36 (WebCore::FEDiffuseLighting::FEDiffuseLighting): 37 (WebCore::FEDiffuseLighting::create): 38 * svg/graphics/filters/SVGFEDiffuseLighting.h: 39 * svg/graphics/filters/SVGFELighting.cpp: Added. 40 (WebCore::FELighting::FELighting): 41 (WebCore::FELighting::LightingData::upLeftPixelValue): 42 (WebCore::FELighting::LightingData::upPixelValue): 43 (WebCore::FELighting::LightingData::upRightPixelValue): 44 (WebCore::FELighting::LightingData::leftPixelValue): 45 (WebCore::FELighting::LightingData::centerPixelValue): 46 (WebCore::FELighting::LightingData::rightPixelValue): 47 (WebCore::FELighting::LightingData::downLeftPixelValue): 48 (WebCore::FELighting::LightingData::downPixelValue): 49 (WebCore::FELighting::LightingData::downRightPixelValue): 50 (WebCore::FELighting::setPixel): 51 (WebCore::FELighting::drawLighting): 52 (WebCore::FELighting::apply): 53 * svg/graphics/filters/SVGFELighting.h: Added. 54 (WebCore::FELighting::uniteChildEffectSubregions): 55 (WebCore::FELighting::): 56 * svg/graphics/filters/SVGFESpecularLighting.cpp: 57 (WebCore::FESpecularLighting::FESpecularLighting): 58 (WebCore::FESpecularLighting::create): 59 * svg/graphics/filters/SVGFESpecularLighting.h: 60 * svg/graphics/filters/SVGLightSource.cpp: 61 (WebCore::PointLightSource::initPaintingData): 62 (WebCore::PointLightSource::updatePaintingData): 63 (WebCore::SpotLightSource::initPaintingData): 64 (WebCore::SpotLightSource::updatePaintingData): 65 (WebCore::DistantLightSource::initPaintingData): 66 (WebCore::DistantLightSource::updatePaintingData): 67 * svg/graphics/filters/SVGLightSource.h: 68 (WebCore::): 69 (WebCore::LightSource::LightSource): 70 (WebCore::LightSource::~LightSource): 71 (WebCore::LightSource::type): 72 * svg/graphics/filters/SVGPointLightSource.h: 73 (WebCore::PointLightSource::create): 74 (WebCore::PointLightSource::position): 75 (WebCore::PointLightSource::PointLightSource): 76 * svg/graphics/filters/SVGSpotLightSource.h: 77 (WebCore::SpotLightSource::create): 78 (WebCore::SpotLightSource::position): 79 (WebCore::SpotLightSource::direction): 80 (WebCore::SpotLightSource::specularExponent): 81 (WebCore::SpotLightSource::limitingConeAngle): 82 (WebCore::SpotLightSource::SpotLightSource): 83 1 84 2010-05-12 Xan Lopez <xlopez@igalia.com> 2 85 -
trunk/WebCore/GNUmakefile.am
r59219 r59220 3528 3528 WebCore/svg/graphics/filters/SVGFEImage.cpp \ 3529 3529 WebCore/svg/graphics/filters/SVGFEImage.h \ 3530 WebCore/svg/graphics/filters/SVGFELighting.cpp \ 3531 WebCore/svg/graphics/filters/SVGFELighting.h \ 3530 3532 WebCore/svg/graphics/filters/SVGFEMerge.cpp \ 3531 3533 WebCore/svg/graphics/filters/SVGFEMerge.h \ -
trunk/WebCore/WebCore.pro
r59148 r59220 1822 1822 svg/graphics/filters/SVGFEFlood.h \ 1823 1823 svg/graphics/filters/SVGFEImage.h \ 1824 svg/graphics/filters/SVGFELighting.h \ 1824 1825 svg/graphics/filters/SVGFEMerge.h \ 1825 1826 svg/graphics/filters/SVGFEMorphology.h \ … … 2736 2737 svg/graphics/filters/SVGFEFlood.cpp \ 2737 2738 svg/graphics/filters/SVGFEImage.cpp \ 2739 svg/graphics/filters/SVGFELighting.cpp \ 2738 2740 svg/graphics/filters/SVGFEMerge.cpp \ 2739 2741 svg/graphics/filters/SVGFEMorphology.cpp \ -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r59162 r59220 4910 4910 E415F1690D9A165D0033CE97 /* DOMElementTimeControl.h in Headers */ = {isa = PBXBuildFile; fileRef = E415F1680D9A165D0033CE97 /* DOMElementTimeControl.h */; }; 4911 4911 E415F1840D9A1A830033CE97 /* ElementTimeControl.h in Headers */ = {isa = PBXBuildFile; fileRef = E415F1830D9A1A830033CE97 /* ElementTimeControl.h */; }; 4912 E440A2D51191A50B000820B0 /* SVGFELighting.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E440A2D41191A50B000820B0 /* SVGFELighting.cpp */; }; 4913 E440A2D71191A523000820B0 /* SVGFELighting.h in Headers */ = {isa = PBXBuildFile; fileRef = E440A2D61191A523000820B0 /* SVGFELighting.h */; }; 4912 4914 E44613A10CD6331000FADA75 /* HTMLAudioElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */; }; 4913 4915 E44613A20CD6331000FADA75 /* HTMLAudioElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E44613900CD6331000FADA75 /* HTMLAudioElement.h */; }; … … 10376 10378 E415F1680D9A165D0033CE97 /* DOMElementTimeControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMElementTimeControl.h; sourceTree = "<group>"; }; 10377 10379 E415F1830D9A1A830033CE97 /* ElementTimeControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementTimeControl.h; sourceTree = "<group>"; }; 10380 E440A2D41191A50B000820B0 /* SVGFELighting.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGFELighting.cpp; sourceTree = "<group>"; }; 10381 E440A2D61191A523000820B0 /* SVGFELighting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGFELighting.h; sourceTree = "<group>"; }; 10378 10382 E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLAudioElement.cpp; sourceTree = "<group>"; }; 10379 10383 E44613900CD6331000FADA75 /* HTMLAudioElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLAudioElement.h; sourceTree = "<group>"; }; … … 14764 14768 children = ( 14765 14769 B25598D70D00D8B900BB825C /* SVGDistantLightSource.h */, 14770 E440A2D61191A523000820B0 /* SVGFELighting.h */, 14771 E440A2D41191A50B000820B0 /* SVGFELighting.cpp */, 14766 14772 B25598E00D00D8B900BB825C /* SVGFEConvolveMatrix.cpp */, 14767 14773 B25598E10D00D8B900BB825C /* SVGFEConvolveMatrix.h */, … … 19153 19159 2E94F43C119207DA00B7F75D /* JSFileReader.h in Headers */, 19154 19160 2E94F4511192096A00B7F75D /* FileReader.h in Headers */, 19161 E440A2D71191A523000820B0 /* SVGFELighting.h in Headers */, 19155 19162 ); 19156 19163 runOnlyForDeploymentPostprocessing = 0; … … 21420 21427 2E94F43B119207DA00B7F75D /* JSFileReader.cpp in Sources */, 21421 21428 2E94F4501192096400B7F75D /* FileReader.cpp in Sources */, 21429 E440A2D51191A50B000820B0 /* SVGFELighting.cpp in Sources */, 21422 21430 ); 21423 21431 runOnlyForDeploymentPostprocessing = 0; -
trunk/WebCore/platform/graphics/FloatPoint3D.cpp
r40827 r59220 23 23 24 24 #include <math.h> 25 #include "FloatPoint.h"26 25 #include "FloatPoint3D.h" 27 26 28 27 namespace WebCore { 29 30 FloatPoint3D::FloatPoint3D()31 : m_x(0)32 , m_y(0)33 , m_z(0)34 {35 }36 37 FloatPoint3D::FloatPoint3D(float x, float y, float z)38 : m_x(x)39 , m_y(y)40 , m_z(z)41 {42 }43 44 FloatPoint3D::FloatPoint3D(const FloatPoint& p)45 : m_x(p.x())46 , m_y(p.y())47 , m_z(0)48 {49 }50 28 51 29 void FloatPoint3D::normalize() -
trunk/WebCore/platform/graphics/FloatPoint3D.h
r46645 r59220 3 3 2004, 2005 Rob Buis <buis@kde.org> 4 4 2005 Eric Seidel <eric@webkit.org> 5 2010 Zoltan Herczeg <zherczeg@webkit.org> 5 6 6 7 This library is free software; you can redistribute it and/or … … 23 24 #define FloatPoint3D_h 24 25 26 #include "FloatPoint.h" 27 25 28 namespace WebCore { 26 27 class FloatPoint;28 29 29 30 class FloatPoint3D { 30 31 public: 31 FloatPoint3D(); 32 FloatPoint3D(float x, float y, float z); 33 FloatPoint3D(const FloatPoint&); 32 FloatPoint3D() 33 : m_x(0) 34 , m_y(0) 35 , m_z(0) 36 { 37 } 38 39 FloatPoint3D(float x, float y, float z) 40 : m_x(x) 41 , m_y(y) 42 , m_z(z) 43 { 44 } 45 46 FloatPoint3D(const FloatPoint& p) 47 : m_x(p.x()) 48 , m_y(p.y()) 49 , m_z(0) 50 { 51 } 52 53 FloatPoint3D(const FloatPoint3D& p) 54 : m_x(p.x()) 55 , m_y(p.y()) 56 , m_z(p.z()) 57 { 58 } 34 59 35 60 float x() const { return m_x; } … … 60 85 } 61 86 87 inline float operator*(const FloatPoint3D& a, const FloatPoint3D& b) 88 { 89 // dot product 90 return a.x() * b.x() + a.y() * b.y() + a.z() * b.z(); 91 } 92 62 93 } // namespace WebCore 63 94 -
trunk/WebCore/svg/SVGFESpotLightElement.cpp
r51945 r59220 38 38 { 39 39 FloatPoint3D pos(x(), y(), z()); 40 FloatPoint3D direction(pointsAtX(), pointsAtY(), pointsAtZ()); 40 41 41 // convert lookAt to a direction42 FloatPoint3D direction(pointsAtX() - pos.x(),43 pointsAtY() - pos.y(),44 pointsAtZ() - pos.z());45 46 direction.normalize();47 42 return SpotLightSource::create(pos, direction, specularExponent(), limitingConeAngle()); 48 43 } -
trunk/WebCore/svg/graphics/filters/SVGDistantLightSource.h
r51945 r59220 29 29 namespace WebCore { 30 30 31 32 33 34 35 36 31 class DistantLightSource : public LightSource { 32 public: 33 static PassRefPtr<DistantLightSource> create(float azimuth, float elevation) 34 { 35 return adoptRef(new DistantLightSource(azimuth, elevation)); 36 } 37 37 38 39 38 float azimuth() const { return m_azimuth; } 39 float elevation() const { return m_elevation; } 40 40 41 virtual TextStream& externalRepresentation(TextStream&) const; 41 virtual void initPaintingData(PaintingData&); 42 virtual void updatePaintingData(PaintingData&, int x, int y, float z); 42 43 43 private: 44 DistantLightSource(float azimuth, float elevation) 45 : LightSource(LS_DISTANT) 46 , m_azimuth(azimuth) 47 , m_elevation(elevation) 48 { 49 } 44 virtual TextStream& externalRepresentation(TextStream&) const; 50 45 51 float m_azimuth; 52 float m_elevation; 53 }; 46 private: 47 DistantLightSource(float azimuth, float elevation) 48 : LightSource(LS_DISTANT) 49 , m_azimuth(azimuth) 50 , m_elevation(elevation) 51 { 52 } 53 54 float m_azimuth; 55 float m_elevation; 56 }; 54 57 55 58 } // namespace WebCore -
trunk/WebCore/svg/graphics/filters/SVGFEDiffuseLighting.cpp
r59069 r59220 23 23 24 24 #if ENABLE(SVG) && ENABLE(FILTERS) 25 #include "SVGFEDiffuseLighting.h" 26 25 27 #include "SVGLightSource.h" 26 #include "SVGFEDiffuseLighting.h"27 28 #include "SVGRenderTreeAsText.h" 28 #include "Filter.h"29 29 30 30 namespace WebCore { 31 31 32 FEDiffuseLighting::FEDiffuseLighting(FilterEffect* in , const Color& lightingColor, const float& surfaceScale, 33 const float& diffuseConstant, const float& kernelUnitLengthX, const float& kernelUnitLengthY, PassRefPtr<LightSource> lightSource) 34 : FilterEffect() 35 , m_in(in) 36 , m_lightingColor(lightingColor) 37 , m_surfaceScale(surfaceScale) 38 , m_diffuseConstant(diffuseConstant) 39 , m_kernelUnitLengthX(kernelUnitLengthX) 40 , m_kernelUnitLengthY(kernelUnitLengthY) 41 , m_lightSource(lightSource) 32 FEDiffuseLighting::FEDiffuseLighting(FilterEffect* in, const Color& lightingColor, float surfaceScale, 33 float diffuseConstant, float kernelUnitLengthX, float kernelUnitLengthY, PassRefPtr<LightSource> lightSource) 34 : FELighting(DiffuseLighting, in, lightingColor, surfaceScale, diffuseConstant, 0.0f, 0.0f, kernelUnitLengthX, kernelUnitLengthY, lightSource) 42 35 { 43 36 } 44 37 45 38 PassRefPtr<FEDiffuseLighting> FEDiffuseLighting::create(FilterEffect* in , const Color& lightingColor, 46 const float& surfaceScale, const float& diffuseConstant, const float&kernelUnitLengthX,47 const float&kernelUnitLengthY, PassRefPtr<LightSource> lightSource)39 float surfaceScale, float diffuseConstant, float kernelUnitLengthX, 40 float kernelUnitLengthY, PassRefPtr<LightSource> lightSource) 48 41 { 49 42 return adoptRef(new FEDiffuseLighting(in, lightingColor, surfaceScale, diffuseConstant, kernelUnitLengthX, kernelUnitLengthY, lightSource)); … … 114 107 } 115 108 116 void FEDiffuseLighting::apply(Filter*)117 {118 }119 120 109 void FEDiffuseLighting::dump() 121 110 { -
trunk/WebCore/svg/graphics/filters/SVGFEDiffuseLighting.h
r59069 r59220 24 24 25 25 #if ENABLE(SVG) && ENABLE(FILTERS) 26 #include "Color.h" 27 #include "FilterEffect.h" 28 #include "Filter.h" 26 #include "SVGFELighting.h" 29 27 30 28 namespace WebCore { 31 29 32 30 class LightSource; 33 31 34 class FEDiffuseLighting : public FilterEffect{35 36 static PassRefPtr<FEDiffuseLighting> create(FilterEffect*, const Color&, const float&, const float&,37 const float&, const float&, PassRefPtr<LightSource>);38 32 class FEDiffuseLighting : public FELighting { 33 public: 34 static PassRefPtr<FEDiffuseLighting> create(FilterEffect*, const Color&, float, float, 35 float, float, PassRefPtr<LightSource>); 36 virtual ~FEDiffuseLighting(); 39 37 40 41 38 Color lightingColor() const; 39 void setLightingColor(const Color&); 42 40 43 44 41 float surfaceScale() const; 42 void setSurfaceScale(float); 45 43 46 47 44 float diffuseConstant() const; 45 void setDiffuseConstant(float); 48 46 49 50 47 float kernelUnitLengthX() const; 48 void setKernelUnitLengthX(float); 51 49 52 53 50 float kernelUnitLengthY() const; 51 void setKernelUnitLengthY(float); 54 52 55 56 53 const LightSource* lightSource() const; 54 void setLightSource(PassRefPtr<LightSource>); 57 55 58 virtual FloatRect uniteChildEffectSubregions(Filter* filter) { return calculateUnionOfChildEffectSubregions(filter, m_in.get()); } 59 void apply(Filter*); 60 void dump(); 61 TextStream& externalRepresentation(TextStream&, int indent) const; 62 63 private: 64 FEDiffuseLighting(FilterEffect*, const Color&, const float&, const float&, 65 const float&, const float&, PassRefPtr<LightSource>); 56 void dump(); 57 TextStream& externalRepresentation(TextStream&, int indent) const; 66 58 67 RefPtr<FilterEffect> m_in; 68 Color m_lightingColor; 69 float m_surfaceScale; 70 float m_diffuseConstant; 71 float m_kernelUnitLengthX; 72 float m_kernelUnitLengthY; 73 RefPtr<LightSource> m_lightSource; 74 }; 59 private: 60 FEDiffuseLighting(FilterEffect*, const Color&, float, float, 61 float, float, PassRefPtr<LightSource>); 62 }; 75 63 76 64 } // namespace WebCore -
trunk/WebCore/svg/graphics/filters/SVGFESpecularLighting.cpp
r59069 r59220 24 24 #if ENABLE(SVG) && ENABLE(FILTERS) 25 25 #include "SVGFESpecularLighting.h" 26 27 #include "SVGLightSource.h" 26 28 #include "SVGRenderTreeAsText.h" 27 #include "Filter.h"28 29 29 30 namespace WebCore { 30 31 31 FESpecularLighting::FESpecularLighting(FilterEffect* in, const Color& lightingColor, const float& surfaceScale, 32 const float& specularConstant, const float& specularExponent, const float& kernelUnitLengthX, 33 const float& kernelUnitLengthY, PassRefPtr<LightSource> lightSource) 34 : FilterEffect() 35 , m_in(in) 36 , m_lightingColor(lightingColor) 37 , m_surfaceScale(surfaceScale) 38 , m_specularConstant(specularConstant) 39 , m_specularExponent(specularExponent) 40 , m_kernelUnitLengthX(kernelUnitLengthX) 41 , m_kernelUnitLengthY(kernelUnitLengthY) 42 , m_lightSource(lightSource) 32 FESpecularLighting::FESpecularLighting(FilterEffect* in, const Color& lightingColor, float surfaceScale, 33 float specularConstant, float specularExponent, float kernelUnitLengthX, 34 float kernelUnitLengthY, PassRefPtr<LightSource> lightSource) 35 : FELighting(SpecularLighting, in, lightingColor, surfaceScale, 0.0f, specularConstant, specularExponent, kernelUnitLengthX, kernelUnitLengthY, lightSource) 43 36 { 44 37 } 45 38 46 39 PassRefPtr<FESpecularLighting> FESpecularLighting::create(FilterEffect* in, const Color& lightingColor, 47 const float& surfaceScale, const float& specularConstant, const float&specularExponent,48 const float& kernelUnitLengthX, const float&kernelUnitLengthY, PassRefPtr<LightSource> lightSource)40 float surfaceScale, float specularConstant, float specularExponent, 41 float kernelUnitLengthX, float kernelUnitLengthY, PassRefPtr<LightSource> lightSource) 49 42 { 50 43 return adoptRef(new FESpecularLighting(in, lightingColor, surfaceScale, specularConstant, specularExponent, … … 126 119 } 127 120 128 void FESpecularLighting::apply(Filter*)129 {130 }131 132 121 void FESpecularLighting::dump() 133 122 { -
trunk/WebCore/svg/graphics/filters/SVGFESpecularLighting.h
r59069 r59220 24 24 25 25 #if ENABLE(SVG) && ENABLE(FILTERS) 26 #include "Color.h" 27 #include "FilterEffect.h" 28 #include "SVGLightSource.h" 29 #include "Filter.h" 26 #include "SVGFELighting.h" 30 27 31 28 namespace WebCore { 32 29 33 class FESpecularLighting : public FilterEffect{34 35 static PassRefPtr<FESpecularLighting> create(FilterEffect*, const Color&, const float&, const float&,36 const float&, const float&, const float&, PassRefPtr<LightSource>);37 30 class FESpecularLighting : public FELighting { 31 public: 32 static PassRefPtr<FESpecularLighting> create(FilterEffect*, const Color&, float, float, 33 float, float, float, PassRefPtr<LightSource>); 34 virtual ~FESpecularLighting(); 38 35 39 40 36 Color lightingColor() const; 37 void setLightingColor(const Color&); 41 38 42 43 39 float surfaceScale() const; 40 void setSurfaceScale(float); 44 41 45 46 42 float specularConstant() const; 43 void setSpecularConstant(float); 47 44 48 49 45 float specularExponent() const; 46 void setSpecularExponent(float); 50 47 51 52 48 float kernelUnitLengthX() const; 49 void setKernelUnitLengthX(float); 53 50 54 55 51 float kernelUnitLengthY() const; 52 void setKernelUnitLengthY(float); 56 53 57 58 54 const LightSource* lightSource() const; 55 void setLightSource(PassRefPtr<LightSource>); 59 56 60 virtual FloatRect uniteEffectRect(Filter* filter) { return calculateUnionOfChildEffectSubregions(filter, m_in.get()); } 61 void apply(Filter*); 62 void dump(); 63 TextStream& externalRepresentation(TextStream&, int indent) const; 57 void dump(); 58 TextStream& externalRepresentation(TextStream&, int indent) const; 64 59 65 private: 66 FESpecularLighting(FilterEffect*, const Color&, const float&, const float&, const float&, 67 const float&, const float&, PassRefPtr<LightSource>); 68 69 RefPtr<FilterEffect> m_in; 70 Color m_lightingColor; 71 float m_surfaceScale; 72 float m_specularConstant; 73 float m_specularExponent; 74 float m_kernelUnitLengthX; 75 float m_kernelUnitLengthY; 76 RefPtr<LightSource> m_lightSource; 77 }; 60 private: 61 FESpecularLighting(FilterEffect*, const Color&, float, float, float, 62 float, float, PassRefPtr<LightSource>); 63 }; 78 64 79 65 } // namespace WebCore -
trunk/WebCore/svg/graphics/filters/SVGLightSource.cpp
r44253 r59220 3 3 2004, 2005 Rob Buis <buis@kde.org> 4 4 2005 Eric Seidel <eric@webkit.org> 5 2010 Zoltan Herczeg <zherczeg@webkit.org> 5 6 6 7 This library is free software; you can redistribute it and/or … … 23 24 24 25 #if ENABLE(SVG) && ENABLE(FILTERS) 26 #include "SVGLightSource.h" 27 28 #include "SVGDistantLightSource.h" 25 29 #include "SVGPointLightSource.h" 26 30 #include "SVGRenderTreeAsText.h" 27 31 #include "SVGSpotLightSource.h" 28 #include "SVGDistantLightSource.h"32 #include <wtf/MathExtras.h> 29 33 30 34 namespace WebCore { 35 36 void PointLightSource::initPaintingData(PaintingData&) 37 { 38 } 39 40 void PointLightSource::updatePaintingData(PaintingData& paintingData, int x, int y, float z) 41 { 42 paintingData.lightVector.setX(m_position.x() - x); 43 paintingData.lightVector.setY(m_position.y() - y); 44 paintingData.lightVector.setZ(m_position.z() - z); 45 paintingData.lightVector.normalize(); 46 } 47 48 void SpotLightSource::initPaintingData(PaintingData& paintingData) 49 { 50 paintingData.privateColorVector = paintingData.colorVector; 51 paintingData.directionVector.setX(m_direction.x() - m_position.x()); 52 paintingData.directionVector.setY(m_direction.y() - m_position.y()); 53 paintingData.directionVector.setZ(m_direction.z() - m_position.z()); 54 paintingData.directionVector.normalize(); 55 56 if (!m_limitingConeAngle) { 57 paintingData.coneCutOffLimit = 0.0f; 58 paintingData.coneFullLight = cosf(deg2rad(92.0f)); 59 } else { 60 float limitingConeAngle = m_limitingConeAngle; 61 if (limitingConeAngle < 0.0f) 62 limitingConeAngle = 0.0f; 63 else if (limitingConeAngle > 90.0f) 64 limitingConeAngle = 90.0f; 65 paintingData.coneCutOffLimit = cosf(deg2rad(180.0f - limitingConeAngle)); 66 limitingConeAngle -= 2.0f; 67 if (limitingConeAngle < 0.0f) 68 limitingConeAngle = 0.0f; 69 paintingData.coneFullLight = cosf(deg2rad(180.0f - limitingConeAngle)); 70 } 71 72 // Optimization for common specularExponent values 73 if (!m_specularExponent) 74 paintingData.specularExponent = 0; 75 else if (m_specularExponent == 1.0f) 76 paintingData.specularExponent = 1; 77 else // It is neither 0.0f nor 1.0f 78 paintingData.specularExponent = 2; 79 } 80 81 void SpotLightSource::updatePaintingData(PaintingData& paintingData, int x, int y, float z) 82 { 83 paintingData.lightVector.setX(m_position.x() - x); 84 paintingData.lightVector.setY(m_position.y() - y); 85 paintingData.lightVector.setZ(m_position.z() - z); 86 paintingData.lightVector.normalize(); 87 88 float cosineOfAngle = paintingData.lightVector * paintingData.directionVector; 89 if (cosineOfAngle > paintingData.coneCutOffLimit) { 90 // No light is produced, scanlines are not updated 91 paintingData.colorVector.setX(0.0f); 92 paintingData.colorVector.setY(0.0f); 93 paintingData.colorVector.setZ(0.0f); 94 return; 95 } 96 97 // Set the color of the pixel 98 float lightStrength; 99 switch (paintingData.specularExponent) { 100 case 0: 101 lightStrength = 1.0f; // -cosineOfAngle ^ 0 == 1 102 break; 103 case 1: 104 lightStrength = -cosineOfAngle; // -cosineOfAngle ^ 1 == -cosineOfAngle 105 break; 106 default: 107 lightStrength = powf(-cosineOfAngle, m_specularExponent); 108 break; 109 } 110 111 if (cosineOfAngle > paintingData.coneFullLight) 112 lightStrength *= (paintingData.coneCutOffLimit - cosineOfAngle) / (paintingData.coneCutOffLimit - paintingData.coneFullLight); 113 114 if (lightStrength > 1.0f) 115 lightStrength = 1.0f; 116 117 paintingData.colorVector.setX(paintingData.privateColorVector.x() * lightStrength); 118 paintingData.colorVector.setY(paintingData.privateColorVector.y() * lightStrength); 119 paintingData.colorVector.setZ(paintingData.privateColorVector.z() * lightStrength); 120 } 121 122 void DistantLightSource::initPaintingData(PaintingData& paintingData) 123 { 124 float azimuth = deg2rad(m_azimuth); 125 float elevation = deg2rad(m_elevation); 126 paintingData.lightVector.setX(cosf(azimuth) * cosf(elevation)); 127 paintingData.lightVector.setY(sinf(azimuth) * cosf(elevation)); 128 paintingData.lightVector.setZ(sinf(elevation)); 129 } 130 131 void DistantLightSource::updatePaintingData(PaintingData&, int, int, float) 132 { 133 } 31 134 32 135 static TextStream& operator<<(TextStream& ts, const FloatPoint3D& p) -
trunk/WebCore/svg/graphics/filters/SVGLightSource.h
r51945 r59220 4 4 2004, 2005 Rob Buis <buis@kde.org> 5 5 2005 Eric Seidel <eric@webkit.org> 6 2010 Zoltan Herczeg <zherczeg@webkit.org> 6 7 7 8 This library is free software; you can redistribute it and/or … … 25 26 26 27 #if ENABLE(SVG) && ENABLE(FILTERS) 28 #include "FloatPoint3D.h" 27 29 #include <wtf/PassRefPtr.h> 28 30 #include <wtf/RefCounted.h> … … 30 32 namespace WebCore { 31 33 32 enum LightType { 33 LS_DISTANT, 34 LS_POINT, 35 LS_SPOT 34 enum LightType { 35 LS_DISTANT, 36 LS_POINT, 37 LS_SPOT 38 }; 39 40 class TextStream; 41 42 class LightSource : public RefCounted<LightSource> { 43 public: 44 45 // Light vectors must be calculated for every pixel during 46 // painting. It is expensive to pass all these arguments to 47 // a frequently called function, especially because not all 48 // light sources require all of them. Instead, we just pass 49 // a reference to the following structure 50 struct PaintingData { 51 // SVGFELighting also use them 52 FloatPoint3D lightVector; 53 FloatPoint3D colorVector; 54 // Private members 55 FloatPoint3D directionVector; 56 FloatPoint3D privateColorVector; 57 float coneCutOffLimit; 58 float coneFullLight; 59 int specularExponent; 36 60 }; 37 61 38 class TextStream; 62 LightSource(LightType type) 63 : m_type(type) 64 { } 39 65 40 class LightSource : public RefCounted<LightSource> { 41 public: 42 LightSource(LightType type) 43 : m_type(type) 44 { } 66 virtual ~LightSource() { } 45 67 46 virtual ~LightSource() { } 68 LightType type() const { return m_type; } 69 virtual TextStream& externalRepresentation(TextStream&) const = 0; 47 70 48 LightType type() const { return m_type; } 49 virtual TextStream& externalRepresentation(TextStream&) const = 0; 71 virtual void initPaintingData(PaintingData&) = 0; 72 // z is a float number, since it is the alpha value scaled by a user 73 // specified "surfaceScale" constant, which type is <number> in the SVG standard 74 virtual void updatePaintingData(PaintingData&, int x, int y, float z) = 0; 50 75 51 52 53 76 private: 77 LightType m_type; 78 }; 54 79 55 80 } // namespace WebCore -
trunk/WebCore/svg/graphics/filters/SVGPointLightSource.h
r51945 r59220 25 25 26 26 #if ENABLE(SVG) && ENABLE(FILTERS) 27 #include "FloatPoint3D.h"28 27 #include "SVGLightSource.h" 29 28 30 29 namespace WebCore { 31 30 32 33 34 35 36 37 31 class PointLightSource : public LightSource { 32 public: 33 static PassRefPtr<PointLightSource> create(const FloatPoint3D& position) 34 { 35 return adoptRef(new PointLightSource(position)); 36 } 38 37 39 38 const FloatPoint3D& position() const { return m_position; } 40 39 41 virtual TextStream& externalRepresentation(TextStream&) const; 40 virtual void initPaintingData(PaintingData&); 41 virtual void updatePaintingData(PaintingData&, int x, int y, float z); 42 42 43 private: 44 PointLightSource(const FloatPoint3D& position) 45 : LightSource(LS_POINT) 46 , m_position(position) 47 { 48 } 43 virtual TextStream& externalRepresentation(TextStream&) const; 49 44 50 FloatPoint3D m_position; 51 }; 45 private: 46 PointLightSource(const FloatPoint3D& position) 47 : LightSource(LS_POINT) 48 , m_position(position) 49 { 50 } 51 52 FloatPoint3D m_position; 53 }; 52 54 53 55 } // namespace WebCore -
trunk/WebCore/svg/graphics/filters/SVGSpotLightSource.h
r51945 r59220 25 25 26 26 #if ENABLE(SVG) && ENABLE(FILTERS) 27 #include "FloatPoint3D.h"28 27 #include "SVGLightSource.h" 29 28 30 29 namespace WebCore { 31 30 32 33 34 static PassRefPtr<SpotLightSource> create(const FloatPoint3D& position, const FloatPoint3D& direction,35 36 37 38 31 class SpotLightSource : public LightSource { 32 public: 33 static PassRefPtr<SpotLightSource> create(const FloatPoint3D& position, 34 const FloatPoint3D& direction, float specularExponent, float limitingConeAngle) 35 { 36 return adoptRef(new SpotLightSource(position, direction, specularExponent, limitingConeAngle)); 37 } 39 38 40 41 39 const FloatPoint3D& position() const { return m_position; } 40 const FloatPoint3D& direction() const { return m_direction; } 42 41 43 44 42 float specularExponent() const { return m_specularExponent; } 43 float limitingConeAngle() const { return m_limitingConeAngle; } 45 44 46 virtual TextStream& externalRepresentation(TextStream&) const; 45 virtual void initPaintingData(PaintingData&); 46 virtual void updatePaintingData(PaintingData&, int x, int y, float z); 47 47 48 private: 49 SpotLightSource(const FloatPoint3D& position, const FloatPoint3D& direction, 50 float specularExponent, float limitingConeAngle) 51 : LightSource(LS_SPOT) 52 , m_position(position) 53 , m_direction(direction) 54 , m_specularExponent(specularExponent) 55 , m_limitingConeAngle(limitingConeAngle) 56 { 57 } 48 virtual TextStream& externalRepresentation(TextStream&) const; 58 49 59 FloatPoint3D m_position; 60 FloatPoint3D m_direction; 50 private: 51 SpotLightSource(const FloatPoint3D& position, const FloatPoint3D& direction, 52 float specularExponent, float limitingConeAngle) 53 : LightSource(LS_SPOT) 54 , m_position(position) 55 , m_direction(direction) 56 , m_specularExponent(specularExponent) 57 , m_limitingConeAngle(limitingConeAngle) 58 { 59 } 61 60 62 float m_specularExponent; 63 float m_limitingConeAngle; 64 }; 61 FloatPoint3D m_position; 62 FloatPoint3D m_direction; 63 64 float m_specularExponent; 65 float m_limitingConeAngle; 66 }; 65 67 66 68 } // namespace WebCore
Note: See TracChangeset
for help on using the changeset viewer.