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

Commit 793f8366 authored by Melody Hsu's avatar Melody Hsu
Browse files

Add promise for buffer releaseFence to LayerFE.

Buffers can only be released when a release fence fires.
Instead of tracking and waiting for each layer's Futures to
complete, LayerFE can keep track of its own Future via a
promise of a fence. This cleans up the shared futures that
are currently being tracked and allow us to setup for
eventual goals to reduce the number of screenshot calls to
the main thread.

Tests using a virtual display are modified to use the
mirrorDisplay API with a unique layerstack.

Bug: b/294936197, b/285553970
Test: manual (screenshot, camera, rotation, picture-in-picture)
Test: presubmit
Test: atest CompositionEnginePostCompositionTest
Test: atest SurfaceFlinger_test
Change-Id: I3a0af2cd02d3d010a1ea7c860c5cb0bc20837ec2
parent 00853e59
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -73,6 +73,9 @@ public:
    // TODO(b/121291683): These will become private/internal
    virtual void preComposition(CompositionRefreshArgs&) = 0;

    // Resolves any unfulfilled promises for release fences
    virtual void postComposition(CompositionRefreshArgs&) = 0;

    virtual FeatureFlags getFeatureFlags() const = 0;

    // Debugging
+22 −0
Original line number Diff line number Diff line
@@ -133,6 +133,15 @@ public:
        uint64_t frameNumber = 0;
    };

    // Describes the states of the release fence. Checking the states allows checks
    // to ensure that set_value() is not called on the same promise multiple times,
    // and can indicate if the promise has been fulfilled.
    enum class ReleaseFencePromiseStatus {
        UNINITIALIZED, // Promise not created
        INITIALIZED,   // Promise created, fence has not been set
        FULFILLED      // Promise fulfilled, fence is set
    };

    // Returns the LayerSettings to pass to RenderEngine::drawLayers. The state may contain shadows
    // casted by the layer or the content of the layer itself. If the layer does not render then an
    // empty optional will be returned.
@@ -142,6 +151,19 @@ public:
    // Called after the layer is displayed to update the presentation fence
    virtual void onLayerDisplayed(ftl::SharedFuture<FenceResult>, ui::LayerStack layerStack) = 0;

    // Initializes a promise for a buffer release fence and provides the future for that
    // fence. This should only be called when a promise has not yet been created, or
    // after the previous promise has already been fulfilled. Attempting to call this
    // when an existing promise is INITIALIZED will fail because the promise has not
    // yet been fulfilled.
    virtual ftl::Future<FenceResult> createReleaseFenceFuture() = 0;

    // Sets promise with its buffer's release fence
    virtual void setReleaseFence(const FenceResult& releaseFence) = 0;

    // Checks if the buffer's release fence has been set
    virtual LayerFE::ReleaseFencePromiseStatus getReleaseFencePromiseStatus() = 0;

    // Gets some kind of identifier for the layer for debug purposes.
    virtual const char* getDebugName() const = 0;

+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ public:

    void preComposition(CompositionRefreshArgs&) override;

    void postComposition(CompositionRefreshArgs&) override;

    FeatureFlags getFeatureFlags() const override;

    // Debugging
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ public:
    MOCK_METHOD1(updateCursorAsync, void(CompositionRefreshArgs&));

    MOCK_METHOD1(preComposition, void(CompositionRefreshArgs&));
    MOCK_METHOD1(postComposition, void(CompositionRefreshArgs&));

    MOCK_CONST_METHOD0(getFeatureFlags, FeatureFlags());

+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <compositionengine/LayerFECompositionState.h>
#include <gmock/gmock.h>
#include <ui/Fence.h>
#include "ui/FenceResult.h"

namespace android::compositionengine::mock {

@@ -52,6 +53,9 @@ public:
    MOCK_METHOD(void, onLayerDisplayed, (ftl::SharedFuture<FenceResult>, ui::LayerStack),
                (override));

    MOCK_METHOD0(createReleaseFenceFuture, ftl::Future<FenceResult>());
    MOCK_METHOD1(setReleaseFence, void(const FenceResult&));
    MOCK_METHOD0(getReleaseFencePromiseStatus, LayerFE::ReleaseFencePromiseStatus());
    MOCK_CONST_METHOD0(getDebugName, const char*());
    MOCK_CONST_METHOD0(getSequence, int32_t());
    MOCK_CONST_METHOD0(hasRoundedCorners, bool());
Loading