From 7734ebfe47f42f980c1b44c1f284a91d8ad1d6c7 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 13 Jul 2011 15:24:42 -0700 Subject: [PATCH] Add set_scaling_mode() to ANativeWindow. This allows to specify the scaling mode independently from the buffer size. Change-Id: Iaa2baa660445531a97d3fac192e580f4929c5d3b --- include/gui/ISurfaceTexture.h | 1 + include/gui/SurfaceTexture.h | 24 ++++++++++++++++++++--- include/gui/SurfaceTextureClient.h | 2 ++ libs/gui/ISurfaceTexture.cpp | 17 ++++++++++++++++ libs/gui/SurfaceTexture.cpp | 24 +++++++++++++++++++++++ libs/gui/SurfaceTextureClient.cpp | 20 +++++++++++++++++++ libs/ui/FramebufferNativeWindow.cpp | 30 ++++++++++++++++++++++++----- 7 files changed, 110 insertions(+), 8 deletions(-) diff --git a/include/gui/ISurfaceTexture.h b/include/gui/ISurfaceTexture.h index 5b5b73134..37a9b4a24 100644 --- a/include/gui/ISurfaceTexture.h +++ b/include/gui/ISurfaceTexture.h @@ -87,6 +87,7 @@ protected: virtual status_t setCrop(const Rect& reg) = 0; virtual status_t setTransform(uint32_t transform) = 0; + virtual status_t setScalingMode(int mode) = 0; // getAllocator retrieves the binder object that must be referenced as long // as the GraphicBuffers dequeued from this ISurfaceTexture are referenced. diff --git a/include/gui/SurfaceTexture.h b/include/gui/SurfaceTexture.h index 4080f2766..e46765e32 100644 --- a/include/gui/SurfaceTexture.h +++ b/include/gui/SurfaceTexture.h @@ -88,6 +88,7 @@ public: virtual void cancelBuffer(int buf); virtual status_t setCrop(const Rect& reg); virtual status_t setTransform(uint32_t transform); + virtual status_t setScalingMode(int mode); virtual int query(int what, int* value); @@ -185,6 +186,9 @@ public: // getCurrentTransform returns the transform of the current buffer uint32_t getCurrentTransform() const; + // getCurrentScalingMode returns the scaling mode of the current buffer + uint32_t getCurrentScalingMode() const; + // dump our state in a String void dump(String8& result) const; void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const; @@ -220,6 +224,7 @@ private: mBufferState(BufferSlot::FREE), mRequestBufferCalled(false), mTransform(0), + mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), mTimestamp(0) { mCrop.makeInvalid(); } @@ -281,6 +286,11 @@ private: // slot. uint32_t mTransform; + // mScalingMode is the current scaling mode for this buffer slot. This + // gets set to mNextScalingMode each time queueBuffer gets called for + // this slot. + uint32_t mScalingMode; + // mTimestamp is the current timestamp for this buffer slot. This gets // to set by queueBuffer each time this slot is queued. int64_t mTimestamp; @@ -337,20 +347,24 @@ private: sp mCurrentTextureBuf; // mCurrentCrop is the crop rectangle that applies to the current texture. - // It gets set to mLastQueuedCrop each time updateTexImage is called. + // It gets set each time updateTexImage is called. Rect mCurrentCrop; // mCurrentTransform is the transform identifier for the current texture. It - // gets set to mLastQueuedTransform each time updateTexImage is called. + // gets set each time updateTexImage is called. uint32_t mCurrentTransform; + // mCurrentScalingMode is the scaling mode for the current texture. It gets + // set to each time updateTexImage is called. + uint32_t mCurrentScalingMode; + // mCurrentTransformMatrix is the transform matrix for the current texture. // It gets computed by computeTransformMatrix each time updateTexImage is // called. float mCurrentTransformMatrix[16]; // mCurrentTimestamp is the timestamp for the current texture. It - // gets set to mLastQueuedTimestamp each time updateTexImage is called. + // gets set each time updateTexImage is called. int64_t mCurrentTimestamp; // mNextCrop is the crop rectangle that will be used for the next buffer @@ -361,6 +375,10 @@ private: // buffer that gets queued. It is set by calling setTransform. uint32_t mNextTransform; + // mNextScalingMode is the scaling mode that will be used for the next + // buffers that get queued. It is set by calling setScalingMode. + int mNextScalingMode; + // mTexName is the name of the OpenGL texture to which streamed images will // be bound when updateTexImage is called. It is set at construction time // changed with a call to setTexName. diff --git a/include/gui/SurfaceTextureClient.h b/include/gui/SurfaceTextureClient.h index cfe2aa13b..76e7119fe 100644 --- a/include/gui/SurfaceTextureClient.h +++ b/include/gui/SurfaceTextureClient.h @@ -63,6 +63,7 @@ private: int dispatchSetBuffersGeometry(va_list args); int dispatchSetBuffersDimensions(va_list args); int dispatchSetBuffersFormat(va_list args); + int dispatchSetScalingMode(va_list args); int dispatchSetBuffersTransform(va_list args); int dispatchSetBuffersTimestamp(va_list args); int dispatchSetCrop(va_list args); @@ -84,6 +85,7 @@ protected: virtual int setBufferCount(int bufferCount); virtual int setBuffersDimensions(int w, int h); virtual int setBuffersFormat(int format); + virtual int setScalingMode(int mode); virtual int setBuffersTransform(int transform); virtual int setBuffersTimestamp(int64_t timestamp); virtual int setCrop(Rect const* rect); diff --git a/libs/gui/ISurfaceTexture.cpp b/libs/gui/ISurfaceTexture.cpp index 41434a4ba..b4b749280 100644 --- a/libs/gui/ISurfaceTexture.cpp +++ b/libs/gui/ISurfaceTexture.cpp @@ -43,6 +43,7 @@ enum { SET_SYNCHRONOUS_MODE, CONNECT, DISCONNECT, + SET_SCALING_MODE, }; @@ -130,6 +131,15 @@ public: return result; } + virtual status_t setScalingMode(int mode) { + Parcel data, reply; + data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); + data.writeInt32(mode); + remote()->transact(SET_SCALING_MODE, data, &reply); + status_t result = reply.readInt32(); + return result; + } + virtual sp getAllocator() { Parcel data, reply; data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); @@ -244,6 +254,13 @@ status_t BnSurfaceTexture::onTransact( 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 GET_ALLOCATOR: { CHECK_INTERFACE(ISurfaceTexture, data, reply); sp result = getAllocator(); diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp index a12d40adc..cc9f461f8 100644 --- a/libs/gui/SurfaceTexture.cpp +++ b/libs/gui/SurfaceTexture.cpp @@ -90,6 +90,7 @@ SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode) : mCurrentTransform(0), mCurrentTimestamp(0), mNextTransform(0), + mNextScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), mTexName(tex), mSynchronousMode(false), mAllowSynchronousMode(allowSynchronousMode), @@ -453,6 +454,7 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { mSlots[buf].mBufferState = BufferSlot::QUEUED; mSlots[buf].mCrop = mNextCrop; mSlots[buf].mTransform = mNextTransform; + mSlots[buf].mScalingMode = mNextScalingMode; mSlots[buf].mTimestamp = timestamp; mDequeueCondition.signal(); } // scope for the lock @@ -542,6 +544,22 @@ status_t SurfaceTexture::disconnect(int api) { return err; } +status_t SurfaceTexture::setScalingMode(int mode) { + LOGV("SurfaceTexture::setScalingMode"); + + switch (mode) { + case NATIVE_WINDOW_SCALING_MODE_FREEZE: + case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: + break; + default: + return BAD_VALUE; + } + + Mutex::Autolock lock(mMutex); + mNextScalingMode = mode; + return OK; +} + status_t SurfaceTexture::updateTexImage() { LOGV("SurfaceTexture::updateTexImage"); Mutex::Autolock lock(mMutex); @@ -602,6 +620,7 @@ status_t SurfaceTexture::updateTexImage() { mCurrentTextureBuf = mSlots[buf].mGraphicBuffer; mCurrentCrop = mSlots[buf].mCrop; mCurrentTransform = mSlots[buf].mTransform; + mCurrentScalingMode = mSlots[buf].mScalingMode; mCurrentTimestamp = mSlots[buf].mTimestamp; computeCurrentTransformMatrix(); @@ -809,6 +828,11 @@ uint32_t SurfaceTexture::getCurrentTransform() const { return mCurrentTransform; } +uint32_t SurfaceTexture::getCurrentScalingMode() const { + Mutex::Autolock lock(mMutex); + return mCurrentScalingMode; +} + int SurfaceTexture::query(int what, int* outValue) { Mutex::Autolock lock(mMutex); diff --git a/libs/gui/SurfaceTextureClient.cpp b/libs/gui/SurfaceTextureClient.cpp index d5b7c89f8..fec80ef93 100644 --- a/libs/gui/SurfaceTextureClient.cpp +++ b/libs/gui/SurfaceTextureClient.cpp @@ -286,6 +286,9 @@ int SurfaceTextureClient::perform(int operation, va_list args) case NATIVE_WINDOW_UNLOCK_AND_POST: res = dispatchUnlockAndPost(args); break; + case NATIVE_WINDOW_SET_SCALING_MODE: + res = dispatchSetScalingMode(args); + break; default: res = NAME_NOT_FOUND; break; @@ -340,6 +343,11 @@ int SurfaceTextureClient::dispatchSetBuffersFormat(va_list args) { return setBuffersFormat(f); } +int SurfaceTextureClient::dispatchSetScalingMode(va_list args) { + int m = va_arg(args, int); + return setScalingMode(m); +} + int SurfaceTextureClient::dispatchSetBuffersTransform(va_list args) { int transform = va_arg(args, int); return setBuffersTransform(transform); @@ -456,6 +464,18 @@ int SurfaceTextureClient::setBuffersFormat(int format) return NO_ERROR; } +int SurfaceTextureClient::setScalingMode(int mode) +{ + LOGV("SurfaceTextureClient::setScalingMode"); + Mutex::Autolock lock(mMutex); + // mode is validated on the server + status_t err = mSurfaceTexture->setScalingMode(mode); + LOGE_IF(err, "ISurfaceTexture::setScalingMode(%d) returned %s", + mode, strerror(-err)); + + return err; +} + int SurfaceTextureClient::setBuffersTransform(int transform) { LOGV("SurfaceTextureClient::setBuffersTransform"); diff --git a/libs/ui/FramebufferNativeWindow.cpp b/libs/ui/FramebufferNativeWindow.cpp index 794747d65..e2772a7fc 100644 --- a/libs/ui/FramebufferNativeWindow.cpp +++ b/libs/ui/FramebufferNativeWindow.cpp @@ -299,18 +299,38 @@ int FramebufferNativeWindow::perform(ANativeWindow* window, { switch (operation) { case NATIVE_WINDOW_SET_USAGE: - case NATIVE_WINDOW_SET_BUFFERS_FORMAT: + // TODO: we should implement this + return NO_ERROR; case NATIVE_WINDOW_CONNECT: + // TODO: we should implement this + return NO_ERROR; case NATIVE_WINDOW_DISCONNECT: - break; + // TODO: we should implement this + return NO_ERROR; case NATIVE_WINDOW_LOCK: return INVALID_OPERATION; case NATIVE_WINDOW_UNLOCK_AND_POST: return INVALID_OPERATION; - default: - return NAME_NOT_FOUND; + case NATIVE_WINDOW_SET_CROP: + return INVALID_OPERATION; + case NATIVE_WINDOW_SET_BUFFER_COUNT: + // TODO: we should implement this + return INVALID_OPERATION; + case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY: + return INVALID_OPERATION; + case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM: + return INVALID_OPERATION; + case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP: + return INVALID_OPERATION; + case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS: + return INVALID_OPERATION; + case NATIVE_WINDOW_SET_BUFFERS_FORMAT: + // TODO: we should implement this + return NO_ERROR; + case NATIVE_WINDOW_SET_SCALING_MODE: + return INVALID_OPERATION; } - return NO_ERROR; + return NAME_NOT_FOUND; } // ----------------------------------------------------------------------------