OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_GFX_MOJO_BUFFER_TYPES_TRAITS_H_ | |
6 #define UI_GFX_MOJO_BUFFER_TYPES_TRAITS_H_ | |
7 | |
8 #include "ui/gfx/buffer_types.h" | |
9 #include "ui/gfx/mojo/buffer_types.mojom.h" | |
10 | |
11 namespace mojo { | |
12 | |
13 template <> | |
14 struct EnumTraits<gfx::mojom::BufferFormat, gfx::BufferFormat> { | |
15 static gfx::mojom::BufferFormat ToMojom(gfx::BufferFormat format) { | |
16 switch (format) { | |
17 case gfx::BufferFormat::ATC: | |
18 return gfx::mojom::BufferFormat::ATC; | |
19 case gfx::BufferFormat::ATCIA: | |
20 return gfx::mojom::BufferFormat::ATCIA; | |
21 case gfx::BufferFormat::DXT1: | |
22 return gfx::mojom::BufferFormat::DXT1; | |
23 case gfx::BufferFormat::DXT5: | |
24 return gfx::mojom::BufferFormat::DXT5; | |
25 case gfx::BufferFormat::ETC1: | |
26 return gfx::mojom::BufferFormat::ETC1; | |
27 case gfx::BufferFormat::R_8: | |
28 return gfx::mojom::BufferFormat::R_8; | |
29 case gfx::BufferFormat::RG_88: | |
30 return gfx::mojom::BufferFormat::RG_88; | |
31 case gfx::BufferFormat::BGR_565: | |
32 return gfx::mojom::BufferFormat::BGR_565; | |
33 case gfx::BufferFormat::RGBA_4444: | |
34 return gfx::mojom::BufferFormat::RGBA_4444; | |
35 case gfx::BufferFormat::RGBX_8888: | |
36 return gfx::mojom::BufferFormat::RGBX_8888; | |
37 case gfx::BufferFormat::RGBA_8888: | |
38 return gfx::mojom::BufferFormat::RGBA_8888; | |
39 case gfx::BufferFormat::BGRX_8888: | |
40 return gfx::mojom::BufferFormat::BGRX_8888; | |
41 case gfx::BufferFormat::BGRA_8888: | |
42 return gfx::mojom::BufferFormat::BGRA_8888; | |
43 case gfx::BufferFormat::YVU_420: | |
44 return gfx::mojom::BufferFormat::YVU_420; | |
45 case gfx::BufferFormat::YUV_420_BIPLANAR: | |
46 return gfx::mojom::BufferFormat::YUV_420_BIPLANAR; | |
47 case gfx::BufferFormat::UYVY_422: | |
48 return gfx::mojom::BufferFormat::UYVY_422; | |
49 } | |
50 NOTREACHED(); | |
51 return gfx::mojom::BufferFormat::LAST; | |
52 } | |
53 | |
54 static bool FromMojom(gfx::mojom::BufferFormat input, | |
55 gfx::BufferFormat* out) { | |
56 switch (input) { | |
57 case gfx::mojom::BufferFormat::ATC: | |
58 *out = gfx::BufferFormat::ATC; | |
59 return true; | |
60 case gfx::mojom::BufferFormat::ATCIA: | |
61 *out = gfx::BufferFormat::ATCIA; | |
62 return true; | |
63 case gfx::mojom::BufferFormat::DXT1: | |
64 *out = gfx::BufferFormat::DXT1; | |
65 return true; | |
66 case gfx::mojom::BufferFormat::DXT5: | |
67 *out = gfx::BufferFormat::DXT5; | |
68 return true; | |
69 case gfx::mojom::BufferFormat::ETC1: | |
70 *out = gfx::BufferFormat::ETC1; | |
71 return true; | |
72 case gfx::mojom::BufferFormat::R_8: | |
73 *out = gfx::BufferFormat::R_8; | |
74 return true; | |
75 case gfx::mojom::BufferFormat::RG_88: | |
76 *out = gfx::BufferFormat::RG_88; | |
77 return true; | |
78 case gfx::mojom::BufferFormat::BGR_565: | |
79 *out = gfx::BufferFormat::BGR_565; | |
80 return true; | |
81 case gfx::mojom::BufferFormat::RGBA_4444: | |
82 *out = gfx::BufferFormat::RGBA_4444; | |
83 return true; | |
84 case gfx::mojom::BufferFormat::RGBX_8888: | |
85 *out = gfx::BufferFormat::RGBX_8888; | |
86 return true; | |
87 case gfx::mojom::BufferFormat::RGBA_8888: | |
88 *out = gfx::BufferFormat::RGBA_8888; | |
89 return true; | |
90 case gfx::mojom::BufferFormat::BGRX_8888: | |
91 *out = gfx::BufferFormat::BGRX_8888; | |
92 return true; | |
93 case gfx::mojom::BufferFormat::BGRA_8888: | |
94 *out = gfx::BufferFormat::BGRA_8888; | |
95 return true; | |
96 case gfx::mojom::BufferFormat::YVU_420: | |
97 *out = gfx::BufferFormat::YVU_420; | |
98 return true; | |
99 case gfx::mojom::BufferFormat::YUV_420_BIPLANAR: | |
100 *out = gfx::BufferFormat::YUV_420_BIPLANAR; | |
101 return true; | |
102 case gfx::mojom::BufferFormat::UYVY_422: | |
103 *out = gfx::BufferFormat::UYVY_422; | |
104 } | |
105 NOTREACHED(); | |
106 return false; | |
107 } | |
108 }; | |
109 | |
110 template <> | |
111 struct EnumTraits<gfx::mojom::BufferUsage, gfx::BufferUsage> { | |
112 static gfx::mojom::BufferUsage ToMojom(gfx::BufferUsage usage) { | |
113 switch (usage) { | |
114 case gfx::BufferUsage::GPU_READ: | |
115 return gfx::mojom::BufferUsage::GPU_READ; | |
116 case gfx::BufferUsage::SCANOUT: | |
117 return gfx::mojom::BufferUsage::SCANOUT; | |
118 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: | |
119 return gfx::mojom::BufferUsage::GPU_READ_CPU_READ_WRITE; | |
120 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: | |
121 return gfx::mojom::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT; | |
122 } | |
123 NOTREACHED(); | |
124 return gfx::mojom::BufferUsage::LAST; | |
125 } | |
126 | |
127 static bool FromMojom(gfx::mojom::BufferUsage input, gfx::BufferUsage* out) { | |
128 switch (input) { | |
129 case gfx::mojom::BufferUsage::GPU_READ: | |
130 *out = gfx::BufferUsage::GPU_READ; | |
131 return true; | |
132 case gfx::mojom::BufferUsage::SCANOUT: | |
133 *out = gfx::BufferUsage::SCANOUT; | |
134 return true; | |
135 case gfx::mojom::BufferUsage::GPU_READ_CPU_READ_WRITE: | |
136 *out = gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; | |
137 return true; | |
138 case gfx::mojom::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: | |
139 *out = gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT; | |
140 return true; | |
141 } | |
142 NOTREACHED(); | |
143 return false; | |
144 } | |
145 }; | |
146 | |
147 template <> | |
148 struct EnumTraits<gfx::mojom::GpuMemoryBufferType, gfx::GpuMemoryBufferType> { | |
149 static gfx::mojom::GpuMemoryBufferType ToMojom( | |
150 gfx::GpuMemoryBufferType type) { | |
151 switch (type) { | |
152 case gfx::GpuMemoryBufferType::EMPTY_BUFFER: | |
153 return gfx::mojom::GpuMemoryBufferType::EMPTY_BUFFER; | |
154 case gfx::GpuMemoryBufferType::SHARED_MEMORY_BUFFER: | |
155 return gfx::mojom::GpuMemoryBufferType::SHARED_MEMORY_BUFFER; | |
156 case gfx::GpuMemoryBufferType::IO_SURFACE_BUFFER: | |
157 return gfx::mojom::GpuMemoryBufferType::IO_SURFACE_BUFFER; | |
158 case gfx::GpuMemoryBufferType::OZONE_NATIVE_PIXMAP: | |
159 return gfx::mojom::GpuMemoryBufferType::OZONE_NATIVE_PIXMAP; | |
160 } | |
161 NOTREACHED(); | |
162 return gfx::mojom::GpuMemoryBufferType::LAST; | |
163 } | |
164 | |
165 static bool FromMojom(gfx::mojom::GpuMemoryBufferType input, | |
166 gfx::GpuMemoryBufferType* out) { | |
167 switch (input) { | |
168 case gfx::mojom::GpuMemoryBufferType::EMPTY_BUFFER: | |
169 *out = gfx::GpuMemoryBufferType::EMPTY_BUFFER; | |
170 return true; | |
171 case gfx::mojom::GpuMemoryBufferType::SHARED_MEMORY_BUFFER: | |
172 *out = gfx::GpuMemoryBufferType::SHARED_MEMORY_BUFFER; | |
173 return true; | |
174 case gfx::mojom::GpuMemoryBufferType::IO_SURFACE_BUFFER: | |
175 *out = gfx::GpuMemoryBufferType::IO_SURFACE_BUFFER; | |
176 return true; | |
177 case gfx::mojom::GpuMemoryBufferType::OZONE_NATIVE_PIXMAP: | |
178 *out = gfx::GpuMemoryBufferType::OZONE_NATIVE_PIXMAP; | |
179 return true; | |
180 } | |
181 return false; | |
182 } | |
183 }; | |
184 | |
185 template <> | |
186 struct StructTraits<gfx::mojom::GpuMemoryBufferIdDataView, | |
187 gfx::GpuMemoryBufferId> { | |
188 static int32_t id(const gfx::GpuMemoryBufferId& buffer_id) { | |
189 return buffer_id.id; | |
190 } | |
191 static bool Read(gfx::mojom::GpuMemoryBufferIdDataView data, | |
192 gfx::GpuMemoryBufferId* out) { | |
193 out->id = data.id(); | |
194 return true; | |
195 } | |
196 }; | |
197 | |
198 template <> | |
199 struct StructTraits<gfx::mojom::NativePixmapPlaneDataView, | |
200 gfx::NativePixmapPlane> { | |
201 static uint32_t stride(const gfx::NativePixmapPlane& plane) { | |
202 return plane.stride; | |
203 } | |
204 static int32_t offset(const gfx::NativePixmapPlane& plane) { | |
205 return plane.offset; | |
206 } | |
207 static uint64_t size(const gfx::NativePixmapPlane& plane) { | |
208 return plane.size; | |
209 } | |
210 static uint64_t modifier(const gfx::NativePixmapPlane& plane) { | |
211 return plane.modifier; | |
212 } | |
213 static bool Read(gfx::mojom::NativePixmapPlaneDataView data, | |
214 gfx::NativePixmapPlane* out) { | |
215 out->stride = data.stride(); | |
216 out->offset = data.offset(); | |
217 out->size = data.size(); | |
218 out->modifier = data.modifier(); | |
219 return true; | |
220 } | |
221 }; | |
222 | |
223 template <> | |
224 struct StructTraits<gfx::mojom::NativePixmapHandleDataView, | |
225 gfx::NativePixmapHandle> { | |
226 using PixmapHandleFdList = std::vector<mojo::ScopedHandle>; | |
227 | |
228 static void* SetUpContext(const gfx::NativePixmapHandle& handle); | |
229 static void TearDownContext(const gfx::NativePixmapHandle& handle, | |
230 void* context); | |
231 | |
232 static bool IsNull(const gfx::NativePixmapHandle& handle) { | |
233 #if defined(USE_OZONE) | |
234 return false; | |
235 #else | |
236 // NativePixmapHandle are not used on non-ozone platforms. | |
237 return true; | |
238 #endif | |
239 } | |
240 static PixmapHandleFdList fds(const gfx::NativePixmapHandle& pixmap_handle, | |
241 void* context); | |
242 | |
243 static const std::vector<gfx::NativePixmapPlane>& planes( | |
244 const gfx::NativePixmapHandle& pixmap_handle) { | |
245 return pixmap_handle.planes; | |
246 } | |
247 | |
248 static bool Read(gfx::mojom::NativePixmapHandleDataView data, | |
249 gfx::NativePixmapHandle* out); | |
250 }; | |
251 | |
252 template <> | |
253 struct StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, | |
254 gfx::GpuMemoryBufferHandle> { | |
255 static gfx::GpuMemoryBufferType type( | |
256 const gfx::GpuMemoryBufferHandle& handle) { | |
257 return handle.type; | |
258 } | |
259 static gfx::GpuMemoryBufferId id(const gfx::GpuMemoryBufferHandle& handle) { | |
260 return handle.id; | |
261 } | |
262 static mojo::ScopedHandle shared_memory_handle( | |
263 const gfx::GpuMemoryBufferHandle& handle); | |
264 static uint32_t offset(const gfx::GpuMemoryBufferHandle& handle) { | |
265 return handle.offset; | |
266 } | |
267 static uint32_t stride(const gfx::GpuMemoryBufferHandle& handle) { | |
268 return handle.stride; | |
269 } | |
270 static const gfx::NativePixmapHandle& native_pixmap_handle( | |
271 const gfx::GpuMemoryBufferHandle& handle); | |
272 static mojo::ScopedHandle mach_port(const gfx::GpuMemoryBufferHandle& handle); | |
273 static bool Read(gfx::mojom::GpuMemoryBufferHandleDataView data, | |
274 gfx::GpuMemoryBufferHandle* handle); | |
275 }; | |
276 | |
277 } // namespace mojo | |
278 | |
279 #endif // UI_GFX_MOJO_BUFFER_TYPES_TRAITS_H_ | |
OLD | NEW |