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

Commit ceaabae2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[ANativeWindow] Add getLastQueuedBuffer api"

parents 4dc8253c ef0b1530
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -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:
+31 −0
Original line number Diff line number Diff line
@@ -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