Automated import from //branches/donutburger/...@142446,142446
This commit is contained in:
committed by
The Android Open Source Project
parent
00f5eca412
commit
2764f30a74
@@ -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<LayerOrientationAnim*>(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);
|
||||
|
||||
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 (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);
|
||||
}
|
||||
|
||||
const int targetOrientation = plane.getOrientation();
|
||||
if (!targetOrientation) {
|
||||
f = -f;
|
||||
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);
|
||||
|
||||
Transform tr;
|
||||
tr.set(f, w*0.5f, h*0.5f);
|
||||
tr.scale(s, w*0.5f, h*0.5f);
|
||||
|
||||
// FIXME: we should not access mVertices and mDrawingState like that,
|
||||
// but since we control the animation, we know it's going to work okay.
|
||||
// eventually we'd need a more formal way of doing things like this.
|
||||
LayerOrientationAnim& self(const_cast<LayerOrientationAnim&>(*this));
|
||||
tr.transform(self.mVertices[0], 0, 0);
|
||||
tr.transform(self.mVertices[1], 0, src.h);
|
||||
tr.transform(self.mVertices[2], src.w, src.h);
|
||||
tr.transform(self.mVertices[3], src.w, 0);
|
||||
|
||||
if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
|
||||
// Too slow to do this in software
|
||||
self.mDrawingState.flags |= ISurfaceComposer::eLayerFilter;
|
||||
}
|
||||
|
||||
if (UNLIKELY(mTextureName == -1LU)) {
|
||||
mTextureName = createTexture();
|
||||
GLuint w=0, h=0;
|
||||
const Region dirty(Rect(t.width, t.height));
|
||||
loadTexture(dirty, mTextureName, t, w, h);
|
||||
}
|
||||
self.mDrawingState.alpha = 255; //-int(alpha*255);
|
||||
const Region clip(Rect( srect.l, srect.t, srect.r, srect.b ));
|
||||
drawWithOpenGL(clip, mTextureName, t);
|
||||
|
||||
if (alpha > 0) {
|
||||
const float sign = (!targetOrientation) ? 1.0f : -1.0f;
|
||||
tr.set(f + sign*(M_PI * 0.5f * ROTATION_FACTOR), w*0.5f, h*0.5f);
|
||||
tr.scale(s, w*0.5f, h*0.5f);
|
||||
Transform tr;
|
||||
tr.set(f,0,0,f);
|
||||
tr.set(xc, yc);
|
||||
|
||||
// FIXME: we should not access mVertices and mDrawingState like that,
|
||||
// but since we control the animation, we know it's going to work okay.
|
||||
// eventually we'd need a more formal way of doing things like this.
|
||||
LayerOrientationAnim& self(const_cast<LayerOrientationAnim&>(*this));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user