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 | |
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), |
| 44 | mFlinger(flinger), |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 45 | mNeedsFiltering(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | mOrientation(0), |
Mathias Agopian | ca6fab2 | 2010-02-19 17:51:58 -0800 | [diff] [blame] | 47 | mLeft(0), mTop(0), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | mTransactionFlags(0), |
Mathias Agopian | 245e4d7 | 2010-04-21 15:24:11 -0700 | [diff] [blame] | 49 | mPremultipliedAlpha(true), mName("unnamed"), mDebug(false), |
The Android Open Source Project | edbf3b6 | 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 | d129659 | 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 | edbf3b6 | 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 | 7e4a587 | 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 | edbf3b6 | 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 | ba6be54 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 101 | void LayerBase::commitTransaction() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | mDrawingState = mCurrentState; |
The Android Open Source Project | edbf3b6 | 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 | edbf3b6 | 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 | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 138 | if (mCurrentState.requested_w == w && mCurrentState.requested_h == h) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | return false; |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 140 | mCurrentState.requested_w = w; |
| 141 | mCurrentState.requested_h = h; |
The Android Open Source Project | edbf3b6 | 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) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | mCurrentState.sequence++; |
| 155 | mCurrentState.transform.set( |
| 156 | matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy); |
| 157 | requestTransaction(); |
| 158 | return true; |
| 159 | } |
| 160 | bool LayerBase::setTransparentRegionHint(const Region& transparent) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | mCurrentState.sequence++; |
| 162 | mCurrentState.transparentRegion = transparent; |
| 163 | requestTransaction(); |
| 164 | return true; |
| 165 | } |
| 166 | bool LayerBase::setFlags(uint8_t flags, uint8_t mask) { |
| 167 | const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask); |
| 168 | if (mCurrentState.flags == newFlags) |
| 169 | return false; |
| 170 | mCurrentState.sequence++; |
| 171 | mCurrentState.flags = newFlags; |
| 172 | requestTransaction(); |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | Rect LayerBase::visibleBounds() const |
| 177 | { |
| 178 | return mTransformedBounds; |
| 179 | } |
| 180 | |
| 181 | void LayerBase::setVisibleRegion(const Region& visibleRegion) { |
| 182 | // always called from main thread |
| 183 | visibleRegionScreen = visibleRegion; |
| 184 | } |
| 185 | |
| 186 | void LayerBase::setCoveredRegion(const Region& coveredRegion) { |
| 187 | // always called from main thread |
| 188 | coveredRegionScreen = coveredRegion; |
| 189 | } |
| 190 | |
| 191 | uint32_t LayerBase::doTransaction(uint32_t flags) |
| 192 | { |
| 193 | const Layer::State& front(drawingState()); |
| 194 | const Layer::State& temp(currentState()); |
| 195 | |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 196 | if ((front.requested_w != temp.requested_w) || |
| 197 | (front.requested_h != temp.requested_h)) { |
| 198 | // resize the layer, set the physical size to the requested size |
| 199 | Layer::State& editTemp(currentState()); |
| 200 | editTemp.w = temp.requested_w; |
| 201 | editTemp.h = temp.requested_h; |
| 202 | } |
| 203 | |
Mathias Agopian | 6656dbc | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 204 | if ((front.w != temp.w) || (front.h != temp.h)) { |
| 205 | // invalidate and recompute the visible regions if needed |
| 206 | flags |= Layer::eVisibleRegion; |
Mathias Agopian | 6656dbc | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 207 | } |
| 208 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | if (temp.sequence != front.sequence) { |
| 210 | // invalidate and recompute the visible regions if needed |
| 211 | flags |= eVisibleRegion; |
| 212 | this->contentDirty = true; |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 213 | |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 214 | mNeedsFiltering = false; |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 215 | if (!(mFlags & DisplayHardware::SLOW_CONFIG)) { |
| 216 | // we may use linear filtering, if the matrix scales us |
| 217 | const uint8_t type = temp.transform.getType(); |
| 218 | if (!temp.transform.preserveRects() || (type >= Transform::SCALE)) { |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 219 | mNeedsFiltering = true; |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | // Commit the transaction |
Mathias Agopian | ba6be54 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 225 | commitTransaction(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | return flags; |
| 227 | } |
| 228 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | void LayerBase::validateVisibility(const Transform& planeTransform) |
| 230 | { |
| 231 | const Layer::State& s(drawingState()); |
| 232 | const Transform tr(planeTransform * s.transform); |
| 233 | const bool transformed = tr.transformed(); |
| 234 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 235 | uint32_t w = s.w; |
| 236 | uint32_t h = s.h; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | tr.transform(mVertices[0], 0, 0); |
| 238 | tr.transform(mVertices[1], 0, h); |
| 239 | tr.transform(mVertices[2], w, h); |
| 240 | tr.transform(mVertices[3], w, 0); |
| 241 | if (UNLIKELY(transformed)) { |
| 242 | // NOTE: here we could also punt if we have too many rectangles |
| 243 | // in the transparent region |
| 244 | if (tr.preserveRects()) { |
| 245 | // transform the transparent region |
| 246 | transparentRegionScreen = tr.transform(s.transparentRegion); |
| 247 | } else { |
| 248 | // transformation too complex, can't do the transparent region |
| 249 | // optimization. |
| 250 | transparentRegionScreen.clear(); |
| 251 | } |
| 252 | } else { |
| 253 | transparentRegionScreen = s.transparentRegion; |
| 254 | } |
| 255 | |
| 256 | // cache a few things... |
| 257 | mOrientation = tr.getOrientation(); |
| 258 | mTransformedBounds = tr.makeBounds(w, h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | mLeft = tr.tx(); |
| 260 | mTop = tr.ty(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) |
| 264 | { |
| 265 | } |
| 266 | |
| 267 | void LayerBase::unlockPageFlip( |
| 268 | const Transform& planeTransform, Region& outDirtyRegion) |
| 269 | { |
| 270 | if ((android_atomic_and(~1, &mInvalidate)&1) == 1) { |
| 271 | outDirtyRegion.orSelf(visibleRegionScreen); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | void LayerBase::finishPageFlip() |
| 276 | { |
| 277 | } |
| 278 | |
| 279 | void LayerBase::invalidate() |
| 280 | { |
| 281 | if ((android_atomic_or(1, &mInvalidate)&1) == 0) { |
| 282 | mFlinger->signalEvent(); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void LayerBase::drawRegion(const Region& reg) const |
| 287 | { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 288 | Region::const_iterator it = reg.begin(); |
| 289 | Region::const_iterator const end = reg.end(); |
| 290 | if (it != end) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | Rect r; |
| 292 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 293 | const int32_t fbWidth = hw.getWidth(); |
| 294 | const int32_t fbHeight = hw.getHeight(); |
| 295 | const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 }, |
| 296 | { fbWidth, fbHeight }, { 0, fbHeight } }; |
| 297 | glVertexPointer(2, GL_SHORT, 0, vertices); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 298 | while (it != end) { |
| 299 | const Rect& r = *it++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | const GLint sy = fbHeight - (r.top + r.height()); |
| 301 | glScissor(r.left, sy, r.width(), r.height()); |
| 302 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | void LayerBase::draw(const Region& inClip) const |
| 308 | { |
| 309 | // invalidate the region we'll update |
| 310 | Region clip(inClip); // copy-on-write, so no-op most of the time |
| 311 | |
| 312 | // Remove the transparent area from the clipping region |
| 313 | const State& s = drawingState(); |
| 314 | if (LIKELY(!s.transparentRegion.isEmpty())) { |
| 315 | clip.subtract(transparentRegionScreen); |
| 316 | if (clip.isEmpty()) { |
| 317 | // usually this won't happen because this should be taken care of |
| 318 | // by SurfaceFlinger::computeVisibleRegions() |
| 319 | return; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // reset GL state |
| 324 | glEnable(GL_SCISSOR_TEST); |
| 325 | |
| 326 | onDraw(clip); |
| 327 | |
| 328 | /* |
| 329 | glDisable(GL_TEXTURE_2D); |
| 330 | glDisable(GL_DITHER); |
| 331 | glEnable(GL_BLEND); |
| 332 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 333 | glColor4x(0, 0x8000, 0, 0x10000); |
| 334 | drawRegion(transparentRegionScreen); |
| 335 | glDisable(GL_BLEND); |
| 336 | */ |
| 337 | } |
| 338 | |
Mathias Agopian | 010fccb | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 339 | void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red, |
| 340 | GLclampf green, GLclampf blue, |
| 341 | GLclampf alpha) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | { |
| 343 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 344 | const uint32_t fbHeight = hw.getHeight(); |
Mathias Agopian | 010fccb | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 345 | glColor4f(red,green,blue,alpha); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | glDisable(GL_TEXTURE_2D); |
| 347 | glDisable(GL_BLEND); |
| 348 | glDisable(GL_DITHER); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 349 | |
| 350 | Region::const_iterator it = clip.begin(); |
| 351 | Region::const_iterator const end = clip.end(); |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 352 | glEnable(GL_SCISSOR_TEST); |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 353 | glVertexPointer(2, GL_FLOAT, 0, mVertices); |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 354 | while (it != end) { |
| 355 | const Rect& r = *it++; |
| 356 | const GLint sy = fbHeight - (r.top + r.height()); |
| 357 | glScissor(r.left, sy, r.width(), r.height()); |
| 358 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 362 | void LayerBase::clearWithOpenGL(const Region& clip) const |
| 363 | { |
| 364 | clearWithOpenGL(clip,0,0,0,0); |
| 365 | } |
| 366 | |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 367 | 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] | 368 | { |
| 369 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 370 | const uint32_t fbHeight = hw.getHeight(); |
| 371 | const State& s(drawingState()); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 372 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | // bind our texture |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 374 | validateTexture(texture.name); |
| 375 | uint32_t width = texture.width; |
| 376 | uint32_t height = texture.height; |
| 377 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | glEnable(GL_TEXTURE_2D); |
| 379 | |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 380 | GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | if (UNLIKELY(s.alpha < 0xFF)) { |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 382 | const GLfloat alpha = s.alpha * (1.0f/255.0f); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 383 | if (mPremultipliedAlpha) { |
| 384 | glColor4f(alpha, alpha, alpha, alpha); |
| 385 | } else { |
| 386 | glColor4f(1, 1, 1, alpha); |
| 387 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | glEnable(GL_BLEND); |
| 389 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 390 | 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] | 391 | } else { |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 392 | glColor4f(1, 1, 1, 1); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 393 | 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] | 394 | if (needsBlending()) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | glEnable(GL_BLEND); |
| 396 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
| 397 | } else { |
| 398 | glDisable(GL_BLEND); |
| 399 | } |
| 400 | } |
| 401 | |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 402 | Region::const_iterator it = clip.begin(); |
| 403 | Region::const_iterator const end = clip.end(); |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 404 | const GLfloat texCoords[4][2] = { |
| 405 | { 0, 0 }, |
| 406 | { 0, 1 }, |
| 407 | { 1, 1 }, |
| 408 | { 1, 0 } |
| 409 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 411 | glMatrixMode(GL_TEXTURE); |
| 412 | glLoadIdentity(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 414 | // the texture's source is rotated |
| 415 | switch (texture.transform) { |
| 416 | case HAL_TRANSFORM_ROT_90: |
| 417 | glTranslatef(0, 1, 0); |
| 418 | glRotatef(-90, 0, 0, 1); |
| 419 | break; |
| 420 | case HAL_TRANSFORM_ROT_180: |
| 421 | glTranslatef(1, 1, 0); |
| 422 | glRotatef(-180, 0, 0, 1); |
| 423 | break; |
| 424 | case HAL_TRANSFORM_ROT_270: |
| 425 | glTranslatef(1, 0, 0); |
| 426 | glRotatef(-270, 0, 0, 1); |
| 427 | break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | } |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 429 | |
| 430 | if (texture.NPOTAdjust) { |
| 431 | glScalef(texture.wScale, texture.hScale, 1.0f); |
| 432 | } |
| 433 | |
| 434 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 435 | glVertexPointer(2, GL_FLOAT, 0, mVertices); |
| 436 | glTexCoordPointer(2, GL_FLOAT, 0, texCoords); |
| 437 | |
| 438 | while (it != end) { |
| 439 | const Rect& r = *it++; |
| 440 | const GLint sy = fbHeight - (r.top + r.height()); |
| 441 | glScissor(r.left, sy, r.width(), r.height()); |
| 442 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 443 | } |
| 444 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | void LayerBase::validateTexture(GLint textureName) const |
| 448 | { |
| 449 | glBindTexture(GL_TEXTURE_2D, textureName); |
| 450 | // TODO: reload the texture if needed |
| 451 | // this is currently done in loadTexture() below |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 452 | if (needsFiltering()) { |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 453 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 454 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 455 | } else { |
| 456 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 457 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 458 | } |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 459 | |
| 460 | if (needsDithering()) { |
| 461 | glEnable(GL_DITHER); |
| 462 | } else { |
| 463 | glDisable(GL_DITHER); |
| 464 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | } |
| 466 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 467 | void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const |
| 468 | { |
| 469 | const Layer::State& s(drawingState()); |
| 470 | snprintf(buffer, SIZE, |
| 471 | "+ %s %p\n" |
| 472 | " " |
| 473 | "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), " |
| 474 | "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, " |
| 475 | "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n", |
| 476 | getTypeId(), this, s.z, tx(), ty(), s.w, s.h, |
| 477 | needsBlending(), needsDithering(), contentDirty, |
| 478 | s.alpha, s.flags, |
| 479 | s.transform[0][0], s.transform[0][1], |
| 480 | s.transform[1][0], s.transform[1][1]); |
| 481 | result.append(buffer); |
| 482 | } |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 483 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | // --------------------------------------------------------------------------- |
| 485 | |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 486 | int32_t LayerBaseClient::sIdentity = 1; |
Mathias Agopian | 2e12324 | 2009-06-23 20:06:46 -0700 | [diff] [blame] | 487 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display, |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 489 | const sp<Client>& client) |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame^] | 490 | : LayerBase(flinger, display), mClientRef(client), |
Mathias Agopian | 948d69f | 2010-03-08 19:29:09 -0800 | [diff] [blame] | 491 | mIdentity(uint32_t(android_atomic_inc(&sIdentity))) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 493 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | LayerBaseClient::~LayerBaseClient() |
| 496 | { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame^] | 497 | sp<Client> c(mClientRef.promote()); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 498 | if (c != 0) { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame^] | 499 | c->detachLayer(this); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 503 | sp<LayerBaseClient::Surface> LayerBaseClient::getSurface() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 505 | sp<Surface> s; |
| 506 | Mutex::Autolock _l(mLock); |
| 507 | s = mClientSurface.promote(); |
| 508 | if (s == 0) { |
| 509 | s = createSurface(); |
| 510 | mClientSurface = s; |
| 511 | } |
| 512 | return s; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 515 | sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const |
| 516 | { |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 517 | return new Surface(mFlinger, mIdentity, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 518 | const_cast<LayerBaseClient *>(this)); |
| 519 | } |
| 520 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 521 | void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const |
| 522 | { |
| 523 | LayerBase::dump(result, buffer, SIZE); |
| 524 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame^] | 525 | sp<Client> client(mClientRef.promote()); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 526 | snprintf(buffer, SIZE, |
| 527 | " name=%s\n" |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 528 | " client=%p, identity=%u\n", |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 529 | getName().string(), |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 530 | client.get(), getIdentity()); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 531 | |
| 532 | result.append(buffer); |
| 533 | } |
| 534 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 535 | // --------------------------------------------------------------------------- |
| 536 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 537 | LayerBaseClient::Surface::Surface( |
| 538 | const sp<SurfaceFlinger>& flinger, |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 539 | int identity, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 540 | const sp<LayerBaseClient>& owner) |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 541 | : mFlinger(flinger), mIdentity(identity), mOwner(owner) |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 542 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 545 | LayerBaseClient::Surface::~Surface() |
| 546 | { |
| 547 | /* |
| 548 | * This is a good place to clean-up all client resources |
| 549 | */ |
| 550 | |
| 551 | // destroy client resources |
| 552 | sp<LayerBaseClient> layer = getOwner(); |
| 553 | if (layer != 0) { |
| 554 | mFlinger->destroySurface(layer); |
| 555 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const { |
| 559 | sp<LayerBaseClient> owner(mOwner.promote()); |
| 560 | return owner; |
| 561 | } |
| 562 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 563 | status_t LayerBaseClient::Surface::onTransact( |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 564 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 565 | { |
| 566 | switch (code) { |
| 567 | case REGISTER_BUFFERS: |
| 568 | case UNREGISTER_BUFFERS: |
| 569 | case CREATE_OVERLAY: |
| 570 | { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 571 | if (!mFlinger->mAccessSurfaceFlinger.checkCalling()) { |
| 572 | IPCThreadState* ipc = IPCThreadState::self(); |
| 573 | const int pid = ipc->getCallingPid(); |
| 574 | const int uid = ipc->getCallingUid(); |
| 575 | LOGE("Permission Denial: " |
| 576 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); |
| 577 | return PERMISSION_DENIED; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | } |
| 581 | return BnSurface::onTransact(code, data, reply, flags); |
| 582 | } |
| 583 | |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 584 | sp<GraphicBuffer> LayerBaseClient::Surface::requestBuffer(int bufferIdx, |
| 585 | uint32_t w, uint32_t h, uint32_t format, uint32_t usage) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 586 | { |
| 587 | return NULL; |
| 588 | } |
| 589 | |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 590 | status_t LayerBaseClient::Surface::setBufferCount(int bufferCount) |
| 591 | { |
| 592 | return INVALID_OPERATION; |
| 593 | } |
| 594 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 595 | status_t LayerBaseClient::Surface::registerBuffers( |
| 596 | const ISurface::BufferHeap& buffers) |
| 597 | { |
| 598 | return INVALID_OPERATION; |
| 599 | } |
| 600 | |
| 601 | void LayerBaseClient::Surface::postBuffer(ssize_t offset) |
| 602 | { |
| 603 | } |
| 604 | |
| 605 | void LayerBaseClient::Surface::unregisterBuffers() |
| 606 | { |
| 607 | } |
| 608 | |
| 609 | sp<OverlayRef> LayerBaseClient::Surface::createOverlay( |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 610 | uint32_t w, uint32_t h, int32_t format, int32_t orientation) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 611 | { |
| 612 | return NULL; |
| 613 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | |
| 615 | // --------------------------------------------------------------------------- |
| 616 | |
| 617 | }; // namespace android |