Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cbfd32d5 authored by Tim Van Patten's avatar Tim Van Patten Committed by Android (Google) Code Review
Browse files

Merge "GraphicsEnv: Add FeatureOverrides" into main

parents 9211819a 93ef636c
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -21,9 +21,25 @@ package {
    default_applicable_licenses: ["frameworks_native_license"],
}

aconfig_declarations {
    name: "graphicsenv_flags",
    package: "com.android.graphics.graphicsenv.flags",
    container: "system",
    srcs: ["graphicsenv_flags.aconfig"],
}

cc_aconfig_library {
    name: "graphicsenv_flags_c_lib",
    aconfig_declarations: "graphicsenv_flags",
}

cc_library_shared {
    name: "libgraphicsenv",

    defaults: [
        "aconfig_lib_cc_static_link.defaults",
    ],

    srcs: [
        "GpuStatsInfo.cpp",
        "GraphicsEnv.cpp",
@@ -35,6 +51,10 @@ cc_library_shared {
        "-Werror",
    ],

    static_libs: [
        "graphicsenv_flags_c_lib",
    ],

    shared_libs: [
        "libbase",
        "libbinder",
@@ -42,6 +62,7 @@ cc_library_shared {
        "libdl_android",
        "liblog",
        "libutils",
        "server_configurable_flags",
    ],

    header_libs: [
+29 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <android-base/strings.h>
#include <android/dlext.h>
#include <binder/IServiceManager.h>
#include <com_android_graphics_graphicsenv_flags.h>
#include <graphicsenv/IGpuService.h>
#include <log/log.h>
#include <nativeloader/dlext_namespaces.h>
@@ -70,6 +71,8 @@ static bool isVndkEnabled() {
}
} // namespace

namespace graphicsenv_flags = com::android::graphics::graphicsenv::flags;

namespace android {

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

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

void GraphicsEnv::getAngleFeatureOverrides(std::vector<const char*>& enabled,
                                           std::vector<const char*>& disabled) {
    if (!graphicsenv_flags::feature_overrides()) {
        return;
    }

    for (const FeatureConfig& feature : mFeatureOverrides.mGlobalFeatures) {
        if (feature.mEnabled) {
            enabled.push_back(feature.mFeatureName.c_str());
        } else {
            disabled.push_back(feature.mFeatureName.c_str());
        }
    }

    if (mFeatureOverrides.mPackageFeatures.count(mPackageName)) {
        for (const FeatureConfig& feature : mFeatureOverrides.mPackageFeatures[mPackageName]) {
            if (feature.mEnabled) {
                enabled.push_back(feature.mFeatureName.c_str());
            } else {
                disabled.push_back(feature.mFeatureName.c_str());
            }
        }
    }
}

android_namespace_t* GraphicsEnv::getAngleNamespace() {
    std::lock_guard<std::mutex> lock(mNamespaceMutex);

+9 −0
Original line number Diff line number Diff line
package: "com.android.graphics.graphicsenv.flags"
container: "system"

flag {
  name: "feature_overrides"
  namespace: "core_graphics"
  description: "This flag controls the Feature Overrides in GraphicsEnv."
  bug: "372694741"
}
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <map>
#include <string>
#include <vector>

namespace android {

class FeatureConfig {
public:
    FeatureConfig() = default;
    FeatureConfig(const FeatureConfig&) = default;
    virtual ~FeatureConfig() = default;

    std::string mFeatureName;
    bool mEnabled;
};

/*
 * Class for transporting OpenGL ES Feature configurations from GpuService to authorized
 * recipients.
 */
class FeatureOverrides {
public:
    FeatureOverrides() = default;
    FeatureOverrides(const FeatureOverrides&) = default;
    virtual ~FeatureOverrides() = default;

    std::vector<FeatureConfig> mGlobalFeatures;
    /* Key: Package Name, Value: Package's Feature Configs */
    std::map<std::string, std::vector<FeatureConfig>> mPackageFeatures;
};

} // namespace android
+4 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef ANDROID_UI_GRAPHICS_ENV_H
#define ANDROID_UI_GRAPHICS_ENV_H 1

#include <graphicsenv/FeatureOverrides.h>
#include <graphicsenv/GpuStatsInfo.h>

#include <mutex>
@@ -120,6 +121,8 @@ public:
    // Get the app package name.
    std::string& getPackageName();
    const std::vector<std::string>& getAngleEglFeatures();
    void getAngleFeatureOverrides(std::vector<const char*>& enabled,
                                  std::vector<const char*>& disabled);
    // Set the persist.graphics.egl system property value.
    void nativeToggleAngleAsSystemDriver(bool enabled);
    bool shouldUseSystemAngle();
@@ -177,6 +180,7 @@ private:
    std::string mPackageName;
    // ANGLE EGL features;
    std::vector<std::string> mAngleEglFeatures;
    FeatureOverrides mFeatureOverrides;
    // Whether ANGLE should be used.
    bool mShouldUseAngle = false;
    // Whether loader should load system ANGLE.