From e1ceec234c618729cc7bd35fecb11744b52c1cc8 Mon Sep 17 00:00:00 2001 From: Chih-Chung Chang Date: Thu, 21 Jan 2010 17:31:06 -0800 Subject: Add an orientation parameter for overlay, so we can do camera preview in portrait mode. --- libs/surfaceflinger/LayerBase.cpp | 2 +- libs/surfaceflinger/LayerBase.h | 2 +- libs/surfaceflinger/LayerBuffer.cpp | 19 ++++++++++++------- libs/surfaceflinger/LayerBuffer.h | 8 +++++--- libs/surfaceflinger/Transform.cpp | 11 +++++++++++ libs/surfaceflinger/Transform.h | 1 + libs/ui/ISurface.cpp | 6 ++++-- 7 files changed, 35 insertions(+), 14 deletions(-) (limited to 'libs') diff --git a/libs/surfaceflinger/LayerBase.cpp b/libs/surfaceflinger/LayerBase.cpp index 8003d22..17db6f4 100644 --- a/libs/surfaceflinger/LayerBase.cpp +++ b/libs/surfaceflinger/LayerBase.cpp @@ -809,7 +809,7 @@ void LayerBaseClient::Surface::unregisterBuffers() } sp LayerBaseClient::Surface::createOverlay( - uint32_t w, uint32_t h, int32_t format) + uint32_t w, uint32_t h, int32_t format, int32_t orientation) { return NULL; }; diff --git a/libs/surfaceflinger/LayerBase.h b/libs/surfaceflinger/LayerBase.h index ed07b3f..f73ea0c 100644 --- a/libs/surfaceflinger/LayerBase.h +++ b/libs/surfaceflinger/LayerBase.h @@ -351,7 +351,7 @@ public: virtual void postBuffer(ssize_t offset); virtual void unregisterBuffers(); virtual sp createOverlay(uint32_t w, uint32_t h, - int32_t format); + int32_t format, int32_t orientation); protected: friend class LayerBaseClient; diff --git a/libs/surfaceflinger/LayerBuffer.cpp b/libs/surfaceflinger/LayerBuffer.cpp index ac9b6b0..2735aa2 100644 --- a/libs/surfaceflinger/LayerBuffer.cpp +++ b/libs/surfaceflinger/LayerBuffer.cpp @@ -182,14 +182,15 @@ status_t LayerBuffer::registerBuffers(const ISurface::BufferHeap& buffers) /** * This creates an "overlay" source for this surface */ -sp LayerBuffer::createOverlay(uint32_t w, uint32_t h, int32_t f) +sp LayerBuffer::createOverlay(uint32_t w, uint32_t h, int32_t f, + int32_t orientation) { sp result; Mutex::Autolock _l(mLock); if (mSource != 0) return result; - sp source = new OverlaySource(*this, &result, w, h, f); + sp source = new OverlaySource(*this, &result, w, h, f, orientation); if (result != 0) { mSource = source; } @@ -248,11 +249,11 @@ void LayerBuffer::SurfaceLayerBuffer::unregisterBuffers() } sp LayerBuffer::SurfaceLayerBuffer::createOverlay( - uint32_t w, uint32_t h, int32_t format) { + uint32_t w, uint32_t h, int32_t format, int32_t orientation) { sp result; sp owner(getOwner()); if (owner != 0) - result = owner->createOverlay(w, h, format); + result = owner->createOverlay(w, h, format, orientation); return result; } @@ -600,9 +601,9 @@ void LayerBuffer::BufferSource::clearTempBufferImage() const LayerBuffer::OverlaySource::OverlaySource(LayerBuffer& layer, sp* overlayRef, - uint32_t w, uint32_t h, int32_t format) + uint32_t w, uint32_t h, int32_t format, int32_t orientation) : Source(layer), mVisibilityChanged(false), - mOverlay(0), mOverlayHandle(0), mOverlayDevice(0) + mOverlay(0), mOverlayHandle(0), mOverlayDevice(0), mOrientation(orientation) { overlay_control_device_t* overlay_dev = mLayer.mFlinger->getOverlayEngine(); if (overlay_dev == NULL) { @@ -684,8 +685,12 @@ void LayerBuffer::OverlaySource::onVisibilityResolved( if (mOverlay) { overlay_control_device_t* overlay_dev = mOverlayDevice; overlay_dev->setPosition(overlay_dev, mOverlay, x,y,w,h); + // we need to combine the layer orientation and the + // user-requested orientation. + Transform finalTransform = Transform(mOrientation) * + Transform(mLayer.getOrientation()); overlay_dev->setParameter(overlay_dev, mOverlay, - OVERLAY_TRANSFORM, mLayer.getOrientation()); + OVERLAY_TRANSFORM, finalTransform.getOrientation()); overlay_dev->commit(overlay_dev, mOverlay); } } diff --git a/libs/surfaceflinger/LayerBuffer.h b/libs/surfaceflinger/LayerBuffer.h index 1b31435..e03f92c 100644 --- a/libs/surfaceflinger/LayerBuffer.h +++ b/libs/surfaceflinger/LayerBuffer.h @@ -74,7 +74,8 @@ public: status_t registerBuffers(const ISurface::BufferHeap& buffers); void postBuffer(ssize_t offset); void unregisterBuffers(); - sp createOverlay(uint32_t w, uint32_t h, int32_t format); + sp createOverlay(uint32_t w, uint32_t h, int32_t format, + int32_t orientation); sp getSource() const; sp clearSource(); @@ -150,7 +151,7 @@ private: public: OverlaySource(LayerBuffer& layer, sp* overlayRef, - uint32_t w, uint32_t h, int32_t format); + uint32_t w, uint32_t h, int32_t format, int32_t orientation); virtual ~OverlaySource(); virtual void onDraw(const Region& clip) const; virtual void onTransaction(uint32_t flags); @@ -183,6 +184,7 @@ private: int32_t mFormat; int32_t mWidthStride; int32_t mHeightStride; + int32_t mOrientation; mutable Mutex mOverlaySourceLock; bool mInitialized; }; @@ -200,7 +202,7 @@ private: virtual void unregisterBuffers(); virtual sp createOverlay( - uint32_t w, uint32_t h, int32_t format); + uint32_t w, uint32_t h, int32_t format, int32_t orientation); private: sp getOwner() const { return static_cast(Surface::getOwner().get()); diff --git a/libs/surfaceflinger/Transform.cpp b/libs/surfaceflinger/Transform.cpp index 1501536..ab6f7ba 100644 --- a/libs/surfaceflinger/Transform.cpp +++ b/libs/surfaceflinger/Transform.cpp @@ -42,6 +42,17 @@ Transform::Transform(const Transform& other) { } +Transform::Transform(int32_t flags) { + mTransform.reset(); + int sx = (flags & FLIP_H) ? -1 : 1; + int sy = (flags & FLIP_V) ? -1 : 1; + if (flags & ROT_90) { + this->set(0, -sy, sx, 0); + } else { + this->set(sx, 0, 0, sy); + } +} + Transform::~Transform() { } diff --git a/libs/surfaceflinger/Transform.h b/libs/surfaceflinger/Transform.h index 78f5c19..ddab404 100644 --- a/libs/surfaceflinger/Transform.h +++ b/libs/surfaceflinger/Transform.h @@ -38,6 +38,7 @@ class Transform public: Transform(); Transform(const Transform& other); + Transform(int32_t flags); ~Transform(); enum orientation_flags { diff --git a/libs/ui/ISurface.cpp b/libs/ui/ISurface.cpp index 4fb38ed..6f3d762 100644 --- a/libs/ui/ISurface.cpp +++ b/libs/ui/ISurface.cpp @@ -115,13 +115,14 @@ public: } virtual sp createOverlay( - uint32_t w, uint32_t h, int32_t format) + uint32_t w, uint32_t h, int32_t format, int32_t orientation) { Parcel data, reply; data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); data.writeInt32(w); data.writeInt32(h); data.writeInt32(format); + data.writeInt32(orientation); remote()->transact(CREATE_OVERLAY, data, &reply); return OverlayRef::readFromParcel(reply); } @@ -173,7 +174,8 @@ status_t BnSurface::onTransact( int w = data.readInt32(); int h = data.readInt32(); int f = data.readInt32(); - sp o = createOverlay(w, h, f); + int orientation = data.readInt32(); + sp o = createOverlay(w, h, f, orientation); return OverlayRef::writeToParcel(reply, o); } break; default: -- cgit v1.1