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

Commit d57b9698 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "[sf] Add support for transform hint in new front end" into udc-dev am: 978c2978

parents 4c84a23d 978c2978
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -89,6 +89,7 @@ struct LayerSnapshot : public compositionengine::LayerFECompositionState {
    gui::GameMode gameMode;
    gui::GameMode gameMode;
    scheduler::LayerInfo::FrameRate frameRate;
    scheduler::LayerInfo::FrameRate frameRate;
    ui::Transform::RotationFlags fixedTransformHint;
    ui::Transform::RotationFlags fixedTransformHint;
    std::optional<ui::Transform::RotationFlags> transformHint;
    bool handleSkipScreenshotFlag = false;
    bool handleSkipScreenshotFlag = false;
    int32_t frameRateSelectionPriority;
    int32_t frameRateSelectionPriority;
    LayerHierarchy::TraversalPath mirrorRootPath;
    LayerHierarchy::TraversalPath mirrorRootPath;
+37 −18
Original line number Original line Diff line number Diff line
@@ -22,10 +22,15 @@
#include "LayerSnapshotBuilder.h"
#include "LayerSnapshotBuilder.h"
#include <gui/TraceUtils.h>
#include <gui/TraceUtils.h>
#include <ui/FloatRect.h>
#include <ui/FloatRect.h>

#include <numeric>
#include <numeric>
#include <optional>

#include <gui/TraceUtils.h>
#include "DisplayHardware/HWC2.h"
#include "DisplayHardware/HWC2.h"
#include "DisplayHardware/Hal.h"
#include "DisplayHardware/Hal.h"
#include "LayerLog.h"
#include "LayerLog.h"
#include "LayerSnapshotBuilder.h"
#include "TimeStats/TimeStats.h"
#include "TimeStats/TimeStats.h"
#include "ftl/small_map.h"
#include "ftl/small_map.h"


@@ -649,12 +654,14 @@ void LayerSnapshotBuilder::resetRelativeState(LayerSnapshot& snapshot) {
    snapshot.relativeLayerMetadata.mMap.clear();
    snapshot.relativeLayerMetadata.mMap.clear();
}
}


uint32_t getDisplayRotationFlags(
uint32_t getPrimaryDisplayRotationFlags(
        const display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& displays,
        const display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& displays) {
        const ui::LayerStack& layerStack) {
    for (auto& [_, display] : displays) {
    static frontend::DisplayInfo sDefaultDisplayInfo = {.isPrimary = false};
        if (display.isPrimary) {
    auto display = displays.get(layerStack).value_or(sDefaultDisplayInfo).get();
            return display.rotationFlags;
    return display.isPrimary ? display.rotationFlags : 0;
        }
    }
    return 0;
}
}


void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& args,
void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& args,
@@ -681,8 +688,7 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a
            ? requested.layerStack
            ? requested.layerStack
            : parentSnapshot.outputFilter.layerStack;
            : parentSnapshot.outputFilter.layerStack;


    uint32_t displayRotationFlags =
    uint32_t primaryDisplayRotationFlags = getPrimaryDisplayRotationFlags(args.displays);
            getDisplayRotationFlags(args.displays, snapshot.outputFilter.layerStack);
    const bool forceUpdate = args.forceUpdate == ForceUpdateFlags::ALL ||
    const bool forceUpdate = args.forceUpdate == ForceUpdateFlags::ALL ||
            snapshot.changes.any(RequestedLayerState::Changes::Visibility |
            snapshot.changes.any(RequestedLayerState::Changes::Visibility |
                                 RequestedLayerState::Changes::Created);
                                 RequestedLayerState::Changes::Created);
@@ -696,7 +702,7 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a
                : Fence::NO_FENCE;
                : Fence::NO_FENCE;
        snapshot.buffer =
        snapshot.buffer =
                requested.externalTexture ? requested.externalTexture->getBuffer() : nullptr;
                requested.externalTexture ? requested.externalTexture->getBuffer() : nullptr;
        snapshot.bufferSize = requested.getBufferSize(displayRotationFlags);
        snapshot.bufferSize = requested.getBufferSize(primaryDisplayRotationFlags);
        snapshot.geomBufferSize = snapshot.bufferSize;
        snapshot.geomBufferSize = snapshot.bufferSize;
        snapshot.croppedBufferSize = requested.getCroppedBufferSize(snapshot.bufferSize);
        snapshot.croppedBufferSize = requested.getCroppedBufferSize(snapshot.bufferSize);
        snapshot.dataspace = requested.dataspace;
        snapshot.dataspace = requested.dataspace;
@@ -751,15 +757,28 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a
        snapshot.gameMode = requested.metadata.has(gui::METADATA_GAME_MODE)
        snapshot.gameMode = requested.metadata.has(gui::METADATA_GAME_MODE)
                ? requested.gameMode
                ? requested.gameMode
                : parentSnapshot.gameMode;
                : parentSnapshot.gameMode;
        snapshot.fixedTransformHint = requested.fixedTransformHint != ui::Transform::ROT_INVALID
                ? requested.fixedTransformHint
                : parentSnapshot.fixedTransformHint;
        // Display mirrors are always placed in a VirtualDisplay so we never want to capture layers
        // Display mirrors are always placed in a VirtualDisplay so we never want to capture layers
        // marked as skip capture
        // marked as skip capture
        snapshot.handleSkipScreenshotFlag = parentSnapshot.handleSkipScreenshotFlag ||
        snapshot.handleSkipScreenshotFlag = parentSnapshot.handleSkipScreenshotFlag ||
                (requested.layerStackToMirror != ui::INVALID_LAYER_STACK);
                (requested.layerStackToMirror != ui::INVALID_LAYER_STACK);
    }
    }


    if (forceUpdate || snapshot.changes.any(RequestedLayerState::Changes::AffectsChildren) ||
        args.displayChanges) {
        snapshot.fixedTransformHint = requested.fixedTransformHint != ui::Transform::ROT_INVALID
                ? requested.fixedTransformHint
                : parentSnapshot.fixedTransformHint;

        if (snapshot.fixedTransformHint != ui::Transform::ROT_INVALID) {
            snapshot.transformHint = snapshot.fixedTransformHint;
        } else {
            const auto display = args.displays.get(snapshot.outputFilter.layerStack);
            snapshot.transformHint = display.has_value()
                    ? std::make_optional<>(display->get().transformHint)
                    : std::nullopt;
        }
    }

    if (forceUpdate ||
    if (forceUpdate ||
        snapshot.changes.any(RequestedLayerState::Changes::FrameRate |
        snapshot.changes.any(RequestedLayerState::Changes::FrameRate |
                             RequestedLayerState::Changes::Hierarchy)) {
                             RequestedLayerState::Changes::Hierarchy)) {
@@ -799,7 +818,7 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a
    if (forceUpdate ||
    if (forceUpdate ||
        snapshot.changes.any(RequestedLayerState::Changes::Hierarchy |
        snapshot.changes.any(RequestedLayerState::Changes::Hierarchy |
                             RequestedLayerState::Changes::Geometry)) {
                             RequestedLayerState::Changes::Geometry)) {
        updateLayerBounds(snapshot, requested, parentSnapshot, displayRotationFlags);
        updateLayerBounds(snapshot, requested, parentSnapshot, primaryDisplayRotationFlags);
        updateRoundedCorner(snapshot, requested, parentSnapshot);
        updateRoundedCorner(snapshot, requested, parentSnapshot);
    }
    }


@@ -870,10 +889,10 @@ void LayerSnapshotBuilder::updateRoundedCorner(LayerSnapshot& snapshot,
void LayerSnapshotBuilder::updateLayerBounds(LayerSnapshot& snapshot,
void LayerSnapshotBuilder::updateLayerBounds(LayerSnapshot& snapshot,
                                             const RequestedLayerState& requested,
                                             const RequestedLayerState& requested,
                                             const LayerSnapshot& parentSnapshot,
                                             const LayerSnapshot& parentSnapshot,
                                             uint32_t displayRotationFlags) {
                                             uint32_t primaryDisplayRotationFlags) {
    snapshot.croppedBufferSize = requested.getCroppedBufferSize(snapshot.bufferSize);
    snapshot.croppedBufferSize = requested.getCroppedBufferSize(snapshot.bufferSize);
    snapshot.geomCrop = requested.crop;
    snapshot.geomCrop = requested.crop;
    snapshot.localTransform = requested.getTransform(displayRotationFlags);
    snapshot.localTransform = requested.getTransform(primaryDisplayRotationFlags);
    snapshot.localTransformInverse = snapshot.localTransform.inverse();
    snapshot.localTransformInverse = snapshot.localTransform.inverse();
    snapshot.geomLayerTransform = parentSnapshot.geomLayerTransform * snapshot.localTransform;
    snapshot.geomLayerTransform = parentSnapshot.geomLayerTransform * snapshot.localTransform;
    const bool transformWasInvalid = snapshot.invalidTransform;
    const bool transformWasInvalid = snapshot.invalidTransform;
@@ -887,14 +906,14 @@ void LayerSnapshotBuilder::updateLayerBounds(LayerSnapshot& snapshot,
                                   requestedT.dsdy(), requestedT.dtdx(), requestedT.dtdy());
                                   requestedT.dsdy(), requestedT.dtdx(), requestedT.dtdy());
        std::string bufferDebug;
        std::string bufferDebug;
        if (requested.externalTexture) {
        if (requested.externalTexture) {
            auto unRotBuffer = requested.getUnrotatedBufferSize(displayRotationFlags);
            auto unRotBuffer = requested.getUnrotatedBufferSize(primaryDisplayRotationFlags);
            auto& destFrame = requested.destinationFrame;
            auto& destFrame = requested.destinationFrame;
            bufferDebug = base::StringPrintf(" buffer={%d,%d}  displayRot=%d"
            bufferDebug = base::StringPrintf(" buffer={%d,%d}  displayRot=%d"
                                             " destFrame={%d,%d,%d,%d} unRotBuffer={%d,%d}",
                                             " destFrame={%d,%d,%d,%d} unRotBuffer={%d,%d}",
                                             requested.externalTexture->getWidth(),
                                             requested.externalTexture->getWidth(),
                                             requested.externalTexture->getHeight(),
                                             requested.externalTexture->getHeight(),
                                             displayRotationFlags, destFrame.left, destFrame.top,
                                             primaryDisplayRotationFlags, destFrame.left,
                                             destFrame.right, destFrame.bottom,
                                             destFrame.top, destFrame.right, destFrame.bottom,
                                             unRotBuffer.getHeight(), unRotBuffer.getWidth());
                                             unRotBuffer.getHeight(), unRotBuffer.getWidth());
        }
        }
        ALOGW("Resetting transform for %s because it is invalid.%s%s",
        ALOGW("Resetting transform for %s because it is invalid.%s%s",
+12 −8
Original line number Original line Diff line number Diff line
@@ -1505,7 +1505,7 @@ void Layer::updateTransformHint(ui::Transform::RotationFlags transformHint) {
        transformHint = ui::Transform::ROT_0;
        transformHint = ui::Transform::ROT_0;
    }
    }


    setTransformHint(transformHint);
    setTransformHintLegacy(transformHint);
}
}


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -2865,9 +2865,13 @@ void Layer::onSurfaceFrameCreated(


void Layer::releasePendingBuffer(nsecs_t dequeueReadyTime) {
void Layer::releasePendingBuffer(nsecs_t dequeueReadyTime) {
    for (const auto& handle : mDrawingState.callbackHandles) {
    for (const auto& handle : mDrawingState.callbackHandles) {
        if (mFlinger->mLayerLifecycleManagerEnabled) {
            handle->transformHint = mTransformHint;
        } else {
            handle->transformHint = mSkipReportingTransformHint
            handle->transformHint = mSkipReportingTransformHint
                    ? std::nullopt
                    ? std::nullopt
                : std::make_optional<uint32_t>(mTransformHint);
                    : std::make_optional<uint32_t>(mTransformHintLegacy);
        }
        handle->dequeueReadyTime = dequeueReadyTime;
        handle->dequeueReadyTime = dequeueReadyTime;
        handle->currentMaxAcquiredBufferCount =
        handle->currentMaxAcquiredBufferCount =
                mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mOwnerUid);
                mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mOwnerUid);
@@ -4027,10 +4031,10 @@ sp<GraphicBuffer> Layer::getBuffer() const {
    return mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer() : nullptr;
    return mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer() : nullptr;
}
}


void Layer::setTransformHint(ui::Transform::RotationFlags displayTransformHint) {
void Layer::setTransformHintLegacy(ui::Transform::RotationFlags displayTransformHint) {
    mTransformHint = getFixedTransformHint();
    mTransformHintLegacy = getFixedTransformHint();
    if (mTransformHint == ui::Transform::ROT_INVALID) {
    if (mTransformHintLegacy == ui::Transform::ROT_INVALID) {
        mTransformHint = displayTransformHint;
        mTransformHintLegacy = displayTransformHint;
    }
    }
    mSkipReportingTransformHint = false;
    mSkipReportingTransformHint = false;
}
}
+6 −4
Original line number Original line Diff line number Diff line
@@ -455,8 +455,6 @@ public:
    sp<GraphicBuffer> getBuffer() const;
    sp<GraphicBuffer> getBuffer() const;
    const std::shared_ptr<renderengine::ExternalTexture>& getExternalTexture() const;
    const std::shared_ptr<renderengine::ExternalTexture>& getExternalTexture() const;


    ui::Transform::RotationFlags getTransformHint() const { return mTransformHint; }

    /*
    /*
     * Returns if a frame is ready
     * Returns if a frame is ready
     */
     */
@@ -878,6 +876,9 @@ public:
        };
        };
    };
    };
    bool hasBuffer() const { return mBufferInfo.mBuffer != nullptr; }
    bool hasBuffer() const { return mBufferInfo.mBuffer != nullptr; }
    void setTransformHint(std::optional<ui::Transform::RotationFlags> transformHint) {
        mTransformHint = transformHint;
    }


protected:
protected:
    // For unit tests
    // For unit tests
@@ -1154,14 +1155,15 @@ private:
    float mBorderWidth;
    float mBorderWidth;
    half4 mBorderColor;
    half4 mBorderColor;


    void setTransformHint(ui::Transform::RotationFlags);
    void setTransformHintLegacy(ui::Transform::RotationFlags);


    const uint32_t mTextureName;
    const uint32_t mTextureName;


    // Transform hint provided to the producer. This must be accessed holding
    // Transform hint provided to the producer. This must be accessed holding
    // the mStateLock.
    // the mStateLock.
    ui::Transform::RotationFlags mTransformHint = ui::Transform::ROT_0;
    ui::Transform::RotationFlags mTransformHintLegacy = ui::Transform::ROT_0;
    bool mSkipReportingTransformHint = true;
    bool mSkipReportingTransformHint = true;
    std::optional<ui::Transform::RotationFlags> mTransformHint = std::nullopt;


    ReleaseCallbackId mPreviousReleaseCallbackId = ReleaseCallbackId::INVALID_ID;
    ReleaseCallbackId mPreviousReleaseCallbackId = ReleaseCallbackId::INVALID_ID;
    uint64_t mPreviousReleasedFrameNumber = 0;
    uint64_t mPreviousReleasedFrameNumber = 0;
+6 −0
Original line number Original line Diff line number Diff line
@@ -5137,6 +5137,12 @@ uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& f
        if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded;
        if (layer->setSidebandStream(s.sidebandStream)) flags |= eTraversalNeeded;
    }
    }
    if (what & layer_state_t::eBufferChanged) {
    if (what & layer_state_t::eBufferChanged) {
        std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt;
        frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence);
        if (snapshot) {
            transformHint = snapshot->transformHint;
        }
        layer->setTransformHint(transformHint);
        if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime,
        if (layer->setBuffer(composerState.externalTexture, *s.bufferData, postTime,
                             desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp,
                             desiredPresentTime, isAutoTimestamp, dequeueBufferTimestamp,
                             frameTimelineInfo)) {
                             frameTimelineInfo)) {