Skip to content

Commit 93ef636

Browse files
committed
GraphicsEnv: Add FeatureOverrides
Add the class FeatureOverrides to GraphicsEnv. This new class will be used to transport OpenGL ES feature configurations from GpuService to authorized recipients. Bug: 372694741 Test: CQ Flag: com.android.graphics.graphicsenv.flags.feature_overrides Change-Id: Id342caa7b67b119d992227d78f0c08c97e583842
1 parent 8c94bdb commit 93ef636

5 files changed

Lines changed: 113 additions & 0 deletions

File tree

libs/graphicsenv/Android.bp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,25 @@ package {
2121
default_applicable_licenses: ["frameworks_native_license"],
2222
}
2323

24+
aconfig_declarations {
25+
name: "graphicsenv_flags",
26+
package: "com.android.graphics.graphicsenv.flags",
27+
container: "system",
28+
srcs: ["graphicsenv_flags.aconfig"],
29+
}
30+
31+
cc_aconfig_library {
32+
name: "graphicsenv_flags_c_lib",
33+
aconfig_declarations: "graphicsenv_flags",
34+
}
35+
2436
cc_library_shared {
2537
name: "libgraphicsenv",
2638

39+
defaults: [
40+
"aconfig_lib_cc_static_link.defaults",
41+
],
42+
2743
srcs: [
2844
"GpuStatsInfo.cpp",
2945
"GraphicsEnv.cpp",
@@ -35,13 +51,18 @@ cc_library_shared {
3551
"-Werror",
3652
],
3753

54+
static_libs: [
55+
"graphicsenv_flags_c_lib",
56+
],
57+
3858
shared_libs: [
3959
"libbase",
4060
"libbinder",
4161
"libcutils",
4262
"libdl_android",
4363
"liblog",
4464
"libutils",
65+
"server_configurable_flags",
4566
],
4667

4768
header_libs: [

libs/graphicsenv/GraphicsEnv.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <android-base/strings.h>
3030
#include <android/dlext.h>
3131
#include <binder/IServiceManager.h>
32+
#include <com_android_graphics_graphicsenv_flags.h>
3233
#include <graphicsenv/IGpuService.h>
3334
#include <log/log.h>
3435
#include <nativeloader/dlext_namespaces.h>
@@ -70,6 +71,8 @@ static bool isVndkEnabled() {
7071
}
7172
} // namespace
7273

74+
namespace graphicsenv_flags = com::android::graphics::graphicsenv::flags;
75+
7376
namespace android {
7477

7578
enum NativeLibrary {
@@ -624,10 +627,36 @@ std::string& GraphicsEnv::getPackageName() {
624627
return mPackageName;
625628
}
626629

630+
// List of ANGLE features to enable, specified in the Global.Settings value "angle_egl_features".
627631
const std::vector<std::string>& GraphicsEnv::getAngleEglFeatures() {
628632
return mAngleEglFeatures;
629633
}
630634

635+
void GraphicsEnv::getAngleFeatureOverrides(std::vector<const char*>& enabled,
636+
std::vector<const char*>& disabled) {
637+
if (!graphicsenv_flags::feature_overrides()) {
638+
return;
639+
}
640+
641+
for (const FeatureConfig& feature : mFeatureOverrides.mGlobalFeatures) {
642+
if (feature.mEnabled) {
643+
enabled.push_back(feature.mFeatureName.c_str());
644+
} else {
645+
disabled.push_back(feature.mFeatureName.c_str());
646+
}
647+
}
648+
649+
if (mFeatureOverrides.mPackageFeatures.count(mPackageName)) {
650+
for (const FeatureConfig& feature : mFeatureOverrides.mPackageFeatures[mPackageName]) {
651+
if (feature.mEnabled) {
652+
enabled.push_back(feature.mFeatureName.c_str());
653+
} else {
654+
disabled.push_back(feature.mFeatureName.c_str());
655+
}
656+
}
657+
}
658+
}
659+
631660
android_namespace_t* GraphicsEnv::getAngleNamespace() {
632661
std::lock_guard<std::mutex> lock(mNamespaceMutex);
633662

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package: "com.android.graphics.graphicsenv.flags"
2+
container: "system"
3+
4+
flag {
5+
name: "feature_overrides"
6+
namespace: "core_graphics"
7+
description: "This flag controls the Feature Overrides in GraphicsEnv."
8+
bug: "372694741"
9+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2024 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+
#pragma once
18+
19+
#include <map>
20+
#include <string>
21+
#include <vector>
22+
23+
namespace android {
24+
25+
class FeatureConfig {
26+
public:
27+
FeatureConfig() = default;
28+
FeatureConfig(const FeatureConfig&) = default;
29+
virtual ~FeatureConfig() = default;
30+
31+
std::string mFeatureName;
32+
bool mEnabled;
33+
};
34+
35+
/*
36+
* Class for transporting OpenGL ES Feature configurations from GpuService to authorized
37+
* recipients.
38+
*/
39+
class FeatureOverrides {
40+
public:
41+
FeatureOverrides() = default;
42+
FeatureOverrides(const FeatureOverrides&) = default;
43+
virtual ~FeatureOverrides() = default;
44+
45+
std::vector<FeatureConfig> mGlobalFeatures;
46+
/* Key: Package Name, Value: Package's Feature Configs */
47+
std::map<std::string, std::vector<FeatureConfig>> mPackageFeatures;
48+
};
49+
50+
} // namespace android

libs/graphicsenv/include/graphicsenv/GraphicsEnv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef ANDROID_UI_GRAPHICS_ENV_H
1818
#define ANDROID_UI_GRAPHICS_ENV_H 1
1919

20+
#include <graphicsenv/FeatureOverrides.h>
2021
#include <graphicsenv/GpuStatsInfo.h>
2122

2223
#include <mutex>
@@ -120,6 +121,8 @@ class GraphicsEnv {
120121
// Get the app package name.
121122
std::string& getPackageName();
122123
const std::vector<std::string>& getAngleEglFeatures();
124+
void getAngleFeatureOverrides(std::vector<const char*>& enabled,
125+
std::vector<const char*>& disabled);
123126
// Set the persist.graphics.egl system property value.
124127
void nativeToggleAngleAsSystemDriver(bool enabled);
125128
bool shouldUseSystemAngle();
@@ -177,6 +180,7 @@ class GraphicsEnv {
177180
std::string mPackageName;
178181
// ANGLE EGL features;
179182
std::vector<std::string> mAngleEglFeatures;
183+
FeatureOverrides mFeatureOverrides;
180184
// Whether ANGLE should be used.
181185
bool mShouldUseAngle = false;
182186
// Whether loader should load system ANGLE.

0 commit comments

Comments
 (0)