diff options
author | 2019-03-15 14:58:34 -0700 | |
---|---|---|
committer | 2019-03-22 14:13:10 -0700 | |
commit | 78b7220f542826771223f9b5c0b876874dd398d2 (patch) | |
tree | ad06c575e7f760c4d4b79448cd69026d8cffe6e8 /libs/ui/GraphicBuffer.cpp | |
parent | 4c6f904ffde2795886477f6de54edcae5d036e68 (diff) |
blast: drop buffer from SF's cache when destroyed
When an app drops its reference to an AHardwareBuffer, the buffer
should be removed from the client and SurfaceFlinger caches.
Ideally, both caches would have wp to the buffer and the buffer
would automatically be removed from the cache.
Unfortunately, GraphicBuffers are refcounted per process. If SurfaceFlinger
just has a wp to the GraphicBuffer, the buffer's destructor will
be called and SurfaceFlinger will lose access to the buffer.
SurfaceFlinger can't just hold onto a sp to the buffer because
then the buffer wouldn't be destoryed when the app drops its reference.
Instead, when the app process drops its last strong reference,
GraphicBuffer will send a callback to the client side cache.
The cache will send a Transaction to SurfaceFlinger to drop its sp
to the buffer.
Bug: 127689853
Test: SurfaceFlinger_test
Change-Id: I2182578ed33d7c731945cb88cd1decb2892266b0
Diffstat (limited to 'libs/ui/GraphicBuffer.cpp')
-rw-r--r-- | libs/ui/GraphicBuffer.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp index f800627ef7..637a9cf725 100644 --- a/libs/ui/GraphicBuffer.cpp +++ b/libs/ui/GraphicBuffer.cpp @@ -133,6 +133,9 @@ GraphicBuffer::~GraphicBuffer() if (handle) { free_handle(); } + for (auto& [callback, context] : mDeathCallbacks) { + callback(context, mId); + } } void GraphicBuffer::free_handle() @@ -534,6 +537,10 @@ status_t GraphicBuffer::unflatten( return NO_ERROR; } +void GraphicBuffer::addDeathCallback(GraphicBufferDeathCallback deathCallback, void* context) { + mDeathCallbacks.emplace_back(deathCallback, context); +} + #ifndef LIBUI_IN_VNDK bool GraphicBuffer::isBufferHubBuffer() const { return mBufferHubBuffer != nullptr; |