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/. */
9 #include "gfxPlatform.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"
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
)
92 case GraphicsFilter::FILTER_NEAREST
:
94 case GraphicsFilter::FILTER_GOOD
:
97 return Filter::LINEAR
;
101 inline GraphicsFilter
ThebesFilter(Filter aFilter
)
105 return GraphicsFilter::FILTER_NEAREST
;
107 return GraphicsFilter::FILTER_BEST
;
111 inline ExtendMode
ToExtendMode(gfxPattern::GraphicsExtend aExtend
)
114 case gfxPattern::EXTEND_REPEAT
:
115 return ExtendMode::REPEAT
;
116 case gfxPattern::EXTEND_REFLECT
:
117 return ExtendMode::REFLECT
;
119 return ExtendMode::CLAMP
;
123 inline gfxPattern::GraphicsExtend
ThebesExtend(ExtendMode aExtend
)
126 case ExtendMode::REPEAT
:
127 return gfxPattern::EXTEND_REPEAT
;
128 case ExtendMode::REFLECT
:
129 return gfxPattern::EXTEND_REFLECT
;
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
)
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
)
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
)
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
;
201 return gfxContext::LINE_JOIN_MITER
;
205 inline JoinStyle
ToJoinStyle(gfxContext::GraphicsLineJoin 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
)
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
;
230 return gfxImageFormat::Unknown
;
234 inline SurfaceFormat
ImageFormatToSurfaceFormat(gfxImageFormat 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
;
246 case gfxImageFormat::Unknown
:
247 return SurfaceFormat::B8G8R8A8
;
251 inline gfxContentType
ContentForFormat(const SurfaceFormat
&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
:
263 return gfxContentType::COLOR_ALPHA
;
267 inline CompositionOp
CompositionOpForOp(gfxContext::GraphicsOperator 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
;
319 return CompositionOp::OP_OVER
;
323 inline gfxContext::GraphicsOperator
ThebesOp(CompositionOp 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
;
375 return gfxContext::OPERATOR_OVER
;
380 ToMatrix4x4(const gfx3DMatrix
& aIn
)
403 To3DMatrix(const Matrix4x4
& aIn
)