1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
gpu / ipc / common / gpu_preferences_mojom_traits.h [blame]
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GPU_IPC_COMMON_GPU_PREFERENCES_MOJOM_TRAITS_H_
#define GPU_IPC_COMMON_GPU_PREFERENCES_MOJOM_TRAITS_H_
#include <vector>
#include "base/notreached.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "gpu/config/gpu_preferences.h"
#include "gpu/gpu_export.h"
#include "gpu/ipc/common/gpu_preferences.mojom-shared.h"
#if BUILDFLAG(IS_OZONE)
#include "base/message_loop/message_pump_type.h"
#include "mojo/public/cpp/base/message_pump_type_mojom_traits.h"
#endif
namespace mojo {
template <>
struct GPU_EXPORT EnumTraits<gpu::mojom::GrContextType, gpu::GrContextType> {
static gpu::mojom::GrContextType ToMojom(gpu::GrContextType input) {
switch (input) {
case gpu::GrContextType::kNone:
return gpu::mojom::GrContextType::kNone;
case gpu::GrContextType::kGL:
return gpu::mojom::GrContextType::kGL;
case gpu::GrContextType::kVulkan:
return gpu::mojom::GrContextType::kVulkan;
case gpu::GrContextType::kGraphiteDawn:
return gpu::mojom::GrContextType::kGraphiteDawn;
case gpu::GrContextType::kGraphiteMetal:
return gpu::mojom::GrContextType::kGraphiteMetal;
}
NOTREACHED();
}
static bool FromMojom(gpu::mojom::GrContextType input,
gpu::GrContextType* out) {
switch (input) {
case gpu::mojom::GrContextType::kNone:
*out = gpu::GrContextType::kNone;
return true;
case gpu::mojom::GrContextType::kGL:
*out = gpu::GrContextType::kGL;
return true;
case gpu::mojom::GrContextType::kVulkan:
*out = gpu::GrContextType::kVulkan;
return true;
case gpu::mojom::GrContextType::kGraphiteDawn:
*out = gpu::GrContextType::kGraphiteDawn;
return true;
case gpu::mojom::GrContextType::kGraphiteMetal:
*out = gpu::GrContextType::kGraphiteMetal;
return true;
}
return false;
}
};
template <>
struct GPU_EXPORT EnumTraits<gpu::mojom::VulkanImplementationName,
gpu::VulkanImplementationName> {
static gpu::mojom::VulkanImplementationName ToMojom(
gpu::VulkanImplementationName input) {
switch (input) {
case gpu::VulkanImplementationName::kNone:
return gpu::mojom::VulkanImplementationName::kNone;
case gpu::VulkanImplementationName::kNative:
return gpu::mojom::VulkanImplementationName::kNative;
case gpu::VulkanImplementationName::kForcedNative:
return gpu::mojom::VulkanImplementationName::kForcedNative;
case gpu::VulkanImplementationName::kSwiftshader:
return gpu::mojom::VulkanImplementationName::kSwiftshader;
}
NOTREACHED();
}
static bool FromMojom(gpu::mojom::VulkanImplementationName input,
gpu::VulkanImplementationName* out) {
switch (input) {
case gpu::mojom::VulkanImplementationName::kNone:
*out = gpu::VulkanImplementationName::kNone;
return true;
case gpu::mojom::VulkanImplementationName::kNative:
*out = gpu::VulkanImplementationName::kNative;
return true;
case gpu::mojom::VulkanImplementationName::kForcedNative:
*out = gpu::VulkanImplementationName::kForcedNative;
return true;
case gpu::mojom::VulkanImplementationName::kSwiftshader:
*out = gpu::VulkanImplementationName::kSwiftshader;
return true;
}
return false;
}
};
template <>
struct GPU_EXPORT
EnumTraits<gpu::mojom::WebGPUAdapterName, gpu::WebGPUAdapterName> {
static gpu::mojom::WebGPUAdapterName ToMojom(gpu::WebGPUAdapterName input) {
switch (input) {
case gpu::WebGPUAdapterName::kDefault:
return gpu::mojom::WebGPUAdapterName::kDefault;
case gpu::WebGPUAdapterName::kD3D11:
return gpu::mojom::WebGPUAdapterName::kD3D11;
case gpu::WebGPUAdapterName::kOpenGLES:
return gpu::mojom::WebGPUAdapterName::kOpenGLES;
case gpu::WebGPUAdapterName::kSwiftShader:
return gpu::mojom::WebGPUAdapterName::kSwiftShader;
}
NOTREACHED();
}
static bool FromMojom(gpu::mojom::WebGPUAdapterName input,
gpu::WebGPUAdapterName* out) {
switch (input) {
case gpu::mojom::WebGPUAdapterName::kDefault:
*out = gpu::WebGPUAdapterName::kDefault;
return true;
case gpu::mojom::WebGPUAdapterName::kD3D11:
*out = gpu::WebGPUAdapterName::kD3D11;
return true;
case gpu::mojom::WebGPUAdapterName::kOpenGLES:
*out = gpu::WebGPUAdapterName::kOpenGLES;
return true;
case gpu::mojom::WebGPUAdapterName::kSwiftShader:
*out = gpu::WebGPUAdapterName::kSwiftShader;
return true;
}
return false;
}
};
template <>
struct GPU_EXPORT
EnumTraits<gpu::mojom::WebGPUPowerPreference, gpu::WebGPUPowerPreference> {
static gpu::mojom::WebGPUPowerPreference ToMojom(
gpu::WebGPUPowerPreference input) {
switch (input) {
case gpu::WebGPUPowerPreference::kNone:
return gpu::mojom::WebGPUPowerPreference::kNone;
case gpu::WebGPUPowerPreference::kDefaultLowPower:
return gpu::mojom::WebGPUPowerPreference::kDefaultLowPower;
case gpu::WebGPUPowerPreference::kDefaultHighPerformance:
return gpu::mojom::WebGPUPowerPreference::kDefaultHighPerformance;
case gpu::WebGPUPowerPreference::kForceLowPower:
return gpu::mojom::WebGPUPowerPreference::kForceLowPower;
case gpu::WebGPUPowerPreference::kForceHighPerformance:
return gpu::mojom::WebGPUPowerPreference::kForceHighPerformance;
}
NOTREACHED();
}
static bool FromMojom(gpu::mojom::WebGPUPowerPreference input,
gpu::WebGPUPowerPreference* out) {
switch (input) {
case gpu::mojom::WebGPUPowerPreference::kNone:
*out = gpu::WebGPUPowerPreference::kNone;
return true;
case gpu::mojom::WebGPUPowerPreference::kDefaultLowPower:
*out = gpu::WebGPUPowerPreference::kDefaultLowPower;
return true;
case gpu::mojom::WebGPUPowerPreference::kDefaultHighPerformance:
*out = gpu::WebGPUPowerPreference::kDefaultHighPerformance;
return true;
case gpu::mojom::WebGPUPowerPreference::kForceLowPower:
*out = gpu::WebGPUPowerPreference::kForceLowPower;
return true;
case gpu::mojom::WebGPUPowerPreference::kForceHighPerformance:
*out = gpu::WebGPUPowerPreference::kForceHighPerformance;
return true;
}
return false;
}
};
template <>
struct GPU_EXPORT EnumTraits<gpu::mojom::DawnBackendValidationLevel,
gpu::DawnBackendValidationLevel> {
static gpu::mojom::DawnBackendValidationLevel ToMojom(
gpu::DawnBackendValidationLevel input) {
switch (input) {
case gpu::DawnBackendValidationLevel::kDisabled:
return gpu::mojom::DawnBackendValidationLevel::kDisabled;
case gpu::DawnBackendValidationLevel::kPartial:
return gpu::mojom::DawnBackendValidationLevel::kPartial;
case gpu::DawnBackendValidationLevel::kFull:
return gpu::mojom::DawnBackendValidationLevel::kFull;
}
NOTREACHED();
}
static bool FromMojom(gpu::mojom::DawnBackendValidationLevel input,
gpu::DawnBackendValidationLevel* out) {
switch (input) {
case gpu::mojom::DawnBackendValidationLevel::kDisabled:
*out = gpu::DawnBackendValidationLevel::kDisabled;
return true;
case gpu::mojom::DawnBackendValidationLevel::kPartial:
*out = gpu::DawnBackendValidationLevel::kPartial;
return true;
case gpu::mojom::DawnBackendValidationLevel::kFull:
*out = gpu::DawnBackendValidationLevel::kFull;
return true;
}
return false;
}
};
template <>
struct GPU_EXPORT
StructTraits<gpu::mojom::GpuPreferencesDataView, gpu::GpuPreferences> {
static bool Read(gpu::mojom::GpuPreferencesDataView prefs,
gpu::GpuPreferences* out) {
out->disable_accelerated_video_decode =
prefs.disable_accelerated_video_decode();
out->disable_accelerated_video_encode =
prefs.disable_accelerated_video_encode();
out->gpu_startup_dialog = prefs.gpu_startup_dialog();
out->disable_gpu_watchdog = prefs.disable_gpu_watchdog();
out->gpu_sandbox_start_early = prefs.gpu_sandbox_start_early();
out->enable_low_latency_dxva = prefs.enable_low_latency_dxva();
out->enable_zero_copy_dxgi_video = prefs.enable_zero_copy_dxgi_video();
out->enable_nv12_dxgi_video = prefs.enable_nv12_dxgi_video();
out->disable_software_rasterizer = prefs.disable_software_rasterizer();
out->log_gpu_control_list_decisions =
prefs.log_gpu_control_list_decisions();
out->compile_shader_always_succeeds =
prefs.compile_shader_always_succeeds();
out->disable_gl_error_limit = prefs.disable_gl_error_limit();
out->disable_glsl_translator = prefs.disable_glsl_translator();
out->disable_shader_name_hashing = prefs.disable_shader_name_hashing();
out->enable_gpu_command_logging = prefs.enable_gpu_command_logging();
out->enable_gpu_debugging = prefs.enable_gpu_debugging();
out->enable_gpu_service_logging_gpu =
prefs.enable_gpu_service_logging_gpu();
out->enable_gpu_driver_debug_logging =
prefs.enable_gpu_driver_debug_logging();
out->disable_gpu_program_cache = prefs.disable_gpu_program_cache();
out->enforce_gl_minimums = prefs.enforce_gl_minimums();
out->force_gpu_mem_available_bytes = prefs.force_gpu_mem_available_bytes();
out->force_gpu_mem_discardable_limit_bytes =
prefs.force_gpu_mem_discardable_limit_bytes();
out->force_max_texture_size = prefs.force_max_texture_size();
out->gpu_program_cache_size = prefs.gpu_program_cache_size();
out->disable_gpu_shader_disk_cache = prefs.disable_gpu_shader_disk_cache();
out->enable_threaded_texture_mailboxes =
prefs.enable_threaded_texture_mailboxes();
out->gl_shader_interm_output = prefs.gl_shader_interm_output();
out->enable_android_surface_control =
prefs.enable_android_surface_control();
out->enable_gpu_service_logging = prefs.enable_gpu_service_logging();
out->enable_gpu_service_tracing = prefs.enable_gpu_service_tracing();
out->use_passthrough_cmd_decoder = prefs.use_passthrough_cmd_decoder();
out->ignore_gpu_blocklist = prefs.ignore_gpu_blocklist();
out->watchdog_starts_backgrounded = prefs.watchdog_starts_backgrounded();
if (!prefs.ReadGrContextType(&out->gr_context_type)) {
return false;
}
if (!prefs.ReadUseVulkan(&out->use_vulkan)) {
return false;
}
out->enable_vulkan_protected_memory =
prefs.enable_vulkan_protected_memory();
out->disable_vulkan_surface = prefs.disable_vulkan_surface();
out->disable_vulkan_fallback_to_gl_for_testing =
prefs.disable_vulkan_fallback_to_gl_for_testing();
out->vulkan_heap_memory_limit = prefs.vulkan_heap_memory_limit();
out->vulkan_sync_cpu_memory_limit = prefs.vulkan_sync_cpu_memory_limit();
out->enable_gpu_benchmarking_extension =
prefs.enable_gpu_benchmarking_extension();
out->enable_webgpu = prefs.enable_webgpu();
out->enable_unsafe_webgpu = prefs.enable_unsafe_webgpu();
out->enable_webgpu_developer_features =
prefs.enable_webgpu_developer_features();
out->enable_webgpu_experimental_features =
prefs.enable_webgpu_experimental_features();
if (!prefs.ReadUseWebgpuAdapter(&out->use_webgpu_adapter))
return false;
if (!prefs.ReadUseWebgpuPowerPreference(
&out->use_webgpu_power_preference)) {
return false;
}
out->force_webgpu_compat = prefs.force_webgpu_compat();
if (!prefs.ReadEnableDawnBackendValidation(
&out->enable_dawn_backend_validation))
return false;
if (!prefs.ReadEnabledDawnFeaturesList(&out->enabled_dawn_features_list))
return false;
if (!prefs.ReadDisabledDawnFeaturesList(&out->disabled_dawn_features_list))
return false;
out->enable_perf_data_collection = prefs.enable_perf_data_collection();
#if BUILDFLAG(IS_OZONE)
if (!prefs.ReadMessagePumpType(&out->message_pump_type))
return false;
#endif
out->enable_native_gpu_memory_buffers =
prefs.enable_native_gpu_memory_buffers();
out->force_separate_egl_display_for_webgl_testing =
prefs.force_separate_egl_display_for_webgl_testing();
return true;
}
static bool disable_accelerated_video_decode(
const gpu::GpuPreferences& prefs) {
return prefs.disable_accelerated_video_decode;
}
static bool disable_accelerated_video_encode(
const gpu::GpuPreferences& prefs) {
return prefs.disable_accelerated_video_encode;
}
static bool gpu_startup_dialog(const gpu::GpuPreferences& prefs) {
return prefs.gpu_startup_dialog;
}
static bool disable_gpu_watchdog(const gpu::GpuPreferences& prefs) {
return prefs.disable_gpu_watchdog;
}
static bool gpu_sandbox_start_early(const gpu::GpuPreferences& prefs) {
return prefs.gpu_sandbox_start_early;
}
static bool enable_low_latency_dxva(const gpu::GpuPreferences& prefs) {
return prefs.enable_low_latency_dxva;
}
static bool enable_zero_copy_dxgi_video(const gpu::GpuPreferences& prefs) {
return prefs.enable_zero_copy_dxgi_video;
}
static bool enable_nv12_dxgi_video(const gpu::GpuPreferences& prefs) {
return prefs.enable_nv12_dxgi_video;
}
static bool disable_software_rasterizer(const gpu::GpuPreferences& prefs) {
return prefs.disable_software_rasterizer;
}
static bool log_gpu_control_list_decisions(const gpu::GpuPreferences& prefs) {
return prefs.log_gpu_control_list_decisions;
}
static bool compile_shader_always_succeeds(const gpu::GpuPreferences& prefs) {
return prefs.compile_shader_always_succeeds;
}
static bool disable_gl_error_limit(const gpu::GpuPreferences& prefs) {
return prefs.disable_gl_error_limit;
}
static bool disable_glsl_translator(const gpu::GpuPreferences& prefs) {
return prefs.disable_glsl_translator;
}
static bool disable_shader_name_hashing(const gpu::GpuPreferences& prefs) {
return prefs.disable_shader_name_hashing;
}
static bool enable_gpu_command_logging(const gpu::GpuPreferences& prefs) {
return prefs.enable_gpu_command_logging;
}
static bool enable_gpu_debugging(const gpu::GpuPreferences& prefs) {
return prefs.enable_gpu_debugging;
}
static bool enable_gpu_service_logging_gpu(const gpu::GpuPreferences& prefs) {
return prefs.enable_gpu_service_logging_gpu;
}
static bool enable_gpu_driver_debug_logging(
const gpu::GpuPreferences& prefs) {
return prefs.enable_gpu_driver_debug_logging;
}
static bool disable_gpu_program_cache(const gpu::GpuPreferences& prefs) {
return prefs.disable_gpu_program_cache;
}
static bool enforce_gl_minimums(const gpu::GpuPreferences& prefs) {
return prefs.enforce_gl_minimums;
}
static uint32_t force_gpu_mem_available_bytes(
const gpu::GpuPreferences& prefs) {
return prefs.force_gpu_mem_available_bytes;
}
static uint32_t force_gpu_mem_discardable_limit_bytes(
const gpu::GpuPreferences& prefs) {
return prefs.force_gpu_mem_discardable_limit_bytes;
}
static uint32_t force_max_texture_size(const gpu::GpuPreferences& prefs) {
return prefs.force_max_texture_size;
}
static uint32_t gpu_program_cache_size(const gpu::GpuPreferences& prefs) {
return prefs.gpu_program_cache_size;
}
static bool disable_gpu_shader_disk_cache(const gpu::GpuPreferences& prefs) {
return prefs.disable_gpu_shader_disk_cache;
}
static bool enable_threaded_texture_mailboxes(
const gpu::GpuPreferences& prefs) {
return prefs.enable_threaded_texture_mailboxes;
}
static bool gl_shader_interm_output(const gpu::GpuPreferences& prefs) {
return prefs.gl_shader_interm_output;
}
static bool enable_android_surface_control(const gpu::GpuPreferences& prefs) {
return prefs.enable_android_surface_control;
}
static bool enable_gpu_service_logging(const gpu::GpuPreferences& prefs) {
return prefs.enable_gpu_service_logging;
}
static bool enable_gpu_service_tracing(const gpu::GpuPreferences& prefs) {
return prefs.enable_gpu_service_tracing;
}
static bool use_passthrough_cmd_decoder(const gpu::GpuPreferences& prefs) {
return prefs.use_passthrough_cmd_decoder;
}
static bool ignore_gpu_blocklist(const gpu::GpuPreferences& prefs) {
return prefs.ignore_gpu_blocklist;
}
static bool watchdog_starts_backgrounded(const gpu::GpuPreferences& prefs) {
return prefs.watchdog_starts_backgrounded;
}
static gpu::GrContextType gr_context_type(const gpu::GpuPreferences& prefs) {
return prefs.gr_context_type;
}
static gpu::VulkanImplementationName use_vulkan(
const gpu::GpuPreferences& prefs) {
return prefs.use_vulkan;
}
static bool enable_vulkan_protected_memory(const gpu::GpuPreferences& prefs) {
return prefs.enable_vulkan_protected_memory;
}
static bool disable_vulkan_surface(const gpu::GpuPreferences& prefs) {
return prefs.disable_vulkan_surface;
}
static bool disable_vulkan_fallback_to_gl_for_testing(
const gpu::GpuPreferences& prefs) {
return prefs.disable_vulkan_fallback_to_gl_for_testing;
}
static uint32_t vulkan_heap_memory_limit(const gpu::GpuPreferences& prefs) {
return prefs.vulkan_heap_memory_limit;
}
static uint32_t vulkan_sync_cpu_memory_limit(
const gpu::GpuPreferences& prefs) {
return prefs.vulkan_sync_cpu_memory_limit;
}
static bool enable_gpu_benchmarking_extension(
const gpu::GpuPreferences& prefs) {
return prefs.enable_gpu_benchmarking_extension;
}
static bool enable_webgpu(const gpu::GpuPreferences& prefs) {
return prefs.enable_webgpu;
}
static bool enable_unsafe_webgpu(const gpu::GpuPreferences& prefs) {
return prefs.enable_unsafe_webgpu;
}
static bool enable_webgpu_developer_features(
const gpu::GpuPreferences& prefs) {
return prefs.enable_webgpu_developer_features;
}
static bool enable_webgpu_experimental_features(
const gpu::GpuPreferences& prefs) {
return prefs.enable_webgpu_experimental_features;
}
static gpu::WebGPUAdapterName use_webgpu_adapter(
const gpu::GpuPreferences& prefs) {
return prefs.use_webgpu_adapter;
}
static gpu::WebGPUPowerPreference use_webgpu_power_preference(
const gpu::GpuPreferences& prefs) {
return prefs.use_webgpu_power_preference;
}
static bool force_webgpu_compat(const gpu::GpuPreferences& prefs) {
return prefs.force_webgpu_compat;
}
static gpu::DawnBackendValidationLevel enable_dawn_backend_validation(
const gpu::GpuPreferences& prefs) {
return prefs.enable_dawn_backend_validation;
}
static const std::vector<std::string>& enabled_dawn_features_list(
const gpu::GpuPreferences& prefs) {
return prefs.enabled_dawn_features_list;
}
static const std::vector<std::string>& disabled_dawn_features_list(
const gpu::GpuPreferences& prefs) {
return prefs.disabled_dawn_features_list;
}
static bool enable_perf_data_collection(const gpu::GpuPreferences& prefs) {
return prefs.enable_perf_data_collection;
}
#if BUILDFLAG(IS_OZONE)
static base::MessagePumpType message_pump_type(
const gpu::GpuPreferences& prefs) {
return prefs.message_pump_type;
}
#endif
static bool enable_native_gpu_memory_buffers(
const gpu::GpuPreferences& prefs) {
return prefs.enable_native_gpu_memory_buffers;
}
static bool force_separate_egl_display_for_webgl_testing(
const gpu::GpuPreferences& prefs) {
return prefs.force_separate_egl_display_for_webgl_testing;
}
};
} // namespace mojo
#endif // GPU_IPC_COMMON_GPU_PREFERENCES_MOJOM_TRAITS_H_