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 | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 46 | mNeedsFiltering(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | mOrientation(0), |
Mathias Agopian | ca6fab2 | 2010-02-19 17:51:58 -0800 | [diff] [blame] | 48 | mLeft(0), mTop(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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | bool LayerBase::setPosition(int32_t x, int32_t y) { |
| 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(); |
| 231 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 232 | uint32_t w = s.w; |
| 233 | uint32_t h = s.h; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | tr.transform(mVertices[0], 0, 0); |
| 235 | tr.transform(mVertices[1], 0, h); |
| 236 | tr.transform(mVertices[2], w, h); |
| 237 | tr.transform(mVertices[3], w, 0); |
| 238 | if (UNLIKELY(transformed)) { |
| 239 | // NOTE: here we could also punt if we have too many rectangles |
| 240 | // in the transparent region |
| 241 | if (tr.preserveRects()) { |
| 242 | // transform the transparent region |
| 243 | transparentRegionScreen = tr.transform(s.transparentRegion); |
| 244 | } else { |
| 245 | // transformation too complex, can't do the transparent region |
| 246 | // optimization. |
| 247 | transparentRegionScreen.clear(); |
| 248 | } |
| 249 | } else { |
| 250 | transparentRegionScreen = s.transparentRegion; |
| 251 | } |
| 252 | |
| 253 | // cache a few things... |
| 254 | mOrientation = tr.getOrientation(); |
| 255 | mTransformedBounds = tr.makeBounds(w, h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | mLeft = tr.tx(); |
| 257 | mTop = tr.ty(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) |
| 261 | { |
| 262 | } |
| 263 | |
| 264 | void LayerBase::unlockPageFlip( |
| 265 | const Transform& planeTransform, Region& outDirtyRegion) |
| 266 | { |
| 267 | if ((android_atomic_and(~1, &mInvalidate)&1) == 1) { |
| 268 | outDirtyRegion.orSelf(visibleRegionScreen); |
| 269 | } |
| 270 | } |
| 271 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | void LayerBase::invalidate() |
| 273 | { |
| 274 | if ((android_atomic_or(1, &mInvalidate)&1) == 0) { |
| 275 | mFlinger->signalEvent(); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | void LayerBase::drawRegion(const Region& reg) const |
| 280 | { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 281 | Region::const_iterator it = reg.begin(); |
| 282 | Region::const_iterator const end = reg.end(); |
| 283 | if (it != end) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | Rect r; |
| 285 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 286 | const int32_t fbWidth = hw.getWidth(); |
| 287 | const int32_t fbHeight = hw.getHeight(); |
| 288 | const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 }, |
| 289 | { fbWidth, fbHeight }, { 0, fbHeight } }; |
| 290 | glVertexPointer(2, GL_SHORT, 0, vertices); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 291 | while (it != end) { |
| 292 | const Rect& r = *it++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | const GLint sy = fbHeight - (r.top + r.height()); |
| 294 | glScissor(r.left, sy, r.width(), r.height()); |
| 295 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 300 | void LayerBase::setGeometry(hwc_layer_t* hwcl) { |
| 301 | hwcl->flags |= HWC_SKIP_LAYER; |
| 302 | } |
| 303 | |
| 304 | void LayerBase::setPerFrameData(hwc_layer_t* hwcl) { |
| 305 | hwcl->compositionType = HWC_FRAMEBUFFER; |
| 306 | hwcl->handle = NULL; |
| 307 | } |
| 308 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 309 | void LayerBase::setFiltering(bool filtering) |
| 310 | { |
| 311 | mFiltering = filtering; |
| 312 | } |
| 313 | |
| 314 | bool LayerBase::getFiltering() const |
| 315 | { |
| 316 | return mFiltering; |
| 317 | } |
| 318 | |
Mathias Agopian | bc7e31a | 2010-08-10 20:42:20 -0700 | [diff] [blame] | 319 | void LayerBase::draw(const Region& clip) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | // reset GL state |
| 322 | glEnable(GL_SCISSOR_TEST); |
| 323 | |
| 324 | onDraw(clip); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 327 | void LayerBase::drawForSreenShot() |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 328 | { |
| 329 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 330 | setFiltering(true); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 331 | onDraw( Region(hw.bounds()) ); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 332 | setFiltering(false); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Mathias Agopian | 010fccb | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 335 | void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red, |
| 336 | GLclampf green, GLclampf blue, |
| 337 | GLclampf alpha) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | { |
| 339 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 340 | const uint32_t fbHeight = hw.getHeight(); |
Mathias Agopian | 010fccb | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 341 | glColor4f(red,green,blue,alpha); |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 342 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 343 | #if defined(GL_OES_EGL_image_external) |
| 344 | if (GLExtensions::getInstance().haveTextureExternal()) { |
| 345 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 346 | } |
| 347 | #endif |
| 348 | glDisable(GL_TEXTURE_2D); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | glDisable(GL_BLEND); |
| 350 | glDisable(GL_DITHER); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 351 | |
| 352 | Region::const_iterator it = clip.begin(); |
| 353 | Region::const_iterator const end = clip.end(); |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 354 | glEnable(GL_SCISSOR_TEST); |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 355 | glVertexPointer(2, GL_FLOAT, 0, mVertices); |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 356 | while (it != end) { |
| 357 | const Rect& r = *it++; |
| 358 | const GLint sy = fbHeight - (r.top + r.height()); |
| 359 | glScissor(r.left, sy, r.width(), r.height()); |
| 360 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 364 | void LayerBase::clearWithOpenGL(const Region& clip) const |
| 365 | { |
| 366 | clearWithOpenGL(clip,0,0,0,0); |
| 367 | } |
| 368 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 369 | void LayerBase::drawWithOpenGL(const Region& clip) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | { |
| 371 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 372 | const uint32_t fbHeight = hw.getHeight(); |
| 373 | const State& s(drawingState()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 375 | GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | if (UNLIKELY(s.alpha < 0xFF)) { |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 377 | const GLfloat alpha = s.alpha * (1.0f/255.0f); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 378 | if (mPremultipliedAlpha) { |
| 379 | glColor4f(alpha, alpha, alpha, alpha); |
| 380 | } else { |
| 381 | glColor4f(1, 1, 1, alpha); |
| 382 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | glEnable(GL_BLEND); |
| 384 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 385 | 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] | 386 | } else { |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 387 | glColor4f(1, 1, 1, 1); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 388 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 389 | if (!isOpaque()) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | glEnable(GL_BLEND); |
| 391 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
| 392 | } else { |
| 393 | glDisable(GL_BLEND); |
| 394 | } |
| 395 | } |
| 396 | |
Mathias Agopian | b661d66 | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 397 | struct TexCoords { |
| 398 | GLfloat u; |
| 399 | GLfloat v; |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 400 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | |
Mathias Agopian | b661d66 | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 402 | TexCoords texCoords[4]; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 403 | texCoords[0].u = 0; |
| 404 | texCoords[0].v = 1; |
| 405 | texCoords[1].u = 0; |
| 406 | texCoords[1].v = 0; |
| 407 | texCoords[2].u = 1; |
| 408 | texCoords[2].v = 0; |
| 409 | texCoords[3].u = 1; |
| 410 | texCoords[3].v = 1; |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 411 | |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 412 | if (needsDithering()) { |
| 413 | glEnable(GL_DITHER); |
| 414 | } else { |
| 415 | glDisable(GL_DITHER); |
| 416 | } |
| 417 | |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 418 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 419 | glVertexPointer(2, GL_FLOAT, 0, mVertices); |
| 420 | glTexCoordPointer(2, GL_FLOAT, 0, texCoords); |
| 421 | |
Mathias Agopian | b661d66 | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 422 | Region::const_iterator it = clip.begin(); |
| 423 | Region::const_iterator const end = clip.end(); |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 424 | while (it != end) { |
| 425 | const Rect& r = *it++; |
| 426 | const GLint sy = fbHeight - (r.top + r.height()); |
| 427 | glScissor(r.left, sy, r.width(), r.height()); |
| 428 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 429 | } |
| 430 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 433 | void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const |
| 434 | { |
| 435 | const Layer::State& s(drawingState()); |
| 436 | snprintf(buffer, SIZE, |
| 437 | "+ %s %p\n" |
| 438 | " " |
| 439 | "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), " |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 440 | "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, " |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 441 | "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n", |
| 442 | getTypeId(), this, s.z, tx(), ty(), s.w, s.h, |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 443 | isOpaque(), needsDithering(), contentDirty, |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 444 | s.alpha, s.flags, |
| 445 | s.transform[0][0], s.transform[0][1], |
| 446 | s.transform[1][0], s.transform[1][1]); |
| 447 | result.append(buffer); |
| 448 | } |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 449 | |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 450 | void LayerBase::shortDump(String8& result, char* scratch, size_t size) const |
| 451 | { |
| 452 | LayerBase::dump(result, scratch, size); |
| 453 | } |
| 454 | |
| 455 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | // --------------------------------------------------------------------------- |
| 457 | |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 458 | int32_t LayerBaseClient::sIdentity = 1; |
Mathias Agopian | 2e12324 | 2009-06-23 20:06:46 -0700 | [diff] [blame] | 459 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display, |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 461 | const sp<Client>& client) |
Mathias Agopian | a1f47b9 | 2011-02-15 19:01:06 -0800 | [diff] [blame] | 462 | : LayerBase(flinger, display), |
| 463 | mHasSurface(false), |
| 464 | mClientRef(client), |
Mathias Agopian | 948d69f | 2010-03-08 19:29:09 -0800 | [diff] [blame] | 465 | mIdentity(uint32_t(android_atomic_inc(&sIdentity))) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 467 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | LayerBaseClient::~LayerBaseClient() |
| 470 | { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 471 | sp<Client> c(mClientRef.promote()); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 472 | if (c != 0) { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 473 | c->detachLayer(this); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 477 | sp<ISurface> LayerBaseClient::createSurface() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 479 | class BSurface : public BnSurface, public LayerCleaner { |
| 480 | virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; } |
| 481 | public: |
| 482 | BSurface(const sp<SurfaceFlinger>& flinger, |
| 483 | const sp<LayerBaseClient>& layer) |
| 484 | : LayerCleaner(flinger, layer) { } |
| 485 | }; |
| 486 | sp<ISurface> sur(new BSurface(mFlinger, this)); |
| 487 | return sur; |
| 488 | } |
| 489 | |
| 490 | sp<ISurface> LayerBaseClient::getSurface() |
| 491 | { |
| 492 | sp<ISurface> s; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 493 | Mutex::Autolock _l(mLock); |
Mathias Agopian | a1f47b9 | 2011-02-15 19:01:06 -0800 | [diff] [blame] | 494 | |
| 495 | LOG_ALWAYS_FATAL_IF(mHasSurface, |
| 496 | "LayerBaseClient::getSurface() has already been called"); |
| 497 | |
| 498 | mHasSurface = true; |
| 499 | s = createSurface(); |
| 500 | mClientSurfaceBinder = s->asBinder(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 501 | return s; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Mathias Agopian | 0d15612 | 2011-01-25 20:17:45 -0800 | [diff] [blame] | 504 | wp<IBinder> LayerBaseClient::getSurfaceBinder() const { |
| 505 | return mClientSurfaceBinder; |
| 506 | } |
| 507 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 508 | void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const |
| 509 | { |
| 510 | LayerBase::dump(result, buffer, SIZE); |
| 511 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 512 | sp<Client> client(mClientRef.promote()); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 513 | snprintf(buffer, SIZE, |
| 514 | " name=%s\n" |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 515 | " client=%p, identity=%u\n", |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 516 | getName().string(), |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 517 | client.get(), getIdentity()); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 518 | |
| 519 | result.append(buffer); |
| 520 | } |
| 521 | |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 522 | |
| 523 | void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const |
| 524 | { |
| 525 | LayerBaseClient::dump(result, scratch, size); |
| 526 | } |
| 527 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 528 | // --------------------------------------------------------------------------- |
| 529 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 530 | LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger, |
| 531 | const sp<LayerBaseClient>& layer) |
| 532 | : mFlinger(flinger), mLayer(layer) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 535 | LayerBaseClient::LayerCleaner::~LayerCleaner() { |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 536 | // destroy client resources |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame^] | 537 | mFlinger->destroySurface(mLayer); |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 538 | } |
| 539 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | // --------------------------------------------------------------------------- |
| 541 | |
| 542 | }; // namespace android |