1 :
2 : #include "gfxRect.h"
3 : #include "gfxMatrix.h"
4 : #include "gfxContext.h"
5 : #include "mozilla/gfx/Rect.h"
6 : #include "mozilla/gfx/2D.h"
7 :
8 : namespace mozilla {
9 : namespace gfx {
10 : class DrawTarget;
11 : class SourceSurface;
12 : class ScaledFont;
13 : }
14 : }
15 :
16 : namespace mozilla {
17 : namespace gfx {
18 :
19 0 : inline Rect ToRect(const gfxRect &aRect)
20 : {
21 : return Rect(Float(aRect.x), Float(aRect.y),
22 0 : Float(aRect.width), Float(aRect.height));
23 : }
24 :
25 : inline Color ToColor(const gfxRGBA &aRGBA)
26 : {
27 : return Color(Float(aRGBA.r), Float(aRGBA.g),
28 : Float(aRGBA.b), Float(aRGBA.a));
29 : }
30 :
31 0 : inline Matrix ToMatrix(const gfxMatrix &aMatrix)
32 : {
33 : return Matrix(Float(aMatrix.xx), Float(aMatrix.yx), Float(aMatrix.xy),
34 0 : Float(aMatrix.yy), Float(aMatrix.x0), Float(aMatrix.y0));
35 : }
36 :
37 : inline Point ToPoint(const gfxPoint &aPoint)
38 : {
39 : return Point(Float(aPoint.x), Float(aPoint.y));
40 : }
41 :
42 : inline Size ToSize(const gfxSize &aSize)
43 : {
44 : return Size(Float(aSize.width), Float(aSize.height));
45 : }
46 :
47 : inline Filter ToFilter(gfxPattern::GraphicsFilter aFilter)
48 : {
49 : switch (aFilter) {
50 : case gfxPattern::FILTER_NEAREST:
51 : return FILTER_POINT;
52 : default:
53 : return FILTER_LINEAR;
54 : }
55 : }
56 :
57 : inline gfxPattern::GraphicsFilter ThebesFilter(Filter aFilter)
58 : {
59 : switch (aFilter) {
60 : case FILTER_POINT:
61 : return gfxPattern::FILTER_NEAREST;
62 : default:
63 : return gfxPattern::FILTER_BEST;
64 : }
65 : }
66 :
67 : inline ExtendMode ToExtendMode(gfxPattern::GraphicsExtend aExtend)
68 : {
69 : switch (aExtend) {
70 : case gfxPattern::EXTEND_REPEAT:
71 : return EXTEND_REPEAT;
72 : case gfxPattern::EXTEND_REFLECT:
73 : return EXTEND_REFLECT;
74 : default:
75 : return EXTEND_CLAMP;
76 : }
77 : }
78 :
79 : inline gfxPattern::GraphicsExtend ThebesExtend(ExtendMode aExtend)
80 : {
81 : switch (aExtend) {
82 : case EXTEND_REPEAT:
83 : return gfxPattern::EXTEND_REPEAT;
84 : case EXTEND_REFLECT:
85 : return gfxPattern::EXTEND_REFLECT;
86 : default:
87 : return gfxPattern::EXTEND_PAD;
88 : }
89 : }
90 :
91 : inline gfxPoint ThebesPoint(const Point &aPoint)
92 : {
93 : return gfxPoint(aPoint.x, aPoint.y);
94 : }
95 :
96 : inline gfxSize ThebesSize(const Size &aSize)
97 : {
98 : return gfxSize(aSize.width, aSize.height);
99 : }
100 :
101 : inline gfxIntSize ThebesIntSize(const IntSize &aSize)
102 : {
103 : return gfxIntSize(aSize.width, aSize.height);
104 : }
105 :
106 0 : inline gfxRect ThebesRect(const Rect &aRect)
107 : {
108 0 : return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
109 : }
110 :
111 : inline gfxRGBA ThebesRGBA(const Color &aColor)
112 : {
113 : return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a);
114 : }
115 :
116 : inline gfxContext::GraphicsLineCap ThebesLineCap(CapStyle aStyle)
117 : {
118 : switch (aStyle) {
119 : case CAP_BUTT:
120 : return gfxContext::LINE_CAP_BUTT;
121 : case CAP_ROUND:
122 : return gfxContext::LINE_CAP_ROUND;
123 : case CAP_SQUARE:
124 : return gfxContext::LINE_CAP_SQUARE;
125 : }
126 : MOZ_NOT_REACHED("Incomplete switch");
127 : }
128 :
129 : inline CapStyle ToCapStyle(gfxContext::GraphicsLineCap aStyle)
130 : {
131 : switch (aStyle) {
132 : case gfxContext::LINE_CAP_BUTT:
133 : return CAP_BUTT;
134 : case gfxContext::LINE_CAP_ROUND:
135 : return CAP_ROUND;
136 : case gfxContext::LINE_CAP_SQUARE:
137 : return CAP_SQUARE;
138 : }
139 : MOZ_NOT_REACHED("Incomplete switch");
140 : }
141 :
142 : inline gfxContext::GraphicsLineJoin ThebesLineJoin(JoinStyle aStyle)
143 : {
144 : switch (aStyle) {
145 : case JOIN_MITER:
146 : return gfxContext::LINE_JOIN_MITER;
147 : case JOIN_BEVEL:
148 : return gfxContext::LINE_JOIN_BEVEL;
149 : case JOIN_ROUND:
150 : return gfxContext::LINE_JOIN_ROUND;
151 : default:
152 : return gfxContext::LINE_JOIN_MITER;
153 : }
154 : }
155 :
156 : inline JoinStyle ToJoinStyle(gfxContext::GraphicsLineJoin aStyle)
157 : {
158 : switch (aStyle) {
159 : case gfxContext::LINE_JOIN_MITER:
160 : return JOIN_MITER;
161 : case gfxContext::LINE_JOIN_BEVEL:
162 : return JOIN_BEVEL;
163 : case gfxContext::LINE_JOIN_ROUND:
164 : return JOIN_ROUND;
165 : }
166 : MOZ_NOT_REACHED("Incomplete switch");
167 : }
168 :
169 : inline gfxMatrix ThebesMatrix(const Matrix &aMatrix)
170 : {
171 : return gfxMatrix(aMatrix._11, aMatrix._12, aMatrix._21,
172 : aMatrix._22, aMatrix._31, aMatrix._32);
173 : }
174 :
175 : inline gfxASurface::gfxContentType ContentForFormat(const SurfaceFormat &aFormat)
176 : {
177 : switch (aFormat) {
178 : case FORMAT_B8G8R8X8:
179 : return gfxASurface::CONTENT_COLOR;
180 : case FORMAT_A8:
181 : return gfxASurface::CONTENT_ALPHA;
182 : case FORMAT_B8G8R8A8:
183 : default:
184 : return gfxASurface::CONTENT_COLOR_ALPHA;
185 : }
186 : }
187 :
188 : inline SurfaceFormat FormatForContent(gfxASurface::gfxContentType aContent)
189 : {
190 : switch (aContent) {
191 : case gfxASurface::CONTENT_COLOR:
192 : return FORMAT_B8G8R8X8;
193 : case gfxASurface::CONTENT_ALPHA:
194 : return FORMAT_A8;
195 : default:
196 : return FORMAT_B8G8R8A8;
197 : }
198 : }
199 :
200 : inline CompositionOp CompositionOpForOp(gfxContext::GraphicsOperator aOp)
201 : {
202 : switch (aOp) {
203 : case gfxContext::OPERATOR_ADD:
204 : return OP_ADD;
205 : case gfxContext::OPERATOR_ATOP:
206 : return OP_ATOP;
207 : case gfxContext::OPERATOR_IN:
208 : return OP_IN;
209 : case gfxContext::OPERATOR_OUT:
210 : return OP_OUT;
211 : case gfxContext::OPERATOR_SOURCE:
212 : return OP_SOURCE;
213 : case gfxContext::OPERATOR_DEST_IN:
214 : return OP_DEST_IN;
215 : case gfxContext::OPERATOR_DEST_OUT:
216 : return OP_DEST_OUT;
217 : case gfxContext::OPERATOR_DEST_ATOP:
218 : return OP_DEST_ATOP;
219 : case gfxContext::OPERATOR_XOR:
220 : return OP_XOR;
221 : default:
222 : return OP_OVER;
223 : }
224 : }
225 :
226 : inline gfxContext::GraphicsOperator ThebesOp(CompositionOp aOp)
227 : {
228 : switch (aOp) {
229 : case OP_ADD:
230 : return gfxContext::OPERATOR_ADD;
231 : case OP_ATOP:
232 : return gfxContext::OPERATOR_ATOP;
233 : case OP_IN:
234 : return gfxContext::OPERATOR_IN;
235 : case OP_OUT:
236 : return gfxContext::OPERATOR_OUT;
237 : case OP_SOURCE:
238 : return gfxContext::OPERATOR_SOURCE;
239 : case OP_DEST_IN:
240 : return gfxContext::OPERATOR_DEST_IN;
241 : case OP_DEST_OUT:
242 : return gfxContext::OPERATOR_DEST_OUT;
243 : case OP_DEST_ATOP:
244 : return gfxContext::OPERATOR_DEST_ATOP;
245 : case OP_XOR:
246 : return gfxContext::OPERATOR_XOR;
247 : default:
248 : return gfxContext::OPERATOR_OVER;
249 : }
250 : }
251 :
252 : }
253 : }
|