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

Commit e2ee040d authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Reorder the layers sent to HWC

Bug: 163076219
Test: manual
Test: I53fc851eca876d44ba7cb9347f1c62d659c38932

Remove OutputLayerCompositionState.z, LayerStateField::ZOrder, and
LayerState::mZOrder. Note that the layers are already stored in the
proper z-order (back to front). When sending them to HWC, specify order
with a local variable. The LayerState and -Field ZOrders were used to
treat layers with different z's as a differing field for comparison. But
in practice, a change in z order will change the geometry, resulting in
recreating all CachedSets. (Add a test to verify this changes the
NonBufferHash.)

Add peekThroughLayer to overrideInfo, which is used by Output to
reorder the layers and to change the blendMode so the peekThroughLayer
can be seen through it.

In Flattener::mergeWithCachedSets, update overrideInfo to include
peekThroughLayer, using a new accessor on CachedSet.

Add more info to CachedSet::dump().

Test updates:
- Remove tests that verify the state of OutputLayerCompositionState.z
and ZOrder.
- In LayerStackTest#getApproximateMatch_doesNotMatchManyDifferences, we
were setting kMaxDifferingFields + 1 fields to be different. Removing z
made these two stacks match, so replace with another (arbitrary) field.
- Fix OutputLayer tests to expect calling the new method
LayerFE::hasRoundedCorners

Latest patch set fixes a rebase error in includesOverrideInfoIfPresent.

Change-Id: I845a0f7016c57652045f6f5a082175304272347f
parent f8a18312
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#pragma once

#include <cstdint>
#include <optional>
#include <string>

@@ -90,8 +91,10 @@ public:
    // Writes the geometry state to the HWC, or does nothing if this layer does
    // not use the HWC. If includeGeometry is false, the geometry state can be
    // skipped. If skipLayer is true, then the alpha of the layer is forced to
    // 0 so that HWC will ignore it.
    virtual void writeStateToHWC(bool includeGeometry, bool skipLayer) = 0;
    // 0 so that HWC will ignore it. z specifies the order to draw the layer in
    // (starting with 0 for the back layer, and increasing for each following
    // layer).
    virtual void writeStateToHWC(bool includeGeometry, bool skipLayer, uint32_t z) = 0;

    // Updates the cursor position with the HWC
    virtual void writeCursorPositionToHWC() const = 0;
+4 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#pragma once

#include <cstdint>
#include <memory>
#include <string>

@@ -42,7 +43,7 @@ public:

    void updateCompositionState(bool includeGeometry, bool forceClientComposition,
                                ui::Transform::RotationFlags) override;
    void writeStateToHWC(bool includeGeometry, bool skipLayer) override;
    void writeStateToHWC(bool includeGeometry, bool skipLayer, uint32_t z) override;
    void writeCursorPositionToHWC() const override;

    HWC2::Layer* getHwcLayer() const override;
@@ -66,7 +67,8 @@ protected:

private:
    Rect calculateInitialCrop() const;
    void writeOutputDependentGeometryStateToHWC(HWC2::Layer*, Hwc2::IComposerClient::Composition);
    void writeOutputDependentGeometryStateToHWC(HWC2::Layer*, Hwc2::IComposerClient::Composition,
                                                uint32_t z);
    void writeOutputIndependentGeometryStateToHWC(HWC2::Layer*, const LayerFECompositionState&,
                                                  bool skipLayer);
    void writeOutputDependentPerFrameStateToHWC(HWC2::Layer*);
+10 −3
Original line number Diff line number Diff line
@@ -46,6 +46,10 @@ class Layer;

class HWComposer;

namespace compositionengine {
class OutputLayer;
} // namespace compositionengine

namespace compositionengine::impl {

// Note that fields that affect HW composer state may need to be mirrored into
@@ -84,9 +88,6 @@ struct OutputLayerCompositionState {
    // The dataspace for this layer
    ui::Dataspace dataspace{ui::Dataspace::UNKNOWN};

    // The Z order index of this layer on this output
    uint32_t z{0};

    // Overrides the buffer, acquire fence, and display frame stored in LayerFECompositionState
    struct {
        std::shared_ptr<renderengine::ExternalTexture> buffer = nullptr;
@@ -96,6 +97,12 @@ struct OutputLayerCompositionState {
        ProjectionSpace displaySpace;
        Region damageRegion = Region::INVALID_REGION;
        Region visibleRegion;

        // The OutputLayer pointed to by this field will be rearranged to draw
        // behind the OutputLayer represented by this CompositionState and will
        // be visible through it. Unowned - the OutputLayer's lifetime will
        // outlast this.)
        OutputLayer* peekThroughLayer = nullptr;
    } overrideInfo;

    /*
+5 −0
Original line number Diff line number Diff line
@@ -115,12 +115,17 @@ public:
    // through. Must be called before ::render().
    void addHolePunchLayer(const LayerState*);

    // Retrieve the layer that will be drawn behind this one.
    OutputLayer* getHolePunchLayer() const;

private:
    CachedSet() = default;

    const NonBufferHash mFingerprint;
    std::chrono::steady_clock::time_point mLastUpdate = std::chrono::steady_clock::now();
    std::vector<Layer> mLayers;

    // Unowned.
    const LayerState* mHolePunchLayer = nullptr;
    Rect mBounds = Rect::EMPTY_RECT;
    Region mVisibleRegion;
+18 −22
Original line number Diff line number Diff line
@@ -53,20 +53,19 @@ enum class LayerStateField : uint32_t {
    Name            = 1u << 1,
    DisplayFrame    = 1u << 2,
    SourceCrop      = 1u << 3,
    ZOrder          = 1u << 4,
    BufferTransform = 1u << 5,
    BlendMode       = 1u << 6,
    Alpha           = 1u << 7,
    LayerMetadata   = 1u << 8,
    VisibleRegion   = 1u << 9,
    Dataspace       = 1u << 10,
    PixelFormat     = 1u << 11,
    ColorTransform  = 1u << 12,
    SurfaceDamage   = 1u << 13,
    CompositionType = 1u << 14,
    SidebandStream  = 1u << 15,
    Buffer          = 1u << 16,
    SolidColor      = 1u << 17,
    BufferTransform = 1u << 4,
    BlendMode       = 1u << 5,
    Alpha           = 1u << 6,
    LayerMetadata   = 1u << 7,
    VisibleRegion   = 1u << 8,
    Dataspace       = 1u << 9,
    PixelFormat     = 1u << 10,
    ColorTransform  = 1u << 11,
    SurfaceDamage   = 1u << 12,
    CompositionType = 1u << 13,
    SidebandStream  = 1u << 14,
    Buffer          = 1u << 15,
    SolidColor      = 1u << 16,
};
// clang-format on

@@ -271,9 +270,6 @@ private:
                                                       rect.top, rect.right, rect.bottom)};
                        }};

    OutputLayerState<uint32_t, LayerStateField::ZOrder> mZOrder{
            [](auto layer) { return layer->getState().z; }};

    using BufferTransformState = OutputLayerState<hardware::graphics::composer::hal::Transform,
                                                  LayerStateField::BufferTransform>;
    BufferTransformState mBufferTransform{[](auto layer) {
@@ -402,7 +398,7 @@ private:
                            return std::vector<std::string>{stream.str()};
                        }};

    static const constexpr size_t kNumNonUniqueFields = 15;
    static const constexpr size_t kNumNonUniqueFields = 14;

    std::array<StateInterface*, kNumNonUniqueFields> getNonUniqueFields() {
        std::array<const StateInterface*, kNumNonUniqueFields> constFields =
@@ -417,10 +413,10 @@ private:

    std::array<const StateInterface*, kNumNonUniqueFields> getNonUniqueFields() const {
        return {
                &mDisplayFrame,    &mSourceCrop,     &mZOrder,         &mBufferTransform,
                &mBlendMode,       &mAlpha,          &mLayerMetadata,  &mVisibleRegion,
                &mOutputDataspace, &mPixelFormat,    &mColorTransform, &mCompositionType,
                &mSidebandStream,  &mBuffer,         &mSolidColor,
                &mDisplayFrame, &mSourceCrop,     &mBufferTransform, &mBlendMode,
                &mAlpha,        &mLayerMetadata,  &mVisibleRegion,   &mOutputDataspace,
                &mPixelFormat,  &mColorTransform, &mCompositionType, &mSidebandStream,
                &mBuffer,       &mSolidColor,
        };
    }
};
Loading