Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef GFX_2D_GLUE_H
8 : #define GFX_2D_GLUE_H
9 :
10 : #include "gfxPlatform.h"
11 : #include "gfxRect.h"
12 : #include "gfxMatrix.h"
13 : #include "gfxContext.h"
14 : #include "mozilla/gfx/Matrix.h"
15 : #include "mozilla/gfx/Rect.h"
16 : #include "mozilla/gfx/2D.h"
17 :
18 : namespace mozilla {
19 : namespace gfx {
20 :
21 923 : inline Rect ToRect(const gfxRect &aRect)
22 : {
23 2769 : return Rect(Float(aRect.x), Float(aRect.y),
24 3692 : Float(aRect.width), Float(aRect.height));
25 : }
26 :
27 : inline RectDouble ToRectDouble(const gfxRect &aRect)
28 : {
29 : return RectDouble(aRect.x, aRect.y, aRect.width, aRect.height);
30 : }
31 :
32 1509 : inline Matrix ToMatrix(const gfxMatrix &aMatrix)
33 : {
34 4527 : return Matrix(Float(aMatrix._11), Float(aMatrix._12), Float(aMatrix._21),
35 6036 : Float(aMatrix._22), Float(aMatrix._31), Float(aMatrix._32));
36 : }
37 :
38 3483 : inline gfxMatrix ThebesMatrix(const Matrix &aMatrix)
39 : {
40 10449 : return gfxMatrix(aMatrix._11, aMatrix._12, aMatrix._21,
41 13932 : aMatrix._22, aMatrix._31, aMatrix._32);
42 : }
43 :
44 1661 : inline Point ToPoint(const gfxPoint &aPoint)
45 : {
46 1661 : return Point(Float(aPoint.x), Float(aPoint.y));
47 : }
48 :
49 : inline Size ToSize(const gfxSize &aSize)
50 : {
51 : return Size(Float(aSize.width), Float(aSize.height));
52 : }
53 :
54 2067 : inline gfxPoint ThebesPoint(const Point &aPoint)
55 : {
56 2067 : return gfxPoint(aPoint.x, aPoint.y);
57 : }
58 :
59 : inline gfxSize ThebesSize(const Size &aSize)
60 : {
61 : return gfxSize(aSize.width, aSize.height);
62 : }
63 :
64 623 : inline gfxRect ThebesRect(const Rect &aRect)
65 : {
66 623 : return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
67 : }
68 :
69 18 : inline gfxRect ThebesRect(const IntRect &aRect)
70 : {
71 18 : return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
72 : }
73 :
74 433 : inline gfxRect ThebesRect(const RectDouble &aRect)
75 : {
76 433 : return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
77 : }
78 :
79 0 : inline gfxImageFormat SurfaceFormatToImageFormat(SurfaceFormat aFormat)
80 : {
81 0 : switch (aFormat) {
82 : case SurfaceFormat::B8G8R8A8:
83 0 : return SurfaceFormat::A8R8G8B8_UINT32;
84 : case SurfaceFormat::B8G8R8X8:
85 0 : return SurfaceFormat::X8R8G8B8_UINT32;
86 : case SurfaceFormat::R5G6B5_UINT16:
87 0 : return SurfaceFormat::R5G6B5_UINT16;
88 : case SurfaceFormat::A8:
89 0 : return SurfaceFormat::A8;
90 : default:
91 0 : return SurfaceFormat::UNKNOWN;
92 : }
93 : }
94 :
95 0 : inline SurfaceFormat ImageFormatToSurfaceFormat(gfxImageFormat aFormat)
96 : {
97 0 : switch (aFormat) {
98 : case SurfaceFormat::A8R8G8B8_UINT32:
99 0 : return SurfaceFormat::B8G8R8A8;
100 : case SurfaceFormat::X8R8G8B8_UINT32:
101 0 : return SurfaceFormat::B8G8R8X8;
102 : case SurfaceFormat::R5G6B5_UINT16:
103 0 : return SurfaceFormat::R5G6B5_UINT16;
104 : case SurfaceFormat::A8:
105 0 : return SurfaceFormat::A8;
106 : default:
107 : case SurfaceFormat::UNKNOWN:
108 0 : return SurfaceFormat::B8G8R8A8;
109 : }
110 : }
111 :
112 103 : inline gfxContentType ContentForFormat(const SurfaceFormat &aFormat)
113 : {
114 103 : switch (aFormat) {
115 : case SurfaceFormat::R5G6B5_UINT16:
116 : case SurfaceFormat::B8G8R8X8:
117 : case SurfaceFormat::R8G8B8X8:
118 47 : return gfxContentType::COLOR;
119 : case SurfaceFormat::A8:
120 0 : return gfxContentType::ALPHA;
121 : case SurfaceFormat::B8G8R8A8:
122 : case SurfaceFormat::R8G8B8A8:
123 : default:
124 56 : return gfxContentType::COLOR_ALPHA;
125 : }
126 : }
127 :
128 : } // namespace gfx
129 : } // namespace mozilla
130 :
131 : #endif
|