blob: 70eec8d68e1fec0ccb5556925c5dcee342e73323 [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#define LOG_TAG "SurfaceFlinger"
18
19#include <stdint.h>
20#include <sys/types.h>
21#include <limits.h>
22
23#include "LayerOrientationAnim.h"
Mathias Agopian0d1318b2009-03-27 17:58:20 -070024#include "LayerOrientationAnimRotate.h"
The Android Open Source Projectedbf3b62009-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
Mathias Agopianc08731e2009-03-27 18:11:38 -070047void OrientationAnimation::onOrientationChanged(uint32_t type)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048{
Mathias Agopianc08731e2009-03-27 18:11:38 -070049 if (mState == DONE) {
50 mType = type;
51 if (!(type & ISurfaceComposer::eOrientationAnimationDisable)) {
52 mState = PREPARE;
53 }
54 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055}
56
57void OrientationAnimation::onAnimationFinished()
58{
59 if (mState != DONE)
60 mState = FINISH;
61}
62
63bool 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
87bool OrientationAnimation::done()
88{
Mathias Agopianc08731e2009-03-27 18:11:38 -070089 return done_impl();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090}
91
92bool 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 Agopian0d1318b2009-03-27 17:58:20 -0700113 LayerOrientationAnimBase* l;
114
Mathias Agopianc08731e2009-03-27 18:11:38 -0700115 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 Agopian0d1318b2009-03-27 17:58:20 -0700122
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123 l->initStates(w, h, 0);
124 l->setLayer(INT_MAX-1);
125 mFlinger->addLayer(l);
126 mLayerOrientationAnim = l;
127 return true;
128}
129
130bool 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
144bool OrientationAnimation::phase2()
145{
146 // do the 2nd phase of the animation
147 mLayerOrientationAnim->invalidate();
148 return false;
149}
150
151bool OrientationAnimation::finished()
152{
153 mState = DONE;
154 mFlinger->removeLayer(mLayerOrientationAnim);
155 mLayerOrientationAnim = NULL;
156 return true;
157}
158
159// ---------------------------------------------------------------------------
160
161}; // namespace android