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

Commit 78bc24dc authored by Vishnu Nair's avatar Vishnu Nair Committed by Android (Google) Code Review
Browse files

Merge "Revert "SF: Introduce new frontend logic""

parents cd5987fc acb18f43
Loading
Loading
Loading
Loading
+2 −19
Original line number Diff line number Diff line
@@ -391,9 +391,7 @@ bool LayerSnapshotBuilder::tryFastUpdate(const Args& args) {

void LayerSnapshotBuilder::updateSnapshots(const Args& args) {
    ATRACE_NAME("UpdateSnapshots");
    if (args.parentCrop) {
        mRootSnapshot.geomLayerBounds = *args.parentCrop;
    } else if (args.forceUpdate || args.displayChanges) {
    if (args.forceUpdate || args.displayChanges) {
        mRootSnapshot.geomLayerBounds = getMaxDisplayBounds(args.displays);
    }
    if (args.displayChanges) {
@@ -620,8 +618,7 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a
             RequestedLayerState::Changes::AffectsChildren);
    snapshot.changes = parentChanges | requested.changes;
    snapshot.isHiddenByPolicyFromParent = parentSnapshot.isHiddenByPolicyFromParent ||
            parentSnapshot.invalidTransform || requested.isHiddenByPolicy() ||
            (args.excludeLayerIds.find(path.id) != args.excludeLayerIds.end());
            parentSnapshot.invalidTransform || requested.isHiddenByPolicy();
    snapshot.contentDirty = requested.what & layer_state_t::CONTENT_DIRTY;
    // TODO(b/238781169) scope down the changes to only buffer updates.
    snapshot.hasReadyFrame =
@@ -986,20 +983,6 @@ void LayerSnapshotBuilder::forEachVisibleSnapshot(const ConstVisitor& visitor) c
    }
}

// Visit each visible snapshot in z-order
void LayerSnapshotBuilder::forEachVisibleSnapshot(const ConstVisitor& visitor,
                                                  const LayerHierarchy& root) const {
    root.traverseInZOrder(
            [this, visitor](const LayerHierarchy&,
                            const LayerHierarchy::TraversalPath& traversalPath) -> bool {
                LayerSnapshot* snapshot = getSnapshot(traversalPath);
                if (snapshot && snapshot->isVisible) {
                    visitor(*snapshot);
                }
                return true;
            });
}

void LayerSnapshotBuilder::forEachVisibleSnapshot(const Visitor& visitor) {
    for (int i = 0; i < mNumInterestingSnapshots; i++) {
        std::unique_ptr<LayerSnapshot>& snapshot = mSnapshots.at((size_t)i);
+1 −6
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ namespace android::surfaceflinger::frontend {
class LayerSnapshotBuilder {
public:
    struct Args {
        LayerHierarchy root;
        const LayerHierarchy& root;
        const LayerLifecycleManager& layerLifecycleManager;
        bool forceUpdate = false;
        bool includeMetadata = false;
@@ -46,8 +46,6 @@ public:
        const renderengine::ShadowSettings& globalShadowSettings;
        bool supportsBlur = true;
        bool forceFullDamage = false;
        std::optional<FloatRect> parentCrop = std::nullopt;
        std::unordered_set<uint32_t> excludeLayerIds;
    };
    LayerSnapshotBuilder();

@@ -67,9 +65,6 @@ public:
    // Visit each visible snapshot in z-order
    void forEachVisibleSnapshot(const ConstVisitor& visitor) const;

    // Visit each visible snapshot in z-order
    void forEachVisibleSnapshot(const ConstVisitor& visitor, const LayerHierarchy& root) const;

    typedef std::function<void(std::unique_ptr<LayerSnapshot>& snapshot)> Visitor;
    // Visit each visible snapshot in z-order and move the snapshot if needed
    void forEachVisibleSnapshot(const Visitor& visitor);
+30 −26
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ Layer::Layer(const LayerCreationArgs& args)
        mLayerCreationFlags(args.flags),
        mBorderEnabled(false),
        mTextureName(args.textureName),
        mLegacyLayerFE(args.flinger->getFactory().createLayerFE(mName)) {
        mLayerFE(args.flinger->getFactory().createLayerFE(mName)) {
    ALOGV("Creating Layer %s", getDebugName());

    uint32_t layerFlags = 0;
@@ -3123,14 +3123,15 @@ bool Layer::setSidebandStream(const sp<NativeHandle>& sidebandStream) {
    return true;
}

bool Layer::setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& handles,
                                             bool willPresent) {
bool Layer::setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& handles) {
    // If there is no handle, we will not send a callback so reset mReleasePreviousBuffer and return
    if (handles.empty()) {
        mReleasePreviousBuffer = false;
        return false;
    }

    const bool willPresent = willPresentCurrentTransaction();

    std::deque<sp<CallbackHandle>> remainingHandles;
    for (const auto& handle : handles) {
        // If this transaction set a buffer on this layer, release its previous buffer
@@ -3213,10 +3214,11 @@ bool Layer::fenceHasSignaled() const {
    return fenceSignaled;
}

void Layer::onPreComposition(nsecs_t refreshStartTime) {
bool Layer::onPreComposition(nsecs_t refreshStartTime) {
    for (const auto& handle : mDrawingState.callbackHandles) {
        handle->refreshStartTime = refreshStartTime;
    }
    return hasReadyFrame();
}

void Layer::setAutoRefresh(bool autoRefresh) {
@@ -3602,7 +3604,7 @@ bool Layer::isHdrY410() const {

sp<LayerFE> Layer::getCompositionEngineLayerFE() const {
    // There's no need to get a CE Layer if the layer isn't going to draw anything.
    return hasSomethingToDraw() ? mLegacyLayerFE : nullptr;
    return hasSomethingToDraw() ? mLayerFE : nullptr;
}

const LayerSnapshot* Layer::getLayerSnapshot() const {
@@ -3613,36 +3615,16 @@ LayerSnapshot* Layer::editLayerSnapshot() {
    return mSnapshot.get();
}

std::unique_ptr<frontend::LayerSnapshot> Layer::stealLayerSnapshot() {
    return std::move(mSnapshot);
}

void Layer::updateLayerSnapshot(std::unique_ptr<frontend::LayerSnapshot> snapshot) {
    mSnapshot = std::move(snapshot);
}

const compositionengine::LayerFECompositionState* Layer::getCompositionState() const {
    return mSnapshot.get();
}

sp<LayerFE> Layer::copyCompositionEngineLayerFE() const {
    auto result = mFlinger->getFactory().createLayerFE(mName);
    auto result = mFlinger->getFactory().createLayerFE(mLayerFE->getDebugName());
    result->mSnapshot = std::make_unique<LayerSnapshot>(*mSnapshot);
    return result;
}

sp<LayerFE> Layer::getCompositionEngineLayerFE(
        const frontend::LayerHierarchy::TraversalPath& path) {
    for (auto& [p, layerFE] : mLayerFEs) {
        if (p == path) {
            return layerFE;
        }
    }
    auto layerFE = mFlinger->getFactory().createLayerFE(mName);
    mLayerFEs.emplace_back(path, layerFE);
    return layerFE;
}

void Layer::useSurfaceDamage() {
    if (mFlinger->mForceFullDamage) {
        surfaceDamageRegion = Region::INVALID_REGION;
@@ -4038,6 +4020,28 @@ void Layer::updateRelativeMetadataSnapshot(const LayerMetadata& relativeLayerMet
    }
}

LayerSnapshotGuard::LayerSnapshotGuard(Layer* layer) : mLayer(layer) {
    if (mLayer) {
        mLayer->mLayerFE->mSnapshot = std::move(mLayer->mSnapshot);
    }
}

LayerSnapshotGuard::~LayerSnapshotGuard() {
    if (mLayer) {
        mLayer->mSnapshot = std::move(mLayer->mLayerFE->mSnapshot);
    }
}

LayerSnapshotGuard::LayerSnapshotGuard(LayerSnapshotGuard&& other) : mLayer(other.mLayer) {
    other.mLayer = nullptr;
}

LayerSnapshotGuard& LayerSnapshotGuard::operator=(LayerSnapshotGuard&& other) {
    mLayer = other.mLayer;
    other.mLayer = nullptr;
    return *this;
}

void Layer::setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds,
                                       TrustedPresentationListener const& listener) {
    bool hadTrustedPresentationListener = hasTrustedPresentationListener();
+30 −9
Original line number Diff line number Diff line
@@ -307,8 +307,7 @@ public:
    bool setSurfaceDamageRegion(const Region& /*surfaceDamage*/);
    bool setApi(int32_t /*api*/);
    bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/);
    bool setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& /*handles*/,
                                          bool willPresent);
    bool setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& /*handles*/);
    virtual bool setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace);
    virtual bool setColorSpaceAgnostic(const bool agnostic);
    virtual bool setDimmingEnabled(const bool dimmingEnabled);
@@ -329,12 +328,9 @@ public:

    virtual sp<LayerFE> getCompositionEngineLayerFE() const;
    virtual sp<LayerFE> copyCompositionEngineLayerFE() const;
    sp<LayerFE> getCompositionEngineLayerFE(const frontend::LayerHierarchy::TraversalPath&);

    const frontend::LayerSnapshot* getLayerSnapshot() const;
    frontend::LayerSnapshot* editLayerSnapshot();
    std::unique_ptr<frontend::LayerSnapshot> stealLayerSnapshot();
    void updateLayerSnapshot(std::unique_ptr<frontend::LayerSnapshot> snapshot);

    // If we have received a new buffer this frame, we will pass its surface
    // damage down to hardware composer. Otherwise, we must send a region with
@@ -516,7 +512,7 @@ public:
    // implements compositionengine::LayerFE
    const compositionengine::LayerFECompositionState* getCompositionState() const;
    bool fenceHasSignaled() const;
    void onPreComposition(nsecs_t refreshStartTime);
    bool onPreComposition(nsecs_t refreshStartTime);
    void onLayerDisplayed(ftl::SharedFuture<FenceResult>);

    void setWasClientComposed(const sp<Fence>& fence) {
@@ -836,7 +832,6 @@ public:
    void updateMetadataSnapshot(const LayerMetadata& parentMetadata);
    void updateRelativeMetadataSnapshot(const LayerMetadata& relativeLayerMetadata,
                                        std::unordered_set<Layer*>& visited);
    bool willPresentCurrentTransaction() const;

protected:
    // For unit tests
@@ -1042,6 +1037,8 @@ private:
    // Crop that applies to the buffer
    Rect computeBufferCrop(const State& s);

    bool willPresentCurrentTransaction() const;

    void callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener,
                                   const sp<GraphicBuffer>& buffer, uint64_t framenumber,
                                   const sp<Fence>& releaseFence,
@@ -1154,10 +1151,34 @@ private:
    // not specify a destination frame.
    ui::Transform mRequestedTransform;

    sp<LayerFE> mLegacyLayerFE;
    std::vector<std::pair<frontend::LayerHierarchy::TraversalPath, sp<LayerFE>>> mLayerFEs;
    sp<LayerFE> mLayerFE;
    std::unique_ptr<frontend::LayerSnapshot> mSnapshot =
            std::make_unique<frontend::LayerSnapshot>();

    friend class LayerSnapshotGuard;
};

// LayerSnapshotGuard manages the movement of LayerSnapshot between a Layer and its corresponding
// LayerFE. This class must be used whenever LayerFEs are passed to CompositionEngine. Instances of
// LayerSnapshotGuard should only be constructed on the main thread and should not be moved outside
// the main thread.
//
// Moving the snapshot instead of sharing common state prevents use of LayerFE outside the main
// thread by making errors obvious (i.e. use outside the main thread results in SEGFAULTs due to
// nullptr dereference).
class LayerSnapshotGuard {
public:
    LayerSnapshotGuard(Layer* layer) REQUIRES(kMainThreadContext);
    ~LayerSnapshotGuard() REQUIRES(kMainThreadContext);

    LayerSnapshotGuard(const LayerSnapshotGuard&) = delete;
    LayerSnapshotGuard& operator=(const LayerSnapshotGuard&) = delete;

    LayerSnapshotGuard(LayerSnapshotGuard&& other) REQUIRES(kMainThreadContext);
    LayerSnapshotGuard& operator=(LayerSnapshotGuard&& other) REQUIRES(kMainThreadContext);

private:
    Layer* mLayer;
};

std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate);
+1 −8
Original line number Diff line number Diff line
@@ -69,14 +69,6 @@ Rect LayerRenderArea::getSourceCrop() const {
void LayerRenderArea::render(std::function<void()> drawLayers) {
    using namespace std::string_literals;

    if (!mChildrenOnly) {
        mTransform = mLayer->getTransform().inverse();
    }

    if (mFlinger.mLayerLifecycleManagerEnabled) {
        drawLayers();
        return;
    }
    // If layer is offscreen, update mirroring info if it exists
    if (mLayer->isRemovedFromCurrentState()) {
        mLayer->traverse(LayerVector::StateSet::Drawing,
@@ -86,6 +78,7 @@ void LayerRenderArea::render(std::function<void()> drawLayers) {
    }

    if (!mChildrenOnly) {
        mTransform = mLayer->getTransform().inverse();
        // If the layer is offscreen, compute bounds since we don't compute bounds for offscreen
        // layers in a regular cycles.
        if (mLayer->isRemovedFromCurrentState()) {
Loading