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

Commit cb54b3b7 authored by Lloyd Pique's avatar Lloyd Pique
Browse files

SF: Refactor onLayerDisplayed

Adds a new LayerFE::onLayerDisplayed interface, and adjusts the
front-end Layer to match.

Adjusts the code in SurfaceFlinger to use the new interface, in
preparation to moving the loop over to CompositionEngine.

Test: atest libsurfaceflinger_unittest libcompositionengine_test
Bug: 121291683
Change-Id: I9231f4b425ea1b9f37363521c7e3f6aef63bcec6
parent 685d7a3c
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -18,10 +18,19 @@

#include <utils/RefBase.h>

namespace android::compositionengine {
namespace android {

class Fence;

namespace compositionengine {

// Defines the interface used by the CompositionEngine to make requests
// of the front-end layer
class LayerFE : public virtual RefBase {};
class LayerFE : public virtual RefBase {
public:
    // Called after the layer is displayed to update the presentation fence
    virtual void onLayerDisplayed(const sp<Fence>&) = 0;
};

} // namespace android::compositionengine
} // namespace compositionengine
} // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <compositionengine/LayerFE.h>
#include <gmock/gmock.h>
#include <ui/Fence.h>

namespace android::compositionengine::mock {

@@ -27,6 +28,8 @@ class LayerFE : public compositionengine::LayerFE {
public:
    LayerFE();
    virtual ~LayerFE();

    MOCK_METHOD1(onLayerDisplayed, void(const sp<Fence>&));
};

} // namespace android::compositionengine::mock
+5 −5
Original line number Diff line number Diff line
@@ -440,6 +440,11 @@ protected:
                                    renderengine::LayerSettings& layer) = 0;

public:
    /*
     * compositionengine::LayerFE overrides
     */
    void onLayerDisplayed(const sp<Fence>& releaseFence) override;

    virtual void setDefaultBufferSize(uint32_t /*w*/, uint32_t /*h*/) {}

    virtual bool isHdrY410() const { return false; }
@@ -460,11 +465,6 @@ public:
    bool getClearClientTarget(const sp<const DisplayDevice>& display) const;
    void updateCursorPosition(const sp<const DisplayDevice>& display);

    /*
     * called after page-flip
     */
    virtual void onLayerDisplayed(const sp<Fence>& releaseFence);

    virtual bool shouldPresentNow(nsecs_t /*expectedPresentTime*/) const { return false; }
    virtual void setTransformHint(uint32_t /*orientation*/) const { }

+10 −8
Original line number Diff line number Diff line
@@ -2448,16 +2448,19 @@ void SurfaceFlinger::postFramebuffer(const sp<DisplayDevice>& displayDevice) {
            getHwComposer().presentAndGetReleaseFences(*displayId);
        }
        display->getRenderSurface()->onPresentDisplayCompleted();
        for (auto& layer : displayDevice->getVisibleLayersSortedByZ()) {
        for (auto& layer : display->getOutputLayersOrderedByZ()) {
            sp<Fence> releaseFence = Fence::NO_FENCE;
            bool usedClientComposition = true;

            // The layer buffer from the previous frame (if any) is released
            // by HWC only when the release fence from this frame (if any) is
            // signaled.  Always get the release fence from HWC first.
            if (displayId && layer->hasHwcLayer(displayDevice)) {
            if (layer->getState().hwc) {
                const auto& hwcState = *layer->getState().hwc;
                releaseFence =
                        getHwComposer().getLayerReleaseFence(*displayId,
                                                             layer->getHwcLayer(displayDevice));
                        getHwComposer().getLayerReleaseFence(*displayId, hwcState.hwcLayer.get());
                usedClientComposition =
                        hwcState.hwcCompositionType == Hwc2::IComposerClient::Composition::CLIENT;
            }

            // If the layer was client composited in the previous frame, we
@@ -2465,14 +2468,13 @@ void SurfaceFlinger::postFramebuffer(const sp<DisplayDevice>& displayDevice) {
            // Since we do not track that, always merge with the current
            // client target acquire fence when it is available, even though
            // this is suboptimal.
            if (layer->getCompositionType(displayDevice) ==
                Hwc2::IComposerClient::Composition::CLIENT) {
            if (usedClientComposition) {
                releaseFence =
                        Fence::merge("LayerRelease", releaseFence,
                                     display->getRenderSurface()->getClientTargetAcquireFence());
            }

            layer->getBE().onLayerDisplayed(releaseFence);
            layer->getLayerFE().onLayerDisplayed(releaseFence);
        }

        // We've got a list of layers needing fences, that are disjoint with
@@ -2482,7 +2484,7 @@ void SurfaceFlinger::postFramebuffer(const sp<DisplayDevice>& displayDevice) {
            sp<Fence> presentFence =
                    displayId ? getHwComposer().getPresentFence(*displayId) : Fence::NO_FENCE;
            for (auto& layer : displayDevice->getLayersNeedingFences()) {
                layer->getBE().onLayerDisplayed(presentFence);
                layer->getCompositionLayer()->getLayerFE()->onLayerDisplayed(presentFence);
            }
        }