blob: 79e53285c1fe5c46a08c8d1a55efcdcdbba229a8 [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 <stdlib.h>
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/Errors.h>
24#include <utils/Log.h>
Mathias Agopianecbeaa02009-03-27 15:36:09 -070025#include <utils/StopWatch.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
27#include <core/SkBitmap.h>
28
29#include <ui/EGLDisplaySurface.h>
30
Mathias Agopianecbeaa02009-03-27 15:36:09 -070031#include "BlurFilter.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032#include "LayerBase.h"
33#include "LayerOrientationAnim.h"
34#include "SurfaceFlinger.h"
35#include "DisplayHardware/DisplayHardware.h"
36#include "OrientationAnimation.h"
37
38namespace android {
39// ---------------------------------------------------------------------------
40
41const uint32_t LayerOrientationAnim::typeInfo = LayerBase::typeInfo | 0x80;
42const char* const LayerOrientationAnim::typeID = "LayerOrientationAnim";
43
44// ---------------------------------------------------------------------------
45
Mathias Agopianecbeaa02009-03-27 15:36:09 -070046// Animation...
47const float DURATION = ms2ns(200);
48const float BOUNCES_PER_SECOND = 0.5f;
Mathias Agopianecbeaa02009-03-27 15:36:09 -070049const float DIM_TARGET = 0.40f;
Mathias Agopianecbeaa02009-03-27 15:36:09 -070050#define INTERPOLATED_TIME(_t) (_t)
51
52// ---------------------------------------------------------------------------
53
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054LayerOrientationAnim::LayerOrientationAnim(
55 SurfaceFlinger* flinger, DisplayID display,
56 OrientationAnimation* anim,
Mathias Agopianecbeaa02009-03-27 15:36:09 -070057 const LayerBitmap& bitmapIn,
58 const LayerBitmap& bitmapOut)
59 : LayerOrientationAnimBase(flinger, display), mAnim(anim),
60 mBitmapIn(bitmapIn), mBitmapOut(bitmapOut),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 mTextureName(-1), mTextureNameIn(-1)
62{
Mathias Agopianecbeaa02009-03-27 15:36:09 -070063 // blur that texture.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064 mOrientationCompleted = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 mNeedsBlending = false;
66}
67
68LayerOrientationAnim::~LayerOrientationAnim()
69{
70 if (mTextureName != -1U) {
71 LayerBase::deletedTextures.add(mTextureName);
72 }
73 if (mTextureNameIn != -1U) {
74 LayerBase::deletedTextures.add(mTextureNameIn);
75 }
76}
77
78bool LayerOrientationAnim::needsBlending() const
79{
80 return mNeedsBlending;
81}
82
83Point LayerOrientationAnim::getPhysicalSize() const
84{
85 const GraphicPlane& plane(graphicPlane(0));
86 const DisplayHardware& hw(plane.displayHardware());
87 return Point(hw.getWidth(), hw.getHeight());
88}
89
90void LayerOrientationAnim::validateVisibility(const Transform&)
91{
92 const Layer::State& s(drawingState());
93 const Transform tr(s.transform);
94 const Point size(getPhysicalSize());
95 uint32_t w = size.x;
96 uint32_t h = size.y;
97 mTransformedBounds = tr.makeBounds(w, h);
98 mLeft = tr.tx();
99 mTop = tr.ty();
100 transparentRegionScreen.clear();
101 mTransformed = true;
102 mCanUseCopyBit = false;
Mathias Agopian74c770b2009-03-24 22:43:22 -0700103 copybit_device_t* copybit = mFlinger->getBlitEngine();
104 if (copybit) {
105 mCanUseCopyBit = true;
106 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107}
108
109void LayerOrientationAnim::onOrientationCompleted()
110{
Mathias Agopian5cd5d312009-07-10 17:00:00 -0700111 mAnim->onAnimationFinished();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112}
113
114void LayerOrientationAnim::onDraw(const Region& clip) const
115{
Mathias Agopian5cd5d312009-07-10 17:00:00 -0700116 float alphaIn = DIM_TARGET;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117
Mathias Agopian5cd5d312009-07-10 17:00:00 -0700118 // clear screen
119 // TODO: with update on demand, we may be able
120 // to not erase the screen at all during the animation
121 if (!mOrientationCompleted) {
122 glDisable(GL_BLEND);
123 glDisable(GL_DITHER);
124 glDisable(GL_SCISSOR_TEST);
125 glClearColor(0,0,0,0);
126 glClear(GL_COLOR_BUFFER_BIT);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800127 }
Mathias Agopian5cd5d312009-07-10 17:00:00 -0700128
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800129 copybit_image_t dst;
130 const GraphicPlane& plane(graphicPlane(0));
131 const DisplayHardware& hw(plane.displayHardware());
132 hw.getDisplaySurface(&dst);
133
Mathias Agopianecbeaa02009-03-27 15:36:09 -0700134 copybit_image_t src;
135 mBitmapIn.getBitmapSurface(&src);
136
137 copybit_image_t srcOut;
138 mBitmapOut.getBitmapSurface(&srcOut);
139
Mathias Agopian5cd5d312009-07-10 17:00:00 -0700140 const int w = dst.w;
141 const int h = dst.h;
Mathias Agopian74c770b2009-03-24 22:43:22 -0700142 const int xc = uint32_t(dst.w-w)/2;
143 const int yc = uint32_t(dst.h-h)/2;
144 const copybit_rect_t drect = { xc, yc, xc+w, yc+h };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145 const copybit_rect_t srect = { 0, 0, src.w, src.h };
Mathias Agopianecbeaa02009-03-27 15:36:09 -0700146 const Region reg(Rect( drect.l, drect.t, drect.r, drect.b ));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800147
Mathias Agopian74c770b2009-03-24 22:43:22 -0700148 int err = NO_ERROR;
149 const int can_use_copybit = canUseCopybit();
150 if (can_use_copybit) {
151 copybit_device_t* copybit = mFlinger->getBlitEngine();
152 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0);
153 copybit->set_parameter(copybit, COPYBIT_DITHER, COPYBIT_ENABLE);
Mathias Agopianecbeaa02009-03-27 15:36:09 -0700154
155 if (alphaIn > 0) {
156 region_iterator it(reg);
157 copybit->set_parameter(copybit, COPYBIT_BLUR, COPYBIT_ENABLE);
158 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, int(alphaIn*255));
159 err = copybit->stretch(copybit, &dst, &src, &drect, &srect, &it);
Mathias Agopianecbeaa02009-03-27 15:36:09 -0700160 copybit->set_parameter(copybit, COPYBIT_BLUR, COPYBIT_DISABLE);
Mathias Agopian74c770b2009-03-24 22:43:22 -0700161 }
162 LOGE_IF(err != NO_ERROR, "copybit failed (%s)", strerror(err));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800163 }
Mathias Agopian74c770b2009-03-24 22:43:22 -0700164 if (!can_use_copybit || err) {
165 GGLSurface t;
166 t.version = sizeof(GGLSurface);
167 t.width = src.w;
168 t.height = src.h;
169 t.stride = src.w;
170 t.vstride= src.h;
171 t.format = src.format;
172 t.data = (GGLubyte*)(intptr_t(src.base) + src.offset);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800173
Mathias Agopian74c770b2009-03-24 22:43:22 -0700174 Transform tr;
Mathias Agopian74c770b2009-03-24 22:43:22 -0700175 tr.set(xc, yc);
176
177 // FIXME: we should not access mVertices and mDrawingState like that,
178 // but since we control the animation, we know it's going to work okay.
179 // eventually we'd need a more formal way of doing things like this.
180 LayerOrientationAnim& self(const_cast<LayerOrientationAnim&>(*this));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800181 tr.transform(self.mVertices[0], 0, 0);
182 tr.transform(self.mVertices[1], 0, src.h);
183 tr.transform(self.mVertices[2], src.w, src.h);
184 tr.transform(self.mVertices[3], src.w, 0);
Mathias Agopian74c770b2009-03-24 22:43:22 -0700185 if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
186 // Too slow to do this in software
187 self.mDrawingState.flags |= ISurfaceComposer::eLayerFilter;
188 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800189
Mathias Agopianecbeaa02009-03-27 15:36:09 -0700190 if (alphaIn > 0.0f) {
Mathias Agopian74c770b2009-03-24 22:43:22 -0700191 t.data = (GGLubyte*)(intptr_t(src.base) + src.offset);
192 if (UNLIKELY(mTextureNameIn == -1LU)) {
193 mTextureNameIn = createTexture();
194 GLuint w=0, h=0;
195 const Region dirty(Rect(t.width, t.height));
196 loadTexture(dirty, mTextureNameIn, t, w, h);
197 }
Mathias Agopianecbeaa02009-03-27 15:36:09 -0700198 self.mDrawingState.alpha = int(alphaIn*255);
199 drawWithOpenGL(reg, mTextureNameIn, t);
Mathias Agopian74c770b2009-03-24 22:43:22 -0700200 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800201 }
202}
203
204// ---------------------------------------------------------------------------
205
206}; // namespace android