2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef SVGPaintServerGradient_h
27 #define SVGPaintServerGradient_h
31 #include "AffineTransform.h"
33 #include "SVGPaintServer.h"
35 #include <wtf/RefCounted.h>
36 #include <wtf/RefPtr.h>
48 class SVGGradientElement
;
50 // FIXME: Remove the spread method enum in SVGGradientElement
51 enum SVGGradientSpreadMethod
{
53 SPREADMETHOD_REFLECT
= 2,
54 SPREADMETHOD_REPEAT
= 3
58 typedef std::pair
<CGFloat
, Color
> SVGGradientStop
;
60 typedef std::pair
<float, Color
> SVGGradientStop
;
64 class SVGPaintServerGradient
: public SVGPaintServer
{
66 virtual ~SVGPaintServerGradient();
68 const Vector
<SVGGradientStop
>& gradientStops() const;
69 void setGradientStops(const Vector
<SVGGradientStop
>&);
71 SVGGradientSpreadMethod
spreadMethod() const;
72 void setGradientSpreadMethod(const SVGGradientSpreadMethod
&);
74 // Gradient start and end points are percentages when used in boundingBox mode.
75 // For instance start point with value (0,0) is top-left and end point with
76 // value (100, 100) is bottom-right. BoundingBox mode is enabled by default.
77 bool boundingBoxMode() const;
78 void setBoundingBoxMode(bool mode
= true);
80 AffineTransform
gradientTransform() const;
81 void setGradientTransform(const AffineTransform
&);
83 /*virtual TextStream& externalRepresentation(TextStream&) const;*/
85 virtual bool setup(QPainter
* painter
, QPainterPath
* path
, const RenderObject
*, SVGPaintTargetType
, bool isPaintingText
) const;
87 virtual void teardown(GraphicsContext
*&, const RenderObject
*, SVGPaintTargetType
, bool isPaintingText
) const;
88 virtual void renderPath(GraphicsContext
*&, const RenderObject
*, SVGPaintTargetType
) const;
90 virtual void invalidate();
93 void updateQuartzGradientStopsCache(const Vector
<SVGGradientStop
>&);
94 void updateQuartzGradientCache(const SVGPaintServerGradient
*);
95 void handleBoundingBoxModeAndGradientTransformation(GraphicsContext
*, const FloatRect
& targetRect
) const;
100 void fillColorArray(QGradient
&, const Vector
<SVGGradientStop
>&, float opacity
) const;
101 virtual QGradient
setupGradient(QPainter
* painter
, QPainterPath
* painterPath
, const RenderObject
*) const = 0;
105 SVGPaintServerGradient(const SVGGradientElement
* owner
);
108 Vector
<SVGGradientStop
> m_stops
;
109 SVGGradientSpreadMethod m_spreadMethod
;
110 bool m_boundingBoxMode
;
111 AffineTransform m_gradientTransform
;
112 const SVGGradientElement
* m_ownerElement
;
117 CGFloat colorArray
[4];
119 CGFloat previousDeltaInverse
;
120 } QuartzGradientStop
;
122 struct SharedStopCache
: public RefCounted
<SharedStopCache
> {
124 static PassRefPtr
<SharedStopCache
> create() { return adoptRef(new SharedStopCache
); }
126 Vector
<QuartzGradientStop
> m_stops
;
129 SharedStopCache() { }
132 RefPtr
<SharedStopCache
> m_stopsCache
;
134 CGShadingRef m_shadingCache
;
135 mutable GraphicsContext
* m_savedContext
;
136 mutable ImageBuffer
* m_imageBuffer
;
140 inline SVGGradientStop
makeGradientStop(float offset
, const Color
& color
)
142 return std::make_pair(offset
, color
);
145 } // namespace WebCore
149 #endif // SVGPaintServerGradient_h