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

Commit 1d01a12e authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

Add support for timestamps into SurfaceTexture.

API addition: The timestamps are represented as nanoseconds from some
arbitrary time point. Like the SurfaceTexture transform matrix, the
timestamp retrieved by getTimestamp is for the last frame sent to the
GL texture using updateTexImage().

Camera HAL change: Expect vendors to set these timestamps using
native_window_set_buffers_timestamp().  For now, they are
autogenerated by SurfaceTextureClient if set_buffers_timestamp() is
never called, but such timing is likely not accurate enough to pass a
CTS test.

bug:3300707

Change-Id: Ife131a0c2a826ac27342e11b8a6c42ff49e1bea7
parent f75ad0db
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -62,8 +62,11 @@ public:
    // contents of the buffer associated with slot and transfers ownership of
    // contents of the buffer associated with slot and transfers ownership of
    // that slot back to the server. It is not valid to call queueBuffer on a
    // that slot back to the server. It is not valid to call queueBuffer on a
    // slot that is not owned by the client or one for which a buffer associated
    // slot that is not owned by the client or one for which a buffer associated
    // via requestBuffer.
    // via requestBuffer. In addition, a timestamp must be provided by the
    virtual status_t queueBuffer(int slot) = 0;
    // client for this buffer. The timestamp is measured in nanoseconds, and
    // must be monotonically increasing. Its other properties (zero point, etc)
    // are client-dependent, and should be documented by the client.
    virtual status_t queueBuffer(int slot, int64_t timestamp) = 0;


    // cancelBuffer indicates that the client does not wish to fill in the
    // cancelBuffer indicates that the client does not wish to fill in the
    // buffer associated with slot and transfers ownership of the slot back to
    // buffer associated with slot and transfers ownership of the slot back to
+22 −1
Original line number Original line Diff line number Diff line
@@ -66,7 +66,12 @@ public:
    // unmodified.
    // unmodified.
    virtual status_t dequeueBuffer(int *buf);
    virtual status_t dequeueBuffer(int *buf);


    virtual status_t queueBuffer(int buf);
    // queueBuffer returns a filled buffer to the SurfaceTexture. In addition, a
    // timestamp must be provided for the buffer. The timestamp is in
    // nanoseconds, and must be monotonically increasing. Its other semantics
    // (zero point, etc) are client-dependent and should be documented by the
    // client.
    virtual status_t queueBuffer(int buf, int64_t timestamp);
    virtual void cancelBuffer(int buf);
    virtual void cancelBuffer(int buf);
    virtual status_t setCrop(const Rect& reg);
    virtual status_t setCrop(const Rect& reg);
    virtual status_t setTransform(uint32_t transform);
    virtual status_t setTransform(uint32_t transform);
@@ -98,6 +103,14 @@ public:
    // functions.
    // functions.
    void getTransformMatrix(float mtx[16]);
    void getTransformMatrix(float mtx[16]);


    // getTimestamp retrieves the timestamp associated with the texture image
    // set by the most recent call to updateTexImage.
    //
    // The timestamp is in nanoseconds, and is monotonically increasing. Its
    // other semantics (zero point, etc) are source-dependent and should be
    // documented by the source.
    int64_t getTimestamp();

    // setFrameAvailableListener sets the listener object that will be notified
    // setFrameAvailableListener sets the listener object that will be notified
    // when a new frame becomes available.
    // when a new frame becomes available.
    void setFrameAvailableListener(const sp<FrameAvailableListener>& l);
    void setFrameAvailableListener(const sp<FrameAvailableListener>& l);
@@ -172,6 +185,10 @@ private:
    // gets set to mLastQueuedTransform each time updateTexImage is called.
    // gets set to mLastQueuedTransform each time updateTexImage is called.
    uint32_t mCurrentTransform;
    uint32_t mCurrentTransform;


    // mCurrentTimestamp is the timestamp for the current texture. It
    // gets set to mLastQueuedTimestamp each time updateTexImage is called.
    int64_t mCurrentTimestamp;

    // mLastQueued is the buffer slot index of the most recently enqueued buffer.
    // mLastQueued is the buffer slot index of the most recently enqueued buffer.
    // At construction time it is initialized to INVALID_BUFFER_SLOT, and is
    // At construction time it is initialized to INVALID_BUFFER_SLOT, and is
    // updated each time queueBuffer is called.
    // updated each time queueBuffer is called.
@@ -187,6 +204,10 @@ private:
    // queueBuffer gets called.
    // queueBuffer gets called.
    uint32_t mLastQueuedTransform;
    uint32_t mLastQueuedTransform;


    // mLastQueuedTimestamp is the timestamp for the buffer that was most
    // recently queued. This gets set by queueBuffer.
    int64_t mLastQueuedTimestamp;

    // mNextCrop is the crop rectangle that will be used for the next buffer
    // mNextCrop is the crop rectangle that will be used for the next buffer
    // that gets queued. It is set by calling setCrop.
    // that gets queued. It is set by calling setCrop.
    Rect mNextCrop;
    Rect mNextCrop;
+7 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ private:
    int dispatchSetBufferCount(va_list args);
    int dispatchSetBufferCount(va_list args);
    int dispatchSetBuffersGeometry(va_list args);
    int dispatchSetBuffersGeometry(va_list args);
    int dispatchSetBuffersTransform(va_list args);
    int dispatchSetBuffersTransform(va_list args);
    int dispatchSetBuffersTimestamp(va_list args);
    int dispatchSetCrop(va_list args);
    int dispatchSetCrop(va_list args);
    int dispatchSetUsage(va_list args);
    int dispatchSetUsage(va_list args);


@@ -71,6 +72,7 @@ private:
    int setBufferCount(int bufferCount);
    int setBufferCount(int bufferCount);
    int setBuffersGeometry(int w, int h, int format);
    int setBuffersGeometry(int w, int h, int format);
    int setBuffersTransform(int transform);
    int setBuffersTransform(int transform);
    int setBuffersTimestamp(int64_t timestamp);
    int setCrop(Rect const* rect);
    int setCrop(Rect const* rect);
    int setUsage(uint32_t reqUsage);
    int setUsage(uint32_t reqUsage);


@@ -114,6 +116,11 @@ private:
    // at the next deuque operation. It is initialized to 0.
    // at the next deuque operation. It is initialized to 0.
    uint32_t mReqUsage;
    uint32_t mReqUsage;


    // mTimestamp is the timestamp that will be used for the next buffer queue
    // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
    // a timestamp is auto-generated when queueBuffer is called.
    int64_t mTimestamp;

    // mMutex is the mutex used to prevent concurrent access to the member
    // mMutex is the mutex used to prevent concurrent access to the member
    // variables of SurfaceTexture objects. It must be locked whenever the
    // variables of SurfaceTexture objects. It must be locked whenever the
    // member variables are accessed.
    // member variables are accessed.
+3 −1
Original line number Original line Diff line number Diff line
@@ -226,6 +226,7 @@ private:
    int  dispatch_set_buffer_count(va_list args);
    int  dispatch_set_buffer_count(va_list args);
    int  dispatch_set_buffers_geometry(va_list args);
    int  dispatch_set_buffers_geometry(va_list args);
    int  dispatch_set_buffers_transform(va_list args);
    int  dispatch_set_buffers_transform(va_list args);
    int  dispatch_set_buffers_timestamp(va_list args);


    void setUsage(uint32_t reqUsage);
    void setUsage(uint32_t reqUsage);
    int  connect(int api);
    int  connect(int api);
@@ -234,6 +235,7 @@ private:
    int  setBufferCount(int bufferCount);
    int  setBufferCount(int bufferCount);
    int  setBuffersGeometry(int w, int h, int format);
    int  setBuffersGeometry(int w, int h, int format);
    int  setBuffersTransform(int transform);
    int  setBuffersTransform(int transform);
    int  setBuffersTimestamp(int64_t timestamp);


    /*
    /*
     *  private stuff...
     *  private stuff...
+29 −3
Original line number Original line Diff line number Diff line
@@ -129,6 +129,7 @@ enum {
    NATIVE_WINDOW_SET_BUFFER_COUNT,
    NATIVE_WINDOW_SET_BUFFER_COUNT,
    NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
    NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
    NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
    NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
    NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
};
};


/* parameter for NATIVE_WINDOW_[DIS]CONNECT */
/* parameter for NATIVE_WINDOW_[DIS]CONNECT */
@@ -157,6 +158,14 @@ enum {
    NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT,       // SurfaceTextureClient
    NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT,       // SurfaceTextureClient
};
};


/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
 *
 * Special timestamp value to indicate that timestamps should be auto-generated
 * by the native window when queueBuffer is called.  This is equal to INT64_MIN,
 * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
 */
const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);

struct ANativeWindow
struct ANativeWindow
{
{
#ifdef __cplusplus
#ifdef __cplusplus
@@ -262,6 +271,7 @@ struct ANativeWindow
     *     NATIVE_WINDOW_SET_BUFFER_COUNT
     *     NATIVE_WINDOW_SET_BUFFER_COUNT
     *     NATIVE_WINDOW_SET_BUFFERS_GEOMETRY
     *     NATIVE_WINDOW_SET_BUFFERS_GEOMETRY
     *     NATIVE_WINDOW_SET_BUFFERS_TRANSFORM
     *     NATIVE_WINDOW_SET_BUFFERS_TRANSFORM
     *     NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
     *
     *
     */
     */
    
    
@@ -389,6 +399,22 @@ static inline int native_window_set_buffers_transform(
            transform);
            transform);
}
}


/*
 * native_window_set_buffers_timestamp(..., int64_t timestamp)
 * All buffers queued after this call will be associated with the timestamp
 * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
 * (the default), timestamps will be generated automatically when queueBuffer is
 * called. The timestamp is measured in nanoseconds, and must be monotonically
 * increasing.
 */
static inline int native_window_set_buffers_timestamp(
        ANativeWindow* window,
        int64_t timestamp)
{
    return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
            timestamp);
}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


/* FIXME: this is legacy for pixmaps */
/* FIXME: this is legacy for pixmaps */
Loading