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