blob: f46e9f6c53283f8b4d7f0cc683f55078cafbaafb [file] [log] [blame]
Jesse Hall90b25ed2016-12-12 12:56:46 -08001/*
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 Park27c39e12017-05-08 13:00:02 +090019#include <graphicsenv/GraphicsEnv.h>
Jesse Hall90b25ed2016-12-12 12:56:46 -080020
Jesse Hall53457db2016-12-14 16:54:06 -080021#include <mutex>
22
Jesse Hall90b25ed2016-12-12 12:56:46 -080023#include <log/log.h>
Jesse Hall53457db2016-12-14 16:54:06 -080024#include <nativeloader/dlext_namespaces.h>
Cody Northropd2aa3ab2017-10-20 09:01:53 -060025#include <nativeloader/native_loader.h>
Jesse Hall90b25ed2016-12-12 12:56:46 -080026
Jesse Hall57de0ff2017-05-05 16:41:35 -070027// TODO(b/37049319) Get this from a header once one exists
28extern "C" {
29 android_namespace_t* android_get_exported_namespace(const char*);
30}
31
Jesse Hall90b25ed2016-12-12 12:56:46 -080032namespace android {
33
34/*static*/ GraphicsEnv& GraphicsEnv::getInstance() {
35 static GraphicsEnv env;
36 return env;
37}
38
39void 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 Northropd2aa3ab2017-10-20 09:01:53 -060049void 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
59android_namespace_t* GraphicsEnv::getAppNamespace() {
60 return mAppNamespace;
61}
62
63const std::string GraphicsEnv::getLayerPaths(){
64 return mLayerPaths;
65}
66
67const std::string GraphicsEnv::getDebugLayers() {
68 return mDebugLayers;
69}
70
71void GraphicsEnv::setDebugLayers(const std::string layers) {
72 mDebugLayers = layers;
73}
74
Jesse Hall53457db2016-12-14 16:54:06 -080075android_namespace_t* GraphicsEnv::getDriverNamespace() {
76 static std::once_flag once;
77 std::call_once(once, [this]() {
Jesse Hall53457db2016-12-14 16:54:06 -080078 if (mDriverPath.empty())
79 return;
Jesse Hall57de0ff2017-05-05 16:41:35 -070080 // 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 Hall53457db2016-12-14 16:54:06 -080091 });
92 return mDriverNamespace;
93}
94
Jesse Hall90b25ed2016-12-12 12:56:46 -080095} // namespace android
Jesse Hall7a8d83e2016-12-20 15:24:28 -080096
97extern "C" android_namespace_t* android_getDriverNamespace() {
98 return android::GraphicsEnv::getInstance().getDriverNamespace();
99}