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

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

SF: Move/Refactor rebuildLayerStacks and computeVisibleRegions

This is the one big final move of code to CompositionEngine.

The logic is restructured, though the basic blocks still correspond to
what existed before to allow for easier conflict resolution across the
move.

The function to compute the per-layer visibility information is still
much bigger than I like -- perhaps this can be cleaned up later after
more unit test coverage is introduced.

Test: atest libsurfaceflinger_unittest libcompositionengine_test
Test: atest CtsColorModeTestCases
Test: atest CtsDisplayTestCases
Test: atest CtsGraphicsTestCases
Test: atest CtsUiRenderingTestCases
Test: atest CtsViewTestCases
Test: atest android.media.cts.EncodeVirtualDisplayWithCompositionTest
Test: go/wm-smoke
Bug: 121291683
Change-Id: Ia3fb6c0fb0bb847ab737a1f92617d3724c08ea54
parent 66c20c4d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <chrono>
#include <optional>
#include <vector>

#include <compositionengine/Display.h>
#include <compositionengine/Layer.h>
@@ -28,6 +29,7 @@ namespace android::compositionengine {

using Layers = std::vector<std::shared_ptr<compositionengine::Layer>>;
using Outputs = std::vector<std::shared_ptr<compositionengine::Output>>;
using RawLayers = std::vector<compositionengine::Layer*>;

/**
 * A parameter object for refreshing a set of outputs
@@ -41,6 +43,9 @@ struct CompositionRefreshArgs {
    // front.
    Layers layers;

    // All the layers that have queued updates.
    RawLayers layersWithQueuedFrames;

    // If true, forces the entire display to be considered dirty and repainted
    bool repaintEverything{false};

@@ -53,6 +58,9 @@ struct CompositionRefreshArgs {
    // Forces a color mode on the outputs being refreshed
    ui::ColorMode forceOutputColorMode{ui::ColorMode::NATIVE};

    // If true, the complete output geometry needs to be recomputed this frame
    bool updatingOutputGeometryThisFrame{false};

    // If true, there was a geometry update this frame
    bool updatingGeometryThisFrame{false};

+9 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <optional>
#include <unordered_set>

#include <renderengine/LayerSettings.h>
#include <utils/RefBase.h>
@@ -99,5 +100,13 @@ public:
    virtual const char* getDebugName() const = 0;
};

// TODO(b/121291683): Specialize std::hash<> for sp<T> so these and others can
// be removed.
struct LayerFESpHash {
    size_t operator()(const sp<LayerFE>& p) const { return std::hash<LayerFE*>()(p.get()); }
};

using LayerFESet = std::unordered_set<sp<LayerFE>, LayerFESpHash>;

} // namespace compositionengine
} // namespace android
+25 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <string>
#include <unordered_map>

#include <compositionengine/LayerFE.h>
#include <renderengine/LayerSettings.h>
#include <ui/Fence.h>
#include <ui/GraphicTypes.h>
@@ -71,6 +72,22 @@ public:
        ui::Dataspace colorSpaceAgnosticDataspace{ui::Dataspace::UNKNOWN};
    };

    // Use internally to incrementally compute visibility/coverage
    struct CoverageState {
        explicit CoverageState(LayerFESet& latchedLayers) : latchedLayers(latchedLayers) {}

        // The set of layers that had been latched for the coverage calls, to
        // avoid duplicate requests to obtain the same front-end layer state.
        LayerFESet& latchedLayers;

        // The region of the output which is covered by layers
        Region aboveCoveredLayers;
        // The region of the output which is opaquely covered by layers
        Region aboveOpaqueLayers;
        // The region of the output which should be considered dirty
        Region dirtyRegion;
    };

    virtual ~Output();

    // Returns true if the output is valid. This is meant to be checked post-
@@ -164,7 +181,7 @@ public:
    virtual ReleasedLayers takeReleasedLayers() = 0;

    // Prepare the output, updating the OutputLayers used in the output
    virtual void prepare(CompositionRefreshArgs&) = 0;
    virtual void prepare(const CompositionRefreshArgs&, LayerFESet&) = 0;

    // Presents the output, finalizing all composition details
    virtual void present(const CompositionRefreshArgs&) = 0;
@@ -176,6 +193,13 @@ protected:
    virtual void setDisplayColorProfile(std::unique_ptr<DisplayColorProfile>) = 0;
    virtual void setRenderSurface(std::unique_ptr<RenderSurface>) = 0;

    virtual void rebuildLayerStacks(const compositionengine::CompositionRefreshArgs&,
                                    LayerFESet&) = 0;
    virtual void collectVisibleLayers(const CompositionRefreshArgs&, CoverageState&) = 0;
    virtual std::unique_ptr<OutputLayer> getOutputLayerIfVisible(
            std::shared_ptr<compositionengine::Layer>, CoverageState&) = 0;
    virtual void setReleasedLayers(const compositionengine::CompositionRefreshArgs&) = 0;

    virtual void updateAndWriteCompositionState(const CompositionRefreshArgs&) = 0;
    virtual void setColorTransform(const CompositionRefreshArgs&) = 0;
    virtual void updateColorProfile(const CompositionRefreshArgs&) = 0;
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ public:
    void dump(std::string&) const override;
    std::unique_ptr<compositionengine::OutputLayer> createOutputLayer(
            const std::shared_ptr<Layer>&, const sp<LayerFE>&) const override;
    using compositionengine::impl::Output::setReleasedLayers;
    void setReleasedLayers(const compositionengine::CompositionRefreshArgs&) override;
    void setColorTransform(const compositionengine::CompositionRefreshArgs&) override;
    void setColorProfile(const ColorProfile&) override;
    void chooseCompositionStrategy() override;
+12 −1
Original line number Diff line number Diff line
@@ -77,9 +77,17 @@ public:
    void setReleasedLayers(ReleasedLayers&&) override;
    ReleasedLayers takeReleasedLayers() override;

    void prepare(compositionengine::CompositionRefreshArgs&) override;
    void prepare(const compositionengine::CompositionRefreshArgs&, LayerFESet&) override;
    void present(const compositionengine::CompositionRefreshArgs&) override;

    void rebuildLayerStacks(const compositionengine::CompositionRefreshArgs&, LayerFESet&) override;
    void collectVisibleLayers(const compositionengine::CompositionRefreshArgs&,
                              compositionengine::Output::CoverageState&) override;
    std::unique_ptr<compositionengine::OutputLayer> getOutputLayerIfVisible(
            std::shared_ptr<compositionengine::Layer>,
            compositionengine::Output::CoverageState&) override;
    void setReleasedLayers(const compositionengine::CompositionRefreshArgs&) override;

    void updateLayerStateFromFE(const CompositionRefreshArgs&) const override;
    void updateAndWriteCompositionState(const compositionengine::CompositionRefreshArgs&) override;
    void updateColorProfile(const compositionengine::CompositionRefreshArgs&) override;
@@ -91,11 +99,14 @@ public:
    void postFramebuffer() override;

    // Testing
    const ReleasedLayers& getReleasedLayersForTest() const;
    void setDisplayColorProfileForTest(std::unique_ptr<compositionengine::DisplayColorProfile>);
    void setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSurface>);

protected:
    const CompositionEngine& getCompositionEngine() const;
    std::unique_ptr<compositionengine::OutputLayer> takeOutputLayerForLayer(
            compositionengine::Layer*);
    void chooseCompositionStrategy() override;
    bool getSkipColorTransform() const override;
    compositionengine::Output::FrameFences presentAndGetFrameFences() override;
Loading