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

Commit d6d8016d authored by Ady Abraham's avatar Ady Abraham
Browse files

SF: move trunk stable flags to FlagManager

Test: presubmit
Bug: 297389311
Bug: 278199093
Bug: 284845445
Bug: 273702768
Bug: 259132483
Bug: 283055450
Change-Id: I2a85b2534ac8d472acd0de443785317871bbfe89
parent c589dc40
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -30,8 +30,8 @@
#include <scheduler/Fps.h>

#include "DisplayHardware/Hal.h"
#include "FlagManager.h"
#include "Scheduler/StrongTyping.h"
#include "Utils/FlagUtils.h"

namespace android {

@@ -50,7 +50,6 @@ using DisplayModeId = StrongTyping<ui::DisplayModeId, struct DisplayModeIdTag, C

using DisplayModes = ftl::SmallMap<DisplayModeId, DisplayModePtr, 3>;
using DisplayModeIterator = DisplayModes::const_iterator;
using namespace com::android::graphics::surfaceflinger;

class DisplayMode {
public:
@@ -140,7 +139,7 @@ public:
    // Peak refresh rate represents the highest refresh rate that can be used
    // for the presentation.
    Fps getPeakFps() const {
        return flagutils::vrrConfigEnabled() && mVrrConfig
        return FlagManager::getInstance().vrr_config() && mVrrConfig
                ? Fps::fromPeriodNsecs(mVrrConfig->minFrameIntervalNs)
                : mVsyncRate;
    }
+74 −8
Original line number Diff line number Diff line
@@ -26,7 +26,11 @@
#include <server_configurable_flags/get_flags.h>
#include <cinttypes>

#include <com_android_graphics_surfaceflinger_flags.h>

namespace android {
using namespace com::android::graphics::surfaceflinger;

static constexpr const char* kExperimentNamespace = "surface_flinger_native_boot";

std::unique_ptr<FlagManager> FlagManager::mInstance;
@@ -48,6 +52,14 @@ std::optional<bool> parseBool(const char* str) {
    }
}

bool getFlagValue(std::function<bool()> getter, std::optional<bool> overrideValue) {
    if (overrideValue.has_value()) {
        return *overrideValue;
    }

    return getter();
}

void dumpFlag(std::string& result, const char* name, std::function<bool()> getter) {
    base::StringAppendF(&result, "%s: %s\n", name, getter() ? "true" : "false");
}
@@ -71,12 +83,25 @@ void FlagManager::markBootCompleted() {
    mBootCompleted = true;
}

void FlagManager::setUnitTestMode() {
    mUnitTestMode = true;

    // Also set boot completed as we don't really care about it in unit testing
    mBootCompleted = true;
}

void FlagManager::dump(std::string& result) const {
#define DUMP_FLAG(name) dumpFlag(result, #name, std::bind(&FlagManager::name, this));
#define DUMP_FLAG(name) dumpFlag(result, #name, std::bind(&FlagManager::name, this))

    base::StringAppendF(&result, "FlagManager values: \n");
    DUMP_FLAG(use_adpf_cpu_hint);
    DUMP_FLAG(use_skia_tracing);
    DUMP_FLAG(connected_display);
    DUMP_FLAG(dont_skip_on_early);
    DUMP_FLAG(enable_small_area_detection);
    DUMP_FLAG(misc1);
    DUMP_FLAG(late_boot_misc2);
    DUMP_FLAG(vrr_config);

#undef DUMP_FLAG
}
@@ -92,7 +117,7 @@ bool FlagManager::getServerConfigurableFlag(const char* experimentFlagName) cons
    return res.has_value() && res.value();
}

#define FLAG_MANAGER_SERVER_FLAG(name, syspropOverride, serverFlagName)                     \
#define FLAG_MANAGER_LEGACY_SERVER_FLAG(name, syspropOverride, serverFlagName)              \
    bool FlagManager::name() const {                                                        \
        LOG_ALWAYS_FATAL_IF(!mBootCompleted,                                                \
                            "Can't read %s before boot completed as it is server writable", \
@@ -102,12 +127,53 @@ bool FlagManager::getServerConfigurableFlag(const char* experimentFlagName) cons
        return getServerConfigurableFlag(serverFlagName);                                   \
    }

FLAG_MANAGER_SERVER_FLAG(test_flag, "", "")
FLAG_MANAGER_SERVER_FLAG(use_adpf_cpu_hint, "debug.sf.enable_adpf_cpu_hint",
#define FLAG_MANAGER_FLAG_INTERNAL(name, syspropOverride, checkForBootCompleted)                \
    bool FlagManager::name() const {                                                            \
        if (checkForBootCompleted) {                                                            \
            LOG_ALWAYS_FATAL_IF(!mBootCompleted,                                                \
                                "Can't read %s before boot completed as it is server writable", \
                                __func__);                                                      \
        }                                                                                       \
        static std::optional<bool> debugOverride = getBoolProperty(syspropOverride);            \
        static bool value = getFlagValue([] { return flags::name(); }, debugOverride);          \
        if (mUnitTestMode) {                                                                    \
            /*                                                                                  \
             * When testing, we don't want to rely on the cached values stored in the static    \
             * variables.                                                                       \
             */                                                                                 \
            debugOverride = getBoolProperty(syspropOverride);                                   \
            value = getFlagValue([] { return flags::name(); }, debugOverride);                  \
        }                                                                                       \
        return value;                                                                           \
    }

#define FLAG_MANAGER_SERVER_FLAG(name, syspropOverride) \
    FLAG_MANAGER_FLAG_INTERNAL(name, syspropOverride, true)

#define FLAG_MANAGER_READ_ONLY_FLAG(name, syspropOverride) \
    FLAG_MANAGER_FLAG_INTERNAL(name, syspropOverride, false)

/// Legacy server flags ///
FLAG_MANAGER_LEGACY_SERVER_FLAG(test_flag, "", "")
FLAG_MANAGER_LEGACY_SERVER_FLAG(use_adpf_cpu_hint, "debug.sf.enable_adpf_cpu_hint",
                                "AdpfFeature__adpf_cpu_hint")
FLAG_MANAGER_SERVER_FLAG(use_skia_tracing, PROPERTY_SKIA_ATRACE_ENABLED,
FLAG_MANAGER_LEGACY_SERVER_FLAG(use_skia_tracing, PROPERTY_SKIA_ATRACE_ENABLED,
                                "SkiaTracingFeature__use_skia_tracing")

#undef FLAG_MANAGER_SERVER_FLAG
/// Trunk stable readonly flags ///
FLAG_MANAGER_READ_ONLY_FLAG(connected_display, "")
FLAG_MANAGER_READ_ONLY_FLAG(enable_small_area_detection, "")
FLAG_MANAGER_READ_ONLY_FLAG(misc1, "")
FLAG_MANAGER_READ_ONLY_FLAG(vrr_config, "debug.sf.enable_vrr_config")

/// Trunk stable server flags ///
FLAG_MANAGER_SERVER_FLAG(late_boot_misc2, "")

/// Exceptions ///
bool FlagManager::dont_skip_on_early() const {
    // Even though this is a server writable flag, we do call it before boot completed, but that's
    // fine since the decision is done per frame. We can't do caching though.
    return flags::dont_skip_on_early();
}

} // namespace android
+15 −1
Original line number Diff line number Diff line
@@ -39,10 +39,23 @@ public:
    void markBootCompleted();
    void dump(std::string& result) const;

    void setUnitTestMode();

    /// Legacy server flags ///
    bool test_flag() const;
    bool use_adpf_cpu_hint() const;
    bool use_skia_tracing() const;

    /// Trunk stable readonly flags ///
    bool connected_display() const;
    bool enable_small_area_detection() const;
    bool misc1() const;
    bool vrr_config() const;

    /// Trunk stable server flags ///
    bool late_boot_misc2() const;
    bool dont_skip_on_early() const;

protected:
    // overridden for unit tests
    virtual std::optional<bool> getBoolProperty(const char*) const;
@@ -53,7 +66,8 @@ private:

    FlagManager(const FlagManager&) = delete;

    std::atomic_bool mBootCompleted;
    std::atomic_bool mBootCompleted = false;
    std::atomic_bool mUnitTestMode = false;

    static std::unique_ptr<FlagManager> mInstance;
    static std::once_flag mOnce;
+3 −2
Original line number Diff line number Diff line
@@ -17,9 +17,9 @@
#include <algorithm>

#include "Client.h"
#include "FlagManager.h"
#include "Layer.h"
#include "RefreshRateOverlay.h"
#include "Utils/FlagUtils.h"

#include <SkSurface.h>

@@ -268,7 +268,8 @@ void RefreshRateOverlay::changeRefreshRate(Fps vsyncRate, Fps renderFps) {
}

void RefreshRateOverlay::changeRenderRate(Fps renderFps) {
    if (mFeatures.test(Features::RenderRate) && mVsyncRate && flagutils::vrrConfigEnabled()) {
    if (mFeatures.test(Features::RenderRate) && mVsyncRate &&
        FlagManager::getInstance().vrr_config()) {
        mRenderFps = renderFps;
        const auto buffer = getOrCreateBuffers(*mVsyncRate, renderFps)[mFrame];
        createTransaction().setBuffer(mSurfaceControl->get(), buffer).apply();
+2 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@

#include <scheduler/VsyncConfig.h>
#include "DisplayHardware/DisplayMode.h"
#include "FlagManager.h"
#include "FrameTimeline.h"
#include "VSyncDispatch.h"
#include "VSyncTracker.h"
@@ -308,7 +309,7 @@ sp<EventThreadConnection> EventThread::createEventConnection(
    auto connection = sp<EventThreadConnection>::make(const_cast<EventThread*>(this),
                                                      IPCThreadState::self()->getCallingUid(),
                                                      eventRegistration);
    if (flags::misc1()) {
    if (FlagManager::getInstance().misc1()) {
        const int policy = SCHED_FIFO;
        connection->setMinSchedulerPolicy(policy, sched_get_priority_min(policy));
    }
Loading