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