From 8724653a77f855b7e062541d6e08f3ea659cef7c Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Mon, 4 Feb 2019 15:20:26 -0800 Subject: SurfaceControl life-cycle refactoring. We provide a method called "release" which allows the client to drop its references without reparenting the SurfaceControl to null as the destructor would. The Java and NDK API's already have this method but it's not perfectly functional at the moment. Additionally we remove the strange pass-through of clear to destroy and expose destroy directly. Test: Builds Bug: 123587983 Change-Id: Ia89ada1476daef97e6f30d50a57065c3636a6489 --- libs/gui/SurfaceControl.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'libs/gui/SurfaceControl.cpp') diff --git a/libs/gui/SurfaceControl.cpp b/libs/gui/SurfaceControl.cpp index 008f520bb0..d2b0e6a220 100644 --- a/libs/gui/SurfaceControl.cpp +++ b/libs/gui/SurfaceControl.cpp @@ -66,10 +66,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() && mOwned) { 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( -- cgit v1.2.3-59-g8ed1b