| 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 |  | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
|  | 18 |  | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 19 | //#define LOG_NDEBUG 1 | 
|  | 20 | #define LOG_TAG "GraphicsEnv" | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 21 |  | 
| Jiyong Park | 27c39e1 | 2017-05-08 13:00:02 +0900 | [diff] [blame] | 22 | #include <graphicsenv/GraphicsEnv.h> | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 23 |  | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 24 | #include <dlfcn.h> | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 25 | #include <unistd.h> | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 26 |  | 
|  | 27 | #include <android-base/file.h> | 
|  | 28 | #include <android-base/properties.h> | 
|  | 29 | #include <android-base/strings.h> | 
|  | 30 | #include <android/dlext.h> | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 31 | #include <binder/IServiceManager.h> | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 32 | #include <cutils/properties.h> | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 33 | #include <graphicsenv/IGpuService.h> | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 34 | #include <log/log.h> | 
| Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 35 | #include <sys/prctl.h> | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 36 | #include <utils/Trace.h> | 
| Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 37 |  | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 38 | #include <memory> | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 39 | #include <string> | 
|  | 40 |  | 
| Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 41 | // TODO(b/37049319) Get this from a header once one exists | 
|  | 42 | extern "C" { | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 43 | android_namespace_t* android_get_exported_namespace(const char*); | 
|  | 44 | android_namespace_t* android_create_namespace(const char* name, const char* ld_library_path, | 
|  | 45 | const char* default_library_path, uint64_t type, | 
|  | 46 | const char* permitted_when_isolated_path, | 
|  | 47 | android_namespace_t* parent); | 
|  | 48 | bool android_link_namespaces(android_namespace_t* from, android_namespace_t* to, | 
|  | 49 | const char* shared_libs_sonames); | 
| Jiyong Park | 9b816a8 | 2018-01-02 17:37:37 +0900 | [diff] [blame] | 50 |  | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 51 | enum { | 
|  | 52 | ANDROID_NAMESPACE_TYPE_ISOLATED = 1, | 
|  | 53 | ANDROID_NAMESPACE_TYPE_SHARED = 2, | 
|  | 54 | }; | 
| Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 55 | } | 
|  | 56 |  | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 57 | // TODO(ianelliott@): Get the following from an ANGLE header: | 
|  | 58 | #define CURRENT_ANGLE_API_VERSION 2 // Current API verion we are targetting | 
|  | 59 | // Version-2 API: | 
|  | 60 | typedef bool (*fpANGLEGetFeatureSupportUtilAPIVersion)(unsigned int* versionToUse); | 
|  | 61 | typedef bool (*fpANGLEAndroidParseRulesString)(const char* rulesString, void** rulesHandle, | 
|  | 62 | int* rulesVersion); | 
|  | 63 | typedef bool (*fpANGLEGetSystemInfo)(void** handle); | 
|  | 64 | typedef bool (*fpANGLEAddDeviceInfoToSystemInfo)(const char* deviceMfr, const char* deviceModel, | 
|  | 65 | void* handle); | 
|  | 66 | typedef bool (*fpANGLEShouldBeUsedForApplication)(void* rulesHandle, int rulesVersion, | 
|  | 67 | void* systemInfoHandle, const char* appName); | 
|  | 68 | typedef bool (*fpANGLEFreeRulesHandle)(void* handle); | 
|  | 69 | typedef bool (*fpANGLEFreeSystemInfoHandle)(void* handle); | 
|  | 70 |  | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 71 | namespace android { | 
|  | 72 |  | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 73 | enum NativeLibrary { | 
|  | 74 | LLNDK = 0, | 
|  | 75 | VNDKSP = 1, | 
|  | 76 | }; | 
|  | 77 |  | 
|  | 78 | static constexpr const char* kNativeLibrariesSystemConfigPath[] = {"/etc/llndk.libraries.txt", | 
|  | 79 | "/etc/vndksp.libraries.txt"}; | 
|  | 80 |  | 
|  | 81 | static std::string vndkVersionStr() { | 
|  | 82 | #ifdef __BIONIC__ | 
|  | 83 | std::string version = android::base::GetProperty("ro.vndk.version", ""); | 
|  | 84 | if (version != "" && version != "current") { | 
|  | 85 | return "." + version; | 
|  | 86 | } | 
|  | 87 | #endif | 
|  | 88 | return ""; | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | static void insertVndkVersionStr(std::string* fileName) { | 
|  | 92 | LOG_ALWAYS_FATAL_IF(!fileName, "fileName should never be nullptr"); | 
|  | 93 | size_t insertPos = fileName->find_last_of("."); | 
|  | 94 | if (insertPos == std::string::npos) { | 
|  | 95 | insertPos = fileName->length(); | 
|  | 96 | } | 
|  | 97 | fileName->insert(insertPos, vndkVersionStr()); | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | static bool readConfig(const std::string& configFile, std::vector<std::string>* soNames) { | 
|  | 101 | // Read list of public native libraries from the config file. | 
|  | 102 | std::string fileContent; | 
|  | 103 | if (!base::ReadFileToString(configFile, &fileContent)) { | 
|  | 104 | return false; | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | std::vector<std::string> lines = base::Split(fileContent, "\n"); | 
|  | 108 |  | 
|  | 109 | for (auto& line : lines) { | 
|  | 110 | auto trimmedLine = base::Trim(line); | 
|  | 111 | if (!trimmedLine.empty()) { | 
|  | 112 | soNames->push_back(trimmedLine); | 
|  | 113 | } | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | return true; | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | static const std::string getSystemNativeLibraries(NativeLibrary type) { | 
|  | 120 | static const char* androidRootEnv = getenv("ANDROID_ROOT"); | 
|  | 121 | static const std::string rootDir = androidRootEnv != nullptr ? androidRootEnv : "/system"; | 
|  | 122 |  | 
|  | 123 | std::string nativeLibrariesSystemConfig = rootDir + kNativeLibrariesSystemConfigPath[type]; | 
|  | 124 |  | 
|  | 125 | insertVndkVersionStr(&nativeLibrariesSystemConfig); | 
|  | 126 |  | 
|  | 127 | std::vector<std::string> soNames; | 
|  | 128 | if (!readConfig(nativeLibrariesSystemConfig, &soNames)) { | 
|  | 129 | ALOGE("Failed to retrieve library names from %s", nativeLibrariesSystemConfig.c_str()); | 
|  | 130 | return ""; | 
|  | 131 | } | 
|  | 132 |  | 
|  | 133 | return base::Join(soNames, ':'); | 
|  | 134 | } | 
|  | 135 |  | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 136 | /*static*/ GraphicsEnv& GraphicsEnv::getInstance() { | 
|  | 137 | static GraphicsEnv env; | 
|  | 138 | return env; | 
|  | 139 | } | 
|  | 140 |  | 
| Cody Northrop | 629ce4e | 2018-10-15 07:22:09 -0600 | [diff] [blame] | 141 | int GraphicsEnv::getCanLoadSystemLibraries() { | 
|  | 142 | if (property_get_bool("ro.debuggable", false) && prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { | 
|  | 143 | // Return an integer value since this crosses library boundaries | 
|  | 144 | return 1; | 
|  | 145 | } | 
|  | 146 | return 0; | 
|  | 147 | } | 
|  | 148 |  | 
| Yiwei Zhang | 6ef8494 | 2019-02-14 12:28:12 -0800 | [diff] [blame] | 149 | void GraphicsEnv::setDriverPathAndSphalLibraries(const std::string path, | 
|  | 150 | const std::string sphalLibraries) { | 
|  | 151 | if (!mDriverPath.empty() || !mSphalLibraries.empty()) { | 
|  | 152 | ALOGV("ignoring attempt to change driver path from '%s' to '%s' or change sphal libraries " | 
|  | 153 | "from '%s' to '%s'", | 
|  | 154 | mDriverPath.c_str(), path.c_str(), mSphalLibraries.c_str(), sphalLibraries.c_str()); | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 155 | return; | 
|  | 156 | } | 
| Yiwei Zhang | 6ef8494 | 2019-02-14 12:28:12 -0800 | [diff] [blame] | 157 | ALOGV("setting driver path to '%s' and sphal libraries to '%s'", path.c_str(), | 
|  | 158 | sphalLibraries.c_str()); | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 159 | mDriverPath = path; | 
| Yiwei Zhang | 6ef8494 | 2019-02-14 12:28:12 -0800 | [diff] [blame] | 160 | mSphalLibraries = sphalLibraries; | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 161 | } | 
|  | 162 |  | 
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 163 | void GraphicsEnv::hintActivityLaunch() { | 
|  | 164 | ATRACE_CALL(); | 
|  | 165 |  | 
|  | 166 | // If there's already graphics driver preloaded in the process, just send | 
|  | 167 | // the stats info to GpuStats directly through async binder. | 
|  | 168 | std::lock_guard<std::mutex> lock(mStatsLock); | 
|  | 169 | if (mGpuStats.glDriverToSend) { | 
|  | 170 | mGpuStats.glDriverToSend = false; | 
|  | 171 | sendGpuStatsLocked(GraphicsEnv::Api::API_GL, true, mGpuStats.glDriverLoadingTime); | 
|  | 172 | } | 
|  | 173 | if (mGpuStats.vkDriverToSend) { | 
|  | 174 | mGpuStats.vkDriverToSend = false; | 
|  | 175 | sendGpuStatsLocked(GraphicsEnv::Api::API_VK, true, mGpuStats.vkDriverLoadingTime); | 
|  | 176 | } | 
|  | 177 | } | 
|  | 178 |  | 
| Greg Kaiser | 210bb7e | 2019-02-12 12:40:05 -0800 | [diff] [blame] | 179 | void GraphicsEnv::setGpuStats(const std::string& driverPackageName, | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 180 | const std::string& driverVersionName, uint64_t driverVersionCode, | 
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 181 | int64_t driverBuildTime, const std::string& appPackageName, | 
|  | 182 | const int vulkanVersion) { | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 183 | ATRACE_CALL(); | 
|  | 184 |  | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 185 | std::lock_guard<std::mutex> lock(mStatsLock); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 186 | ALOGV("setGpuStats:\n" | 
|  | 187 | "\tdriverPackageName[%s]\n" | 
|  | 188 | "\tdriverVersionName[%s]\n" | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 189 | "\tdriverVersionCode[%" PRIu64 "]\n" | 
|  | 190 | "\tdriverBuildTime[%" PRId64 "]\n" | 
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 191 | "\tappPackageName[%s]\n" | 
|  | 192 | "\tvulkanVersion[%d]\n", | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 193 | driverPackageName.c_str(), driverVersionName.c_str(), driverVersionCode, driverBuildTime, | 
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 194 | appPackageName.c_str(), vulkanVersion); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 195 |  | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 196 | mGpuStats.driverPackageName = driverPackageName; | 
|  | 197 | mGpuStats.driverVersionName = driverVersionName; | 
|  | 198 | mGpuStats.driverVersionCode = driverVersionCode; | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 199 | mGpuStats.driverBuildTime = driverBuildTime; | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 200 | mGpuStats.appPackageName = appPackageName; | 
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 201 | mGpuStats.vulkanVersion = vulkanVersion; | 
| Yiwei Zhang | 8c8c181 | 2019-02-04 18:56:38 -0800 | [diff] [blame] | 202 | } | 
|  | 203 |  | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 204 | void GraphicsEnv::setDriverToLoad(GraphicsEnv::Driver driver) { | 
|  | 205 | ATRACE_CALL(); | 
|  | 206 |  | 
|  | 207 | std::lock_guard<std::mutex> lock(mStatsLock); | 
|  | 208 | switch (driver) { | 
|  | 209 | case GraphicsEnv::Driver::GL: | 
|  | 210 | case GraphicsEnv::Driver::GL_UPDATED: | 
|  | 211 | case GraphicsEnv::Driver::ANGLE: { | 
|  | 212 | if (mGpuStats.glDriverToLoad == GraphicsEnv::Driver::NONE) { | 
|  | 213 | mGpuStats.glDriverToLoad = driver; | 
|  | 214 | break; | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | if (mGpuStats.glDriverFallback == GraphicsEnv::Driver::NONE) { | 
|  | 218 | mGpuStats.glDriverFallback = driver; | 
|  | 219 | } | 
|  | 220 | break; | 
|  | 221 | } | 
|  | 222 | case Driver::VULKAN: | 
|  | 223 | case Driver::VULKAN_UPDATED: { | 
|  | 224 | if (mGpuStats.vkDriverToLoad == GraphicsEnv::Driver::NONE) { | 
|  | 225 | mGpuStats.vkDriverToLoad = driver; | 
|  | 226 | break; | 
|  | 227 | } | 
|  | 228 |  | 
|  | 229 | if (mGpuStats.vkDriverFallback == GraphicsEnv::Driver::NONE) { | 
|  | 230 | mGpuStats.vkDriverFallback = driver; | 
|  | 231 | } | 
|  | 232 | break; | 
|  | 233 | } | 
|  | 234 | default: | 
|  | 235 | break; | 
|  | 236 | } | 
|  | 237 | } | 
|  | 238 |  | 
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 239 | void GraphicsEnv::setDriverLoaded(GraphicsEnv::Api api, bool isDriverLoaded, | 
|  | 240 | int64_t driverLoadingTime) { | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 241 | ATRACE_CALL(); | 
|  | 242 |  | 
|  | 243 | std::lock_guard<std::mutex> lock(mStatsLock); | 
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 244 | const bool doNotSend = mGpuStats.appPackageName.empty(); | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 245 | if (api == GraphicsEnv::Api::API_GL) { | 
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 246 | if (doNotSend) mGpuStats.glDriverToSend = true; | 
|  | 247 | mGpuStats.glDriverLoadingTime = driverLoadingTime; | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 248 | } else { | 
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 249 | if (doNotSend) mGpuStats.vkDriverToSend = true; | 
|  | 250 | mGpuStats.vkDriverLoadingTime = driverLoadingTime; | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 251 | } | 
|  | 252 |  | 
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 253 | sendGpuStatsLocked(api, isDriverLoaded, driverLoadingTime); | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 254 | } | 
|  | 255 |  | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 256 | static sp<IGpuService> getGpuService() { | 
|  | 257 | const sp<IBinder> binder = defaultServiceManager()->checkService(String16("gpu")); | 
|  | 258 | if (!binder) { | 
|  | 259 | ALOGE("Failed to get gpu service"); | 
|  | 260 | return nullptr; | 
|  | 261 | } | 
|  | 262 |  | 
|  | 263 | return interface_cast<IGpuService>(binder); | 
|  | 264 | } | 
|  | 265 |  | 
| Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 266 | void GraphicsEnv::setCpuVulkanInUse() { | 
|  | 267 | ATRACE_CALL(); | 
|  | 268 |  | 
|  | 269 | // Use the same stats lock to protect getGpuService() as well. | 
|  | 270 | std::lock_guard<std::mutex> lock(mStatsLock); | 
|  | 271 | const sp<IGpuService> gpuService = getGpuService(); | 
|  | 272 | if (gpuService) { | 
|  | 273 | gpuService->setCpuVulkanInUse(mGpuStats.appPackageName, mGpuStats.driverVersionCode); | 
|  | 274 | } | 
|  | 275 | } | 
|  | 276 |  | 
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 277 | void GraphicsEnv::sendGpuStatsLocked(GraphicsEnv::Api api, bool isDriverLoaded, | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 278 | int64_t driverLoadingTime) { | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 279 | ATRACE_CALL(); | 
|  | 280 |  | 
|  | 281 | // Do not sendGpuStats for those skipping the GraphicsEnvironment setup | 
|  | 282 | if (mGpuStats.appPackageName.empty()) return; | 
|  | 283 |  | 
|  | 284 | ALOGV("sendGpuStats:\n" | 
|  | 285 | "\tdriverPackageName[%s]\n" | 
|  | 286 | "\tdriverVersionName[%s]\n" | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 287 | "\tdriverVersionCode[%" PRIu64 "]\n" | 
|  | 288 | "\tdriverBuildTime[%" PRId64 "]\n" | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 289 | "\tappPackageName[%s]\n" | 
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 290 | "\tvulkanVersion[%d]\n" | 
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 291 | "\tapi[%d]\n" | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 292 | "\tisDriverLoaded[%d]\n" | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 293 | "\tdriverLoadingTime[%" PRId64 "]", | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 294 | mGpuStats.driverPackageName.c_str(), mGpuStats.driverVersionName.c_str(), | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 295 | mGpuStats.driverVersionCode, mGpuStats.driverBuildTime, mGpuStats.appPackageName.c_str(), | 
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 296 | mGpuStats.vulkanVersion, static_cast<int32_t>(api), isDriverLoaded, driverLoadingTime); | 
|  | 297 |  | 
|  | 298 | GraphicsEnv::Driver driver = GraphicsEnv::Driver::NONE; | 
|  | 299 | bool isIntendedDriverLoaded = false; | 
|  | 300 | if (api == GraphicsEnv::Api::API_GL) { | 
|  | 301 | driver = mGpuStats.glDriverToLoad; | 
|  | 302 | isIntendedDriverLoaded = | 
|  | 303 | isDriverLoaded && (mGpuStats.glDriverFallback == GraphicsEnv::Driver::NONE); | 
|  | 304 | } else { | 
|  | 305 | driver = mGpuStats.vkDriverToLoad; | 
|  | 306 | isIntendedDriverLoaded = | 
|  | 307 | isDriverLoaded && (mGpuStats.vkDriverFallback == GraphicsEnv::Driver::NONE); | 
|  | 308 | } | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 309 |  | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 310 | const sp<IGpuService> gpuService = getGpuService(); | 
|  | 311 | if (gpuService) { | 
|  | 312 | gpuService->setGpuStats(mGpuStats.driverPackageName, mGpuStats.driverVersionName, | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 313 | mGpuStats.driverVersionCode, mGpuStats.driverBuildTime, | 
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 314 | mGpuStats.appPackageName, mGpuStats.vulkanVersion, driver, | 
| Yiwei Zhang | 5c640c1 | 2019-05-08 18:29:38 -0700 | [diff] [blame] | 315 | isIntendedDriverLoaded, driverLoadingTime); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 316 | } | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 317 | } | 
|  | 318 |  | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 319 | void* GraphicsEnv::loadLibrary(std::string name) { | 
|  | 320 | const android_dlextinfo dlextinfo = { | 
|  | 321 | .flags = ANDROID_DLEXT_USE_NAMESPACE, | 
|  | 322 | .library_namespace = getAngleNamespace(), | 
|  | 323 | }; | 
|  | 324 |  | 
|  | 325 | std::string libName = std::string("lib") + name + "_angle.so"; | 
|  | 326 |  | 
|  | 327 | void* so = android_dlopen_ext(libName.c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo); | 
|  | 328 |  | 
|  | 329 | if (so) { | 
|  | 330 | ALOGD("dlopen_ext from APK (%s) success at %p", libName.c_str(), so); | 
|  | 331 | return so; | 
|  | 332 | } else { | 
|  | 333 | ALOGE("dlopen_ext(\"%s\") failed: %s", libName.c_str(), dlerror()); | 
|  | 334 | } | 
|  | 335 |  | 
|  | 336 | return nullptr; | 
|  | 337 | } | 
|  | 338 |  | 
|  | 339 | bool GraphicsEnv::checkAngleRules(void* so) { | 
|  | 340 | char manufacturer[PROPERTY_VALUE_MAX]; | 
|  | 341 | char model[PROPERTY_VALUE_MAX]; | 
|  | 342 | property_get("ro.product.manufacturer", manufacturer, "UNSET"); | 
|  | 343 | property_get("ro.product.model", model, "UNSET"); | 
|  | 344 |  | 
|  | 345 | auto ANGLEGetFeatureSupportUtilAPIVersion = | 
|  | 346 | (fpANGLEGetFeatureSupportUtilAPIVersion)dlsym(so, | 
|  | 347 | "ANGLEGetFeatureSupportUtilAPIVersion"); | 
|  | 348 |  | 
|  | 349 | if (!ANGLEGetFeatureSupportUtilAPIVersion) { | 
|  | 350 | ALOGW("Cannot find ANGLEGetFeatureSupportUtilAPIVersion function"); | 
|  | 351 | return false; | 
|  | 352 | } | 
|  | 353 |  | 
|  | 354 | // Negotiate the interface version by requesting most recent known to the platform | 
|  | 355 | unsigned int versionToUse = CURRENT_ANGLE_API_VERSION; | 
|  | 356 | if (!(ANGLEGetFeatureSupportUtilAPIVersion)(&versionToUse)) { | 
|  | 357 | ALOGW("Cannot use ANGLE feature-support library, it is older than supported by EGL, " | 
|  | 358 | "requested version %u", | 
|  | 359 | versionToUse); | 
|  | 360 | return false; | 
|  | 361 | } | 
|  | 362 |  | 
|  | 363 | // Add and remove versions below as needed | 
|  | 364 | bool useAngle = false; | 
|  | 365 | switch (versionToUse) { | 
|  | 366 | case 2: { | 
|  | 367 | ALOGV("Using version %d of ANGLE feature-support library", versionToUse); | 
|  | 368 | void* rulesHandle = nullptr; | 
|  | 369 | int rulesVersion = 0; | 
|  | 370 | void* systemInfoHandle = nullptr; | 
|  | 371 |  | 
|  | 372 | // Get the symbols for the feature-support-utility library: | 
|  | 373 | #define GET_SYMBOL(symbol)                                                 \ | 
|  | 374 | fp##symbol symbol = (fp##symbol)dlsym(so, #symbol);                    \ | 
|  | 375 | if (!symbol) {                                                         \ | 
|  | 376 | ALOGW("Cannot find " #symbol " in ANGLE feature-support library"); \ | 
|  | 377 | break;                                                             \ | 
|  | 378 | } | 
|  | 379 | GET_SYMBOL(ANGLEAndroidParseRulesString); | 
|  | 380 | GET_SYMBOL(ANGLEGetSystemInfo); | 
|  | 381 | GET_SYMBOL(ANGLEAddDeviceInfoToSystemInfo); | 
|  | 382 | GET_SYMBOL(ANGLEShouldBeUsedForApplication); | 
|  | 383 | GET_SYMBOL(ANGLEFreeRulesHandle); | 
|  | 384 | GET_SYMBOL(ANGLEFreeSystemInfoHandle); | 
|  | 385 |  | 
|  | 386 | // Parse the rules, obtain the SystemInfo, and evaluate the | 
|  | 387 | // application against the rules: | 
|  | 388 | if (!(ANGLEAndroidParseRulesString)(mRulesBuffer.data(), &rulesHandle, &rulesVersion)) { | 
|  | 389 | ALOGW("ANGLE feature-support library cannot parse rules file"); | 
|  | 390 | break; | 
|  | 391 | } | 
|  | 392 | if (!(ANGLEGetSystemInfo)(&systemInfoHandle)) { | 
|  | 393 | ALOGW("ANGLE feature-support library cannot obtain SystemInfo"); | 
|  | 394 | break; | 
|  | 395 | } | 
|  | 396 | if (!(ANGLEAddDeviceInfoToSystemInfo)(manufacturer, model, systemInfoHandle)) { | 
|  | 397 | ALOGW("ANGLE feature-support library cannot add device info to SystemInfo"); | 
|  | 398 | break; | 
|  | 399 | } | 
|  | 400 | useAngle = (ANGLEShouldBeUsedForApplication)(rulesHandle, rulesVersion, | 
|  | 401 | systemInfoHandle, mAngleAppName.c_str()); | 
|  | 402 | (ANGLEFreeRulesHandle)(rulesHandle); | 
|  | 403 | (ANGLEFreeSystemInfoHandle)(systemInfoHandle); | 
|  | 404 | } break; | 
|  | 405 |  | 
|  | 406 | default: | 
|  | 407 | ALOGW("Version %u of ANGLE feature-support library is NOT supported.", versionToUse); | 
|  | 408 | } | 
|  | 409 |  | 
|  | 410 | ALOGV("Close temporarily-loaded ANGLE opt-in/out logic"); | 
|  | 411 | return useAngle; | 
|  | 412 | } | 
|  | 413 |  | 
|  | 414 | bool GraphicsEnv::shouldUseAngle(std::string appName) { | 
|  | 415 | if (appName != mAngleAppName) { | 
|  | 416 | // Make sure we are checking the app we were init'ed for | 
|  | 417 | ALOGE("App name does not match: expected '%s', got '%s'", mAngleAppName.c_str(), | 
|  | 418 | appName.c_str()); | 
|  | 419 | return false; | 
|  | 420 | } | 
|  | 421 |  | 
|  | 422 | return shouldUseAngle(); | 
|  | 423 | } | 
|  | 424 |  | 
|  | 425 | bool GraphicsEnv::shouldUseAngle() { | 
|  | 426 | // Make sure we are init'ed | 
|  | 427 | if (mAngleAppName.empty()) { | 
| Cody Northrop | 2d7af74 | 2019-01-24 16:55:03 -0700 | [diff] [blame] | 428 | ALOGV("App name is empty. setAngleInfo() has not been called to enable ANGLE."); | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 429 | return false; | 
|  | 430 | } | 
|  | 431 |  | 
| Tim Van Patten | 8bd24e9 | 2019-02-08 10:16:40 -0700 | [diff] [blame] | 432 | return (mUseAngle == YES) ? true : false; | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 433 | } | 
|  | 434 |  | 
|  | 435 | void GraphicsEnv::updateUseAngle() { | 
| Tim Van Patten | 8bd24e9 | 2019-02-08 10:16:40 -0700 | [diff] [blame] | 436 | mUseAngle = NO; | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 437 |  | 
|  | 438 | const char* ANGLE_PREFER_ANGLE = "angle"; | 
|  | 439 | const char* ANGLE_PREFER_NATIVE = "native"; | 
|  | 440 |  | 
|  | 441 | if (mAngleDeveloperOptIn == ANGLE_PREFER_ANGLE) { | 
|  | 442 | ALOGV("User set \"Developer Options\" to force the use of ANGLE"); | 
| Tim Van Patten | 8bd24e9 | 2019-02-08 10:16:40 -0700 | [diff] [blame] | 443 | mUseAngle = YES; | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 444 | } else if (mAngleDeveloperOptIn == ANGLE_PREFER_NATIVE) { | 
|  | 445 | ALOGV("User set \"Developer Options\" to force the use of Native"); | 
| Tim Van Patten | 8bd24e9 | 2019-02-08 10:16:40 -0700 | [diff] [blame] | 446 | mUseAngle = NO; | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 447 | } else { | 
|  | 448 | // The "Developer Options" value wasn't set to force the use of ANGLE.  Need to temporarily | 
|  | 449 | // load ANGLE and call the updatable opt-in/out logic: | 
| Cody Northrop | c15d382 | 2019-01-17 10:26:47 -0700 | [diff] [blame] | 450 | void* featureSo = loadLibrary("feature_support"); | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 451 | if (featureSo) { | 
|  | 452 | ALOGV("loaded ANGLE's opt-in/out logic from namespace"); | 
| Tim Van Patten | 8bd24e9 | 2019-02-08 10:16:40 -0700 | [diff] [blame] | 453 | mUseAngle = checkAngleRules(featureSo) ? YES : NO; | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 454 | dlclose(featureSo); | 
|  | 455 | featureSo = nullptr; | 
|  | 456 | } else { | 
|  | 457 | ALOGV("Could not load the ANGLE opt-in/out logic, cannot use ANGLE."); | 
|  | 458 | } | 
|  | 459 | } | 
|  | 460 | } | 
|  | 461 |  | 
| Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 462 | void GraphicsEnv::setAngleInfo(const std::string path, const std::string appName, | 
| Tim Van Patten | a2a60a0 | 2018-11-09 16:51:15 -0700 | [diff] [blame] | 463 | const std::string developerOptIn, const int rulesFd, | 
|  | 464 | const long rulesOffset, const long rulesLength) { | 
| Tim Van Patten | 8bd24e9 | 2019-02-08 10:16:40 -0700 | [diff] [blame] | 465 | if (mUseAngle != UNKNOWN) { | 
|  | 466 | // We've already figured out an answer for this app, so just return. | 
|  | 467 | ALOGV("Already evaluated the rules file for '%s': use ANGLE = %s", appName.c_str(), | 
|  | 468 | (mUseAngle == YES) ? "true" : "false"); | 
|  | 469 | return; | 
|  | 470 | } | 
|  | 471 |  | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 472 | ALOGV("setting ANGLE path to '%s'", path.c_str()); | 
|  | 473 | mAnglePath = path; | 
|  | 474 | ALOGV("setting ANGLE app name to '%s'", appName.c_str()); | 
|  | 475 | mAngleAppName = appName; | 
|  | 476 | ALOGV("setting ANGLE application opt-in to '%s'", developerOptIn.c_str()); | 
|  | 477 | mAngleDeveloperOptIn = developerOptIn; | 
| Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 478 |  | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 479 | lseek(rulesFd, rulesOffset, SEEK_SET); | 
|  | 480 | mRulesBuffer = std::vector<char>(rulesLength + 1); | 
|  | 481 | ssize_t numBytesRead = read(rulesFd, mRulesBuffer.data(), rulesLength); | 
|  | 482 | if (numBytesRead < 0) { | 
|  | 483 | ALOGE("Cannot read rules file: numBytesRead = %zd", numBytesRead); | 
|  | 484 | numBytesRead = 0; | 
|  | 485 | } else if (numBytesRead == 0) { | 
|  | 486 | ALOGW("Empty rules file"); | 
| Courtney Goeltzenleuchter | d41ef25 | 2018-09-26 14:37:42 -0600 | [diff] [blame] | 487 | } | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 488 | if (numBytesRead != rulesLength) { | 
|  | 489 | ALOGW("Did not read all of the necessary bytes from the rules file." | 
|  | 490 | "expected: %ld, got: %zd", | 
|  | 491 | rulesLength, numBytesRead); | 
| Tim Van Patten | a2a60a0 | 2018-11-09 16:51:15 -0700 | [diff] [blame] | 492 | } | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 493 | mRulesBuffer[numBytesRead] = '\0'; | 
| Cody Northrop | 04e7043 | 2018-09-06 10:34:58 -0600 | [diff] [blame] | 494 |  | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 495 | // Update the current status of whether we should use ANGLE or not | 
|  | 496 | updateUseAngle(); | 
| Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 497 | } | 
|  | 498 |  | 
| Victor Khimenko | 4819b52 | 2018-07-13 17:24:18 +0200 | [diff] [blame] | 499 | void GraphicsEnv::setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths) { | 
| Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 500 | if (mLayerPaths.empty()) { | 
|  | 501 | mLayerPaths = layerPaths; | 
|  | 502 | mAppNamespace = appNamespace; | 
|  | 503 | } else { | 
|  | 504 | ALOGV("Vulkan layer search path already set, not clobbering with '%s' for namespace %p'", | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 505 | layerPaths.c_str(), appNamespace); | 
| Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 506 | } | 
|  | 507 | } | 
|  | 508 |  | 
| Victor Khimenko | 4819b52 | 2018-07-13 17:24:18 +0200 | [diff] [blame] | 509 | NativeLoaderNamespace* GraphicsEnv::getAppNamespace() { | 
| Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 510 | return mAppNamespace; | 
|  | 511 | } | 
|  | 512 |  | 
| Tim Van Patten | 5f744f1 | 2018-12-12 11:46:21 -0700 | [diff] [blame] | 513 | std::string& GraphicsEnv::getAngleAppName() { | 
|  | 514 | return mAngleAppName; | 
| Cody Northrop | 04e7043 | 2018-09-06 10:34:58 -0600 | [diff] [blame] | 515 | } | 
|  | 516 |  | 
| Courtney Goeltzenleuchter | 30ad2ab | 2018-10-30 08:20:44 -0600 | [diff] [blame] | 517 | const std::string& GraphicsEnv::getLayerPaths() { | 
| Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 518 | return mLayerPaths; | 
|  | 519 | } | 
|  | 520 |  | 
| Courtney Goeltzenleuchter | 30ad2ab | 2018-10-30 08:20:44 -0600 | [diff] [blame] | 521 | const std::string& GraphicsEnv::getDebugLayers() { | 
| Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 522 | return mDebugLayers; | 
|  | 523 | } | 
|  | 524 |  | 
| Cody Northrop | b9b01b6 | 2018-10-23 13:13:10 -0600 | [diff] [blame] | 525 | const std::string& GraphicsEnv::getDebugLayersGLES() { | 
|  | 526 | return mDebugLayersGLES; | 
|  | 527 | } | 
|  | 528 |  | 
| Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 529 | void GraphicsEnv::setDebugLayers(const std::string layers) { | 
|  | 530 | mDebugLayers = layers; | 
|  | 531 | } | 
|  | 532 |  | 
| Cody Northrop | b9b01b6 | 2018-10-23 13:13:10 -0600 | [diff] [blame] | 533 | void GraphicsEnv::setDebugLayersGLES(const std::string layers) { | 
|  | 534 | mDebugLayersGLES = layers; | 
|  | 535 | } | 
|  | 536 |  | 
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 537 | android_namespace_t* GraphicsEnv::getDriverNamespace() { | 
|  | 538 | static std::once_flag once; | 
|  | 539 | std::call_once(once, [this]() { | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 540 | if (mDriverPath.empty()) return; | 
|  | 541 |  | 
|  | 542 | auto vndkNamespace = android_get_exported_namespace("vndk"); | 
|  | 543 | if (!vndkNamespace) return; | 
|  | 544 |  | 
| Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 545 | mDriverNamespace = android_create_namespace("gfx driver", | 
| Peiyong Lin | 2e9c74c | 2018-10-24 11:18:07 -0700 | [diff] [blame] | 546 | mDriverPath.c_str(), // ld_library_path | 
| Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 547 | mDriverPath.c_str(), // default_library_path | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 548 | ANDROID_NAMESPACE_TYPE_ISOLATED, | 
| Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 549 | nullptr, // permitted_when_isolated_path | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 550 | nullptr); | 
|  | 551 |  | 
|  | 552 | const std::string llndkLibraries = getSystemNativeLibraries(NativeLibrary::LLNDK); | 
|  | 553 | if (llndkLibraries.empty()) { | 
|  | 554 | mDriverNamespace = nullptr; | 
|  | 555 | return; | 
|  | 556 | } | 
|  | 557 | if (!android_link_namespaces(mDriverNamespace, nullptr, llndkLibraries.c_str())) { | 
|  | 558 | ALOGE("Failed to link default namespace[%s]", dlerror()); | 
|  | 559 | mDriverNamespace = nullptr; | 
|  | 560 | return; | 
|  | 561 | } | 
|  | 562 |  | 
|  | 563 | const std::string vndkspLibraries = getSystemNativeLibraries(NativeLibrary::VNDKSP); | 
|  | 564 | if (vndkspLibraries.empty()) { | 
|  | 565 | mDriverNamespace = nullptr; | 
|  | 566 | return; | 
|  | 567 | } | 
|  | 568 | if (!android_link_namespaces(mDriverNamespace, vndkNamespace, vndkspLibraries.c_str())) { | 
|  | 569 | ALOGE("Failed to link vndk namespace[%s]", dlerror()); | 
|  | 570 | mDriverNamespace = nullptr; | 
|  | 571 | return; | 
|  | 572 | } | 
| Yiwei Zhang | 6ef8494 | 2019-02-14 12:28:12 -0800 | [diff] [blame] | 573 |  | 
|  | 574 | if (mSphalLibraries.empty()) return; | 
|  | 575 |  | 
|  | 576 | // Make additional libraries in sphal to be accessible | 
|  | 577 | auto sphalNamespace = android_get_exported_namespace("sphal"); | 
|  | 578 | if (!sphalNamespace) { | 
|  | 579 | ALOGE("Depend on these libraries[%s] in sphal, but failed to get sphal namespace", | 
|  | 580 | mSphalLibraries.c_str()); | 
|  | 581 | mDriverNamespace = nullptr; | 
|  | 582 | return; | 
|  | 583 | } | 
|  | 584 |  | 
|  | 585 | if (!android_link_namespaces(mDriverNamespace, sphalNamespace, mSphalLibraries.c_str())) { | 
|  | 586 | ALOGE("Failed to link sphal namespace[%s]", dlerror()); | 
|  | 587 | mDriverNamespace = nullptr; | 
|  | 588 | return; | 
|  | 589 | } | 
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 590 | }); | 
| Yiwei Zhang | 64d8921 | 2018-11-27 19:58:29 -0800 | [diff] [blame] | 591 |  | 
| Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 592 | return mDriverNamespace; | 
|  | 593 | } | 
|  | 594 |  | 
| Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 595 | android_namespace_t* GraphicsEnv::getAngleNamespace() { | 
| Cody Northrop | 3892cfa | 2019-01-30 10:03:12 -0700 | [diff] [blame] | 596 | std::lock_guard<std::mutex> lock(mNamespaceMutex); | 
| Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 597 |  | 
| Cody Northrop | 3892cfa | 2019-01-30 10:03:12 -0700 | [diff] [blame] | 598 | if (mAngleNamespace) { | 
|  | 599 | return mAngleNamespace; | 
|  | 600 | } | 
|  | 601 |  | 
|  | 602 | if (mAnglePath.empty()) { | 
|  | 603 | ALOGV("mAnglePath is empty, not creating ANGLE namespace"); | 
|  | 604 | return nullptr; | 
|  | 605 | } | 
|  | 606 |  | 
|  | 607 | mAngleNamespace = android_create_namespace("ANGLE", | 
|  | 608 | nullptr,            // ld_library_path | 
|  | 609 | mAnglePath.c_str(), // default_library_path | 
|  | 610 | ANDROID_NAMESPACE_TYPE_SHARED | | 
|  | 611 | ANDROID_NAMESPACE_TYPE_ISOLATED, | 
|  | 612 | nullptr, // permitted_when_isolated_path | 
|  | 613 | nullptr); | 
|  | 614 |  | 
|  | 615 | ALOGD_IF(!mAngleNamespace, "Could not create ANGLE namespace from default"); | 
| Cody Northrop | 1f00e17 | 2018-04-02 11:23:31 -0600 | [diff] [blame] | 616 |  | 
|  | 617 | return mAngleNamespace; | 
|  | 618 | } | 
|  | 619 |  | 
| Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 620 | } // namespace android |