blob: 893dcb9d03e797e3cde0c9cb55fcbf5e60ae2a9a [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Projectedbf3b62009-03-03 19:31:44 -080017#include <stdlib.h>
18#include <stdint.h>
19#include <sys/types.h>
20
21#include <utils/Errors.h>
22#include <utils/Log.h>
Mathias Agopian310f8da2009-05-22 01:27:01 -070023#include <binder/IPCThreadState.h>
24#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025
26#include <GLES/gl.h>
27#include <GLES/glext.h>
28
29#include <hardware/hardware.h>
30
31#include "clz.h"
Mathias Agopiandb403e82012-06-18 16:47:56 -070032#include "Client.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033#include "LayerBase.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034#include "SurfaceFlinger.h"
35#include "DisplayHardware/DisplayHardware.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037namespace android {
38
39// ---------------------------------------------------------------------------
40
Mathias Agopianf6679fc2010-08-10 18:09:09 -070041int32_t LayerBase::sSequence = 1;
42
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display)
44 : dpy(display), contentDirty(false),
Mathias Agopianf6679fc2010-08-10 18:09:09 -070045 sequence(uint32_t(android_atomic_inc(&sSequence))),
Mathias Agopiana67932f2011-04-20 14:20:59 -070046 mFlinger(flinger), mFiltering(false),
Mathias Agopiana2f4e562012-04-15 23:34:59 -070047 mNeedsFiltering(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048 mOrientation(0),
Jamie Gennis8d91b422011-09-23 15:54:34 -070049 mPlaneOrientation(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050 mTransactionFlags(0),
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080051 mPremultipliedAlpha(true), mName("unnamed"), mDebug(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052{
53 const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware());
54 mFlags = hw.getFlags();
55}
56
57LayerBase::~LayerBase()
58{
59}
60
Mathias Agopiand1296592010-03-09 19:17:47 -080061void LayerBase::setName(const String8& name) {
62 mName = name;
63}
64
65String8 LayerBase::getName() const {
66 return mName;
67}
68
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069const GraphicPlane& LayerBase::graphicPlane(int dpy) const
70{
71 return mFlinger->graphicPlane(dpy);
72}
73
74GraphicPlane& LayerBase::graphicPlane(int dpy)
75{
76 return mFlinger->graphicPlane(dpy);
77}
78
79void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags)
80{
81 uint32_t layerFlags = 0;
82 if (flags & ISurfaceComposer::eHidden)
83 layerFlags = ISurfaceComposer::eLayerHidden;
84
85 if (flags & ISurfaceComposer::eNonPremultiplied)
86 mPremultipliedAlpha = false;
87
Mathias Agopian93ffb862012-05-16 17:07:49 -070088 mCurrentState.active.w = w;
89 mCurrentState.active.h = h;
90 mCurrentState.active.crop.makeInvalid();
91 mCurrentState.z = 0;
92 mCurrentState.alpha = 0xFF;
93 mCurrentState.flags = layerFlags;
94 mCurrentState.sequence = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095 mCurrentState.transform.set(0, 0);
Mathias Agopian93ffb862012-05-16 17:07:49 -070096 mCurrentState.requested = mCurrentState.active;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097
98 // drawing state & current state are identical
99 mDrawingState = mCurrentState;
100}
101
Mathias Agopianba6be542009-09-29 22:32:36 -0700102void LayerBase::commitTransaction() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103 mDrawingState = mCurrentState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104}
105void LayerBase::forceVisibilityTransaction() {
106 // this can be called without SurfaceFlinger.mStateLock, but if we
107 // can atomically increment the sequence number, it doesn't matter.
108 android_atomic_inc(&mCurrentState.sequence);
109 requestTransaction();
110}
111bool LayerBase::requestTransaction() {
112 int32_t old = setTransactionFlags(eTransactionNeeded);
113 return ((old & eTransactionNeeded) == 0);
114}
115uint32_t LayerBase::getTransactionFlags(uint32_t flags) {
116 return android_atomic_and(~flags, &mTransactionFlags) & flags;
117}
118uint32_t LayerBase::setTransactionFlags(uint32_t flags) {
119 return android_atomic_or(flags, &mTransactionFlags);
120}
121
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700122bool LayerBase::setPosition(float x, float y) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123 if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
124 return false;
125 mCurrentState.sequence++;
126 mCurrentState.transform.set(x, y);
127 requestTransaction();
128 return true;
129}
130bool LayerBase::setLayer(uint32_t z) {
131 if (mCurrentState.z == z)
132 return false;
133 mCurrentState.sequence++;
134 mCurrentState.z = z;
135 requestTransaction();
136 return true;
137}
138bool LayerBase::setSize(uint32_t w, uint32_t h) {
Mathias Agopian93ffb862012-05-16 17:07:49 -0700139 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140 return false;
Mathias Agopian93ffb862012-05-16 17:07:49 -0700141 mCurrentState.requested.w = w;
142 mCurrentState.requested.h = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 requestTransaction();
144 return true;
145}
146bool LayerBase::setAlpha(uint8_t alpha) {
147 if (mCurrentState.alpha == alpha)
148 return false;
149 mCurrentState.sequence++;
150 mCurrentState.alpha = alpha;
151 requestTransaction();
152 return true;
153}
154bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800155 mCurrentState.sequence++;
156 mCurrentState.transform.set(
157 matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
158 requestTransaction();
159 return true;
160}
161bool LayerBase::setTransparentRegionHint(const Region& transparent) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800162 mCurrentState.sequence++;
163 mCurrentState.transparentRegion = transparent;
164 requestTransaction();
165 return true;
166}
167bool LayerBase::setFlags(uint8_t flags, uint8_t mask) {
168 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
169 if (mCurrentState.flags == newFlags)
170 return false;
171 mCurrentState.sequence++;
172 mCurrentState.flags = newFlags;
173 requestTransaction();
174 return true;
175}
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700176bool LayerBase::setCrop(const Rect& crop) {
Mathias Agopianb30c4152012-05-16 18:21:32 -0700177 if (mCurrentState.requested.crop == crop)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700178 return false;
179 mCurrentState.sequence++;
Mathias Agopianb30c4152012-05-16 18:21:32 -0700180 mCurrentState.requested.crop = crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700181 requestTransaction();
182 return true;
183}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800184
185Rect LayerBase::visibleBounds() const
186{
187 return mTransformedBounds;
188}
189
190void LayerBase::setVisibleRegion(const Region& visibleRegion) {
191 // always called from main thread
192 visibleRegionScreen = visibleRegion;
193}
194
195void LayerBase::setCoveredRegion(const Region& coveredRegion) {
196 // always called from main thread
197 coveredRegionScreen = coveredRegion;
198}
199
200uint32_t LayerBase::doTransaction(uint32_t flags)
201{
202 const Layer::State& front(drawingState());
203 const Layer::State& temp(currentState());
204
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700205 // always set active to requested, unless we're asked not to
206 // this is used by Layer, which special cases resizes.
207 if (flags & eDontUpdateGeometryState) {
208 } else {
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700209 Layer::State& editTemp(currentState());
Mathias Agopianb30c4152012-05-16 18:21:32 -0700210 editTemp.active = temp.requested;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700211 }
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700212
Mathias Agopianb30c4152012-05-16 18:21:32 -0700213 if (front.active != temp.active) {
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700214 // invalidate and recompute the visible regions if needed
215 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700216 }
217
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800218 if (temp.sequence != front.sequence) {
219 // invalidate and recompute the visible regions if needed
220 flags |= eVisibleRegion;
221 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700222
Mathias Agopian733189d2010-12-02 21:32:29 -0800223 // we may use linear filtering, if the matrix scales us
224 const uint8_t type = temp.transform.getType();
225 mNeedsFiltering = (!temp.transform.preserveRects() ||
226 (type >= Transform::SCALE));
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700227 }
228
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800229 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700230 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800231 return flags;
232}
233
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800234void LayerBase::validateVisibility(const Transform& planeTransform)
235{
236 const Layer::State& s(drawingState());
237 const Transform tr(planeTransform * s.transform);
238 const bool transformed = tr.transformed();
Mathias Agopianffcf4652011-07-07 17:30:31 -0700239 const DisplayHardware& hw(graphicPlane(0).displayHardware());
240 const uint32_t hw_h = hw.getHeight();
Mathias Agopian93ffb862012-05-16 17:07:49 -0700241 const Rect& crop(s.active.crop);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700242
Mathias Agopian93ffb862012-05-16 17:07:49 -0700243 Rect win(s.active.w, s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700244 if (!crop.isEmpty()) {
245 win.intersect(crop, &win);
246 }
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700247
248 mNumVertices = 4;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700249 tr.transform(mVertices[0], win.left, win.top);
250 tr.transform(mVertices[1], win.left, win.bottom);
251 tr.transform(mVertices[2], win.right, win.bottom);
252 tr.transform(mVertices[3], win.right, win.top);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700253 for (size_t i=0 ; i<4 ; i++)
254 mVertices[i][1] = hw_h - mVertices[i][1];
255
Glenn Kasten99ed2242011-12-15 09:51:17 -0800256 if (CC_UNLIKELY(transformed)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800257 // NOTE: here we could also punt if we have too many rectangles
258 // in the transparent region
259 if (tr.preserveRects()) {
260 // transform the transparent region
261 transparentRegionScreen = tr.transform(s.transparentRegion);
262 } else {
263 // transformation too complex, can't do the transparent region
264 // optimization.
265 transparentRegionScreen.clear();
266 }
267 } else {
268 transparentRegionScreen = s.transparentRegion;
269 }
270
271 // cache a few things...
272 mOrientation = tr.getOrientation();
Jamie Gennis8d91b422011-09-23 15:54:34 -0700273 mPlaneOrientation = planeTransform.getOrientation();
Mathias Agopiand992db32011-08-18 18:31:00 -0700274 mTransform = tr;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700275 mTransformedBounds = tr.transform(win);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800276}
277
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800278void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800279}
280
281void LayerBase::unlockPageFlip(
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800282 const Transform& planeTransform, Region& outDirtyRegion) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800283}
284
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700285void LayerBase::setGeometry(HWComposer::HWCLayerInterface& layer)
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700286{
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700287 layer.setDefaultState();
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700288
289 // this gives us only the "orientation" component of the transform
290 const State& s(drawingState());
291 const uint32_t finalTransform = s.transform.getOrientation();
292 // we can only handle simple transformation
293 if (finalTransform & Transform::ROT_INVALID) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700294 layer.setTransform(0);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700295 } else {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700296 layer.setTransform(finalTransform);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700297 }
298
299 if (!isOpaque()) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700300 layer.setBlending(mPremultipliedAlpha ?
301 HWC_BLENDING_PREMULT :
302 HWC_BLENDING_COVERAGE);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700303 }
304
305 // scaling is already applied in mTransformedBounds
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700306 layer.setFrame(mTransformedBounds);
307 layer.setVisibleRegionScreen(visibleRegionScreen);
308 layer.setCrop(mTransformedBounds.getBounds());
Mathias Agopiana350ff92010-08-10 17:14:02 -0700309}
310
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700311void LayerBase::setPerFrameData(HWComposer::HWCLayerInterface& layer) {
312 layer.setBuffer(0);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700313}
314
Mathias Agopiana67932f2011-04-20 14:20:59 -0700315void LayerBase::setFiltering(bool filtering)
316{
317 mFiltering = filtering;
318}
319
320bool LayerBase::getFiltering() const
321{
322 return mFiltering;
323}
324
Mathias Agopianbc7e31a2010-08-10 20:42:20 -0700325void LayerBase::draw(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800326{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800327 onDraw(clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800328}
329
Mathias Agopiana67932f2011-04-20 14:20:59 -0700330void LayerBase::drawForSreenShot()
Mathias Agopian74c40c02010-09-29 13:02:36 -0700331{
332 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopiana67932f2011-04-20 14:20:59 -0700333 setFiltering(true);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700334 onDraw( Region(hw.bounds()) );
Mathias Agopiana67932f2011-04-20 14:20:59 -0700335 setFiltering(false);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700336}
337
Mathias Agopian010fccb2010-05-26 22:26:12 -0700338void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
339 GLclampf green, GLclampf blue,
340 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800341{
342 const DisplayHardware& hw(graphicPlane(0).displayHardware());
343 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700344 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700345
Mathias Agopianc492e672011-10-18 14:49:27 -0700346 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700347 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800348 glDisable(GL_BLEND);
Mathias Agopian20f68782009-05-11 00:03:41 -0700349
Mathias Agopian78fd5012010-04-20 14:51:04 -0700350 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700351 glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800352}
353
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700354void LayerBase::clearWithOpenGL(const Region& clip) const
355{
356 clearWithOpenGL(clip,0,0,0,0);
357}
358
Mathias Agopiana67932f2011-04-20 14:20:59 -0700359void LayerBase::drawWithOpenGL(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800360{
361 const DisplayHardware& hw(graphicPlane(0).displayHardware());
362 const uint32_t fbHeight = hw.getHeight();
363 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800364
Mathias Agopian49753262010-04-12 15:34:55 -0700365 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800366 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700367 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700368 if (mPremultipliedAlpha) {
369 glColor4f(alpha, alpha, alpha, alpha);
370 } else {
371 glColor4f(1, 1, 1, alpha);
372 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373 glEnable(GL_BLEND);
374 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700375 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800376 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700377 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700378 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700379 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800380 glEnable(GL_BLEND);
381 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
382 } else {
383 glDisable(GL_BLEND);
384 }
385 }
386
Mathias Agopianb661d662010-08-19 17:01:19 -0700387 struct TexCoords {
388 GLfloat u;
389 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700390 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800391
Mathias Agopian93ffb862012-05-16 17:07:49 -0700392 Rect crop(s.active.w, s.active.h);
393 if (!s.active.crop.isEmpty()) {
394 crop = s.active.crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700395 }
Mathias Agopian93ffb862012-05-16 17:07:49 -0700396 GLfloat left = GLfloat(crop.left) / GLfloat(s.active.w);
397 GLfloat top = GLfloat(crop.top) / GLfloat(s.active.h);
398 GLfloat right = GLfloat(crop.right) / GLfloat(s.active.w);
399 GLfloat bottom = GLfloat(crop.bottom) / GLfloat(s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700400
Mathias Agopianb661d662010-08-19 17:01:19 -0700401 TexCoords texCoords[4];
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700402 texCoords[0].u = left;
403 texCoords[0].v = top;
404 texCoords[1].u = left;
405 texCoords[1].v = bottom;
406 texCoords[2].u = right;
407 texCoords[2].v = bottom;
408 texCoords[3].u = right;
409 texCoords[3].v = top;
410 for (int i = 0; i < 4; i++) {
411 texCoords[i].v = 1.0f - texCoords[i].v;
412 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700413
414 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
415 glVertexPointer(2, GL_FLOAT, 0, mVertices);
416 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700417 glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700418
Mathias Agopian78fd5012010-04-20 14:51:04 -0700419 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700420 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800421}
422
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700423void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
424{
425 const Layer::State& s(drawingState());
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800426
427 snprintf(buffer, SIZE,
428 "+ %s %p (%s)\n",
429 getTypeId(), this, getName().string());
430 result.append(buffer);
431
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800432 s.transparentRegion.dump(result, "transparentRegion");
433 transparentRegionScreen.dump(result, "transparentRegionScreen");
434 visibleRegionScreen.dump(result, "visibleRegionScreen");
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800435
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700436 snprintf(buffer, SIZE,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700437 " "
Mathias Agopian93ffb862012-05-16 17:07:49 -0700438 "z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700439 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700440 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian93ffb862012-05-16 17:07:49 -0700441 s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
442 s.active.crop.left, s.active.crop.top,
443 s.active.crop.right, s.active.crop.bottom,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700444 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700445 s.alpha, s.flags,
446 s.transform[0][0], s.transform[0][1],
447 s.transform[1][0], s.transform[1][1]);
448 result.append(buffer);
449}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700450
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800451void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800452 LayerBase::dump(result, scratch, size);
453}
454
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800455void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
456}
457
458void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800459}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800460
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800461// ---------------------------------------------------------------------------
462
Mathias Agopian631f3582010-05-25 17:51:34 -0700463int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700464
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800465LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700466 const sp<Client>& client)
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800467 : LayerBase(flinger, display),
468 mHasSurface(false),
469 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800470 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800471{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700472}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800473
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800474LayerBaseClient::~LayerBaseClient()
475{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700476 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700477 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700478 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800479 }
480}
481
Mathias Agopiana67932f2011-04-20 14:20:59 -0700482sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800483{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700484 class BSurface : public BnSurface, public LayerCleaner {
485 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
486 public:
487 BSurface(const sp<SurfaceFlinger>& flinger,
488 const sp<LayerBaseClient>& layer)
489 : LayerCleaner(flinger, layer) { }
490 };
491 sp<ISurface> sur(new BSurface(mFlinger, this));
492 return sur;
493}
494
495sp<ISurface> LayerBaseClient::getSurface()
496{
497 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700498 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800499
500 LOG_ALWAYS_FATAL_IF(mHasSurface,
501 "LayerBaseClient::getSurface() has already been called");
502
503 mHasSurface = true;
504 s = createSurface();
505 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700506 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800507}
508
Mathias Agopian0d156122011-01-25 20:17:45 -0800509wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
510 return mClientSurfaceBinder;
511}
512
Jamie Gennis582270d2011-08-17 18:19:00 -0700513wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
514 return 0;
515}
516
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700517void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
518{
519 LayerBase::dump(result, buffer, SIZE);
520
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700521 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700522 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700523 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700524 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700525
526 result.append(buffer);
527}
528
Mathias Agopian48b888a2011-01-19 16:15:53 -0800529
530void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
531{
532 LayerBaseClient::dump(result, scratch, size);
533}
534
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700535// ---------------------------------------------------------------------------
536
Mathias Agopiana67932f2011-04-20 14:20:59 -0700537LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
538 const sp<LayerBaseClient>& layer)
539 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700540}
541
Mathias Agopiana67932f2011-04-20 14:20:59 -0700542LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700543 // destroy client resources
Mathias Agopiana67932f2011-04-20 14:20:59 -0700544 mFlinger->destroySurface(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700545}
546
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800547// ---------------------------------------------------------------------------
548
549}; // namespace android