diff options
| author | 2019-12-17 09:39:07 -0800 | |
|---|---|---|
| committer | 2020-02-13 13:36:32 -0800 | |
| commit | ef0b153009c04608ac2316d247ab70009c338e9c (patch) | |
| tree | 2b185d216829fabaaf37fea6d686abbdf71c6fc8 | |
| parent | 612231d21e2c82f4730dad24dab35ebb22144cd2 (diff) | |
[ANativeWindow] Add getLastQueuedBuffer api
Bug: 137012798
Bug: 148962594
Test: builds
Change-Id: I3dcf6741c8d5dc62b7ae13d5cf5dc56173f95660
| -rw-r--r-- | libs/gui/Surface.cpp | 27 | ||||
| -rw-r--r-- | libs/gui/include/gui/Surface.h | 1 | ||||
| -rw-r--r-- | libs/nativewindow/include/system/window.h | 31 |
3 files changed, 59 insertions, 0 deletions
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 23532e7e38..278cc593b7 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1180,6 +1180,9 @@ int Surface::perform(int operation, va_list args) allocateBuffers(); res = NO_ERROR; break; + case NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER: + res = dispatchGetLastQueuedBuffer(args); + break; default: res = NAME_NOT_FOUND; break; @@ -1452,6 +1455,30 @@ int Surface::dispatchAddQueueInterceptor(va_list args) { return NO_ERROR; } +int Surface::dispatchGetLastQueuedBuffer(va_list args) { + AHardwareBuffer** buffer = va_arg(args, AHardwareBuffer**); + int* fence = va_arg(args, int*); + float* matrix = va_arg(args, float*); + sp<GraphicBuffer> graphicBuffer; + sp<Fence> spFence; + + int result = mGraphicBufferProducer->getLastQueuedBuffer(&graphicBuffer, &spFence, matrix); + + if (graphicBuffer != nullptr) { + *buffer = reinterpret_cast<AHardwareBuffer*>(graphicBuffer.get()); + AHardwareBuffer_acquire(*buffer); + } 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; diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index 0139507101..4a353fc659 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -262,6 +262,7 @@ private: int dispatchAddDequeueInterceptor(va_list args); int dispatchAddPerformInterceptor(va_list args); int dispatchAddQueueInterceptor(va_list args); + int dispatchGetLastQueuedBuffer(va_list args); bool transformToDisplayInverse(); protected: diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h index 121374b1d5..f686147a5f 100644 --- a/libs/nativewindow/include/system/window.h +++ b/libs/nativewindow/include/system/window.h @@ -253,6 +253,7 @@ enum { NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR = 43, /* private */ NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR = 44, /* private */ NATIVE_WINDOW_ALLOCATE_BUFFERS = 45, /* private */ + NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER = 46, /* private */ // clang-format on }; @@ -1018,4 +1019,34 @@ static inline int native_window_set_frame_rate(struct ANativeWindow* window, flo return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, (double)frameRate); } +// ------------------------------------------------------------------------------------------------ +// Candidates for APEX visibility +// These functions are planned to be made stable for APEX modules, but have not +// yet been stabilized to a specific api version. +// ------------------------------------------------------------------------------------------------ + +/** + * Retrieves the last queued buffer for this window, along with the fence that + * fires when the buffer is ready to be read, and the 4x4 coordinate + * transform matrix that should be applied to the buffer's content. The + * transform matrix is represented in column-major order. + * + * If there was no buffer previously queued, then outBuffer will be NULL and + * the value of outFence will be -1. + * + * Note that if outBuffer is not NULL, then the caller will hold a reference + * onto the buffer. Accordingly, the caller must call AHardwareBuffer_release + * when the buffer is no longer needed so that the system may reclaim the + * buffer. + * + * \return NO_ERROR on success. + * \return NO_MEMORY if there was insufficient memory. + */ +static inline int ANativeWindow_getLastQueuedBuffer(ANativeWindow* window, + AHardwareBuffer** outBuffer, int* outFence, + float outTransformMatrix[16]) { + return window->perform(window, NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER, outBuffer, outFence, + outTransformMatrix); +} + __END_DECLS |