Home | History | Annotate | Download | only in filters
      1 /*
      2  * Copyright (C) 2008 Alex Mathews <possessedpenguinbob (at) gmail.com>
      3  * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      4  * Copyright (C) 2004, 2005 Rob Buis <buis (at) kde.org>
      5  * Copyright (C) 2005 Eric Seidel <eric (at) webkit.org>
      6  * Copyright (C) 2010 Zoltan Herczeg <zherczeg (at) webkit.org>
      7  *
      8  * This library is free software; you can redistribute it and/or
      9  * modify it under the terms of the GNU Library General Public
     10  * License as published by the Free Software Foundation; either
     11  * version 2 of the License, or (at your option) any later version.
     12  *
     13  * This library is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16  * Library General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU Library General Public License
     19  * along with this library; see the file COPYING.LIB.  If not, write to
     20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     21  * Boston, MA 02110-1301, USA.
     22  */
     23 
     24 #ifndef LightSource_h
     25 #define LightSource_h
     26 
     27 #if ENABLE(FILTERS)
     28 #include "FloatPoint3D.h"
     29 #include <wtf/PassRefPtr.h>
     30 #include <wtf/RefCounted.h>
     31 
     32 namespace WebCore {
     33 
     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         float lightVectorLength;
     55         // Private members
     56         FloatPoint3D directionVector;
     57         FloatPoint3D privateColorVector;
     58         float coneCutOffLimit;
     59         float coneFullLight;
     60         int specularExponent;
     61     };
     62 
     63     LightSource(LightType type)
     64         : m_type(type)
     65     { }
     66 
     67     virtual ~LightSource() { }
     68 
     69     LightType type() const { return m_type; }
     70     virtual TextStream& externalRepresentation(TextStream&) const = 0;
     71 
     72     virtual void initPaintingData(PaintingData&) = 0;
     73     // z is a float number, since it is the alpha value scaled by a user
     74     // specified "surfaceScale" constant, which type is <number> in the SVG standard
     75     virtual void updatePaintingData(PaintingData&, int x, int y, float z) = 0;
     76 
     77     bool setAzimuth(float);
     78     bool setElevation(float);
     79     bool setX(float);
     80     bool setY(float);
     81     bool setZ(float);
     82     bool setPointsAtX(float);
     83     bool setPointsAtY(float);
     84     bool setPointsAtZ(float);
     85     bool setSpecularExponent(float);
     86     bool setLimitingConeAngle(float);
     87 
     88 private:
     89     LightType m_type;
     90 };
     91 
     92 } // namespace WebCore
     93 
     94 #endif // ENABLE(FILTERS)
     95 
     96 #endif // LightSource_h
     97