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" |
Mathias Agopian | d606de6 | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 35 | #include "TextureManager.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | namespace android { |
| 39 | |
| 40 | // --------------------------------------------------------------------------- |
| 41 | |
Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 42 | int32_t LayerBase::sSequence = 1; |
| 43 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display) |
| 45 | : dpy(display), contentDirty(false), |
Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 46 | sequence(uint32_t(android_atomic_inc(&sSequence))), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | mFlinger(flinger), |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 48 | mNeedsFiltering(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | mOrientation(0), |
Mathias Agopian | ca6fab2 | 2010-02-19 17:51:58 -0800 | [diff] [blame] | 50 | mLeft(0), mTop(0), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | mTransactionFlags(0), |
Mathias Agopian | 245e4d7 | 2010-04-21 15:24:11 -0700 | [diff] [blame] | 52 | mPremultipliedAlpha(true), mName("unnamed"), mDebug(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | mInvalidate(0) |
| 54 | { |
| 55 | const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware()); |
| 56 | mFlags = hw.getFlags(); |
| 57 | } |
| 58 | |
| 59 | LayerBase::~LayerBase() |
| 60 | { |
| 61 | } |
| 62 | |
Mathias Agopian | d129659 | 2010-03-09 19:17:47 -0800 | [diff] [blame] | 63 | void LayerBase::setName(const String8& name) { |
| 64 | mName = name; |
| 65 | } |
| 66 | |
| 67 | String8 LayerBase::getName() const { |
| 68 | return mName; |
| 69 | } |
| 70 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | const GraphicPlane& LayerBase::graphicPlane(int dpy) const |
| 72 | { |
| 73 | return mFlinger->graphicPlane(dpy); |
| 74 | } |
| 75 | |
| 76 | GraphicPlane& LayerBase::graphicPlane(int dpy) |
| 77 | { |
| 78 | return mFlinger->graphicPlane(dpy); |
| 79 | } |
| 80 | |
| 81 | void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags) |
| 82 | { |
| 83 | uint32_t layerFlags = 0; |
| 84 | if (flags & ISurfaceComposer::eHidden) |
| 85 | layerFlags = ISurfaceComposer::eLayerHidden; |
| 86 | |
| 87 | if (flags & ISurfaceComposer::eNonPremultiplied) |
| 88 | mPremultipliedAlpha = false; |
| 89 | |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 90 | mCurrentState.z = 0; |
| 91 | mCurrentState.w = w; |
| 92 | mCurrentState.h = h; |
| 93 | mCurrentState.requested_w = w; |
| 94 | mCurrentState.requested_h = h; |
| 95 | mCurrentState.alpha = 0xFF; |
| 96 | mCurrentState.flags = layerFlags; |
| 97 | mCurrentState.sequence = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | mCurrentState.transform.set(0, 0); |
| 99 | |
| 100 | // drawing state & current state are identical |
| 101 | mDrawingState = mCurrentState; |
| 102 | } |
| 103 | |
Mathias Agopian | ba6be54 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 104 | void LayerBase::commitTransaction() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | mDrawingState = mCurrentState; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | } |
| 107 | void LayerBase::forceVisibilityTransaction() { |
| 108 | // this can be called without SurfaceFlinger.mStateLock, but if we |
| 109 | // can atomically increment the sequence number, it doesn't matter. |
| 110 | android_atomic_inc(&mCurrentState.sequence); |
| 111 | requestTransaction(); |
| 112 | } |
| 113 | bool LayerBase::requestTransaction() { |
| 114 | int32_t old = setTransactionFlags(eTransactionNeeded); |
| 115 | return ((old & eTransactionNeeded) == 0); |
| 116 | } |
| 117 | uint32_t LayerBase::getTransactionFlags(uint32_t flags) { |
| 118 | return android_atomic_and(~flags, &mTransactionFlags) & flags; |
| 119 | } |
| 120 | uint32_t LayerBase::setTransactionFlags(uint32_t flags) { |
| 121 | return android_atomic_or(flags, &mTransactionFlags); |
| 122 | } |
| 123 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | bool LayerBase::setPosition(int32_t x, int32_t y) { |
| 125 | if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y) |
| 126 | return false; |
| 127 | mCurrentState.sequence++; |
| 128 | mCurrentState.transform.set(x, y); |
| 129 | requestTransaction(); |
| 130 | return true; |
| 131 | } |
| 132 | bool LayerBase::setLayer(uint32_t z) { |
| 133 | if (mCurrentState.z == z) |
| 134 | return false; |
| 135 | mCurrentState.sequence++; |
| 136 | mCurrentState.z = z; |
| 137 | requestTransaction(); |
| 138 | return true; |
| 139 | } |
| 140 | bool LayerBase::setSize(uint32_t w, uint32_t h) { |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 141 | if (mCurrentState.requested_w == w && mCurrentState.requested_h == h) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | return false; |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 143 | mCurrentState.requested_w = w; |
| 144 | mCurrentState.requested_h = h; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | requestTransaction(); |
| 146 | return true; |
| 147 | } |
| 148 | bool LayerBase::setAlpha(uint8_t alpha) { |
| 149 | if (mCurrentState.alpha == alpha) |
| 150 | return false; |
| 151 | mCurrentState.sequence++; |
| 152 | mCurrentState.alpha = alpha; |
| 153 | requestTransaction(); |
| 154 | return true; |
| 155 | } |
| 156 | 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] | 157 | mCurrentState.sequence++; |
| 158 | mCurrentState.transform.set( |
| 159 | matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy); |
| 160 | requestTransaction(); |
| 161 | return true; |
| 162 | } |
| 163 | bool LayerBase::setTransparentRegionHint(const Region& transparent) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | mCurrentState.sequence++; |
| 165 | mCurrentState.transparentRegion = transparent; |
| 166 | requestTransaction(); |
| 167 | return true; |
| 168 | } |
| 169 | bool LayerBase::setFlags(uint8_t flags, uint8_t mask) { |
| 170 | const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask); |
| 171 | if (mCurrentState.flags == newFlags) |
| 172 | return false; |
| 173 | mCurrentState.sequence++; |
| 174 | mCurrentState.flags = newFlags; |
| 175 | requestTransaction(); |
| 176 | return true; |
| 177 | } |
| 178 | |
| 179 | Rect LayerBase::visibleBounds() const |
| 180 | { |
| 181 | return mTransformedBounds; |
| 182 | } |
| 183 | |
| 184 | void LayerBase::setVisibleRegion(const Region& visibleRegion) { |
| 185 | // always called from main thread |
| 186 | visibleRegionScreen = visibleRegion; |
| 187 | } |
| 188 | |
| 189 | void LayerBase::setCoveredRegion(const Region& coveredRegion) { |
| 190 | // always called from main thread |
| 191 | coveredRegionScreen = coveredRegion; |
| 192 | } |
| 193 | |
| 194 | uint32_t LayerBase::doTransaction(uint32_t flags) |
| 195 | { |
| 196 | const Layer::State& front(drawingState()); |
| 197 | const Layer::State& temp(currentState()); |
| 198 | |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 199 | if ((front.requested_w != temp.requested_w) || |
| 200 | (front.requested_h != temp.requested_h)) { |
| 201 | // resize the layer, set the physical size to the requested size |
| 202 | Layer::State& editTemp(currentState()); |
| 203 | editTemp.w = temp.requested_w; |
| 204 | editTemp.h = temp.requested_h; |
| 205 | } |
| 206 | |
Mathias Agopian | 6656dbc | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 207 | if ((front.w != temp.w) || (front.h != temp.h)) { |
| 208 | // invalidate and recompute the visible regions if needed |
| 209 | flags |= Layer::eVisibleRegion; |
Mathias Agopian | 6656dbc | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 210 | } |
| 211 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | if (temp.sequence != front.sequence) { |
| 213 | // invalidate and recompute the visible regions if needed |
| 214 | flags |= eVisibleRegion; |
| 215 | this->contentDirty = true; |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 216 | |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 217 | mNeedsFiltering = false; |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 218 | if (!(mFlags & DisplayHardware::SLOW_CONFIG)) { |
| 219 | // we may use linear filtering, if the matrix scales us |
| 220 | const uint8_t type = temp.transform.getType(); |
| 221 | if (!temp.transform.preserveRects() || (type >= Transform::SCALE)) { |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 222 | mNeedsFiltering = true; |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | // Commit the transaction |
Mathias Agopian | ba6be54 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 228 | commitTransaction(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | return flags; |
| 230 | } |
| 231 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | void LayerBase::validateVisibility(const Transform& planeTransform) |
| 233 | { |
| 234 | const Layer::State& s(drawingState()); |
| 235 | const Transform tr(planeTransform * s.transform); |
| 236 | const bool transformed = tr.transformed(); |
| 237 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 238 | uint32_t w = s.w; |
| 239 | uint32_t h = s.h; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | tr.transform(mVertices[0], 0, 0); |
| 241 | tr.transform(mVertices[1], 0, h); |
| 242 | tr.transform(mVertices[2], w, h); |
| 243 | tr.transform(mVertices[3], w, 0); |
| 244 | if (UNLIKELY(transformed)) { |
| 245 | // NOTE: here we could also punt if we have too many rectangles |
| 246 | // in the transparent region |
| 247 | if (tr.preserveRects()) { |
| 248 | // transform the transparent region |
| 249 | transparentRegionScreen = tr.transform(s.transparentRegion); |
| 250 | } else { |
| 251 | // transformation too complex, can't do the transparent region |
| 252 | // optimization. |
| 253 | transparentRegionScreen.clear(); |
| 254 | } |
| 255 | } else { |
| 256 | transparentRegionScreen = s.transparentRegion; |
| 257 | } |
| 258 | |
| 259 | // cache a few things... |
| 260 | mOrientation = tr.getOrientation(); |
| 261 | mTransformedBounds = tr.makeBounds(w, h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | mLeft = tr.tx(); |
| 263 | mTop = tr.ty(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) |
| 267 | { |
| 268 | } |
| 269 | |
| 270 | void LayerBase::unlockPageFlip( |
| 271 | const Transform& planeTransform, Region& outDirtyRegion) |
| 272 | { |
| 273 | if ((android_atomic_and(~1, &mInvalidate)&1) == 1) { |
| 274 | outDirtyRegion.orSelf(visibleRegionScreen); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | void LayerBase::finishPageFlip() |
| 279 | { |
| 280 | } |
| 281 | |
| 282 | void LayerBase::invalidate() |
| 283 | { |
| 284 | if ((android_atomic_or(1, &mInvalidate)&1) == 0) { |
| 285 | mFlinger->signalEvent(); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | void LayerBase::drawRegion(const Region& reg) const |
| 290 | { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 291 | Region::const_iterator it = reg.begin(); |
| 292 | Region::const_iterator const end = reg.end(); |
| 293 | if (it != end) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | Rect r; |
| 295 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 296 | const int32_t fbWidth = hw.getWidth(); |
| 297 | const int32_t fbHeight = hw.getHeight(); |
| 298 | const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 }, |
| 299 | { fbWidth, fbHeight }, { 0, fbHeight } }; |
| 300 | glVertexPointer(2, GL_SHORT, 0, vertices); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 301 | while (it != end) { |
| 302 | const Rect& r = *it++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | const GLint sy = fbHeight - (r.top + r.height()); |
| 304 | glScissor(r.left, sy, r.width(), r.height()); |
| 305 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame^] | 310 | void LayerBase::setGeometry(hwc_layer_t* hwcl) { |
| 311 | hwcl->flags |= HWC_SKIP_LAYER; |
| 312 | } |
| 313 | |
| 314 | void LayerBase::setPerFrameData(hwc_layer_t* hwcl) { |
| 315 | hwcl->compositionType = HWC_FRAMEBUFFER; |
| 316 | hwcl->handle = NULL; |
| 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 | 010fccb | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 327 | void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red, |
| 328 | GLclampf green, GLclampf blue, |
| 329 | GLclampf alpha) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | { |
| 331 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 332 | const uint32_t fbHeight = hw.getHeight(); |
Mathias Agopian | 010fccb | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 333 | glColor4f(red,green,blue,alpha); |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 334 | |
| 335 | TextureManager::deactivateTextures(); |
| 336 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | glDisable(GL_BLEND); |
| 338 | glDisable(GL_DITHER); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 339 | |
| 340 | Region::const_iterator it = clip.begin(); |
| 341 | Region::const_iterator const end = clip.end(); |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 342 | glEnable(GL_SCISSOR_TEST); |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 343 | glVertexPointer(2, GL_FLOAT, 0, mVertices); |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 344 | while (it != end) { |
| 345 | const Rect& r = *it++; |
| 346 | const GLint sy = fbHeight - (r.top + r.height()); |
| 347 | glScissor(r.left, sy, r.width(), r.height()); |
| 348 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 352 | void LayerBase::clearWithOpenGL(const Region& clip) const |
| 353 | { |
| 354 | clearWithOpenGL(clip,0,0,0,0); |
| 355 | } |
| 356 | |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 357 | void LayerBase::drawWithOpenGL(const Region& clip, const Texture& texture) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | { |
| 359 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 360 | const uint32_t fbHeight = hw.getHeight(); |
| 361 | const State& s(drawingState()); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 362 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | // bind our texture |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 364 | TextureManager::activateTexture(texture, needsFiltering()); |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 365 | uint32_t width = texture.width; |
| 366 | uint32_t height = texture.height; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 368 | GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | if (UNLIKELY(s.alpha < 0xFF)) { |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 370 | const GLfloat alpha = s.alpha * (1.0f/255.0f); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 371 | if (mPremultipliedAlpha) { |
| 372 | glColor4f(alpha, alpha, alpha, alpha); |
| 373 | } else { |
| 374 | glColor4f(1, 1, 1, alpha); |
| 375 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | glEnable(GL_BLEND); |
| 377 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 378 | 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] | 379 | } else { |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 380 | glColor4f(1, 1, 1, 1); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 381 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | if (needsBlending()) { |
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); |
| 385 | } else { |
| 386 | glDisable(GL_BLEND); |
| 387 | } |
| 388 | } |
| 389 | |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 390 | Region::const_iterator it = clip.begin(); |
| 391 | Region::const_iterator const end = clip.end(); |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 392 | const GLfloat texCoords[4][2] = { |
| 393 | { 0, 0 }, |
| 394 | { 0, 1 }, |
| 395 | { 1, 1 }, |
| 396 | { 1, 0 } |
| 397 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 399 | glMatrixMode(GL_TEXTURE); |
| 400 | glLoadIdentity(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 402 | // the texture's source is rotated |
| 403 | switch (texture.transform) { |
| 404 | case HAL_TRANSFORM_ROT_90: |
| 405 | glTranslatef(0, 1, 0); |
| 406 | glRotatef(-90, 0, 0, 1); |
| 407 | break; |
| 408 | case HAL_TRANSFORM_ROT_180: |
| 409 | glTranslatef(1, 1, 0); |
| 410 | glRotatef(-180, 0, 0, 1); |
| 411 | break; |
| 412 | case HAL_TRANSFORM_ROT_270: |
| 413 | glTranslatef(1, 0, 0); |
| 414 | glRotatef(-270, 0, 0, 1); |
| 415 | break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | } |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 417 | |
| 418 | if (texture.NPOTAdjust) { |
| 419 | glScalef(texture.wScale, texture.hScale, 1.0f); |
| 420 | } |
| 421 | |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 422 | if (needsDithering()) { |
| 423 | glEnable(GL_DITHER); |
| 424 | } else { |
| 425 | glDisable(GL_DITHER); |
| 426 | } |
| 427 | |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 428 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 429 | glVertexPointer(2, GL_FLOAT, 0, mVertices); |
| 430 | glTexCoordPointer(2, GL_FLOAT, 0, texCoords); |
| 431 | |
| 432 | while (it != end) { |
| 433 | const Rect& r = *it++; |
| 434 | const GLint sy = fbHeight - (r.top + r.height()); |
| 435 | glScissor(r.left, sy, r.width(), r.height()); |
| 436 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 437 | } |
| 438 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 441 | void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const |
| 442 | { |
| 443 | const Layer::State& s(drawingState()); |
| 444 | snprintf(buffer, SIZE, |
| 445 | "+ %s %p\n" |
| 446 | " " |
| 447 | "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), " |
| 448 | "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, " |
| 449 | "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n", |
| 450 | getTypeId(), this, s.z, tx(), ty(), s.w, s.h, |
| 451 | needsBlending(), needsDithering(), contentDirty, |
| 452 | s.alpha, s.flags, |
| 453 | s.transform[0][0], s.transform[0][1], |
| 454 | s.transform[1][0], s.transform[1][1]); |
| 455 | result.append(buffer); |
| 456 | } |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 457 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | // --------------------------------------------------------------------------- |
| 459 | |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 460 | int32_t LayerBaseClient::sIdentity = 1; |
Mathias Agopian | 2e12324 | 2009-06-23 20:06:46 -0700 | [diff] [blame] | 461 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display, |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 463 | const sp<Client>& client) |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 464 | : LayerBase(flinger, display), 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 | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 477 | sp<LayerBaseClient::Surface> LayerBaseClient::getSurface() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 479 | sp<Surface> s; |
| 480 | Mutex::Autolock _l(mLock); |
| 481 | s = mClientSurface.promote(); |
| 482 | if (s == 0) { |
| 483 | s = createSurface(); |
| 484 | mClientSurface = s; |
| 485 | } |
| 486 | return s; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 489 | sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const |
| 490 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 491 | return new Surface(mFlinger, mIdentity, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 492 | const_cast<LayerBaseClient *>(this)); |
| 493 | } |
| 494 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 495 | void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const |
| 496 | { |
| 497 | LayerBase::dump(result, buffer, SIZE); |
| 498 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 499 | sp<Client> client(mClientRef.promote()); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 500 | snprintf(buffer, SIZE, |
| 501 | " name=%s\n" |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 502 | " client=%p, identity=%u\n", |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 503 | getName().string(), |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 504 | client.get(), getIdentity()); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 505 | |
| 506 | result.append(buffer); |
| 507 | } |
| 508 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 509 | // --------------------------------------------------------------------------- |
| 510 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 511 | LayerBaseClient::Surface::Surface( |
| 512 | const sp<SurfaceFlinger>& flinger, |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 513 | int identity, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 514 | const sp<LayerBaseClient>& owner) |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 515 | : mFlinger(flinger), mIdentity(identity), mOwner(owner) |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 516 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 519 | LayerBaseClient::Surface::~Surface() |
| 520 | { |
| 521 | /* |
| 522 | * This is a good place to clean-up all client resources |
| 523 | */ |
| 524 | |
| 525 | // destroy client resources |
| 526 | sp<LayerBaseClient> layer = getOwner(); |
| 527 | if (layer != 0) { |
| 528 | mFlinger->destroySurface(layer); |
| 529 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const { |
| 533 | sp<LayerBaseClient> owner(mOwner.promote()); |
| 534 | return owner; |
| 535 | } |
| 536 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 537 | status_t LayerBaseClient::Surface::onTransact( |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 538 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 539 | { |
| 540 | switch (code) { |
| 541 | case REGISTER_BUFFERS: |
| 542 | case UNREGISTER_BUFFERS: |
| 543 | case CREATE_OVERLAY: |
| 544 | { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 545 | if (!mFlinger->mAccessSurfaceFlinger.checkCalling()) { |
| 546 | IPCThreadState* ipc = IPCThreadState::self(); |
| 547 | const int pid = ipc->getCallingPid(); |
| 548 | const int uid = ipc->getCallingUid(); |
| 549 | LOGE("Permission Denial: " |
| 550 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); |
| 551 | return PERMISSION_DENIED; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | } |
| 555 | return BnSurface::onTransact(code, data, reply, flags); |
| 556 | } |
| 557 | |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 558 | sp<GraphicBuffer> LayerBaseClient::Surface::requestBuffer(int bufferIdx, |
| 559 | uint32_t w, uint32_t h, uint32_t format, uint32_t usage) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 560 | { |
| 561 | return NULL; |
| 562 | } |
| 563 | |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 564 | status_t LayerBaseClient::Surface::setBufferCount(int bufferCount) |
| 565 | { |
| 566 | return INVALID_OPERATION; |
| 567 | } |
| 568 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 569 | status_t LayerBaseClient::Surface::registerBuffers( |
| 570 | const ISurface::BufferHeap& buffers) |
| 571 | { |
| 572 | return INVALID_OPERATION; |
| 573 | } |
| 574 | |
| 575 | void LayerBaseClient::Surface::postBuffer(ssize_t offset) |
| 576 | { |
| 577 | } |
| 578 | |
| 579 | void LayerBaseClient::Surface::unregisterBuffers() |
| 580 | { |
| 581 | } |
| 582 | |
| 583 | sp<OverlayRef> LayerBaseClient::Surface::createOverlay( |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 584 | uint32_t w, uint32_t h, int32_t format, int32_t orientation) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 585 | { |
| 586 | return NULL; |
| 587 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | |
| 589 | // --------------------------------------------------------------------------- |
| 590 | |
| 591 | }; // namespace android |