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 "base/export.h" 18 // #include "android/skin/winsys.h" 19 20 #include <stdbool.h> 21 22 // List of values describing how EGL/GLES emulation should work in a given 23 // Android virtual device. 24 // 25 // kAndroidGlesEmulationOff 26 // Means there is no GPU emulation, equivalent to "-gpu off" and instructs 27 // the guest system to use its old GLES 1.x software renderer. 28 // 29 // kAndroidGlesEmulationHost 30 // Means Host GPU emulation is being used. All EGL/GLES commands are 31 // sent to the host GPU or CPU through a simple wire protocol. This 32 // corresponds to "-gpu host" and "-gpu mesa". 33 // 34 // kAndroidGlesEmulationGuest 35 // Means a guest GLES 2.x library (e.g. SwiftShader) is being used in 36 // the guest. This should only be used with accelerated emulation, or 37 // results will be very very slow. 38 typedef enum { 39 kAndroidGlesEmulationOff = 0, 40 kAndroidGlesEmulationHost, 41 kAndroidGlesEmulationGuest, 42 } AndroidGlesEmulationMode; 43 // A small structure used to model the EmuGL configuration 44 // to use. 45 // |enabled| is true if GPU emulation is enabled, false otherwise. 46 // |backend| contains the name of the backend to use, if |enabled| 47 // is true. 48 // |status| is a string used to report error or the current status 49 // of EmuGL emulation. 50 typedef struct { 51 bool enabled; 52 bool use_backend; 53 int bitness; 54 char backend[64]; 55 char status[256]; 56 bool use_host_vulkan; 57 } EmuglConfig; 58 59 // Check whether or not the host GPU is blacklisted. If so, fall back 60 // to software rendering. 61 bool isHostGpuBlacklisted(); 62 63 typedef struct { 64 char* make; 65 char* model; 66 char* device_id; 67 char* revision_id; 68 char* version; 69 char* renderer; 70 } emugl_host_gpu_props; 71 72 typedef struct { 73 int num_gpus; 74 emugl_host_gpu_props* props; 75 } emugl_host_gpu_prop_list; 76 77 // Get a description of host GPU properties. 78 // Need to free after use. 79 emugl_host_gpu_prop_list emuglConfig_get_host_gpu_props(); 80 81 // Enum tracking all current available renderer backends 82 // for the emulator. 83 typedef enum SelectedRenderer { 84 SELECTED_RENDERER_UNKNOWN = 0, 85 SELECTED_RENDERER_HOST = 1, 86 SELECTED_RENDERER_OFF = 2, 87 SELECTED_RENDERER_GUEST = 3, 88 SELECTED_RENDERER_MESA = 4, 89 SELECTED_RENDERER_SWIFTSHADER = 5, 90 SELECTED_RENDERER_ANGLE = 6, // ANGLE D3D11 with D3D9 fallback 91 SELECTED_RENDERER_ANGLE9 = 7, // ANGLE forced to D3D9 92 SELECTED_RENDERER_SWIFTSHADER_INDIRECT = 8, 93 SELECTED_RENDERER_ANGLE_INDIRECT = 9, 94 SELECTED_RENDERER_ANGLE9_INDIRECT = 10, 95 SELECTED_RENDERER_ERROR = 255, 96 } SelectedRenderer; 97 98 // Returns SelectedRenderer value the selected gpu mode. 99 // Assumes that the -gpu command line option 100 // has been taken into account already. 101 SelectedRenderer emuglConfig_get_renderer(const char* gpu_mode); 102 103 // Returns the renderer that is active, after config is done. 104 SelectedRenderer emuglConfig_get_current_renderer(); 105 106 // Returns a string representation of the renderer enum. Return value is a 107 // static constant string, it is NOT heap-allocated. 108 const char* emuglConfig_renderer_to_string(SelectedRenderer renderer); 109 110 // Returns if the current renderer supports snapshot. 111 bool emuglConfig_current_renderer_supports_snapshot(); 112 113 void free_emugl_host_gpu_props(emugl_host_gpu_prop_list props); 114 115 // Initialize an EmuglConfig instance based on the AVD's hardware properties 116 // and the command-line -gpu option, if any. 117 // 118 // |config| is the instance to initialize. 119 // |gpu_enabled| is the value of the hw.gpu.enabled hardware property. 120 // |gpu_mode| is the value of the hw.gpu.mode hardware property. 121 // |gpu_option| is the value of the '-gpu <mode>' option, or NULL. 122 // |bitness| is the host bitness (0, 32 or 64). 123 // |no_window| is true if the '-no-window' emulator flag was used. 124 // |blacklisted| is true if the GPU driver is on the list of 125 // crashy GPU drivers. 126 // |use_host_vulkan| is true if the '-use-host-vulkan' emulator flag was used. 127 // 128 // Returns true on success, or false if there was an error (e.g. bad 129 // mode or option value), in which case the |status| field will contain 130 // a small error message. 131 AEMU_EXPORT bool emuglConfig_init(EmuglConfig* config, 132 bool gpu_enabled, 133 const char* gpu_mode, 134 const char* gpu_option, 135 int bitness, 136 bool no_window, 137 bool blacklisted, 138 bool google_apis, 139 int uiPreferredBackend, 140 bool use_host_vulkan); 141 142 // Setup GPU emulation according to a given |backend|. 143 // |bitness| is the host bitness, and can be 0 (autodetect), 32 or 64. 144 AEMU_EXPORT void emuglConfig_setupEnv(const EmuglConfig* config); 145