blob: 7a47f620f39228dc474787733c37906d898b39b3 [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 Agopianf9abeb92011-09-09 01:47:48 -070046 mNeedsFiltering(false), mInOverlay(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 Agopian245e4d72010-04-21 15:24:11 -070050 mPremultipliedAlpha(true), mName("unnamed"), mDebug(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051 mInvalidate(0)
52{
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 Agopian7e4a5872009-09-29 22:39:22 -070088 mCurrentState.z = 0;
89 mCurrentState.w = w;
90 mCurrentState.h = h;
91 mCurrentState.requested_w = w;
92 mCurrentState.requested_h = h;
93 mCurrentState.alpha = 0xFF;
94 mCurrentState.flags = layerFlags;
95 mCurrentState.sequence = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096 mCurrentState.transform.set(0, 0);
97
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 Agopian7e4a5872009-09-29 22:39:22 -0700139 if (mCurrentState.requested_w == w && mCurrentState.requested_h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140 return false;
Mathias Agopian7e4a5872009-09-29 22:39:22 -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}
176
177Rect LayerBase::visibleBounds() const
178{
179 return mTransformedBounds;
180}
181
182void LayerBase::setVisibleRegion(const Region& visibleRegion) {
183 // always called from main thread
184 visibleRegionScreen = visibleRegion;
185}
186
187void LayerBase::setCoveredRegion(const Region& coveredRegion) {
188 // always called from main thread
189 coveredRegionScreen = coveredRegion;
190}
191
192uint32_t LayerBase::doTransaction(uint32_t flags)
193{
194 const Layer::State& front(drawingState());
195 const Layer::State& temp(currentState());
196
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700197 if ((front.requested_w != temp.requested_w) ||
198 (front.requested_h != temp.requested_h)) {
199 // resize the layer, set the physical size to the requested size
200 Layer::State& editTemp(currentState());
201 editTemp.w = temp.requested_w;
202 editTemp.h = temp.requested_h;
203 }
204
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700205 if ((front.w != temp.w) || (front.h != temp.h)) {
206 // invalidate and recompute the visible regions if needed
207 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700208 }
209
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800210 if (temp.sequence != front.sequence) {
211 // invalidate and recompute the visible regions if needed
212 flags |= eVisibleRegion;
213 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700214
Mathias Agopian733189d2010-12-02 21:32:29 -0800215 // we may use linear filtering, if the matrix scales us
216 const uint8_t type = temp.transform.getType();
217 mNeedsFiltering = (!temp.transform.preserveRects() ||
218 (type >= Transform::SCALE));
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700219 }
220
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800221 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700222 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800223 return flags;
224}
225
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800226void LayerBase::validateVisibility(const Transform& planeTransform)
227{
228 const Layer::State& s(drawingState());
229 const Transform tr(planeTransform * s.transform);
230 const bool transformed = tr.transformed();
Mathias Agopianffcf4652011-07-07 17:30:31 -0700231 const DisplayHardware& hw(graphicPlane(0).displayHardware());
232 const uint32_t hw_h = hw.getHeight();
233
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700234 uint32_t w = s.w;
235 uint32_t h = s.h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800236 tr.transform(mVertices[0], 0, 0);
237 tr.transform(mVertices[1], 0, h);
238 tr.transform(mVertices[2], w, h);
239 tr.transform(mVertices[3], w, 0);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700240 for (size_t i=0 ; i<4 ; i++)
241 mVertices[i][1] = hw_h - mVertices[i][1];
242
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800243 if (UNLIKELY(transformed)) {
244 // NOTE: here we could also punt if we have too many rectangles
245 // in the transparent region
246 if (tr.preserveRects()) {
247 // transform the transparent region
248 transparentRegionScreen = tr.transform(s.transparentRegion);
249 } else {
250 // transformation too complex, can't do the transparent region
251 // optimization.
252 transparentRegionScreen.clear();
253 }
254 } else {
255 transparentRegionScreen = s.transparentRegion;
256 }
257
258 // cache a few things...
259 mOrientation = tr.getOrientation();
Jamie Gennis8d91b422011-09-23 15:54:34 -0700260 mPlaneOrientation = planeTransform.getOrientation();
Mathias Agopiand992db32011-08-18 18:31:00 -0700261 mTransform = tr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800262 mTransformedBounds = tr.makeBounds(w, h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800263}
264
265void LayerBase::lockPageFlip(bool& recomputeVisibleRegions)
266{
267}
268
269void LayerBase::unlockPageFlip(
270 const Transform& planeTransform, Region& outDirtyRegion)
271{
272 if ((android_atomic_and(~1, &mInvalidate)&1) == 1) {
273 outDirtyRegion.orSelf(visibleRegionScreen);
274 }
275}
276
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800277void LayerBase::invalidate()
278{
279 if ((android_atomic_or(1, &mInvalidate)&1) == 0) {
280 mFlinger->signalEvent();
281 }
282}
283
284void LayerBase::drawRegion(const Region& reg) const
285{
Mathias Agopian20f68782009-05-11 00:03:41 -0700286 Region::const_iterator it = reg.begin();
287 Region::const_iterator const end = reg.end();
288 if (it != end) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800289 Rect r;
290 const DisplayHardware& hw(graphicPlane(0).displayHardware());
291 const int32_t fbWidth = hw.getWidth();
292 const int32_t fbHeight = hw.getHeight();
293 const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 },
294 { fbWidth, fbHeight }, { 0, fbHeight } };
295 glVertexPointer(2, GL_SHORT, 0, vertices);
Mathias Agopian20f68782009-05-11 00:03:41 -0700296 while (it != end) {
297 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800298 const GLint sy = fbHeight - (r.top + r.height());
299 glScissor(r.left, sy, r.width(), r.height());
300 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
301 }
302 }
303}
304
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700305void LayerBase::setGeometry(hwc_layer_t* hwcl)
306{
307 hwcl->compositionType = HWC_FRAMEBUFFER;
308 hwcl->hints = 0;
309 hwcl->flags = HWC_SKIP_LAYER;
310 hwcl->transform = 0;
311 hwcl->blending = HWC_BLENDING_NONE;
312
313 // this gives us only the "orientation" component of the transform
314 const State& s(drawingState());
315 const uint32_t finalTransform = s.transform.getOrientation();
316 // we can only handle simple transformation
317 if (finalTransform & Transform::ROT_INVALID) {
318 hwcl->flags = HWC_SKIP_LAYER;
319 } else {
320 hwcl->transform = finalTransform;
321 }
322
323 if (!isOpaque()) {
324 hwcl->blending = mPremultipliedAlpha ?
325 HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE;
326 }
327
328 // scaling is already applied in mTransformedBounds
329 hwcl->displayFrame.left = mTransformedBounds.left;
330 hwcl->displayFrame.top = mTransformedBounds.top;
331 hwcl->displayFrame.right = mTransformedBounds.right;
332 hwcl->displayFrame.bottom = mTransformedBounds.bottom;
333 hwcl->visibleRegionScreen.rects =
334 reinterpret_cast<hwc_rect_t const *>(
335 visibleRegionScreen.getArray(
336 &hwcl->visibleRegionScreen.numRects));
Mathias Agopianc7f33812011-08-30 15:02:41 -0700337
338 hwcl->sourceCrop.left = 0;
339 hwcl->sourceCrop.top = 0;
340 hwcl->sourceCrop.right = mTransformedBounds.width();
341 hwcl->sourceCrop.bottom = mTransformedBounds.height();
Mathias Agopiana350ff92010-08-10 17:14:02 -0700342}
343
344void LayerBase::setPerFrameData(hwc_layer_t* hwcl) {
345 hwcl->compositionType = HWC_FRAMEBUFFER;
346 hwcl->handle = NULL;
347}
348
Mathias Agopianf384cc32011-09-08 18:31:55 -0700349void LayerBase::setOverlay(bool inOverlay) {
350 mInOverlay = inOverlay;
351}
352
353bool LayerBase::isOverlay() const {
354 return mInOverlay;
355}
356
Mathias Agopiana67932f2011-04-20 14:20:59 -0700357void LayerBase::setFiltering(bool filtering)
358{
359 mFiltering = filtering;
360}
361
362bool LayerBase::getFiltering() const
363{
364 return mFiltering;
365}
366
Mathias Agopianbc7e31a2010-08-10 20:42:20 -0700367void LayerBase::draw(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800368{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800369 // reset GL state
370 glEnable(GL_SCISSOR_TEST);
371
372 onDraw(clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373}
374
Mathias Agopiana67932f2011-04-20 14:20:59 -0700375void LayerBase::drawForSreenShot()
Mathias Agopian74c40c02010-09-29 13:02:36 -0700376{
377 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopiana67932f2011-04-20 14:20:59 -0700378 setFiltering(true);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700379 onDraw( Region(hw.bounds()) );
Mathias Agopiana67932f2011-04-20 14:20:59 -0700380 setFiltering(false);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700381}
382
Mathias Agopian010fccb2010-05-26 22:26:12 -0700383void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
384 GLclampf green, GLclampf blue,
385 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800386{
387 const DisplayHardware& hw(graphicPlane(0).displayHardware());
388 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700389 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700390
Mathias Agopiana67932f2011-04-20 14:20:59 -0700391#if defined(GL_OES_EGL_image_external)
392 if (GLExtensions::getInstance().haveTextureExternal()) {
393 glDisable(GL_TEXTURE_EXTERNAL_OES);
394 }
395#endif
396 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800397 glDisable(GL_BLEND);
398 glDisable(GL_DITHER);
Mathias Agopian20f68782009-05-11 00:03:41 -0700399
400 Region::const_iterator it = clip.begin();
401 Region::const_iterator const end = clip.end();
Mathias Agopian95a666b2009-09-24 14:57:26 -0700402 glEnable(GL_SCISSOR_TEST);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700403 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopian95a666b2009-09-24 14:57:26 -0700404 while (it != end) {
405 const Rect& r = *it++;
406 const GLint sy = fbHeight - (r.top + r.height());
407 glScissor(r.left, sy, r.width(), r.height());
408 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800409 }
410}
411
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700412void LayerBase::clearWithOpenGL(const Region& clip) const
413{
414 clearWithOpenGL(clip,0,0,0,0);
415}
416
Mathias Agopiana67932f2011-04-20 14:20:59 -0700417void LayerBase::drawWithOpenGL(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800418{
419 const DisplayHardware& hw(graphicPlane(0).displayHardware());
420 const uint32_t fbHeight = hw.getHeight();
421 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800422
Mathias Agopian49753262010-04-12 15:34:55 -0700423 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800424 if (UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700425 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700426 if (mPremultipliedAlpha) {
427 glColor4f(alpha, alpha, alpha, alpha);
428 } else {
429 glColor4f(1, 1, 1, alpha);
430 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800431 glEnable(GL_BLEND);
432 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700433 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800434 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700435 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700436 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700437 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800438 glEnable(GL_BLEND);
439 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
440 } else {
441 glDisable(GL_BLEND);
442 }
443 }
444
Mathias Agopianb661d662010-08-19 17:01:19 -0700445 struct TexCoords {
446 GLfloat u;
447 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700448 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800449
Mathias Agopianb661d662010-08-19 17:01:19 -0700450 TexCoords texCoords[4];
Mathias Agopiana67932f2011-04-20 14:20:59 -0700451 texCoords[0].u = 0;
452 texCoords[0].v = 1;
453 texCoords[1].u = 0;
454 texCoords[1].v = 0;
455 texCoords[2].u = 1;
456 texCoords[2].v = 0;
457 texCoords[3].u = 1;
458 texCoords[3].v = 1;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700459
Mathias Agopian0a917752010-06-14 21:20:00 -0700460 if (needsDithering()) {
461 glEnable(GL_DITHER);
462 } else {
463 glDisable(GL_DITHER);
464 }
465
Mathias Agopian78fd5012010-04-20 14:51:04 -0700466 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
467 glVertexPointer(2, GL_FLOAT, 0, mVertices);
468 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
469
Mathias Agopianb661d662010-08-19 17:01:19 -0700470 Region::const_iterator it = clip.begin();
471 Region::const_iterator const end = clip.end();
Mathias Agopian78fd5012010-04-20 14:51:04 -0700472 while (it != end) {
473 const Rect& r = *it++;
474 const GLint sy = fbHeight - (r.top + r.height());
475 glScissor(r.left, sy, r.width(), r.height());
476 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
477 }
478 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800479}
480
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700481void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
482{
483 const Layer::State& s(drawingState());
484 snprintf(buffer, SIZE,
Mathias Agopian22da60c2011-09-09 00:49:11 -0700485 "+ %s %p (%s)\n"
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700486 " "
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700487 "z=%9d, pos=(%g,%g), size=(%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700488 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700489 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian22da60c2011-09-09 00:49:11 -0700490 getTypeId(), this, getName().string(),
491 s.z, s.transform.tx(), s.transform.ty(), s.w, s.h,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700492 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700493 s.alpha, s.flags,
494 s.transform[0][0], s.transform[0][1],
495 s.transform[1][0], s.transform[1][1]);
496 result.append(buffer);
497}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700498
Mathias Agopian48b888a2011-01-19 16:15:53 -0800499void LayerBase::shortDump(String8& result, char* scratch, size_t size) const
500{
501 LayerBase::dump(result, scratch, size);
502}
503
504
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800505// ---------------------------------------------------------------------------
506
Mathias Agopian631f3582010-05-25 17:51:34 -0700507int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700508
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800509LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700510 const sp<Client>& client)
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800511 : LayerBase(flinger, display),
512 mHasSurface(false),
513 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800514 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800515{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700516}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800517
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800518LayerBaseClient::~LayerBaseClient()
519{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700520 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700521 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700522 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800523 }
524}
525
Mathias Agopiana67932f2011-04-20 14:20:59 -0700526sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800527{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700528 class BSurface : public BnSurface, public LayerCleaner {
529 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
530 public:
531 BSurface(const sp<SurfaceFlinger>& flinger,
532 const sp<LayerBaseClient>& layer)
533 : LayerCleaner(flinger, layer) { }
534 };
535 sp<ISurface> sur(new BSurface(mFlinger, this));
536 return sur;
537}
538
539sp<ISurface> LayerBaseClient::getSurface()
540{
541 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700542 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800543
544 LOG_ALWAYS_FATAL_IF(mHasSurface,
545 "LayerBaseClient::getSurface() has already been called");
546
547 mHasSurface = true;
548 s = createSurface();
549 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700550 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800551}
552
Mathias Agopian0d156122011-01-25 20:17:45 -0800553wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
554 return mClientSurfaceBinder;
555}
556
Jamie Gennis582270d2011-08-17 18:19:00 -0700557wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
558 return 0;
559}
560
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700561void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
562{
563 LayerBase::dump(result, buffer, SIZE);
564
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700565 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700566 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700567 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700568 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700569
570 result.append(buffer);
571}
572
Mathias Agopian48b888a2011-01-19 16:15:53 -0800573
574void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
575{
576 LayerBaseClient::dump(result, scratch, size);
577}
578
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700579// ---------------------------------------------------------------------------
580
Mathias Agopiana67932f2011-04-20 14:20:59 -0700581LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
582 const sp<LayerBaseClient>& layer)
583 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700584}
585
Mathias Agopiana67932f2011-04-20 14:20:59 -0700586LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700587 // destroy client resources
Mathias Agopiana67932f2011-04-20 14:20:59 -0700588 mFlinger->destroySurface(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700589}
590
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800591// ---------------------------------------------------------------------------
592
593}; // namespace android