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

Commit f5d0ea54 authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Remove manual enum stringification

Upgrade to scoped enums where applicable. Pull GameMode from TimeStats
into libgui to plumb it as an enum rather than int32_t.

Bug: 185536303
Test: libsurfaceflinger_unittest
Change-Id: I81fdd24805757ef953484055ee867684eb94fecf
parent 079ec332
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -59,4 +59,14 @@ struct LayerMetadata : public Parcelable {
    std::string itemToString(uint32_t key, const char* separator) const;
};

// Keep in sync with the GameManager.java constants.
enum class GameMode : int32_t {
    Unsupported = 0,
    Standard = 1,
    Performance = 2,
    Battery = 3,

    ftl_last = Battery
};

} // namespace android
+6 −8
Original line number Diff line number Diff line
@@ -401,12 +401,13 @@ void BufferLayer::onPostComposition(const DisplayDevice* display,
        const Fps refreshRate = display->refreshRateConfigs().getCurrentRefreshRate().getFps();
        const std::optional<Fps> renderRate =
                mFlinger->mScheduler->getFrameRateOverride(getOwnerUid());

        const auto vote = frameRateToSetFrameRateVotePayload(mDrawingState.frameRate);
        const auto gameMode = getGameMode();

        if (presentFence->isValid()) {
            mFlinger->mTimeStats->setPresentFence(layerId, mCurrentFrameNumber, presentFence,
                                                  refreshRate, renderRate,
                                                  frameRateToSetFrameRateVotePayload(
                                                          mDrawingState.frameRate),
                                                  getGameMode());
                                                  refreshRate, renderRate, vote, gameMode);
            mFlinger->mFrameTracer->traceFence(layerId, getCurrentBufferId(), mCurrentFrameNumber,
                                               presentFence,
                                               FrameTracer::FrameEvent::PRESENT_FENCE);
@@ -417,10 +418,7 @@ void BufferLayer::onPostComposition(const DisplayDevice* display,
            // timestamp instead.
            const nsecs_t actualPresentTime = display->getRefreshTimestamp();
            mFlinger->mTimeStats->setPresentTime(layerId, mCurrentFrameNumber, actualPresentTime,
                                                 refreshRate, renderRate,
                                                 frameRateToSetFrameRateVotePayload(
                                                         mDrawingState.frameRate),
                                                 getGameMode());
                                                 refreshRate, renderRate, vote, gameMode);
            mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(),
                                                   mCurrentFrameNumber, actualPresentTime,
                                                   FrameTracer::FrameEvent::PRESENT_FENCE);
+4 −7
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#pragma once

#include <cinttypes>

#include <ui/Size.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
@@ -47,13 +49,8 @@ public:
    // before composition takes place. The DisplaySurface can use the
    // composition type to decide how to manage the flow of buffers between
    // GPU and HWC for this frame.
    enum CompositionType {
        COMPOSITION_UNKNOWN = 0,
        COMPOSITION_GPU = 1,
        COMPOSITION_HWC = 2,
        COMPOSITION_MIXED = COMPOSITION_GPU | COMPOSITION_HWC
    };
    virtual status_t prepareFrame(CompositionType compositionType) = 0;
    enum class CompositionType : uint8_t { Unknown = 0, Gpu = 0b1, Hwc = 0b10, Mixed = Gpu | Hwc };
    virtual status_t prepareFrame(CompositionType) = 0;

    // Inform the surface that GPU composition is complete for this frame, and
    // the surface should make sure that HWComposer has the correct buffer for
+9 −10
Original line number Diff line number Diff line
@@ -127,19 +127,18 @@ status_t RenderSurface::beginFrame(bool mustRecompose) {
}

void RenderSurface::prepareFrame(bool usesClientComposition, bool usesDeviceComposition) {
    DisplaySurface::CompositionType compositionType;
    if (usesClientComposition && usesDeviceComposition) {
        compositionType = DisplaySurface::COMPOSITION_MIXED;
    } else if (usesClientComposition) {
        compositionType = DisplaySurface::COMPOSITION_GPU;
    } else if (usesDeviceComposition) {
        compositionType = DisplaySurface::COMPOSITION_HWC;
    } else {
    const auto compositionType = [=] {
        using CompositionType = DisplaySurface::CompositionType;

        if (usesClientComposition && usesDeviceComposition) return CompositionType::Mixed;
        if (usesClientComposition) return CompositionType::Gpu;
        if (usesDeviceComposition) return CompositionType::Hwc;

        // Nothing to do -- when turning the screen off we get a frame like
        // this. Call it a HWC frame since we won't be doing any GPU work but
        // will do a prepare/set cycle.
        compositionType = DisplaySurface::COMPOSITION_HWC;
    }
        return CompositionType::Hwc;
    }();

    if (status_t result = mDisplaySurface->prepareFrame(compositionType); result != NO_ERROR) {
        ALOGE("updateCompositionType failed for %s: %d (%s)", mDisplay.getName().c_str(), result,
+4 −4
Original line number Diff line number Diff line
@@ -201,28 +201,28 @@ TEST_F(RenderSurfaceTest, beginFrameAppliesChange) {
 */

TEST_F(RenderSurfaceTest, prepareFrameHandlesMixedComposition) {
    EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_MIXED))
    EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::CompositionType::Mixed))
            .WillOnce(Return(NO_ERROR));

    mSurface.prepareFrame(true, true);
}

TEST_F(RenderSurfaceTest, prepareFrameHandlesOnlyGpuComposition) {
    EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_GPU))
    EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::CompositionType::Gpu))
            .WillOnce(Return(NO_ERROR));

    mSurface.prepareFrame(true, false);
}

TEST_F(RenderSurfaceTest, prepareFrameHandlesOnlyHwcComposition) {
    EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_HWC))
    EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::CompositionType::Hwc))
            .WillOnce(Return(NO_ERROR));

    mSurface.prepareFrame(false, true);
}

TEST_F(RenderSurfaceTest, prepareFrameHandlesNoComposition) {
    EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::COMPOSITION_HWC))
    EXPECT_CALL(*mDisplaySurface, prepareFrame(DisplaySurface::CompositionType::Hwc))
            .WillOnce(Return(NO_ERROR));

    mSurface.prepareFrame(false, false);
Loading