blob: c52b49ce812e4a99a92bef7ecc39d64fa5ecf4b6 [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"
32#include "LayerBase.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033#include "SurfaceFlinger.h"
34#include "DisplayHardware/DisplayHardware.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036namespace android {
37
38// ---------------------------------------------------------------------------
39
Mathias Agopianf6679fc2010-08-10 18:09:09 -070040int32_t LayerBase::sSequence = 1;
41
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display)
43 : dpy(display), contentDirty(false),
Mathias Agopianf6679fc2010-08-10 18:09:09 -070044 sequence(uint32_t(android_atomic_inc(&sSequence))),
Mathias Agopiana67932f2011-04-20 14:20:59 -070045 mFlinger(flinger), mFiltering(false),
Mathias Agopiana2f4e562012-04-15 23:34:59 -070046 mNeedsFiltering(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047 mOrientation(0),
Jamie Gennis8d91b422011-09-23 15:54:34 -070048 mPlaneOrientation(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049 mTransactionFlags(0),
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080050 mPremultipliedAlpha(true), mName("unnamed"), mDebug(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051{
52 const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware());
53 mFlags = hw.getFlags();
54}
55
56LayerBase::~LayerBase()
57{
58}
59
Mathias Agopiand1296592010-03-09 19:17:47 -080060void LayerBase::setName(const String8& name) {
61 mName = name;
62}
63
64String8 LayerBase::getName() const {
65 return mName;
66}
67
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068const GraphicPlane& LayerBase::graphicPlane(int dpy) const
69{
70 return mFlinger->graphicPlane(dpy);
71}
72
73GraphicPlane& LayerBase::graphicPlane(int dpy)
74{
75 return mFlinger->graphicPlane(dpy);
76}
77
78void 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 Agopian93ffb862012-05-16 17:07:49 -070087 mCurrentState.active.w = w;
88 mCurrentState.active.h = h;
89 mCurrentState.active.crop.makeInvalid();
90 mCurrentState.z = 0;
91 mCurrentState.alpha = 0xFF;
92 mCurrentState.flags = layerFlags;
93 mCurrentState.sequence = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094 mCurrentState.transform.set(0, 0);
Mathias Agopian93ffb862012-05-16 17:07:49 -070095 mCurrentState.requested = mCurrentState.active;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096
97 // drawing state & current state are identical
98 mDrawingState = mCurrentState;
99}
100
Mathias Agopianba6be542009-09-29 22:32:36 -0700101void LayerBase::commitTransaction() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 mDrawingState = mCurrentState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103}
104void 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}
110bool LayerBase::requestTransaction() {
111 int32_t old = setTransactionFlags(eTransactionNeeded);
112 return ((old & eTransactionNeeded) == 0);
113}
114uint32_t LayerBase::getTransactionFlags(uint32_t flags) {
115 return android_atomic_and(~flags, &mTransactionFlags) & flags;
116}
117uint32_t LayerBase::setTransactionFlags(uint32_t flags) {
118 return android_atomic_or(flags, &mTransactionFlags);
119}
120
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700121bool LayerBase::setPosition(float x, float y) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800122 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}
129bool 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}
137bool LayerBase::setSize(uint32_t w, uint32_t h) {
Mathias Agopian93ffb862012-05-16 17:07:49 -0700138 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800139 return false;
Mathias Agopian93ffb862012-05-16 17:07:49 -0700140 mCurrentState.requested.w = w;
141 mCurrentState.requested.h = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 requestTransaction();
143 return true;
144}
145bool 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}
153bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800154 mCurrentState.sequence++;
155 mCurrentState.transform.set(
156 matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
157 requestTransaction();
158 return true;
159}
160bool LayerBase::setTransparentRegionHint(const Region& transparent) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800161 mCurrentState.sequence++;
162 mCurrentState.transparentRegion = transparent;
163 requestTransaction();
164 return true;
165}
166bool 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 Gennisf15a83f2012-05-10 20:43:55 -0700175bool LayerBase::setCrop(const Rect& crop) {
Mathias Agopian93ffb862012-05-16 17:07:49 -0700176 if (mCurrentState.active.crop == crop)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700177 return false;
178 mCurrentState.sequence++;
Mathias Agopian93ffb862012-05-16 17:07:49 -0700179 mCurrentState.active.crop = crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700180 requestTransaction();
181 return true;
182}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800183
184Rect LayerBase::visibleBounds() const
185{
186 return mTransformedBounds;
187}
188
189void LayerBase::setVisibleRegion(const Region& visibleRegion) {
190 // always called from main thread
191 visibleRegionScreen = visibleRegion;
192}
193
194void LayerBase::setCoveredRegion(const Region& coveredRegion) {
195 // always called from main thread
196 coveredRegionScreen = coveredRegion;
197}
198
199uint32_t LayerBase::doTransaction(uint32_t flags)
200{
201 const Layer::State& front(drawingState());
202 const Layer::State& temp(currentState());
203
Mathias Agopian93ffb862012-05-16 17:07:49 -0700204 if ((front.requested.w != temp.requested.w) ||
205 (front.requested.h != temp.requested.h)) {
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700206 // resize the layer, set the physical size to the requested size
207 Layer::State& editTemp(currentState());
Mathias Agopian93ffb862012-05-16 17:07:49 -0700208 editTemp.active.w = temp.requested.w;
209 editTemp.active.h = temp.requested.h;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700210 }
211
Mathias Agopian93ffb862012-05-16 17:07:49 -0700212 if ((front.active.w != temp.active.w) || (front.active.h != temp.active.h)) {
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700213 // invalidate and recompute the visible regions if needed
214 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700215 }
216
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800217 if (temp.sequence != front.sequence) {
218 // invalidate and recompute the visible regions if needed
219 flags |= eVisibleRegion;
220 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700221
Mathias Agopian733189d2010-12-02 21:32:29 -0800222 // we may use linear filtering, if the matrix scales us
223 const uint8_t type = temp.transform.getType();
224 mNeedsFiltering = (!temp.transform.preserveRects() ||
225 (type >= Transform::SCALE));
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700226 }
227
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800228 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700229 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800230 return flags;
231}
232
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800233void 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();
Mathias Agopianffcf4652011-07-07 17:30:31 -0700238 const DisplayHardware& hw(graphicPlane(0).displayHardware());
239 const uint32_t hw_h = hw.getHeight();
Mathias Agopian93ffb862012-05-16 17:07:49 -0700240 const Rect& crop(s.active.crop);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700241
Mathias Agopian93ffb862012-05-16 17:07:49 -0700242 Rect win(s.active.w, s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700243 if (!crop.isEmpty()) {
244 win.intersect(crop, &win);
245 }
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700246
247 mNumVertices = 4;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700248 tr.transform(mVertices[0], win.left, win.top);
249 tr.transform(mVertices[1], win.left, win.bottom);
250 tr.transform(mVertices[2], win.right, win.bottom);
251 tr.transform(mVertices[3], win.right, win.top);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700252 for (size_t i=0 ; i<4 ; i++)
253 mVertices[i][1] = hw_h - mVertices[i][1];
254
Glenn Kasten99ed2242011-12-15 09:51:17 -0800255 if (CC_UNLIKELY(transformed)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800256 // NOTE: here we could also punt if we have too many rectangles
257 // in the transparent region
258 if (tr.preserveRects()) {
259 // transform the transparent region
260 transparentRegionScreen = tr.transform(s.transparentRegion);
261 } else {
262 // transformation too complex, can't do the transparent region
263 // optimization.
264 transparentRegionScreen.clear();
265 }
266 } else {
267 transparentRegionScreen = s.transparentRegion;
268 }
269
270 // cache a few things...
271 mOrientation = tr.getOrientation();
Jamie Gennis8d91b422011-09-23 15:54:34 -0700272 mPlaneOrientation = planeTransform.getOrientation();
Mathias Agopiand992db32011-08-18 18:31:00 -0700273 mTransform = tr;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700274 mTransformedBounds = tr.transform(win);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800275}
276
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800277void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800278}
279
280void LayerBase::unlockPageFlip(
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800281 const Transform& planeTransform, Region& outDirtyRegion) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800282}
283
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700284void LayerBase::setGeometry(hwc_layer_t* hwcl)
285{
286 hwcl->compositionType = HWC_FRAMEBUFFER;
287 hwcl->hints = 0;
288 hwcl->flags = HWC_SKIP_LAYER;
289 hwcl->transform = 0;
290 hwcl->blending = HWC_BLENDING_NONE;
291
292 // this gives us only the "orientation" component of the transform
293 const State& s(drawingState());
294 const uint32_t finalTransform = s.transform.getOrientation();
295 // we can only handle simple transformation
296 if (finalTransform & Transform::ROT_INVALID) {
297 hwcl->flags = HWC_SKIP_LAYER;
298 } else {
299 hwcl->transform = finalTransform;
300 }
301
302 if (!isOpaque()) {
303 hwcl->blending = mPremultipliedAlpha ?
304 HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE;
305 }
306
307 // scaling is already applied in mTransformedBounds
308 hwcl->displayFrame.left = mTransformedBounds.left;
309 hwcl->displayFrame.top = mTransformedBounds.top;
310 hwcl->displayFrame.right = mTransformedBounds.right;
311 hwcl->displayFrame.bottom = mTransformedBounds.bottom;
312 hwcl->visibleRegionScreen.rects =
313 reinterpret_cast<hwc_rect_t const *>(
314 visibleRegionScreen.getArray(
315 &hwcl->visibleRegionScreen.numRects));
Mathias Agopianc7f33812011-08-30 15:02:41 -0700316
317 hwcl->sourceCrop.left = 0;
318 hwcl->sourceCrop.top = 0;
319 hwcl->sourceCrop.right = mTransformedBounds.width();
320 hwcl->sourceCrop.bottom = mTransformedBounds.height();
Mathias Agopiana350ff92010-08-10 17:14:02 -0700321}
322
323void LayerBase::setPerFrameData(hwc_layer_t* hwcl) {
324 hwcl->compositionType = HWC_FRAMEBUFFER;
325 hwcl->handle = NULL;
326}
327
Mathias Agopiana67932f2011-04-20 14:20:59 -0700328void LayerBase::setFiltering(bool filtering)
329{
330 mFiltering = filtering;
331}
332
333bool LayerBase::getFiltering() const
334{
335 return mFiltering;
336}
337
Mathias Agopianbc7e31a2010-08-10 20:42:20 -0700338void LayerBase::draw(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800340 onDraw(clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800341}
342
Mathias Agopiana67932f2011-04-20 14:20:59 -0700343void LayerBase::drawForSreenShot()
Mathias Agopian74c40c02010-09-29 13:02:36 -0700344{
345 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopiana67932f2011-04-20 14:20:59 -0700346 setFiltering(true);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700347 onDraw( Region(hw.bounds()) );
Mathias Agopiana67932f2011-04-20 14:20:59 -0700348 setFiltering(false);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700349}
350
Mathias Agopian010fccb2010-05-26 22:26:12 -0700351void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
352 GLclampf green, GLclampf blue,
353 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800354{
355 const DisplayHardware& hw(graphicPlane(0).displayHardware());
356 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700357 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700358
Mathias Agopianc492e672011-10-18 14:49:27 -0700359 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700360 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800361 glDisable(GL_BLEND);
Mathias Agopian20f68782009-05-11 00:03:41 -0700362
Mathias Agopian78fd5012010-04-20 14:51:04 -0700363 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700364 glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800365}
366
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700367void LayerBase::clearWithOpenGL(const Region& clip) const
368{
369 clearWithOpenGL(clip,0,0,0,0);
370}
371
Mathias Agopiana67932f2011-04-20 14:20:59 -0700372void LayerBase::drawWithOpenGL(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373{
374 const DisplayHardware& hw(graphicPlane(0).displayHardware());
375 const uint32_t fbHeight = hw.getHeight();
376 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800377
Mathias Agopian49753262010-04-12 15:34:55 -0700378 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800379 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700380 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700381 if (mPremultipliedAlpha) {
382 glColor4f(alpha, alpha, alpha, alpha);
383 } else {
384 glColor4f(1, 1, 1, alpha);
385 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800386 glEnable(GL_BLEND);
387 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700388 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800389 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700390 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700391 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700392 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800393 glEnable(GL_BLEND);
394 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
395 } else {
396 glDisable(GL_BLEND);
397 }
398 }
399
Mathias Agopianb661d662010-08-19 17:01:19 -0700400 struct TexCoords {
401 GLfloat u;
402 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700403 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800404
Mathias Agopian93ffb862012-05-16 17:07:49 -0700405 Rect crop(s.active.w, s.active.h);
406 if (!s.active.crop.isEmpty()) {
407 crop = s.active.crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700408 }
Mathias Agopian93ffb862012-05-16 17:07:49 -0700409 GLfloat left = GLfloat(crop.left) / GLfloat(s.active.w);
410 GLfloat top = GLfloat(crop.top) / GLfloat(s.active.h);
411 GLfloat right = GLfloat(crop.right) / GLfloat(s.active.w);
412 GLfloat bottom = GLfloat(crop.bottom) / GLfloat(s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700413
Mathias Agopianb661d662010-08-19 17:01:19 -0700414 TexCoords texCoords[4];
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700415 texCoords[0].u = left;
416 texCoords[0].v = top;
417 texCoords[1].u = left;
418 texCoords[1].v = bottom;
419 texCoords[2].u = right;
420 texCoords[2].v = bottom;
421 texCoords[3].u = right;
422 texCoords[3].v = top;
423 for (int i = 0; i < 4; i++) {
424 texCoords[i].v = 1.0f - texCoords[i].v;
425 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700426
427 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
428 glVertexPointer(2, GL_FLOAT, 0, mVertices);
429 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700430 glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700431
Mathias Agopian78fd5012010-04-20 14:51:04 -0700432 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700433 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800434}
435
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700436void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
437{
438 const Layer::State& s(drawingState());
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800439
440 snprintf(buffer, SIZE,
441 "+ %s %p (%s)\n",
442 getTypeId(), this, getName().string());
443 result.append(buffer);
444
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800445 s.transparentRegion.dump(result, "transparentRegion");
446 transparentRegionScreen.dump(result, "transparentRegionScreen");
447 visibleRegionScreen.dump(result, "visibleRegionScreen");
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800448
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700449 snprintf(buffer, SIZE,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700450 " "
Mathias Agopian93ffb862012-05-16 17:07:49 -0700451 "z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700452 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700453 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian93ffb862012-05-16 17:07:49 -0700454 s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
455 s.active.crop.left, s.active.crop.top,
456 s.active.crop.right, s.active.crop.bottom,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700457 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700458 s.alpha, s.flags,
459 s.transform[0][0], s.transform[0][1],
460 s.transform[1][0], s.transform[1][1]);
461 result.append(buffer);
462}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700463
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800464void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800465 LayerBase::dump(result, scratch, size);
466}
467
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800468void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
469}
470
471void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800472}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800473
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800474// ---------------------------------------------------------------------------
475
Mathias Agopian631f3582010-05-25 17:51:34 -0700476int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700477
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800478LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700479 const sp<Client>& client)
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800480 : LayerBase(flinger, display),
481 mHasSurface(false),
482 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800483 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800484{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700485}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800486
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800487LayerBaseClient::~LayerBaseClient()
488{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700489 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700490 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700491 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800492 }
493}
494
Mathias Agopiana67932f2011-04-20 14:20:59 -0700495sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800496{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700497 class BSurface : public BnSurface, public LayerCleaner {
498 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
499 public:
500 BSurface(const sp<SurfaceFlinger>& flinger,
501 const sp<LayerBaseClient>& layer)
502 : LayerCleaner(flinger, layer) { }
503 };
504 sp<ISurface> sur(new BSurface(mFlinger, this));
505 return sur;
506}
507
508sp<ISurface> LayerBaseClient::getSurface()
509{
510 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700511 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800512
513 LOG_ALWAYS_FATAL_IF(mHasSurface,
514 "LayerBaseClient::getSurface() has already been called");
515
516 mHasSurface = true;
517 s = createSurface();
518 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700519 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800520}
521
Mathias Agopian0d156122011-01-25 20:17:45 -0800522wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
523 return mClientSurfaceBinder;
524}
525
Jamie Gennis582270d2011-08-17 18:19:00 -0700526wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
527 return 0;
528}
529
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700530void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
531{
532 LayerBase::dump(result, buffer, SIZE);
533
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700534 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700535 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700536 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700537 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700538
539 result.append(buffer);
540}
541
Mathias Agopian48b888a2011-01-19 16:15:53 -0800542
543void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
544{
545 LayerBaseClient::dump(result, scratch, size);
546}
547
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700548// ---------------------------------------------------------------------------
549
Mathias Agopiana67932f2011-04-20 14:20:59 -0700550LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
551 const sp<LayerBaseClient>& layer)
552 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700553}
554
Mathias Agopiana67932f2011-04-20 14:20:59 -0700555LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700556 // destroy client resources
Mathias Agopiana67932f2011-04-20 14:20:59 -0700557 mFlinger->destroySurface(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700558}
559
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800560// ---------------------------------------------------------------------------
561
562}; // namespace android