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 #include "core/platform/graphics/FloatPoint3D.h"
     28 #include "wtf/PassRefPtr.h"
     29 #include "wtf/RefCounted.h"
     30 
     31 namespace WebCore {
     32 
     33 enum LightType {
     34     LS_DISTANT,
     35     LS_POINT,
     36     LS_SPOT
     37 };
     38 
     39 class TextStream;
     40 
     41 class LightSource : public RefCounted<LightSource> {
     42 public:
     43 
     44     // Light vectors must be calculated for every pixel during
     45     // painting. It is expensive to pass all these arguments to
     46     // a frequently called function, especially because not all
     47     // light sources require all of them. Instead, we just pass
     48     // a reference to the following structure
     49     struct PaintingData {
     50         // SVGFELighting also use them
     51         FloatPoint3D lightVector;
     52         FloatPoint3D colorVector;
     53         float lightVectorLength;
     54         // Private members
     55         FloatPoint3D directionVector;
     56         FloatPoint3D privateColorVector;
     57         float coneCutOffLimit;
     58         float coneFullLight;
     59         int specularExponent;
     60     };
     61 
     62     LightSource(LightType type)
     63         : m_type(type)
     64     { }
     65 
     66     virtual ~LightSource() { }
     67 
     68     LightType type() const { return m_type; }
     69     virtual TextStream& externalRepresentation(TextStream&) const = 0;
     70 
     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;
     75 
     76     virtual bool setAzimuth(float) { return false; }
     77     virtual bool setElevation(float) { return false; }
     78     virtual bool setX(float) { return false; }
     79     virtual bool setY(float) { return false; }
     80     virtual bool setZ(float) { return false; }
     81     virtual bool setPointsAtX(float) { return false; }
     82     virtual bool setPointsAtY(float) { return false; }
     83     virtual bool setPointsAtZ(float) { return false; }
     84     virtual bool setSpecularExponent(float) { return false; }
     85     virtual bool setLimitingConeAngle(float) { return false; }
     86 
     87 private:
     88     LightType m_type;
     89 };
     90 
     91 } // namespace WebCore
     92 
     93 #endif // LightSource_h
     94