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

Commit 9e217d60 authored by Snild Dolkow's avatar Snild Dolkow Committed by Lloyd Pique
Browse files

CompositionEngine: base inverse transform on primary display



Layers with geomBufferUsesDisplayInverseTransform set (usually layers
showing a camera preview) were not being rotated correctly on external
displays with hardware composition. Forcing GPU composition avoided
the issue, since BufferLayer.prepareClientLayer() uses the *primary*
display's orientation to create the inverse transformation.

But, the HWC path used each screen's orientation, resulting in a bad
layer rotation when the primary and external displays' orientation
differed. So let's do what the GPU path does.

This, of course, only makes a difference when the primary and secondary
display rotations differ. In our case, we noticed the problem when
running the landscape-oriented CinemaPro app, while our default camera,
which runs in portrait, did not have a problem.

Co-authored-by: default avatarMikael Magnusson <mikael.magnusson@sony.com>

Note: This is an updated version of the change with the same Change-Id
as uploaded to AOSP, as refactoring has continued, and more tests were
added since.

Bug: 155329360
Test: the new unit test fails without the patch
Test: the new unit test passes with the patch
Test: record using Cinema Pro app with an external screen
Reference: I0da22423490a93fe943fd59e6c122aa6aaf30b11
Change-Id: I8b4975a14a0ae42d10e4eeaa66385e72ff00c23d
parent 547bea03
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <compositionengine/LayerFE.h>
#include <compositionengine/OutputColorSetting.h>
#include <math/mat4.h>
#include <ui/Transform.h>

namespace android::compositionengine {

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

    // Used to correctly apply an inverse-display buffer transform if applicable
    ui::Transform::RotationFlags internalDisplayRotationFlags{ui::Transform::ROT_0};

    // If true, GPU clocks will be increased when rendering blurs
    bool blursAreExpensive{false};

+7 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <optional>
#include <string>

#include <ui/Transform.h>
#include <utils/StrongPointer.h>

// TODO(b/129481165): remove the #pragma below and fix conversion issues
@@ -77,7 +78,12 @@ public:

    // Recalculates the state of the output layer from the output-independent
    // layer. If includeGeometry is false, the geometry state can be skipped.
    virtual void updateCompositionState(bool includeGeometry, bool forceClientComposition) = 0;
    // internalDisplayRotationFlags must be set to the rotation flags for the
    // internal display, and is used to properly compute the inverse-display
    // transform, if needed.
    virtual void updateCompositionState(
            bool includeGeometry, bool forceClientComposition,
            ui::Transform::RotationFlags internalDisplayRotationFlags) = 0;

    // 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
+4 −2
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ public:

    void setHwcLayer(std::shared_ptr<HWC2::Layer>) override;

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

@@ -55,7 +56,8 @@ public:

    virtual FloatRect calculateOutputSourceCrop() const;
    virtual Rect calculateOutputDisplayFrame() const;
    virtual uint32_t calculateOutputRelativeBufferTransform() const;
    virtual uint32_t calculateOutputRelativeBufferTransform(
            uint32_t internalDisplayRotationFlags) const;

protected:
    // Implemented by the final implementation for the final state it uses.
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ public:
    MOCK_CONST_METHOD0(getState, const impl::OutputLayerCompositionState&());
    MOCK_METHOD0(editState, impl::OutputLayerCompositionState&());

    MOCK_METHOD2(updateCompositionState, void(bool, bool));
    MOCK_METHOD3(updateCompositionState, void(bool, bool, ui::Transform::RotationFlags));
    MOCK_METHOD1(writeStateToHWC, void(bool));
    MOCK_CONST_METHOD0(writeCursorPositionToHWC, void());

+2 −1
Original line number Diff line number Diff line
@@ -588,7 +588,8 @@ void Output::updateAndWriteCompositionState(
    for (auto* layer : getOutputLayersOrderedByZ()) {
        layer->updateCompositionState(refreshArgs.updatingGeometryThisFrame,
                                      refreshArgs.devOptForceClientComposition ||
                                              forceClientComposition);
                                              forceClientComposition,
                                      refreshArgs.internalDisplayRotationFlags);

        if (mLayerRequestingBackgroundBlur == layer) {
            forceClientComposition = false;
Loading