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 GPU_IPC_COMMON_GPU_INFO_MOJOM_TRAITS_H_
6 #define GPU_IPC_COMMON_GPU_INFO_MOJOM_TRAITS_H_
7 
8 #include "base/time/time.h"
9 #include "build/build_config.h"
10 #include "gpu/config/gpu_info.h"
11 #include "gpu/ipc/common/dx_diag_node_mojom_traits.h"
12 #include "gpu/ipc/common/gpu_info.mojom.h"
13 #include "ui/gfx/buffer_types.h"
14 #include "ui/gfx/geometry/mojom/geometry_mojom_traits.h"
15 
16 namespace mojo {
17 
18 template <>
19 struct StructTraits<gpu::mojom::GpuDeviceDataView, gpu::GPUInfo::GPUDevice> {
20   static bool Read(gpu::mojom::GpuDeviceDataView data,
21                    gpu::GPUInfo::GPUDevice* out);
22 
23   static uint32_t vendor_id(const gpu::GPUInfo::GPUDevice& input) {
24     return input.vendor_id;
25   }
26 
27   static uint32_t device_id(const gpu::GPUInfo::GPUDevice& input) {
28     return input.device_id;
29   }
30 
31 #if defined(OS_WIN)
32   static uint32_t sub_sys_id(const gpu::GPUInfo::GPUDevice& input) {
33     return input.sub_sys_id;
34   }
35 
36   static uint32_t revision(const gpu::GPUInfo::GPUDevice& input) {
37     return input.revision;
38   }
39 #endif  // OS_WIN
40 
41   static bool active(const gpu::GPUInfo::GPUDevice& input) {
42     return input.active;
43   }
44 
45   static const std::string& vendor_string(
46       const gpu::GPUInfo::GPUDevice& input) {
47     return input.vendor_string;
48   }
49 
50   static const std::string& device_string(
51       const gpu::GPUInfo::GPUDevice& input) {
52     return input.device_string;
53   }
54 
55   static const std::string& driver_vendor(
56       const gpu::GPUInfo::GPUDevice& input) {
57     return input.driver_vendor;
58   }
59 
60   static const std::string& driver_version(
61       const gpu::GPUInfo::GPUDevice& input) {
62     return input.driver_version;
63   }
64 
65   static int cuda_compute_capability_major(
66       const gpu::GPUInfo::GPUDevice& input) {
67     return input.cuda_compute_capability_major;
68   }
69 };
70 
71 template <>
72 struct EnumTraits<gpu::mojom::VideoCodecProfile, gpu::VideoCodecProfile> {
73   static gpu::mojom::VideoCodecProfile ToMojom(
74       gpu::VideoCodecProfile video_codec_profile);
75   static bool FromMojom(gpu::mojom::VideoCodecProfile input,
76                         gpu::VideoCodecProfile* out);
77 };
78 
79 template <>
80 struct StructTraits<gpu::mojom::VideoDecodeAcceleratorSupportedProfileDataView,
81                     gpu::VideoDecodeAcceleratorSupportedProfile> {
82   static bool Read(
83       gpu::mojom::VideoDecodeAcceleratorSupportedProfileDataView data,
84       gpu::VideoDecodeAcceleratorSupportedProfile* out);
85 
86   static gpu::VideoCodecProfile profile(
87       const gpu::VideoDecodeAcceleratorSupportedProfile& input) {
88     return input.profile;
89   }
90 
91   static const gfx::Size& max_resolution(
92       const gpu::VideoDecodeAcceleratorSupportedProfile& input) {
93     return input.max_resolution;
94   }
95 
96   static const gfx::Size& min_resolution(
97       const gpu::VideoDecodeAcceleratorSupportedProfile& input) {
98     return input.min_resolution;
99   }
100 
101   static bool encrypted_only(
102       const gpu::VideoDecodeAcceleratorSupportedProfile& input) {
103     return input.encrypted_only;
104   }
105 };
106 
107 template <>
108 struct StructTraits<gpu::mojom::VideoDecodeAcceleratorCapabilitiesDataView,
109                     gpu::VideoDecodeAcceleratorCapabilities> {
110   static bool Read(gpu::mojom::VideoDecodeAcceleratorCapabilitiesDataView data,
111                    gpu::VideoDecodeAcceleratorCapabilities* out);
112 
113   static uint32_t flags(const gpu::VideoDecodeAcceleratorCapabilities& input) {
114     return input.flags;
115   }
116 
117   static std::vector<gpu::VideoDecodeAcceleratorSupportedProfile>
118   supported_profiles(const gpu::VideoDecodeAcceleratorCapabilities& input) {
119     return input.supported_profiles;
120   }
121 };
122 
123 template <>
124 struct StructTraits<gpu::mojom::VideoEncodeAcceleratorSupportedProfileDataView,
125                     gpu::VideoEncodeAcceleratorSupportedProfile> {
126   static bool Read(
127       gpu::mojom::VideoEncodeAcceleratorSupportedProfileDataView data,
128       gpu::VideoEncodeAcceleratorSupportedProfile* out);
129 
130   static gpu::VideoCodecProfile profile(
131       const gpu::VideoEncodeAcceleratorSupportedProfile& input) {
132     return input.profile;
133   }
134 
135   static const gfx::Size& min_resolution(
136       const gpu::VideoEncodeAcceleratorSupportedProfile& input) {
137     return input.min_resolution;
138   }
139 
140   static const gfx::Size& max_resolution(
141       const gpu::VideoEncodeAcceleratorSupportedProfile& input) {
142     return input.max_resolution;
143   }
144 
145   static uint32_t max_framerate_numerator(
146       const gpu::VideoEncodeAcceleratorSupportedProfile& input) {
147     return input.max_framerate_numerator;
148   }
149 
150   static uint32_t max_framerate_denominator(
151       const gpu::VideoEncodeAcceleratorSupportedProfile& input) {
152     return input.max_framerate_denominator;
153   }
154 };
155 
156 template <>
157 struct EnumTraits<gpu::mojom::ImageDecodeAcceleratorType,
158                   gpu::ImageDecodeAcceleratorType> {
159   static gpu::mojom::ImageDecodeAcceleratorType ToMojom(
160       gpu::ImageDecodeAcceleratorType image_type);
161   static bool FromMojom(gpu::mojom::ImageDecodeAcceleratorType input,
162                         gpu::ImageDecodeAcceleratorType* out);
163 };
164 
165 template <>
166 struct EnumTraits<gpu::mojom::ImageDecodeAcceleratorSubsampling,
167                   gpu::ImageDecodeAcceleratorSubsampling> {
168   static gpu::mojom::ImageDecodeAcceleratorSubsampling ToMojom(
169       gpu::ImageDecodeAcceleratorSubsampling subsampling);
170   static bool FromMojom(gpu::mojom::ImageDecodeAcceleratorSubsampling input,
171                         gpu::ImageDecodeAcceleratorSubsampling* out);
172 };
173 
174 template <>
175 struct StructTraits<gpu::mojom::ImageDecodeAcceleratorSupportedProfileDataView,
176                     gpu::ImageDecodeAcceleratorSupportedProfile> {
177   static bool Read(
178       gpu::mojom::ImageDecodeAcceleratorSupportedProfileDataView data,
179       gpu::ImageDecodeAcceleratorSupportedProfile* out);
180 
181   static gpu::ImageDecodeAcceleratorType image_type(
182       const gpu::ImageDecodeAcceleratorSupportedProfile& input) {
183     return input.image_type;
184   }
185 
186   static const gfx::Size& min_encoded_dimensions(
187       const gpu::ImageDecodeAcceleratorSupportedProfile& input) {
188     return input.min_encoded_dimensions;
189   }
190 
191   static const gfx::Size& max_encoded_dimensions(
192       const gpu::ImageDecodeAcceleratorSupportedProfile& input) {
193     return input.max_encoded_dimensions;
194   }
195 
196   static std::vector<gpu::ImageDecodeAcceleratorSubsampling> subsamplings(
197       const gpu::ImageDecodeAcceleratorSupportedProfile& input) {
198     return input.subsamplings;
199   }
200 };
201 
202 #if defined(OS_WIN)
203 template <>
204 struct EnumTraits<gpu::mojom::OverlaySupport, gpu::OverlaySupport> {
205   static gpu::mojom::OverlaySupport ToMojom(gpu::OverlaySupport support);
206   static bool FromMojom(gpu::mojom::OverlaySupport input,
207                         gpu::OverlaySupport* out);
208 };
209 
210 template <>
211 struct StructTraits<gpu::mojom::Dx12VulkanVersionInfoDataView,
212                     gpu::Dx12VulkanVersionInfo> {
213   static bool Read(gpu::mojom::Dx12VulkanVersionInfoDataView data,
214                    gpu::Dx12VulkanVersionInfo* out);
215 
216   static bool supports_dx12(const gpu::Dx12VulkanVersionInfo& input) {
217     return input.supports_dx12;
218   }
219 
220   static bool supports_vulkan(const gpu::Dx12VulkanVersionInfo& input) {
221     return input.supports_vulkan;
222   }
223 
224   static uint32_t d3d12_feature_level(const gpu::Dx12VulkanVersionInfo& input) {
225     return input.d3d12_feature_level;
226   }
227 
228   static uint32_t vulkan_version(const gpu::Dx12VulkanVersionInfo& input) {
229     return input.vulkan_version;
230   }
231 };
232 
233 template <>
234 struct StructTraits<gpu::mojom::OverlayInfoDataView, gpu::OverlayInfo> {
235   static bool Read(gpu::mojom::OverlayInfoDataView data, gpu::OverlayInfo* out);
236 
237   static bool direct_composition(const gpu::OverlayInfo& input) {
238     return input.direct_composition;
239   }
240 
241   static bool supports_overlays(const gpu::OverlayInfo& input) {
242     return input.supports_overlays;
243   }
244 
245   static gpu::OverlaySupport yuy2_overlay_support(
246       const gpu::OverlayInfo& input) {
247     return input.yuy2_overlay_support;
248   }
249 
250   static gpu::OverlaySupport nv12_overlay_support(
251       const gpu::OverlayInfo& input) {
252     return input.nv12_overlay_support;
253   }
254 };
255 
256 #endif
257 
258 template <>
259 struct StructTraits<gpu::mojom::GpuInfoDataView, gpu::GPUInfo> {
260   static bool Read(gpu::mojom::GpuInfoDataView data, gpu::GPUInfo* out);
261 
262   static base::TimeDelta initialization_time(const gpu::GPUInfo& input) {
263     return input.initialization_time;
264   }
265 
266   static bool optimus(const gpu::GPUInfo& input) { return input.optimus; }
267 
268   static bool amd_switchable(const gpu::GPUInfo& input) {
269     return input.amd_switchable;
270   }
271 
272   static const gpu::GPUInfo::GPUDevice& gpu(const gpu::GPUInfo& input) {
273     return input.gpu;
274   }
275 
276   static const std::vector<gpu::GPUInfo::GPUDevice>& secondary_gpus(
277       const gpu::GPUInfo& input) {
278     return input.secondary_gpus;
279   }
280 
281   static const std::string& pixel_shader_version(const gpu::GPUInfo& input) {
282     return input.pixel_shader_version;
283   }
284 
285   static const std::string& vertex_shader_version(const gpu::GPUInfo& input) {
286     return input.vertex_shader_version;
287   }
288 
289   static const std::string& max_msaa_samples(const gpu::GPUInfo& input) {
290     return input.max_msaa_samples;
291   }
292 
293   static const std::string& machine_model_name(const gpu::GPUInfo& input) {
294     return input.machine_model_name;
295   }
296 
297   static const std::string& machine_model_version(const gpu::GPUInfo& input) {
298     return input.machine_model_version;
299   }
300 
301   static const std::string& gl_version(const gpu::GPUInfo& input) {
302     return input.gl_version;
303   }
304 
305   static const std::string& gl_vendor(const gpu::GPUInfo& input) {
306     return input.gl_vendor;
307   }
308 
309   static const std::string& gl_renderer(const gpu::GPUInfo& input) {
310     return input.gl_renderer;
311   }
312 
313   static const std::string& gl_extensions(const gpu::GPUInfo& input) {
314     return input.gl_extensions;
315   }
316 
317   static const std::string& gl_ws_vendor(const gpu::GPUInfo& input) {
318     return input.gl_ws_vendor;
319   }
320 
321   static const std::string& gl_ws_version(const gpu::GPUInfo& input) {
322     return input.gl_ws_version;
323   }
324 
325   static const std::string& gl_ws_extensions(const gpu::GPUInfo& input) {
326     return input.gl_ws_extensions;
327   }
328 
329   static uint32_t gl_reset_notification_strategy(const gpu::GPUInfo& input) {
330     return input.gl_reset_notification_strategy;
331   }
332 
333   static bool software_rendering(const gpu::GPUInfo& input) {
334     return input.software_rendering;
335   }
336 
337   static const std::string& direct_rendering_version(
338       const gpu::GPUInfo& input) {
339     return input.direct_rendering_version;
340   }
341 
342   static bool sandboxed(const gpu::GPUInfo& input) { return input.sandboxed; }
343 
344   static bool in_process_gpu(const gpu::GPUInfo& input) {
345     return input.in_process_gpu;
346   }
347 
348   static bool passthrough_cmd_decoder(const gpu::GPUInfo& input) {
349     return input.passthrough_cmd_decoder;
350   }
351 
352   static bool can_support_threaded_texture_mailbox(const gpu::GPUInfo& input) {
353     return input.can_support_threaded_texture_mailbox;
354   }
355 
356 #if defined(OS_MACOSX)
357   static uint32_t macos_specific_texture_target(const gpu::GPUInfo& input) {
358     return input.macos_specific_texture_target;
359   }
360 #endif  // OS_MACOSX
361 
362 #if defined(OS_WIN)
363 
364   static const gpu::DxDiagNode& dx_diagnostics(const gpu::GPUInfo& input) {
365     return input.dx_diagnostics;
366   }
367 
368   static const gpu::Dx12VulkanVersionInfo& dx12_vulkan_version_info(
369       const gpu::GPUInfo& input) {
370     return input.dx12_vulkan_version_info;
371   }
372 
373   static const gpu::OverlayInfo& overlay_info(const gpu::GPUInfo& input) {
374     return input.overlay_info;
375   }
376 #endif
377 
378   static const gpu::VideoDecodeAcceleratorCapabilities&
379   video_decode_accelerator_capabilities(const gpu::GPUInfo& input) {
380     return input.video_decode_accelerator_capabilities;
381   }
382 
383   static std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>
384   video_encode_accelerator_supported_profiles(const gpu::GPUInfo& input) {
385     return input.video_encode_accelerator_supported_profiles;
386   }
387 
388   static bool jpeg_decode_accelerator_supported(const gpu::GPUInfo& input) {
389     return input.jpeg_decode_accelerator_supported;
390   }
391 
392   static std::vector<gpu::ImageDecodeAcceleratorSupportedProfile>
393   image_decode_accelerator_supported_profiles(const gpu::GPUInfo& input) {
394     return input.image_decode_accelerator_supported_profiles;
395   }
396 
397   static bool oop_rasterization_supported(const gpu::GPUInfo& input) {
398     return input.oop_rasterization_supported;
399   }
400 
401   static bool subpixel_font_rendering(const gpu::GPUInfo& input) {
402     return input.subpixel_font_rendering;
403   }
404 
405 #if BUILDFLAG(ENABLE_VULKAN)
406   static const base::Optional<gpu::VulkanInfo> vulkan_info(
407       const gpu::GPUInfo& input) {
408     return input.vulkan_info;
409   }
410 #endif
411 };
412 
413 }  // namespace mojo
414 #endif  // GPU_IPC_COMMON_GPU_INFO_MOJOM_TRAITS_H_
415