auto import from //branches/cupcake_rel/...@141571
diff --git a/camera/libcameraservice/Android.mk b/camera/libcameraservice/Android.mk
index 2dfe659..96cc512 100644
--- a/camera/libcameraservice/Android.mk
+++ b/camera/libcameraservice/Android.mk
@@ -42,7 +42,8 @@
 LOCAL_SHARED_LIBRARIES:= \
     libui \
     libutils \
-    libcutils
+    libcutils \
+    libmedia
 
 LOCAL_MODULE:= libcameraservice
 
diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp
index 15e3b21..851b213 100644
--- a/camera/libcameraservice/CameraService.cpp
+++ b/camera/libcameraservice/CameraService.cpp
@@ -28,6 +28,8 @@
 #include <utils/MemoryHeapBase.h>
 #include <ui/ICameraService.h>
 
+#include <media/mediaplayer.h>
+#include <media/AudioSystem.h>
 #include "CameraService.h"
 
 namespace android {
@@ -151,6 +153,19 @@
     }
 }
 
+static sp<MediaPlayer> newMediaPlayer(const char *file) 
+{
+    sp<MediaPlayer> mp = new MediaPlayer();
+    if (mp->setDataSource(file) == NO_ERROR) {
+        mp->setAudioStreamType(AudioSystem::ALARM);
+        mp->prepare();
+    } else {
+        mp.clear();
+        LOGE("Failed to load CameraService sounds.");
+    }
+    return mp;
+}
+
 CameraService::Client::Client(const sp<CameraService>& cameraService,
         const sp<ICameraClient>& cameraClient, pid_t clientPid)
 {
@@ -161,6 +176,9 @@
     mHardware = openCameraHardware();
     mUseOverlay = mHardware->useOverlay();
 
+    mMediaPlayerClick = newMediaPlayer("/system/media/audio/ui/camera_click.ogg");
+    mMediaPlayerBeep = newMediaPlayer("/system/media/audio/ui/VideoRecord.ogg");
+
     // Callback is disabled by default
     mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
     LOGD("Client X constructor");
@@ -265,6 +283,9 @@
 #endif
     }
 
+    mMediaPlayerBeep.clear();
+    mMediaPlayerClick.clear();
+
     // make sure we tear down the hardware
     mClientPid = IPCThreadState::self()->getCallingPid();
     disconnect();
@@ -464,6 +485,9 @@
 
 status_t CameraService::Client::startRecording()
 {
+    if (mMediaPlayerBeep.get() != NULL) {
+        mMediaPlayerBeep->start();
+    }
     return startCameraMode(CAMERA_RECORDING_MODE);
 }
 
@@ -502,6 +526,9 @@
         return;
     }
 
+    if (mMediaPlayerBeep.get() != NULL) {
+        mMediaPlayerBeep->start();
+    }
     mHardware->stopRecording();
     LOGV("stopRecording(), hardware stopped OK");
     mPreviewBuffer.clear();
@@ -684,6 +711,9 @@
         return INVALID_OPERATION;
     }
 
+    if (mMediaPlayerClick.get() != NULL) {
+        mMediaPlayerClick->start();
+    }
     return mHardware->takePicture(shutterCallback,
                                   yuvPictureCallback,
                                   jpegPictureCallback,
diff --git a/camera/libcameraservice/CameraService.h b/camera/libcameraservice/CameraService.h
index d9b7927..6752f26 100644
--- a/camera/libcameraservice/CameraService.h
+++ b/camera/libcameraservice/CameraService.h
@@ -27,6 +27,8 @@
 
 namespace android {
 
+class MediaPlayer;
+
 // ----------------------------------------------------------------------------
 
 #define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
@@ -178,6 +180,9 @@
                     sp<MemoryHeapBase>          mPreviewBuffer;
                     int                         mPreviewCallbackFlag;
 
+                    sp<MediaPlayer>             mMediaPlayerClick;
+                    sp<MediaPlayer>             mMediaPlayerBeep;
+
                     // these are immutable once the object is created,
                     // they don't need to be protected by a lock
                     sp<ICameraClient>           mCameraClient;
diff --git a/libs/surfaceflinger/BootAnimation.cpp b/libs/surfaceflinger/BootAnimation.cpp
index 2b30336..03edbf3 100644
--- a/libs/surfaceflinger/BootAnimation.cpp
+++ b/libs/surfaceflinger/BootAnimation.cpp
@@ -187,44 +187,20 @@
 }
 
 bool BootAnimation::android() {
-    initTexture(&mAndroid[0], mAssets, "images/android_320x480.png");
-    initTexture(&mAndroid[1], mAssets, "images/boot_robot.png");
-    initTexture(&mAndroid[2], mAssets, "images/boot_robot_glow.png");
-
-    // erase screen
-    glDisable(GL_SCISSOR_TEST);
-    glBindTexture(GL_TEXTURE_2D, mAndroid[0].name);
+    initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
+    initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
 
     // clear screen
+    glDisable(GL_DITHER);
+    glDisable(GL_SCISSOR_TEST);
     glClear(GL_COLOR_BUFFER_BIT);
     eglSwapBuffers(mDisplay, mSurface);
 
     // wait ~1s
-    usleep(800000);
 
-    // fade in
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-    const int steps = 8;
-    for (int i = 1; i < steps; i++) {
-        float fade = i / float(steps);
-        glColor4f(1, 1, 1, fade * fade);
-        glClear(GL_COLOR_BUFFER_BIT);
-        glDrawTexiOES(0, 0, 0, mAndroid[0].w, mAndroid[0].h);
-        eglSwapBuffers(mDisplay, mSurface);
-    }
-
-    // draw last frame
-    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-    glDisable(GL_BLEND);
-    glDrawTexiOES(0, 0, 0, mAndroid[0].w, mAndroid[0].h);
-    eglSwapBuffers(mDisplay, mSurface);
-
-    // update rect for the robot
-    const int x = mWidth - mAndroid[1].w - 33;
-    const int y = (mHeight - mAndroid[1].h) / 2 - 1;
-    const Rect updateRect(x, y, x + mAndroid[1].w, y + mAndroid[1].h);
+    const GLint xc = (mWidth  - mAndroid[0].w) / 2;
+    const GLint yc = (mHeight - mAndroid[0].h) / 2;
+    const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h);
 
     // draw and update only what we need
     mNativeWindowSurface->setSwapRectangle(updateRect.left,
@@ -234,166 +210,31 @@
     glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
             updateRect.height());
 
+    // Blend state
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
     const nsecs_t startTime = systemTime();
     do {
-        // glow speed and shape
-        nsecs_t time = systemTime() - startTime;
-        float t = ((4.0f / (360.0f * us2ns(16667))) * time);
-        t = t - floorf(t);
-        const float fade = 0.5f + 0.5f * sinf(t * 2 * M_PI);
+        double time = systemTime() - startTime;
+        float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w;
+        GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w;
+        GLint x = xc - offset;
 
-        // fade the glow in and out
         glDisable(GL_BLEND);
-        glBindTexture(GL_TEXTURE_2D, mAndroid[2].name);
-        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-        glColor4f(fade, fade, fade, fade);
-        glDrawTexiOES(updateRect.left, mHeight - updateRect.bottom, 0,
-                updateRect.width(), updateRect.height());
-
-        // draw the robot
-        glEnable(GL_BLEND);
         glBindTexture(GL_TEXTURE_2D, mAndroid[1].name);
-        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-        glDrawTexiOES(updateRect.left, mHeight - updateRect.bottom, 0,
-                updateRect.width(), updateRect.height());
+        glDrawTexiOES(x,                 yc, 0, mAndroid[1].w, mAndroid[1].h);
+        glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h);
 
-        // make sure sleep a lot to not take too much CPU away from 
-        // the boot process. With this "glow" animation there is no
-        // visible difference. 
-        usleep(16667 * 4);
+        glEnable(GL_BLEND);
+        glBindTexture(GL_TEXTURE_2D, mAndroid[0].name);
+        glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h);
 
         eglSwapBuffers(mDisplay, mSurface);
     } while (!exitPending());
 
     glDeleteTextures(1, &mAndroid[0].name);
     glDeleteTextures(1, &mAndroid[1].name);
-    glDeleteTextures(1, &mAndroid[2].name);
-    return false;
-}
-
-bool BootAnimation::cylon() {
-    // initialize the textures...
-    initTexture(&mLeftTrail, mAssets, "images/cylon_left.png");
-    initTexture(&mRightTrail, mAssets, "images/cylon_right.png");
-    initTexture(&mBrightSpot, mAssets, "images/cylon_dot.png");
-
-    int w = mWidth;
-    int h = mHeight;
-
-    const Point c(w / 2, h / 2);
-    const GLint amplitude = 60;
-    const int scx = c.x - amplitude - mBrightSpot.w / 2;
-    const int scy = c.y - mBrightSpot.h / 2;
-    const int scw = amplitude * 2 + mBrightSpot.w;
-    const int sch = mBrightSpot.h;
-    const Rect updateRect(scx, h - scy - sch, scx + scw, h - scy);
-
-    // erase screen
-    glDisable(GL_SCISSOR_TEST);
-    glClear(GL_COLOR_BUFFER_BIT);
-
-    eglSwapBuffers(mDisplay, mSurface);
-
-    glClear(GL_COLOR_BUFFER_BIT);
-
-    mNativeWindowSurface->setSwapRectangle(updateRect.left,
-            updateRect.top, updateRect.width(), updateRect.height());
-
-    glEnable(GL_SCISSOR_TEST);
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
-    // clear the screen to white
-    Point p;
-    float t = 0;
-    float alpha = 1.0f;
-    const nsecs_t startTime = systemTime();
-    nsecs_t fadeTime = 0;
-
-    do {
-        // Set scissor in interesting area
-        glScissor(scx, scy, scw, sch);
-
-        // erase screen
-        glClear(GL_COLOR_BUFFER_BIT);
-
-        // compute wave
-        const float a = (t * 2 * M_PI) - M_PI / 2;
-        const float sn = sinf(a);
-        const float cs = cosf(a);
-        GLint x = GLint(amplitude * sn);
-        float derivative = cs;
-
-        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
-        if (derivative > 0) {
-            // vanishing trail...
-            p.x = (-amplitude + c.x) - mBrightSpot.w / 2;
-            p.y = c.y - mLeftTrail.h / 2;
-            float fade = 2.0f * (0.5f - t);
-            //fade *= fade;
-            glColor4f(fade, fade, fade, fade);
-            glBindTexture(GL_TEXTURE_2D, mLeftTrail.name);
-            glDrawTexiOES(p.x, p.y, 0, mLeftTrail.w, mLeftTrail.h);
-
-            // trail...
-            p.x = (x + c.x) - (mRightTrail.w + mBrightSpot.w / 2) + 16;
-            p.y = c.y - mRightTrail.h / 2;
-            fade = t < 0.25f ? t * 4.0f : 1.0f;
-            fade *= fade;
-            glColor4f(fade, fade, fade, fade);
-            glBindTexture(GL_TEXTURE_2D, mRightTrail.name);
-            glDrawTexiOES(p.x, p.y, 0, mRightTrail.w, mRightTrail.h);
-        } else {
-            // vanishing trail..
-            p.x = (amplitude + c.x) - (mRightTrail.w + mBrightSpot.w / 2) + 16;
-            p.y = c.y - mRightTrail.h / 2;
-            float fade = 2.0f * (0.5f - (t - 0.5f));
-            //fade *= fade;
-            glColor4f(fade, fade, fade, fade);
-            glBindTexture(GL_TEXTURE_2D, mRightTrail.name);
-            glDrawTexiOES(p.x, p.y, 0, mRightTrail.w, mRightTrail.h);
-
-            // trail...
-            p.x = (x + c.x) - mBrightSpot.w / 2;
-            p.y = c.y - mLeftTrail.h / 2;
-            fade = t < 0.5f + 0.25f ? (t - 0.5f) * 4.0f : 1.0f;
-            fade *= fade;
-            glColor4f(fade, fade, fade, fade);
-            glBindTexture(GL_TEXTURE_2D, mLeftTrail.name);
-            glDrawTexiOES(p.x, p.y, 0, mLeftTrail.w, mLeftTrail.h);
-        }
-
-        const Point p(x + c.x - mBrightSpot.w / 2, c.y - mBrightSpot.h / 2);
-        glBindTexture(GL_TEXTURE_2D, mBrightSpot.name);
-        glColor4f(1, 0.5, 0.5, 1);
-        glDrawTexiOES(p.x, p.y, 0, mBrightSpot.w, mBrightSpot.h);
-
-        // update animation
-        nsecs_t time = systemTime() - startTime;
-        t = ((4.0f / (360.0f * us2ns(16667))) * time);
-        t = t - floorf(t);
-
-        eglSwapBuffers(mDisplay, mSurface);
-
-        if (exitPending()) {
-            if (fadeTime == 0) {
-                fadeTime = time;
-            }
-            time -= fadeTime;
-            alpha = 1.0f - ((float(time) * 6.0f) / float(s2ns(1)));
-
-            session()->openTransaction();
-            mFlingerSurface->setAlpha(alpha * alpha);
-            session()->closeTransaction();
-        }
-    } while (alpha > 0);
-
-    // cleanup
-    glFinish();
-    glDeleteTextures(1, &mLeftTrail.name);
-    glDeleteTextures(1, &mRightTrail.name);
-    glDeleteTextures(1, &mBrightSpot.name);
     return false;
 }
 
diff --git a/libs/surfaceflinger/BootAnimation.h b/libs/surfaceflinger/BootAnimation.h
index b20cea0..3fb6670 100644
--- a/libs/surfaceflinger/BootAnimation.h
+++ b/libs/surfaceflinger/BootAnimation.h
@@ -62,16 +62,12 @@
 
     status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
     bool android();
-    bool cylon();
 
     sp<SurfaceComposerClient>       mSession;
     AssetManager mAssets;
-    Texture mLeftTrail;
-    Texture mRightTrail;
-    Texture mBrightSpot;
-    Texture mAndroid[3];
-    int     mWidth;
-    int     mHeight;
+    Texture     mAndroid[2];
+    int         mWidth;
+    int         mHeight;
     EGLDisplay  mDisplay;
     EGLDisplay  mContext;
     EGLDisplay  mSurface;
diff --git a/libs/surfaceflinger/LayerOrientationAnim.cpp b/libs/surfaceflinger/LayerOrientationAnim.cpp
index 2b72d7c..5fec325 100644
--- a/libs/surfaceflinger/LayerOrientationAnim.cpp
+++ b/libs/surfaceflinger/LayerOrientationAnim.cpp
@@ -55,6 +55,7 @@
     mOrientationCompleted = false;
     mFirstRedraw = false;
     mLastNormalizedTime = 0;
+    mLastAngle = 0;
     mLastScale = 0;
     mNeedsBlending = false;
 }
@@ -94,10 +95,6 @@
     transparentRegionScreen.clear();
     mTransformed = true;
     mCanUseCopyBit = false;
-    copybit_device_t* copybit = mFlinger->getBlitEngine();
-    if (copybit) { 
-        mCanUseCopyBit = true;
-    }
 }
 
 void LayerOrientationAnim::onOrientationCompleted()
@@ -109,35 +106,33 @@
     mFlinger->invalidateLayerVisibility(this);
 }
 
+const float ROTATION = M_PI * 0.5f;
+const float ROTATION_FACTOR = 1.0f; // 1.0 or 2.0
+const float DURATION = ms2ns(200);
+const float BOUNCES_PER_SECOND = 1.618f;
+const float BOUNCES_AMPLITUDE = (5.0f/180.f) * M_PI;
+
 void LayerOrientationAnim::onDraw(const Region& clip) const
 {
     // Animation...
-    const float MIN_SCALE = 0.5f;
-    const float DURATION = ms2ns(200);
-    const float BOUNCES_PER_SECOND = 1.618f;
-    const float BOUNCES_AMPLITUDE = 1.0f/32.0f;
 
+    // FIXME: works only for portrait framebuffers
+    const Point size(getPhysicalSize());
+    const float TARGET_SCALE = size.x * (1.0f / size.y);
+    
     const nsecs_t now = systemTime();
-    float scale, alpha;
+    float angle, scale, alpha;
     
     if (mOrientationCompleted) {
         if (mFirstRedraw) {
-            mFirstRedraw = false;
-            
             // make a copy of what's on screen
             copybit_image_t image;
             mBitmapIn.getBitmapSurface(&image);
             const DisplayHardware& hw(graphicPlane(0).displayHardware());
             hw.copyBackToImage(image);
-
-            // and erase the screen for this round
-            glDisable(GL_BLEND);
-            glDisable(GL_DITHER);
-            glDisable(GL_SCISSOR_TEST);
-            glClearColor(0,0,0,0);
-            glClear(GL_COLOR_BUFFER_BIT);
             
             // FIXME: code below is gross
+            mFirstRedraw = false; 
             mNeedsBlending = false;
             LayerOrientationAnim* self(const_cast<LayerOrientationAnim*>(this));
             mFlinger->invalidateLayerVisibility(self);
@@ -148,36 +143,39 @@
         const float normalizedTime = (float(now - mFinishTime) / duration);
         if (normalizedTime <= 1.0f) {
             const float squaredTime = normalizedTime*normalizedTime;
+            angle = (ROTATION*ROTATION_FACTOR - mLastAngle)*squaredTime + mLastAngle;
             scale = (1.0f - mLastScale)*squaredTime + mLastScale;
-            alpha = (1.0f - normalizedTime);
-            alpha *= alpha;
-            alpha *= alpha;
+            alpha = normalizedTime;
         } else {
             mAnim->onAnimationFinished();
+            angle = ROTATION;
+            alpha = 1.0f;
             scale = 1.0f;
-            alpha = 0.0f;
         }
     } else {
         const float normalizedTime = float(now - mStartTime) / DURATION;
         if (normalizedTime <= 1.0f) {
             mLastNormalizedTime = normalizedTime;
             const float squaredTime = normalizedTime*normalizedTime;
-            scale = (MIN_SCALE-1.0f)*squaredTime + 1.0f;
-            alpha = 1.0f;
+            angle = ROTATION * squaredTime;
+            scale = (TARGET_SCALE - 1.0f)*squaredTime + 1.0f;
+            alpha = 0;
         } else {
             mLastNormalizedTime = 1.0f;
             const float to_seconds = DURATION / seconds(1);
             const float phi = BOUNCES_PER_SECOND * 
-                    (((normalizedTime - 1.0f) * to_seconds)*M_PI*2);
-            scale = MIN_SCALE + BOUNCES_AMPLITUDE * (1.0f - cosf(phi));
-            alpha = 1.0f;
+            (((normalizedTime - 1.0f) * to_seconds)*M_PI*2);
+            angle = ROTATION + BOUNCES_AMPLITUDE * sinf(phi);
+            scale = TARGET_SCALE;
+            alpha = 0;
         }
+        mLastAngle = angle;
         mLastScale = scale;
     }
-    drawScaled(scale, alpha);
+    drawScaled(angle, scale, alpha);
 }
 
-void LayerOrientationAnim::drawScaled(float f, float alpha) const
+void LayerOrientationAnim::drawScaled(float f, float s, float alpha) const
 {
     copybit_image_t dst;
     const GraphicPlane& plane(graphicPlane(0));
@@ -187,98 +185,83 @@
     // clear screen
     // TODO: with update on demand, we may be able 
     // to not erase the screen at all during the animation 
-    if (!mOrientationCompleted) {
-        glDisable(GL_BLEND);
-        glDisable(GL_DITHER);
-        glDisable(GL_SCISSOR_TEST);
-        glClearColor(0,0,0,0);
-        glClear(GL_COLOR_BUFFER_BIT);
-    }
+    glDisable(GL_BLEND);
+    glDisable(GL_DITHER);
+    glDisable(GL_SCISSOR_TEST);
+    glClearColor(0,0,0,0);
+    glClear(GL_COLOR_BUFFER_BIT);
     
-    const int w = dst.w*f; 
-    const int h = dst.h*f; 
-    const int xc = uint32_t(dst.w-w)/2;
-    const int yc = uint32_t(dst.h-h)/2;
-    const copybit_rect_t drect = { xc, yc, xc+w, yc+h }; 
+    const int w = dst.w; 
+    const int h = dst.h; 
 
     copybit_image_t src;
     mBitmap.getBitmapSurface(&src);
     const copybit_rect_t srect = { 0, 0, src.w, src.h };
 
-    int err = NO_ERROR;
-    const int can_use_copybit = canUseCopybit();
-    if (can_use_copybit)  {
-        copybit_device_t* copybit = mFlinger->getBlitEngine();
-        copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0);
-        copybit->set_parameter(copybit, COPYBIT_DITHER, COPYBIT_ENABLE);
 
-        if (alpha < 1.0f) {
-            copybit_image_t srcIn;
-            mBitmapIn.getBitmapSurface(&srcIn);
-            region_iterator it(Region(Rect( drect.l, drect.t, drect.r, drect.b )));
-            copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 0xFF);
-            err = copybit->stretch(copybit, &dst, &srcIn, &drect, &srect, &it);
-        }
+    GGLSurface t;
+    t.version = sizeof(GGLSurface);
+    t.width  = src.w;
+    t.height = src.h;
+    t.stride = src.w;
+    t.vstride= src.h;
+    t.format = src.format;
+    t.data = (GGLubyte*)(intptr_t(src.base) + src.offset);
 
-        if (!err && alpha > 0.0f) {
-            region_iterator it(Region(Rect( drect.l, drect.t, drect.r, drect.b )));
-            copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, int(alpha*255));
-            err = copybit->stretch(copybit, &dst, &src, &drect, &srect, &it);
-        }
-        LOGE_IF(err != NO_ERROR, "copybit failed (%s)", strerror(err));
+    const int targetOrientation = plane.getOrientation(); 
+    if (!targetOrientation) {
+        f = -f;
     }
-    if (!can_use_copybit || err) {   
-        GGLSurface t;
-        t.version = sizeof(GGLSurface);
-        t.width  = src.w;
-        t.height = src.h;
-        t.stride = src.w;
-        t.vstride= src.h;
-        t.format = src.format;
-        t.data = (GGLubyte*)(intptr_t(src.base) + src.offset);
 
-        Transform tr;
-        tr.set(f,0,0,f);
-        tr.set(xc, yc);
-        
-        // FIXME: we should not access mVertices and mDrawingState like that,
-        // but since we control the animation, we know it's going to work okay.
-        // eventually we'd need a more formal way of doing things like this.
-        LayerOrientationAnim& self(const_cast<LayerOrientationAnim&>(*this));
+    Transform tr;
+    tr.set(f, w*0.5f, h*0.5f);
+    tr.scale(s, w*0.5f, h*0.5f);
+
+    // FIXME: we should not access mVertices and mDrawingState like that,
+    // but since we control the animation, we know it's going to work okay.
+    // eventually we'd need a more formal way of doing things like this.
+    LayerOrientationAnim& self(const_cast<LayerOrientationAnim&>(*this));
+    tr.transform(self.mVertices[0], 0, 0);
+    tr.transform(self.mVertices[1], 0, src.h);
+    tr.transform(self.mVertices[2], src.w, src.h);
+    tr.transform(self.mVertices[3], src.w, 0);
+
+    if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
+        // Too slow to do this in software
+        self.mDrawingState.flags |= ISurfaceComposer::eLayerFilter;
+    }
+
+    if (UNLIKELY(mTextureName == -1LU)) {
+        mTextureName = createTexture();
+        GLuint w=0, h=0;
+        const Region dirty(Rect(t.width, t.height));
+        loadTexture(dirty, mTextureName, t, w, h);
+    }
+    self.mDrawingState.alpha = 255; //-int(alpha*255);
+    const Region clip(Rect( srect.l, srect.t, srect.r, srect.b ));
+    drawWithOpenGL(clip, mTextureName, t);
+    
+    if (alpha > 0) {
+        const float sign = (!targetOrientation) ? 1.0f : -1.0f;
+        tr.set(f + sign*(M_PI * 0.5f * ROTATION_FACTOR), w*0.5f, h*0.5f);
+        tr.scale(s, w*0.5f, h*0.5f);
         tr.transform(self.mVertices[0], 0, 0);
         tr.transform(self.mVertices[1], 0, src.h);
         tr.transform(self.mVertices[2], src.w, src.h);
         tr.transform(self.mVertices[3], src.w, 0);
-        if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
-            // Too slow to do this in software
-            self.mDrawingState.flags |= ISurfaceComposer::eLayerFilter;
-        }
 
-        if (alpha < 1.0f) {
-            copybit_image_t src;
-            mBitmapIn.getBitmapSurface(&src);
-            t.data = (GGLubyte*)(intptr_t(src.base) + src.offset);
-            if (UNLIKELY(mTextureNameIn == -1LU)) {
-                mTextureNameIn = createTexture();
-                GLuint w=0, h=0;
-                const Region dirty(Rect(t.width, t.height));
-                loadTexture(dirty, mTextureNameIn, t, w, h);
-            }
-            self.mDrawingState.alpha = 255;
-            const Region clip(Rect( drect.l, drect.t, drect.r, drect.b ));
-            drawWithOpenGL(clip, mTextureName, t);
-        }
-
+        copybit_image_t src;
+        mBitmapIn.getBitmapSurface(&src);
         t.data = (GGLubyte*)(intptr_t(src.base) + src.offset);
-        if (UNLIKELY(mTextureName == -1LU)) {
-            mTextureName = createTexture();
+        if (UNLIKELY(mTextureNameIn == -1LU)) {
+            mTextureNameIn = createTexture();
             GLuint w=0, h=0;
             const Region dirty(Rect(t.width, t.height));
-            loadTexture(dirty, mTextureName, t, w, h);
+            loadTexture(dirty, mTextureNameIn, t, w, h);
         }
         self.mDrawingState.alpha = int(alpha*255);
-        const Region clip(Rect( drect.l, drect.t, drect.r, drect.b ));
-        drawWithOpenGL(clip, mTextureName, t);
+        const Region clip(Rect( srect.l, srect.t, srect.r, srect.b ));
+        drawWithOpenGL(clip, mTextureNameIn, t);
     }
 }
 
diff --git a/libs/surfaceflinger/LayerOrientationAnim.h b/libs/surfaceflinger/LayerOrientationAnim.h
index 7367685..b527c7e 100644
--- a/libs/surfaceflinger/LayerOrientationAnim.h
+++ b/libs/surfaceflinger/LayerOrientationAnim.h
@@ -52,7 +52,7 @@
     virtual bool needsBlending() const;
     virtual bool isSecure() const       { return false; }
 private:
-    void drawScaled(float scale, float alpha) const;
+    void drawScaled(float angle, float scale, float alpha) const;
 
     OrientationAnimation* mAnim;
     LayerBitmap mBitmap;
@@ -62,6 +62,7 @@
     bool mOrientationCompleted;
     mutable bool mFirstRedraw;
     mutable float mLastNormalizedTime;
+    mutable float mLastAngle;
     mutable float mLastScale;
     mutable GLuint  mTextureName;
     mutable GLuint  mTextureNameIn;
diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp
index d915a84..8499b67 100644
--- a/libs/surfaceflinger/SurfaceFlinger.cpp
+++ b/libs/surfaceflinger/SurfaceFlinger.cpp
@@ -1804,6 +1804,7 @@
     if (orientation == ISurfaceComposer::eOrientationDefault) {
         // make sure the default orientation is optimal
         mOrientationTransform.reset();
+        mOrientation = orientation;
         mGlobalTransform = mTransform;
         return NO_ERROR;
     }
@@ -1824,7 +1825,7 @@
         GraphicPlane::orientationToTransfrom(orientation, w, h,
                 &mOrientationTransform);
     }
-    
+    mOrientation = orientation;
     mGlobalTransform = mOrientationTransform * mTransform;
     return NO_ERROR;
 }
diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/libs/surfaceflinger/SurfaceFlinger.h
index f7d7764..3c10481 100644
--- a/libs/surfaceflinger/SurfaceFlinger.h
+++ b/libs/surfaceflinger/SurfaceFlinger.h
@@ -122,6 +122,7 @@
         void                    setDisplayHardware(DisplayHardware *);
         void                    setTransform(const Transform& tr);
         status_t                setOrientation(int orientation);
+        int                     getOrientation() const { return mOrientation; }
 
         const DisplayHardware&  displayHardware() const;
         const Transform&        transform() const;
@@ -133,6 +134,7 @@
         Transform               mTransform;
         Transform               mOrientationTransform;
         Transform               mGlobalTransform;
+        int                     mOrientation;
 };
 
 // ---------------------------------------------------------------------------
diff --git a/libs/surfaceflinger/Transform.cpp b/libs/surfaceflinger/Transform.cpp
index bec7a64..e8b0f45 100644
--- a/libs/surfaceflinger/Transform.cpp
+++ b/libs/surfaceflinger/Transform.cpp
@@ -103,6 +103,25 @@
     mType |= 0x80000000;
 }
 
+void Transform::set(float radian, float x, float y)
+{
+    float r00 = cosf(radian);    float r01 = -sinf(radian);
+    float r10 = sinf(radian);    float r11 =  cosf(radian);
+    mTransform.set(SkMatrix::kMScaleX, SkFloatToScalar(r00));
+    mTransform.set(SkMatrix::kMSkewX, SkFloatToScalar(r01));
+    mTransform.set(SkMatrix::kMSkewY, SkFloatToScalar(r10));
+    mTransform.set(SkMatrix::kMScaleY, SkFloatToScalar(r11));
+    mTransform.set(SkMatrix::kMTransX, SkIntToScalar(x - r00*x - r01*y));
+    mTransform.set(SkMatrix::kMTransY, SkIntToScalar(y - r10*x - r11*y));
+    mType |= 0x80000000 | SkMatrix::kTranslate_Mask;
+}
+
+void Transform::scale(float s, float x, float y)
+{
+    mTransform.postScale(s, s, x, y); 
+    mType |= 0x80000000;
+}
+
 void Transform::set(int tx, int ty)
 {
     if (tx | ty) {
diff --git a/libs/surfaceflinger/Transform.h b/libs/surfaceflinger/Transform.h
index 0b4835e..4c4528e 100644
--- a/libs/surfaceflinger/Transform.h
+++ b/libs/surfaceflinger/Transform.h
@@ -60,7 +60,9 @@
             void    reset();
             void    set(float xx, float xy, float yx, float yy);
             void    set(int tx, int ty);
-
+            void    set(float radian, float x, float y);
+            void    scale(float s, float x, float y);
+            
             Rect    makeBounds(int w, int h) const;
             void    transform(GLfixed* point, int x, int y) const;
             Region  transform(const Region& reg) const;