SurfaceTexture: clean up some comments, tests, etc.
This change fixes up some stale comments, member variable names, log messages and disables a failing test. Change-Id: Ic1d3344b18066cf710e4a42838b2417c6b1f2f6c
This commit is contained in:
parent
d958485844
commit
8cd5ba4b7f
|
@ -197,8 +197,9 @@ private:
|
||||||
mEglDisplay(EGL_NO_DISPLAY),
|
mEglDisplay(EGL_NO_DISPLAY),
|
||||||
mBufferState(BufferSlot::FREE),
|
mBufferState(BufferSlot::FREE),
|
||||||
mRequestBufferCalled(false),
|
mRequestBufferCalled(false),
|
||||||
mLastQueuedTransform(0),
|
mTransform(0),
|
||||||
mLastQueuedTimestamp(0) {
|
mTimestamp(0) {
|
||||||
|
mCrop.makeInvalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
// mGraphicBuffer points to the buffer allocated for this slot or is NULL
|
// mGraphicBuffer points to the buffer allocated for this slot or is NULL
|
||||||
|
@ -211,32 +212,56 @@ private:
|
||||||
// mEglDisplay is the EGLDisplay used to create mEglImage.
|
// mEglDisplay is the EGLDisplay used to create mEglImage.
|
||||||
EGLDisplay mEglDisplay;
|
EGLDisplay mEglDisplay;
|
||||||
|
|
||||||
// mBufferState indicates whether the slot is currently accessible to a
|
// BufferState represents the different states in which a buffer slot
|
||||||
// client and should not be used by the SurfaceTexture object. It gets
|
// can be.
|
||||||
// set to true when dequeueBuffer returns the slot and is reset to false
|
enum BufferState {
|
||||||
// when the client calls either queueBuffer or cancelBuffer on the slot.
|
// FREE indicates that the buffer is not currently being used and
|
||||||
enum { DEQUEUED=-2, FREE=-1, QUEUED=0 };
|
// will not be used in the future until it gets dequeued and
|
||||||
int8_t mBufferState;
|
// subseqently queued by the client.
|
||||||
|
FREE = 0,
|
||||||
|
|
||||||
|
// DEQUEUED indicates that the buffer has been dequeued by the
|
||||||
|
// client, but has not yet been queued or canceled. The buffer is
|
||||||
|
// considered 'owned' by the client, and the server should not use
|
||||||
|
// it for anything.
|
||||||
|
//
|
||||||
|
// Note that when in synchronous-mode (mSynchronousMode == true),
|
||||||
|
// the buffer that's currently attached to the texture may be
|
||||||
|
// dequeued by the client. That means that the current buffer can
|
||||||
|
// be in either the DEQUEUED or QUEUED state. In asynchronous mode,
|
||||||
|
// however, the current buffer is always in the QUEUED state.
|
||||||
|
DEQUEUED = 1,
|
||||||
|
|
||||||
|
// QUEUED indicates that the buffer has been queued by the client,
|
||||||
|
// and has not since been made available for the client to dequeue.
|
||||||
|
// Attaching the buffer to the texture does NOT transition the
|
||||||
|
// buffer away from the QUEUED state. However, in Synchronous mode
|
||||||
|
// the current buffer may be dequeued by the client under some
|
||||||
|
// circumstances. See the note about the current buffer in the
|
||||||
|
// documentation for DEQUEUED.
|
||||||
|
QUEUED = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
// mBufferState is the current state of this buffer slot.
|
||||||
|
BufferState mBufferState;
|
||||||
|
|
||||||
// mRequestBufferCalled is used for validating that the client did
|
// mRequestBufferCalled is used for validating that the client did
|
||||||
// call requestBuffer() when told to do so. Technically this is not
|
// call requestBuffer() when told to do so. Technically this is not
|
||||||
// needed but useful for debugging and catching client bugs.
|
// needed but useful for debugging and catching client bugs.
|
||||||
bool mRequestBufferCalled;
|
bool mRequestBufferCalled;
|
||||||
|
|
||||||
// mLastQueuedCrop is the crop rectangle for the buffer that was most
|
// mCrop is the current crop rectangle for this buffer slot. This gets
|
||||||
// recently queued. This gets set to mNextCrop each time queueBuffer gets
|
// set to mNextCrop each time queueBuffer gets called for this buffer.
|
||||||
// called.
|
Rect mCrop;
|
||||||
Rect mLastQueuedCrop;
|
|
||||||
|
|
||||||
// mLastQueuedTransform is the transform identifier for the buffer that was
|
// mTransform is the current transform flags for this buffer slot. This
|
||||||
// most recently queued. This gets set to mNextTransform each time
|
// gets set to mNextTransform each time queueBuffer gets called for this
|
||||||
// queueBuffer gets called.
|
// slot.
|
||||||
uint32_t mLastQueuedTransform;
|
uint32_t mTransform;
|
||||||
|
|
||||||
// mLastQueuedTimestamp is the timestamp for the buffer that was most
|
// mTimestamp is the current timestamp for this buffer slot. This gets
|
||||||
// recently queued. This gets set by queueBuffer.
|
// to set by queueBuffer each time this slot is queued.
|
||||||
int64_t mLastQueuedTimestamp;
|
int64_t mTimestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
// mSlots is the array of buffer slots that must be mirrored on the client
|
// mSlots is the array of buffer slots that must be mirrored on the client
|
||||||
|
|
|
@ -390,49 +390,49 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) {
|
||||||
sp<FrameAvailableListener> listener;
|
sp<FrameAvailableListener> listener;
|
||||||
|
|
||||||
{ // scope for the lock
|
{ // scope for the lock
|
||||||
Mutex::Autolock lock(mMutex);
|
Mutex::Autolock lock(mMutex);
|
||||||
if (buf < 0 || buf >= mBufferCount) {
|
if (buf < 0 || buf >= mBufferCount) {
|
||||||
LOGE("queueBuffer: slot index out of range [0, %d]: %d",
|
LOGE("queueBuffer: slot index out of range [0, %d]: %d",
|
||||||
mBufferCount, buf);
|
mBufferCount, buf);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
} else if (mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
|
} else if (mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
|
||||||
LOGE("queueBuffer: slot %d is not owned by the client (state=%d)",
|
LOGE("queueBuffer: slot %d is not owned by the client (state=%d)",
|
||||||
buf, mSlots[buf].mBufferState);
|
buf, mSlots[buf].mBufferState);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
} else if (buf == mCurrentTexture) {
|
} else if (buf == mCurrentTexture) {
|
||||||
LOGE("queueBuffer: slot %d is current!", buf);
|
LOGE("queueBuffer: slot %d is current!", buf);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
} else if (!mSlots[buf].mRequestBufferCalled) {
|
} else if (!mSlots[buf].mRequestBufferCalled) {
|
||||||
LOGE("queueBuffer: slot %d was enqueued without requesting a buffer",
|
LOGE("queueBuffer: slot %d was enqueued without requesting a "
|
||||||
buf);
|
"buffer", buf);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mQueue.empty()) {
|
|
||||||
listener = mFrameAvailableListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mSynchronousMode) {
|
|
||||||
// in synchronous mode we queue all buffers in a FIFO
|
|
||||||
mQueue.push_back(buf);
|
|
||||||
} else {
|
|
||||||
// in asynchronous mode we only keep the most recent buffer
|
|
||||||
if (mQueue.empty()) {
|
if (mQueue.empty()) {
|
||||||
|
listener = mFrameAvailableListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mSynchronousMode) {
|
||||||
|
// in synchronous mode we queue all buffers in a FIFO
|
||||||
mQueue.push_back(buf);
|
mQueue.push_back(buf);
|
||||||
} else {
|
} else {
|
||||||
Fifo::iterator front(mQueue.begin());
|
// in asynchronous mode we only keep the most recent buffer
|
||||||
// buffer currently queued is freed
|
if (mQueue.empty()) {
|
||||||
mSlots[*front].mBufferState = BufferSlot::FREE;
|
mQueue.push_back(buf);
|
||||||
// and we record the new buffer index in the queued list
|
} else {
|
||||||
*front = buf;
|
Fifo::iterator front(mQueue.begin());
|
||||||
|
// buffer currently queued is freed
|
||||||
|
mSlots[*front].mBufferState = BufferSlot::FREE;
|
||||||
|
// and we record the new buffer index in the queued list
|
||||||
|
*front = buf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mSlots[buf].mBufferState = BufferSlot::QUEUED;
|
mSlots[buf].mBufferState = BufferSlot::QUEUED;
|
||||||
mSlots[buf].mLastQueuedCrop = mNextCrop;
|
mSlots[buf].mCrop = mNextCrop;
|
||||||
mSlots[buf].mLastQueuedTransform = mNextTransform;
|
mSlots[buf].mTransform = mNextTransform;
|
||||||
mSlots[buf].mLastQueuedTimestamp = timestamp;
|
mSlots[buf].mTimestamp = timestamp;
|
||||||
mDequeueCondition.signal();
|
mDequeueCondition.signal();
|
||||||
} // scope for the lock
|
} // scope for the lock
|
||||||
|
|
||||||
// call back without lock held
|
// call back without lock held
|
||||||
|
@ -540,9 +540,9 @@ status_t SurfaceTexture::updateTexImage() {
|
||||||
mCurrentTexture = buf;
|
mCurrentTexture = buf;
|
||||||
mCurrentTextureTarget = target;
|
mCurrentTextureTarget = target;
|
||||||
mCurrentTextureBuf = mSlots[buf].mGraphicBuffer;
|
mCurrentTextureBuf = mSlots[buf].mGraphicBuffer;
|
||||||
mCurrentCrop = mSlots[buf].mLastQueuedCrop;
|
mCurrentCrop = mSlots[buf].mCrop;
|
||||||
mCurrentTransform = mSlots[buf].mLastQueuedTransform;
|
mCurrentTransform = mSlots[buf].mTransform;
|
||||||
mCurrentTimestamp = mSlots[buf].mLastQueuedTimestamp;
|
mCurrentTimestamp = mSlots[buf].mTimestamp;
|
||||||
mDequeueCondition.signal();
|
mDequeueCondition.signal();
|
||||||
} else {
|
} else {
|
||||||
// We always bind the texture even if we don't update its contents.
|
// We always bind the texture even if we don't update its contents.
|
||||||
|
@ -826,12 +826,10 @@ void SurfaceTexture::dump(String8& result, const char* prefix,
|
||||||
const BufferSlot& slot(mSlots[i]);
|
const BufferSlot& slot(mSlots[i]);
|
||||||
snprintf(buffer, SIZE,
|
snprintf(buffer, SIZE,
|
||||||
"%s%s[%02d] state=%-8s, crop=[%d,%d,%d,%d], transform=0x%02x, "
|
"%s%s[%02d] state=%-8s, crop=[%d,%d,%d,%d], transform=0x%02x, "
|
||||||
"timestamp=%lld\n"
|
"timestamp=%lld\n",
|
||||||
,
|
|
||||||
prefix, (i==mCurrentTexture)?">":" ", i, stateName(slot.mBufferState),
|
prefix, (i==mCurrentTexture)?">":" ", i, stateName(slot.mBufferState),
|
||||||
slot.mLastQueuedCrop.left, slot.mLastQueuedCrop.top,
|
slot.mCrop.left, slot.mCrop.top, slot.mCrop.right, slot.mCrop.bottom,
|
||||||
slot.mLastQueuedCrop.right, slot.mLastQueuedCrop.bottom,
|
slot.mTransform, slot.mTimestamp
|
||||||
slot.mLastQueuedTransform, slot.mLastQueuedTimestamp
|
|
||||||
);
|
);
|
||||||
result.append(buffer);
|
result.append(buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,8 @@ int SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer) {
|
||||||
mReqFormat, mReqUsage);
|
mReqFormat, mReqUsage);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
LOGV("dequeueBuffer: ISurfaceTexture::dequeueBuffer(%d, %d, %d, %d)"
|
LOGV("dequeueBuffer: ISurfaceTexture::dequeueBuffer(%d, %d, %d, %d)"
|
||||||
"failed: %d", result, mReqWidth, mReqHeight, mReqFormat, mReqUsage);
|
"failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage,
|
||||||
|
result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
sp<GraphicBuffer>& gbuf(mSlots[buf]);
|
sp<GraphicBuffer>& gbuf(mSlots[buf]);
|
||||||
|
|
|
@ -400,7 +400,9 @@ TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeDQQR) {
|
||||||
EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
|
EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeDequeueCurrent) {
|
// XXX: We currently have no hardware that properly handles dequeuing the
|
||||||
|
// buffer that is currently bound to the texture.
|
||||||
|
TEST_F(SurfaceTextureClientTest, DISABLED_SurfaceTextureSyncModeDequeueCurrent) {
|
||||||
sp<ANativeWindow> anw(mSTC);
|
sp<ANativeWindow> anw(mSTC);
|
||||||
sp<SurfaceTexture> st(mST);
|
sp<SurfaceTexture> st(mST);
|
||||||
android_native_buffer_t* buf[3];
|
android_native_buffer_t* buf[3];
|
||||||
|
|
Loading…
Reference in New Issue