KHTML
SVGPaintServerGradient.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef SVGPaintServerGradient_h
00027 #define SVGPaintServerGradient_h
00028
00029 #if ENABLE(SVG)
00030
00031 #include "AffineTransform.h"
00032 #include "Color.h"
00033 #include "SVGPaintServer.h"
00034
00035 #include <wtf/RefCounted.h>
00036 #include <wtf/RefPtr.h>
00037
00038 #if PLATFORM(QT)
00039 #include <qglobal.h>
00040 QT_BEGIN_NAMESPACE
00041 class QGradient;
00042 QT_END_NAMESPACE
00043 #endif
00044
00045 namespace WebCore {
00046
00047 class ImageBuffer;
00048 class SVGGradientElement;
00049
00050
00051 enum SVGGradientSpreadMethod {
00052 SPREADMETHOD_PAD = 1,
00053 SPREADMETHOD_REFLECT = 2,
00054 SPREADMETHOD_REPEAT = 3
00055 };
00056
00057 #if PLATFORM(CG)
00058 typedef std::pair<CGFloat, Color> SVGGradientStop;
00059 #else
00060 typedef std::pair<float, Color> SVGGradientStop;
00061 #endif
00062
00063
00064 class SVGPaintServerGradient : public SVGPaintServer {
00065 public:
00066 virtual ~SVGPaintServerGradient();
00067
00068 const Vector<SVGGradientStop>& gradientStops() const;
00069 void setGradientStops(const Vector<SVGGradientStop>&);
00070
00071 SVGGradientSpreadMethod spreadMethod() const;
00072 void setGradientSpreadMethod(const SVGGradientSpreadMethod&);
00073
00074
00075
00076
00077 bool boundingBoxMode() const;
00078 void setBoundingBoxMode(bool mode = true);
00079
00080 AffineTransform gradientTransform() const;
00081 void setGradientTransform(const AffineTransform&);
00082
00083
00084
00085 virtual bool setup(QPainter* painter, QPainterPath* path, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
00086 #if PLATFORM(CG)
00087 virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
00088 virtual void renderPath(GraphicsContext*&, const RenderObject*, SVGPaintTargetType) const;
00089
00090 virtual void invalidate();
00091
00092
00093 void updateQuartzGradientStopsCache(const Vector<SVGGradientStop>&);
00094 void updateQuartzGradientCache(const SVGPaintServerGradient*);
00095 void handleBoundingBoxModeAndGradientTransformation(GraphicsContext*, const FloatRect& targetRect) const;
00096 #endif
00097
00098 #if PLATFORM(QT)
00099 protected:
00100 void fillColorArray(QGradient&, const Vector<SVGGradientStop>&, float opacity) const;
00101 virtual QGradient setupGradient(QPainter* painter, QPainterPath* painterPath, const RenderObject*) const = 0;
00102 #endif
00103
00104 protected:
00105 SVGPaintServerGradient(const SVGGradientElement* owner);
00106
00107 private:
00108 Vector<SVGGradientStop> m_stops;
00109 SVGGradientSpreadMethod m_spreadMethod;
00110 bool m_boundingBoxMode;
00111 AffineTransform m_gradientTransform;
00112 const SVGGradientElement* m_ownerElement;
00113
00114 #if PLATFORM(CG)
00115 public:
00116 typedef struct {
00117 CGFloat colorArray[4];
00118 CGFloat offset;
00119 CGFloat previousDeltaInverse;
00120 } QuartzGradientStop;
00121
00122 struct SharedStopCache : public RefCounted<SharedStopCache> {
00123 public:
00124 static PassRefPtr<SharedStopCache> create() { return adoptRef(new SharedStopCache); }
00125
00126 Vector<QuartzGradientStop> m_stops;
00127
00128 private:
00129 SharedStopCache() { }
00130 };
00131
00132 RefPtr<SharedStopCache> m_stopsCache;
00133
00134 CGShadingRef m_shadingCache;
00135 mutable GraphicsContext* m_savedContext;
00136 mutable ImageBuffer* m_imageBuffer;
00137 #endif
00138 };
00139
00140 inline SVGGradientStop makeGradientStop(float offset, const Color& color)
00141 {
00142 return std::make_pair(offset, color);
00143 }
00144
00145 }
00146
00147 #endif
00148
00149 #endif // SVGPaintServerGradient_h