| 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 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <stdint.h> | 
|  | 18 | #include <sys/types.h> | 
|  | 19 | #include <limits.h> | 
|  | 20 |  | 
|  | 21 | #include "LayerOrientationAnim.h" | 
| Mathias Agopian | 0d1318b | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 22 | #include "LayerOrientationAnimRotate.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include "OrientationAnimation.h" | 
|  | 24 | #include "SurfaceFlinger.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 |  | 
|  | 26 | #include "DisplayHardware/DisplayHardware.h" | 
|  | 27 |  | 
|  | 28 | namespace android { | 
|  | 29 |  | 
|  | 30 | // --------------------------------------------------------------------------- | 
|  | 31 |  | 
|  | 32 | OrientationAnimation::OrientationAnimation(const sp<SurfaceFlinger>& flinger) | 
|  | 33 | : mFlinger(flinger), mLayerOrientationAnim(NULL), mState(DONE) | 
|  | 34 | { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | } | 
|  | 36 |  | 
|  | 37 | OrientationAnimation::~OrientationAnimation() | 
|  | 38 | { | 
|  | 39 | } | 
|  | 40 |  | 
| Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 41 | void OrientationAnimation::onOrientationChanged(uint32_t type) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | { | 
| Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 43 | if (mState == DONE) { | 
|  | 44 | mType = type; | 
|  | 45 | if (!(type & ISurfaceComposer::eOrientationAnimationDisable)) { | 
|  | 46 | mState = PREPARE; | 
|  | 47 | } | 
|  | 48 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | } | 
|  | 50 |  | 
|  | 51 | void OrientationAnimation::onAnimationFinished() | 
|  | 52 | { | 
|  | 53 | if (mState != DONE) | 
|  | 54 | mState = FINISH; | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | bool 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 |  | 
|  | 81 | bool OrientationAnimation::done() | 
|  | 82 | { | 
| Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 83 | return done_impl(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | } | 
|  | 85 |  | 
|  | 86 | bool 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 Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 95 | sp<Buffer> bitmap = new Buffer(w, h, hw.getFormat()); | 
|  | 96 | sp<Buffer> bitmapIn = new Buffer(w, h, hw.getFormat()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 |  | 
|  | 98 | copybit_image_t front; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 99 | bitmap->getBitmapSurface(&front); | 
|  | 100 | hw.copyFrontToImage(front); // FIXME: we need an extension to do this | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 102 | sp<LayerOrientationAnimBase> l; | 
| Mathias Agopian | 0d1318b | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 103 |  | 
| Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 104 | 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 Agopian | 0d1318b | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 111 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | l->initStates(w, h, 0); | 
|  | 113 | l->setLayer(INT_MAX-1); | 
|  | 114 | mFlinger->addLayer(l); | 
|  | 115 | mLayerOrientationAnim = l; | 
|  | 116 | return true; | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | bool 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 |  | 
|  | 133 | bool OrientationAnimation::phase2() | 
|  | 134 | { | 
|  | 135 | // do the 2nd phase of the animation | 
|  | 136 | mLayerOrientationAnim->invalidate(); | 
|  | 137 | return false; | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | bool OrientationAnimation::finished() | 
|  | 141 | { | 
|  | 142 | mState = DONE; | 
|  | 143 | mFlinger->removeLayer(mLayerOrientationAnim); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 144 | mLayerOrientationAnim.clear(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | return true; | 
|  | 146 | } | 
|  | 147 |  | 
|  | 148 | // --------------------------------------------------------------------------- | 
|  | 149 |  | 
|  | 150 | }; // namespace android |