blob: 12c0eefe83bb8487d98e374139cefb28544ce61e [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"
24#include "OrientationAnimation.h"
25#include "SurfaceFlinger.h"
26#include "VRamHeap.h"
27
28#include "DisplayHardware/DisplayHardware.h"
29
30namespace android {
31
32// ---------------------------------------------------------------------------
33
34OrientationAnimation::OrientationAnimation(const sp<SurfaceFlinger>& flinger)
35 : mFlinger(flinger), mLayerOrientationAnim(NULL), mState(DONE)
36{
37 // allocate a memory-dealer for this the first time
38 mTemporaryDealer = mFlinger->getSurfaceHeapManager()->createHeap(
39 ISurfaceComposer::eHardware);
40}
41
42OrientationAnimation::~OrientationAnimation()
43{
44}
45
Mathias Agopianceff6e12009-03-25 23:18:56 -070046void OrientationAnimation::onOrientationChanged(uint32_t type)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047{
Mathias Agopianceff6e12009-03-25 23:18:56 -070048 if (mState == DONE) {
49 mType = type;
50 if (!(type & ISurfaceComposer::eOrientationAnimationDisable)) {
51 mState = PREPARE;
52 }
53 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054}
55
56void OrientationAnimation::onAnimationFinished()
57{
58 if (mState != DONE)
59 mState = FINISH;
60}
61
62bool OrientationAnimation::run_impl()
63{
64 bool skip_frame;
65 switch (mState) {
66 default:
67 case DONE:
68 skip_frame = done();
69 break;
70 case PREPARE:
71 skip_frame = prepare();
72 break;
73 case PHASE1:
74 skip_frame = phase1();
75 break;
76 case PHASE2:
77 skip_frame = phase2();
78 break;
79 case FINISH:
80 skip_frame = finished();
81 break;
82 }
83 return skip_frame;
84}
85
86bool OrientationAnimation::done()
87{
Mathias Agopianceff6e12009-03-25 23:18:56 -070088 return done_impl();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089}
90
91bool OrientationAnimation::prepare()
92{
93 mState = PHASE1;
94
95 const GraphicPlane& plane(mFlinger->graphicPlane(0));
96 const DisplayHardware& hw(plane.displayHardware());
97 const uint32_t w = hw.getWidth();
98 const uint32_t h = hw.getHeight();
99
100 LayerBitmap bitmap;
101 bitmap.init(mTemporaryDealer);
102 bitmap.setBits(w, h, 1, hw.getFormat());
103
104 LayerBitmap bitmapIn;
105 bitmapIn.init(mTemporaryDealer);
106 bitmapIn.setBits(w, h, 1, hw.getFormat());
107
108 copybit_image_t front;
109 bitmap.getBitmapSurface(&front);
110 hw.copyFrontToImage(front);
111
Mathias Agopian262453c2009-03-25 21:42:35 -0700112 LayerOrientationAnimBase* l;
113
Jean-Baptiste Queru02f54242009-07-29 14:25:07 -0700114 l = new LayerOrientationAnim(
115 mFlinger.get(), 0, this, bitmap, bitmapIn);
Mathias Agopian262453c2009-03-25 21:42:35 -0700116
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117 l->initStates(w, h, 0);
118 l->setLayer(INT_MAX-1);
119 mFlinger->addLayer(l);
120 mLayerOrientationAnim = l;
121 return true;
122}
123
124bool OrientationAnimation::phase1()
125{
126 if (mFlinger->isFrozen() == false) {
127 // start phase 2
128 mState = PHASE2;
129 mLayerOrientationAnim->onOrientationCompleted();
130 mLayerOrientationAnim->invalidate();
131 return true;
132
133 }
Jean-Baptiste Queru02f54242009-07-29 14:25:07 -0700134 //mLayerOrientationAnim->invalidate();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135 return false;
136}
137
138bool OrientationAnimation::phase2()
139{
140 // do the 2nd phase of the animation
141 mLayerOrientationAnim->invalidate();
142 return false;
143}
144
145bool OrientationAnimation::finished()
146{
147 mState = DONE;
148 mFlinger->removeLayer(mLayerOrientationAnim);
149 mLayerOrientationAnim = NULL;
150 return true;
151}
152
153// ---------------------------------------------------------------------------
154
155}; // namespace android