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" |
| 35 | |
| 36 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | namespace android { |
| 38 | |
| 39 | // --------------------------------------------------------------------------- |
| 40 | |
| 41 | const uint32_t LayerBase::typeInfo = 1; |
| 42 | const char* const LayerBase::typeID = "LayerBase"; |
| 43 | |
| 44 | const uint32_t LayerBaseClient::typeInfo = LayerBase::typeInfo | 2; |
| 45 | const char* const LayerBaseClient::typeID = "LayerBaseClient"; |
| 46 | |
| 47 | // --------------------------------------------------------------------------- |
| 48 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display) |
| 50 | : dpy(display), contentDirty(false), |
| 51 | mFlinger(flinger), |
| 52 | mTransformed(false), |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 53 | mUseLinearFiltering(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | mOrientation(0), |
Mathias Agopian | ca6fab2 | 2010-02-19 17:51:58 -0800 | [diff] [blame] | 55 | mLeft(0), mTop(0), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | mTransactionFlags(0), |
| 57 | mPremultipliedAlpha(true), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | mInvalidate(0) |
| 59 | { |
| 60 | const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware()); |
| 61 | mFlags = hw.getFlags(); |
| 62 | } |
| 63 | |
| 64 | LayerBase::~LayerBase() |
| 65 | { |
| 66 | } |
| 67 | |
| 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) { |
| 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 | 7e4a587 | 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 | 6656dbc | 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; |
| 209 | this->contentDirty = true; |
| 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 | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 217 | const bool linearFiltering = mUseLinearFiltering; |
| 218 | mUseLinearFiltering = false; |
| 219 | if (!(mFlags & DisplayHardware::SLOW_CONFIG)) { |
| 220 | // we may use linear filtering, if the matrix scales us |
| 221 | const uint8_t type = temp.transform.getType(); |
| 222 | if (!temp.transform.preserveRects() || (type >= Transform::SCALE)) { |
| 223 | mUseLinearFiltering = true; |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | // Commit the transaction |
Mathias Agopian | ba6be54 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 229 | commitTransaction(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | return flags; |
| 231 | } |
| 232 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | void LayerBase::validateVisibility(const Transform& planeTransform) |
| 234 | { |
| 235 | const Layer::State& s(drawingState()); |
| 236 | const Transform tr(planeTransform * s.transform); |
| 237 | const bool transformed = tr.transformed(); |
| 238 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 239 | uint32_t w = s.w; |
| 240 | uint32_t h = s.h; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | tr.transform(mVertices[0], 0, 0); |
| 242 | tr.transform(mVertices[1], 0, h); |
| 243 | tr.transform(mVertices[2], w, h); |
| 244 | tr.transform(mVertices[3], w, 0); |
| 245 | if (UNLIKELY(transformed)) { |
| 246 | // NOTE: here we could also punt if we have too many rectangles |
| 247 | // in the transparent region |
| 248 | if (tr.preserveRects()) { |
| 249 | // transform the transparent region |
| 250 | transparentRegionScreen = tr.transform(s.transparentRegion); |
| 251 | } else { |
| 252 | // transformation too complex, can't do the transparent region |
| 253 | // optimization. |
| 254 | transparentRegionScreen.clear(); |
| 255 | } |
| 256 | } else { |
| 257 | transparentRegionScreen = s.transparentRegion; |
| 258 | } |
| 259 | |
| 260 | // cache a few things... |
| 261 | mOrientation = tr.getOrientation(); |
| 262 | mTransformedBounds = tr.makeBounds(w, h); |
| 263 | mTransformed = transformed; |
| 264 | mLeft = tr.tx(); |
| 265 | mTop = tr.ty(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) |
| 269 | { |
| 270 | } |
| 271 | |
| 272 | void LayerBase::unlockPageFlip( |
| 273 | const Transform& planeTransform, Region& outDirtyRegion) |
| 274 | { |
| 275 | if ((android_atomic_and(~1, &mInvalidate)&1) == 1) { |
| 276 | outDirtyRegion.orSelf(visibleRegionScreen); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | void LayerBase::finishPageFlip() |
| 281 | { |
| 282 | } |
| 283 | |
| 284 | void LayerBase::invalidate() |
| 285 | { |
| 286 | if ((android_atomic_or(1, &mInvalidate)&1) == 0) { |
| 287 | mFlinger->signalEvent(); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | void LayerBase::drawRegion(const Region& reg) const |
| 292 | { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 293 | Region::const_iterator it = reg.begin(); |
| 294 | Region::const_iterator const end = reg.end(); |
| 295 | if (it != end) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | Rect r; |
| 297 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 298 | const int32_t fbWidth = hw.getWidth(); |
| 299 | const int32_t fbHeight = hw.getHeight(); |
| 300 | const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 }, |
| 301 | { fbWidth, fbHeight }, { 0, fbHeight } }; |
| 302 | glVertexPointer(2, GL_SHORT, 0, vertices); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 303 | while (it != end) { |
| 304 | const Rect& r = *it++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | const GLint sy = fbHeight - (r.top + r.height()); |
| 306 | glScissor(r.left, sy, r.width(), r.height()); |
| 307 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | void LayerBase::draw(const Region& inClip) const |
| 313 | { |
| 314 | // invalidate the region we'll update |
| 315 | Region clip(inClip); // copy-on-write, so no-op most of the time |
| 316 | |
| 317 | // Remove the transparent area from the clipping region |
| 318 | const State& s = drawingState(); |
| 319 | if (LIKELY(!s.transparentRegion.isEmpty())) { |
| 320 | clip.subtract(transparentRegionScreen); |
| 321 | if (clip.isEmpty()) { |
| 322 | // usually this won't happen because this should be taken care of |
| 323 | // by SurfaceFlinger::computeVisibleRegions() |
| 324 | return; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | // reset GL state |
| 329 | glEnable(GL_SCISSOR_TEST); |
| 330 | |
| 331 | onDraw(clip); |
| 332 | |
| 333 | /* |
| 334 | glDisable(GL_TEXTURE_2D); |
| 335 | glDisable(GL_DITHER); |
| 336 | glEnable(GL_BLEND); |
| 337 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 338 | glColor4x(0, 0x8000, 0, 0x10000); |
| 339 | drawRegion(transparentRegionScreen); |
| 340 | glDisable(GL_BLEND); |
| 341 | */ |
| 342 | } |
| 343 | |
| 344 | GLuint LayerBase::createTexture() const |
| 345 | { |
| 346 | GLuint textureName = -1; |
| 347 | glGenTextures(1, &textureName); |
| 348 | glBindTexture(GL_TEXTURE_2D, textureName); |
| 349 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 350 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 351 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 352 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | return textureName; |
| 354 | } |
| 355 | |
Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 356 | void LayerBase::clearWithOpenGL(const Region& clip, GLclampx red, |
| 357 | GLclampx green, GLclampx blue, |
| 358 | GLclampx alpha) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | { |
| 360 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 361 | const uint32_t fbHeight = hw.getHeight(); |
Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 362 | glColor4x(red,green,blue,alpha); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | glDisable(GL_TEXTURE_2D); |
| 364 | glDisable(GL_BLEND); |
| 365 | glDisable(GL_DITHER); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 366 | |
| 367 | Region::const_iterator it = clip.begin(); |
| 368 | Region::const_iterator const end = clip.end(); |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 369 | glEnable(GL_SCISSOR_TEST); |
| 370 | glVertexPointer(2, GL_FIXED, 0, mVertices); |
| 371 | while (it != end) { |
| 372 | const Rect& r = *it++; |
| 373 | const GLint sy = fbHeight - (r.top + r.height()); |
| 374 | glScissor(r.left, sy, r.width(), r.height()); |
| 375 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 379 | void LayerBase::clearWithOpenGL(const Region& clip) const |
| 380 | { |
| 381 | clearWithOpenGL(clip,0,0,0,0); |
| 382 | } |
| 383 | |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 384 | 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] | 385 | { |
| 386 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
| 387 | const uint32_t fbHeight = hw.getHeight(); |
| 388 | const State& s(drawingState()); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 389 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | // bind our texture |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 391 | validateTexture(texture.name); |
| 392 | uint32_t width = texture.width; |
| 393 | uint32_t height = texture.height; |
| 394 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | glEnable(GL_TEXTURE_2D); |
| 396 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | if (UNLIKELY(s.alpha < 0xFF)) { |
| 398 | // We have an alpha-modulation. We need to modulate all |
| 399 | // texture components by alpha because we're always using |
| 400 | // premultiplied alpha. |
| 401 | |
| 402 | // If the texture doesn't have an alpha channel we can |
| 403 | // use REPLACE and switch to non premultiplied alpha |
| 404 | // blending (SRCA/ONE_MINUS_SRCA). |
| 405 | |
| 406 | GLenum env, src; |
| 407 | if (needsBlending()) { |
| 408 | env = GL_MODULATE; |
| 409 | src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; |
| 410 | } else { |
| 411 | env = GL_REPLACE; |
| 412 | src = GL_SRC_ALPHA; |
| 413 | } |
| 414 | const GGLfixed alpha = (s.alpha << 16)/255; |
| 415 | glColor4x(alpha, alpha, alpha, alpha); |
| 416 | glEnable(GL_BLEND); |
| 417 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
| 418 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env); |
| 419 | } else { |
| 420 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 421 | glColor4x(0x10000, 0x10000, 0x10000, 0x10000); |
| 422 | if (needsBlending()) { |
| 423 | GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; |
| 424 | glEnable(GL_BLEND); |
| 425 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
| 426 | } else { |
| 427 | glDisable(GL_BLEND); |
| 428 | } |
| 429 | } |
| 430 | |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 431 | Region::const_iterator it = clip.begin(); |
| 432 | Region::const_iterator const end = clip.end(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | if (UNLIKELY(transformed() |
| 434 | || !(mFlags & DisplayHardware::DRAW_TEXTURE_EXTENSION) )) |
| 435 | { |
| 436 | //StopWatch watch("GL transformed"); |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 437 | const GLfixed texCoords[4][2] = { |
| 438 | { 0, 0 }, |
| 439 | { 0, 0x10000 }, |
| 440 | { 0x10000, 0x10000 }, |
| 441 | { 0x10000, 0 } |
| 442 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 444 | glMatrixMode(GL_TEXTURE); |
| 445 | glLoadIdentity(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 447 | // the texture's source is rotated |
Chih-Chung Chang | 5994a33 | 2010-01-22 16:30:39 -0800 | [diff] [blame] | 448 | switch (texture.transform) { |
| 449 | case HAL_TRANSFORM_ROT_90: |
| 450 | glTranslatef(0, 1, 0); |
| 451 | glRotatef(-90, 0, 0, 1); |
| 452 | break; |
| 453 | case HAL_TRANSFORM_ROT_180: |
| 454 | glTranslatef(1, 1, 0); |
| 455 | glRotatef(-180, 0, 0, 1); |
| 456 | break; |
| 457 | case HAL_TRANSFORM_ROT_270: |
| 458 | glTranslatef(1, 0, 0); |
| 459 | glRotatef(-270, 0, 0, 1); |
| 460 | break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | } |
Chih-Chung Chang | 5994a33 | 2010-01-22 16:30:39 -0800 | [diff] [blame] | 462 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 463 | if (texture.NPOTAdjust) { |
| 464 | glScalef(texture.wScale, texture.hScale, 1.0f); |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 468 | glVertexPointer(2, GL_FIXED, 0, mVertices); |
| 469 | glTexCoordPointer(2, GL_FIXED, 0, texCoords); |
| 470 | |
| 471 | while (it != end) { |
| 472 | const Rect& r = *it++; |
| 473 | const GLint sy = fbHeight - (r.top + r.height()); |
| 474 | glScissor(r.left, sy, r.width(), r.height()); |
| 475 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 476 | } |
| 477 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | } else { |
Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 479 | GLint crop[4] = { 0, height, width, -height }; |
| 480 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 481 | int x = tx(); |
| 482 | int y = ty(); |
| 483 | y = fbHeight - (y + height); |
| 484 | while (it != end) { |
| 485 | const Rect& r = *it++; |
| 486 | const GLint sy = fbHeight - (r.top + r.height()); |
| 487 | glScissor(r.left, sy, r.width(), r.height()); |
| 488 | glDrawTexiOES(x, y, 0, width, height); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | void LayerBase::validateTexture(GLint textureName) const |
| 494 | { |
| 495 | glBindTexture(GL_TEXTURE_2D, textureName); |
| 496 | // TODO: reload the texture if needed |
| 497 | // this is currently done in loadTexture() below |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 498 | if (mUseLinearFiltering) { |
| 499 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 500 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 501 | } else { |
| 502 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 503 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 504 | } |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 505 | |
| 506 | if (needsDithering()) { |
| 507 | glEnable(GL_DITHER); |
| 508 | } else { |
| 509 | glDisable(GL_DITHER); |
| 510 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 513 | bool LayerBase::isSupportedYuvFormat(int format) const |
| 514 | { |
| 515 | switch (format) { |
| 516 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 517 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 518 | case HAL_PIXEL_FORMAT_YCbCr_422_P: |
| 519 | case HAL_PIXEL_FORMAT_YCbCr_420_P: |
| 520 | case HAL_PIXEL_FORMAT_YCbCr_422_I: |
| 521 | case HAL_PIXEL_FORMAT_YCbCr_420_I: |
| 522 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 523 | return true; |
| 524 | } |
| 525 | return false; |
| 526 | } |
| 527 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 528 | void LayerBase::loadTexture(Texture* texture, |
Mathias Agopian | 1fed11c | 2009-06-23 18:08:22 -0700 | [diff] [blame] | 529 | const Region& dirty, const GGLSurface& t) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 531 | if (texture->name == -1U) { |
| 532 | // uh? |
| 533 | return; |
| 534 | } |
Mathias Agopian | 57720c3 | 2009-10-21 16:27:21 -0700 | [diff] [blame] | 535 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 536 | glBindTexture(GL_TEXTURE_2D, texture->name); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | |
| 538 | /* |
| 539 | * In OpenGL ES we can't specify a stride with glTexImage2D (however, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 540 | * GL_UNPACK_ALIGNMENT is a limited form of stride). |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | * So if the stride here isn't representable with GL_UNPACK_ALIGNMENT, we |
| 542 | * need to do something reasonable (here creating a bigger texture). |
| 543 | * |
| 544 | * extra pixels = (((stride - width) * pixelsize) / GL_UNPACK_ALIGNMENT); |
| 545 | * |
| 546 | * This situation doesn't happen often, but some h/w have a limitation |
| 547 | * for their framebuffer (eg: must be multiple of 8 pixels), and |
| 548 | * we need to take that into account when using these buffers as |
| 549 | * textures. |
| 550 | * |
| 551 | * This should never be a problem with POT textures |
| 552 | */ |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 553 | |
| 554 | int unpack = __builtin_ctz(t.stride * bytesPerPixel(t.format)); |
| 555 | unpack = 1 << ((unpack > 3) ? 3 : unpack); |
| 556 | glPixelStorei(GL_UNPACK_ALIGNMENT, unpack); |
| 557 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | /* |
| 559 | * round to POT if needed |
| 560 | */ |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 561 | if (!(mFlags & DisplayHardware::NPOT_EXTENSION)) { |
| 562 | texture->NPOTAdjust = true; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 564 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 565 | if (texture->NPOTAdjust) { |
| 566 | // find the smallest power-of-two that will accommodate our surface |
| 567 | texture->potWidth = 1 << (31 - clz(t.width)); |
| 568 | texture->potHeight = 1 << (31 - clz(t.height)); |
| 569 | if (texture->potWidth < t.width) texture->potWidth <<= 1; |
| 570 | if (texture->potHeight < t.height) texture->potHeight <<= 1; |
| 571 | texture->wScale = float(t.width) / texture->potWidth; |
| 572 | texture->hScale = float(t.height) / texture->potHeight; |
| 573 | } else { |
| 574 | texture->potWidth = t.width; |
| 575 | texture->potHeight = t.height; |
| 576 | } |
| 577 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 578 | Rect bounds(dirty.bounds()); |
| 579 | GLvoid* data = 0; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 580 | if (texture->width != t.width || texture->height != t.height) { |
| 581 | texture->width = t.width; |
| 582 | texture->height = t.height; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 584 | // texture size changed, we need to create a new one |
| 585 | bounds.set(Rect(t.width, t.height)); |
| 586 | if (t.width == texture->potWidth && |
| 587 | t.height == texture->potHeight) { |
| 588 | // we can do it one pass |
| 589 | data = t.data; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | } |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 591 | |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 592 | if (t.format == HAL_PIXEL_FORMAT_RGB_565) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 593 | glTexImage2D(GL_TEXTURE_2D, 0, |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 594 | GL_RGB, texture->potWidth, texture->potHeight, 0, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 595 | GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data); |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 596 | } else if (t.format == HAL_PIXEL_FORMAT_RGBA_4444) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 597 | glTexImage2D(GL_TEXTURE_2D, 0, |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 598 | GL_RGBA, texture->potWidth, texture->potHeight, 0, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 599 | GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, data); |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 600 | } else if (t.format == HAL_PIXEL_FORMAT_RGBA_8888 || |
| 601 | t.format == HAL_PIXEL_FORMAT_RGBX_8888) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 602 | glTexImage2D(GL_TEXTURE_2D, 0, |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 603 | GL_RGBA, texture->potWidth, texture->potHeight, 0, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 604 | GL_RGBA, GL_UNSIGNED_BYTE, data); |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 605 | } else if (isSupportedYuvFormat(t.format)) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 606 | // just show the Y plane of YUV buffers |
| 607 | glTexImage2D(GL_TEXTURE_2D, 0, |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 608 | GL_LUMINANCE, texture->potWidth, texture->potHeight, 0, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 609 | GL_LUMINANCE, GL_UNSIGNED_BYTE, data); |
| 610 | } else { |
| 611 | // oops, we don't handle this format! |
| 612 | LOGE("layer %p, texture=%d, using format %d, which is not " |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 613 | "supported by the GL", this, texture->name, t.format); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 614 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 615 | } |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 616 | if (!data) { |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 617 | if (t.format == HAL_PIXEL_FORMAT_RGB_565) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 618 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 619 | 0, bounds.top, t.width, bounds.height(), |
| 620 | GL_RGB, GL_UNSIGNED_SHORT_5_6_5, |
| 621 | t.data + bounds.top*t.stride*2); |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 622 | } else if (t.format == HAL_PIXEL_FORMAT_RGBA_4444) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 623 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 624 | 0, bounds.top, t.width, bounds.height(), |
| 625 | GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, |
| 626 | t.data + bounds.top*t.stride*2); |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 627 | } else if (t.format == HAL_PIXEL_FORMAT_RGBA_8888 || |
| 628 | t.format == HAL_PIXEL_FORMAT_RGBX_8888) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 629 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 630 | 0, bounds.top, t.width, bounds.height(), |
| 631 | GL_RGBA, GL_UNSIGNED_BYTE, |
| 632 | t.data + bounds.top*t.stride*4); |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 633 | } else if (isSupportedYuvFormat(t.format)) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 634 | // just show the Y plane of YUV buffers |
| 635 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 636 | 0, bounds.top, t.width, bounds.height(), |
| 637 | GL_LUMINANCE, GL_UNSIGNED_BYTE, |
| 638 | t.data + bounds.top*t.stride); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 643 | status_t LayerBase::initializeEglImage( |
| 644 | const sp<GraphicBuffer>& buffer, Texture* texture) |
| 645 | { |
| 646 | status_t err = NO_ERROR; |
| 647 | |
| 648 | // we need to recreate the texture |
| 649 | EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay()); |
| 650 | |
| 651 | // free the previous image |
| 652 | if (texture->image != EGL_NO_IMAGE_KHR) { |
| 653 | eglDestroyImageKHR(dpy, texture->image); |
| 654 | texture->image = EGL_NO_IMAGE_KHR; |
| 655 | } |
| 656 | |
| 657 | // construct an EGL_NATIVE_BUFFER_ANDROID |
| 658 | android_native_buffer_t* clientBuf = buffer->getNativeBuffer(); |
| 659 | |
| 660 | // create the new EGLImageKHR |
| 661 | const EGLint attrs[] = { |
| 662 | EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, |
| 663 | EGL_NONE, EGL_NONE |
| 664 | }; |
| 665 | texture->image = eglCreateImageKHR( |
| 666 | dpy, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, |
| 667 | (EGLClientBuffer)clientBuf, attrs); |
| 668 | |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 669 | if (texture->image != EGL_NO_IMAGE_KHR) { |
| 670 | glBindTexture(GL_TEXTURE_2D, texture->name); |
| 671 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, |
| 672 | (GLeglImageOES)texture->image); |
| 673 | GLint error = glGetError(); |
| 674 | if (UNLIKELY(error != GL_NO_ERROR)) { |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 675 | LOGE("layer=%p, glEGLImageTargetTexture2DOES(%p) " |
| 676 | "failed err=0x%04x", |
| 677 | this, texture->image, error); |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 678 | err = INVALID_OPERATION; |
| 679 | } else { |
| 680 | // Everything went okay! |
| 681 | texture->NPOTAdjust = false; |
| 682 | texture->dirty = false; |
| 683 | texture->width = clientBuf->width; |
| 684 | texture->height = clientBuf->height; |
| 685 | } |
| 686 | } else { |
Mathias Agopian | fcfeb4b | 2010-03-08 11:14:20 -0800 | [diff] [blame] | 687 | LOGE("layer=%p, eglCreateImageKHR() failed. err=0x%4x", |
| 688 | this, eglGetError()); |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 689 | err = INVALID_OPERATION; |
| 690 | } |
| 691 | return err; |
| 692 | } |
| 693 | |
| 694 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | // --------------------------------------------------------------------------- |
| 696 | |
Mathias Agopian | 2e12324 | 2009-06-23 20:06:46 -0700 | [diff] [blame] | 697 | int32_t LayerBaseClient::sIdentity = 0; |
| 698 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display, |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 700 | const sp<Client>& client, int32_t i) |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 701 | : LayerBase(flinger, display), lcblk(NULL), client(client), |
Mathias Agopian | 948d69f | 2010-03-08 19:29:09 -0800 | [diff] [blame^] | 702 | mDebug(false), mIndex(i), |
| 703 | mIdentity(uint32_t(android_atomic_inc(&sIdentity))) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 704 | { |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 705 | lcblk = new SharedBufferServer( |
| 706 | client->ctrlblk, i, NUM_BUFFERS, |
| 707 | mIdentity); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 708 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 710 | void LayerBaseClient::onFirstRef() |
| 711 | { |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 712 | sp<Client> client(this->client.promote()); |
| 713 | if (client != 0) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 714 | client->bindLayer(this, mIndex); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
| 718 | LayerBaseClient::~LayerBaseClient() |
| 719 | { |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 720 | sp<Client> client(this->client.promote()); |
| 721 | if (client != 0) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | client->free(mIndex); |
| 723 | } |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 724 | delete lcblk; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | } |
| 726 | |
Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 727 | void LayerBaseClient::setName(const String8& name) { |
| 728 | mName = name; |
| 729 | } |
| 730 | |
| 731 | String8 LayerBaseClient::getName() const { |
| 732 | return mName; |
| 733 | } |
| 734 | |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 735 | int32_t LayerBaseClient::serverIndex() const |
| 736 | { |
| 737 | sp<Client> client(this->client.promote()); |
| 738 | if (client != 0) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | return (client->cid<<16)|mIndex; |
| 740 | } |
| 741 | return 0xFFFF0000 | mIndex; |
| 742 | } |
| 743 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 744 | sp<LayerBaseClient::Surface> LayerBaseClient::getSurface() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 746 | sp<Surface> s; |
| 747 | Mutex::Autolock _l(mLock); |
| 748 | s = mClientSurface.promote(); |
| 749 | if (s == 0) { |
| 750 | s = createSurface(); |
| 751 | mClientSurface = s; |
| 752 | } |
| 753 | return s; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | } |
| 755 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 756 | sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const |
| 757 | { |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 758 | return new Surface(mFlinger, clientIndex(), mIdentity, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 759 | const_cast<LayerBaseClient *>(this)); |
| 760 | } |
| 761 | |
Mathias Agopian | 0b3ad46 | 2009-10-02 18:12:30 -0700 | [diff] [blame] | 762 | // called with SurfaceFlinger::mStateLock as soon as the layer is entered |
| 763 | // in the purgatory list |
| 764 | void LayerBaseClient::onRemoved() |
| 765 | { |
| 766 | // wake up the condition |
| 767 | lcblk->setStatus(NO_INIT); |
| 768 | } |
| 769 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 770 | // --------------------------------------------------------------------------- |
| 771 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 772 | LayerBaseClient::Surface::Surface( |
| 773 | const sp<SurfaceFlinger>& flinger, |
| 774 | SurfaceID id, int identity, |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 775 | const sp<LayerBaseClient>& owner) |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 776 | : mFlinger(flinger), mToken(id), mIdentity(identity), mOwner(owner) |
| 777 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 780 | LayerBaseClient::Surface::~Surface() |
| 781 | { |
| 782 | /* |
| 783 | * This is a good place to clean-up all client resources |
| 784 | */ |
| 785 | |
| 786 | // destroy client resources |
| 787 | sp<LayerBaseClient> layer = getOwner(); |
| 788 | if (layer != 0) { |
| 789 | mFlinger->destroySurface(layer); |
| 790 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const { |
| 794 | sp<LayerBaseClient> owner(mOwner.promote()); |
| 795 | return owner; |
| 796 | } |
| 797 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 798 | status_t LayerBaseClient::Surface::onTransact( |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 799 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 800 | { |
| 801 | switch (code) { |
| 802 | case REGISTER_BUFFERS: |
| 803 | case UNREGISTER_BUFFERS: |
| 804 | case CREATE_OVERLAY: |
| 805 | { |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 806 | if (!mFlinger->mAccessSurfaceFlinger.checkCalling()) { |
| 807 | IPCThreadState* ipc = IPCThreadState::self(); |
| 808 | const int pid = ipc->getCallingPid(); |
| 809 | const int uid = ipc->getCallingUid(); |
| 810 | LOGE("Permission Denial: " |
| 811 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); |
| 812 | return PERMISSION_DENIED; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | } |
| 816 | return BnSurface::onTransact(code, data, reply, flags); |
| 817 | } |
| 818 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 819 | sp<GraphicBuffer> LayerBaseClient::Surface::requestBuffer(int index, int usage) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 820 | { |
| 821 | return NULL; |
| 822 | } |
| 823 | |
| 824 | status_t LayerBaseClient::Surface::registerBuffers( |
| 825 | const ISurface::BufferHeap& buffers) |
| 826 | { |
| 827 | return INVALID_OPERATION; |
| 828 | } |
| 829 | |
| 830 | void LayerBaseClient::Surface::postBuffer(ssize_t offset) |
| 831 | { |
| 832 | } |
| 833 | |
| 834 | void LayerBaseClient::Surface::unregisterBuffers() |
| 835 | { |
| 836 | } |
| 837 | |
| 838 | sp<OverlayRef> LayerBaseClient::Surface::createOverlay( |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 839 | uint32_t w, uint32_t h, int32_t format, int32_t orientation) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 840 | { |
| 841 | return NULL; |
| 842 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | |
| 844 | // --------------------------------------------------------------------------- |
| 845 | |
| 846 | }; // namespace android |