|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef GFX_2D_GLUE_H |
|
6 #define GFX_2D_GLUE_H |
|
7 |
|
8 |
|
9 #include "gfxPlatform.h" |
|
10 #include "gfxRect.h" |
|
11 #include "gfxMatrix.h" |
|
12 #include "gfx3DMatrix.h" |
|
13 #include "gfxContext.h" |
|
14 #include "mozilla/gfx/Matrix.h" |
|
15 #include "mozilla/gfx/Rect.h" |
|
16 #include "mozilla/gfx/2D.h" |
|
17 #include "gfxColor.h" |
|
18 |
|
19 namespace mozilla { |
|
20 namespace gfx { |
|
21 class DrawTarget; |
|
22 class SourceSurface; |
|
23 class ScaledFont; |
|
24 } |
|
25 } |
|
26 |
|
27 namespace mozilla { |
|
28 namespace gfx { |
|
29 |
|
30 inline Rect ToRect(const gfxRect &aRect) |
|
31 { |
|
32 return Rect(Float(aRect.x), Float(aRect.y), |
|
33 Float(aRect.width), Float(aRect.height)); |
|
34 } |
|
35 |
|
36 inline Rect ToRect(const nsIntRect &aRect) |
|
37 { |
|
38 return Rect(aRect.x, aRect.y, aRect.width, aRect.height); |
|
39 } |
|
40 |
|
41 inline IntRect ToIntRect(const nsIntRect &aRect) |
|
42 { |
|
43 return IntRect(aRect.x, aRect.y, aRect.width, aRect.height); |
|
44 } |
|
45 |
|
46 inline Color ToColor(const gfxRGBA &aRGBA) |
|
47 { |
|
48 return Color(Float(aRGBA.r), Float(aRGBA.g), |
|
49 Float(aRGBA.b), Float(aRGBA.a)); |
|
50 } |
|
51 |
|
52 inline Matrix ToMatrix(const gfxMatrix &aMatrix) |
|
53 { |
|
54 return Matrix(Float(aMatrix.xx), Float(aMatrix.yx), Float(aMatrix.xy), |
|
55 Float(aMatrix.yy), Float(aMatrix.x0), Float(aMatrix.y0)); |
|
56 } |
|
57 |
|
58 inline gfxMatrix ThebesMatrix(const Matrix &aMatrix) |
|
59 { |
|
60 return gfxMatrix(aMatrix._11, aMatrix._12, aMatrix._21, |
|
61 aMatrix._22, aMatrix._31, aMatrix._32); |
|
62 } |
|
63 |
|
64 inline Point ToPoint(const gfxPoint &aPoint) |
|
65 { |
|
66 return Point(Float(aPoint.x), Float(aPoint.y)); |
|
67 } |
|
68 |
|
69 inline IntPoint ToIntPoint(const nsIntPoint &aPoint) |
|
70 { |
|
71 return IntPoint(aPoint.x, aPoint.y); |
|
72 } |
|
73 |
|
74 inline Size ToSize(const gfxSize &aSize) |
|
75 { |
|
76 return Size(Float(aSize.width), Float(aSize.height)); |
|
77 } |
|
78 |
|
79 inline IntSize ToIntSize(const gfxIntSize &aSize) |
|
80 { |
|
81 return IntSize(aSize.width, aSize.height); |
|
82 } |
|
83 |
|
84 inline Filter ToFilter(GraphicsFilter aFilter) |
|
85 { |
|
86 switch (aFilter) { |
|
87 case GraphicsFilter::FILTER_NEAREST: |
|
88 return Filter::POINT; |
|
89 case GraphicsFilter::FILTER_GOOD: |
|
90 return Filter::GOOD; |
|
91 default: |
|
92 return Filter::LINEAR; |
|
93 } |
|
94 } |
|
95 |
|
96 inline GraphicsFilter ThebesFilter(Filter aFilter) |
|
97 { |
|
98 switch (aFilter) { |
|
99 case Filter::POINT: |
|
100 return GraphicsFilter::FILTER_NEAREST; |
|
101 default: |
|
102 return GraphicsFilter::FILTER_BEST; |
|
103 } |
|
104 } |
|
105 |
|
106 inline ExtendMode ToExtendMode(gfxPattern::GraphicsExtend aExtend) |
|
107 { |
|
108 switch (aExtend) { |
|
109 case gfxPattern::EXTEND_REPEAT: |
|
110 return ExtendMode::REPEAT; |
|
111 case gfxPattern::EXTEND_REFLECT: |
|
112 return ExtendMode::REFLECT; |
|
113 default: |
|
114 return ExtendMode::CLAMP; |
|
115 } |
|
116 } |
|
117 |
|
118 inline gfxPattern::GraphicsExtend ThebesExtend(ExtendMode aExtend) |
|
119 { |
|
120 switch (aExtend) { |
|
121 case ExtendMode::REPEAT: |
|
122 return gfxPattern::EXTEND_REPEAT; |
|
123 case ExtendMode::REFLECT: |
|
124 return gfxPattern::EXTEND_REFLECT; |
|
125 default: |
|
126 return gfxPattern::EXTEND_PAD; |
|
127 } |
|
128 } |
|
129 |
|
130 inline gfxPoint ThebesPoint(const Point &aPoint) |
|
131 { |
|
132 return gfxPoint(aPoint.x, aPoint.y); |
|
133 } |
|
134 |
|
135 inline gfxSize ThebesSize(const Size &aSize) |
|
136 { |
|
137 return gfxSize(aSize.width, aSize.height); |
|
138 } |
|
139 |
|
140 inline gfxIntSize ThebesIntSize(const IntSize &aSize) |
|
141 { |
|
142 return gfxIntSize(aSize.width, aSize.height); |
|
143 } |
|
144 |
|
145 inline gfxRect ThebesRect(const Rect &aRect) |
|
146 { |
|
147 return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height); |
|
148 } |
|
149 |
|
150 inline nsIntRect ThebesIntRect(const IntRect &aRect) |
|
151 { |
|
152 return nsIntRect(aRect.x, aRect.y, aRect.width, aRect.height); |
|
153 } |
|
154 |
|
155 inline gfxRGBA ThebesRGBA(const Color &aColor) |
|
156 { |
|
157 return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a); |
|
158 } |
|
159 |
|
160 inline gfxContext::GraphicsLineCap ThebesLineCap(CapStyle aStyle) |
|
161 { |
|
162 switch (aStyle) { |
|
163 case CapStyle::BUTT: |
|
164 return gfxContext::LINE_CAP_BUTT; |
|
165 case CapStyle::ROUND: |
|
166 return gfxContext::LINE_CAP_ROUND; |
|
167 case CapStyle::SQUARE: |
|
168 return gfxContext::LINE_CAP_SQUARE; |
|
169 } |
|
170 MOZ_CRASH("Incomplete switch"); |
|
171 } |
|
172 |
|
173 inline CapStyle ToCapStyle(gfxContext::GraphicsLineCap aStyle) |
|
174 { |
|
175 switch (aStyle) { |
|
176 case gfxContext::LINE_CAP_BUTT: |
|
177 return CapStyle::BUTT; |
|
178 case gfxContext::LINE_CAP_ROUND: |
|
179 return CapStyle::ROUND; |
|
180 case gfxContext::LINE_CAP_SQUARE: |
|
181 return CapStyle::SQUARE; |
|
182 } |
|
183 MOZ_CRASH("Incomplete switch"); |
|
184 } |
|
185 |
|
186 inline gfxContext::GraphicsLineJoin ThebesLineJoin(JoinStyle aStyle) |
|
187 { |
|
188 switch (aStyle) { |
|
189 case JoinStyle::MITER: |
|
190 return gfxContext::LINE_JOIN_MITER; |
|
191 case JoinStyle::BEVEL: |
|
192 return gfxContext::LINE_JOIN_BEVEL; |
|
193 case JoinStyle::ROUND: |
|
194 return gfxContext::LINE_JOIN_ROUND; |
|
195 default: |
|
196 return gfxContext::LINE_JOIN_MITER; |
|
197 } |
|
198 } |
|
199 |
|
200 inline JoinStyle ToJoinStyle(gfxContext::GraphicsLineJoin aStyle) |
|
201 { |
|
202 switch (aStyle) { |
|
203 case gfxContext::LINE_JOIN_MITER: |
|
204 return JoinStyle::MITER; |
|
205 case gfxContext::LINE_JOIN_BEVEL: |
|
206 return JoinStyle::BEVEL; |
|
207 case gfxContext::LINE_JOIN_ROUND: |
|
208 return JoinStyle::ROUND; |
|
209 } |
|
210 MOZ_CRASH("Incomplete switch"); |
|
211 } |
|
212 |
|
213 inline gfxImageFormat SurfaceFormatToImageFormat(SurfaceFormat aFormat) |
|
214 { |
|
215 switch (aFormat) { |
|
216 case SurfaceFormat::B8G8R8A8: |
|
217 return gfxImageFormat::ARGB32; |
|
218 case SurfaceFormat::B8G8R8X8: |
|
219 return gfxImageFormat::RGB24; |
|
220 case SurfaceFormat::R5G6B5: |
|
221 return gfxImageFormat::RGB16_565; |
|
222 case SurfaceFormat::A8: |
|
223 return gfxImageFormat::A8; |
|
224 default: |
|
225 return gfxImageFormat::Unknown; |
|
226 } |
|
227 } |
|
228 |
|
229 inline SurfaceFormat ImageFormatToSurfaceFormat(gfxImageFormat aFormat) |
|
230 { |
|
231 switch (aFormat) { |
|
232 case gfxImageFormat::ARGB32: |
|
233 return SurfaceFormat::B8G8R8A8; |
|
234 case gfxImageFormat::RGB24: |
|
235 return SurfaceFormat::B8G8R8X8; |
|
236 case gfxImageFormat::RGB16_565: |
|
237 return SurfaceFormat::R5G6B5; |
|
238 case gfxImageFormat::A8: |
|
239 return SurfaceFormat::A8; |
|
240 default: |
|
241 case gfxImageFormat::Unknown: |
|
242 return SurfaceFormat::B8G8R8A8; |
|
243 } |
|
244 } |
|
245 |
|
246 inline gfxContentType ContentForFormat(const SurfaceFormat &aFormat) |
|
247 { |
|
248 switch (aFormat) { |
|
249 case SurfaceFormat::R5G6B5: |
|
250 case SurfaceFormat::B8G8R8X8: |
|
251 case SurfaceFormat::R8G8B8X8: |
|
252 return gfxContentType::COLOR; |
|
253 case SurfaceFormat::A8: |
|
254 return gfxContentType::ALPHA; |
|
255 case SurfaceFormat::B8G8R8A8: |
|
256 case SurfaceFormat::R8G8B8A8: |
|
257 default: |
|
258 return gfxContentType::COLOR_ALPHA; |
|
259 } |
|
260 } |
|
261 |
|
262 inline CompositionOp CompositionOpForOp(gfxContext::GraphicsOperator aOp) |
|
263 { |
|
264 switch (aOp) { |
|
265 case gfxContext::OPERATOR_ADD: |
|
266 return CompositionOp::OP_ADD; |
|
267 case gfxContext::OPERATOR_ATOP: |
|
268 return CompositionOp::OP_ATOP; |
|
269 case gfxContext::OPERATOR_IN: |
|
270 return CompositionOp::OP_IN; |
|
271 case gfxContext::OPERATOR_OUT: |
|
272 return CompositionOp::OP_OUT; |
|
273 case gfxContext::OPERATOR_SOURCE: |
|
274 return CompositionOp::OP_SOURCE; |
|
275 case gfxContext::OPERATOR_DEST_IN: |
|
276 return CompositionOp::OP_DEST_IN; |
|
277 case gfxContext::OPERATOR_DEST_OUT: |
|
278 return CompositionOp::OP_DEST_OUT; |
|
279 case gfxContext::OPERATOR_DEST_ATOP: |
|
280 return CompositionOp::OP_DEST_ATOP; |
|
281 case gfxContext::OPERATOR_XOR: |
|
282 return CompositionOp::OP_XOR; |
|
283 case gfxContext::OPERATOR_MULTIPLY: |
|
284 return CompositionOp::OP_MULTIPLY; |
|
285 case gfxContext::OPERATOR_SCREEN: |
|
286 return CompositionOp::OP_SCREEN; |
|
287 case gfxContext::OPERATOR_OVERLAY: |
|
288 return CompositionOp::OP_OVERLAY; |
|
289 case gfxContext::OPERATOR_DARKEN: |
|
290 return CompositionOp::OP_DARKEN; |
|
291 case gfxContext::OPERATOR_LIGHTEN: |
|
292 return CompositionOp::OP_LIGHTEN; |
|
293 case gfxContext::OPERATOR_COLOR_DODGE: |
|
294 return CompositionOp::OP_COLOR_DODGE; |
|
295 case gfxContext::OPERATOR_COLOR_BURN: |
|
296 return CompositionOp::OP_COLOR_BURN; |
|
297 case gfxContext::OPERATOR_HARD_LIGHT: |
|
298 return CompositionOp::OP_HARD_LIGHT; |
|
299 case gfxContext::OPERATOR_SOFT_LIGHT: |
|
300 return CompositionOp::OP_SOFT_LIGHT; |
|
301 case gfxContext::OPERATOR_DIFFERENCE: |
|
302 return CompositionOp::OP_DIFFERENCE; |
|
303 case gfxContext::OPERATOR_EXCLUSION: |
|
304 return CompositionOp::OP_EXCLUSION; |
|
305 case gfxContext::OPERATOR_HUE: |
|
306 return CompositionOp::OP_HUE; |
|
307 case gfxContext::OPERATOR_SATURATION: |
|
308 return CompositionOp::OP_SATURATION; |
|
309 case gfxContext::OPERATOR_COLOR: |
|
310 return CompositionOp::OP_COLOR; |
|
311 case gfxContext::OPERATOR_LUMINOSITY: |
|
312 return CompositionOp::OP_LUMINOSITY; |
|
313 default: |
|
314 return CompositionOp::OP_OVER; |
|
315 } |
|
316 } |
|
317 |
|
318 inline gfxContext::GraphicsOperator ThebesOp(CompositionOp aOp) |
|
319 { |
|
320 switch (aOp) { |
|
321 case CompositionOp::OP_ADD: |
|
322 return gfxContext::OPERATOR_ADD; |
|
323 case CompositionOp::OP_ATOP: |
|
324 return gfxContext::OPERATOR_ATOP; |
|
325 case CompositionOp::OP_IN: |
|
326 return gfxContext::OPERATOR_IN; |
|
327 case CompositionOp::OP_OUT: |
|
328 return gfxContext::OPERATOR_OUT; |
|
329 case CompositionOp::OP_SOURCE: |
|
330 return gfxContext::OPERATOR_SOURCE; |
|
331 case CompositionOp::OP_DEST_IN: |
|
332 return gfxContext::OPERATOR_DEST_IN; |
|
333 case CompositionOp::OP_DEST_OUT: |
|
334 return gfxContext::OPERATOR_DEST_OUT; |
|
335 case CompositionOp::OP_DEST_ATOP: |
|
336 return gfxContext::OPERATOR_DEST_ATOP; |
|
337 case CompositionOp::OP_XOR: |
|
338 return gfxContext::OPERATOR_XOR; |
|
339 case CompositionOp::OP_MULTIPLY: |
|
340 return gfxContext::OPERATOR_MULTIPLY; |
|
341 case CompositionOp::OP_SCREEN: |
|
342 return gfxContext::OPERATOR_SCREEN; |
|
343 case CompositionOp::OP_OVERLAY: |
|
344 return gfxContext::OPERATOR_OVERLAY; |
|
345 case CompositionOp::OP_DARKEN: |
|
346 return gfxContext::OPERATOR_DARKEN; |
|
347 case CompositionOp::OP_LIGHTEN: |
|
348 return gfxContext::OPERATOR_LIGHTEN; |
|
349 case CompositionOp::OP_COLOR_DODGE: |
|
350 return gfxContext::OPERATOR_COLOR_DODGE; |
|
351 case CompositionOp::OP_COLOR_BURN: |
|
352 return gfxContext::OPERATOR_COLOR_BURN; |
|
353 case CompositionOp::OP_HARD_LIGHT: |
|
354 return gfxContext::OPERATOR_HARD_LIGHT; |
|
355 case CompositionOp::OP_SOFT_LIGHT: |
|
356 return gfxContext::OPERATOR_SOFT_LIGHT; |
|
357 case CompositionOp::OP_DIFFERENCE: |
|
358 return gfxContext::OPERATOR_DIFFERENCE; |
|
359 case CompositionOp::OP_EXCLUSION: |
|
360 return gfxContext::OPERATOR_EXCLUSION; |
|
361 case CompositionOp::OP_HUE: |
|
362 return gfxContext::OPERATOR_HUE; |
|
363 case CompositionOp::OP_SATURATION: |
|
364 return gfxContext::OPERATOR_SATURATION; |
|
365 case CompositionOp::OP_COLOR: |
|
366 return gfxContext::OPERATOR_COLOR; |
|
367 case CompositionOp::OP_LUMINOSITY: |
|
368 return gfxContext::OPERATOR_LUMINOSITY; |
|
369 default: |
|
370 return gfxContext::OPERATOR_OVER; |
|
371 } |
|
372 } |
|
373 |
|
374 inline void |
|
375 ToMatrix4x4(const gfx3DMatrix& aIn, Matrix4x4& aOut) |
|
376 { |
|
377 aOut._11 = aIn._11; |
|
378 aOut._12 = aIn._12; |
|
379 aOut._13 = aIn._13; |
|
380 aOut._14 = aIn._14; |
|
381 aOut._21 = aIn._21; |
|
382 aOut._22 = aIn._22; |
|
383 aOut._23 = aIn._23; |
|
384 aOut._24 = aIn._24; |
|
385 aOut._31 = aIn._31; |
|
386 aOut._32 = aIn._32; |
|
387 aOut._33 = aIn._33; |
|
388 aOut._34 = aIn._34; |
|
389 aOut._41 = aIn._41; |
|
390 aOut._42 = aIn._42; |
|
391 aOut._43 = aIn._43; |
|
392 aOut._44 = aIn._44; |
|
393 } |
|
394 |
|
395 inline void |
|
396 To3DMatrix(const Matrix4x4& aIn, gfx3DMatrix& aOut) |
|
397 { |
|
398 aOut._11 = aIn._11; |
|
399 aOut._12 = aIn._12; |
|
400 aOut._13 = aIn._13; |
|
401 aOut._14 = aIn._14; |
|
402 aOut._21 = aIn._21; |
|
403 aOut._22 = aIn._22; |
|
404 aOut._23 = aIn._23; |
|
405 aOut._24 = aIn._24; |
|
406 aOut._31 = aIn._31; |
|
407 aOut._32 = aIn._32; |
|
408 aOut._33 = aIn._33; |
|
409 aOut._34 = aIn._34; |
|
410 aOut._41 = aIn._41; |
|
411 aOut._42 = aIn._42; |
|
412 aOut._43 = aIn._43; |
|
413 aOut._44 = aIn._44; |
|
414 } |
|
415 |
|
416 } |
|
417 } |
|
418 |
|
419 #endif |