root/trunk/BAL/Graphics/WebCore/WK/BCGradientWK.h

Revision 1387, 5.1 kB (checked in by gpenin, 7 months ago)

merge with webkit revision 55226

Line 
1 /*
2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3  * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4  * Copyright (C) 2008 Torch Mobile, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #ifndef Gradient_h
29 #define Gradient_h
30
31 #include "AffineTransform.h"
32 #include "FloatPoint.h"
33 #include "Generator.h"
34 #include "GraphicsTypes.h"
35 #include <wtf/PassRefPtr.h>
36 #include <wtf/Vector.h>
37
38 #if PLATFORM(CG)
39
40 #define USE_CG_SHADING defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD)
41
42 #if USE_CG_SHADING
43 typedef struct CGShading* CGShadingRef;
44 typedef CGShadingRef PlatformGradient;
45 #else
46 typedef struct CGGradient* CGGradientRef;
47 typedef CGGradientRef PlatformGradient;
48 #endif
49
50 #elif PLATFORM(QT)
51 QT_BEGIN_NAMESPACE
52 class QGradient;
53 QT_END_NAMESPACE
54 typedef QGradient* PlatformGradient;
55 #elif PLATFORM(CAIRO)
56 typedef struct _cairo_pattern cairo_pattern_t;
57 typedef cairo_pattern_t* PlatformGradient;
58 #elif PLATFORM(SKIA)
59 class SkShader;
60 typedef class SkShader* PlatformGradient;
61 typedef class SkShader* PlatformPattern;
62 #elif PLATFORM(HAIKU)
63 class BGradient;
64 typedef BGradient* PlatformGradient;
65 #else
66 typedef void* PlatformGradient;
67 #endif
68
69 namespace WebCore {
70
71     class Color;
72
73     class Gradient : public Generator {
74     public:
75         static PassRefPtr<Gradient> create(const FloatPoint& p0, const FloatPoint& p1)
76         {
77             return adoptRef(new Gradient(p0, p1));
78         }
79         static PassRefPtr<Gradient> create(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1)
80         {
81             return adoptRef(new Gradient(p0, r0, p1, r1));
82         }
83         virtual ~Gradient();
84
85         void addColorStop(float, const Color&);
86
87         void getColor(float value, float* r, float* g, float* b, float* a) const;
88
89 #if OS(WINCE) && !PLATFORM(QT)
90         const FloatPoint& p0() const { return m_p0; }
91         const FloatPoint& p1() const { return m_p1; }
92         float r0() const { return m_r0; }
93         float r1() const { return m_r1; }
94         bool isRadial() const { return m_radial; }
95         struct ColorStop;
96         const Vector<ColorStop>& getStops() const;
97 #else
98         PlatformGradient platformGradient();
99 #endif
100         struct ColorStop {
101             float stop;
102             float red;
103             float green;
104             float blue;
105             float alpha;
106
107             ColorStop() : stop(0), red(0), green(0), blue(0), alpha(0) { }
108             ColorStop(float s, float r, float g, float b, float a) : stop(s), red(r), green(g), blue(b), alpha(a) { }
109         };
110
111         void setStopsSorted(bool s) { m_stopsSorted = s; }
112        
113         void setSpreadMethod(GradientSpreadMethod);
114         GradientSpreadMethod spreadMethod() { return m_spreadMethod; }
115         void setGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation);
116         // Qt and CG transform the gradient at draw time
117         AffineTransform gradientSpaceTransform() { return m_gradientSpaceTransformation; }
118
119         virtual void fill(GraphicsContext*, const FloatRect&);
120         virtual void adjustParametersForTiledDrawing(IntSize& size, FloatRect& srcRect);
121
122         void setPlatformGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation);
123
124 #if PLATFORM(CG)
125         void paint(GraphicsContext*);
126 #endif
127     private:
128         Gradient(const FloatPoint& p0, const FloatPoint& p1);
129         Gradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1);
130
131         void platformInit() { m_gradient = 0; }
132         void platformDestroy();
133
134         int findStop(float value) const;
135         void sortStopsIfNecessary();
136
137         bool m_radial;
138         FloatPoint m_p0;
139         FloatPoint m_p1;
140         float m_r0;
141         float m_r1;
142         mutable Vector<ColorStop> m_stops;
143         mutable bool m_stopsSorted;
144         mutable int m_lastStop;
145         GradientSpreadMethod m_spreadMethod;
146         AffineTransform m_gradientSpaceTransformation;
147
148         PlatformGradient m_gradient;
149     };
150
151 } //namespace
152
153 #endif
154
Note: See TracBrowser for help on using the browser.