| 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 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <stdlib.h> | 
|  | 18 | #include <stdint.h> | 
|  | 19 | #include <sys/types.h> | 
|  | 20 |  | 
|  | 21 | #include <utils/Errors.h> | 
|  | 22 | #include <utils/Log.h> | 
| Mathias Agopian | 310f8da | 2009-05-22 01:27:01 -0700 | [diff] [blame] | 23 | #include <binder/IPCThreadState.h> | 
|  | 24 | #include <binder/IServiceManager.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 |  | 
|  | 26 | #include <GLES/gl.h> | 
|  | 27 | #include <GLES/glext.h> | 
|  | 28 |  | 
|  | 29 | #include <hardware/hardware.h> | 
|  | 30 |  | 
|  | 31 | #include "clz.h" | 
|  | 32 | #include "LayerBase.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | #include "SurfaceFlinger.h" | 
|  | 34 | #include "DisplayHardware/DisplayHardware.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | namespace android { | 
|  | 37 |  | 
|  | 38 | // --------------------------------------------------------------------------- | 
|  | 39 |  | 
| Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 40 | int32_t LayerBase::sSequence = 1; | 
|  | 41 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display) | 
|  | 43 | : dpy(display), contentDirty(false), | 
| Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 44 | sequence(uint32_t(android_atomic_inc(&sSequence))), | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 45 | mFlinger(flinger), mFiltering(false), | 
| Mathias Agopian | f9abeb9 | 2011-09-09 01:47:48 -0700 | [diff] [blame] | 46 | mNeedsFiltering(false), mInOverlay(false), | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | mOrientation(0), | 
| Jamie Gennis | 8d91b42 | 2011-09-23 15:54:34 -0700 | [diff] [blame] | 48 | mPlaneOrientation(0), | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | mTransactionFlags(0), | 
| Mathias Agopian | 245e4d7 | 2010-04-21 15:24:11 -0700 | [diff] [blame] | 50 | mPremultipliedAlpha(true), mName("unnamed"), mDebug(false), | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | mInvalidate(0) | 
|  | 52 | { | 
|  | 53 | const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware()); | 
|  | 54 | mFlags = hw.getFlags(); | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | LayerBase::~LayerBase() | 
|  | 58 | { | 
|  | 59 | } | 
|  | 60 |  | 
| Mathias Agopian | d129659 | 2010-03-09 19:17:47 -0800 | [diff] [blame] | 61 | void LayerBase::setName(const String8& name) { | 
|  | 62 | mName = name; | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | String8 LayerBase::getName() const { | 
|  | 66 | return mName; | 
|  | 67 | } | 
|  | 68 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | const GraphicPlane& LayerBase::graphicPlane(int dpy) const | 
|  | 70 | { | 
|  | 71 | return mFlinger->graphicPlane(dpy); | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | GraphicPlane& LayerBase::graphicPlane(int dpy) | 
|  | 75 | { | 
|  | 76 | return mFlinger->graphicPlane(dpy); | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 | void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags) | 
|  | 80 | { | 
|  | 81 | uint32_t layerFlags = 0; | 
|  | 82 | if (flags & ISurfaceComposer::eHidden) | 
|  | 83 | layerFlags = ISurfaceComposer::eLayerHidden; | 
|  | 84 |  | 
|  | 85 | if (flags & ISurfaceComposer::eNonPremultiplied) | 
|  | 86 | mPremultipliedAlpha = false; | 
|  | 87 |  | 
| Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 88 | mCurrentState.z             = 0; | 
|  | 89 | mCurrentState.w             = w; | 
|  | 90 | mCurrentState.h             = h; | 
|  | 91 | mCurrentState.requested_w   = w; | 
|  | 92 | mCurrentState.requested_h   = h; | 
|  | 93 | mCurrentState.alpha         = 0xFF; | 
|  | 94 | mCurrentState.flags         = layerFlags; | 
|  | 95 | mCurrentState.sequence      = 0; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | mCurrentState.transform.set(0, 0); | 
|  | 97 |  | 
|  | 98 | // drawing state & current state are identical | 
|  | 99 | mDrawingState = mCurrentState; | 
|  | 100 | } | 
|  | 101 |  | 
| Mathias Agopian | ba6be54 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 102 | void LayerBase::commitTransaction() { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | mDrawingState = mCurrentState; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | } | 
|  | 105 | void LayerBase::forceVisibilityTransaction() { | 
|  | 106 | // this can be called without SurfaceFlinger.mStateLock, but if we | 
|  | 107 | // can atomically increment the sequence number, it doesn't matter. | 
|  | 108 | android_atomic_inc(&mCurrentState.sequence); | 
|  | 109 | requestTransaction(); | 
|  | 110 | } | 
|  | 111 | bool LayerBase::requestTransaction() { | 
|  | 112 | int32_t old = setTransactionFlags(eTransactionNeeded); | 
|  | 113 | return ((old & eTransactionNeeded) == 0); | 
|  | 114 | } | 
|  | 115 | uint32_t LayerBase::getTransactionFlags(uint32_t flags) { | 
|  | 116 | return android_atomic_and(~flags, &mTransactionFlags) & flags; | 
|  | 117 | } | 
|  | 118 | uint32_t LayerBase::setTransactionFlags(uint32_t flags) { | 
|  | 119 | return android_atomic_or(flags, &mTransactionFlags); | 
|  | 120 | } | 
|  | 121 |  | 
| Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 122 | bool LayerBase::setPosition(float x, float y) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y) | 
|  | 124 | return false; | 
|  | 125 | mCurrentState.sequence++; | 
|  | 126 | mCurrentState.transform.set(x, y); | 
|  | 127 | requestTransaction(); | 
|  | 128 | return true; | 
|  | 129 | } | 
|  | 130 | bool LayerBase::setLayer(uint32_t z) { | 
|  | 131 | if (mCurrentState.z == z) | 
|  | 132 | return false; | 
|  | 133 | mCurrentState.sequence++; | 
|  | 134 | mCurrentState.z = z; | 
|  | 135 | requestTransaction(); | 
|  | 136 | return true; | 
|  | 137 | } | 
|  | 138 | bool LayerBase::setSize(uint32_t w, uint32_t h) { | 
| Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 139 | if (mCurrentState.requested_w == w && mCurrentState.requested_h == h) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | return false; | 
| Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 141 | mCurrentState.requested_w = w; | 
|  | 142 | mCurrentState.requested_h = h; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | requestTransaction(); | 
|  | 144 | return true; | 
|  | 145 | } | 
|  | 146 | bool LayerBase::setAlpha(uint8_t alpha) { | 
|  | 147 | if (mCurrentState.alpha == alpha) | 
|  | 148 | return false; | 
|  | 149 | mCurrentState.sequence++; | 
|  | 150 | mCurrentState.alpha = alpha; | 
|  | 151 | requestTransaction(); | 
|  | 152 | return true; | 
|  | 153 | } | 
|  | 154 | bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | mCurrentState.sequence++; | 
|  | 156 | mCurrentState.transform.set( | 
|  | 157 | matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy); | 
|  | 158 | requestTransaction(); | 
|  | 159 | return true; | 
|  | 160 | } | 
|  | 161 | bool LayerBase::setTransparentRegionHint(const Region& transparent) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | mCurrentState.sequence++; | 
|  | 163 | mCurrentState.transparentRegion = transparent; | 
|  | 164 | requestTransaction(); | 
|  | 165 | return true; | 
|  | 166 | } | 
|  | 167 | bool LayerBase::setFlags(uint8_t flags, uint8_t mask) { | 
|  | 168 | const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask); | 
|  | 169 | if (mCurrentState.flags == newFlags) | 
|  | 170 | return false; | 
|  | 171 | mCurrentState.sequence++; | 
|  | 172 | mCurrentState.flags = newFlags; | 
|  | 173 | requestTransaction(); | 
|  | 174 | return true; | 
|  | 175 | } | 
|  | 176 |  | 
|  | 177 | Rect LayerBase::visibleBounds() const | 
|  | 178 | { | 
|  | 179 | return mTransformedBounds; | 
|  | 180 | } | 
|  | 181 |  | 
|  | 182 | void LayerBase::setVisibleRegion(const Region& visibleRegion) { | 
|  | 183 | // always called from main thread | 
|  | 184 | visibleRegionScreen = visibleRegion; | 
|  | 185 | } | 
|  | 186 |  | 
|  | 187 | void LayerBase::setCoveredRegion(const Region& coveredRegion) { | 
|  | 188 | // always called from main thread | 
|  | 189 | coveredRegionScreen = coveredRegion; | 
|  | 190 | } | 
|  | 191 |  | 
|  | 192 | uint32_t LayerBase::doTransaction(uint32_t flags) | 
|  | 193 | { | 
|  | 194 | const Layer::State& front(drawingState()); | 
|  | 195 | const Layer::State& temp(currentState()); | 
|  | 196 |  | 
| Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 197 | if ((front.requested_w != temp.requested_w) || | 
|  | 198 | (front.requested_h != temp.requested_h))  { | 
|  | 199 | // resize the layer, set the physical size to the requested size | 
|  | 200 | Layer::State& editTemp(currentState()); | 
|  | 201 | editTemp.w = temp.requested_w; | 
|  | 202 | editTemp.h = temp.requested_h; | 
|  | 203 | } | 
|  | 204 |  | 
| Mathias Agopian | 6656dbc | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 205 | if ((front.w != temp.w) || (front.h != temp.h)) { | 
|  | 206 | // invalidate and recompute the visible regions if needed | 
|  | 207 | flags |= Layer::eVisibleRegion; | 
| Mathias Agopian | 6656dbc | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 208 | } | 
|  | 209 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | if (temp.sequence != front.sequence) { | 
|  | 211 | // invalidate and recompute the visible regions if needed | 
|  | 212 | flags |= eVisibleRegion; | 
|  | 213 | this->contentDirty = true; | 
| Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 214 |  | 
| Mathias Agopian | 733189d | 2010-12-02 21:32:29 -0800 | [diff] [blame] | 215 | // we may use linear filtering, if the matrix scales us | 
|  | 216 | const uint8_t type = temp.transform.getType(); | 
|  | 217 | mNeedsFiltering = (!temp.transform.preserveRects() || | 
|  | 218 | (type >= Transform::SCALE)); | 
| Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 219 | } | 
|  | 220 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | // Commit the transaction | 
| Mathias Agopian | ba6be54 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 222 | commitTransaction(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | return flags; | 
|  | 224 | } | 
|  | 225 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | void LayerBase::validateVisibility(const Transform& planeTransform) | 
|  | 227 | { | 
|  | 228 | const Layer::State& s(drawingState()); | 
|  | 229 | const Transform tr(planeTransform * s.transform); | 
|  | 230 | const bool transformed = tr.transformed(); | 
| Mathias Agopian | ffcf465 | 2011-07-07 17:30:31 -0700 | [diff] [blame] | 231 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
|  | 232 | const uint32_t hw_h = hw.getHeight(); | 
|  | 233 |  | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 234 | uint32_t w = s.w; | 
|  | 235 | uint32_t h = s.h; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | tr.transform(mVertices[0], 0, 0); | 
|  | 237 | tr.transform(mVertices[1], 0, h); | 
|  | 238 | tr.transform(mVertices[2], w, h); | 
|  | 239 | tr.transform(mVertices[3], w, 0); | 
| Mathias Agopian | ffcf465 | 2011-07-07 17:30:31 -0700 | [diff] [blame] | 240 | for (size_t i=0 ; i<4 ; i++) | 
|  | 241 | mVertices[i][1] = hw_h - mVertices[i][1]; | 
|  | 242 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | if (UNLIKELY(transformed)) { | 
|  | 244 | // NOTE: here we could also punt if we have too many rectangles | 
|  | 245 | // in the transparent region | 
|  | 246 | if (tr.preserveRects()) { | 
|  | 247 | // transform the transparent region | 
|  | 248 | transparentRegionScreen = tr.transform(s.transparentRegion); | 
|  | 249 | } else { | 
|  | 250 | // transformation too complex, can't do the transparent region | 
|  | 251 | // optimization. | 
|  | 252 | transparentRegionScreen.clear(); | 
|  | 253 | } | 
|  | 254 | } else { | 
|  | 255 | transparentRegionScreen = s.transparentRegion; | 
|  | 256 | } | 
|  | 257 |  | 
|  | 258 | // cache a few things... | 
|  | 259 | mOrientation = tr.getOrientation(); | 
| Jamie Gennis | 8d91b42 | 2011-09-23 15:54:34 -0700 | [diff] [blame] | 260 | mPlaneOrientation = planeTransform.getOrientation(); | 
| Mathias Agopian | d992db3 | 2011-08-18 18:31:00 -0700 | [diff] [blame] | 261 | mTransform = tr; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | mTransformedBounds = tr.makeBounds(w, h); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | } | 
|  | 264 |  | 
|  | 265 | void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) | 
|  | 266 | { | 
|  | 267 | } | 
|  | 268 |  | 
|  | 269 | void LayerBase::unlockPageFlip( | 
|  | 270 | const Transform& planeTransform, Region& outDirtyRegion) | 
|  | 271 | { | 
|  | 272 | if ((android_atomic_and(~1, &mInvalidate)&1) == 1) { | 
|  | 273 | outDirtyRegion.orSelf(visibleRegionScreen); | 
|  | 274 | } | 
|  | 275 | } | 
|  | 276 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | void LayerBase::invalidate() | 
|  | 278 | { | 
|  | 279 | if ((android_atomic_or(1, &mInvalidate)&1) == 0) { | 
|  | 280 | mFlinger->signalEvent(); | 
|  | 281 | } | 
|  | 282 | } | 
|  | 283 |  | 
|  | 284 | void LayerBase::drawRegion(const Region& reg) const | 
|  | 285 | { | 
| Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 286 | Region::const_iterator it = reg.begin(); | 
|  | 287 | Region::const_iterator const end = reg.end(); | 
|  | 288 | if (it != end) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | Rect r; | 
|  | 290 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
|  | 291 | const int32_t fbWidth  = hw.getWidth(); | 
|  | 292 | const int32_t fbHeight = hw.getHeight(); | 
|  | 293 | const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 }, | 
|  | 294 | { fbWidth, fbHeight }, { 0, fbHeight }  }; | 
|  | 295 | glVertexPointer(2, GL_SHORT, 0, vertices); | 
| Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 296 | while (it != end) { | 
|  | 297 | const Rect& r = *it++; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | const GLint sy = fbHeight - (r.top + r.height()); | 
|  | 299 | glScissor(r.left, sy, r.width(), r.height()); | 
|  | 300 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 
|  | 301 | } | 
|  | 302 | } | 
|  | 303 | } | 
|  | 304 |  | 
| Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 305 | void LayerBase::setGeometry(hwc_layer_t* hwcl) | 
|  | 306 | { | 
|  | 307 | hwcl->compositionType = HWC_FRAMEBUFFER; | 
|  | 308 | hwcl->hints = 0; | 
|  | 309 | hwcl->flags = HWC_SKIP_LAYER; | 
|  | 310 | hwcl->transform = 0; | 
|  | 311 | hwcl->blending = HWC_BLENDING_NONE; | 
|  | 312 |  | 
|  | 313 | // this gives us only the "orientation" component of the transform | 
|  | 314 | const State& s(drawingState()); | 
|  | 315 | const uint32_t finalTransform = s.transform.getOrientation(); | 
|  | 316 | // we can only handle simple transformation | 
|  | 317 | if (finalTransform & Transform::ROT_INVALID) { | 
|  | 318 | hwcl->flags = HWC_SKIP_LAYER; | 
|  | 319 | } else { | 
|  | 320 | hwcl->transform = finalTransform; | 
|  | 321 | } | 
|  | 322 |  | 
|  | 323 | if (!isOpaque()) { | 
|  | 324 | hwcl->blending = mPremultipliedAlpha ? | 
|  | 325 | HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE; | 
|  | 326 | } | 
|  | 327 |  | 
|  | 328 | // scaling is already applied in mTransformedBounds | 
|  | 329 | hwcl->displayFrame.left   = mTransformedBounds.left; | 
|  | 330 | hwcl->displayFrame.top    = mTransformedBounds.top; | 
|  | 331 | hwcl->displayFrame.right  = mTransformedBounds.right; | 
|  | 332 | hwcl->displayFrame.bottom = mTransformedBounds.bottom; | 
|  | 333 | hwcl->visibleRegionScreen.rects = | 
|  | 334 | reinterpret_cast<hwc_rect_t const *>( | 
|  | 335 | visibleRegionScreen.getArray( | 
|  | 336 | &hwcl->visibleRegionScreen.numRects)); | 
| Mathias Agopian | c7f3381 | 2011-08-30 15:02:41 -0700 | [diff] [blame] | 337 |  | 
|  | 338 | hwcl->sourceCrop.left   = 0; | 
|  | 339 | hwcl->sourceCrop.top    = 0; | 
|  | 340 | hwcl->sourceCrop.right  = mTransformedBounds.width(); | 
|  | 341 | hwcl->sourceCrop.bottom = mTransformedBounds.height(); | 
| Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 342 | } | 
|  | 343 |  | 
|  | 344 | void LayerBase::setPerFrameData(hwc_layer_t* hwcl) { | 
|  | 345 | hwcl->compositionType = HWC_FRAMEBUFFER; | 
|  | 346 | hwcl->handle = NULL; | 
|  | 347 | } | 
|  | 348 |  | 
| Mathias Agopian | f384cc3 | 2011-09-08 18:31:55 -0700 | [diff] [blame] | 349 | void LayerBase::setOverlay(bool inOverlay) { | 
|  | 350 | mInOverlay = inOverlay; | 
|  | 351 | } | 
|  | 352 |  | 
|  | 353 | bool LayerBase::isOverlay() const { | 
|  | 354 | return mInOverlay; | 
|  | 355 | } | 
|  | 356 |  | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 357 | void LayerBase::setFiltering(bool filtering) | 
|  | 358 | { | 
|  | 359 | mFiltering = filtering; | 
|  | 360 | } | 
|  | 361 |  | 
|  | 362 | bool LayerBase::getFiltering() const | 
|  | 363 | { | 
|  | 364 | return mFiltering; | 
|  | 365 | } | 
|  | 366 |  | 
| Mathias Agopian | bc7e31a | 2010-08-10 20:42:20 -0700 | [diff] [blame] | 367 | void LayerBase::draw(const Region& clip) const | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | // reset GL state | 
|  | 370 | glEnable(GL_SCISSOR_TEST); | 
|  | 371 |  | 
|  | 372 | onDraw(clip); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | } | 
|  | 374 |  | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 375 | void LayerBase::drawForSreenShot() | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 376 | { | 
|  | 377 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 378 | setFiltering(true); | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 379 | onDraw( Region(hw.bounds()) ); | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 380 | setFiltering(false); | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 381 | } | 
|  | 382 |  | 
| Mathias Agopian | 010fccb | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 383 | void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red, | 
|  | 384 | GLclampf green, GLclampf blue, | 
|  | 385 | GLclampf alpha) const | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | { | 
|  | 387 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
|  | 388 | const uint32_t fbHeight = hw.getHeight(); | 
| Mathias Agopian | 010fccb | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 389 | glColor4f(red,green,blue,alpha); | 
| Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 390 |  | 
| Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 391 | glDisable(GL_TEXTURE_EXTERNAL_OES); | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 392 | glDisable(GL_TEXTURE_2D); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | glDisable(GL_BLEND); | 
| Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 394 |  | 
|  | 395 | Region::const_iterator it = clip.begin(); | 
|  | 396 | Region::const_iterator const end = clip.end(); | 
| Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 397 | glEnable(GL_SCISSOR_TEST); | 
| Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 398 | glVertexPointer(2, GL_FLOAT, 0, mVertices); | 
| Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 399 | while (it != end) { | 
|  | 400 | const Rect& r = *it++; | 
|  | 401 | const GLint sy = fbHeight - (r.top + r.height()); | 
|  | 402 | glScissor(r.left, sy, r.width(), r.height()); | 
|  | 403 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | } | 
|  | 405 | } | 
|  | 406 |  | 
| Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 407 | void LayerBase::clearWithOpenGL(const Region& clip) const | 
|  | 408 | { | 
|  | 409 | clearWithOpenGL(clip,0,0,0,0); | 
|  | 410 | } | 
|  | 411 |  | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 412 | void LayerBase::drawWithOpenGL(const Region& clip) const | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | { | 
|  | 414 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
|  | 415 | const uint32_t fbHeight = hw.getHeight(); | 
|  | 416 | const State& s(drawingState()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 |  | 
| Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 418 | GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | if (UNLIKELY(s.alpha < 0xFF)) { | 
| Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 420 | const GLfloat alpha = s.alpha * (1.0f/255.0f); | 
| Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 421 | if (mPremultipliedAlpha) { | 
|  | 422 | glColor4f(alpha, alpha, alpha, alpha); | 
|  | 423 | } else { | 
|  | 424 | glColor4f(1, 1, 1, alpha); | 
|  | 425 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | glEnable(GL_BLEND); | 
|  | 427 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); | 
| Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 428 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | } else { | 
| Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 430 | glColor4f(1, 1, 1, 1); | 
| Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 431 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 432 | if (!isOpaque()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | glEnable(GL_BLEND); | 
|  | 434 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); | 
|  | 435 | } else { | 
|  | 436 | glDisable(GL_BLEND); | 
|  | 437 | } | 
|  | 438 | } | 
|  | 439 |  | 
| Mathias Agopian | b661d66 | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 440 | struct TexCoords { | 
|  | 441 | GLfloat u; | 
|  | 442 | GLfloat v; | 
| Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 443 | }; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 |  | 
| Mathias Agopian | b661d66 | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 445 | TexCoords texCoords[4]; | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 446 | texCoords[0].u = 0; | 
|  | 447 | texCoords[0].v = 1; | 
|  | 448 | texCoords[1].u = 0; | 
|  | 449 | texCoords[1].v = 0; | 
|  | 450 | texCoords[2].u = 1; | 
|  | 451 | texCoords[2].v = 0; | 
|  | 452 | texCoords[3].u = 1; | 
|  | 453 | texCoords[3].v = 1; | 
| Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 454 |  | 
|  | 455 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); | 
|  | 456 | glVertexPointer(2, GL_FLOAT, 0, mVertices); | 
|  | 457 | glTexCoordPointer(2, GL_FLOAT, 0, texCoords); | 
|  | 458 |  | 
| Mathias Agopian | b661d66 | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 459 | Region::const_iterator it = clip.begin(); | 
|  | 460 | Region::const_iterator const end = clip.end(); | 
| Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 461 | while (it != end) { | 
|  | 462 | const Rect& r = *it++; | 
|  | 463 | const GLint sy = fbHeight - (r.top + r.height()); | 
|  | 464 | glScissor(r.left, sy, r.width(), r.height()); | 
|  | 465 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 
|  | 466 | } | 
|  | 467 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | 
| Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 468 | glDisable(GL_BLEND); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | } | 
|  | 470 |  | 
| Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 471 | void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const | 
|  | 472 | { | 
|  | 473 | const Layer::State& s(drawingState()); | 
|  | 474 | snprintf(buffer, SIZE, | 
| Mathias Agopian | 22da60c | 2011-09-09 00:49:11 -0700 | [diff] [blame] | 475 | "+ %s %p (%s)\n" | 
| Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 476 | "      " | 
| Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 477 | "z=%9d, pos=(%g,%g), size=(%4d,%4d), " | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 478 | "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, " | 
| Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 479 | "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n", | 
| Mathias Agopian | 22da60c | 2011-09-09 00:49:11 -0700 | [diff] [blame] | 480 | getTypeId(), this, getName().string(), | 
|  | 481 | s.z, s.transform.tx(), s.transform.ty(), s.w, s.h, | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 482 | isOpaque(), needsDithering(), contentDirty, | 
| Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 483 | s.alpha, s.flags, | 
|  | 484 | s.transform[0][0], s.transform[0][1], | 
|  | 485 | s.transform[1][0], s.transform[1][1]); | 
|  | 486 | result.append(buffer); | 
|  | 487 | } | 
| Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 488 |  | 
| Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 489 | void LayerBase::shortDump(String8& result, char* scratch, size_t size) const | 
|  | 490 | { | 
|  | 491 | LayerBase::dump(result, scratch, size); | 
|  | 492 | } | 
|  | 493 |  | 
|  | 494 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | // --------------------------------------------------------------------------- | 
|  | 496 |  | 
| Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 497 | int32_t LayerBaseClient::sIdentity = 1; | 
| Mathias Agopian | 2e12324 | 2009-06-23 20:06:46 -0700 | [diff] [blame] | 498 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display, | 
| Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 500 | const sp<Client>& client) | 
| Mathias Agopian | a1f47b9 | 2011-02-15 19:01:06 -0800 | [diff] [blame] | 501 | : LayerBase(flinger, display), | 
|  | 502 | mHasSurface(false), | 
|  | 503 | mClientRef(client), | 
| Mathias Agopian | 948d69f | 2010-03-08 19:29:09 -0800 | [diff] [blame] | 504 | mIdentity(uint32_t(android_atomic_inc(&sIdentity))) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 506 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | LayerBaseClient::~LayerBaseClient() | 
|  | 509 | { | 
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 510 | sp<Client> c(mClientRef.promote()); | 
| Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 511 | if (c != 0) { | 
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 512 | c->detachLayer(this); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | } | 
|  | 514 | } | 
|  | 515 |  | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 516 | sp<ISurface> LayerBaseClient::createSurface() | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | { | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 518 | class BSurface : public BnSurface, public LayerCleaner { | 
|  | 519 | virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; } | 
|  | 520 | public: | 
|  | 521 | BSurface(const sp<SurfaceFlinger>& flinger, | 
|  | 522 | const sp<LayerBaseClient>& layer) | 
|  | 523 | : LayerCleaner(flinger, layer) { } | 
|  | 524 | }; | 
|  | 525 | sp<ISurface> sur(new BSurface(mFlinger, this)); | 
|  | 526 | return sur; | 
|  | 527 | } | 
|  | 528 |  | 
|  | 529 | sp<ISurface> LayerBaseClient::getSurface() | 
|  | 530 | { | 
|  | 531 | sp<ISurface> s; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 532 | Mutex::Autolock _l(mLock); | 
| Mathias Agopian | a1f47b9 | 2011-02-15 19:01:06 -0800 | [diff] [blame] | 533 |  | 
|  | 534 | LOG_ALWAYS_FATAL_IF(mHasSurface, | 
|  | 535 | "LayerBaseClient::getSurface() has already been called"); | 
|  | 536 |  | 
|  | 537 | mHasSurface = true; | 
|  | 538 | s = createSurface(); | 
|  | 539 | mClientSurfaceBinder = s->asBinder(); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 540 | return s; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | } | 
|  | 542 |  | 
| Mathias Agopian | 0d15612 | 2011-01-25 20:17:45 -0800 | [diff] [blame] | 543 | wp<IBinder> LayerBaseClient::getSurfaceBinder() const { | 
|  | 544 | return mClientSurfaceBinder; | 
|  | 545 | } | 
|  | 546 |  | 
| Jamie Gennis | 582270d | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 547 | wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const { | 
|  | 548 | return 0; | 
|  | 549 | } | 
|  | 550 |  | 
| Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 551 | void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const | 
|  | 552 | { | 
|  | 553 | LayerBase::dump(result, buffer, SIZE); | 
|  | 554 |  | 
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 555 | sp<Client> client(mClientRef.promote()); | 
| Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 556 | snprintf(buffer, SIZE, | 
| Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 557 | "      client=%p, identity=%u\n", | 
| Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 558 | client.get(), getIdentity()); | 
| Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 559 |  | 
|  | 560 | result.append(buffer); | 
|  | 561 | } | 
|  | 562 |  | 
| Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 563 |  | 
|  | 564 | void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const | 
|  | 565 | { | 
|  | 566 | LayerBaseClient::dump(result, scratch, size); | 
|  | 567 | } | 
|  | 568 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 569 | // --------------------------------------------------------------------------- | 
|  | 570 |  | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 571 | LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger, | 
|  | 572 | const sp<LayerBaseClient>& layer) | 
|  | 573 | : mFlinger(flinger), mLayer(layer) { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 574 | } | 
|  | 575 |  | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 576 | LayerBaseClient::LayerCleaner::~LayerCleaner() { | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 577 | // destroy client resources | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 578 | mFlinger->destroySurface(mLayer); | 
| Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 579 | } | 
|  | 580 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | // --------------------------------------------------------------------------- | 
|  | 582 |  | 
|  | 583 | }; // namespace android |