blob: 39b5829fafff32e54651228638230a9c9c728610 [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>
Jesse Hall90b25ed2016-12-12 12:56:46 -080025
Jesse Hall57de0ff2017-05-05 16:41:35 -070026// TODO(b/37049319) Get this from a header once one exists
27extern "C" {
28 android_namespace_t* android_get_exported_namespace(const char*);
29}
30
Jesse Hall90b25ed2016-12-12 12:56:46 -080031namespace android {
32
33/*static*/ GraphicsEnv& GraphicsEnv::getInstance() {
34 static GraphicsEnv env;
35 return env;
36}
37
38void GraphicsEnv::setDriverPath(const std::string path) {
39 if (!mDriverPath.empty()) {
40 ALOGV("ignoring attempt to change driver path from '%s' to '%s'",
41 mDriverPath.c_str(), path.c_str());
42 return;
43 }
44 ALOGV("setting driver path to '%s'", path.c_str());
45 mDriverPath = path;
46}
47
Jesse Hall53457db2016-12-14 16:54:06 -080048android_namespace_t* GraphicsEnv::getDriverNamespace() {
49 static std::once_flag once;
50 std::call_once(once, [this]() {
Jesse Hall53457db2016-12-14 16:54:06 -080051 if (mDriverPath.empty())
52 return;
Jesse Hall57de0ff2017-05-05 16:41:35 -070053 // If the sphal namespace isn't configured for a device, don't support updatable drivers.
54 // We need a parent namespace to inherit the default search path from.
55 auto sphalNamespace = android_get_exported_namespace("sphal");
56 if (!sphalNamespace) return;
57 mDriverNamespace = android_create_namespace("gfx driver",
58 nullptr, // ld_library_path
59 mDriverPath.c_str(), // default_library_path
60 ANDROID_NAMESPACE_TYPE_SHARED |
61 ANDROID_NAMESPACE_TYPE_ISOLATED,
62 nullptr, // permitted_when_isolated_path
63 sphalNamespace);
Jesse Hall53457db2016-12-14 16:54:06 -080064 });
65 return mDriverNamespace;
66}
67
Jesse Hall90b25ed2016-12-12 12:56:46 -080068} // namespace android
Jesse Hall7a8d83e2016-12-20 15:24:28 -080069
70extern "C" android_namespace_t* android_getDriverNamespace() {
71 return android::GraphicsEnv::getInstance().getDriverNamespace();
72}