Android-cuttlefish cvd tool
gpu_mode.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <string>
20#include <string_view>
21
23
24namespace cuttlefish {
25
26enum class GpuMode {
27 Auto,
28 Custom,
36 None,
37};
38
39inline constexpr std::string_view kGpuModeAuto = "auto";
40inline constexpr std::string_view kGpuModeCustom = "custom";
41inline constexpr std::string_view kGpuModeDrmVirgl = "drm_virgl";
42inline constexpr std::string_view kGpuModeGfxstream = "gfxstream";
43inline constexpr std::string_view kGpuModeGfxstreamGuestAngle =
44 "gfxstream_guest_angle";
45inline constexpr std::string_view kGpuModeGfxstreamGuestAngleHostLavapipe =
46 "gfxstream_guest_angle_host_lavapipe";
47inline constexpr std::string_view kGpuModeGfxstreamGuestAngleHostSwiftshader =
48 "gfxstream_guest_angle_host_swiftshader";
49inline constexpr std::string_view kGpuModeGuestLavapipe = "guest_lavapipe";
50inline constexpr std::string_view kGpuModeGuestSwiftshader =
51 "guest_swiftshader";
52inline constexpr std::string_view kGpuModeNone = "none";
53
54template <typename Sink>
55void AbslStringify(Sink& sink, GpuMode mode) {
56 switch (mode) {
57 case GpuMode::Auto:
58 sink.Append(kGpuModeAuto);
59 break;
60 case GpuMode::Custom:
61 sink.Append(kGpuModeCustom);
62 break;
64 sink.Append(kGpuModeDrmVirgl);
65 break;
67 sink.Append(kGpuModeGfxstream);
68 break;
70 sink.Append(kGpuModeGfxstreamGuestAngle);
71 break;
74 break;
77 break;
79 sink.Append(kGpuModeGuestLavapipe);
80 break;
82 sink.Append(kGpuModeGuestSwiftshader);
83 break;
84 case GpuMode::None:
85 sink.Append(kGpuModeNone);
86 break;
87 }
88}
89
90Result<GpuMode> GpuModeFromString(std::string_view mode);
91std::string GpuModeString(GpuMode mode);
92std::string_view format_as(GpuMode mode); // For libfmt
93
94bool IsGfxstreamMode(GpuMode mode);
96
98
99} // namespace cuttlefish
Definition: alloc_driver.h:20
constexpr std::string_view kGpuModeDrmVirgl
Definition: gpu_mode.h:41
constexpr std::string_view kGpuModeGuestLavapipe
Definition: gpu_mode.h:49
void AbslStringify(Sink &sink, DeviceType device_type)
Definition: device_type.h:42
std::string GpuModeString(GpuMode mode)
Definition: gpu_mode.cc:54
constexpr std::string_view kGpuModeAuto
Definition: gpu_mode.h:39
constexpr std::string_view kGpuModeGuestSwiftshader
Definition: gpu_mode.h:50
bool IsGfxstreamGuestAngleMode(GpuMode mode)
Definition: gpu_mode.cc:95
constexpr std::string_view kGpuModeCustom
Definition: gpu_mode.h:40
Result< GpuMode > GpuModeFromString(std::string_view mode)
Definition: gpu_mode.cc:28
constexpr std::string_view kGpuModeGfxstreamGuestAngleHostLavapipe
Definition: gpu_mode.h:45
bool IsGuestRenderingMode(GpuMode mode)
Definition: gpu_mode.cc:101
constexpr std::string_view kGpuModeGfxstreamGuestAngle
Definition: gpu_mode.h:43
bool IsGfxstreamMode(GpuMode mode)
Definition: gpu_mode.cc:89
constexpr std::string_view kGpuModeNone
Definition: gpu_mode.h:52
constexpr std::string_view kGpuModeGfxstream
Definition: gpu_mode.h:42
std::string_view format_as(DeviceType device_type)
Definition: device_type.cpp:76
constexpr std::string_view kGpuModeGfxstreamGuestAngleHostSwiftshader
Definition: gpu_mode.h:47
GpuMode
Definition: gpu_mode.h:26