• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include "aemu/base/c_header.h"
18 #include "aemu/base/export.h"
19 // #include "android/skin/winsys.h"
20 
21 #include <stdbool.h>
22 
23 ANDROID_BEGIN_HEADER
24 
25 // List of values describing how EGL/GLES emulation should work in a given
26 // Android virtual device.
27 //
28 // kAndroidGlesEmulationOff
29 //    Means there is no GPU emulation, equivalent to "-gpu off" and instructs
30 //    the guest system to use its old GLES 1.x software renderer.
31 //
32 // kAndroidGlesEmulationHost
33 //    Means Host GPU emulation is being used. All EGL/GLES commands are
34 //    sent to the host GPU or CPU through a simple wire protocol. This
35 //    corresponds to "-gpu host" and "-gpu mesa".
36 //
37 // kAndroidGlesEmulationGuest
38 //    Means a guest GLES 2.x library (e.g. SwiftShader) is being used in
39 //    the guest. This should only be used with accelerated emulation, or
40 //    results will be very very slow.
41 typedef enum {
42     kAndroidGlesEmulationOff = 0,
43     kAndroidGlesEmulationHost,
44     kAndroidGlesEmulationGuest,
45 } AndroidGlesEmulationMode;
46 // A small structure used to model the EmuGL configuration
47 // to use.
48 // |enabled| is true if GPU emulation is enabled, false otherwise.
49 // |backend| contains the name of the backend to use, if |enabled|
50 // is true.
51 // |status| is a string used to report error or the current status
52 // of EmuGL emulation.
53 typedef struct {
54     bool enabled;
55     bool use_backend;
56     int bitness;
57     char backend[64];
58     char status[256];
59     bool use_host_vulkan;
60 } EmuglConfig;
61 
62 // Check whether or not the host GPU is blacklisted. If so, fall back
63 // to software rendering.
64 bool isHostGpuBlacklisted();
65 
66 typedef struct {
67     char* make;
68     char* model;
69     char* device_id;
70     char* revision_id;
71     char* version;
72     char* renderer;
73 } emugl_host_gpu_props;
74 
75 typedef struct {
76     int num_gpus;
77     emugl_host_gpu_props* props;
78 } emugl_host_gpu_prop_list;
79 
80 // Get a description of host GPU properties.
81 // Need to free after use.
82 emugl_host_gpu_prop_list emuglConfig_get_host_gpu_props();
83 
84 // Enum tracking all current available renderer backends
85 // for the emulator.
86 typedef enum SelectedRenderer {
87     SELECTED_RENDERER_UNKNOWN = 0,
88     SELECTED_RENDERER_HOST = 1,
89     SELECTED_RENDERER_OFF = 2,
90     SELECTED_RENDERER_GUEST = 3,
91     SELECTED_RENDERER_MESA = 4,
92     SELECTED_RENDERER_SWIFTSHADER = 5,
93     SELECTED_RENDERER_ANGLE = 6, // ANGLE D3D11 with D3D9 fallback
94     SELECTED_RENDERER_ANGLE9 = 7, // ANGLE forced to D3D9
95     SELECTED_RENDERER_SWIFTSHADER_INDIRECT = 8,
96     SELECTED_RENDERER_ANGLE_INDIRECT = 9,
97     SELECTED_RENDERER_ANGLE9_INDIRECT = 10,
98     SELECTED_RENDERER_ERROR = 255,
99 } SelectedRenderer;
100 
101 enum GrallocImplementation { MINIGBM, GOLDFISH_GRALLOC };
102 
103 // Returns SelectedRenderer value the selected gpu mode.
104 // Assumes that the -gpu command line option
105 // has been taken into account already.
106 SelectedRenderer emuglConfig_get_renderer(const char* gpu_mode);
107 
108 // Returns the renderer that is active, after config is done.
109 SelectedRenderer emuglConfig_get_current_renderer();
110 
111 // Returns the '-gpu <mode>' option. If '-gpu <mode>' option is NULL, returns
112 // the hw.gpu.mode hardware property.
113 const char* emuglConfig_get_user_gpu_option();
114 
115 void emuglConfig_get_vulkan_hardware_gpu(char** vendor, int* major, int* minor,
116         int* patch);
117 
118 // Returns a string representation of the renderer enum. Return value is a
119 // static constant string, it is NOT heap-allocated.
120 const char* emuglConfig_renderer_to_string(SelectedRenderer renderer);
121 
122 // Returns if the current renderer supports snapshot.
123 bool emuglConfig_current_renderer_supports_snapshot();
124 
125 void free_emugl_host_gpu_props(emugl_host_gpu_prop_list props);
126 
127 // Initialize an EmuglConfig instance based on the AVD's hardware properties
128 // and the command-line -gpu option, if any.
129 //
130 // |config| is the instance to initialize.
131 // |gpu_enabled| is the value of the hw.gpu.enabled hardware property.
132 // |gpu_mode| is the value of the hw.gpu.mode hardware property.
133 // |gpu_option| is the value of the '-gpu <mode>' option, or NULL.
134 // |bitness| is the host bitness (0, 32 or 64).
135 // |no_window| is true if the '-no-window' emulator flag was used.
136 // |blacklisted| is true if the GPU driver is on the list of
137 // crashy GPU drivers.
138 // |use_host_vulkan| is true if the '-use-host-vulkan' emulator flag was used.
139 //
140 // Returns true on success, or false if there was an error (e.g. bad
141 // mode or option value), in which case the |status| field will contain
142 // a small error message.
143 AEMU_EXPORT bool emuglConfig_init(EmuglConfig* config,
144                                   bool gpu_enabled,
145                                   const char* gpu_mode,
146                                   const char* gpu_option,
147                                   int bitness,
148                                   bool no_window,
149                                   bool blacklisted,
150                                   bool google_apis,
151                                   int uiPreferredBackend,
152                                   bool use_host_vulkan);
153 
154 // Setup GPU emulation according to a given |backend|.
155 // |bitness| is the host bitness, and can be 0 (autodetect), 32 or 64.
156 AEMU_EXPORT void emuglConfig_setupEnv(const EmuglConfig* config);
157 
158 ANDROID_END_HEADER
159