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

Commit 15eae09e authored by Robert Carr's avatar Robert Carr
Browse files

SurfaceFlinger: Fix reparenting following ReparentForDrawing

Counterintuitively, the new-parent doesn't have the children in
it's child list so even when cleaning up we need to call
reparentChildrenForDrawing on the old parent instead of the new parent.
Also clarify name to make this more obvious and add test.

Test: Transaction_test.cpp
Bug: 76099859
Change-Id: I935eec303dba320b5a2731606ec862311c5ca43e
parent 14c461a4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1594,7 +1594,7 @@ bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) {
    return true;
}

void Layer::reparentChildrenForDrawing(const sp<Layer>& newParent) {
void Layer::setChildrenDrawingParent(const sp<Layer>& newParent) {
    for (const sp<Layer>& child : mDrawingChildren) {
        child->mDrawingParent = newParent;
    }
+1 −1
Original line number Diff line number Diff line
@@ -287,7 +287,7 @@ public:
    bool setOverrideScalingMode(int32_t overrideScalingMode);
    void setInfo(uint32_t type, uint32_t appId);
    bool reparentChildren(const sp<IBinder>& layer);
    void reparentChildrenForDrawing(const sp<Layer>& layer);
    void setChildrenDrawingParent(const sp<Layer>& layer);
    bool reparent(const sp<IBinder>& newParentHandle);
    bool detachChildren();

+2 −2
Original line number Diff line number Diff line
@@ -4460,9 +4460,9 @@ status_t SurfaceFlinger::captureLayers(const sp<IBinder>& layerHandleBinder,

            ReparentForDrawing(const sp<Layer>& oldParent, const sp<Layer>& newParent)
                  : oldParent(oldParent), newParent(newParent) {
                oldParent->reparentChildrenForDrawing(newParent);
                oldParent->setChildrenDrawingParent(newParent);
            }
            ~ReparentForDrawing() { newParent->reparentChildrenForDrawing(oldParent); }
            ~ReparentForDrawing() { oldParent->setChildrenDrawingParent(oldParent); }
        };

        void render(std::function<void()> drawLayers) override {
+11 −0
Original line number Diff line number Diff line
@@ -2384,6 +2384,17 @@ TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresTransform) {
    verify();
}

TEST_F(ScreenCaptureChildOnlyTest, RegressionTest76099859) {
    SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true);

    // Even though the parent is hidden we should still capture the child.
    verify();

    // Verify everything was properly hidden when rendering the full-screen.
    screenshot()->expectBGColor(0,0);
}


TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) {
    auto fgHandle = mFGSurfaceControl->getHandle();