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 | |
| 17 | //#define LOG_NDEBUG 1 |
| 18 | #define LOG_TAG "GraphicsEnv" |
Jiyong Park | 27c39e1 | 2017-05-08 13:00:02 +0900 | [diff] [blame] | 19 | #include <graphicsenv/GraphicsEnv.h> |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 20 | |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 21 | #include <mutex> |
| 22 | |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 23 | #include <log/log.h> |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 24 | #include <nativeloader/dlext_namespaces.h> |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 25 | #include <nativeloader/native_loader.h> |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 26 | |
Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 27 | // TODO(b/37049319) Get this from a header once one exists |
| 28 | extern "C" { |
| 29 | android_namespace_t* android_get_exported_namespace(const char*); |
| 30 | } |
| 31 | |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 32 | namespace android { |
| 33 | |
| 34 | /*static*/ GraphicsEnv& GraphicsEnv::getInstance() { |
| 35 | static GraphicsEnv env; |
| 36 | return env; |
| 37 | } |
| 38 | |
| 39 | void GraphicsEnv::setDriverPath(const std::string path) { |
| 40 | if (!mDriverPath.empty()) { |
| 41 | ALOGV("ignoring attempt to change driver path from '%s' to '%s'", |
| 42 | mDriverPath.c_str(), path.c_str()); |
| 43 | return; |
| 44 | } |
| 45 | ALOGV("setting driver path to '%s'", path.c_str()); |
| 46 | mDriverPath = path; |
| 47 | } |
| 48 | |
Cody Northrop | d2aa3ab | 2017-10-20 09:01:53 -0600 | [diff] [blame] | 49 | void GraphicsEnv::setLayerPaths(android_namespace_t* appNamespace, const std::string layerPaths) { |
| 50 | if (mLayerPaths.empty()) { |
| 51 | mLayerPaths = layerPaths; |
| 52 | mAppNamespace = appNamespace; |
| 53 | } else { |
| 54 | ALOGV("Vulkan layer search path already set, not clobbering with '%s' for namespace %p'", |
| 55 | layerPaths.c_str(), appNamespace); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | android_namespace_t* GraphicsEnv::getAppNamespace() { |
| 60 | return mAppNamespace; |
| 61 | } |
| 62 | |
| 63 | const std::string GraphicsEnv::getLayerPaths(){ |
| 64 | return mLayerPaths; |
| 65 | } |
| 66 | |
| 67 | const std::string GraphicsEnv::getDebugLayers() { |
| 68 | return mDebugLayers; |
| 69 | } |
| 70 | |
| 71 | void GraphicsEnv::setDebugLayers(const std::string layers) { |
| 72 | mDebugLayers = layers; |
| 73 | } |
| 74 | |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 75 | android_namespace_t* GraphicsEnv::getDriverNamespace() { |
| 76 | static std::once_flag once; |
| 77 | std::call_once(once, [this]() { |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 78 | if (mDriverPath.empty()) |
| 79 | return; |
Jesse Hall | 57de0ff | 2017-05-05 16:41:35 -0700 | [diff] [blame] | 80 | // If the sphal namespace isn't configured for a device, don't support updatable drivers. |
| 81 | // We need a parent namespace to inherit the default search path from. |
| 82 | auto sphalNamespace = android_get_exported_namespace("sphal"); |
| 83 | if (!sphalNamespace) return; |
| 84 | mDriverNamespace = android_create_namespace("gfx driver", |
| 85 | nullptr, // ld_library_path |
| 86 | mDriverPath.c_str(), // default_library_path |
| 87 | ANDROID_NAMESPACE_TYPE_SHARED | |
| 88 | ANDROID_NAMESPACE_TYPE_ISOLATED, |
| 89 | nullptr, // permitted_when_isolated_path |
| 90 | sphalNamespace); |
Jesse Hall | 53457db | 2016-12-14 16:54:06 -0800 | [diff] [blame] | 91 | }); |
| 92 | return mDriverNamespace; |
| 93 | } |
| 94 | |
Jesse Hall | 90b25ed | 2016-12-12 12:56:46 -0800 | [diff] [blame] | 95 | } // namespace android |
Jesse Hall | 7a8d83e | 2016-12-20 15:24:28 -0800 | [diff] [blame] | 96 | |
| 97 | extern "C" android_namespace_t* android_getDriverNamespace() { |
| 98 | return android::GraphicsEnv::getInstance().getDriverNamespace(); |
| 99 | } |