diff options
author | 2021-05-18 00:42:56 -0400 | |
---|---|---|
committer | 2021-06-22 12:59:35 -0400 | |
commit | f0f13e8565bbac178e631a81a173c6533728c6a1 (patch) | |
tree | 06977717caab22a68b9d2e7f30a6b3e7bf55e6b0 /libs/gui/Surface.cpp | |
parent | 1b48b713a208d35308b6f990334444fd9b7febe0 (diff) |
Add a better getLastQueuedBuffer
Avoid obfuscation via a matrix that's not necessarily useful or in
the desired origin of the caller. Instead return the source data,
which is also a lot smaller than the matrix is...
Bug: 183553027
Test: atest android.view.cts.PixelCopyTest (+new testBufferQueueCrop)
Change-Id: I1f7b5981405b2f20293bce9119414fc7780b8eb6
Merged-In: I1f7b5981405b2f20293bce9119414fc7780b8eb6
Diffstat (limited to 'libs/gui/Surface.cpp')
-rw-r--r-- | libs/gui/Surface.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index d6f9e635f3..8a64a4f0f7 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1207,6 +1207,9 @@ int Surface::perform(int operation, va_list args) case NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER: res = dispatchGetLastQueuedBuffer(args); break; + case NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER2: + res = dispatchGetLastQueuedBuffer2(args); + break; default: res = NAME_NOT_FOUND; break; @@ -1513,6 +1516,39 @@ int Surface::dispatchGetLastQueuedBuffer(va_list args) { return result; } +int Surface::dispatchGetLastQueuedBuffer2(va_list args) { + AHardwareBuffer** buffer = va_arg(args, AHardwareBuffer**); + int* fence = va_arg(args, int*); + ARect* crop = va_arg(args, ARect*); + uint32_t* transform = va_arg(args, uint32_t*); + sp<GraphicBuffer> graphicBuffer; + sp<Fence> spFence; + + Rect r; + int result = + mGraphicBufferProducer->getLastQueuedBuffer(&graphicBuffer, &spFence, &r, transform); + + if (graphicBuffer != nullptr) { + *buffer = graphicBuffer->toAHardwareBuffer(); + AHardwareBuffer_acquire(*buffer); + + // Avoid setting crop* unless buffer is valid (matches IGBP behavior) + crop->left = r.left; + crop->top = r.top; + crop->right = r.right; + crop->bottom = r.bottom; + } else { + *buffer = nullptr; + } + + if (spFence != nullptr) { + *fence = spFence->dup(); + } else { + *fence = -1; + } + return result; +} + bool Surface::transformToDisplayInverse() { return (mTransform & NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY) == NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY; |