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> |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 20 | #include <math.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | |
| 22 | #include <utils/Errors.h> |
| 23 | #include <utils/Log.h> |
Mathias Agopian | 310f8da | 2009-05-22 01:27:01 -0700 | [diff] [blame] | 24 | #include <binder/IPCThreadState.h> |
| 25 | #include <binder/IServiceManager.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
| 27 | #include <GLES/gl.h> |
| 28 | #include <GLES/glext.h> |
| 29 | |
| 30 | #include <hardware/hardware.h> |
| 31 | |
| 32 | #include "clz.h" |
Mathias Agopian | db403e8 | 2012-06-18 16:47:56 -0700 | [diff] [blame] | 33 | #include "Client.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include "LayerBase.h" |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 35 | #include "Layer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | #include "SurfaceFlinger.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 37 | #include "DisplayDevice.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | namespace android { |
| 40 | |
| 41 | // --------------------------------------------------------------------------- |
| 42 | |
Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 43 | int32_t LayerBase::sSequence = 1; |
| 44 | |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 45 | LayerBase::LayerBase(SurfaceFlinger* flinger, const sp<Client>& client) |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 46 | : contentDirty(false), |
Mathias Agopian | f6679fc | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 47 | sequence(uint32_t(android_atomic_inc(&sSequence))), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 48 | mFlinger(flinger), mFiltering(false), |
Mathias Agopian | a2f4e56 | 2012-04-15 23:34:59 -0700 | [diff] [blame] | 49 | mNeedsFiltering(false), |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | mTransactionFlags(0), |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 51 | mPremultipliedAlpha(true), mName("unnamed"), mDebug(false), |
| 52 | mHasSurface(false), |
| 53 | mClientRef(client) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | LayerBase::~LayerBase() |
| 58 | { |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 59 | sp<Client> c(mClientRef.promote()); |
| 60 | if (c != 0) { |
| 61 | c->detachLayer(this); |
| 62 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Mathias Agopian | d129659 | 2010-03-09 19:17:47 -0800 | [diff] [blame] | 65 | void LayerBase::setName(const String8& name) { |
| 66 | mName = name; |
| 67 | } |
| 68 | |
| 69 | String8 LayerBase::getName() const { |
| 70 | return mName; |
| 71 | } |
| 72 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags) |
| 74 | { |
| 75 | uint32_t layerFlags = 0; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 76 | if (flags & ISurfaceComposerClient::eHidden) |
| 77 | layerFlags = layer_state_t::eLayerHidden; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 79 | if (flags & ISurfaceComposerClient::eNonPremultiplied) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | mPremultipliedAlpha = false; |
| 81 | |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 82 | mCurrentState.active.w = w; |
| 83 | mCurrentState.active.h = h; |
| 84 | mCurrentState.active.crop.makeInvalid(); |
| 85 | mCurrentState.z = 0; |
| 86 | mCurrentState.alpha = 0xFF; |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 87 | mCurrentState.layerStack = 0; |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 88 | mCurrentState.flags = layerFlags; |
| 89 | mCurrentState.sequence = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | mCurrentState.transform.set(0, 0); |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 91 | mCurrentState.requested = mCurrentState.active; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | |
| 93 | // drawing state & current state are identical |
| 94 | mDrawingState = mCurrentState; |
| 95 | } |
| 96 | |
Mathias Agopian | eba8c68 | 2012-09-19 23:14:45 -0700 | [diff] [blame] | 97 | bool LayerBase::needsFiltering(const sp<const DisplayDevice>& hw) const { |
| 98 | return mNeedsFiltering || hw->needsFiltering(); |
| 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 | |
Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 121 | bool LayerBase::setPosition(float x, float y) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | 93ffb86 | 2012-05-16 17:07:49 -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 | 93ffb86 | 2012-05-16 17:07:49 -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 | } |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 175 | bool LayerBase::setCrop(const Rect& crop) { |
Mathias Agopian | b30c415 | 2012-05-16 18:21:32 -0700 | [diff] [blame] | 176 | if (mCurrentState.requested.crop == crop) |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 177 | return false; |
| 178 | mCurrentState.sequence++; |
Mathias Agopian | b30c415 | 2012-05-16 18:21:32 -0700 | [diff] [blame] | 179 | mCurrentState.requested.crop = crop; |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 180 | requestTransaction(); |
| 181 | return true; |
| 182 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 184 | bool LayerBase::setLayerStack(uint32_t layerStack) { |
| 185 | if (mCurrentState.layerStack == layerStack) |
| 186 | return false; |
| 187 | mCurrentState.sequence++; |
| 188 | mCurrentState.layerStack = layerStack; |
| 189 | requestTransaction(); |
| 190 | return true; |
| 191 | } |
| 192 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | void LayerBase::setVisibleRegion(const Region& visibleRegion) { |
| 194 | // always called from main thread |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 195 | this->visibleRegion = visibleRegion; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void LayerBase::setCoveredRegion(const Region& coveredRegion) { |
| 199 | // always called from main thread |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 200 | this->coveredRegion = coveredRegion; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Jesse Hall | a8026d2 | 2012-09-25 13:25:04 -0700 | [diff] [blame] | 203 | void LayerBase::setVisibleNonTransparentRegion(const Region& |
| 204 | setVisibleNonTransparentRegion) { |
| 205 | // always called from main thread |
| 206 | this->visibleNonTransparentRegion = setVisibleNonTransparentRegion; |
| 207 | } |
| 208 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | uint32_t LayerBase::doTransaction(uint32_t flags) |
| 210 | { |
| 211 | const Layer::State& front(drawingState()); |
| 212 | const Layer::State& temp(currentState()); |
| 213 | |
Mathias Agopian | 05cec9d | 2012-05-23 14:35:49 -0700 | [diff] [blame] | 214 | // always set active to requested, unless we're asked not to |
| 215 | // this is used by Layer, which special cases resizes. |
| 216 | if (flags & eDontUpdateGeometryState) { |
| 217 | } else { |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 218 | Layer::State& editTemp(currentState()); |
Mathias Agopian | b30c415 | 2012-05-16 18:21:32 -0700 | [diff] [blame] | 219 | editTemp.active = temp.requested; |
Mathias Agopian | 7e4a587 | 2009-09-29 22:39:22 -0700 | [diff] [blame] | 220 | } |
Mathias Agopian | 05cec9d | 2012-05-23 14:35:49 -0700 | [diff] [blame] | 221 | |
Mathias Agopian | b30c415 | 2012-05-16 18:21:32 -0700 | [diff] [blame] | 222 | if (front.active != temp.active) { |
Mathias Agopian | 6656dbc | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 223 | // invalidate and recompute the visible regions if needed |
| 224 | flags |= Layer::eVisibleRegion; |
Mathias Agopian | 6656dbc | 2009-09-30 12:48:47 -0700 | [diff] [blame] | 225 | } |
| 226 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | if (temp.sequence != front.sequence) { |
| 228 | // invalidate and recompute the visible regions if needed |
| 229 | flags |= eVisibleRegion; |
| 230 | this->contentDirty = true; |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 231 | |
Mathias Agopian | 733189d | 2010-12-02 21:32:29 -0800 | [diff] [blame] | 232 | // we may use linear filtering, if the matrix scales us |
| 233 | const uint8_t type = temp.transform.getType(); |
| 234 | mNeedsFiltering = (!temp.transform.preserveRects() || |
| 235 | (type >= Transform::SCALE)); |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 236 | } |
| 237 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | // Commit the transaction |
Mathias Agopian | ba6be54 | 2009-09-29 22:32:36 -0700 | [diff] [blame] | 239 | commitTransaction(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | return flags; |
| 241 | } |
| 242 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 243 | void LayerBase::computeGeometry(const sp<const DisplayDevice>& hw, LayerMesh* mesh) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | { |
| 245 | const Layer::State& s(drawingState()); |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 246 | const Transform tr(hw->getTransform() * s.transform); |
| 247 | const uint32_t hw_h = hw->getHeight(); |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 248 | Rect win(s.active.w, s.active.h); |
Mathias Agopian | a046dd9 | 2012-09-24 22:01:01 -0700 | [diff] [blame] | 249 | if (!s.active.crop.isEmpty()) { |
| 250 | win.intersect(s.active.crop, &win); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 251 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 252 | if (mesh) { |
| 253 | tr.transform(mesh->mVertices[0], win.left, win.top); |
| 254 | tr.transform(mesh->mVertices[1], win.left, win.bottom); |
| 255 | tr.transform(mesh->mVertices[2], win.right, win.bottom); |
| 256 | tr.transform(mesh->mVertices[3], win.right, win.top); |
| 257 | for (size_t i=0 ; i<4 ; i++) { |
| 258 | mesh->mVertices[i][1] = hw_h - mesh->mVertices[i][1]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | } |
| 262 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 263 | Rect LayerBase::computeBounds() const { |
| 264 | const Layer::State& s(drawingState()); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 265 | Rect win(s.active.w, s.active.h); |
Mathias Agopian | a046dd9 | 2012-09-24 22:01:01 -0700 | [diff] [blame] | 266 | if (!s.active.crop.isEmpty()) { |
| 267 | win.intersect(s.active.crop, &win); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 268 | } |
Mathias Agopian | 5219a06 | 2013-02-26 16:37:53 -0800 | [diff] [blame] | 269 | return win; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 272 | Region LayerBase::latchBuffer(bool& recomputeVisibleRegions) { |
| 273 | Region result; |
| 274 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 277 | |
| 278 | Rect LayerBase::getContentCrop() const { |
| 279 | // regular layers just use their active area as the content crop |
| 280 | const State& s(drawingState()); |
| 281 | return Rect(s.active.w, s.active.h); |
| 282 | } |
| 283 | |
| 284 | uint32_t LayerBase::getContentTransform() const { |
| 285 | // regular layers don't have a content transform |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | Rect LayerBase::computeCrop(const sp<const DisplayDevice>& hw) const { |
Mathias Agopian | 3da1672 | 2013-02-28 17:12:07 -0800 | [diff] [blame] | 290 | /* |
| 291 | * The way we compute the crop (aka. texture coordinates when we have a |
| 292 | * Layer) produces a different output from the GL code in |
| 293 | * drawWithOpenGL() due to HWC being limited to integers. The difference |
| 294 | * can be large if getContentTransform() contains a large scale factor. |
| 295 | * See comments in drawWithOpenGL() for more details. |
| 296 | */ |
| 297 | |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 298 | // the content crop is the area of the content that gets scaled to the |
| 299 | // layer's size. |
| 300 | Rect crop(getContentCrop()); |
| 301 | |
| 302 | // the active.crop is the area of the window that gets cropped, but not |
| 303 | // scaled in any ways. |
| 304 | const State& s(drawingState()); |
Mathias Agopian | 3da1672 | 2013-02-28 17:12:07 -0800 | [diff] [blame] | 305 | |
| 306 | // apply the projection's clipping to the window crop in |
| 307 | // layerstack space, and convert-back to layer space. |
| 308 | // if there are no window scaling (or content scaling) involved, |
| 309 | // this operation will map to full pixels in the buffer. |
| 310 | // NOTE: should we revert to GL composition if a scaling is involved |
| 311 | // since it cannot be represented in the HWC API? |
| 312 | Rect activeCrop(s.transform.transform(s.active.crop)); |
| 313 | activeCrop.intersect(hw->getViewport(), &activeCrop); |
| 314 | activeCrop = s.transform.inverse().transform(activeCrop); |
| 315 | |
| 316 | // paranoia: make sure the window-crop is constrained in the |
| 317 | // window's bounds |
| 318 | activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop); |
| 319 | |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 320 | if (!activeCrop.isEmpty()) { |
| 321 | // Transform the window crop to match the buffer coordinate system, |
| 322 | // which means using the inverse of the current transform set on the |
| 323 | // SurfaceFlingerConsumer. |
| 324 | uint32_t invTransform = getContentTransform(); |
| 325 | int winWidth = s.active.w; |
| 326 | int winHeight = s.active.h; |
| 327 | if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) { |
| 328 | invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | |
| 329 | NATIVE_WINDOW_TRANSFORM_FLIP_H; |
| 330 | winWidth = s.active.h; |
| 331 | winHeight = s.active.w; |
| 332 | } |
| 333 | const Rect winCrop = activeCrop.transform( |
| 334 | invTransform, s.active.w, s.active.h); |
| 335 | |
| 336 | // the code below essentially performs a scaled intersection |
| 337 | // of crop and winCrop |
| 338 | float xScale = float(crop.width()) / float(winWidth); |
| 339 | float yScale = float(crop.height()) / float(winHeight); |
| 340 | |
| 341 | int insetL = int(ceilf( winCrop.left * xScale)); |
| 342 | int insetT = int(ceilf( winCrop.top * yScale)); |
| 343 | int insetR = int(ceilf((winWidth - winCrop.right ) * xScale)); |
| 344 | int insetB = int(ceilf((winHeight - winCrop.bottom) * yScale)); |
| 345 | |
| 346 | crop.left += insetL; |
| 347 | crop.top += insetT; |
| 348 | crop.right -= insetR; |
| 349 | crop.bottom -= insetB; |
| 350 | } |
| 351 | return crop; |
| 352 | } |
| 353 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 354 | void LayerBase::setGeometry( |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 355 | const sp<const DisplayDevice>& hw, |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 356 | HWComposer::HWCLayerInterface& layer) |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 357 | { |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 358 | layer.setDefaultState(); |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 359 | |
| 360 | // this gives us only the "orientation" component of the transform |
| 361 | const State& s(drawingState()); |
| 362 | const uint32_t finalTransform = s.transform.getOrientation(); |
| 363 | // we can only handle simple transformation |
| 364 | if (finalTransform & Transform::ROT_INVALID) { |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 365 | layer.setTransform(0); |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 366 | } else { |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 367 | layer.setTransform(finalTransform); |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Mathias Agopian | 9f8386e | 2013-01-29 18:56:42 -0800 | [diff] [blame] | 370 | if (!isOpaque() || s.alpha != 0xFF) { |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 371 | layer.setBlending(mPremultipliedAlpha ? |
| 372 | HWC_BLENDING_PREMULT : |
| 373 | HWC_BLENDING_COVERAGE); |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 376 | |
Mathias Agopian | 5219a06 | 2013-02-26 16:37:53 -0800 | [diff] [blame] | 377 | // apply the layer's transform, followed by the display's global transform |
| 378 | // here we're guaranteed that the layer's transform preserves rects |
| 379 | |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 380 | Rect frame(s.transform.transform(computeBounds())); |
Mathias Agopian | 3da1672 | 2013-02-28 17:12:07 -0800 | [diff] [blame] | 381 | frame.intersect(hw->getViewport(), &frame); |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 382 | const Transform& tr(hw->getTransform()); |
| 383 | layer.setFrame(tr.transform(frame)); |
| 384 | layer.setCrop(computeCrop(hw)); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 387 | void LayerBase::setPerFrameData(const sp<const DisplayDevice>& hw, |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 388 | HWComposer::HWCLayerInterface& layer) { |
Mathias Agopian | c397360 | 2012-08-31 17:51:25 -0700 | [diff] [blame] | 389 | // we have to set the visible region on every frame because |
| 390 | // we currently free it during onLayerDisplayed(), which is called |
| 391 | // after HWComposer::commit() -- every frame. |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 392 | // Apply this display's projection's viewport to the visible region |
| 393 | // before giving it to the HWC HAL. |
Mathias Agopian | c397360 | 2012-08-31 17:51:25 -0700 | [diff] [blame] | 394 | const Transform& tr = hw->getTransform(); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 395 | Region visible = tr.transform(visibleRegion.intersect(hw->getViewport())); |
| 396 | layer.setVisibleRegionScreen(visible); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 399 | void LayerBase::setAcquireFence(const sp<const DisplayDevice>& hw, |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 400 | HWComposer::HWCLayerInterface& layer) { |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 401 | layer.setAcquireFenceFd(-1); |
| 402 | } |
| 403 | |
Mathias Agopian | c397360 | 2012-08-31 17:51:25 -0700 | [diff] [blame] | 404 | void LayerBase::onLayerDisplayed(const sp<const DisplayDevice>& hw, |
| 405 | HWComposer::HWCLayerInterface* layer) { |
| 406 | if (layer) { |
| 407 | layer->onDisplayed(); |
| 408 | } |
| 409 | } |
| 410 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 411 | void LayerBase::setFiltering(bool filtering) |
| 412 | { |
| 413 | mFiltering = filtering; |
| 414 | } |
| 415 | |
| 416 | bool LayerBase::getFiltering() const |
| 417 | { |
| 418 | return mFiltering; |
| 419 | } |
| 420 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 421 | bool LayerBase::isVisible() const { |
| 422 | const Layer::State& s(mDrawingState); |
| 423 | return !(s.flags & layer_state_t::eLayerHidden) && s.alpha; |
| 424 | } |
| 425 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 426 | void LayerBase::draw(const sp<const DisplayDevice>& hw, const Region& clip) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | { |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 428 | onDraw(hw, clip); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | } |
| 430 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 431 | void LayerBase::draw(const sp<const DisplayDevice>& hw) |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 432 | { |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 433 | onDraw( hw, Region(hw->bounds()) ); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 436 | void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip, |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 437 | GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | { |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 439 | const uint32_t fbHeight = hw->getHeight(); |
Mathias Agopian | 010fccb | 2010-05-26 22:26:12 -0700 | [diff] [blame] | 440 | glColor4f(red,green,blue,alpha); |
Mathias Agopian | 0a91775 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 441 | |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 442 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 443 | glDisable(GL_TEXTURE_2D); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | glDisable(GL_BLEND); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 445 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 446 | LayerMesh mesh; |
| 447 | computeGeometry(hw, &mesh); |
| 448 | |
| 449 | glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices()); |
| 450 | glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | } |
| 452 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 453 | void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const |
Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 454 | { |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 455 | clearWithOpenGL(hw, clip, 0,0,0,0); |
Rebecca Schultz Zavin | 29aa74c | 2009-09-01 23:06:45 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 458 | void LayerBase::drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | { |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 460 | const uint32_t fbHeight = hw->getHeight(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | const State& s(drawingState()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 463 | GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; |
Glenn Kasten | 99ed224 | 2011-12-15 09:51:17 -0800 | [diff] [blame] | 464 | if (CC_UNLIKELY(s.alpha < 0xFF)) { |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 465 | const GLfloat alpha = s.alpha * (1.0f/255.0f); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 466 | if (mPremultipliedAlpha) { |
| 467 | glColor4f(alpha, alpha, alpha, alpha); |
| 468 | } else { |
| 469 | glColor4f(1, 1, 1, alpha); |
| 470 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | glEnable(GL_BLEND); |
| 472 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 473 | 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] | 474 | } else { |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 475 | glColor4f(1, 1, 1, 1); |
Mathias Agopian | 4975326 | 2010-04-12 15:34:55 -0700 | [diff] [blame] | 476 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 477 | if (!isOpaque()) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | glEnable(GL_BLEND); |
| 479 | glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA); |
| 480 | } else { |
| 481 | glDisable(GL_BLEND); |
| 482 | } |
| 483 | } |
| 484 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 485 | LayerMesh mesh; |
| 486 | computeGeometry(hw, &mesh); |
| 487 | |
| 488 | // TODO: we probably want to generate the texture coords with the mesh |
| 489 | // here we assume that we only have 4 vertices |
| 490 | |
Mathias Agopian | b661d66 | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 491 | struct TexCoords { |
| 492 | GLfloat u; |
| 493 | GLfloat v; |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 494 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | |
Mathias Agopian | 3da1672 | 2013-02-28 17:12:07 -0800 | [diff] [blame] | 496 | |
| 497 | /* |
| 498 | * NOTE: the way we compute the texture coordinates here produces |
| 499 | * different results than when we take the HWC path -- in the later case |
| 500 | * the "source crop" is rounded to texel boundaries. |
| 501 | * This can produce significantly different results when the texture |
| 502 | * is scaled by a large amount. |
| 503 | * |
| 504 | * The GL code below is more logical (imho), and the difference with |
| 505 | * HWC is due to a limitation of the HWC API to integers -- a question |
| 506 | * is suspend is wether we should ignore this problem or revert to |
| 507 | * GL composition when a buffer scaling is applied (maybe with some |
| 508 | * minimal value)? Or, we could make GL behave like HWC -- but this feel |
| 509 | * like more of a hack. |
| 510 | */ |
| 511 | const Rect win(computeBounds()); |
Mathias Agopian | a046dd9 | 2012-09-24 22:01:01 -0700 | [diff] [blame] | 512 | |
| 513 | GLfloat left = GLfloat(win.left) / GLfloat(s.active.w); |
| 514 | GLfloat top = GLfloat(win.top) / GLfloat(s.active.h); |
| 515 | GLfloat right = GLfloat(win.right) / GLfloat(s.active.w); |
| 516 | GLfloat bottom = GLfloat(win.bottom) / GLfloat(s.active.h); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 517 | |
Mathias Agopian | b661d66 | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 518 | TexCoords texCoords[4]; |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 519 | texCoords[0].u = left; |
| 520 | texCoords[0].v = top; |
| 521 | texCoords[1].u = left; |
| 522 | texCoords[1].v = bottom; |
| 523 | texCoords[2].u = right; |
| 524 | texCoords[2].v = bottom; |
| 525 | texCoords[3].u = right; |
| 526 | texCoords[3].v = top; |
| 527 | for (int i = 0; i < 4; i++) { |
| 528 | texCoords[i].v = 1.0f - texCoords[i].v; |
| 529 | } |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 530 | |
| 531 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 532 | glTexCoordPointer(2, GL_FLOAT, 0, texCoords); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 533 | glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices()); |
| 534 | glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount()); |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 535 | |
Mathias Agopian | 78fd501 | 2010-04-20 14:51:04 -0700 | [diff] [blame] | 536 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 537 | glDisable(GL_BLEND); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 540 | void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const |
| 541 | { |
| 542 | const Layer::State& s(drawingState()); |
Mathias Agopian | c95dbdc | 2012-02-05 00:19:27 -0800 | [diff] [blame] | 543 | |
| 544 | snprintf(buffer, SIZE, |
| 545 | "+ %s %p (%s)\n", |
| 546 | getTypeId(), this, getName().string()); |
| 547 | result.append(buffer); |
| 548 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 549 | s.transparentRegion.dump(result, "transparentRegion"); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 550 | visibleRegion.dump(result, "visibleRegion"); |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 551 | sp<Client> client(mClientRef.promote()); |
Mathias Agopian | c95dbdc | 2012-02-05 00:19:27 -0800 | [diff] [blame] | 552 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 553 | snprintf(buffer, SIZE, |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 554 | " " |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 555 | "layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), " |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 556 | "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, " |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 557 | "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n" |
| 558 | " client=%p\n", |
Mathias Agopian | 791da60 | 2012-09-11 20:52:46 -0700 | [diff] [blame] | 559 | s.layerStack, s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h, |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 560 | s.active.crop.left, s.active.crop.top, |
| 561 | s.active.crop.right, s.active.crop.bottom, |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 562 | isOpaque(), needsDithering(), contentDirty, |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 563 | s.alpha, s.flags, |
| 564 | s.transform[0][0], s.transform[0][1], |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 565 | s.transform[1][0], s.transform[1][1], |
| 566 | client.get()); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 567 | result.append(buffer); |
| 568 | } |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 569 | |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 570 | void LayerBase::shortDump(String8& result, char* scratch, size_t size) const { |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 571 | LayerBase::dump(result, scratch, size); |
| 572 | } |
| 573 | |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 574 | void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const { |
| 575 | } |
| 576 | |
| 577 | void LayerBase::clearStats() { |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 578 | } |
Mathias Agopian | 48b888a | 2011-01-19 16:15:53 -0800 | [diff] [blame] | 579 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 580 | sp<Layer> LayerBase::getLayer() const { |
| 581 | return 0; |
| 582 | } |
| 583 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | // --------------------------------------------------------------------------- |
| 585 | |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 586 | sp<ISurface> LayerBase::createSurface() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 588 | class BSurface : public BnSurface, public LayerCleaner { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 589 | virtual sp<IGraphicBufferProducer> getSurfaceTexture() const { return 0; } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 590 | public: |
| 591 | BSurface(const sp<SurfaceFlinger>& flinger, |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 592 | const sp<LayerBase>& layer) |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 593 | : LayerCleaner(flinger, layer) { } |
| 594 | }; |
| 595 | sp<ISurface> sur(new BSurface(mFlinger, this)); |
| 596 | return sur; |
| 597 | } |
| 598 | |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 599 | sp<ISurface> LayerBase::getSurface() |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 600 | { |
| 601 | sp<ISurface> s; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 602 | Mutex::Autolock _l(mLock); |
Mathias Agopian | a1f47b9 | 2011-02-15 19:01:06 -0800 | [diff] [blame] | 603 | |
| 604 | LOG_ALWAYS_FATAL_IF(mHasSurface, |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 605 | "LayerBase::getSurface() has already been called"); |
Mathias Agopian | a1f47b9 | 2011-02-15 19:01:06 -0800 | [diff] [blame] | 606 | |
| 607 | mHasSurface = true; |
| 608 | s = createSurface(); |
| 609 | mClientSurfaceBinder = s->asBinder(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 610 | return s; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | } |
| 612 | |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 613 | wp<IBinder> LayerBase::getSurfaceBinder() const { |
Mathias Agopian | 0d15612 | 2011-01-25 20:17:45 -0800 | [diff] [blame] | 614 | return mClientSurfaceBinder; |
| 615 | } |
| 616 | |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 617 | wp<IBinder> LayerBase::getSurfaceTextureBinder() const { |
Jamie Gennis | 582270d | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 618 | return 0; |
| 619 | } |
| 620 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 621 | // --------------------------------------------------------------------------- |
| 622 | |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 623 | LayerBase::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger, |
| 624 | const sp<LayerBase>& layer) |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 625 | : mFlinger(flinger), mLayer(layer) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Mathias Agopian | b79f61d | 2013-03-05 15:14:58 -0800 | [diff] [blame^] | 628 | LayerBase::LayerCleaner::~LayerCleaner() { |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 629 | // destroy client resources |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 630 | mFlinger->onLayerDestroyed(mLayer); |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 631 | } |
| 632 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | // --------------------------------------------------------------------------- |
| 634 | |
| 635 | }; // namespace android |