diff options
author | Mathias Agopian <mathias@google.com> | 2012-03-29 17:10:08 -0700 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2012-03-30 15:16:30 -0700 |
commit | 851ef8f1bfbb164d61b1528a529a464f0a60dbaf (patch) | |
tree | 89341bb3c0cbda6b18dc0585c64e892c83f134a4 /libs/gui | |
parent | 9285a16450323d0e91513e2c270c2ac03c8b940c (diff) | |
download | frameworks_native-851ef8f1bfbb164d61b1528a529a464f0a60dbaf.zip frameworks_native-851ef8f1bfbb164d61b1528a529a464f0a60dbaf.tar.gz frameworks_native-851ef8f1bfbb164d61b1528a529a464f0a60dbaf.tar.bz2 |
reduce IPC with BufferQueue
collapse setCrop, setTransform and setScalingMode to queueBuffer()
this ends up simplifying things quite a bit and reducing the numnber
of IPC needed per frame.
Change-Id: I3a13c07603abe4e76b8251e6380b107fde22e6d9
Diffstat (limited to 'libs/gui')
-rw-r--r-- | libs/gui/BufferQueue.cpp | 77 | ||||
-rw-r--r-- | libs/gui/ISurfaceTexture.cpp | 75 | ||||
-rw-r--r-- | libs/gui/SurfaceTextureClient.cpp | 51 |
3 files changed, 51 insertions, 152 deletions
diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index ffc5fa0..1762a4a 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -76,8 +76,6 @@ BufferQueue::BufferQueue( bool allowSynchronousMode ) : mBufferCount(MIN_ASYNC_BUFFER_SLOTS), mClientBufferCount(0), mServerBufferCount(MIN_ASYNC_BUFFER_SLOTS), - mNextTransform(0), - mNextScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), mSynchronousMode(false), mAllowSynchronousMode(allowSynchronousMode), mConnectedApi(NO_CONNECTED_API), @@ -94,7 +92,6 @@ BufferQueue::BufferQueue( bool allowSynchronousMode ) : ST_LOGV("BufferQueue"); sp<ISurfaceComposer> composer(ComposerService::getComposerService()); mGraphicBufferAlloc = composer->createGraphicBufferAlloc(); - mNextCrop.makeInvalid(); } BufferQueue::~BufferQueue() { @@ -454,9 +451,6 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h, mSlots[buf].mFence = EGL_NO_SYNC_KHR; mSlots[buf].mEglDisplay = EGL_NO_DISPLAY; - - - returnFlags |= ISurfaceTexture::BUFFER_NEEDS_REALLOCATION; } @@ -476,7 +470,6 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h, ALOGE("dequeueBuffer: timeout waiting for fence"); } eglDestroySyncKHR(dpy, fence); - } ST_LOGV("dequeueBuffer: returning slot=%d buf=%p flags=%#x", *outBuf, @@ -518,6 +511,7 @@ status_t BufferQueue::setSynchronousMode(bool enabled) { } status_t BufferQueue::queueBuffer(int buf, int64_t timestamp, + const Rect& crop, int scalingMode, uint32_t transform, uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { ATRACE_CALL(); ATRACE_BUFFER_INDEX(buf); @@ -571,10 +565,20 @@ status_t BufferQueue::queueBuffer(int buf, int64_t timestamp, } } + switch (scalingMode) { + case NATIVE_WINDOW_SCALING_MODE_FREEZE: + case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: + break; + default: + ST_LOGE("unknown scaling mode: %d (ignoring)", scalingMode); + scalingMode = mSlots[buf].mScalingMode; + break; + } + mSlots[buf].mBufferState = BufferSlot::QUEUED; - mSlots[buf].mCrop = mNextCrop; - mSlots[buf].mTransform = mNextTransform; - mSlots[buf].mScalingMode = mNextScalingMode; + mSlots[buf].mCrop = crop; + mSlots[buf].mTransform = transform; + mSlots[buf].mScalingMode = scalingMode; mSlots[buf].mTimestamp = timestamp; mFrameCounter++; mSlots[buf].mFrameNumber = mFrameCounter; @@ -620,50 +624,6 @@ void BufferQueue::cancelBuffer(int buf) { mDequeueCondition.broadcast(); } -status_t BufferQueue::setCrop(const Rect& crop) { - ATRACE_CALL(); - ST_LOGV("setCrop: crop=[%d,%d,%d,%d]", crop.left, crop.top, crop.right, - crop.bottom); - - Mutex::Autolock lock(mMutex); - if (mAbandoned) { - ST_LOGE("setCrop: BufferQueue has been abandoned!"); - return NO_INIT; - } - mNextCrop = crop; - return OK; -} - -status_t BufferQueue::setTransform(uint32_t transform) { - ATRACE_CALL(); - ST_LOGV("setTransform: xform=%#x", transform); - Mutex::Autolock lock(mMutex); - if (mAbandoned) { - ST_LOGE("setTransform: BufferQueue has been abandoned!"); - return NO_INIT; - } - mNextTransform = transform; - return OK; -} - -status_t BufferQueue::setScalingMode(int mode) { - ATRACE_CALL(); - ST_LOGV("setScalingMode: mode=%d", mode); - - switch (mode) { - case NATIVE_WINDOW_SCALING_MODE_FREEZE: - case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: - break; - default: - ST_LOGE("unknown scaling mode: %d", mode); - return BAD_VALUE; - } - - Mutex::Autolock lock(mMutex); - mNextScalingMode = mode; - return OK; -} - status_t BufferQueue::connect(int api, uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { ATRACE_CALL(); @@ -731,9 +691,6 @@ status_t BufferQueue::disconnect(int api) { if (mConnectedApi == api) { drainQueueAndFreeBuffersLocked(); mConnectedApi = NO_CONNECTED_API; - mNextCrop.makeInvalid(); - mNextScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; - mNextTransform = 0; mDequeueCondition.broadcast(); listener = mConsumerListener; } else { @@ -766,12 +723,6 @@ void BufferQueue::dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const { Mutex::Autolock _l(mMutex); - snprintf(buffer, SIZE, - "%snext : {crop=[%d,%d,%d,%d], transform=0x%02x}\n" - ,prefix, mNextCrop.left, mNextCrop.top, mNextCrop.right, - mNextCrop.bottom, mNextTransform - ); - result.append(buffer); String8 fifo; int fifoSize = 0; diff --git a/libs/gui/ISurfaceTexture.cpp b/libs/gui/ISurfaceTexture.cpp index d2e5627..29c50c9 100644 --- a/libs/gui/ISurfaceTexture.cpp +++ b/libs/gui/ISurfaceTexture.cpp @@ -36,13 +36,10 @@ enum { DEQUEUE_BUFFER, QUEUE_BUFFER, CANCEL_BUFFER, - SET_CROP, - SET_TRANSFORM, QUERY, SET_SYNCHRONOUS_MODE, CONNECT, DISCONNECT, - SET_SCALING_MODE, }; @@ -102,11 +99,15 @@ public: } virtual status_t queueBuffer(int buf, int64_t timestamp, + const Rect& crop, int scalingMode, uint32_t transform, uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { Parcel data, reply; data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); data.writeInt32(buf); data.writeInt64(timestamp); + memcpy(data.writeInplace(sizeof(Rect)), &crop, sizeof(Rect)); + data.writeInt32(scalingMode); + data.writeInt32(transform); status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); if (result != NO_ERROR) { return result; @@ -125,45 +126,6 @@ public: remote()->transact(CANCEL_BUFFER, data, &reply); } - virtual status_t setCrop(const Rect& reg) { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); - data.writeFloat(reg.left); - data.writeFloat(reg.top); - data.writeFloat(reg.right); - data.writeFloat(reg.bottom); - status_t result = remote()->transact(SET_CROP, data, &reply); - if (result != NO_ERROR) { - return result; - } - result = reply.readInt32(); - return result; - } - - virtual status_t setTransform(uint32_t transform) { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); - data.writeInt32(transform); - status_t result = remote()->transact(SET_TRANSFORM, data, &reply); - if (result != NO_ERROR) { - return result; - } - result = reply.readInt32(); - return result; - } - - virtual status_t setScalingMode(int mode) { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); - data.writeInt32(mode); - status_t result = remote()->transact(SET_SCALING_MODE, data, &reply); - if (result != NO_ERROR) { - return result; - } - result = reply.readInt32(); - return result; - } - virtual int query(int what, int* value) { Parcel data, reply; data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); @@ -261,8 +223,12 @@ status_t BnSurfaceTexture::onTransact( CHECK_INTERFACE(ISurfaceTexture, data, reply); int buf = data.readInt32(); int64_t timestamp = data.readInt64(); + Rect crop( *reinterpret_cast<Rect const *>(data.readInplace(sizeof(Rect))) ); + int scalingMode = data.readInt32(); + uint32_t transform = data.readInt32(); uint32_t outWidth, outHeight, outTransform; status_t result = queueBuffer(buf, timestamp, + crop, scalingMode, transform, &outWidth, &outHeight, &outTransform); reply->writeInt32(outWidth); reply->writeInt32(outHeight); @@ -276,31 +242,6 @@ status_t BnSurfaceTexture::onTransact( cancelBuffer(buf); return NO_ERROR; } break; - case SET_CROP: { - Rect reg; - CHECK_INTERFACE(ISurfaceTexture, data, reply); - reg.left = data.readFloat(); - reg.top = data.readFloat(); - reg.right = data.readFloat(); - reg.bottom = data.readFloat(); - status_t result = setCrop(reg); - reply->writeInt32(result); - return NO_ERROR; - } break; - case SET_TRANSFORM: { - CHECK_INTERFACE(ISurfaceTexture, data, reply); - uint32_t transform = data.readInt32(); - status_t result = setTransform(transform); - reply->writeInt32(result); - return NO_ERROR; - } break; - case SET_SCALING_MODE: { - CHECK_INTERFACE(ISurfaceTexture, data, reply); - int mode = data.readInt32(); - status_t result = setScalingMode(mode); - reply->writeInt32(result); - return NO_ERROR; - } break; case QUERY: { CHECK_INTERFACE(ISurfaceTexture, data, reply); int value; diff --git a/libs/gui/SurfaceTextureClient.cpp b/libs/gui/SurfaceTextureClient.cpp index b9e870d..6aa81a9 100644 --- a/libs/gui/SurfaceTextureClient.cpp +++ b/libs/gui/SurfaceTextureClient.cpp @@ -75,6 +75,9 @@ void SurfaceTextureClient::init() { mReqFormat = 0; mReqUsage = 0; mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO; + mCrop.clear(); + mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; + mTransform = 0; mDefaultWidth = 0; mDefaultHeight = 0; mTransformHint = 0; @@ -245,6 +248,7 @@ int SurfaceTextureClient::queueBuffer(android_native_buffer_t* buffer) { return i; } status_t err = mSurfaceTexture->queueBuffer(i, timestamp, + mCrop, mScalingMode, mTransform, &mDefaultWidth, &mDefaultHeight, &mTransformHint); if (err != OK) { ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err); @@ -444,6 +448,9 @@ int SurfaceTextureClient::disconnect(int api) { mReqWidth = 0; mReqHeight = 0; mReqUsage = 0; + mCrop.clear(); + mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; + mTransform = 0; if (api == NATIVE_WINDOW_API_CPU) { mConnectedToCpu = false; } @@ -463,19 +470,17 @@ int SurfaceTextureClient::setCrop(Rect const* rect) { ATRACE_CALL(); ALOGV("SurfaceTextureClient::setCrop"); - Mutex::Autolock lock(mMutex); Rect realRect; if (rect == NULL || rect->isEmpty()) { - realRect = Rect(0, 0); + realRect.clear(); } else { realRect = *rect; } - status_t err = mSurfaceTexture->setCrop(*rect); - ALOGE_IF(err, "ISurfaceTexture::setCrop(...) returned %s", strerror(-err)); - - return err; + Mutex::Autolock lock(mMutex); + mCrop = *rect; + return NO_ERROR; } int SurfaceTextureClient::setBufferCount(int bufferCount) @@ -499,7 +504,6 @@ int SurfaceTextureClient::setBuffersDimensions(int w, int h) { ATRACE_CALL(); ALOGV("SurfaceTextureClient::setBuffersDimensions"); - Mutex::Autolock lock(mMutex); if (w<0 || h<0) return BAD_VALUE; @@ -507,25 +511,22 @@ int SurfaceTextureClient::setBuffersDimensions(int w, int h) if ((w && !h) || (!w && h)) return BAD_VALUE; + Mutex::Autolock lock(mMutex); mReqWidth = w; mReqHeight = h; - - status_t err = mSurfaceTexture->setCrop(Rect(0, 0)); - ALOGE_IF(err, "ISurfaceTexture::setCrop(...) returned %s", strerror(-err)); - - return err; + mCrop.clear(); + return NO_ERROR; } int SurfaceTextureClient::setBuffersFormat(int format) { ALOGV("SurfaceTextureClient::setBuffersFormat"); - Mutex::Autolock lock(mMutex); if (format<0) return BAD_VALUE; + Mutex::Autolock lock(mMutex); mReqFormat = format; - return NO_ERROR; } @@ -533,13 +534,19 @@ int SurfaceTextureClient::setScalingMode(int mode) { ATRACE_CALL(); ALOGV("SurfaceTextureClient::setScalingMode(%d)", mode); - Mutex::Autolock lock(mMutex); - // mode is validated on the server - status_t err = mSurfaceTexture->setScalingMode(mode); - ALOGE_IF(err, "ISurfaceTexture::setScalingMode(%d) returned %s", - mode, strerror(-err)); - return err; + switch (mode) { + case NATIVE_WINDOW_SCALING_MODE_FREEZE: + case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: + break; + default: + ALOGE("unknown scaling mode: %d", mode); + return BAD_VALUE; + } + + Mutex::Autolock lock(mMutex); + mScalingMode = mode; + return NO_ERROR; } int SurfaceTextureClient::setBuffersTransform(int transform) @@ -547,8 +554,8 @@ int SurfaceTextureClient::setBuffersTransform(int transform) ATRACE_CALL(); ALOGV("SurfaceTextureClient::setBuffersTransform"); Mutex::Autolock lock(mMutex); - status_t err = mSurfaceTexture->setTransform(transform); - return err; + mTransform = transform; + return NO_ERROR; } int SurfaceTextureClient::setBuffersTimestamp(int64_t timestamp) |