Bumping manifests a=b2g-bump
[gecko.git] / gfx / thebes / gfx2DGlue.h
blob7750e0d3d0fd65774de626438edb6a8b933f8fa9
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/. */
5 #ifndef GFX_2D_GLUE_H
6 #define GFX_2D_GLUE_H
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"
19 namespace mozilla {
20 namespace gfx {
21 class DrawTarget;
22 class SourceSurface;
23 class ScaledFont;
27 namespace mozilla {
28 namespace gfx {
30 inline Rect ToRect(const gfxRect &aRect)
32 return Rect(Float(aRect.x), Float(aRect.y),
33 Float(aRect.width), Float(aRect.height));
36 inline Rect ToRect(const nsIntRect &aRect)
38 return Rect(aRect.x, aRect.y, aRect.width, aRect.height);
41 inline IntRect ToIntRect(const nsIntRect &aRect)
43 return IntRect(aRect.x, aRect.y, aRect.width, aRect.height);
46 inline Color ToColor(const gfxRGBA &aRGBA)
48 return Color(Float(aRGBA.r), Float(aRGBA.g),
49 Float(aRGBA.b), Float(aRGBA.a));
52 inline gfxRGBA ThebesColor(Color &aColor)
54 return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a);
57 inline Matrix ToMatrix(const gfxMatrix &aMatrix)
59 return Matrix(Float(aMatrix._11), Float(aMatrix._12), Float(aMatrix._21),
60 Float(aMatrix._22), Float(aMatrix._31), Float(aMatrix._32));
63 inline gfxMatrix ThebesMatrix(const Matrix &aMatrix)
65 return gfxMatrix(aMatrix._11, aMatrix._12, aMatrix._21,
66 aMatrix._22, aMatrix._31, aMatrix._32);
69 inline Point ToPoint(const gfxPoint &aPoint)
71 return Point(Float(aPoint.x), Float(aPoint.y));
74 inline IntPoint ToIntPoint(const nsIntPoint &aPoint)
76 return IntPoint(aPoint.x, aPoint.y);
79 inline Size ToSize(const gfxSize &aSize)
81 return Size(Float(aSize.width), Float(aSize.height));
84 inline IntSize ToIntSize(const gfxIntSize &aSize)
86 return IntSize(aSize.width, aSize.height);
89 inline Filter ToFilter(GraphicsFilter aFilter)
91 switch (aFilter) {
92 case GraphicsFilter::FILTER_NEAREST:
93 return Filter::POINT;
94 case GraphicsFilter::FILTER_GOOD:
95 return Filter::GOOD;
96 default:
97 return Filter::LINEAR;
101 inline GraphicsFilter ThebesFilter(Filter aFilter)
103 switch (aFilter) {
104 case Filter::POINT:
105 return GraphicsFilter::FILTER_NEAREST;
106 default:
107 return GraphicsFilter::FILTER_BEST;
111 inline ExtendMode ToExtendMode(gfxPattern::GraphicsExtend aExtend)
113 switch (aExtend) {
114 case gfxPattern::EXTEND_REPEAT:
115 return ExtendMode::REPEAT;
116 case gfxPattern::EXTEND_REFLECT:
117 return ExtendMode::REFLECT;
118 default:
119 return ExtendMode::CLAMP;
123 inline gfxPattern::GraphicsExtend ThebesExtend(ExtendMode aExtend)
125 switch (aExtend) {
126 case ExtendMode::REPEAT:
127 return gfxPattern::EXTEND_REPEAT;
128 case ExtendMode::REFLECT:
129 return gfxPattern::EXTEND_REFLECT;
130 default:
131 return gfxPattern::EXTEND_PAD;
135 inline gfxPoint ThebesPoint(const Point &aPoint)
137 return gfxPoint(aPoint.x, aPoint.y);
140 inline gfxSize ThebesSize(const Size &aSize)
142 return gfxSize(aSize.width, aSize.height);
145 inline gfxIntSize ThebesIntSize(const IntSize &aSize)
147 return gfxIntSize(aSize.width, aSize.height);
150 inline gfxRect ThebesRect(const Rect &aRect)
152 return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
155 inline nsIntRect ThebesIntRect(const IntRect &aRect)
157 return nsIntRect(aRect.x, aRect.y, aRect.width, aRect.height);
160 inline gfxRGBA ThebesRGBA(const Color &aColor)
162 return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a);
165 inline gfxContext::GraphicsLineCap ThebesLineCap(CapStyle aStyle)
167 switch (aStyle) {
168 case CapStyle::BUTT:
169 return gfxContext::LINE_CAP_BUTT;
170 case CapStyle::ROUND:
171 return gfxContext::LINE_CAP_ROUND;
172 case CapStyle::SQUARE:
173 return gfxContext::LINE_CAP_SQUARE;
175 MOZ_CRASH("Incomplete switch");
178 inline CapStyle ToCapStyle(gfxContext::GraphicsLineCap aStyle)
180 switch (aStyle) {
181 case gfxContext::LINE_CAP_BUTT:
182 return CapStyle::BUTT;
183 case gfxContext::LINE_CAP_ROUND:
184 return CapStyle::ROUND;
185 case gfxContext::LINE_CAP_SQUARE:
186 return CapStyle::SQUARE;
188 MOZ_CRASH("Incomplete switch");
191 inline gfxContext::GraphicsLineJoin ThebesLineJoin(JoinStyle aStyle)
193 switch (aStyle) {
194 case JoinStyle::MITER:
195 return gfxContext::LINE_JOIN_MITER;
196 case JoinStyle::BEVEL:
197 return gfxContext::LINE_JOIN_BEVEL;
198 case JoinStyle::ROUND:
199 return gfxContext::LINE_JOIN_ROUND;
200 default:
201 return gfxContext::LINE_JOIN_MITER;
205 inline JoinStyle ToJoinStyle(gfxContext::GraphicsLineJoin aStyle)
207 switch (aStyle) {
208 case gfxContext::LINE_JOIN_MITER:
209 return JoinStyle::MITER;
210 case gfxContext::LINE_JOIN_BEVEL:
211 return JoinStyle::BEVEL;
212 case gfxContext::LINE_JOIN_ROUND:
213 return JoinStyle::ROUND;
215 MOZ_CRASH("Incomplete switch");
218 inline gfxImageFormat SurfaceFormatToImageFormat(SurfaceFormat aFormat)
220 switch (aFormat) {
221 case SurfaceFormat::B8G8R8A8:
222 return gfxImageFormat::ARGB32;
223 case SurfaceFormat::B8G8R8X8:
224 return gfxImageFormat::RGB24;
225 case SurfaceFormat::R5G6B5:
226 return gfxImageFormat::RGB16_565;
227 case SurfaceFormat::A8:
228 return gfxImageFormat::A8;
229 default:
230 return gfxImageFormat::Unknown;
234 inline SurfaceFormat ImageFormatToSurfaceFormat(gfxImageFormat aFormat)
236 switch (aFormat) {
237 case gfxImageFormat::ARGB32:
238 return SurfaceFormat::B8G8R8A8;
239 case gfxImageFormat::RGB24:
240 return SurfaceFormat::B8G8R8X8;
241 case gfxImageFormat::RGB16_565:
242 return SurfaceFormat::R5G6B5;
243 case gfxImageFormat::A8:
244 return SurfaceFormat::A8;
245 default:
246 case gfxImageFormat::Unknown:
247 return SurfaceFormat::B8G8R8A8;
251 inline gfxContentType ContentForFormat(const SurfaceFormat &aFormat)
253 switch (aFormat) {
254 case SurfaceFormat::R5G6B5:
255 case SurfaceFormat::B8G8R8X8:
256 case SurfaceFormat::R8G8B8X8:
257 return gfxContentType::COLOR;
258 case SurfaceFormat::A8:
259 return gfxContentType::ALPHA;
260 case SurfaceFormat::B8G8R8A8:
261 case SurfaceFormat::R8G8B8A8:
262 default:
263 return gfxContentType::COLOR_ALPHA;
267 inline CompositionOp CompositionOpForOp(gfxContext::GraphicsOperator aOp)
269 switch (aOp) {
270 case gfxContext::OPERATOR_ADD:
271 return CompositionOp::OP_ADD;
272 case gfxContext::OPERATOR_ATOP:
273 return CompositionOp::OP_ATOP;
274 case gfxContext::OPERATOR_IN:
275 return CompositionOp::OP_IN;
276 case gfxContext::OPERATOR_OUT:
277 return CompositionOp::OP_OUT;
278 case gfxContext::OPERATOR_SOURCE:
279 return CompositionOp::OP_SOURCE;
280 case gfxContext::OPERATOR_DEST_IN:
281 return CompositionOp::OP_DEST_IN;
282 case gfxContext::OPERATOR_DEST_OUT:
283 return CompositionOp::OP_DEST_OUT;
284 case gfxContext::OPERATOR_DEST_ATOP:
285 return CompositionOp::OP_DEST_ATOP;
286 case gfxContext::OPERATOR_XOR:
287 return CompositionOp::OP_XOR;
288 case gfxContext::OPERATOR_MULTIPLY:
289 return CompositionOp::OP_MULTIPLY;
290 case gfxContext::OPERATOR_SCREEN:
291 return CompositionOp::OP_SCREEN;
292 case gfxContext::OPERATOR_OVERLAY:
293 return CompositionOp::OP_OVERLAY;
294 case gfxContext::OPERATOR_DARKEN:
295 return CompositionOp::OP_DARKEN;
296 case gfxContext::OPERATOR_LIGHTEN:
297 return CompositionOp::OP_LIGHTEN;
298 case gfxContext::OPERATOR_COLOR_DODGE:
299 return CompositionOp::OP_COLOR_DODGE;
300 case gfxContext::OPERATOR_COLOR_BURN:
301 return CompositionOp::OP_COLOR_BURN;
302 case gfxContext::OPERATOR_HARD_LIGHT:
303 return CompositionOp::OP_HARD_LIGHT;
304 case gfxContext::OPERATOR_SOFT_LIGHT:
305 return CompositionOp::OP_SOFT_LIGHT;
306 case gfxContext::OPERATOR_DIFFERENCE:
307 return CompositionOp::OP_DIFFERENCE;
308 case gfxContext::OPERATOR_EXCLUSION:
309 return CompositionOp::OP_EXCLUSION;
310 case gfxContext::OPERATOR_HUE:
311 return CompositionOp::OP_HUE;
312 case gfxContext::OPERATOR_SATURATION:
313 return CompositionOp::OP_SATURATION;
314 case gfxContext::OPERATOR_COLOR:
315 return CompositionOp::OP_COLOR;
316 case gfxContext::OPERATOR_LUMINOSITY:
317 return CompositionOp::OP_LUMINOSITY;
318 default:
319 return CompositionOp::OP_OVER;
323 inline gfxContext::GraphicsOperator ThebesOp(CompositionOp aOp)
325 switch (aOp) {
326 case CompositionOp::OP_ADD:
327 return gfxContext::OPERATOR_ADD;
328 case CompositionOp::OP_ATOP:
329 return gfxContext::OPERATOR_ATOP;
330 case CompositionOp::OP_IN:
331 return gfxContext::OPERATOR_IN;
332 case CompositionOp::OP_OUT:
333 return gfxContext::OPERATOR_OUT;
334 case CompositionOp::OP_SOURCE:
335 return gfxContext::OPERATOR_SOURCE;
336 case CompositionOp::OP_DEST_IN:
337 return gfxContext::OPERATOR_DEST_IN;
338 case CompositionOp::OP_DEST_OUT:
339 return gfxContext::OPERATOR_DEST_OUT;
340 case CompositionOp::OP_DEST_ATOP:
341 return gfxContext::OPERATOR_DEST_ATOP;
342 case CompositionOp::OP_XOR:
343 return gfxContext::OPERATOR_XOR;
344 case CompositionOp::OP_MULTIPLY:
345 return gfxContext::OPERATOR_MULTIPLY;
346 case CompositionOp::OP_SCREEN:
347 return gfxContext::OPERATOR_SCREEN;
348 case CompositionOp::OP_OVERLAY:
349 return gfxContext::OPERATOR_OVERLAY;
350 case CompositionOp::OP_DARKEN:
351 return gfxContext::OPERATOR_DARKEN;
352 case CompositionOp::OP_LIGHTEN:
353 return gfxContext::OPERATOR_LIGHTEN;
354 case CompositionOp::OP_COLOR_DODGE:
355 return gfxContext::OPERATOR_COLOR_DODGE;
356 case CompositionOp::OP_COLOR_BURN:
357 return gfxContext::OPERATOR_COLOR_BURN;
358 case CompositionOp::OP_HARD_LIGHT:
359 return gfxContext::OPERATOR_HARD_LIGHT;
360 case CompositionOp::OP_SOFT_LIGHT:
361 return gfxContext::OPERATOR_SOFT_LIGHT;
362 case CompositionOp::OP_DIFFERENCE:
363 return gfxContext::OPERATOR_DIFFERENCE;
364 case CompositionOp::OP_EXCLUSION:
365 return gfxContext::OPERATOR_EXCLUSION;
366 case CompositionOp::OP_HUE:
367 return gfxContext::OPERATOR_HUE;
368 case CompositionOp::OP_SATURATION:
369 return gfxContext::OPERATOR_SATURATION;
370 case CompositionOp::OP_COLOR:
371 return gfxContext::OPERATOR_COLOR;
372 case CompositionOp::OP_LUMINOSITY:
373 return gfxContext::OPERATOR_LUMINOSITY;
374 default:
375 return gfxContext::OPERATOR_OVER;
379 inline Matrix4x4
380 ToMatrix4x4(const gfx3DMatrix& aIn)
382 Matrix4x4 m;
383 m._11 = aIn._11;
384 m._12 = aIn._12;
385 m._13 = aIn._13;
386 m._14 = aIn._14;
387 m._21 = aIn._21;
388 m._22 = aIn._22;
389 m._23 = aIn._23;
390 m._24 = aIn._24;
391 m._31 = aIn._31;
392 m._32 = aIn._32;
393 m._33 = aIn._33;
394 m._34 = aIn._34;
395 m._41 = aIn._41;
396 m._42 = aIn._42;
397 m._43 = aIn._43;
398 m._44 = aIn._44;
399 return m;
402 inline gfx3DMatrix
403 To3DMatrix(const Matrix4x4& aIn)
405 gfx3DMatrix m;
406 m._11 = aIn._11;
407 m._12 = aIn._12;
408 m._13 = aIn._13;
409 m._14 = aIn._14;
410 m._21 = aIn._21;
411 m._22 = aIn._22;
412 m._23 = aIn._23;
413 m._24 = aIn._24;
414 m._31 = aIn._31;
415 m._32 = aIn._32;
416 m._33 = aIn._33;
417 m._34 = aIn._34;
418 m._41 = aIn._41;
419 m._42 = aIn._42;
420 m._43 = aIn._43;
421 m._44 = aIn._44;
422 return m;
428 #endif