From 0c2bcbc6cc2c41c567596e1579adae64570e9aad Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Thu, 19 Mar 2009 23:08:54 -0700 Subject: auto import from //branches/cupcake_rel/...@141571 --- camera/libcameraservice/Android.mk | 3 +- camera/libcameraservice/CameraService.cpp | 30 ++++ camera/libcameraservice/CameraService.h | 5 + libs/surfaceflinger/BootAnimation.cpp | 199 +++------------------------ libs/surfaceflinger/BootAnimation.h | 10 +- libs/surfaceflinger/LayerOrientationAnim.cpp | 187 ++++++++++++------------- libs/surfaceflinger/LayerOrientationAnim.h | 3 +- libs/surfaceflinger/SurfaceFlinger.cpp | 3 +- libs/surfaceflinger/SurfaceFlinger.h | 2 + libs/surfaceflinger/Transform.cpp | 19 +++ libs/surfaceflinger/Transform.h | 4 +- 11 files changed, 173 insertions(+), 292 deletions(-) diff --git a/camera/libcameraservice/Android.mk b/camera/libcameraservice/Android.mk index 2dfe659a2e..96cc512dc5 100644 --- a/camera/libcameraservice/Android.mk +++ b/camera/libcameraservice/Android.mk @@ -42,7 +42,8 @@ LOCAL_SRC_FILES:= \ LOCAL_SHARED_LIBRARIES:= \ libui \ libutils \ - libcutils + libcutils \ + libmedia LOCAL_MODULE:= libcameraservice diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index 15e3b21aea..851b2132f6 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -28,6 +28,8 @@ #include #include +#include +#include #include "CameraService.h" namespace android { @@ -151,6 +153,19 @@ void CameraService::removeClient(const sp& cameraClient) } } +static sp newMediaPlayer(const char *file) +{ + sp 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, const sp& cameraClient, pid_t clientPid) { @@ -161,6 +176,9 @@ CameraService::Client::Client(const sp& cameraService, 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 @@ CameraService::Client::~Client() #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::startPreview() status_t CameraService::Client::startRecording() { + if (mMediaPlayerBeep.get() != NULL) { + mMediaPlayerBeep->start(); + } return startCameraMode(CAMERA_RECORDING_MODE); } @@ -502,6 +526,9 @@ void CameraService::Client::stopRecording() return; } + if (mMediaPlayerBeep.get() != NULL) { + mMediaPlayerBeep->start(); + } mHardware->stopRecording(); LOGV("stopRecording(), hardware stopped OK"); mPreviewBuffer.clear(); @@ -684,6 +711,9 @@ status_t CameraService::Client::takePicture() 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 d9b79276a7..6752f265da 100644 --- a/camera/libcameraservice/CameraService.h +++ b/camera/libcameraservice/CameraService.h @@ -27,6 +27,8 @@ class android::MemoryHeapBase; namespace android { +class MediaPlayer; + // ---------------------------------------------------------------------------- #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) @@ -178,6 +180,9 @@ private: sp mPreviewBuffer; int mPreviewCallbackFlag; + sp mMediaPlayerClick; + sp mMediaPlayerBeep; + // these are immutable once the object is created, // they don't need to be protected by a lock sp mCameraClient; diff --git a/libs/surfaceflinger/BootAnimation.cpp b/libs/surfaceflinger/BootAnimation.cpp index 2b30336b78..03edbf380f 100644 --- a/libs/surfaceflinger/BootAnimation.cpp +++ b/libs/surfaceflinger/BootAnimation.cpp @@ -187,44 +187,20 @@ bool BootAnimation::threadLoop() { } 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 @@ bool BootAnimation::android() { 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 b20cea09a4..3fb6670b3e 100644 --- a/libs/surfaceflinger/BootAnimation.h +++ b/libs/surfaceflinger/BootAnimation.h @@ -62,16 +62,12 @@ private: status_t initTexture(Texture* texture, AssetManager& asset, const char* name); bool android(); - bool cylon(); sp 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 2b72d7ce94..5fec325b80 100644 --- a/libs/surfaceflinger/LayerOrientationAnim.cpp +++ b/libs/surfaceflinger/LayerOrientationAnim.cpp @@ -55,6 +55,7 @@ LayerOrientationAnim::LayerOrientationAnim( mOrientationCompleted = false; mFirstRedraw = false; mLastNormalizedTime = 0; + mLastAngle = 0; mLastScale = 0; mNeedsBlending = false; } @@ -94,10 +95,6 @@ void LayerOrientationAnim::validateVisibility(const Transform&) transparentRegionScreen.clear(); mTransformed = true; mCanUseCopyBit = false; - copybit_device_t* copybit = mFlinger->getBlitEngine(); - if (copybit) { - mCanUseCopyBit = true; - } } void LayerOrientationAnim::onOrientationCompleted() @@ -109,35 +106,33 @@ void LayerOrientationAnim::onOrientationCompleted() 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(this)); mFlinger->invalidateLayerVisibility(self); @@ -148,36 +143,39 @@ void LayerOrientationAnim::onDraw(const Region& clip) const 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 @@ void LayerOrientationAnim::drawScaled(float f, float alpha) const // 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); - } - 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)); + 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); + + const int targetOrientation = plane.getOrientation(); + if (!targetOrientation) { + f = -f; + } + + 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(*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 (!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(*this)); + 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 73676859bc..b527c7e595 100644 --- a/libs/surfaceflinger/LayerOrientationAnim.h +++ b/libs/surfaceflinger/LayerOrientationAnim.h @@ -52,7 +52,7 @@ public: 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 @@ private: 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 d915a8424b..8499b67ac6 100644 --- a/libs/surfaceflinger/SurfaceFlinger.cpp +++ b/libs/surfaceflinger/SurfaceFlinger.cpp @@ -1804,6 +1804,7 @@ status_t GraphicPlane::setOrientation(int orientation) if (orientation == ISurfaceComposer::eOrientationDefault) { // make sure the default orientation is optimal mOrientationTransform.reset(); + mOrientation = orientation; mGlobalTransform = mTransform; return NO_ERROR; } @@ -1824,7 +1825,7 @@ status_t GraphicPlane::setOrientation(int orientation) 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 f7d77640ae..3c10481f90 100644 --- a/libs/surfaceflinger/SurfaceFlinger.h +++ b/libs/surfaceflinger/SurfaceFlinger.h @@ -122,6 +122,7 @@ public: 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 @@ private: Transform mTransform; Transform mOrientationTransform; Transform mGlobalTransform; + int mOrientation; }; // --------------------------------------------------------------------------- diff --git a/libs/surfaceflinger/Transform.cpp b/libs/surfaceflinger/Transform.cpp index bec7a64036..e8b0f45f81 100644 --- a/libs/surfaceflinger/Transform.cpp +++ b/libs/surfaceflinger/Transform.cpp @@ -103,6 +103,25 @@ void Transform::set( float xx, float xy, 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 0b4835effd..4c4528ecd4 100644 --- a/libs/surfaceflinger/Transform.h +++ b/libs/surfaceflinger/Transform.h @@ -60,7 +60,9 @@ public: 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; -- cgit v1.2.3-59-g8ed1b From 4d45243ceac53b611c500be9408cff341ab8edbf Mon Sep 17 00:00:00 2001 From: Jason Sams <> Date: Tue, 24 Mar 2009 17:58:31 -0700 Subject: Automated import from //branches/cupcake/...@141597,141597 --- camera/libcameraservice/CameraService.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index 851b2132f6..c5c95b05e7 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -283,8 +283,14 @@ CameraService::Client::~Client() #endif } - mMediaPlayerBeep.clear(); - mMediaPlayerClick.clear(); + if (mMediaPlayerBeep.get() != NULL) { + mMediaPlayerBeep->disconnect(); + mMediaPlayerBeep.clear(); + } + if (mMediaPlayerClick.get() != NULL) { + mMediaPlayerClick->disconnect(); + mMediaPlayerClick.clear(); + } // make sure we tear down the hardware mClientPid = IPCThreadState::self()->getCallingPid(); @@ -711,9 +717,6 @@ status_t CameraService::Client::takePicture() return INVALID_OPERATION; } - if (mMediaPlayerClick.get() != NULL) { - mMediaPlayerClick->start(); - } return mHardware->takePicture(shutterCallback, yuvPictureCallback, jpegPictureCallback, @@ -751,6 +754,10 @@ void CameraService::Client::shutterCallback(void *user) client->mSurface->registerBuffers(buffers); } + + if (client->mMediaPlayerClick.get() != NULL) { + client->mMediaPlayerClick->start(); + } } // picture callback - raw image ready -- cgit v1.2.3-59-g8ed1b From ab9687f0f8e9c6ac29ed25a07fa67993b7664408 Mon Sep 17 00:00:00 2001 From: Wu-cheng Li <> Date: Tue, 24 Mar 2009 18:01:34 -0700 Subject: Automated import from //branches/cupcake/...@141613,141613 --- camera/libcameraservice/CameraService.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index c5c95b05e7..6a6a811fa7 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -731,6 +731,11 @@ void CameraService::Client::shutterCallback(void *user) return; } + // Play shutter sound. + if (client->mMediaPlayerClick.get() != NULL) { + client->mMediaPlayerClick->start(); + } + // Screen goes black after the buffer is unregistered. if (client->mSurface != 0 && !client->mUseOverlay) { client->mSurface->unregisterBuffers(); @@ -754,10 +759,6 @@ void CameraService::Client::shutterCallback(void *user) client->mSurface->registerBuffers(buffers); } - - if (client->mMediaPlayerClick.get() != NULL) { - client->mMediaPlayerClick->start(); - } } // picture callback - raw image ready -- cgit v1.2.3-59-g8ed1b From e4d3058e2ffaec9ab0e1983676d31dce20eae5de Mon Sep 17 00:00:00 2001 From: Andreas Huber <> Date: Tue, 24 Mar 2009 18:14:23 -0700 Subject: Automated import from //branches/cupcake/...@141708,141708 --- camera/libcameraservice/CameraService.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index 6a6a811fa7..7e5fdbe156 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -492,6 +492,7 @@ status_t CameraService::Client::startPreview() status_t CameraService::Client::startRecording() { if (mMediaPlayerBeep.get() != NULL) { + mMediaPlayerBeep->seekTo(0); mMediaPlayerBeep->start(); } return startCameraMode(CAMERA_RECORDING_MODE); @@ -533,6 +534,7 @@ void CameraService::Client::stopRecording() } if (mMediaPlayerBeep.get() != NULL) { + mMediaPlayerBeep->seekTo(0); mMediaPlayerBeep->start(); } mHardware->stopRecording(); @@ -733,6 +735,7 @@ void CameraService::Client::shutterCallback(void *user) // Play shutter sound. if (client->mMediaPlayerClick.get() != NULL) { + client->mMediaPlayerClick->seekTo(0); client->mMediaPlayerClick->start(); } -- cgit v1.2.3-59-g8ed1b From 2ed5f739ebd88f25e16f1f5edfd0041bdf637394 Mon Sep 17 00:00:00 2001 From: Mathias Agopian <> Date: Tue, 24 Mar 2009 19:41:37 -0700 Subject: Automated import from //branches/cupcake/...@142427,142427 --- libs/surfaceflinger/BootAnimation.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/surfaceflinger/BootAnimation.cpp b/libs/surfaceflinger/BootAnimation.cpp index 03edbf380f..db40385732 100644 --- a/libs/surfaceflinger/BootAnimation.cpp +++ b/libs/surfaceflinger/BootAnimation.cpp @@ -164,9 +164,7 @@ status_t BootAnimation::readyToRun() { // initialize GL glShadeModel(GL_FLAT); - glEnable(GL_DITHER); glEnable(GL_TEXTURE_2D); - glEnable(GL_SCISSOR_TEST); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); return NO_ERROR; @@ -196,8 +194,6 @@ bool BootAnimation::android() { glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(mDisplay, mSurface); - // wait ~1s - 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); @@ -216,7 +212,8 @@ bool BootAnimation::android() { const nsecs_t startTime = systemTime(); do { - double time = systemTime() - startTime; + nsecs_t now = systemTime(); + double time = now - 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; @@ -231,6 +228,11 @@ bool BootAnimation::android() { glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h); eglSwapBuffers(mDisplay, mSurface); + + // 12fps: don't animate too fast to preserve CPU + const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); + if (sleepTime > 0) + usleep(sleepTime); } while (!exitPending()); glDeleteTextures(1, &mAndroid[0].name); -- cgit v1.2.3-59-g8ed1b From 0348218e930441c68e90a4e55893ae3b9e1ea0ef Mon Sep 17 00:00:00 2001 From: Mathias Agopian <> Date: Tue, 24 Mar 2009 19:43:24 -0700 Subject: Automated import from //branches/cupcake/...@142445,142445 --- libs/surfaceflinger/LayerOrientationAnim.cpp | 187 +++++++++++++++------------ libs/surfaceflinger/LayerOrientationAnim.h | 3 +- libs/surfaceflinger/SurfaceFlinger.cpp | 3 +- libs/surfaceflinger/SurfaceFlinger.h | 2 - libs/surfaceflinger/Transform.cpp | 19 --- libs/surfaceflinger/Transform.h | 4 +- 6 files changed, 105 insertions(+), 113 deletions(-) diff --git a/libs/surfaceflinger/LayerOrientationAnim.cpp b/libs/surfaceflinger/LayerOrientationAnim.cpp index 5fec325b80..2b72d7ce94 100644 --- a/libs/surfaceflinger/LayerOrientationAnim.cpp +++ b/libs/surfaceflinger/LayerOrientationAnim.cpp @@ -55,7 +55,6 @@ LayerOrientationAnim::LayerOrientationAnim( mOrientationCompleted = false; mFirstRedraw = false; mLastNormalizedTime = 0; - mLastAngle = 0; mLastScale = 0; mNeedsBlending = false; } @@ -95,6 +94,10 @@ void LayerOrientationAnim::validateVisibility(const Transform&) transparentRegionScreen.clear(); mTransformed = true; mCanUseCopyBit = false; + copybit_device_t* copybit = mFlinger->getBlitEngine(); + if (copybit) { + mCanUseCopyBit = true; + } } void LayerOrientationAnim::onOrientationCompleted() @@ -106,33 +109,35 @@ void LayerOrientationAnim::onOrientationCompleted() 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 angle, scale, alpha; + float 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(this)); mFlinger->invalidateLayerVisibility(self); @@ -143,39 +148,36 @@ void LayerOrientationAnim::onDraw(const Region& clip) const 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 = normalizedTime; + alpha = (1.0f - normalizedTime); + alpha *= alpha; + alpha *= alpha; } 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; - angle = ROTATION * squaredTime; - scale = (TARGET_SCALE - 1.0f)*squaredTime + 1.0f; - alpha = 0; + scale = (MIN_SCALE-1.0f)*squaredTime + 1.0f; + alpha = 1.0f; } 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); - angle = ROTATION + BOUNCES_AMPLITUDE * sinf(phi); - scale = TARGET_SCALE; - alpha = 0; + (((normalizedTime - 1.0f) * to_seconds)*M_PI*2); + scale = MIN_SCALE + BOUNCES_AMPLITUDE * (1.0f - cosf(phi)); + alpha = 1.0f; } - mLastAngle = angle; mLastScale = scale; } - drawScaled(angle, scale, alpha); + drawScaled(scale, alpha); } -void LayerOrientationAnim::drawScaled(float f, float s, float alpha) const +void LayerOrientationAnim::drawScaled(float f, float alpha) const { copybit_image_t dst; const GraphicPlane& plane(graphicPlane(0)); @@ -185,83 +187,98 @@ void LayerOrientationAnim::drawScaled(float f, float s, float alpha) const // clear screen // TODO: with update on demand, we may be able // to not erase the screen at all during the animation - glDisable(GL_BLEND); - glDisable(GL_DITHER); - glDisable(GL_SCISSOR_TEST); - glClearColor(0,0,0,0); - glClear(GL_COLOR_BUFFER_BIT); + if (!mOrientationCompleted) { + 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; - const int h = dst.h; + 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 }; 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); - - const int targetOrientation = plane.getOrientation(); - if (!targetOrientation) { - f = -f; - } - - 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(*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 (!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)); } + 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); - 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); + 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(*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 (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(mTextureNameIn == -1LU)) { - mTextureNameIn = createTexture(); + if (UNLIKELY(mTextureName == -1LU)) { + mTextureName = createTexture(); GLuint w=0, h=0; const Region dirty(Rect(t.width, t.height)); - loadTexture(dirty, mTextureNameIn, t, w, h); + loadTexture(dirty, mTextureName, t, w, h); } self.mDrawingState.alpha = int(alpha*255); - const Region clip(Rect( srect.l, srect.t, srect.r, srect.b )); - drawWithOpenGL(clip, mTextureNameIn, t); + const Region clip(Rect( drect.l, drect.t, drect.r, drect.b )); + drawWithOpenGL(clip, mTextureName, t); } } diff --git a/libs/surfaceflinger/LayerOrientationAnim.h b/libs/surfaceflinger/LayerOrientationAnim.h index b527c7e595..73676859bc 100644 --- a/libs/surfaceflinger/LayerOrientationAnim.h +++ b/libs/surfaceflinger/LayerOrientationAnim.h @@ -52,7 +52,7 @@ public: virtual bool needsBlending() const; virtual bool isSecure() const { return false; } private: - void drawScaled(float angle, float scale, float alpha) const; + void drawScaled(float scale, float alpha) const; OrientationAnimation* mAnim; LayerBitmap mBitmap; @@ -62,7 +62,6 @@ private: 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 8499b67ac6..d915a8424b 100644 --- a/libs/surfaceflinger/SurfaceFlinger.cpp +++ b/libs/surfaceflinger/SurfaceFlinger.cpp @@ -1804,7 +1804,6 @@ status_t GraphicPlane::setOrientation(int orientation) if (orientation == ISurfaceComposer::eOrientationDefault) { // make sure the default orientation is optimal mOrientationTransform.reset(); - mOrientation = orientation; mGlobalTransform = mTransform; return NO_ERROR; } @@ -1825,7 +1824,7 @@ status_t GraphicPlane::setOrientation(int orientation) 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 3c10481f90..f7d77640ae 100644 --- a/libs/surfaceflinger/SurfaceFlinger.h +++ b/libs/surfaceflinger/SurfaceFlinger.h @@ -122,7 +122,6 @@ public: 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; @@ -134,7 +133,6 @@ private: Transform mTransform; Transform mOrientationTransform; Transform mGlobalTransform; - int mOrientation; }; // --------------------------------------------------------------------------- diff --git a/libs/surfaceflinger/Transform.cpp b/libs/surfaceflinger/Transform.cpp index e8b0f45f81..bec7a64036 100644 --- a/libs/surfaceflinger/Transform.cpp +++ b/libs/surfaceflinger/Transform.cpp @@ -103,25 +103,6 @@ void Transform::set( float xx, float xy, 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 4c4528ecd4..0b4835effd 100644 --- a/libs/surfaceflinger/Transform.h +++ b/libs/surfaceflinger/Transform.h @@ -60,9 +60,7 @@ public: 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; -- cgit v1.2.3-59-g8ed1b From df351ba57378ee9e58cf0b0cd1ff6d4700052ec6 Mon Sep 17 00:00:00 2001 From: Jack Palevich <> Date: Tue, 24 Mar 2009 20:18:08 -0700 Subject: Automated import from //branches/cupcake/...@142481,142481 --- opengl/libagl/egl.cpp | 24 ++++++++++++++++++------ opengl/libs/EGL/egl.cpp | 35 ++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/opengl/libagl/egl.cpp b/opengl/libagl/egl.cpp index 5b90bf03fd..3b4c0419f0 100644 --- a/opengl/libagl/egl.cpp +++ b/opengl/libagl/egl.cpp @@ -1055,8 +1055,12 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, { if (egl_display_t::is_valid(dpy) == EGL_FALSE) return setError(EGL_BAD_DISPLAY, EGL_FALSE); + + if (ggl_unlikely(num_config==0)) { + return setError(EGL_BAD_PARAMETER, EGL_FALSE); + } - if (ggl_unlikely(configs==0 || attrib_list==0)) { + if (ggl_unlikely(attrib_list==0)) { *num_config = 0; return EGL_TRUE; } @@ -1102,11 +1106,19 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, // return the configurations found int n=0; if (possibleMatch) { - for (int i=0 ; config_size && i0) { // n has to be 0 or 1, by construction, and we already know // which config it will return (since there can be only one). - configs[0] = MAKE_CONFIG(i, index); + if (configs) { + configs[0] = MAKE_CONFIG(i, index); + } *num_config = 1; } } @@ -798,19 +799,23 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, if (cnx->dso) { if (cnx->hooks->egl.eglChooseConfig( dp->dpys[i], attrib_list, configs, config_size, &n)) { - // now we need to convert these client EGLConfig to our - // internal EGLConfig format. This is done in O(n log n). - for (int j=0 ; j( - dp->configs[i], 0, dp->numConfigs[i]-1, configs[j]); - if (index >= 0) { - configs[j] = MAKE_CONFIG(i, index); - } else { - return setError(EGL_BAD_CONFIG, EGL_FALSE); + if (configs) { + // now we need to convert these client EGLConfig to our + // internal EGLConfig format. This is done in O(n log n). + for (int j=0 ; j( + dp->configs[i], 0, dp->numConfigs[i]-1, configs[j]); + if (index >= 0) { + if (configs) { + configs[j] = MAKE_CONFIG(i, index); + } + } else { + return setError(EGL_BAD_CONFIG, EGL_FALSE); + } } + configs += n; + config_size -= n; } - configs += n; - config_size -= n; *num_config += n; res = EGL_TRUE; } -- cgit v1.2.3-59-g8ed1b From 11d93f968ca515cd448ef51e4d8b79e3de561475 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn <> Date: Wed, 25 Mar 2009 15:32:28 -0700 Subject: Automated import from //branches/cupcake/...@142663,142663 --- libs/ui/EventHub.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/ui/EventHub.cpp b/libs/ui/EventHub.cpp index 3b29b094db..7c2fc8e54b 100644 --- a/libs/ui/EventHub.cpp +++ b/libs/ui/EventHub.cpp @@ -245,6 +245,7 @@ EventHub::device_t* EventHub::getDevice(int32_t deviceId) const int32_t id = deviceId & ID_MASK; if (id >= mNumDevicesById || id < 0) return NULL; device_t* dev = mDevicesById[id].device; + if (dev == NULL) return NULL; if (dev->id == deviceId) { return dev; } -- cgit v1.2.3-59-g8ed1b From 262453cecb32ba418c9001bc9cc33dcc4f306b64 Mon Sep 17 00:00:00 2001 From: Mathias Agopian <> Date: Wed, 25 Mar 2009 21:42:35 -0700 Subject: Automated import from //branches/cupcake/...@142856,142856 --- libs/surfaceflinger/Android.mk | 1 + libs/surfaceflinger/LayerOrientationAnim.cpp | 152 +++++++----- libs/surfaceflinger/LayerOrientationAnim.h | 49 +++- libs/surfaceflinger/LayerOrientationAnimRotate.cpp | 274 +++++++++++++++++++++ libs/surfaceflinger/LayerOrientationAnimRotate.h | 76 ++++++ libs/surfaceflinger/OrientationAnimation.cpp | 9 +- libs/surfaceflinger/OrientationAnimation.h | 2 +- libs/surfaceflinger/SurfaceFlinger.cpp | 3 +- libs/surfaceflinger/SurfaceFlinger.h | 2 + libs/surfaceflinger/Transform.cpp | 19 ++ libs/surfaceflinger/Transform.h | 4 +- 11 files changed, 514 insertions(+), 77 deletions(-) create mode 100644 libs/surfaceflinger/LayerOrientationAnimRotate.cpp create mode 100644 libs/surfaceflinger/LayerOrientationAnimRotate.h diff --git a/libs/surfaceflinger/Android.mk b/libs/surfaceflinger/Android.mk index 496e2717fb..22124361ab 100644 --- a/libs/surfaceflinger/Android.mk +++ b/libs/surfaceflinger/Android.mk @@ -16,6 +16,7 @@ LOCAL_SRC_FILES:= \ LayerBitmap.cpp \ LayerDim.cpp \ LayerOrientationAnim.cpp \ + LayerOrientationAnimRotate.cpp \ OrientationAnimation.cpp \ SurfaceFlinger.cpp \ Tokenizer.cpp \ diff --git a/libs/surfaceflinger/LayerOrientationAnim.cpp b/libs/surfaceflinger/LayerOrientationAnim.cpp index 2b72d7ce94..3e4035e9fc 100644 --- a/libs/surfaceflinger/LayerOrientationAnim.cpp +++ b/libs/surfaceflinger/LayerOrientationAnim.cpp @@ -22,11 +22,13 @@ #include #include +#include #include #include +#include "BlurFilter.h" #include "LayerBase.h" #include "LayerOrientationAnim.h" #include "SurfaceFlinger.h" @@ -41,22 +43,35 @@ const char* const LayerOrientationAnim::typeID = "LayerOrientationAnim"; // --------------------------------------------------------------------------- +// Animation... +const float DURATION = ms2ns(200); +const float BOUNCES_PER_SECOND = 0.5f; +//const float BOUNCES_AMPLITUDE = 1.0f/16.0f; +const float BOUNCES_AMPLITUDE = 0; +const float DIM_TARGET = 0.40f; +//#define INTERPOLATED_TIME(_t) ((_t)*(_t)) +#define INTERPOLATED_TIME(_t) (_t) + +// --------------------------------------------------------------------------- + LayerOrientationAnim::LayerOrientationAnim( SurfaceFlinger* flinger, DisplayID display, OrientationAnimation* anim, - const LayerBitmap& bitmap, - const LayerBitmap& bitmapIn) - : LayerBase(flinger, display), mAnim(anim), - mBitmap(bitmap), mBitmapIn(bitmapIn), + const LayerBitmap& bitmapIn, + const LayerBitmap& bitmapOut) + : LayerOrientationAnimBase(flinger, display), mAnim(anim), + mBitmapIn(bitmapIn), mBitmapOut(bitmapOut), mTextureName(-1), mTextureNameIn(-1) { + // blur that texture. mStartTime = systemTime(); mFinishTime = 0; mOrientationCompleted = false; mFirstRedraw = false; mLastNormalizedTime = 0; - mLastScale = 0; mNeedsBlending = false; + mAlphaInLerp.set(1.0f, DIM_TARGET); + mAlphaOutLerp.set(0.5f, 1.0f); } LayerOrientationAnim::~LayerOrientationAnim() @@ -111,14 +126,8 @@ void LayerOrientationAnim::onOrientationCompleted() 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; - const nsecs_t now = systemTime(); - float scale, alpha; + float alphaIn, alphaOut; if (mOrientationCompleted) { if (mFirstRedraw) { @@ -126,7 +135,7 @@ void LayerOrientationAnim::onDraw(const Region& clip) const // make a copy of what's on screen copybit_image_t image; - mBitmapIn.getBitmapSurface(&image); + mBitmapOut.getBitmapSurface(&image); const DisplayHardware& hw(graphicPlane(0).displayHardware()); hw.copyBackToImage(image); @@ -147,37 +156,40 @@ void LayerOrientationAnim::onDraw(const Region& clip) const const float duration = DURATION * mLastNormalizedTime; const float normalizedTime = (float(now - mFinishTime) / duration); if (normalizedTime <= 1.0f) { - const float squaredTime = normalizedTime*normalizedTime; - scale = (1.0f - mLastScale)*squaredTime + mLastScale; - alpha = (1.0f - normalizedTime); - alpha *= alpha; - alpha *= alpha; + const float interpolatedTime = INTERPOLATED_TIME(normalizedTime); + alphaIn = mAlphaInLerp.getOut(); + alphaOut = mAlphaOutLerp(interpolatedTime); } else { mAnim->onAnimationFinished(); - scale = 1.0f; - alpha = 0.0f; + alphaIn = mAlphaInLerp.getOut(); + alphaOut = mAlphaOutLerp.getOut(); } } 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; + const float interpolatedTime = INTERPOLATED_TIME(normalizedTime); + alphaIn = mAlphaInLerp(interpolatedTime); + alphaOut = 0.0f; } 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; + alphaIn = mAlphaInLerp.getOut(); + if (BOUNCES_AMPLITUDE > 0.0f) { + const float phi = BOUNCES_PER_SECOND * + (((normalizedTime - 1.0f) * to_seconds)*M_PI*2); + if (alphaIn > 1.0f) alphaIn = 1.0f; + else if (alphaIn < 0.0f) alphaIn = 0.0f; + alphaIn += BOUNCES_AMPLITUDE * (1.0f - cosf(phi)); + } + alphaOut = 0.0f; } - mLastScale = scale; + mAlphaOutLerp.setIn(alphaIn); } - drawScaled(scale, alpha); + drawScaled(1.0f, alphaIn, alphaOut); } -void LayerOrientationAnim::drawScaled(float f, float alpha) const +void LayerOrientationAnim::drawScaled(float scale, float alphaIn, float alphaOut) const { copybit_image_t dst; const GraphicPlane& plane(graphicPlane(0)); @@ -188,22 +200,30 @@ void LayerOrientationAnim::drawScaled(float f, float alpha) const // 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); + if (scale==1.0f && (alphaIn>=1.0f || alphaOut>=1.0f)) { + // we don't need to erase the screen in that case + } else { + 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; + copybit_image_t src; + mBitmapIn.getBitmapSurface(&src); + + copybit_image_t srcOut; + mBitmapOut.getBitmapSurface(&srcOut); + + const int w = dst.w*scale; + const int h = dst.h*scale; 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 }; - - copybit_image_t src; - mBitmap.getBitmapSurface(&src); const copybit_rect_t srect = { 0, 0, src.w, src.h }; + const Region reg(Rect( drect.l, drect.t, drect.r, drect.b )); int err = NO_ERROR; const int can_use_copybit = canUseCopybit(); @@ -211,19 +231,19 @@ void LayerOrientationAnim::drawScaled(float f, float alpha) const 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); + + if (alphaIn > 0) { + region_iterator it(reg); + copybit->set_parameter(copybit, COPYBIT_BLUR, COPYBIT_ENABLE); + copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, int(alphaIn*255)); + err = copybit->stretch(copybit, &dst, &src, &drect, &srect, &it); } - 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); + if (!err && alphaOut > 0.0f) { + region_iterator it(reg); + copybit->set_parameter(copybit, COPYBIT_BLUR, COPYBIT_DISABLE); + copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, int(alphaOut*255)); + err = copybit->stretch(copybit, &dst, &srcOut, &drect, &srect, &it); } LOGE_IF(err != NO_ERROR, "copybit failed (%s)", strerror(err)); } @@ -238,7 +258,7 @@ void LayerOrientationAnim::drawScaled(float f, float alpha) const t.data = (GGLubyte*)(intptr_t(src.base) + src.offset); Transform tr; - tr.set(f,0,0,f); + tr.set(scale,0,0,scale); tr.set(xc, yc); // FIXME: we should not access mVertices and mDrawingState like that, @@ -254,9 +274,7 @@ void LayerOrientationAnim::drawScaled(float f, float alpha) const self.mDrawingState.flags |= ISurfaceComposer::eLayerFilter; } - if (alpha < 1.0f) { - copybit_image_t src; - mBitmapIn.getBitmapSurface(&src); + if (alphaIn > 0.0f) { t.data = (GGLubyte*)(intptr_t(src.base) + src.offset); if (UNLIKELY(mTextureNameIn == -1LU)) { mTextureNameIn = createTexture(); @@ -264,21 +282,21 @@ void LayerOrientationAnim::drawScaled(float f, float alpha) const 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); + self.mDrawingState.alpha = int(alphaIn*255); + drawWithOpenGL(reg, mTextureNameIn, t); } - t.data = (GGLubyte*)(intptr_t(src.base) + src.offset); - 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); + if (alphaOut > 0.0f) { + t.data = (GGLubyte*)(intptr_t(srcOut.base) + srcOut.offset); + 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 = int(alphaOut*255); + drawWithOpenGL(reg, mTextureName, t); } - self.mDrawingState.alpha = int(alpha*255); - const Region clip(Rect( drect.l, drect.t, drect.r, drect.b )); - drawWithOpenGL(clip, mTextureName, t); } } diff --git a/libs/surfaceflinger/LayerOrientationAnim.h b/libs/surfaceflinger/LayerOrientationAnim.h index 73676859bc..365c6aeed4 100644 --- a/libs/surfaceflinger/LayerOrientationAnim.h +++ b/libs/surfaceflinger/LayerOrientationAnim.h @@ -30,7 +30,19 @@ namespace android { // --------------------------------------------------------------------------- class OrientationAnimation; -class LayerOrientationAnim : public LayerBase + +class LayerOrientationAnimBase : public LayerBase +{ +public: + LayerOrientationAnimBase(SurfaceFlinger* flinger, DisplayID display) + : LayerBase(flinger, display) { + } + virtual void onOrientationCompleted() = 0; +}; + +// --------------------------------------------------------------------------- + +class LayerOrientationAnim : public LayerOrientationAnimBase { public: static const uint32_t typeInfo; @@ -40,8 +52,8 @@ public: LayerOrientationAnim(SurfaceFlinger* flinger, DisplayID display, OrientationAnimation* anim, - const LayerBitmap& zoomOut, - const LayerBitmap& zoomIn); + const LayerBitmap& bitmapIn, + const LayerBitmap& bitmapOut); virtual ~LayerOrientationAnim(); void onOrientationCompleted(); @@ -52,20 +64,45 @@ public: virtual bool needsBlending() const; virtual bool isSecure() const { return false; } private: - void drawScaled(float scale, float alpha) const; + void drawScaled(float scale, float alphaIn, float alphaOut) const; + class Lerp { + float in; + float outMinusIn; + public: + Lerp() : in(0), outMinusIn(0) { } + Lerp(float in, float out) : in(in), outMinusIn(out-in) { } + float getIn() const { return in; }; + float getOut() const { return in + outMinusIn; } + void set(float in, float out) { + this->in = in; + this->outMinusIn = out-in; + } + void setIn(float in) { + this->in = in; + } + void setOut(float out) { + this->outMinusIn = out - this->in; + } + float operator()(float t) const { + return outMinusIn*t + in; + } + }; + OrientationAnimation* mAnim; - LayerBitmap mBitmap; LayerBitmap mBitmapIn; + LayerBitmap mBitmapOut; nsecs_t mStartTime; nsecs_t mFinishTime; bool mOrientationCompleted; mutable bool mFirstRedraw; mutable float mLastNormalizedTime; - mutable float mLastScale; mutable GLuint mTextureName; mutable GLuint mTextureNameIn; mutable bool mNeedsBlending; + + mutable Lerp mAlphaInLerp; + mutable Lerp mAlphaOutLerp; }; // --------------------------------------------------------------------------- diff --git a/libs/surfaceflinger/LayerOrientationAnimRotate.cpp b/libs/surfaceflinger/LayerOrientationAnimRotate.cpp new file mode 100644 index 0000000000..12d5d80141 --- /dev/null +++ b/libs/surfaceflinger/LayerOrientationAnimRotate.cpp @@ -0,0 +1,274 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "SurfaceFlinger" + +#include +#include +#include + +#include +#include + +#include + +#include + +#include "LayerBase.h" +#include "LayerOrientationAnim.h" +#include "LayerOrientationAnimRotate.h" +#include "SurfaceFlinger.h" +#include "DisplayHardware/DisplayHardware.h" +#include "OrientationAnimation.h" + +namespace android { +// --------------------------------------------------------------------------- + +const uint32_t LayerOrientationAnimRotate::typeInfo = LayerBase::typeInfo | 0x100; +const char* const LayerOrientationAnimRotate::typeID = "LayerOrientationAnimRotate"; + +// --------------------------------------------------------------------------- + +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 = 0.8; +const float BOUNCES_AMPLITUDE = (5.0f/180.f) * M_PI; + +LayerOrientationAnimRotate::LayerOrientationAnimRotate( + SurfaceFlinger* flinger, DisplayID display, + OrientationAnimation* anim, + const LayerBitmap& bitmap, + const LayerBitmap& bitmapIn) + : LayerOrientationAnimBase(flinger, display), mAnim(anim), + mBitmap(bitmap), mBitmapIn(bitmapIn), + mTextureName(-1), mTextureNameIn(-1) +{ + mStartTime = systemTime(); + mFinishTime = 0; + mOrientationCompleted = false; + mFirstRedraw = false; + mLastNormalizedTime = 0; + mLastAngle = 0; + mLastScale = 0; + mNeedsBlending = false; +} + +LayerOrientationAnimRotate::~LayerOrientationAnimRotate() +{ + if (mTextureName != -1U) { + LayerBase::deletedTextures.add(mTextureName); + } + if (mTextureNameIn != -1U) { + LayerBase::deletedTextures.add(mTextureNameIn); + } +} + +bool LayerOrientationAnimRotate::needsBlending() const +{ + return mNeedsBlending; +} + +Point LayerOrientationAnimRotate::getPhysicalSize() const +{ + const GraphicPlane& plane(graphicPlane(0)); + const DisplayHardware& hw(plane.displayHardware()); + return Point(hw.getWidth(), hw.getHeight()); +} + +void LayerOrientationAnimRotate::validateVisibility(const Transform&) +{ + const Layer::State& s(drawingState()); + const Transform tr(s.transform); + const Point size(getPhysicalSize()); + uint32_t w = size.x; + uint32_t h = size.y; + mTransformedBounds = tr.makeBounds(w, h); + mLeft = tr.tx(); + mTop = tr.ty(); + transparentRegionScreen.clear(); + mTransformed = true; + mCanUseCopyBit = false; +} + +void LayerOrientationAnimRotate::onOrientationCompleted() +{ + mFinishTime = systemTime(); + mOrientationCompleted = true; + mFirstRedraw = true; + mNeedsBlending = true; + mFlinger->invalidateLayerVisibility(this); +} + +void LayerOrientationAnimRotate::onDraw(const Region& clip) const +{ + // Animation... + + // 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 angle, scale, alpha; + + if (mOrientationCompleted) { + if (mFirstRedraw) { + // make a copy of what's on screen + copybit_image_t image; + mBitmapIn.getBitmapSurface(&image); + const DisplayHardware& hw(graphicPlane(0).displayHardware()); + hw.copyBackToImage(image); + + // FIXME: code below is gross + mFirstRedraw = false; + mNeedsBlending = false; + LayerOrientationAnimRotate* self(const_cast(this)); + mFlinger->invalidateLayerVisibility(self); + } + + // make sure pick-up where we left off + const float duration = DURATION * mLastNormalizedTime; + 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 = normalizedTime; + } else { + mAnim->onAnimationFinished(); + angle = ROTATION; + alpha = 1.0f; + scale = 1.0f; + } + } else { + const float normalizedTime = float(now - mStartTime) / DURATION; + if (normalizedTime <= 1.0f) { + mLastNormalizedTime = normalizedTime; + const float squaredTime = normalizedTime*normalizedTime; + angle = ROTATION * squaredTime; + scale = (TARGET_SCALE - 1.0f)*squaredTime + 1.0f; + alpha = 0; + } else { + mLastNormalizedTime = 1.0f; + angle = ROTATION; + if (BOUNCES_AMPLITUDE) { + const float to_seconds = DURATION / seconds(1); + const float phi = BOUNCES_PER_SECOND * + (((normalizedTime - 1.0f) * to_seconds)*M_PI*2); + angle += BOUNCES_AMPLITUDE * sinf(phi); + } + scale = TARGET_SCALE; + alpha = 0; + } + mLastAngle = angle; + mLastScale = scale; + } + drawScaled(angle, scale, alpha); +} + +void LayerOrientationAnimRotate::drawScaled(float f, float s, float alpha) const +{ + copybit_image_t dst; + const GraphicPlane& plane(graphicPlane(0)); + const DisplayHardware& hw(plane.displayHardware()); + hw.getDisplaySurface(&dst); + + // clear screen + // TODO: with update on demand, we may be able + // to not erase the screen at all during the animation + 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; + const int h = dst.h; + + copybit_image_t src; + mBitmap.getBitmapSurface(&src); + const copybit_rect_t srect = { 0, 0, src.w, src.h }; + + + 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); + + const int targetOrientation = plane.getOrientation(); + if (!targetOrientation) { + f = -f; + } + + 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. + LayerOrientationAnimRotate& self(const_cast(*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); + + 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 = int(alpha*255); + const Region clip(Rect( srect.l, srect.t, srect.r, srect.b )); + drawWithOpenGL(clip, mTextureNameIn, t); + } +} + +// --------------------------------------------------------------------------- + +}; // namespace android diff --git a/libs/surfaceflinger/LayerOrientationAnimRotate.h b/libs/surfaceflinger/LayerOrientationAnimRotate.h new file mode 100644 index 0000000000..5ca5780a2e --- /dev/null +++ b/libs/surfaceflinger/LayerOrientationAnimRotate.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_LAYER_ORIENTATION_ANIM_ROTATE_H +#define ANDROID_LAYER_ORIENTATION_ANIM_ROTATE_H + +#include +#include +#include +#include + +#include "LayerBase.h" +#include "LayerBitmap.h" + +namespace android { + +// --------------------------------------------------------------------------- +class OrientationAnimation; + +class LayerOrientationAnimRotate : public LayerOrientationAnimBase +{ +public: + static const uint32_t typeInfo; + static const char* const typeID; + virtual char const* getTypeID() const { return typeID; } + virtual uint32_t getTypeInfo() const { return typeInfo; } + + LayerOrientationAnimRotate(SurfaceFlinger* flinger, DisplayID display, + OrientationAnimation* anim, + const LayerBitmap& zoomOut, + const LayerBitmap& zoomIn); + virtual ~LayerOrientationAnimRotate(); + + void onOrientationCompleted(); + + virtual void onDraw(const Region& clip) const; + virtual Point getPhysicalSize() const; + virtual void validateVisibility(const Transform& globalTransform); + virtual bool needsBlending() const; + virtual bool isSecure() const { return false; } +private: + void drawScaled(float angle, float scale, float alpha) const; + + OrientationAnimation* mAnim; + LayerBitmap mBitmap; + LayerBitmap mBitmapIn; + nsecs_t mStartTime; + nsecs_t mFinishTime; + bool mOrientationCompleted; + mutable bool mFirstRedraw; + mutable float mLastNormalizedTime; + mutable float mLastAngle; + mutable float mLastScale; + mutable GLuint mTextureName; + mutable GLuint mTextureNameIn; + mutable bool mNeedsBlending; +}; + +// --------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_LAYER_ORIENTATION_ANIM_ROTATE_H diff --git a/libs/surfaceflinger/OrientationAnimation.cpp b/libs/surfaceflinger/OrientationAnimation.cpp index f6f1326b10..e59688e43a 100644 --- a/libs/surfaceflinger/OrientationAnimation.cpp +++ b/libs/surfaceflinger/OrientationAnimation.cpp @@ -21,6 +21,7 @@ #include #include "LayerOrientationAnim.h" +#include "LayerOrientationAnimRotate.h" #include "OrientationAnimation.h" #include "SurfaceFlinger.h" #include "VRamHeap.h" @@ -112,8 +113,14 @@ bool OrientationAnimation::prepare() bitmap.getBitmapSurface(&front); hw.copyFrontToImage(front); - LayerOrientationAnim* l = new LayerOrientationAnim( + LayerOrientationAnimBase* l; + + l = new LayerOrientationAnim( mFlinger.get(), 0, this, bitmap, bitmapIn); + + //l = new LayerOrientationAnimRotate( + // mFlinger.get(), 0, this, bitmap, bitmapIn); + l->initStates(w, h, 0); l->setLayer(INT_MAX-1); mFlinger->addLayer(l); diff --git a/libs/surfaceflinger/OrientationAnimation.h b/libs/surfaceflinger/OrientationAnimation.h index ba33fcedd4..b170dcb02a 100644 --- a/libs/surfaceflinger/OrientationAnimation.h +++ b/libs/surfaceflinger/OrientationAnimation.h @@ -62,7 +62,7 @@ private: sp mFlinger; sp mTemporaryDealer; - LayerOrientationAnim* mLayerOrientationAnim; + LayerOrientationAnimBase* mLayerOrientationAnim; int mState; }; diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp index d915a8424b..8499b67ac6 100644 --- a/libs/surfaceflinger/SurfaceFlinger.cpp +++ b/libs/surfaceflinger/SurfaceFlinger.cpp @@ -1804,6 +1804,7 @@ status_t GraphicPlane::setOrientation(int orientation) if (orientation == ISurfaceComposer::eOrientationDefault) { // make sure the default orientation is optimal mOrientationTransform.reset(); + mOrientation = orientation; mGlobalTransform = mTransform; return NO_ERROR; } @@ -1824,7 +1825,7 @@ status_t GraphicPlane::setOrientation(int orientation) 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 f7d77640ae..3c10481f90 100644 --- a/libs/surfaceflinger/SurfaceFlinger.h +++ b/libs/surfaceflinger/SurfaceFlinger.h @@ -122,6 +122,7 @@ public: 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 @@ private: Transform mTransform; Transform mOrientationTransform; Transform mGlobalTransform; + int mOrientation; }; // --------------------------------------------------------------------------- diff --git a/libs/surfaceflinger/Transform.cpp b/libs/surfaceflinger/Transform.cpp index bec7a64036..e8b0f45f81 100644 --- a/libs/surfaceflinger/Transform.cpp +++ b/libs/surfaceflinger/Transform.cpp @@ -103,6 +103,25 @@ void Transform::set( float xx, float xy, 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 0b4835effd..4c4528ecd4 100644 --- a/libs/surfaceflinger/Transform.h +++ b/libs/surfaceflinger/Transform.h @@ -60,7 +60,9 @@ public: 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; -- cgit v1.2.3-59-g8ed1b From ceff6e1874d760f4d5029b49b4da344b428555e5 Mon Sep 17 00:00:00 2001 From: Mathias Agopian <> Date: Wed, 25 Mar 2009 23:18:56 -0700 Subject: Automated import from //branches/cupcake/...@142873,142873 --- include/ui/ISurfaceComposer.h | 7 ++++++- include/ui/SurfaceComposerClient.h | 2 +- libs/surfaceflinger/OrientationAnimation.cpp | 31 ++++++++++++++-------------- libs/surfaceflinger/OrientationAnimation.h | 18 +++++++++++++--- libs/surfaceflinger/SurfaceFlinger.cpp | 9 +++++--- libs/surfaceflinger/SurfaceFlinger.h | 3 ++- libs/ui/ISurfaceComposer.cpp | 6 ++++-- libs/ui/SurfaceComposerClient.cpp | 5 +++-- 8 files changed, 52 insertions(+), 29 deletions(-) diff --git a/include/ui/ISurfaceComposer.h b/include/ui/ISurfaceComposer.h index f9eeb30e1b..5c64b222bc 100644 --- a/include/ui/ISurfaceComposer.h +++ b/include/ui/ISurfaceComposer.h @@ -81,6 +81,11 @@ public: eOrientation270 = 3, eOrientationSwapMask = 0x01 }; + + // flags for setOrientation + enum { + eOrientationAnimationDisable = 0x00000001 + }; /* create connection with surface flinger, requires * ACCESS_SURFACE_FLINGER permission @@ -100,7 +105,7 @@ public: virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags) = 0; /* Set display orientation. recquires ACCESS_SURFACE_FLINGER permission */ - virtual int setOrientation(DisplayID dpy, int orientation) = 0; + virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags) = 0; /* signal that we're done booting. * recquires ACCESS_SURFACE_FLINGER permission diff --git a/include/ui/SurfaceComposerClient.h b/include/ui/SurfaceComposerClient.h index 5d9222d851..76a3b554ba 100644 --- a/include/ui/SurfaceComposerClient.h +++ b/include/ui/SurfaceComposerClient.h @@ -97,7 +97,7 @@ public: static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0); //! Set the orientation of the given display - static int setOrientation(DisplayID dpy, int orientation); + static int setOrientation(DisplayID dpy, int orientation, uint32_t flags); // Query the number of displays static ssize_t getNumberOfDisplays(); diff --git a/libs/surfaceflinger/OrientationAnimation.cpp b/libs/surfaceflinger/OrientationAnimation.cpp index e59688e43a..70eec8d68e 100644 --- a/libs/surfaceflinger/OrientationAnimation.cpp +++ b/libs/surfaceflinger/OrientationAnimation.cpp @@ -44,10 +44,14 @@ OrientationAnimation::~OrientationAnimation() { } -void OrientationAnimation::onOrientationChanged() +void OrientationAnimation::onOrientationChanged(uint32_t type) { - if (mState == DONE) - mState = PREPARE; + if (mState == DONE) { + mType = type; + if (!(type & ISurfaceComposer::eOrientationAnimationDisable)) { + mState = PREPARE; + } + } } void OrientationAnimation::onAnimationFinished() @@ -82,14 +86,7 @@ bool OrientationAnimation::run_impl() bool OrientationAnimation::done() { - if (mFlinger->isFrozen()) { - // we are not allowed to draw, but pause a bit to make sure - // apps don't end up using the whole CPU, if they depend on - // surfaceflinger for synchronization. - usleep(8333); // 8.3ms ~ 120fps - return true; - } - return false; + return done_impl(); } bool OrientationAnimation::prepare() @@ -115,11 +112,13 @@ bool OrientationAnimation::prepare() LayerOrientationAnimBase* l; - l = new LayerOrientationAnim( - mFlinger.get(), 0, this, bitmap, bitmapIn); - - //l = new LayerOrientationAnimRotate( - // mFlinger.get(), 0, this, bitmap, bitmapIn); + if (mType & 0x80) { + l = new LayerOrientationAnimRotate( + mFlinger.get(), 0, this, bitmap, bitmapIn); + } else { + l = new LayerOrientationAnim( + mFlinger.get(), 0, this, bitmap, bitmapIn); + } l->initStates(w, h, 0); l->setLayer(INT_MAX-1); diff --git a/libs/surfaceflinger/OrientationAnimation.h b/libs/surfaceflinger/OrientationAnimation.h index b170dcb02a..cafa38d2e4 100644 --- a/libs/surfaceflinger/OrientationAnimation.h +++ b/libs/surfaceflinger/OrientationAnimation.h @@ -36,11 +36,11 @@ public: OrientationAnimation(const sp& flinger); virtual ~OrientationAnimation(); - void onOrientationChanged(); + void onOrientationChanged(uint32_t type); void onAnimationFinished(); inline bool run() { if (LIKELY(mState == DONE)) - return false; + return done_impl(); return run_impl(); } @@ -54,7 +54,18 @@ private: }; bool run_impl(); - bool done(); + inline bool done_impl() { + if (mFlinger->isFrozen()) { + // we are not allowed to draw, but pause a bit to make sure + // apps don't end up using the whole CPU, if they depend on + // surfaceflinger for synchronization. + usleep(8333); // 8.3ms ~ 120fps + return true; + } + return false; + } + + bool done(); bool prepare(); bool phase1(); bool phase2(); @@ -64,6 +75,7 @@ private: sp mTemporaryDealer; LayerOrientationAnimBase* mLayerOrientationAnim; int mState; + uint32_t mType; }; // --------------------------------------------------------------------------- diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp index 8499b67ac6..de64f55fbd 100644 --- a/libs/surfaceflinger/SurfaceFlinger.cpp +++ b/libs/surfaceflinger/SurfaceFlinger.cpp @@ -655,6 +655,7 @@ void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) const int dpy = 0; const int orientation = mCurrentState.orientation; + const uint32_t type = mCurrentState.orientationType; GraphicPlane& plane(graphicPlane(dpy)); plane.setOrientation(orientation); @@ -673,8 +674,8 @@ void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) mVisibleRegionsDirty = true; mDirtyRegion.set(hw.bounds()); - - mOrientationAnimation->onOrientationChanged(); + mFreezeDisplayTime = 0; + mOrientationAnimation->onOrientationChanged(type); } if (mCurrentState.freezeDisplay != mDrawingState.freezeDisplay) { @@ -1201,7 +1202,8 @@ status_t SurfaceFlinger::unfreezeDisplay(DisplayID dpy, uint32_t flags) return NO_ERROR; } -int SurfaceFlinger::setOrientation(DisplayID dpy, int orientation) +int SurfaceFlinger::setOrientation(DisplayID dpy, + int orientation, uint32_t flags) { if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) return BAD_VALUE; @@ -1209,6 +1211,7 @@ int SurfaceFlinger::setOrientation(DisplayID dpy, int orientation) Mutex::Autolock _l(mStateLock); if (mCurrentState.orientation != orientation) { if (uint32_t(orientation)<=eOrientation270 || orientation==42) { + mCurrentState.orientationType = flags; mCurrentState.orientation = orientation; setTransactionFlags(eTransactionNeeded); mTransactionCV.wait(mStateLock); diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/libs/surfaceflinger/SurfaceFlinger.h index 3c10481f90..e023182591 100644 --- a/libs/surfaceflinger/SurfaceFlinger.h +++ b/libs/surfaceflinger/SurfaceFlinger.h @@ -167,7 +167,7 @@ public: virtual void closeGlobalTransaction(); virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags); virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags); - virtual int setOrientation(DisplayID dpy, int orientation); + virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags); virtual void signal() const; virtual status_t requestGPU(const sp& callback, gpu_info_t* gpu); @@ -244,6 +244,7 @@ private: } LayerVector layersSortedByZ; uint8_t orientation; + uint8_t orientationType; uint8_t freezeDisplay; }; diff --git a/libs/ui/ISurfaceComposer.cpp b/libs/ui/ISurfaceComposer.cpp index 0fea6f9388..76597e1712 100644 --- a/libs/ui/ISurfaceComposer.cpp +++ b/libs/ui/ISurfaceComposer.cpp @@ -96,12 +96,13 @@ public: return reply.readInt32(); } - virtual int setOrientation(DisplayID dpy, int orientation) + virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags) { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); data.writeInt32(dpy); data.writeInt32(orientation); + data.writeInt32(flags); remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply); return reply.readInt32(); } @@ -184,7 +185,8 @@ status_t BnSurfaceComposer::onTransact( case SET_ORIENTATION: { DisplayID dpy = data.readInt32(); int orientation = data.readInt32(); - reply->writeInt32( setOrientation(dpy, orientation) ); + uint32_t flags = data.readInt32(); + reply->writeInt32( setOrientation(dpy, orientation, flags) ); } break; case FREEZE_DISPLAY: { DisplayID dpy = data.readInt32(); diff --git a/libs/ui/SurfaceComposerClient.cpp b/libs/ui/SurfaceComposerClient.cpp index 9354a7a40d..fe803ff249 100644 --- a/libs/ui/SurfaceComposerClient.cpp +++ b/libs/ui/SurfaceComposerClient.cpp @@ -813,10 +813,11 @@ status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags) return sm->unfreezeDisplay(dpy, flags); } -int SurfaceComposerClient::setOrientation(DisplayID dpy, int orientation) +int SurfaceComposerClient::setOrientation(DisplayID dpy, + int orientation, uint32_t flags) { const sp& sm(_get_surface_manager()); - return sm->setOrientation(dpy, orientation); + return sm->setOrientation(dpy, orientation, flags); } status_t SurfaceComposerClient::openTransaction() -- cgit v1.2.3-59-g8ed1b From 192f79fe71af21e6a877bd298b33be92bee6b353 Mon Sep 17 00:00:00 2001 From: Mathias Agopian <> Date: Wed, 25 Mar 2009 23:26:39 -0700 Subject: Automated import from //branches/cupcake/...@142875,142875 --- libs/surfaceflinger/LayerOrientationAnimRotate.cpp | 14 +++++++------- libs/surfaceflinger/LayerOrientationAnimRotate.h | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libs/surfaceflinger/LayerOrientationAnimRotate.cpp b/libs/surfaceflinger/LayerOrientationAnimRotate.cpp index 12d5d80141..89ffb19ffb 100644 --- a/libs/surfaceflinger/LayerOrientationAnimRotate.cpp +++ b/libs/surfaceflinger/LayerOrientationAnimRotate.cpp @@ -65,6 +65,8 @@ LayerOrientationAnimRotate::LayerOrientationAnimRotate( mLastAngle = 0; mLastScale = 0; mNeedsBlending = false; + const GraphicPlane& plane(graphicPlane(0)); + mOriginalTargetOrientation = plane.getOrientation(); } LayerOrientationAnimRotate::~LayerOrientationAnimRotate() @@ -117,10 +119,6 @@ void LayerOrientationAnimRotate::onDraw(const Region& clip) const { // Animation... - // 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 angle, scale, alpha; @@ -154,6 +152,9 @@ void LayerOrientationAnimRotate::onDraw(const Region& clip) const scale = 1.0f; } } else { + // FIXME: works only for portrait framebuffers + const Point size(getPhysicalSize()); + const float TARGET_SCALE = size.x * (1.0f / size.y); const float normalizedTime = float(now - mStartTime) / DURATION; if (normalizedTime <= 1.0f) { mLastNormalizedTime = normalizedTime; @@ -212,8 +213,7 @@ void LayerOrientationAnimRotate::drawScaled(float f, float s, float alpha) const t.format = src.format; t.data = (GGLubyte*)(intptr_t(src.base) + src.offset); - const int targetOrientation = plane.getOrientation(); - if (!targetOrientation) { + if (!mOriginalTargetOrientation) { f = -f; } @@ -246,7 +246,7 @@ void LayerOrientationAnimRotate::drawScaled(float f, float s, float alpha) const drawWithOpenGL(clip, mTextureName, t); if (alpha > 0) { - const float sign = (!targetOrientation) ? 1.0f : -1.0f; + const float sign = (!mOriginalTargetOrientation) ? 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); diff --git a/libs/surfaceflinger/LayerOrientationAnimRotate.h b/libs/surfaceflinger/LayerOrientationAnimRotate.h index 5ca5780a2e..5fbbd428d6 100644 --- a/libs/surfaceflinger/LayerOrientationAnimRotate.h +++ b/libs/surfaceflinger/LayerOrientationAnimRotate.h @@ -60,6 +60,7 @@ private: nsecs_t mStartTime; nsecs_t mFinishTime; bool mOrientationCompleted; + int mOriginalTargetOrientation; mutable bool mFirstRedraw; mutable float mLastNormalizedTime; mutable float mLastAngle; -- cgit v1.2.3-59-g8ed1b From b1596ee235b568d4c25313e2d335a1203953663b Mon Sep 17 00:00:00 2001 From: Eric Laurent <> Date: Thu, 26 Mar 2009 01:57:59 -0700 Subject: Automated import from //branches/cupcake/...@142889,142889 --- camera/libcameraservice/CameraService.cpp | 10 +++++++++- libs/audioflinger/AudioFlinger.cpp | 9 ++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index 7e5fdbe156..cb8ab58827 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -32,6 +32,8 @@ #include #include "CameraService.h" +#include + namespace android { extern "C" { @@ -157,7 +159,13 @@ static sp newMediaPlayer(const char *file) { sp mp = new MediaPlayer(); if (mp->setDataSource(file) == NO_ERROR) { - mp->setAudioStreamType(AudioSystem::ALARM); + char value[PROPERTY_VALUE_MAX]; + property_get("ro.camera.sound.forced", value, "0"); + if (atoi(value)) { + mp->setAudioStreamType(AudioSystem::ENFORCED_AUDIBLE); + } else { + mp->setAudioStreamType(AudioSystem::SYSTEM); + } mp->prepare(); } else { mp.clear(); diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp index 9ba7f90f95..b9ecdd8e41 100644 --- a/libs/audioflinger/AudioFlinger.cpp +++ b/libs/audioflinger/AudioFlinger.cpp @@ -243,7 +243,8 @@ bool AudioFlinger::streamForcedToSpeaker(int streamType) // AudioSystem::routedToA2dpOutput(streamType) == false return (streamType == AudioSystem::RING || streamType == AudioSystem::ALARM || - streamType == AudioSystem::NOTIFICATION); + streamType == AudioSystem::NOTIFICATION || + streamType == AudioSystem::ENFORCED_AUDIBLE); } status_t AudioFlinger::dumpClients(int fd, const Vector& args) @@ -645,7 +646,8 @@ status_t AudioFlinger::setStreamVolume(int stream, float value) return PERMISSION_DENIED; } - if (uint32_t(stream) >= AudioSystem::NUM_STREAM_TYPES) { + if (uint32_t(stream) >= AudioSystem::NUM_STREAM_TYPES || + uint32_t(stream) == AudioSystem::ENFORCED_AUDIBLE) { return BAD_VALUE; } @@ -680,7 +682,8 @@ status_t AudioFlinger::setStreamMute(int stream, bool muted) return PERMISSION_DENIED; } - if (uint32_t(stream) >= AudioSystem::NUM_STREAM_TYPES) { + if (uint32_t(stream) >= AudioSystem::NUM_STREAM_TYPES || + uint32_t(stream) == AudioSystem::ENFORCED_AUDIBLE) { return BAD_VALUE; } -- cgit v1.2.3-59-g8ed1b From 3c52588ca99742ad9c651b08b4def40bfd5b6aac Mon Sep 17 00:00:00 2001 From: Eric Laurent <> Date: Tue, 31 Mar 2009 09:38:57 -0700 Subject: AI 143620: Attempt for fixing crash in AudioFlinger::MixerThread::dumpTracks() seen in bug report for issue 1747119. AudioFlinger::MixerThread::dumpTracks() was reading mTracks[] vector instead of mActiveTracks[] when dumping active tracks. BUG=1747119 Automated import of CL 143620 --- libs/audioflinger/AudioFlinger.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp index b9ecdd8e41..d11e13a7fb 100644 --- a/libs/audioflinger/AudioFlinger.cpp +++ b/libs/audioflinger/AudioFlinger.cpp @@ -941,13 +941,10 @@ status_t AudioFlinger::MixerThread::dumpTracks(int fd, const Vector& a result.append(buffer); result.append(" Name Clien Typ Fmt Chn Buf S M F SRate LeftV RighV Serv User\n"); for (size_t i = 0; i < mTracks.size(); ++i) { - wp wTrack = mTracks[i]; - if (wTrack != 0) { - sp track = wTrack.promote(); - if (track != 0) { - track->dump(buffer, SIZE); - result.append(buffer); - } + sp track = mTracks[i]; + if (track != 0) { + track->dump(buffer, SIZE); + result.append(buffer); } } @@ -955,7 +952,7 @@ status_t AudioFlinger::MixerThread::dumpTracks(int fd, const Vector& a result.append(buffer); result.append(" Name Clien Typ Fmt Chn Buf S M F SRate LeftV RighV Serv User\n"); for (size_t i = 0; i < mActiveTracks.size(); ++i) { - wp wTrack = mTracks[i]; + wp wTrack = mActiveTracks[i]; if (wTrack != 0) { sp track = wTrack.promote(); if (track != 0) { -- cgit v1.2.3-59-g8ed1b From cb5883ecc50adf888a95d5c4f601b0dc1c1ec6ce Mon Sep 17 00:00:00 2001 From: Nick Pelly <> Date: Wed, 1 Apr 2009 16:40:01 -0700 Subject: AI 144150: Fix heap corruption. Take mutex in close(), and skip write path after turning bluetooth off. BUG=1751710 Automated import of CL 144150 --- libs/audioflinger/A2dpAudioInterface.cpp | 50 +++++++++++++++++++++++++------- libs/audioflinger/A2dpAudioInterface.h | 5 +++- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/libs/audioflinger/A2dpAudioInterface.cpp b/libs/audioflinger/A2dpAudioInterface.cpp index 2974e32ee1..b6d5078c44 100644 --- a/libs/audioflinger/A2dpAudioInterface.cpp +++ b/libs/audioflinger/A2dpAudioInterface.cpp @@ -92,16 +92,15 @@ status_t A2dpAudioInterface::getMicMute(bool* state) status_t A2dpAudioInterface::setParameter(const char *key, const char *value) { LOGD("setParameter %s,%s\n", key, value); - + if (!key || !value) return -EINVAL; - - if (strcmp(key, "a2dp_sink_address") == 0) { + + if (strcmp(key, "a2dp_sink_address") == 0) { return mOutput->setAddress(value); } - if (strcmp(key, "bluetooth_enabled") == 0 && - strcmp(value, "false") == 0) { - return mOutput->close(); + if (strcmp(key, "bluetooth_enabled") == 0) { + mOutput->setBluetoothEnabled(strcmp(value, "true") == 0); } return 0; @@ -130,7 +129,10 @@ status_t A2dpAudioInterface::dump(int fd, const Vector& args) // ---------------------------------------------------------------------------- A2dpAudioInterface::A2dpAudioStreamOut::A2dpAudioStreamOut() : - mFd(-1), mStandby(true), mStartCount(0), mRetryCount(0), mData(NULL) + mFd(-1), mStandby(true), mStartCount(0), mRetryCount(0), mData(NULL), + // assume BT enabled to start, this is safe because its only the + // enabled->disabled transition we are worried about + mBluetoothEnabled(true) { // use any address by default strcpy(mA2dpAddress, "00:00:00:00:00:00"); @@ -162,14 +164,21 @@ A2dpAudioInterface::A2dpAudioStreamOut::~A2dpAudioStreamOut() } ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t bytes) -{ +{ Mutex::Autolock lock(mLock); size_t remaining = bytes; - status_t status = init(); + status_t status = -1; + + if (!mBluetoothEnabled) { + LOGW("A2dpAudioStreamOut::write(), but bluetooth disabled"); + goto Error; + } + + status = init(); if (status < 0) goto Error; - + while (remaining > 0) { status = a2dp_write(mData, buffer, remaining); if (status <= 0) { @@ -181,7 +190,7 @@ ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t } mStandby = false; - + return bytes; Error: @@ -235,7 +244,26 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setAddress(const char* address) return NO_ERROR; } +status_t A2dpAudioInterface::A2dpAudioStreamOut::setBluetoothEnabled(bool enabled) +{ + LOGD("setBluetoothEnabled %d", enabled); + + Mutex::Autolock lock(mLock); + + mBluetoothEnabled = enabled; + if (!enabled) { + return close_l(); + } + return NO_ERROR; +} + status_t A2dpAudioInterface::A2dpAudioStreamOut::close() +{ + Mutex::Autolock lock(mLock); + return close_l(); +} + +status_t A2dpAudioInterface::A2dpAudioStreamOut::close_l() { if (mData) { a2dp_cleanup(mData); diff --git a/libs/audioflinger/A2dpAudioInterface.h b/libs/audioflinger/A2dpAudioInterface.h index 99614dc108..7901a8cca7 100644 --- a/libs/audioflinger/A2dpAudioInterface.h +++ b/libs/audioflinger/A2dpAudioInterface.h @@ -88,7 +88,9 @@ private: friend class A2dpAudioInterface; status_t init(); status_t close(); - status_t setAddress(const char* address); + status_t close_l(); + status_t setAddress(const char* address); + status_t setBluetoothEnabled(bool enabled); private: int mFd; @@ -98,6 +100,7 @@ private: char mA2dpAddress[20]; void* mData; Mutex mLock; + bool mBluetoothEnabled; }; A2dpAudioStreamOut* mOutput; -- cgit v1.2.3-59-g8ed1b From 490b2ba510c0857605f4913f0fdd1c47a1d93647 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn <> Date: Thu, 9 Apr 2009 12:31:13 -0700 Subject: AI 145382: API review: change new media keycode names to avoid ambiguity. Updates the key maps. During this I noticed that the dream keymap didn't have all of the media buttons like the sapphire key map...! So this is now changed to match. BUG=1779435 Automated import of CL 145382 --- include/ui/KeycodeLabels.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/ui/KeycodeLabels.h b/include/ui/KeycodeLabels.h index efa6d2bdd3..571e47b22d 100644 --- a/include/ui/KeycodeLabels.h +++ b/include/ui/KeycodeLabels.h @@ -107,12 +107,12 @@ static const KeycodeLabel KEYCODES[] = { { "MENU", 82 }, { "NOTIFICATION", 83 }, { "SEARCH", 84 }, - { "PLAYPAUSE", 85 }, - { "STOP", 86 }, - { "NEXTSONG", 87 }, - { "PREVIOUSSONG", 88 }, - { "REWIND", 89 }, - { "FORWARD", 90 }, + { "MEDIA_PLAY_PAUSE", 85 }, + { "MEDIA_STOP", 86 }, + { "MEDIA_NEXT", 87 }, + { "MEDIA_PREVIOUS", 88 }, + { "MEDIA_REWIND", 89 }, + { "MEDIA_FAST_FORWARD", 90 }, { "MUTE", 91 }, // NOTE: If you add a new keycode here you must also add it to: -- cgit v1.2.3-59-g8ed1b