blob: 83448d4ce7c8d358fa8728a24a03f63e9dd46c27 [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
Mathias Agopian991d2542017-02-06 13:51:32 -080017#ifndef ANDROID_UI_GRAPHICS_ENV_H
18#define ANDROID_UI_GRAPHICS_ENV_H 1
Jesse Hall90b25ed2016-12-12 12:56:46 -080019
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -070020#include <graphicsenv/GpuStatsInfo.h>
21
Cody Northrop3892cfa2019-01-30 10:03:12 -070022#include <mutex>
Jesse Hall90b25ed2016-12-12 12:56:46 -080023#include <string>
Tim Van Patten5f744f12018-12-12 11:46:21 -070024#include <vector>
Jesse Hall90b25ed2016-12-12 12:56:46 -080025
Jesse Hall53457db2016-12-14 16:54:06 -080026struct android_namespace_t;
27
Jesse Hall90b25ed2016-12-12 12:56:46 -080028namespace android {
29
Nicolas Geoffraya655dac2019-01-11 15:59:42 +000030struct NativeLoaderNamespace;
Victor Khimenko4819b522018-07-13 17:24:18 +020031
Jesse Hall90b25ed2016-12-12 12:56:46 -080032class GraphicsEnv {
Yiwei Zhangd9861812019-02-13 11:51:55 -080033public:
Jesse Hall90b25ed2016-12-12 12:56:46 -080034 static GraphicsEnv& getInstance();
35
Yiwei Zhang81e26a12019-07-02 19:48:23 -070036 // Check if device is debuggable.
Cody Northrop629ce4e2018-10-15 07:22:09 -060037 int getCanLoadSystemLibraries();
38
Yiwei Zhang81e26a12019-07-02 19:48:23 -070039 /*
40 * Apis for updatable driver
41 */
Jesse Hall90b25ed2016-12-12 12:56:46 -080042 // 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 Zhang6ef84942019-02-14 12:28:12 -080047 // 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 Zhang81e26a12019-07-02 19:48:23 -070051 // Get the updatable driver namespace.
Jesse Hall53457db2016-12-14 16:54:06 -080052 android_namespace_t* getDriverNamespace();
Yiwei Zhang81e26a12019-07-02 19:48:23 -070053
54 /*
55 * Apis for GpuStats
56 */
57 // Hint there's real activity launching on the app process.
Yiwei Zhang5c640c12019-05-08 18:29:38 -070058 void hintActivityLaunch();
Yiwei Zhang81e26a12019-07-02 19:48:23 -070059 // Set the initial GpuStats.
Greg Kaiser210bb7e2019-02-12 12:40:05 -080060 void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName,
Yiwei Zhang96c01712019-02-19 16:00:25 -080061 uint64_t versionCode, int64_t driverBuildTime,
Yiwei Zhang794d2952019-05-06 17:43:59 -070062 const std::string& appPackageName, const int32_t vulkanVersion);
Yiwei Zhangbcba4112019-07-03 13:39:32 -070063 // Set stats for target GpuStatsInfo::Stats type.
64 void setTargetStats(const GpuStatsInfo::Stats stats, const uint64_t value = 0);
Yiwei Zhang81e26a12019-07-02 19:48:23 -070065 // Set which driver is intended to load.
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -070066 void setDriverToLoad(GpuStatsInfo::Driver driver);
Yiwei Zhang81e26a12019-07-02 19:48:23 -070067 // Set which driver is actually loaded.
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -070068 void setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime);
Jesse Hall90b25ed2016-12-12 12:56:46 -080069
Yiwei Zhang81e26a12019-07-02 19:48:23 -070070 /*
Adam Bodnar0afcca02019-09-17 13:23:17 -070071 * 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 Zhang81e26a12019-07-02 19:48:23 -070079 * Apis for ANGLE
80 */
81 // Check if the requested app should use ANGLE.
Tim Van Patten5f744f12018-12-12 11:46:21 -070082 bool shouldUseAngle(std::string appName);
Yiwei Zhang81e26a12019-07-02 19:48:23 -070083 // Check if this app process should use ANGLE.
Tim Van Patten5f744f12018-12-12 11:46:21 -070084 bool shouldUseAngle();
Cody Northrop1f00e172018-04-02 11:23:31 -060085 // 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 Pattena2a60a02018-11-09 16:51:15 -070090 void setAngleInfo(const std::string path, const std::string appName, std::string devOptIn,
Cody Northropf0874d32018-10-29 10:59:45 -060091 const int rulesFd, const long rulesOffset, const long rulesLength);
Yiwei Zhang81e26a12019-07-02 19:48:23 -070092 // Get the ANGLE driver namespace.
Cody Northrop1f00e172018-04-02 11:23:31 -060093 android_namespace_t* getAngleNamespace();
Yiwei Zhang81e26a12019-07-02 19:48:23 -070094 // Get the app name for ANGLE debug message.
Tim Van Patten5f744f12018-12-12 11:46:21 -070095 std::string& getAngleAppName();
Cody Northrop1f00e172018-04-02 11:23:31 -060096
Yiwei Zhang81e26a12019-07-02 19:48:23 -070097 /*
98 * Apis for debug layer
99 */
100 // Set additional layer search paths.
Victor Khimenko4819b522018-07-13 17:24:18 +0200101 void setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths);
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700102 // Get the app namespace for loading layers.
Victor Khimenko4819b522018-07-13 17:24:18 +0200103 NativeLoaderNamespace* getAppNamespace();
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700104 // Get additional layer search paths.
Courtney Goeltzenleuchter30ad2ab2018-10-30 08:20:44 -0600105 const std::string& getLayerPaths();
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700106 // Set the Vulkan debug layers.
Cody Northropd2aa3ab2017-10-20 09:01:53 -0600107 void setDebugLayers(const std::string layers);
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700108 // Set the GL debug layers.
Cody Northropb9b01b62018-10-23 13:13:10 -0600109 void setDebugLayersGLES(const std::string layers);
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700110 // Get the debug layers to load.
Courtney Goeltzenleuchter30ad2ab2018-10-30 08:20:44 -0600111 const std::string& getDebugLayers();
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700112 // Get the debug layers to load.
Cody Northropb9b01b62018-10-23 13:13:10 -0600113 const std::string& getDebugLayersGLES();
Cody Northropd2aa3ab2017-10-20 09:01:53 -0600114
Jesse Hall90b25ed2016-12-12 12:56:46 -0800115private:
Tim Van Patten8bd24e92019-02-08 10:16:40 -0700116 enum UseAngle { UNKNOWN, YES, NO };
117
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700118 // Load requested ANGLE library.
Tim Van Patten5f744f12018-12-12 11:46:21 -0700119 void* loadLibrary(std::string name);
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700120 // Check ANGLE support with the rules.
Tim Van Patten5f744f12018-12-12 11:46:21 -0700121 bool checkAngleRules(void* so);
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700122 // Update whether ANGLE should be used.
Tim Van Patten5f744f12018-12-12 11:46:21 -0700123 void updateUseAngle();
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700124 // Link updatable driver namespace with llndk and vndk-sp libs.
Yiwei Zhang5e21eb32019-06-05 00:26:03 -0700125 bool linkDriverNamespaceLocked(android_namespace_t* vndkNamespace);
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700126 // Send the initial complete GpuStats to GpuService.
127 void sendGpuStatsLocked(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime);
Tim Van Patten5f744f12018-12-12 11:46:21 -0700128
Jesse Hall90b25ed2016-12-12 12:56:46 -0800129 GraphicsEnv() = default;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700130 // Path to updatable driver libs.
Jesse Hall90b25ed2016-12-12 12:56:46 -0800131 std::string mDriverPath;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700132 // Path to additional sphal libs linked to updatable driver namespace.
Yiwei Zhang6ef84942019-02-14 12:28:12 -0800133 std::string mSphalLibraries;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700134 // This mutex protects mGpuStats and get gpuservice call.
Yiwei Zhangd9861812019-02-13 11:51:55 -0800135 std::mutex mStatsLock;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700136 // Information bookkept for GpuStats.
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -0700137 GpuStatsInfo mGpuStats;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700138 // Path to ANGLE libs.
Cody Northrop1f00e172018-04-02 11:23:31 -0600139 std::string mAnglePath;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700140 // This App's name.
Courtney Goeltzenleuchterd41ef252018-09-26 14:37:42 -0600141 std::string mAngleAppName;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700142 // ANGLE developer opt in status.
Tim Van Pattena2a60a02018-11-09 16:51:15 -0700143 std::string mAngleDeveloperOptIn;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700144 // ANGLE rules.
Tim Van Patten5f744f12018-12-12 11:46:21 -0700145 std::vector<char> mRulesBuffer;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700146 // Use ANGLE flag.
Tim Van Patten8bd24e92019-02-08 10:16:40 -0700147 UseAngle mUseAngle = UNKNOWN;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700148 // Vulkan debug layers libs.
Cody Northropd2aa3ab2017-10-20 09:01:53 -0600149 std::string mDebugLayers;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700150 // GL debug layers libs.
Cody Northropb9b01b62018-10-23 13:13:10 -0600151 std::string mDebugLayersGLES;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700152 // Additional debug layers search path.
Cody Northropd2aa3ab2017-10-20 09:01:53 -0600153 std::string mLayerPaths;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700154 // This mutex protects the namespace creation.
Cody Northrop3892cfa2019-01-30 10:03:12 -0700155 std::mutex mNamespaceMutex;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700156 // Updatable driver namespace.
Jesse Hall53457db2016-12-14 16:54:06 -0800157 android_namespace_t* mDriverNamespace = nullptr;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700158 // ANGLE namespace.
Cody Northrop1f00e172018-04-02 11:23:31 -0600159 android_namespace_t* mAngleNamespace = nullptr;
Yiwei Zhang81e26a12019-07-02 19:48:23 -0700160 // This App's namespace.
Victor Khimenko4819b522018-07-13 17:24:18 +0200161 NativeLoaderNamespace* mAppNamespace = nullptr;
Jesse Hall90b25ed2016-12-12 12:56:46 -0800162};
163
164} // namespace android
165
Mathias Agopian991d2542017-02-06 13:51:32 -0800166#endif // ANDROID_UI_GRAPHICS_ENV_H