blob: 8ba66210e873a3f8fe96730d2d7301f9ce2fe138 [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
17#ifndef ANDROID_ORIENTATION_ANIMATION_H
18#define ANDROID_ORIENTATION_ANIMATION_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include "SurfaceFlinger.h"
24
25namespace android {
26
27// ---------------------------------------------------------------------------
28
29class SurfaceFlinger;
30class MemoryDealer;
31class LayerOrientationAnim;
32
33class OrientationAnimation
34{
35public:
36 OrientationAnimation(const sp<SurfaceFlinger>& flinger);
37 virtual ~OrientationAnimation();
38
Mathias Agopianc08731e2009-03-27 18:11:38 -070039 void onOrientationChanged(uint32_t type);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040 void onAnimationFinished();
41 inline bool run() {
42 if (LIKELY(mState == DONE))
Mathias Agopianc08731e2009-03-27 18:11:38 -070043 return done_impl();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044 return run_impl();
45 }
46
47private:
48 enum {
49 DONE = 0,
50 PREPARE,
51 PHASE1,
52 PHASE2,
53 FINISH
54 };
55
56 bool run_impl();
Mathias Agopianc08731e2009-03-27 18:11:38 -070057 inline bool done_impl() {
58 if (mFlinger->isFrozen()) {
59 // we are not allowed to draw, but pause a bit to make sure
60 // apps don't end up using the whole CPU, if they depend on
61 // surfaceflinger for synchronization.
62 usleep(8333); // 8.3ms ~ 120fps
63 return true;
64 }
65 return false;
66 }
67
68 bool done();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 bool prepare();
70 bool phase1();
71 bool phase2();
72 bool finished();
73
74 sp<SurfaceFlinger> mFlinger;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070075 sp< LayerOrientationAnimBase > mLayerOrientationAnim;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076 int mState;
Mathias Agopianc08731e2009-03-27 18:11:38 -070077 uint32_t mType;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078};
79
80// ---------------------------------------------------------------------------
81
82}; // namespace android
83
84#endif // ANDROID_ORIENTATION_ANIMATION_H