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

Commit 9db32ff2 authored by Melody Hsu's avatar Melody Hsu
Browse files

[legacy sf flag] - LayerRenderArea cleanup

LayerRenderArea no longer needs reparentForDrawing()
or flinger field after removing the legacy frontend.

Bug: b/330785038
Test: presubmit
Change-Id: I55828d7f342be55e1c4b7430d2a7cb4a251cad0c
parent 12ecd082
Loading
Loading
Loading
Loading
+5 −68
Original line number Diff line number Diff line
@@ -24,31 +24,17 @@
#include "SurfaceFlinger.h"

namespace android {
namespace {

void reparentForDrawing(const sp<Layer>& oldParent, const sp<Layer>& newParent,
                   const Rect& drawingBounds) {
        // Compute and cache the bounds for the new parent layer.
        newParent->computeBounds(drawingBounds.toFloatRect(), ui::Transform(),
            0.f /* shadowRadius */);
        newParent->updateSnapshot(true /* updateGeometry */);
        oldParent->setChildrenDrawingParent(newParent);
};

} // namespace

LayerRenderArea::LayerRenderArea(SurfaceFlinger& flinger, sp<Layer> layer, const Rect& crop,
                                 ui::Size reqSize, ui::Dataspace reqDataSpace, bool childrenOnly,
                                 bool allowSecureLayers, const ui::Transform& layerTransform,
                                 const Rect& layerBufferSize, bool hintForSeamlessTransition)
LayerRenderArea::LayerRenderArea(sp<Layer> layer, const Rect& crop, ui::Size reqSize,
                                 ui::Dataspace reqDataSpace, bool allowSecureLayers,
                                 const ui::Transform& layerTransform, const Rect& layerBufferSize,
                                 bool hintForSeamlessTransition)
      : RenderArea(reqSize, CaptureFill::CLEAR, reqDataSpace, hintForSeamlessTransition,
                   allowSecureLayers),
        mLayer(std::move(layer)),
        mLayerTransform(layerTransform),
        mLayerBufferSize(layerBufferSize),
        mCrop(crop),
        mFlinger(flinger),
        mChildrenOnly(childrenOnly) {}
        mTransform(layerTransform) {}

const ui::Transform& LayerRenderArea::getTransform() const {
    return mTransform;
@@ -71,53 +57,4 @@ Rect LayerRenderArea::getSourceCrop() const {
    }
}

void LayerRenderArea::render(std::function<void()> drawLayers) {
    using namespace std::string_literals;

    if (!mChildrenOnly) {
        mTransform = mLayerTransform.inverse();
    }

    if (mFlinger.mLayerLifecycleManagerEnabled) {
        drawLayers();
        return;
    }
    // If layer is offscreen, update mirroring info if it exists
    if (mLayer->isRemovedFromCurrentState()) {
        mLayer->traverse(LayerVector::StateSet::Drawing,
                         [&](Layer* layer) { layer->updateMirrorInfo({}); });
        mLayer->traverse(LayerVector::StateSet::Drawing,
                         [&](Layer* layer) { layer->updateCloneBufferInfo(); });
    }

    if (!mChildrenOnly) {
        // If the layer is offscreen, compute bounds since we don't compute bounds for offscreen
        // layers in a regular cycles.
        if (mLayer->isRemovedFromCurrentState()) {
            FloatRect maxBounds = mFlinger.getMaxDisplayBounds();
            mLayer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */);
        }
        drawLayers();
    } else {
        // In the "childrenOnly" case we reparent the children to a screenshot
        // layer which has no properties set and which does not draw.
        //  We hold the statelock as the reparent-for-drawing operation modifies the
        //  hierarchy and there could be readers on Binder threads, like dump.
        auto screenshotParentLayer = mFlinger.getFactory().createEffectLayer(
                {&mFlinger, nullptr, "Screenshot Parent"s, ISurfaceComposerClient::eNoColorFill,
                 LayerMetadata()});
        {
            Mutex::Autolock _l(mFlinger.mStateLock);
            reparentForDrawing(mLayer, screenshotParentLayer, getSourceCrop());
        }
        drawLayers();
        {
            Mutex::Autolock _l(mFlinger.mStateLock);
            mLayer->setChildrenDrawingParent(mLayer);
        }
    }
    mLayer->updateSnapshot(/*updateGeometry=*/true);
    mLayer->updateChildrenSnapshots(/*updateGeometry=*/true);
}

} // namespace android
+3 −9
Original line number Diff line number Diff line
@@ -32,29 +32,23 @@ class SurfaceFlinger;

class LayerRenderArea : public RenderArea {
public:
    LayerRenderArea(SurfaceFlinger& flinger, sp<Layer> layer, const Rect& crop, ui::Size reqSize,
                    ui::Dataspace reqDataSpace, bool childrenOnly, bool allowSecureLayers,
                    const ui::Transform& layerTransform, const Rect& layerBufferSize,
                    bool hintForSeamlessTransition);
    LayerRenderArea(sp<Layer> layer, const Rect& crop, ui::Size reqSize, ui::Dataspace reqDataSpace,
                    bool allowSecureLayers, const ui::Transform& layerTransform,
                    const Rect& layerBufferSize, bool hintForSeamlessTransition);

    const ui::Transform& getTransform() const override;
    bool isSecure() const override;
    sp<const DisplayDevice> getDisplayDevice() const override;
    Rect getSourceCrop() const override;

    void render(std::function<void()> drawLayers) override;
    virtual sp<Layer> getParentLayer() const { return mLayer; }

private:
    const sp<Layer> mLayer;
    const ui::Transform mLayerTransform;
    const Rect mLayerBufferSize;
    const Rect mCrop;

    ui::Transform mTransform;

    SurfaceFlinger& mFlinger;
    const bool mChildrenOnly;
};

} // namespace android
+0 −3
Original line number Diff line number Diff line
@@ -47,9 +47,6 @@ public:

    virtual ~RenderArea() = default;

    // Invoke drawLayers to render layers into the render area.
    virtual void render(std::function<void()> drawLayers) { drawLayers(); }

    // Returns true if the render area is secure.  A secure layer should be
    // blacked out / skipped when rendered to an insecure render area.
    virtual bool isSecure() const = 0;
+14 −21
Original line number Diff line number Diff line
@@ -8080,29 +8080,24 @@ void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args,
        return;
    }

    bool childrenOnly = args.childrenOnly;
    RenderAreaFuture renderAreaFuture = ftl::defer([=, this]() FTL_FAKE_GUARD(kMainThreadContext)
                                                           -> std::unique_ptr<RenderArea> {
        ui::Transform layerTransform;
        Rect layerBufferSize;
        if (mLayerLifecycleManagerEnabled) {
        frontend::LayerSnapshot* snapshot =
                mLayerSnapshotBuilder.getSnapshot(parent->getSequence());
        if (!snapshot) {
            ALOGW("Couldn't find layer snapshot for %d", parent->getSequence());
        } else {
                layerTransform = snapshot->localTransform;
                layerBufferSize = snapshot->bufferSize;
            if (!args.childrenOnly) {
                layerTransform = snapshot->localTransform.inverse();
            }
        } else {
            layerTransform = parent->getTransform();
            layerBufferSize = parent->getBufferSize(parent->getDrawingState());
            layerBufferSize = snapshot->bufferSize;
        }

        return std::make_unique<LayerRenderArea>(*this, parent, crop, reqSize, dataspace,
                                                 childrenOnly, args.captureSecureLayers,
                                                 layerTransform, layerBufferSize,
                                                 args.hintForSeamlessTransition);
        return std::make_unique<LayerRenderArea>(parent, crop, reqSize, dataspace,
                                                 args.captureSecureLayers, layerTransform,
                                                 layerBufferSize, args.hintForSeamlessTransition);
    });
    GetLayerSnapshotsFunction getLayerSnapshots;
    if (mLayerLifecycleManagerEnabled) {
@@ -8255,11 +8250,9 @@ ftl::SharedFuture<FenceResult> SurfaceFlinger::captureScreenshot(
            return ftl::yield<FenceResult>(base::unexpected(NO_ERROR)).share();
        }

        ftl::SharedFuture<FenceResult> renderFuture;
        renderArea->render([&]() FTL_FAKE_GUARD(kMainThreadContext) {
            renderFuture = renderScreenImpl(renderArea, buffer, regionSampling, grayscale,
                                            isProtected, captureResults, layers);
        });
        ftl::SharedFuture<FenceResult> renderFuture =
                renderScreenImpl(renderArea, buffer, regionSampling, grayscale, isProtected,
                                 captureResults, layers);

        if (captureListener) {
            // Defer blocking on renderFuture back to the Binder thread.