| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
| Mathias Agopian | 991d254 | 2017-02-06 13:51:32 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_UI_GRAPHICS_ENV_H |
| 18 | #define ANDROID_UI_GRAPHICS_ENV_H 1 |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 19 | |
| Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 20 | #include <graphicsenv/GpuStatsInfo.h> |
| 21 | |
| Cody Northrop | 3892cfa | 2019-01-30 10:03:12 -0700 | [diff] [blame] | 22 | #include <mutex> |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 23 | #include <string> |
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 24 | #include <vector> |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 25 | |
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 26 | struct android_namespace_t; |
| 27 | |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 28 | namespace android { |
| 29 | |
| Nicolas Geoffray | a655dac | 2019-01-11 15:59:42 +0000 | [diff] [blame] | 30 | struct NativeLoaderNamespace; |
| Victor Khimenko | 4819b52 | 2018-07-13 17:24:18 +0200 | [diff] [blame] | 31 | |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 32 | class GraphicsEnv { |
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 33 | public: |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 34 | static GraphicsEnv& getInstance(); |
| 35 | |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 36 | // Check if device is debuggable. |
| Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 37 | int getCanLoadSystemLibraries(); |
| 38 | |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 39 | /* |
| 40 | * Apis for updatable driver |
| 41 | */ |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 42 | // Set a search path for loading graphics drivers. The path is a list of |
| 43 | // directories separated by ':'. A directory can be contained in a zip file |
| 44 | // (drivers must be stored uncompressed and page aligned); such elements |
| 45 | // in the search path must have a '!' after the zip filename, e.g. |
| 46 | // /data/app/com.example.driver/base.apk!/lib/arm64-v8a |
| Yiwei Zhang | 6ef8494 | 2019-02-14 12:28:12 -0800 | [diff] [blame] | 47 | // Also set additional required sphal libraries to the linker for loading |
| 48 | // graphics drivers. The string is a list of libraries separated by ':', |
| 49 | // which is required by android_link_namespaces. |
| 50 | void setDriverPathAndSphalLibraries(const std::string path, const std::string sphalLibraries); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 51 | // Get the updatable driver namespace. |
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 52 | android_namespace_t* getDriverNamespace(); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * Apis for GpuStats |
| 56 | */ |
| 57 | // Hint there's real activity launching on the app process. |
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 58 | void hintActivityLaunch(); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 59 | // Set the initial GpuStats. |
| Greg Kaiser | 210bb7e | 2019-02-12 12:40:05 -0800 | [diff] [blame] | 60 | void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName, |
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 61 | uint64_t versionCode, int64_t driverBuildTime, |
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 62 | const std::string& appPackageName, const int32_t vulkanVersion); |
| Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 63 | // Set stats for target GpuStatsInfo::Stats type. |
| 64 | void setTargetStats(const GpuStatsInfo::Stats stats, const uint64_t value = 0); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 65 | // Set which driver is intended to load. |
| Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 66 | void setDriverToLoad(GpuStatsInfo::Driver driver); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 67 | // Set which driver is actually loaded. |
| Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 68 | void setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime); |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 69 | |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 70 | /* |
| Adam Bodnar | 0afcca0 | 2019-09-17 13:23:17 -0700 | [diff] [blame] | 71 | * Api for Vk/GL layer injection. Presently, drivers enable certain |
| 72 | * profiling features when prctl(PR_GET_DUMPABLE) returns true. |
| 73 | * Calling this when layer injection metadata is present allows the driver |
| 74 | * to enable profiling even when in a non-debuggable app |
| 75 | */ |
| 76 | bool setInjectLayersPrSetDumpable(); |
| 77 | |
| 78 | /* |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 79 | * Apis for ANGLE |
| 80 | */ |
| 81 | // Check if the requested app should use ANGLE. |
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 82 | bool shouldUseAngle(std::string appName); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 83 | // Check if this app process should use ANGLE. |
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 84 | bool shouldUseAngle(); |
| Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 85 | // Set a search path for loading ANGLE libraries. The path is a list of |
| 86 | // directories separated by ':'. A directory can be contained in a zip file |
| 87 | // (libraries must be stored uncompressed and page aligned); such elements |
| 88 | // in the search path must have a '!' after the zip filename, e.g. |
| 89 | // /system/app/ANGLEPrebuilt/ANGLEPrebuilt.apk!/lib/arm64-v8a |
| Tim Van Patten | a2a60a0 | 2018-11-09 16:51:15 -0700 | [diff] [blame] | 90 | void setAngleInfo(const std::string path, const std::string appName, std::string devOptIn, |
| Cody Northrop | f0874d3 | 2018-10-29 10:59:45 -0600 | [diff] [blame] | 91 | const int rulesFd, const long rulesOffset, const long rulesLength); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 92 | // Get the ANGLE driver namespace. |
| Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 93 | android_namespace_t* getAngleNamespace(); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 94 | // Get the app name for ANGLE debug message. |
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 95 | std::string& getAngleAppName(); |
| Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 96 | |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 97 | /* |
| 98 | * Apis for debug layer |
| 99 | */ |
| 100 | // Set additional layer search paths. |
| Victor Khimenko | 4819b52 | 2018-07-13 17:24:18 +0200 | [diff] [blame] | 101 | void setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 102 | // Get the app namespace for loading layers. |
| Victor Khimenko | 4819b52 | 2018-07-13 17:24:18 +0200 | [diff] [blame] | 103 | NativeLoaderNamespace* getAppNamespace(); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 104 | // Get additional layer search paths. |
| Courtney Goeltzenleuchter | 30ad2ab | 2018-10-30 08:20:44 -0600 | [diff] [blame] | 105 | const std::string& getLayerPaths(); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 106 | // Set the Vulkan debug layers. |
| Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 107 | void setDebugLayers(const std::string layers); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 108 | // Set the GL debug layers. |
| Cody Northrop | b9b01b6 | 2018-10-23 13:13:10 -0600 | [diff] [blame] | 109 | void setDebugLayersGLES(const std::string layers); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 110 | // Get the debug layers to load. |
| Courtney Goeltzenleuchter | 30ad2ab | 2018-10-30 08:20:44 -0600 | [diff] [blame] | 111 | const std::string& getDebugLayers(); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 112 | // Get the debug layers to load. |
| Cody Northrop | b9b01b6 | 2018-10-23 13:13:10 -0600 | [diff] [blame] | 113 | const std::string& getDebugLayersGLES(); |
| Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 114 | |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 115 | private: |
| Tim Van Patten | 8bd24e9 | 2019-02-08 10:16:40 -0700 | [diff] [blame] | 116 | enum UseAngle { UNKNOWN, YES, NO }; |
| 117 | |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 118 | // Load requested ANGLE library. |
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 119 | void* loadLibrary(std::string name); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 120 | // Check ANGLE support with the rules. |
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 121 | bool checkAngleRules(void* so); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 122 | // Update whether ANGLE should be used. |
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 123 | void updateUseAngle(); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 124 | // Link updatable driver namespace with llndk and vndk-sp libs. |
| Yiwei Zhang | 5e21eb3 | 2019-06-05 00:26:03 -0700 | [diff] [blame] | 125 | bool linkDriverNamespaceLocked(android_namespace_t* vndkNamespace); |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 126 | // Send the initial complete GpuStats to GpuService. |
| 127 | void sendGpuStatsLocked(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime); |
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 128 | |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 129 | GraphicsEnv() = default; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 130 | // Path to updatable driver libs. |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 131 | std::string mDriverPath; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 132 | // Path to additional sphal libs linked to updatable driver namespace. |
| Yiwei Zhang | 6ef8494 | 2019-02-14 12:28:12 -0800 | [diff] [blame] | 133 | std::string mSphalLibraries; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 134 | // This mutex protects mGpuStats and get gpuservice call. |
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 135 | std::mutex mStatsLock; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 136 | // Information bookkept for GpuStats. |
| Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 137 | GpuStatsInfo mGpuStats; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 138 | // Path to ANGLE libs. |
| Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 139 | std::string mAnglePath; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 140 | // This App's name. |
| Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 141 | std::string mAngleAppName; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 142 | // ANGLE developer opt in status. |
| Tim Van Patten | a2a60a0 | 2018-11-09 16:51:15 -0700 | [diff] [blame] | 143 | std::string mAngleDeveloperOptIn; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 144 | // ANGLE rules. |
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 145 | std::vector<char> mRulesBuffer; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 146 | // Use ANGLE flag. |
| Tim Van Patten | 8bd24e9 | 2019-02-08 10:16:40 -0700 | [diff] [blame] | 147 | UseAngle mUseAngle = UNKNOWN; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 148 | // Vulkan debug layers libs. |
| Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 149 | std::string mDebugLayers; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 150 | // GL debug layers libs. |
| Cody Northrop | b9b01b6 | 2018-10-23 13:13:10 -0600 | [diff] [blame] | 151 | std::string mDebugLayersGLES; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 152 | // Additional debug layers search path. |
| Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 153 | std::string mLayerPaths; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 154 | // This mutex protects the namespace creation. |
| Cody Northrop | 3892cfa | 2019-01-30 10:03:12 -0700 | [diff] [blame] | 155 | std::mutex mNamespaceMutex; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 156 | // Updatable driver namespace. |
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 157 | android_namespace_t* mDriverNamespace = nullptr; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 158 | // ANGLE namespace. |
| Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 159 | android_namespace_t* mAngleNamespace = nullptr; |
| Yiwei Zhang | 81e26a1 | 2019-07-02 19:48:23 -0700 | [diff] [blame] | 160 | // This App's namespace. |
| Victor Khimenko | 4819b52 | 2018-07-13 17:24:18 +0200 | [diff] [blame] | 161 | NativeLoaderNamespace* mAppNamespace = nullptr; |
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | } // namespace android |
| 165 | |
| Mathias Agopian | 991d254 | 2017-02-06 13:51:32 -0800 | [diff] [blame] | 166 | #endif // ANDROID_UI_GRAPHICS_ENV_H |