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

Commit c2fdc9a5 authored by Rob Carr's avatar Rob Carr Committed by Android (Google) Code Review
Browse files

Merge "SurfaceControl life-cycle refactoring."

parents b73e4954 8724653a
Loading
Loading
Loading
Loading
+7 −16
Original line number Diff line number Diff line
@@ -68,10 +68,7 @@ SurfaceControl::~SurfaceControl()
    if (mClient != nullptr && mHandle != nullptr && mOwned) {
        SurfaceComposerClient::doDropReferenceTransaction(mHandle, mClient->getClient());
    }
    mClient.clear();
    mHandle.clear();
    mGraphicBufferProducer.clear();
    IPCThreadState::self()->flushCommands();
    release();
}

void SurfaceControl::destroy()
@@ -79,7 +76,12 @@ void SurfaceControl::destroy()
    if (isValid()) {
        SurfaceComposerClient::Transaction().reparent(this, nullptr).apply();
    }
    // clear all references and trigger an IPC now, to make sure things
    release();
}

void SurfaceControl::release()
{
    // Trigger an IPC now, to make sure things
    // happen without delay, since these resources are quite heavy.
    mClient.clear();
    mHandle.clear();
@@ -87,17 +89,6 @@ void SurfaceControl::destroy()
    IPCThreadState::self()->flushCommands();
}

void SurfaceControl::clear()
{
    // here, the window manager tells us explicitly that we should destroy
    // the surface's resource. Soon after this call, it will also release
    // its last reference (which will call the dtor); however, it is possible
    // that a client living in the same process still holds references which
    // would delay the call to the dtor -- that is why we need this explicit
    // "clear()" call.
    destroy();
}

void SurfaceControl::disconnect() {
    if (mGraphicBufferProducer != nullptr) {
        mGraphicBufferProducer->disconnect(
+6 −3
Original line number Diff line number Diff line
@@ -58,8 +58,12 @@ public:
    static bool isSameSurface(
            const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);

    // release surface data from java
    void        clear();
    // Release the handles assosciated with the SurfaceControl, without reparenting
    // them off-screen. At the moment if this isn't executed before ~SurfaceControl
    // is called then the destructor will reparent the layer off-screen for you.
    void        release();
    // Reparent off-screen and release. This is invoked by the destructor.
    void destroy();

    // disconnect any api that's connected
    void        disconnect();
@@ -98,7 +102,6 @@ private:

    sp<Surface> generateSurfaceLocked() const;
    status_t validate() const;
    void destroy();

    sp<SurfaceComposerClient>   mClient;
    sp<IBinder>                 mHandle;
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ TEST(SurfaceFlingerStress, create_and_destroy) {
            auto surf = client->createSurface(String8("t"), 100, 100,
                    PIXEL_FORMAT_RGBA_8888, 0);
            ASSERT_TRUE(surf != nullptr);
            surf->clear();
            surf.clear();
        }
    };

+3 −3
Original line number Diff line number Diff line
@@ -1134,7 +1134,7 @@ TEST_P(LayerTypeAndRenderTypeTransactionTest, SetRelativeZBug64572777) {
            .setRelativeLayer(layerG, layerR->getHandle(), 1)
            .apply();

    layerG->clear();
    layerG.clear();
    // layerG should have been removed
    getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED);
}
@@ -4332,7 +4332,7 @@ TEST_F(ChildLayerTest, ChildrenSurviveParentDestruction) {
        mCapture->checkPixel(64, 64, 111, 111, 111);
    }

    mChild->clear();
    mChild.clear();

    {
        SCOPED_TRACE("After destroying child");
@@ -5204,7 +5204,7 @@ TEST_F(ScreenCaptureTest, CaptureInvalidLayer) {
    ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60));

    auto redLayerHandle = redLayer->getHandle();
    redLayer->clear();
    redLayer.clear();
    SurfaceComposerClient::Transaction().apply(true);

    sp<GraphicBuffer> outBuffer;