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 <stdlib.h> |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/Errors.h> |
| 24 | #include <utils/Log.h> |
Mathias Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 25 | #include <utils/StopWatch.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
| 27 | #include <core/SkBitmap.h> |
| 28 | |
| 29 | #include <ui/EGLDisplaySurface.h> |
| 30 | |
Mathias Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 31 | #include "BlurFilter.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include "LayerBase.h" |
| 33 | #include "LayerOrientationAnim.h" |
| 34 | #include "SurfaceFlinger.h" |
| 35 | #include "DisplayHardware/DisplayHardware.h" |
| 36 | #include "OrientationAnimation.h" |
| 37 | |
| 38 | namespace android { |
| 39 | // --------------------------------------------------------------------------- |
| 40 | |
| 41 | const uint32_t LayerOrientationAnim::typeInfo = LayerBase::typeInfo | 0x80; |
| 42 | const char* const LayerOrientationAnim::typeID = "LayerOrientationAnim"; |
| 43 | |
| 44 | // --------------------------------------------------------------------------- |
| 45 | |
Mathias Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 46 | // Animation... |
| 47 | const float DURATION = ms2ns(200); |
| 48 | const float BOUNCES_PER_SECOND = 0.5f; |
Mathias Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 49 | const float DIM_TARGET = 0.40f; |
Mathias Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 50 | #define INTERPOLATED_TIME(_t) (_t) |
| 51 | |
| 52 | // --------------------------------------------------------------------------- |
| 53 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | LayerOrientationAnim::LayerOrientationAnim( |
| 55 | SurfaceFlinger* flinger, DisplayID display, |
| 56 | OrientationAnimation* anim, |
Mathias Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 57 | const LayerBitmap& bitmapIn, |
| 58 | const LayerBitmap& bitmapOut) |
| 59 | : LayerOrientationAnimBase(flinger, display), mAnim(anim), |
| 60 | mBitmapIn(bitmapIn), mBitmapOut(bitmapOut), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | mTextureName(-1), mTextureNameIn(-1) |
| 62 | { |
Mathias Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 63 | // blur that texture. |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | mOrientationCompleted = false; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | mNeedsBlending = false; |
| 66 | } |
| 67 | |
| 68 | LayerOrientationAnim::~LayerOrientationAnim() |
| 69 | { |
| 70 | if (mTextureName != -1U) { |
| 71 | LayerBase::deletedTextures.add(mTextureName); |
| 72 | } |
| 73 | if (mTextureNameIn != -1U) { |
| 74 | LayerBase::deletedTextures.add(mTextureNameIn); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | bool LayerOrientationAnim::needsBlending() const |
| 79 | { |
| 80 | return mNeedsBlending; |
| 81 | } |
| 82 | |
| 83 | Point 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 | |
| 90 | void 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 Agopian | 74c770b | 2009-03-24 22:43:22 -0700 | [diff] [blame] | 103 | copybit_device_t* copybit = mFlinger->getBlitEngine(); |
| 104 | if (copybit) { |
| 105 | mCanUseCopyBit = true; |
| 106 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void LayerOrientationAnim::onOrientationCompleted() |
| 110 | { |
Mathias Agopian | 5cd5d31 | 2009-07-10 17:00:00 -0700 | [diff] [blame] | 111 | mAnim->onAnimationFinished(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | void LayerOrientationAnim::onDraw(const Region& clip) const |
| 115 | { |
Mathias Agopian | 5cd5d31 | 2009-07-10 17:00:00 -0700 | [diff] [blame] | 116 | float alphaIn = DIM_TARGET; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | |
Mathias Agopian | 5cd5d31 | 2009-07-10 17:00:00 -0700 | [diff] [blame] | 118 | // 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | } |
Mathias Agopian | 5cd5d31 | 2009-07-10 17:00:00 -0700 | [diff] [blame] | 128 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | copybit_image_t dst; |
| 130 | const GraphicPlane& plane(graphicPlane(0)); |
| 131 | const DisplayHardware& hw(plane.displayHardware()); |
| 132 | hw.getDisplaySurface(&dst); |
| 133 | |
Mathias Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 134 | copybit_image_t src; |
| 135 | mBitmapIn.getBitmapSurface(&src); |
| 136 | |
| 137 | copybit_image_t srcOut; |
| 138 | mBitmapOut.getBitmapSurface(&srcOut); |
| 139 | |
Mathias Agopian | 5cd5d31 | 2009-07-10 17:00:00 -0700 | [diff] [blame] | 140 | const int w = dst.w; |
| 141 | const int h = dst.h; |
Mathias Agopian | 74c770b | 2009-03-24 22:43:22 -0700 | [diff] [blame] | 142 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | const copybit_rect_t srect = { 0, 0, src.w, src.h }; |
Mathias Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 146 | const Region reg(Rect( drect.l, drect.t, drect.r, drect.b )); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | |
Mathias Agopian | 74c770b | 2009-03-24 22:43:22 -0700 | [diff] [blame] | 148 | 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 Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 154 | |
| 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 Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 160 | copybit->set_parameter(copybit, COPYBIT_BLUR, COPYBIT_DISABLE); |
Mathias Agopian | 74c770b | 2009-03-24 22:43:22 -0700 | [diff] [blame] | 161 | } |
| 162 | LOGE_IF(err != NO_ERROR, "copybit failed (%s)", strerror(err)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | } |
Mathias Agopian | 74c770b | 2009-03-24 22:43:22 -0700 | [diff] [blame] | 164 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | |
Mathias Agopian | 74c770b | 2009-03-24 22:43:22 -0700 | [diff] [blame] | 174 | Transform tr; |
Mathias Agopian | 74c770b | 2009-03-24 22:43:22 -0700 | [diff] [blame] | 175 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | 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 Agopian | 74c770b | 2009-03-24 22:43:22 -0700 | [diff] [blame] | 185 | if (!(mFlags & DisplayHardware::SLOW_CONFIG)) { |
| 186 | // Too slow to do this in software |
| 187 | self.mDrawingState.flags |= ISurfaceComposer::eLayerFilter; |
| 188 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | |
Mathias Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 190 | if (alphaIn > 0.0f) { |
Mathias Agopian | 74c770b | 2009-03-24 22:43:22 -0700 | [diff] [blame] | 191 | 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 Agopian | ecbeaa0 | 2009-03-27 15:36:09 -0700 | [diff] [blame] | 198 | self.mDrawingState.alpha = int(alphaIn*255); |
| 199 | drawWithOpenGL(reg, mTextureNameIn, t); |
Mathias Agopian | 74c770b | 2009-03-24 22:43:22 -0700 | [diff] [blame] | 200 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | // --------------------------------------------------------------------------- |
| 205 | |
| 206 | }; // namespace android |