diff options
| -rw-r--r-- | include/gui/ISurfaceTexture.h | 1 | ||||
| -rw-r--r-- | include/gui/SurfaceTexture.h | 24 | ||||
| -rw-r--r-- | include/gui/SurfaceTextureClient.h | 2 | ||||
| -rw-r--r-- | libs/gui/ISurfaceTexture.cpp | 17 | ||||
| -rw-r--r-- | libs/gui/SurfaceTexture.cpp | 24 | ||||
| -rw-r--r-- | libs/gui/SurfaceTextureClient.cpp | 20 | ||||
| -rw-r--r-- | libs/ui/FramebufferNativeWindow.cpp | 30 | ||||
| -rw-r--r-- | media/libstagefright/ACodec.cpp | 7 | ||||
| -rwxr-xr-x | media/libstagefright/OMXCodec.cpp | 7 | ||||
| -rw-r--r-- | media/libstagefright/colorconversion/SoftwareRenderer.cpp | 5 | ||||
| -rw-r--r-- | native/android/native_window.cpp | 10 | ||||
| -rw-r--r-- | services/camera/libcameraservice/CameraService.cpp | 4 | ||||
| -rw-r--r-- | services/surfaceflinger/Layer.cpp | 20 | ||||
| -rw-r--r-- | services/surfaceflinger/Layer.h | 4 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceTextureLayer.cpp | 3 |
15 files changed, 152 insertions, 26 deletions
diff --git a/include/gui/ISurfaceTexture.h b/include/gui/ISurfaceTexture.h index 5b5b731..37a9b4a 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 4080f27..e46765e 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<GraphicBuffer> 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 cfe2aa1..76e7119 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 41434a4..b4b7492 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<IBinder> 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<IBinder> result = getAllocator(); diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp index a12d40a..3ab6c79 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(%d)", mode); + + 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 d5b7c89..68475e9 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(%d)", mode); + 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 794747d..e2772a7 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; } // ---------------------------------------------------------------------------- diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index d4d07b2..174ec92 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -445,6 +445,13 @@ status_t ACodec::allocateOutputBuffersFromNativeWindow() { return err; } + err = native_window_set_scaling_mode(mNativeWindow.get(), + NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); + + if (err != OK) { + return err; + } + err = native_window_set_buffers_geometry( mNativeWindow.get(), def.format.video.nFrameWidth, diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index 4f8336e..7bcbdcf 100755 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -1765,6 +1765,13 @@ status_t OMXCodec::allocateOutputBuffersFromNativeWindow() { return err; } + err = native_window_set_scaling_mode(mNativeWindow.get(), + NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); + + if (err != OK) { + return err; + } + err = native_window_set_buffers_geometry( mNativeWindow.get(), def.format.video.nFrameWidth, diff --git a/media/libstagefright/colorconversion/SoftwareRenderer.cpp b/media/libstagefright/colorconversion/SoftwareRenderer.cpp index a4ca32d..3246021 100644 --- a/media/libstagefright/colorconversion/SoftwareRenderer.cpp +++ b/media/libstagefright/colorconversion/SoftwareRenderer.cpp @@ -93,6 +93,11 @@ SoftwareRenderer::SoftwareRenderer( GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP)); + CHECK_EQ(0, + native_window_set_scaling_mode( + mNativeWindow.get(), + NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)); + // Width must be multiple of 32??? CHECK_EQ(0, native_window_set_buffers_geometry( mNativeWindow.get(), diff --git a/native/android/native_window.cpp b/native/android/native_window.cpp index 5c016c4..36fc9bf 100644 --- a/native/android/native_window.cpp +++ b/native/android/native_window.cpp @@ -76,7 +76,15 @@ int32_t ANativeWindow_getFormat(ANativeWindow* window) { int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, int32_t width, int32_t height, int32_t format) { - return native_window_set_buffers_geometry(window, width, height, format); + int32_t err = native_window_set_buffers_geometry(window, width, height, format); + if (!err) { + int mode = NATIVE_WINDOW_SCALING_MODE_FREEZE; + if (width && height) { + mode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW; + } + err = native_window_set_scaling_mode(window, mode); + } + return err; } int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 0eff776..637ccd8 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -536,6 +536,8 @@ status_t CameraService::Client::setPreviewWindow(const sp<IBinder>& binder, // If preview has been already started, register preview buffers now. if (mHardware->previewEnabled()) { if (window != 0) { + native_window_set_scaling_mode(window.get(), + NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); native_window_set_buffers_transform(window.get(), mOrientation); result = mHardware->setPreviewWindow(window); } @@ -642,6 +644,8 @@ status_t CameraService::Client::startPreviewMode() { } if (mPreviewWindow != 0) { + native_window_set_scaling_mode(mPreviewWindow.get(), + NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); native_window_set_buffers_transform(mPreviewWindow.get(), mOrientation); } diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index f3b6c4d..c29aeca 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -56,14 +56,14 @@ Layer::Layer(SurfaceFlinger* flinger, mTextureName(-1U), mQueuedFrames(0), mCurrentTransform(0), + mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), mCurrentOpacity(true), mFormat(PIXEL_FORMAT_NONE), mGLExtensions(GLExtensions::getInstance()), mOpaqueLayer(true), mNeedsDithering(false), mSecure(false), - mProtectedByApp(false), - mFixedSize(false) + mProtectedByApp(false) { mCurrentCrop.makeInvalid(); glGenTextures(1, &mTextureName); @@ -400,14 +400,7 @@ uint32_t Layer::doTransaction(uint32_t flags) } bool Layer::isFixedSize() const { - Mutex::Autolock _l(mLock); - return mFixedSize; -} - -void Layer::setFixedSize(bool fixedSize) -{ - Mutex::Autolock _l(mLock); - mFixedSize = fixedSize; + return mCurrentScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE; } bool Layer::isCropped() const { @@ -437,9 +430,14 @@ void Layer::lockPageFlip(bool& recomputeVisibleRegions) const Rect crop(mSurfaceTexture->getCurrentCrop()); const uint32_t transform(mSurfaceTexture->getCurrentTransform()); - if ((crop != mCurrentCrop) || (transform != mCurrentTransform)) { + const uint32_t scalingMode(mSurfaceTexture->getCurrentScalingMode()); + if ((crop != mCurrentCrop) || + (transform != mCurrentTransform) || + (scalingMode != mCurrentScalingMode)) + { mCurrentCrop = crop; mCurrentTransform = transform; + mCurrentScalingMode = scalingMode; mFlinger->invalidateHwcGeometry(); } diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index e3fc13d..ddfc666 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -59,7 +59,6 @@ public: status_t setBuffers(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags=0); - // Set this Layer's buffers size bool isFixedSize() const; // LayerBase interface @@ -88,7 +87,6 @@ private: void onFrameQueued(); virtual sp<ISurface> createSurface(); uint32_t getEffectiveUsage(uint32_t usage) const; - void setFixedSize(bool fixedSize); bool isCropped() const; static bool getOpacityForFormat(uint32_t format); @@ -106,6 +104,7 @@ private: GLfloat mTextureMatrix[16]; Rect mCurrentCrop; uint32_t mCurrentTransform; + uint32_t mCurrentScalingMode; bool mCurrentOpacity; // constants @@ -124,7 +123,6 @@ private: // binder thread, transaction thread mutable Mutex mLock; - bool mFixedSize; }; // --------------------------------------------------------------------------- diff --git a/services/surfaceflinger/SurfaceTextureLayer.cpp b/services/surfaceflinger/SurfaceTextureLayer.cpp index 60fa965..a586d59 100644 --- a/services/surfaceflinger/SurfaceTextureLayer.cpp +++ b/services/surfaceflinger/SurfaceTextureLayer.cpp @@ -64,9 +64,6 @@ status_t SurfaceTextureLayer::dequeueBuffer(int *buf, //LOGD("%s, w=%u, h=%u, format=%u, usage=%08x, effectiveUsage=%08x", // __PRETTY_FUNCTION__, w, h, format, usage, effectiveUsage); res = SurfaceTexture::dequeueBuffer(buf, w, h, format, effectiveUsage); - if (res == NO_ERROR) { - layer->setFixedSize(w && h); - } } return res; } |
