From 4cf7abeed2c748314327462986e452fc1ccc6e99 Mon Sep 17 00:00:00 2001 From: Mathias Agopian <> Date: Tue, 24 Mar 2009 20:25:29 -0700 Subject: [PATCH] Automated import from //branches/donutburger/...@141502,141502 --- 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, 113 insertions(+), 105 deletions(-) diff --git a/libs/surfaceflinger/LayerOrientationAnim.cpp b/libs/surfaceflinger/LayerOrientationAnim.cpp index 2b72d7ce9487..5fec325b807f 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 73676859bc03..b527c7e59519 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 d915a8424b6d..8499b67ac656 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 f7d77640ae3c..3c10481f90c5 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 bec7a64036e5..e8b0f45f811b 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 0b4835effd3a..4c4528ecd4bd 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; -- 2.11.0