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