blob: a6c9c28d0ba8be869260fec0df19fd1098694e08 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080017#include <stdint.h>
18#include <sys/types.h>
19#include <limits.h>
20
21#include "LayerOrientationAnim.h"
Mathias Agopian0d1318b2009-03-27 17:58:20 -070022#include "LayerOrientationAnimRotate.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include "OrientationAnimation.h"
24#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025
26#include "DisplayHardware/DisplayHardware.h"
27
28namespace android {
29
30// ---------------------------------------------------------------------------
31
32OrientationAnimation::OrientationAnimation(const sp<SurfaceFlinger>& flinger)
33 : mFlinger(flinger), mLayerOrientationAnim(NULL), mState(DONE)
34{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035}
36
37OrientationAnimation::~OrientationAnimation()
38{
39}
40
Mathias Agopianc08731e2009-03-27 18:11:38 -070041void OrientationAnimation::onOrientationChanged(uint32_t type)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042{
Mathias Agopianc08731e2009-03-27 18:11:38 -070043 if (mState == DONE) {
44 mType = type;
45 if (!(type & ISurfaceComposer::eOrientationAnimationDisable)) {
46 mState = PREPARE;
47 }
48 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049}
50
51void OrientationAnimation::onAnimationFinished()
52{
53 if (mState != DONE)
54 mState = FINISH;
55}
56
57bool OrientationAnimation::run_impl()
58{
59 bool skip_frame;
60 switch (mState) {
61 default:
62 case DONE:
63 skip_frame = done();
64 break;
65 case PREPARE:
66 skip_frame = prepare();
67 break;
68 case PHASE1:
69 skip_frame = phase1();
70 break;
71 case PHASE2:
72 skip_frame = phase2();
73 break;
74 case FINISH:
75 skip_frame = finished();
76 break;
77 }
78 return skip_frame;
79}
80
81bool OrientationAnimation::done()
82{
Mathias Agopianc08731e2009-03-27 18:11:38 -070083 return done_impl();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084}
85
86bool OrientationAnimation::prepare()
87{
88 mState = PHASE1;
89
90 const GraphicPlane& plane(mFlinger->graphicPlane(0));
91 const DisplayHardware& hw(plane.displayHardware());
92 const uint32_t w = hw.getWidth();
93 const uint32_t h = hw.getHeight();
94
Mathias Agopian076b1cc2009-04-10 14:24:30 -070095 sp<Buffer> bitmap = new Buffer(w, h, hw.getFormat());
96 sp<Buffer> bitmapIn = new Buffer(w, h, hw.getFormat());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097
98 copybit_image_t front;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070099 bitmap->getBitmapSurface(&front);
100 hw.copyFrontToImage(front); // FIXME: we need an extension to do this
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700102 sp<LayerOrientationAnimBase> l;
Mathias Agopian0d1318b2009-03-27 17:58:20 -0700103
Mathias Agopianc08731e2009-03-27 18:11:38 -0700104 if (mType & 0x80) {
105 l = new LayerOrientationAnimRotate(
106 mFlinger.get(), 0, this, bitmap, bitmapIn);
107 } else {
108 l = new LayerOrientationAnim(
109 mFlinger.get(), 0, this, bitmap, bitmapIn);
110 }
Mathias Agopian0d1318b2009-03-27 17:58:20 -0700111
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112 l->initStates(w, h, 0);
113 l->setLayer(INT_MAX-1);
114 mFlinger->addLayer(l);
115 mLayerOrientationAnim = l;
116 return true;
117}
118
119bool OrientationAnimation::phase1()
120{
121 if (mFlinger->isFrozen() == false) {
122 // start phase 2
123 mState = PHASE2;
124 mLayerOrientationAnim->onOrientationCompleted();
125 mLayerOrientationAnim->invalidate();
126 return true;
127
128 }
129 mLayerOrientationAnim->invalidate();
130 return false;
131}
132
133bool OrientationAnimation::phase2()
134{
135 // do the 2nd phase of the animation
136 mLayerOrientationAnim->invalidate();
137 return false;
138}
139
140bool OrientationAnimation::finished()
141{
142 mState = DONE;
143 mFlinger->removeLayer(mLayerOrientationAnim);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700144 mLayerOrientationAnim.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145 return true;
146}
147
148// ---------------------------------------------------------------------------
149
150}; // namespace android