The Android Open Source Project | 9066cfe | 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 | 9066cfe | 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 | 947f4f4 | 2009-05-22 01:27:01 -0700 | [diff] [blame] | 23 | #include <binder/IPCThreadState.h> |
| 24 | #include <binder/IServiceManager.h> |
The Android Open Source Project | 9066cfe | 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 | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | #include "SurfaceFlinger.h" |
| 34 | #include "DisplayHardware/DisplayHardware.h" |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 35 | #include "TextureManager.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | namespace android { |
| 39 | |
| 40 | // --------------------------------------------------------------------------- |
| 41 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display) |
| 43 | : dpy(display), contentDirty(false), |
| 44 | mFlinger(flinger), |
Mathias Agopian | 9237703 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 45 | mNeedsFiltering(false), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | mOrientation(0), |
Mathias Agopian | ed2ab7f | 2010-02-19 17:51:58 -0800 | [diff] [blame] | 47 | mLeft(0), mTop(0), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | mTransactionFlags(0), |
Mathias Agopian | a8a0aa8 | 2010-04-21 15:24:11 -0700 | [diff] [blame] | 49 | mPremultipliedAlpha(true), mName("unnamed"), mDebug(false), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | mInvalidate(0) |
| 51 | { |
| 52 | const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware()); |
| 53 | mFlags = hw.getFlags(); |
| 54 | } |
| 55 | |
| 56 | LayerBase::~LayerBase() |
| 57 | { |
| 58 | } |
| 59 | |
Mathias Agopian | 015b597 | 2010-03-09 19:17:47 -0800 | [diff] [blame] | 60 | void LayerBase::setName(const String8& name) { |
| 61 | mName = name; |
| 62 | } |
| 63 | |
| 64 | String8 LayerBase::getName() const { |
| 65 | return mName; |
| 66 | } |
| 67 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | const GraphicPlane& LayerBase::graphicPlane(int dpy) const |
| 69 | { |
| 70 | return mFlinger->graphicPlane(dpy); |
| 71 | } |
| 72 | |
| 73 | GraphicPlane& LayerBase::graphicPlane(int dpy) |
| 74 | { |
| 75 | return mFlinger->graphicPlane(dpy); |
| 76 | } |
| 77 | |
| 78 | void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags) |
| 79 | { |
| 80 | uint32_t layerFlags = 0; |
| 81 | if (flags & ISurfaceComposer::eHidden) |
| 82 | layerFlags = ISurfaceComposer::eLayerHidden; |
| 83 | |
| 84 | if (flags & ISurfaceComposer::eNonPremultiplied) |
| 85 | mPremultipliedAlpha = false; |
| 86 | |
Mathias Agopian | e1b6f24 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 87 | mCurrentState.z = 0; |
| 88 | mCurrentState.w = w; |
| 89 | mCurrentState.h = h; |
| 90 | mCurrentState.requested_w = w; |
| 91 | mCurrentState.requested_h = h; |
| 92 | mCurrentState.alpha = 0xFF; |
| 93 | mCurrentState.flags = layerFlags; |
| 94 | mCurrentState.sequence = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | mCurrentState.transform.set(0, 0); |
| 96 | |
| 97 | // drawing state & current state are identical |
| 98 | mDrawingState = mCurrentState; |
| 99 | } |
| 100 | |
Mathias Agopian | 8851617 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 101 | void LayerBase::commitTransaction() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | mDrawingState = mCurrentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | } |
| 104 | void LayerBase::forceVisibilityTransaction() { |
| 105 | // this can be called without SurfaceFlinger.mStateLock, but if we |
| 106 | // can atomically increment the sequence number, it doesn't matter. |
| 107 | android_atomic_inc(&mCurrentState.sequence); |
| 108 | requestTransaction(); |
| 109 | } |
| 110 | bool LayerBase::requestTransaction() { |
| 111 | int32_t old = setTransactionFlags(eTransactionNeeded); |
| 112 | return ((old & eTransactionNeeded) == 0); |
| 113 | } |
| 114 | uint32_t LayerBase::getTransactionFlags(uint32_t flags) { |
| 115 | return android_atomic_and(~flags, &mTransactionFlags) & flags; |
| 116 | } |
| 117 | uint32_t LayerBase::setTransactionFlags(uint32_t flags) { |
| 118 | return android_atomic_or(flags, &mTransactionFlags); |
| 119 | } |
| 120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | bool LayerBase::setPosition(int32_t x, int32_t y) { |
| 122 | if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y) |
| 123 | return false; |
| 124 | mCurrentState.sequence++; |
| 125 | mCurrentState.transform.set(x, y); |
| 126 | requestTransaction(); |
| 127 | return true; |
| 128 | } |
| 129 | bool LayerBase::setLayer(uint32_t z) { |
| 130 | if (mCurrentState.z == z) |
| 131 | return false; |
| 132 | mCurrentState.sequence++; |
| 133 | mCurrentState.z = z; |
| 134 | requestTransaction(); |
| 135 | return true; |
| 136 | } |
| 137 | bool LayerBase::setSize(uint32_t w, uint32_t h) { |
Mathias Agopian | e1b6f24 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 138 | if (mCurrentState.requested_w == w && mCurrentState.requested_h == h) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | return false; |
Mathias Agopian | e1b6f24 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 140 | mCurrentState.requested_w = w; |
| 141 | mCurrentState.requested_h = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | requestTransaction(); |
| 143 | return true; |
| 144 | } |
| 145 | bool LayerBase::setAlpha(uint8_t alpha) { |
| 146 | if (mCurrentState.alpha == alpha) |
| 147 | return false; |
| 148 | mCurrentState.sequence++; |
| 149 | mCurrentState.alpha = alpha; |
| 150 | requestTransaction(); |
| 151 | return true; |
| 152 | } |
| 153 | bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) { |
| 154 | // TODO: check the matrix has changed |
| 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) { |
| 162 | // TODO: check the region has changed |
| 163 | mCurrentState.sequence++; |
| 164 | mCurrentState.transparentRegion = transparent; |
| 165 | requestTransaction(); |
| 166 | return true; |
| 167 | } |
| 168 | bool LayerBase::setFlags(uint8_t flags, uint8_t mask) { |
| 169 | const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask); |
| 170 | if (mCurrentState.flags == newFlags) |
| 171 | return false; |
| 172 | mCurrentState.sequence++; |
| 173 | mCurrentState.flags = newFlags; |
| 174 | requestTransaction(); |
| 175 | return true; |
| 176 | } |
| 177 | |
| 178 | Rect LayerBase::visibleBounds() const |
| 179 | { |
| 180 | return mTransformedBounds; |
| 181 | } |
| 182 | |
| 183 | void LayerBase::setVisibleRegion(const Region& visibleRegion) { |
| 184 | // always called from main thread |
| 185 | visibleRegionScreen = visibleRegion; |
| 186 | } |
| 187 | |
| 188 | void LayerBase::setCoveredRegion(const Region& coveredRegion) { |
| 189 | // always called from main thread |
| 190 | coveredRegionScreen = coveredRegion; |
| 191 | } |
| 192 | |
| 193 | uint32_t LayerBase::doTransaction(uint32_t flags) |
| 194 | { |
| 195 | const Layer::State& front(drawingState()); |
| 196 | const Layer::State& temp(currentState()); |
| 197 | |
Mathias Agopian | e1b6f24 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 198 | if ((front.requested_w != temp.requested_w) || |
| 199 | (front.requested_h != temp.requested_h)) { |
| 200 | // resize the layer, set the physical size to the requested size |
| 201 | Layer::State& editTemp(currentState()); |
| 202 | editTemp.w = temp.requested_w; |
| 203 | editTemp.h = temp.requested_h; |
| 204 | } |
| 205 | |
Mathias Agopian | 70cab91 | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 206 | if ((front.w != temp.w) || (front.h != temp.h)) { |
| 207 | // invalidate and recompute the visible regions if needed |
| 208 | flags |= Layer::eVisibleRegion; |
Mathias Agopian | 70cab91 | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 209 | } |
| 210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | if (temp.sequence != front.sequence) { |
| 212 | // invalidate and recompute the visible regions if needed |
| 213 | flags |= eVisibleRegion; |
| 214 | this->contentDirty = true; |
Mathias Agopian | 44cac13 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 215 | |
Mathias Agopian | 9237703 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 216 | mNeedsFiltering = false; |
Mathias Agopian | 44cac13 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 217 | if (!(mFlags & DisplayHardware::SLOW_CONFIG)) { |
| 218 | // we may use linear filtering, if the matrix scales us |
| 219 | const uint8_t type = temp.transform.getType(); |
| 220 | if (!temp.transform.preserveRects() || (type >= Transform::SCALE)) { |
Mathias Agopian | 9237703 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 221 | mNeedsFiltering = true; |
Mathias Agopian | 44cac13 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | // Commit the transaction |
Mathias Agopian | 8851617 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 227 | commitTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | return flags; |
| 229 | } |
| 230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | void LayerBase::validateVisibility(const Transform& planeTransform) |
| 232 | { |
| 233 | const Layer::State& s(drawingState()); |
| 234 | const Transform tr(planeTransform * s.transform); |
| 235 | const bool transformed = tr.transformed(); |
| 236 | |
Mathias Agopian | 9779b22 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 237 | uint32_t w = s.w; |
| 238 | uint32_t h = s.h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | tr.transform(mVertices[0], 0, 0); |
| 240 | tr.transform(mVertices[1], 0, h); |
| 241 | tr.transform(mVertices[2], w, h); |
| 242 | tr.transform(mVertices[3], w, 0); |
| 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(); |
| 260 | mTransformedBounds = tr.makeBounds(w, h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | mLeft = tr.tx(); |
| 262 | mTop = tr.ty(); |
The Android Open Source Project | 9066cfe | 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 | |
| 277 | void LayerBase::finishPageFlip() |
| 278 | { |
| 279 | } |
| 280 | |
| 281 | void LayerBase::invalidate() |
| 282 | { |
| 283 | if ((android_atomic_or(1, &mInvalidate)&1) == 0) { |
| 284 | mFlinger->signalEvent(); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void LayerBase::drawRegion(const Region& reg) const |
| 289 | { |
Mathias Agopian | 6158b1b | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 290 | Region::const_iterator it = reg.begin(); |
| 291 | Region::const_iterator const end = reg.end(); |
| 292 | if (it != end) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | Rect r; |
| 294 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 295 | const int32_t fbWidth = hw.getWidth(); |
| 296 | const int32_t fbHeight = hw.getHeight(); |
| 297 | const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 }, |
| 298 | { fbWidth, fbHeight }, { 0, fbHeight } }; |
| 299 | glVertexPointer(2, GL_SHORT, 0, vertices); |
Mathias Agopian | 6158b1b | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 300 | while (it != end) { |
| 301 | const Rect& r = *it++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | const GLint sy = fbHeight - (r.top + r.height()); |
| 303 | glScissor(r.left, sy, r.width(), r.height()); |
| 304 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | void LayerBase::draw(const Region& inClip) const |
| 310 | { |
| 311 | // invalidate the region we'll update |
| 312 | Region clip(inClip); // copy-on-write, so no-op most of the time |
| 313 | |
| 314 | // Remove the transparent area from the clipping region |
| 315 | const State& s = drawingState(); |
| 316 | if (LIKELY(!s.transparentRegion.isEmpty())) { |
| 317 | clip.subtract(transparentRegionScreen); |
| 318 | if (clip.isEmpty()) { |
| 319 | // usually this won't happen because this should be taken care of |
| 320 | // by SurfaceFlinger::computeVisibleRegions() |
| 321 | return; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | // reset GL state |
| 326 | glEnable(GL_SCISSOR_TEST); |
| 327 | |
| 328 | onDraw(clip); |
| 329 | |
| 330 | /* |
| 331 | glDisable(GL_TEXTURE_2D); |
| 332 | glDisable(GL_DITHER); |
| 333 | glEnable(GL_BLEND); |
| 334 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 335 | glColor4x(0, 0x8000, 0, 0x10000); |
| 336 | drawRegion(transparentRegionScreen); |
| 337 | glDisable(GL_BLEND); |
| 338 | */ |
| 339 | } |
| 340 | |
Mathias Agopian | 0d3c006 | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 341 | void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red, |
| 342 | GLclampf green, GLclampf blue, |
| 343 | GLclampf alpha) const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | { |
| 345 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 346 | const uint32_t fbHeight = hw.getHeight(); |
Mathias Agopian | 0d3c006 | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 347 | glColor4f(red,green,blue,alpha); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | glDisable(GL_TEXTURE_2D); |
| 349 | glDisable(GL_BLEND); |
| 350 | glDisable(GL_DITHER); |
Mathias Agopian | 6158b1b | 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 | f2d28b7 | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 354 | glEnable(GL_SCISSOR_TEST); |
Mathias Agopian | e5c0a7b | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 355 | glVertexPointer(2, GL_FLOAT, 0, mVertices); |
Mathias Agopian | f2d28b7 | 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 | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
Rebecca Schultz Zavin | c854678 | 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 | 999543b | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 369 | void LayerBase::drawWithOpenGL(const Region& clip, const Texture& texture) const |
The Android Open Source Project | 9066cfe | 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()); |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | // bind our texture |
Mathias Agopian | 999543b | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 376 | validateTexture(texture.name); |
| 377 | uint32_t width = texture.width; |
| 378 | uint32_t height = texture.height; |
| 379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | glEnable(GL_TEXTURE_2D); |
| 381 | |
Mathias Agopian | a0612e4 | 2010-04-12 15:34:55 -0700 | [diff] [blame^] | 382 | GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | if (UNLIKELY(s.alpha < 0xFF)) { |
Mathias Agopian | e5c0a7b | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 384 | const GLfloat alpha = s.alpha * (1.0f/255.0f); |
Mathias Agopian | a0612e4 | 2010-04-12 15:34:55 -0700 | [diff] [blame^] | 385 | if (mPremultipliedAlpha) { |
| 386 | glColor4f(alpha, alpha, alpha, alpha); |
| 387 | } else { |
| 388 | glColor4f(1, 1, 1, alpha); |
| 389 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | glEnable(GL_BLEND); |
| 391 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | a0612e4 | 2010-04-12 15:34:55 -0700 | [diff] [blame^] | 392 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | } else { |
Mathias Agopian | e5c0a7b | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 394 | glColor4f(1, 1, 1, 1); |
Mathias Agopian | a0612e4 | 2010-04-12 15:34:55 -0700 | [diff] [blame^] | 395 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | if (needsBlending()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | glEnable(GL_BLEND); |
| 398 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
| 399 | } else { |
| 400 | glDisable(GL_BLEND); |
| 401 | } |
| 402 | } |
| 403 | |
Mathias Agopian | f2d28b7 | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 404 | Region::const_iterator it = clip.begin(); |
| 405 | Region::const_iterator const end = clip.end(); |
Mathias Agopian | e5c0a7b | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 406 | const GLfloat texCoords[4][2] = { |
| 407 | { 0, 0 }, |
| 408 | { 0, 1 }, |
| 409 | { 1, 1 }, |
| 410 | { 1, 0 } |
| 411 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | |
Mathias Agopian | e5c0a7b | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 413 | glMatrixMode(GL_TEXTURE); |
| 414 | glLoadIdentity(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | |
Mathias Agopian | e5c0a7b | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 416 | // the texture's source is rotated |
| 417 | switch (texture.transform) { |
| 418 | case HAL_TRANSFORM_ROT_90: |
| 419 | glTranslatef(0, 1, 0); |
| 420 | glRotatef(-90, 0, 0, 1); |
| 421 | break; |
| 422 | case HAL_TRANSFORM_ROT_180: |
| 423 | glTranslatef(1, 1, 0); |
| 424 | glRotatef(-180, 0, 0, 1); |
| 425 | break; |
| 426 | case HAL_TRANSFORM_ROT_270: |
| 427 | glTranslatef(1, 0, 0); |
| 428 | glRotatef(-270, 0, 0, 1); |
| 429 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | } |
Mathias Agopian | e5c0a7b | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 431 | |
| 432 | if (texture.NPOTAdjust) { |
| 433 | glScalef(texture.wScale, texture.hScale, 1.0f); |
| 434 | } |
| 435 | |
| 436 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 437 | glVertexPointer(2, GL_FLOAT, 0, mVertices); |
| 438 | glTexCoordPointer(2, GL_FLOAT, 0, texCoords); |
| 439 | |
| 440 | while (it != end) { |
| 441 | const Rect& r = *it++; |
| 442 | const GLint sy = fbHeight - (r.top + r.height()); |
| 443 | glScissor(r.left, sy, r.width(), r.height()); |
| 444 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 445 | } |
| 446 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void LayerBase::validateTexture(GLint textureName) const |
| 450 | { |
| 451 | glBindTexture(GL_TEXTURE_2D, textureName); |
| 452 | // TODO: reload the texture if needed |
| 453 | // this is currently done in loadTexture() below |
Mathias Agopian | 9237703 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 454 | if (needsFiltering()) { |
Mathias Agopian | 44cac13 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 455 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 456 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 457 | } else { |
| 458 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 459 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 460 | } |
Mathias Agopian | cc93476 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 461 | |
| 462 | if (needsDithering()) { |
| 463 | glEnable(GL_DITHER); |
| 464 | } else { |
| 465 | glDisable(GL_DITHER); |
| 466 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 469 | void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const |
| 470 | { |
| 471 | const Layer::State& s(drawingState()); |
| 472 | snprintf(buffer, SIZE, |
| 473 | "+ %s %p\n" |
| 474 | " " |
| 475 | "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), " |
| 476 | "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, " |
| 477 | "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n", |
| 478 | getTypeId(), this, s.z, tx(), ty(), s.w, s.h, |
| 479 | needsBlending(), needsDithering(), contentDirty, |
| 480 | s.alpha, s.flags, |
| 481 | s.transform[0][0], s.transform[0][1], |
| 482 | s.transform[1][0], s.transform[1][1]); |
| 483 | result.append(buffer); |
| 484 | } |
Mathias Agopian | 9042b45 | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | // --------------------------------------------------------------------------- |
| 487 | |
Mathias Agopian | 2ce19af | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 488 | int32_t LayerBaseClient::sIdentity = 1; |
Mathias Agopian | c660395 | 2009-06-23 20:06:46 -0700 | [diff] [blame] | 489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display, |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 491 | const sp<Client>& client, int32_t i) |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 492 | : LayerBase(flinger, display), client(client), mIndex(i), |
Mathias Agopian | 85b8d12 | 2010-03-08 19:29:09 -0800 | [diff] [blame] | 493 | mIdentity(uint32_t(android_atomic_inc(&sIdentity))) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 495 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 497 | void LayerBaseClient::onFirstRef() |
| 498 | { |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 499 | sp<Client> client(this->client.promote()); |
| 500 | if (client != 0) { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 501 | client->bindLayer(this, mIndex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
| 505 | LayerBaseClient::~LayerBaseClient() |
| 506 | { |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 507 | sp<Client> client(this->client.promote()); |
| 508 | if (client != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | client->free(mIndex); |
| 510 | } |
| 511 | } |
| 512 | |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 513 | ssize_t LayerBaseClient::serverIndex() const |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 514 | { |
| 515 | sp<Client> client(this->client.promote()); |
| 516 | if (client != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | return (client->cid<<16)|mIndex; |
| 518 | } |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 519 | return ssize_t(0xFFFF0000 | mIndex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | } |
| 521 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 522 | sp<LayerBaseClient::Surface> LayerBaseClient::getSurface() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 524 | sp<Surface> s; |
| 525 | Mutex::Autolock _l(mLock); |
| 526 | s = mClientSurface.promote(); |
| 527 | if (s == 0) { |
| 528 | s = createSurface(); |
| 529 | mClientSurface = s; |
| 530 | } |
| 531 | return s; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | } |
| 533 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 534 | sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const |
| 535 | { |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 536 | return new Surface(mFlinger, clientIndex(), mIdentity, |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 537 | const_cast<LayerBaseClient *>(this)); |
| 538 | } |
| 539 | |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 540 | void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const |
| 541 | { |
| 542 | LayerBase::dump(result, buffer, SIZE); |
| 543 | |
| 544 | sp<Client> client(this->client.promote()); |
| 545 | snprintf(buffer, SIZE, |
| 546 | " name=%s\n" |
| 547 | " id=0x%08x, client=0x%08x, identity=%u\n", |
| 548 | getName().string(), |
| 549 | clientIndex(), client.get() ? client->cid : 0, |
| 550 | getIdentity()); |
| 551 | |
| 552 | result.append(buffer); |
| 553 | } |
| 554 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 555 | // --------------------------------------------------------------------------- |
| 556 | |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 557 | LayerBaseClient::Surface::Surface( |
| 558 | const sp<SurfaceFlinger>& flinger, |
| 559 | SurfaceID id, int identity, |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 560 | const sp<LayerBaseClient>& owner) |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 561 | : mFlinger(flinger), mToken(id), mIdentity(identity), mOwner(owner) |
| 562 | { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 565 | LayerBaseClient::Surface::~Surface() |
| 566 | { |
| 567 | /* |
| 568 | * This is a good place to clean-up all client resources |
| 569 | */ |
| 570 | |
| 571 | // destroy client resources |
| 572 | sp<LayerBaseClient> layer = getOwner(); |
| 573 | if (layer != 0) { |
| 574 | mFlinger->destroySurface(layer); |
| 575 | } |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const { |
| 579 | sp<LayerBaseClient> owner(mOwner.promote()); |
| 580 | return owner; |
| 581 | } |
| 582 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 583 | status_t LayerBaseClient::Surface::onTransact( |
Mathias Agopian | 151e859 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 584 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 585 | { |
| 586 | switch (code) { |
| 587 | case REGISTER_BUFFERS: |
| 588 | case UNREGISTER_BUFFERS: |
| 589 | case CREATE_OVERLAY: |
| 590 | { |
Mathias Agopian | 151e859 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 591 | if (!mFlinger->mAccessSurfaceFlinger.checkCalling()) { |
| 592 | IPCThreadState* ipc = IPCThreadState::self(); |
| 593 | const int pid = ipc->getCallingPid(); |
| 594 | const int uid = ipc->getCallingUid(); |
| 595 | LOGE("Permission Denial: " |
| 596 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); |
| 597 | return PERMISSION_DENIED; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | } |
| 601 | return BnSurface::onTransact(code, data, reply, flags); |
| 602 | } |
| 603 | |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 604 | sp<GraphicBuffer> LayerBaseClient::Surface::requestBuffer(int bufferIdx, |
| 605 | uint32_t w, uint32_t h, uint32_t format, uint32_t usage) |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 606 | { |
| 607 | return NULL; |
| 608 | } |
| 609 | |
Mathias Agopian | 59751db | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 610 | status_t LayerBaseClient::Surface::setBufferCount(int bufferCount) |
| 611 | { |
| 612 | return INVALID_OPERATION; |
| 613 | } |
| 614 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 615 | status_t LayerBaseClient::Surface::registerBuffers( |
| 616 | const ISurface::BufferHeap& buffers) |
| 617 | { |
| 618 | return INVALID_OPERATION; |
| 619 | } |
| 620 | |
| 621 | void LayerBaseClient::Surface::postBuffer(ssize_t offset) |
| 622 | { |
| 623 | } |
| 624 | |
| 625 | void LayerBaseClient::Surface::unregisterBuffers() |
| 626 | { |
| 627 | } |
| 628 | |
| 629 | sp<OverlayRef> LayerBaseClient::Surface::createOverlay( |
Chih-Chung Chang | e1ceec2 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 630 | uint32_t w, uint32_t h, int32_t format, int32_t orientation) |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 631 | { |
| 632 | return NULL; |
| 633 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | |
| 635 | // --------------------------------------------------------------------------- |
| 636 | |
| 637 | }; // namespace android |