Changeset 59220 in webkit


Ignore:
Timestamp:
May 12, 2010 3:18:00 AM (14 years ago)
Author:
zherczeg@webkit.org
Message:

WebCore: Implementing SVG filters: feDiffuseLighting and feSpecularLighting
https://bugs.webkit.org/show_bug.cgi?id=32197
https://bugs.webkit.org/show_bug.cgi?id=32199

Reviewed by Nikolas Zimmermann.

The patch implements the SVG filters feDiffuseLighting and
feSpecularLighting including the impementation of their possible
light sources according to the Scalable Vector Graphics (SVG)
1.1 Specification. Only two features are missing: supporting images
with height or width set to 1, and kernelUnitLength other than (1,1).
Since the two lighting filters have a similar body, a common base
class called FELighting is introduced, and contains the code for
both filters. The implementation employs single precision floating
point arithmetic (fixed precision integer arithmetic seemed too difficult).

Indentation is removed of the modified header files in svg/graphics/filters

  • GNUmakefile.am:
  • WebCore.pro:
  • WebCore.xcodeproj/project.pbxproj:
  • platform/graphics/FloatPoint3D.cpp:
  • platform/graphics/FloatPoint3D.h:

(WebCore::FloatPoint3D::FloatPoint3D): constructors changed to inline
(WebCore::operator*): dot product

  • svg/SVGFESpotLightElement.cpp:

(WebCore::SVGFESpotLightElement::lightSource):

  • svg/graphics/filters/SVGDistantLightSource.h:

(WebCore::DistantLightSource::create):
(WebCore::DistantLightSource::azimuth):
(WebCore::DistantLightSource::elevation):
(WebCore::DistantLightSource::DistantLightSource):

  • svg/graphics/filters/SVGFEDiffuseLighting.cpp:

(WebCore::FEDiffuseLighting::FEDiffuseLighting):
(WebCore::FEDiffuseLighting::create):

  • svg/graphics/filters/SVGFEDiffuseLighting.h:
  • svg/graphics/filters/SVGFELighting.cpp: Added.

(WebCore::FELighting::FELighting):
(WebCore::FELighting::LightingData::upLeftPixelValue):
(WebCore::FELighting::LightingData::upPixelValue):
(WebCore::FELighting::LightingData::upRightPixelValue):
(WebCore::FELighting::LightingData::leftPixelValue):
(WebCore::FELighting::LightingData::centerPixelValue):
(WebCore::FELighting::LightingData::rightPixelValue):
(WebCore::FELighting::LightingData::downLeftPixelValue):
(WebCore::FELighting::LightingData::downPixelValue):
(WebCore::FELighting::LightingData::downRightPixelValue):
(WebCore::FELighting::setPixel):
(WebCore::FELighting::drawLighting):
(WebCore::FELighting::apply):

  • svg/graphics/filters/SVGFELighting.h: Added.

(WebCore::FELighting::uniteChildEffectSubregions):
(WebCore::FELighting::):

  • svg/graphics/filters/SVGFESpecularLighting.cpp:

(WebCore::FESpecularLighting::FESpecularLighting):
(WebCore::FESpecularLighting::create):

  • svg/graphics/filters/SVGFESpecularLighting.h:
  • svg/graphics/filters/SVGLightSource.cpp:

(WebCore::PointLightSource::initPaintingData):
(WebCore::PointLightSource::updatePaintingData):
(WebCore::SpotLightSource::initPaintingData):
(WebCore::SpotLightSource::updatePaintingData):
(WebCore::DistantLightSource::initPaintingData):
(WebCore::DistantLightSource::updatePaintingData):

  • svg/graphics/filters/SVGLightSource.h:

(WebCore::):
(WebCore::LightSource::LightSource):
(WebCore::LightSource::~LightSource):
(WebCore::LightSource::type):

  • svg/graphics/filters/SVGPointLightSource.h:

(WebCore::PointLightSource::create):
(WebCore::PointLightSource::position):
(WebCore::PointLightSource::PointLightSource):

  • svg/graphics/filters/SVGSpotLightSource.h:

(WebCore::SpotLightSource::create):
(WebCore::SpotLightSource::position):
(WebCore::SpotLightSource::direction):
(WebCore::SpotLightSource::specularExponent):
(WebCore::SpotLightSource::limitingConeAngle):
(WebCore::SpotLightSource::SpotLightSource):

LayoutTests: Updating the pixel tests for feDiffuseLighting and feSpecularLighting
https://bugs.webkit.org/show_bug.cgi?id=32197
https://bugs.webkit.org/show_bug.cgi?id=32199

Reviewed by Nikolas Zimmermann.

No new test were added, since SVG expected values cover
the features of the implementation

  • platform/mac/svg/W3C-SVG-1.1/filters-diffuse-01-f-expected.checksum:
  • platform/mac/svg/W3C-SVG-1.1/filters-diffuse-01-f-expected.png:
  • platform/mac/svg/W3C-SVG-1.1/filters-light-01-f-expected.checksum:
  • platform/mac/svg/W3C-SVG-1.1/filters-light-01-f-expected.png:
  • platform/mac/svg/W3C-SVG-1.1/filters-specular-01-f-expected.checksum:
  • platform/mac/svg/W3C-SVG-1.1/filters-specular-01-f-expected.png:
Location:
trunk
Files:
2 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r59214 r59220  
     12010-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
    1192010-05-12  Csaba Osztrogonác  <ossy@webkit.org>
    220
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/filters-diffuse-01-f-expected.checksum

    r51800 r59220  
    1 6ee9ab81b1ac19dd038277e7aa1279b2
     19a4aa2ceea5110c8983ece9488b29d64
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/filters-light-01-f-expected.checksum

    r51800 r59220  
    1 fa5f87c2370b77dc0e4c0559d5473760
     1b59839285201b39c68fbe5fd8ff644fe
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/filters-specular-01-f-expected.checksum

    r51800 r59220  
    1 7e5b6aaf5eac391cf8b5649677485618
     1971950a557cecf04016f415711a3a415
  • trunk/WebCore/ChangeLog

    r59219 r59220  
     12010-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
    1842010-05-12  Xan Lopez  <xlopez@igalia.com>
    285
  • trunk/WebCore/GNUmakefile.am

    r59219 r59220  
    35283528        WebCore/svg/graphics/filters/SVGFEImage.cpp \
    35293529        WebCore/svg/graphics/filters/SVGFEImage.h \
     3530        WebCore/svg/graphics/filters/SVGFELighting.cpp \
     3531        WebCore/svg/graphics/filters/SVGFELighting.h \
    35303532        WebCore/svg/graphics/filters/SVGFEMerge.cpp \
    35313533        WebCore/svg/graphics/filters/SVGFEMerge.h \
  • trunk/WebCore/WebCore.pro

    r59148 r59220  
    18221822    svg/graphics/filters/SVGFEFlood.h \
    18231823    svg/graphics/filters/SVGFEImage.h \
     1824    svg/graphics/filters/SVGFELighting.h \
    18241825    svg/graphics/filters/SVGFEMerge.h \
    18251826    svg/graphics/filters/SVGFEMorphology.h \
     
    27362737        svg/graphics/filters/SVGFEFlood.cpp \
    27372738        svg/graphics/filters/SVGFEImage.cpp \
     2739        svg/graphics/filters/SVGFELighting.cpp \
    27382740        svg/graphics/filters/SVGFEMerge.cpp \
    27392741        svg/graphics/filters/SVGFEMorphology.cpp \
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r59162 r59220  
    49104910                E415F1690D9A165D0033CE97 /* DOMElementTimeControl.h in Headers */ = {isa = PBXBuildFile; fileRef = E415F1680D9A165D0033CE97 /* DOMElementTimeControl.h */; };
    49114911                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 */; };
    49124914                E44613A10CD6331000FADA75 /* HTMLAudioElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */; };
    49134915                E44613A20CD6331000FADA75 /* HTMLAudioElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E44613900CD6331000FADA75 /* HTMLAudioElement.h */; };
     
    1037610378                E415F1680D9A165D0033CE97 /* DOMElementTimeControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMElementTimeControl.h; sourceTree = "<group>"; };
    1037710379                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>"; };
    1037810382                E446138F0CD6331000FADA75 /* HTMLAudioElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLAudioElement.cpp; sourceTree = "<group>"; };
    1037910383                E44613900CD6331000FADA75 /* HTMLAudioElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLAudioElement.h; sourceTree = "<group>"; };
     
    1476414768                        children = (
    1476514769                                B25598D70D00D8B900BB825C /* SVGDistantLightSource.h */,
     14770                                E440A2D61191A523000820B0 /* SVGFELighting.h */,
     14771                                E440A2D41191A50B000820B0 /* SVGFELighting.cpp */,
    1476614772                                B25598E00D00D8B900BB825C /* SVGFEConvolveMatrix.cpp */,
    1476714773                                B25598E10D00D8B900BB825C /* SVGFEConvolveMatrix.h */,
     
    1915319159                                2E94F43C119207DA00B7F75D /* JSFileReader.h in Headers */,
    1915419160                                2E94F4511192096A00B7F75D /* FileReader.h in Headers */,
     19161                                E440A2D71191A523000820B0 /* SVGFELighting.h in Headers */,
    1915519162                        );
    1915619163                        runOnlyForDeploymentPostprocessing = 0;
     
    2142021427                                2E94F43B119207DA00B7F75D /* JSFileReader.cpp in Sources */,
    2142121428                                2E94F4501192096400B7F75D /* FileReader.cpp in Sources */,
     21429                                E440A2D51191A50B000820B0 /* SVGFELighting.cpp in Sources */,
    2142221430                        );
    2142321431                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/platform/graphics/FloatPoint3D.cpp

    r40827 r59220  
    2323
    2424#include <math.h>
    25 #include "FloatPoint.h"
    2625#include "FloatPoint3D.h"
    2726
    2827namespace 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 }
    5028
    5129void FloatPoint3D::normalize()
  • trunk/WebCore/platform/graphics/FloatPoint3D.h

    r46645 r59220  
    33                  2004, 2005 Rob Buis <buis@kde.org>
    44                  2005 Eric Seidel <eric@webkit.org>
     5                  2010 Zoltan Herczeg <zherczeg@webkit.org>
    56
    67    This library is free software; you can redistribute it and/or
     
    2324#define FloatPoint3D_h
    2425
     26#include "FloatPoint.h"
     27
    2528namespace WebCore {
    26 
    27 class FloatPoint;
    2829
    2930class FloatPoint3D {
    3031public:
    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    }
    3459
    3560    float x() const { return m_x; }
     
    6085}
    6186
     87inline 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
    6293} // namespace WebCore
    6394
  • trunk/WebCore/svg/SVGFESpotLightElement.cpp

    r51945 r59220  
    3838{
    3939    FloatPoint3D pos(x(), y(), z());
     40    FloatPoint3D direction(pointsAtX(), pointsAtY(), pointsAtZ());
    4041
    41     // convert lookAt to a direction
    42     FloatPoint3D direction(pointsAtX() - pos.x(),
    43                            pointsAtY() - pos.y(),
    44                            pointsAtZ() - pos.z());
    45 
    46     direction.normalize();
    4742    return SpotLightSource::create(pos, direction, specularExponent(), limitingConeAngle());
    4843}
  • trunk/WebCore/svg/graphics/filters/SVGDistantLightSource.h

    r51945 r59220  
    2929namespace WebCore {
    3030
    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         }
     31class DistantLightSource : public LightSource {
     32public:
     33    static PassRefPtr<DistantLightSource> create(float azimuth, float elevation)
     34    {
     35        return adoptRef(new DistantLightSource(azimuth, elevation));
     36    }
    3737
    38         float azimuth() const { return m_azimuth; }
    39         float elevation() const { return m_elevation; }
     38    float azimuth() const { return m_azimuth; }
     39    float elevation() const { return m_elevation; }
    4040
    41         virtual TextStream& externalRepresentation(TextStream&) const;
     41    virtual void initPaintingData(PaintingData&);
     42    virtual void updatePaintingData(PaintingData&, int x, int y, float z);
    4243
    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;
    5045
    51         float m_azimuth;
    52         float m_elevation;
    53     };
     46private:
     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};
    5457
    5558} // namespace WebCore
  • trunk/WebCore/svg/graphics/filters/SVGFEDiffuseLighting.cpp

    r59069 r59220  
    2323
    2424#if ENABLE(SVG) && ENABLE(FILTERS)
     25#include "SVGFEDiffuseLighting.h"
     26
    2527#include "SVGLightSource.h"
    26 #include "SVGFEDiffuseLighting.h"
    2728#include "SVGRenderTreeAsText.h"
    28 #include "Filter.h"
    2929
    3030namespace WebCore {
    3131
    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)
     32FEDiffuseLighting::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)
    4235{
    4336}
    4437
    4538PassRefPtr<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)
    4841{
    4942    return adoptRef(new FEDiffuseLighting(in, lightingColor, surfaceScale, diffuseConstant, kernelUnitLengthX, kernelUnitLengthY, lightSource));
     
    114107}
    115108
    116 void FEDiffuseLighting::apply(Filter*)
    117 {
    118 }
    119 
    120109void FEDiffuseLighting::dump()
    121110{
  • trunk/WebCore/svg/graphics/filters/SVGFEDiffuseLighting.h

    r59069 r59220  
    2424
    2525#if ENABLE(SVG) && ENABLE(FILTERS)
    26 #include "Color.h"
    27 #include "FilterEffect.h"
    28 #include "Filter.h"
     26#include "SVGFELighting.h"
    2927
    3028namespace WebCore {
    3129
    32     class LightSource;
     30class LightSource;
    3331
    34     class FEDiffuseLighting : public FilterEffect {
    35     public:
    36         static PassRefPtr<FEDiffuseLighting> create(FilterEffect*, const Color&, const float&, const float&,
    37                 const float&, const float&, PassRefPtr<LightSource>);
    38         virtual ~FEDiffuseLighting();
     32class FEDiffuseLighting : public FELighting {
     33public:
     34    static PassRefPtr<FEDiffuseLighting> create(FilterEffect*, const Color&, float, float,
     35        float, float, PassRefPtr<LightSource>);
     36    virtual ~FEDiffuseLighting();
    3937
    40         Color lightingColor() const;
    41         void setLightingColor(const Color&);
     38    Color lightingColor() const;
     39    void setLightingColor(const Color&);
    4240
    43         float surfaceScale() const;
    44         void setSurfaceScale(float);
     41    float surfaceScale() const;
     42    void setSurfaceScale(float);
    4543
    46         float diffuseConstant() const;
    47         void setDiffuseConstant(float);
     44    float diffuseConstant() const;
     45    void setDiffuseConstant(float);
    4846
    49         float kernelUnitLengthX() const;
    50         void setKernelUnitLengthX(float);
     47    float kernelUnitLengthX() const;
     48    void setKernelUnitLengthX(float);
    5149
    52         float kernelUnitLengthY() const;
    53         void setKernelUnitLengthY(float);
     50    float kernelUnitLengthY() const;
     51    void setKernelUnitLengthY(float);
    5452
    55         const LightSource* lightSource() const;
    56         void setLightSource(PassRefPtr<LightSource>);
     53    const LightSource* lightSource() const;
     54    void setLightSource(PassRefPtr<LightSource>);
    5755
    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;
    6658
    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     };
     59private:
     60    FEDiffuseLighting(FilterEffect*, const Color&, float, float,
     61        float, float, PassRefPtr<LightSource>);
     62};
    7563
    7664} // namespace WebCore
  • trunk/WebCore/svg/graphics/filters/SVGFESpecularLighting.cpp

    r59069 r59220  
    2424#if ENABLE(SVG) && ENABLE(FILTERS)
    2525#include "SVGFESpecularLighting.h"
     26
     27#include "SVGLightSource.h"
    2628#include "SVGRenderTreeAsText.h"
    27 #include "Filter.h"
    2829
    2930namespace WebCore {
    3031
    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)
     32FESpecularLighting::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)
    4336{
    4437}
    4538
    4639PassRefPtr<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)
    4942{
    5043    return adoptRef(new FESpecularLighting(in, lightingColor, surfaceScale, specularConstant, specularExponent,
     
    126119}
    127120
    128 void FESpecularLighting::apply(Filter*)
    129 {
    130 }
    131 
    132121void FESpecularLighting::dump()
    133122{
  • trunk/WebCore/svg/graphics/filters/SVGFESpecularLighting.h

    r59069 r59220  
    2424
    2525#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"
    3027
    3128namespace WebCore {
    3229
    33     class FESpecularLighting : public FilterEffect {
    34     public:
    35         static PassRefPtr<FESpecularLighting> create(FilterEffect*, const Color&, const float&, const float&,
    36             const float&, const float&, const float&, PassRefPtr<LightSource>);
    37         virtual ~FESpecularLighting();
     30class FESpecularLighting : public FELighting {
     31public:
     32    static PassRefPtr<FESpecularLighting> create(FilterEffect*, const Color&, float, float,
     33        float, float, float, PassRefPtr<LightSource>);
     34    virtual ~FESpecularLighting();
    3835
    39         Color lightingColor() const;
    40         void setLightingColor(const Color&);
     36    Color lightingColor() const;
     37    void setLightingColor(const Color&);
    4138
    42         float surfaceScale() const;
    43         void setSurfaceScale(float);
     39    float surfaceScale() const;
     40    void setSurfaceScale(float);
    4441
    45         float specularConstant() const;
    46         void setSpecularConstant(float);
     42    float specularConstant() const;
     43    void setSpecularConstant(float);
    4744
    48         float specularExponent() const;
    49         void setSpecularExponent(float);
     45    float specularExponent() const;
     46    void setSpecularExponent(float);
    5047
    51         float kernelUnitLengthX() const;
    52         void setKernelUnitLengthX(float);
     48    float kernelUnitLengthX() const;
     49    void setKernelUnitLengthX(float);
    5350
    54         float kernelUnitLengthY() const;
    55         void setKernelUnitLengthY(float);
     51    float kernelUnitLengthY() const;
     52    void setKernelUnitLengthY(float);
    5653
    57         const LightSource* lightSource() const;
    58         void setLightSource(PassRefPtr<LightSource>);
     54    const LightSource* lightSource() const;
     55    void setLightSource(PassRefPtr<LightSource>);
    5956
    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;
    6459
    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     };
     60private:
     61    FESpecularLighting(FilterEffect*, const Color&, float, float, float,
     62        float, float, PassRefPtr<LightSource>);
     63};
    7864
    7965} // namespace WebCore
  • trunk/WebCore/svg/graphics/filters/SVGLightSource.cpp

    r44253 r59220  
    33                  2004, 2005 Rob Buis <buis@kde.org>
    44                  2005 Eric Seidel <eric@webkit.org>
     5                  2010 Zoltan Herczeg <zherczeg@webkit.org>
    56
    67    This library is free software; you can redistribute it and/or
     
    2324
    2425#if ENABLE(SVG) && ENABLE(FILTERS)
     26#include "SVGLightSource.h"
     27
     28#include "SVGDistantLightSource.h"
    2529#include "SVGPointLightSource.h"
    2630#include "SVGRenderTreeAsText.h"
    2731#include "SVGSpotLightSource.h"
    28 #include "SVGDistantLightSource.h"
     32#include <wtf/MathExtras.h>
    2933
    3034namespace WebCore {
     35
     36void PointLightSource::initPaintingData(PaintingData&)
     37{
     38}
     39
     40void 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
     48void 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
     81void 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
     122void 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
     131void DistantLightSource::updatePaintingData(PaintingData&, int, int, float)
     132{
     133}
    31134
    32135static TextStream& operator<<(TextStream& ts, const FloatPoint3D& p)
  • trunk/WebCore/svg/graphics/filters/SVGLightSource.h

    r51945 r59220  
    44                  2004, 2005 Rob Buis <buis@kde.org>
    55                  2005 Eric Seidel <eric@webkit.org>
     6                  2010 Zoltan Herczeg <zherczeg@webkit.org>
    67
    78    This library is free software; you can redistribute it and/or
     
    2526
    2627#if ENABLE(SVG) && ENABLE(FILTERS)
     28#include "FloatPoint3D.h"
    2729#include <wtf/PassRefPtr.h>
    2830#include <wtf/RefCounted.h>
     
    3032namespace WebCore {
    3133
    32     enum LightType {
    33         LS_DISTANT,
    34         LS_POINT,
    35         LS_SPOT
     34enum LightType {
     35    LS_DISTANT,
     36    LS_POINT,
     37    LS_SPOT
     38};
     39
     40class TextStream;
     41
     42class LightSource : public RefCounted<LightSource> {
     43public:
     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;
    3660    };
    3761
    38     class TextStream;
     62    LightSource(LightType type)
     63        : m_type(type)
     64    { }
    3965
    40     class LightSource : public RefCounted<LightSource> {
    41     public:
    42         LightSource(LightType type)
    43             : m_type(type)
    44         { }
     66    virtual ~LightSource() { }
    4567
    46         virtual ~LightSource() { }
     68    LightType type() const { return m_type; }
     69    virtual TextStream& externalRepresentation(TextStream&) const = 0;
    4770
    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;
    5075
    51     private:
    52         LightType m_type;
    53     };
     76private:
     77    LightType m_type;
     78};
    5479
    5580} // namespace WebCore
  • trunk/WebCore/svg/graphics/filters/SVGPointLightSource.h

    r51945 r59220  
    2525
    2626#if ENABLE(SVG) && ENABLE(FILTERS)
    27 #include "FloatPoint3D.h"
    2827#include "SVGLightSource.h"
    2928
    3029namespace WebCore {
    3130
    32     class PointLightSource : public LightSource {
    33     public:
    34         static PassRefPtr<PointLightSource> create(const FloatPoint3D& position)
    35         {
    36             return adoptRef(new PointLightSource(position));
    37         }
     31class PointLightSource : public LightSource {
     32public:
     33    static PassRefPtr<PointLightSource> create(const FloatPoint3D& position)
     34    {
     35        return adoptRef(new PointLightSource(position));
     36    }
    3837
    39         const FloatPoint3D& position() const { return m_position; }
     38    const FloatPoint3D& position() const { return m_position; }
    4039
    41         virtual TextStream& externalRepresentation(TextStream&) const;
     40    virtual void initPaintingData(PaintingData&);
     41    virtual void updatePaintingData(PaintingData&, int x, int y, float z);
    4242
    43     private:
    44         PointLightSource(const FloatPoint3D& position)
    45             : LightSource(LS_POINT)
    46             , m_position(position)
    47         {
    48         }
     43    virtual TextStream& externalRepresentation(TextStream&) const;
    4944
    50         FloatPoint3D m_position;
    51     };
     45private:
     46    PointLightSource(const FloatPoint3D& position)
     47        : LightSource(LS_POINT)
     48        , m_position(position)
     49    {
     50    }
     51
     52    FloatPoint3D m_position;
     53};
    5254
    5355} // namespace WebCore
  • trunk/WebCore/svg/graphics/filters/SVGSpotLightSource.h

    r51945 r59220  
    2525
    2626#if ENABLE(SVG) && ENABLE(FILTERS)
    27 #include "FloatPoint3D.h"
    2827#include "SVGLightSource.h"
    2928
    3029namespace WebCore {
    3130
    32     class SpotLightSource : public LightSource {
    33     public:
    34         static PassRefPtr<SpotLightSource> create(const FloatPoint3D& position, const FloatPoint3D& direction,
    35                                                   float specularExponent, float limitingConeAngle)
    36         {
    37             return adoptRef(new SpotLightSource(position, direction, specularExponent, limitingConeAngle));
    38         }
     31class SpotLightSource : public LightSource {
     32public:
     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    }
    3938
    40         const FloatPoint3D& position() const { return m_position; }
    41         const FloatPoint3D& direction() const { return m_direction; }
     39    const FloatPoint3D& position() const { return m_position; }
     40    const FloatPoint3D& direction() const { return m_direction; }
    4241
    43         float specularExponent() const { return m_specularExponent; }
    44         float limitingConeAngle() const { return m_limitingConeAngle; }
     42    float specularExponent() const { return m_specularExponent; }
     43    float limitingConeAngle() const { return m_limitingConeAngle; }
    4544
    46         virtual TextStream& externalRepresentation(TextStream&) const;
     45    virtual void initPaintingData(PaintingData&);
     46    virtual void updatePaintingData(PaintingData&, int x, int y, float z);
    4747
    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;
    5849
    59         FloatPoint3D m_position;
    60         FloatPoint3D m_direction;
     50private:
     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    }
    6160
    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};
    6567
    6668} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.