blob: f6f1326b1003b07ce59514de08ddfd02f10586ba [file] [log] [blame]
The Android Open Source Project9066cfe2009-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
17#define LOG_TAG "SurfaceFlinger"
18
19#include <stdint.h>
20#include <sys/types.h>
21#include <limits.h>
22
23#include "LayerOrientationAnim.h"
24#include "OrientationAnimation.h"
25#include "SurfaceFlinger.h"
26#include "VRamHeap.h"
27
28#include "DisplayHardware/DisplayHardware.h"
29
30namespace android {
31
32// ---------------------------------------------------------------------------
33
34OrientationAnimation::OrientationAnimation(const sp<SurfaceFlinger>& flinger)
35 : mFlinger(flinger), mLayerOrientationAnim(NULL), mState(DONE)
36{
37 // allocate a memory-dealer for this the first time
38 mTemporaryDealer = mFlinger->getSurfaceHeapManager()->createHeap(
39 ISurfaceComposer::eHardware);
40}
41
42OrientationAnimation::~OrientationAnimation()
43{
44}
45
46void OrientationAnimation::onOrientationChanged()
47{
48 if (mState == DONE)
49 mState = PREPARE;
50}
51
52void OrientationAnimation::onAnimationFinished()
53{
54 if (mState != DONE)
55 mState = FINISH;
56}
57
58bool OrientationAnimation::run_impl()
59{
60 bool skip_frame;
61 switch (mState) {
62 default:
63 case DONE:
64 skip_frame = done();
65 break;
66 case PREPARE:
67 skip_frame = prepare();
68 break;
69 case PHASE1:
70 skip_frame = phase1();
71 break;
72 case PHASE2:
73 skip_frame = phase2();
74 break;
75 case FINISH:
76 skip_frame = finished();
77 break;
78 }
79 return skip_frame;
80}
81
82bool OrientationAnimation::done()
83{
84 if (mFlinger->isFrozen()) {
85 // we are not allowed to draw, but pause a bit to make sure
86 // apps don't end up using the whole CPU, if they depend on
87 // surfaceflinger for synchronization.
88 usleep(8333); // 8.3ms ~ 120fps
89 return true;
90 }
91 return false;
92}
93
94bool OrientationAnimation::prepare()
95{
96 mState = PHASE1;
97
98 const GraphicPlane& plane(mFlinger->graphicPlane(0));
99 const DisplayHardware& hw(plane.displayHardware());
100 const uint32_t w = hw.getWidth();
101 const uint32_t h = hw.getHeight();
102
103 LayerBitmap bitmap;
104 bitmap.init(mTemporaryDealer);
105 bitmap.setBits(w, h, 1, hw.getFormat());
106
107 LayerBitmap bitmapIn;
108 bitmapIn.init(mTemporaryDealer);
109 bitmapIn.setBits(w, h, 1, hw.getFormat());
110
111 copybit_image_t front;
112 bitmap.getBitmapSurface(&front);
113 hw.copyFrontToImage(front);
114
115 LayerOrientationAnim* l = new LayerOrientationAnim(
116 mFlinger.get(), 0, this, bitmap, bitmapIn);
117 l->initStates(w, h, 0);
118 l->setLayer(INT_MAX-1);
119 mFlinger->addLayer(l);
120 mLayerOrientationAnim = l;
121 return true;
122}
123
124bool OrientationAnimation::phase1()
125{
126 if (mFlinger->isFrozen() == false) {
127 // start phase 2
128 mState = PHASE2;
129 mLayerOrientationAnim->onOrientationCompleted();
130 mLayerOrientationAnim->invalidate();
131 return true;
132
133 }
134 mLayerOrientationAnim->invalidate();
135 return false;
136}
137
138bool OrientationAnimation::phase2()
139{
140 // do the 2nd phase of the animation
141 mLayerOrientationAnim->invalidate();
142 return false;
143}
144
145bool OrientationAnimation::finished()
146{
147 mState = DONE;
148 mFlinger->removeLayer(mLayerOrientationAnim);
149 mLayerOrientationAnim = NULL;
150 return true;
151}
152
153// ---------------------------------------------------------------------------
154
155}; // namespace android