The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | namespace android { |
| 26 | |
| 27 | // --------------------------------------------------------------------------- |
| 28 | |
| 29 | class SurfaceFlinger; |
| 30 | class MemoryDealer; |
| 31 | class LayerOrientationAnim; |
| 32 | |
| 33 | class OrientationAnimation |
| 34 | { |
| 35 | public: |
| 36 | OrientationAnimation(const sp<SurfaceFlinger>& flinger); |
| 37 | virtual ~OrientationAnimation(); |
| 38 | |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 39 | void onOrientationChanged(uint32_t type); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | void onAnimationFinished(); |
| 41 | inline bool run() { |
| 42 | if (LIKELY(mState == DONE)) |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 43 | return done_impl(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | return run_impl(); |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | enum { |
| 49 | DONE = 0, |
| 50 | PREPARE, |
| 51 | PHASE1, |
| 52 | PHASE2, |
| 53 | FINISH |
| 54 | }; |
| 55 | |
| 56 | bool run_impl(); |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 57 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | bool prepare(); |
| 70 | bool phase1(); |
| 71 | bool phase2(); |
| 72 | bool finished(); |
| 73 | |
| 74 | sp<SurfaceFlinger> mFlinger; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame^] | 75 | sp< LayerOrientationAnimBase > mLayerOrientationAnim; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | int mState; |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 77 | uint32_t mType; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | // --------------------------------------------------------------------------- |
| 81 | |
| 82 | }; // namespace android |
| 83 | |
| 84 | #endif // ANDROID_ORIENTATION_ANIMATION_H |