1 /*
2  * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef PainterOpenVG_h
21 #define PainterOpenVG_h
22 
23 #include "Color.h"
24 #include "GraphicsContext.h"
25 
26 #include <openvg.h>
27 
28 #include <wtf/Noncopyable.h>
29 #include <wtf/Vector.h>
30 
31 namespace WebCore {
32 
33 class AffineTransform;
34 class FloatPoint;
35 class FloatRect;
36 class IntRect;
37 class IntSize;
38 class Path;
39 class SurfaceOpenVG;
40 class TiledImageOpenVG;
41 
42 struct PlatformPainterState;
43 
44 class PainterOpenVG {
45     WTF_MAKE_NONCOPYABLE(PainterOpenVG);
46 public:
47     friend class SurfaceOpenVG;
48     friend struct PlatformPainterState;
49 
50     enum SaveMode {
51         CreateNewState,
52         KeepCurrentState,
53         CreateNewStateWithPaintStateOnly // internal usage only, do not use outside PainterOpenVG
54     };
55     enum ClipOperation {
56         IntersectClip = VG_INTERSECT_MASK,
57         SubtractClip = VG_SUBTRACT_MASK
58     };
59 
60     PainterOpenVG();
61     PainterOpenVG(SurfaceOpenVG*);
62     ~PainterOpenVG();
63 
64     void begin(SurfaceOpenVG*);
65     void end();
66 
67     AffineTransform transformation() const;
68     void setTransformation(const AffineTransform&);
69     void concatTransformation(const AffineTransform&);
70 
71     static void transformPath(VGPath dst, VGPath src, const AffineTransform&);
72 
73     CompositeOperator compositeOperation() const;
74     void setCompositeOperation(CompositeOperator);
75     float opacity() const;
76     void setOpacity(float);
77 
78     float strokeThickness() const;
79     void setStrokeThickness(float);
80     StrokeStyle strokeStyle() const;
81     void setStrokeStyle(StrokeStyle);
82 
83     void setLineDash(const DashArray&, float dashOffset);
84     void setLineCap(LineCap);
85     void setLineJoin(LineJoin);
86     void setMiterLimit(float);
87 
88     Color strokeColor() const;
89     void setStrokeColor(const Color&);
90 
91     Color fillColor() const;
92     void setFillColor(const Color&);
93 
94     int textDrawingMode() const;
95     void setTextDrawingMode(int mode);
96 
97     bool antialiasingEnabled() const;
98     void setAntialiasingEnabled(bool);
99 
100     void drawRect(const FloatRect&, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
101     void drawRoundedRect(const FloatRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
102     void drawLine(const IntPoint& from, const IntPoint& to);
103     void drawArc(const IntRect& ellipseBounds, int startAngle, int angleSpan, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
104     void drawEllipse(const IntRect& bounds, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
105     void drawPolygon(size_t numPoints, const FloatPoint* points, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
106     void drawImage(TiledImageOpenVG*, const FloatRect& dst, const FloatRect& src);
107 #ifdef OPENVG_VERSION_1_1
108     void drawText(VGFont, Vector<VGuint>& characters, VGfloat* adjustmentsX, VGfloat* adjustmentsY, const FloatPoint&);
109 #endif
110 
111     void scale(const FloatSize& scaleFactors);
112     void rotate(float radians);
113     void translate(float dx, float dy);
114 
115     void drawPath(const Path&, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH), WindRule fillRule = RULE_NONZERO);
116 
117     void intersectClipRect(const FloatRect&);
118     void clipPath(const Path&, PainterOpenVG::ClipOperation, WindRule clipRule = RULE_NONZERO);
119 
120     TiledImageOpenVG* asNewNativeImage(const IntRect& src, VGImageFormat);
121 
122     void save(PainterOpenVG::SaveMode saveMode = CreateNewState);
123     void restore();
124 
surface()125     SurfaceOpenVG* surface() { return m_surface; }
126     void blitToSurface();
127 
128 private:
129     void destroyPainterStates();
130     void applyState();
131 
132     void intersectScissorRect(const FloatRect&);
133 
134 private:
135     Vector<PlatformPainterState*> m_stateStack;
136     PlatformPainterState* m_state;
137     SurfaceOpenVG* m_surface;
138 };
139 
140 }
141 
142 #endif
143