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 | #define LOG_TAG "SurfaceFlinger" |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <limits.h> |
| 22 | |
| 23 | #include "LayerOrientationAnim.h" |
Mathias Agopian | 0d1318b | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 24 | #include "LayerOrientationAnimRotate.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include "OrientationAnimation.h" |
| 26 | #include "SurfaceFlinger.h" |
| 27 | #include "VRamHeap.h" |
| 28 | |
| 29 | #include "DisplayHardware/DisplayHardware.h" |
| 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | // --------------------------------------------------------------------------- |
| 34 | |
| 35 | OrientationAnimation::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 | |
| 43 | OrientationAnimation::~OrientationAnimation() |
| 44 | { |
| 45 | } |
| 46 | |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 47 | void OrientationAnimation::onOrientationChanged(uint32_t type) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | { |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 49 | if (mState == DONE) { |
| 50 | mType = type; |
| 51 | if (!(type & ISurfaceComposer::eOrientationAnimationDisable)) { |
| 52 | mState = PREPARE; |
| 53 | } |
| 54 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void OrientationAnimation::onAnimationFinished() |
| 58 | { |
| 59 | if (mState != DONE) |
| 60 | mState = FINISH; |
| 61 | } |
| 62 | |
| 63 | bool OrientationAnimation::run_impl() |
| 64 | { |
| 65 | bool skip_frame; |
| 66 | switch (mState) { |
| 67 | default: |
| 68 | case DONE: |
| 69 | skip_frame = done(); |
| 70 | break; |
| 71 | case PREPARE: |
| 72 | skip_frame = prepare(); |
| 73 | break; |
| 74 | case PHASE1: |
| 75 | skip_frame = phase1(); |
| 76 | break; |
| 77 | case PHASE2: |
| 78 | skip_frame = phase2(); |
| 79 | break; |
| 80 | case FINISH: |
| 81 | skip_frame = finished(); |
| 82 | break; |
| 83 | } |
| 84 | return skip_frame; |
| 85 | } |
| 86 | |
| 87 | bool OrientationAnimation::done() |
| 88 | { |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 89 | return done_impl(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | bool OrientationAnimation::prepare() |
| 93 | { |
| 94 | mState = PHASE1; |
| 95 | |
| 96 | const GraphicPlane& plane(mFlinger->graphicPlane(0)); |
| 97 | const DisplayHardware& hw(plane.displayHardware()); |
| 98 | const uint32_t w = hw.getWidth(); |
| 99 | const uint32_t h = hw.getHeight(); |
| 100 | |
| 101 | LayerBitmap bitmap; |
| 102 | bitmap.init(mTemporaryDealer); |
| 103 | bitmap.setBits(w, h, 1, hw.getFormat()); |
| 104 | |
| 105 | LayerBitmap bitmapIn; |
| 106 | bitmapIn.init(mTemporaryDealer); |
| 107 | bitmapIn.setBits(w, h, 1, hw.getFormat()); |
| 108 | |
| 109 | copybit_image_t front; |
| 110 | bitmap.getBitmapSurface(&front); |
| 111 | hw.copyFrontToImage(front); |
| 112 | |
Mathias Agopian | 0d1318b | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 113 | LayerOrientationAnimBase* l; |
| 114 | |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 115 | if (mType & 0x80) { |
| 116 | l = new LayerOrientationAnimRotate( |
| 117 | mFlinger.get(), 0, this, bitmap, bitmapIn); |
| 118 | } else { |
| 119 | l = new LayerOrientationAnim( |
| 120 | mFlinger.get(), 0, this, bitmap, bitmapIn); |
| 121 | } |
Mathias Agopian | 0d1318b | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 122 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | l->initStates(w, h, 0); |
| 124 | l->setLayer(INT_MAX-1); |
| 125 | mFlinger->addLayer(l); |
| 126 | mLayerOrientationAnim = l; |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | bool OrientationAnimation::phase1() |
| 131 | { |
| 132 | if (mFlinger->isFrozen() == false) { |
| 133 | // start phase 2 |
| 134 | mState = PHASE2; |
| 135 | mLayerOrientationAnim->onOrientationCompleted(); |
| 136 | mLayerOrientationAnim->invalidate(); |
| 137 | return true; |
| 138 | |
| 139 | } |
| 140 | mLayerOrientationAnim->invalidate(); |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | bool OrientationAnimation::phase2() |
| 145 | { |
| 146 | // do the 2nd phase of the animation |
| 147 | mLayerOrientationAnim->invalidate(); |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | bool OrientationAnimation::finished() |
| 152 | { |
| 153 | mState = DONE; |
| 154 | mFlinger->removeLayer(mLayerOrientationAnim); |
| 155 | mLayerOrientationAnim = NULL; |
| 156 | return true; |
| 157 | } |
| 158 | |
| 159 | // --------------------------------------------------------------------------- |
| 160 | |
| 161 | }; // namespace android |