blob: dfc531e2f15fdaa7c02a024da703cce4785bceae [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Project9066cfe2009-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 Agopian947f4f42009-05-22 01:27:01 -070023#include <binder/IPCThreadState.h>
24#include <binder/IServiceManager.h>
The Android Open Source Project9066cfe2009-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 Project9066cfe2009-03-03 19:31:44 -080033#include "SurfaceFlinger.h"
34#include "DisplayHardware/DisplayHardware.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036namespace android {
37
38// ---------------------------------------------------------------------------
39
Mathias Agopian1efba9a2010-08-10 18:09:09 -070040int32_t LayerBase::sSequence = 1;
41
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display)
43 : dpy(display), contentDirty(false),
Mathias Agopian1efba9a2010-08-10 18:09:09 -070044 sequence(uint32_t(android_atomic_inc(&sSequence))),
Mathias Agopian7bb843c2011-04-20 14:20:59 -070045 mFlinger(flinger), mFiltering(false),
Mathias Agopian92377032010-05-26 22:08:52 -070046 mNeedsFiltering(false),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 mOrientation(0),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 mTransactionFlags(0),
Mathias Agopiana8a0aa82010-04-21 15:24:11 -070049 mPremultipliedAlpha(true), mName("unnamed"), mDebug(false),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 mInvalidate(0)
51{
52 const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware());
53 mFlags = hw.getFlags();
54}
55
56LayerBase::~LayerBase()
57{
58}
59
Mathias Agopian015b5972010-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 Project9066cfe2009-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 Agopiane1b6f242009-09-29 22:39:22 -070087 mCurrentState.z = 0;
88 mCurrentState.w = w;
89 mCurrentState.h = h;
90 mCurrentState.requested_w = w;
91 mCurrentState.requested_h = h;
92 mCurrentState.alpha = 0xFF;
93 mCurrentState.flags = layerFlags;
94 mCurrentState.sequence = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 mCurrentState.transform.set(0, 0);
96
97 // drawing state & current state are identical
98 mDrawingState = mCurrentState;
99}
100
Mathias Agopian88516172009-09-29 22:32:36 -0700101void LayerBase::commitTransaction() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 mDrawingState = mCurrentState;
The Android Open Source Project9066cfe2009-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 Agopian34cb9f2a2011-08-30 18:51:54 -0700121bool LayerBase::setPosition(float x, float y) {
The Android Open Source Project9066cfe2009-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 Agopiane1b6f242009-09-29 22:39:22 -0700138 if (mCurrentState.requested_w == w && mCurrentState.requested_h == h)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 return false;
Mathias Agopiane1b6f242009-09-29 22:39:22 -0700140 mCurrentState.requested_w = w;
141 mCurrentState.requested_h = h;
The Android Open Source Project9066cfe2009-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 Project9066cfe2009-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 Project9066cfe2009-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}
175
176Rect LayerBase::visibleBounds() const
177{
178 return mTransformedBounds;
179}
180
181void LayerBase::setVisibleRegion(const Region& visibleRegion) {
182 // always called from main thread
183 visibleRegionScreen = visibleRegion;
184}
185
186void LayerBase::setCoveredRegion(const Region& coveredRegion) {
187 // always called from main thread
188 coveredRegionScreen = coveredRegion;
189}
190
191uint32_t LayerBase::doTransaction(uint32_t flags)
192{
193 const Layer::State& front(drawingState());
194 const Layer::State& temp(currentState());
195
Mathias Agopiane1b6f242009-09-29 22:39:22 -0700196 if ((front.requested_w != temp.requested_w) ||
197 (front.requested_h != temp.requested_h)) {
198 // resize the layer, set the physical size to the requested size
199 Layer::State& editTemp(currentState());
200 editTemp.w = temp.requested_w;
201 editTemp.h = temp.requested_h;
202 }
203
Mathias Agopian70cab912009-09-30 12:48:47 -0700204 if ((front.w != temp.w) || (front.h != temp.h)) {
205 // invalidate and recompute the visible regions if needed
206 flags |= Layer::eVisibleRegion;
Mathias Agopian70cab912009-09-30 12:48:47 -0700207 }
208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 if (temp.sequence != front.sequence) {
210 // invalidate and recompute the visible regions if needed
211 flags |= eVisibleRegion;
212 this->contentDirty = true;
Mathias Agopian44cac132009-09-23 18:34:53 -0700213
Mathias Agopian1989af22010-12-02 21:32:29 -0800214 // we may use linear filtering, if the matrix scales us
215 const uint8_t type = temp.transform.getType();
216 mNeedsFiltering = (!temp.transform.preserveRects() ||
217 (type >= Transform::SCALE));
Mathias Agopian44cac132009-09-23 18:34:53 -0700218 }
219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 // Commit the transaction
Mathias Agopian88516172009-09-29 22:32:36 -0700221 commitTransaction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 return flags;
223}
224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225void LayerBase::validateVisibility(const Transform& planeTransform)
226{
227 const Layer::State& s(drawingState());
228 const Transform tr(planeTransform * s.transform);
229 const bool transformed = tr.transformed();
Mathias Agopian3a831d22011-07-07 17:30:31 -0700230 const DisplayHardware& hw(graphicPlane(0).displayHardware());
231 const uint32_t hw_h = hw.getHeight();
232
Mathias Agopian9779b222009-09-07 16:32:45 -0700233 uint32_t w = s.w;
234 uint32_t h = s.h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 tr.transform(mVertices[0], 0, 0);
236 tr.transform(mVertices[1], 0, h);
237 tr.transform(mVertices[2], w, h);
238 tr.transform(mVertices[3], w, 0);
Mathias Agopian3a831d22011-07-07 17:30:31 -0700239 for (size_t i=0 ; i<4 ; i++)
240 mVertices[i][1] = hw_h - mVertices[i][1];
241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 if (UNLIKELY(transformed)) {
243 // NOTE: here we could also punt if we have too many rectangles
244 // in the transparent region
245 if (tr.preserveRects()) {
246 // transform the transparent region
247 transparentRegionScreen = tr.transform(s.transparentRegion);
248 } else {
249 // transformation too complex, can't do the transparent region
250 // optimization.
251 transparentRegionScreen.clear();
252 }
253 } else {
254 transparentRegionScreen = s.transparentRegion;
255 }
256
257 // cache a few things...
258 mOrientation = tr.getOrientation();
Mathias Agopian3f883272011-08-18 18:31:00 -0700259 mTransform = tr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 mTransformedBounds = tr.makeBounds(w, h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261}
262
263void LayerBase::lockPageFlip(bool& recomputeVisibleRegions)
264{
265}
266
267void LayerBase::unlockPageFlip(
268 const Transform& planeTransform, Region& outDirtyRegion)
269{
270 if ((android_atomic_and(~1, &mInvalidate)&1) == 1) {
271 outDirtyRegion.orSelf(visibleRegionScreen);
272 }
273}
274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275void LayerBase::invalidate()
276{
277 if ((android_atomic_or(1, &mInvalidate)&1) == 0) {
278 mFlinger->signalEvent();
279 }
280}
281
282void LayerBase::drawRegion(const Region& reg) const
283{
Mathias Agopian6158b1b2009-05-11 00:03:41 -0700284 Region::const_iterator it = reg.begin();
285 Region::const_iterator const end = reg.end();
286 if (it != end) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 Rect r;
288 const DisplayHardware& hw(graphicPlane(0).displayHardware());
289 const int32_t fbWidth = hw.getWidth();
290 const int32_t fbHeight = hw.getHeight();
291 const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 },
292 { fbWidth, fbHeight }, { 0, fbHeight } };
293 glVertexPointer(2, GL_SHORT, 0, vertices);
Mathias Agopian6158b1b2009-05-11 00:03:41 -0700294 while (it != end) {
295 const Rect& r = *it++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 const GLint sy = fbHeight - (r.top + r.height());
297 glScissor(r.left, sy, r.width(), r.height());
298 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
299 }
300 }
301}
302
Mathias Agopian0fb1a942011-08-02 15:51:37 -0700303void LayerBase::setGeometry(hwc_layer_t* hwcl)
304{
305 hwcl->compositionType = HWC_FRAMEBUFFER;
306 hwcl->hints = 0;
307 hwcl->flags = HWC_SKIP_LAYER;
308 hwcl->transform = 0;
309 hwcl->blending = HWC_BLENDING_NONE;
310
311 // this gives us only the "orientation" component of the transform
312 const State& s(drawingState());
313 const uint32_t finalTransform = s.transform.getOrientation();
314 // we can only handle simple transformation
315 if (finalTransform & Transform::ROT_INVALID) {
316 hwcl->flags = HWC_SKIP_LAYER;
317 } else {
318 hwcl->transform = finalTransform;
319 }
320
321 if (!isOpaque()) {
322 hwcl->blending = mPremultipliedAlpha ?
323 HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE;
324 }
325
326 // scaling is already applied in mTransformedBounds
327 hwcl->displayFrame.left = mTransformedBounds.left;
328 hwcl->displayFrame.top = mTransformedBounds.top;
329 hwcl->displayFrame.right = mTransformedBounds.right;
330 hwcl->displayFrame.bottom = mTransformedBounds.bottom;
331 hwcl->visibleRegionScreen.rects =
332 reinterpret_cast<hwc_rect_t const *>(
333 visibleRegionScreen.getArray(
334 &hwcl->visibleRegionScreen.numRects));
Mathias Agopiance8e0ba2011-08-30 15:02:41 -0700335
336 hwcl->sourceCrop.left = 0;
337 hwcl->sourceCrop.top = 0;
338 hwcl->sourceCrop.right = mTransformedBounds.width();
339 hwcl->sourceCrop.bottom = mTransformedBounds.height();
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700340}
341
342void LayerBase::setPerFrameData(hwc_layer_t* hwcl) {
343 hwcl->compositionType = HWC_FRAMEBUFFER;
344 hwcl->handle = NULL;
345}
346
Mathias Agopian4bacc9d2011-09-08 18:31:55 -0700347void LayerBase::setOverlay(bool inOverlay) {
348 mInOverlay = inOverlay;
349}
350
351bool LayerBase::isOverlay() const {
352 return mInOverlay;
353}
354
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700355void LayerBase::setFiltering(bool filtering)
356{
357 mFiltering = filtering;
358}
359
360bool LayerBase::getFiltering() const
361{
362 return mFiltering;
363}
364
Mathias Agopian8514b922010-08-10 20:42:20 -0700365void LayerBase::draw(const Region& clip) const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 // reset GL state
368 glEnable(GL_SCISSOR_TEST);
369
370 onDraw(clip);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371}
372
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700373void LayerBase::drawForSreenShot()
Mathias Agopian38ed2e32010-09-29 13:02:36 -0700374{
375 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700376 setFiltering(true);
Mathias Agopian38ed2e32010-09-29 13:02:36 -0700377 onDraw( Region(hw.bounds()) );
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700378 setFiltering(false);
Mathias Agopian38ed2e32010-09-29 13:02:36 -0700379}
380
Mathias Agopian0d3c0062010-05-26 22:26:12 -0700381void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
382 GLclampf green, GLclampf blue,
383 GLclampf alpha) const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384{
385 const DisplayHardware& hw(graphicPlane(0).displayHardware());
386 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian0d3c0062010-05-26 22:26:12 -0700387 glColor4f(red,green,blue,alpha);
Mathias Agopianf8b4b442010-06-14 21:20:00 -0700388
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700389#if defined(GL_OES_EGL_image_external)
390 if (GLExtensions::getInstance().haveTextureExternal()) {
391 glDisable(GL_TEXTURE_EXTERNAL_OES);
392 }
393#endif
394 glDisable(GL_TEXTURE_2D);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 glDisable(GL_BLEND);
396 glDisable(GL_DITHER);
Mathias Agopian6158b1b2009-05-11 00:03:41 -0700397
398 Region::const_iterator it = clip.begin();
399 Region::const_iterator const end = clip.end();
Mathias Agopianf2d28b72009-09-24 14:57:26 -0700400 glEnable(GL_SCISSOR_TEST);
Mathias Agopiane5c0a7b2010-04-20 14:51:04 -0700401 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopianf2d28b72009-09-24 14:57:26 -0700402 while (it != end) {
403 const Rect& r = *it++;
404 const GLint sy = fbHeight - (r.top + r.height());
405 glScissor(r.left, sy, r.width(), r.height());
406 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 }
408}
409
Rebecca Schultz Zavinc8546782009-09-01 23:06:45 -0700410void LayerBase::clearWithOpenGL(const Region& clip) const
411{
412 clearWithOpenGL(clip,0,0,0,0);
413}
414
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700415void LayerBase::drawWithOpenGL(const Region& clip) const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416{
417 const DisplayHardware& hw(graphicPlane(0).displayHardware());
418 const uint32_t fbHeight = hw.getHeight();
419 const State& s(drawingState());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420
Mathias Agopiana0612e42010-04-12 15:34:55 -0700421 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 if (UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopiane5c0a7b2010-04-20 14:51:04 -0700423 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopiana0612e42010-04-12 15:34:55 -0700424 if (mPremultipliedAlpha) {
425 glColor4f(alpha, alpha, alpha, alpha);
426 } else {
427 glColor4f(1, 1, 1, alpha);
428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 glEnable(GL_BLEND);
430 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopiana0612e42010-04-12 15:34:55 -0700431 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 } else {
Mathias Agopiane5c0a7b2010-04-20 14:51:04 -0700433 glColor4f(1, 1, 1, 1);
Mathias Agopiana0612e42010-04-12 15:34:55 -0700434 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700435 if (!isOpaque()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 glEnable(GL_BLEND);
437 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
438 } else {
439 glDisable(GL_BLEND);
440 }
441 }
442
Mathias Agopiane96aa3e2010-08-19 17:01:19 -0700443 struct TexCoords {
444 GLfloat u;
445 GLfloat v;
Mathias Agopiane5c0a7b2010-04-20 14:51:04 -0700446 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447
Mathias Agopiane96aa3e2010-08-19 17:01:19 -0700448 TexCoords texCoords[4];
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700449 texCoords[0].u = 0;
450 texCoords[0].v = 1;
451 texCoords[1].u = 0;
452 texCoords[1].v = 0;
453 texCoords[2].u = 1;
454 texCoords[2].v = 0;
455 texCoords[3].u = 1;
456 texCoords[3].v = 1;
Mathias Agopiane5c0a7b2010-04-20 14:51:04 -0700457
Mathias Agopianf8b4b442010-06-14 21:20:00 -0700458 if (needsDithering()) {
459 glEnable(GL_DITHER);
460 } else {
461 glDisable(GL_DITHER);
462 }
463
Mathias Agopiane5c0a7b2010-04-20 14:51:04 -0700464 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
465 glVertexPointer(2, GL_FLOAT, 0, mVertices);
466 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
467
Mathias Agopiane96aa3e2010-08-19 17:01:19 -0700468 Region::const_iterator it = clip.begin();
469 Region::const_iterator const end = clip.end();
Mathias Agopiane5c0a7b2010-04-20 14:51:04 -0700470 while (it != end) {
471 const Rect& r = *it++;
472 const GLint sy = fbHeight - (r.top + r.height());
473 glScissor(r.left, sy, r.width(), r.height());
474 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
475 }
476 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477}
478
Mathias Agopian9bce8732010-04-20 17:55:49 -0700479void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
480{
481 const Layer::State& s(drawingState());
482 snprintf(buffer, SIZE,
483 "+ %s %p\n"
484 " "
Mathias Agopian34cb9f2a2011-08-30 18:51:54 -0700485 "z=%9d, pos=(%g,%g), size=(%4d,%4d), "
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700486 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian9bce8732010-04-20 17:55:49 -0700487 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian34cb9f2a2011-08-30 18:51:54 -0700488 getTypeId(), this, s.z, s.transform.tx(), s.transform.ty(), s.w, s.h,
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700489 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian9bce8732010-04-20 17:55:49 -0700490 s.alpha, s.flags,
491 s.transform[0][0], s.transform[0][1],
492 s.transform[1][0], s.transform[1][1]);
493 result.append(buffer);
494}
Mathias Agopian9042b452009-10-26 20:12:37 -0700495
Mathias Agopian06a61e22011-01-19 16:15:53 -0800496void LayerBase::shortDump(String8& result, char* scratch, size_t size) const
497{
498 LayerBase::dump(result, scratch, size);
499}
500
501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502// ---------------------------------------------------------------------------
503
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700504int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopianc6603952009-06-23 20:06:46 -0700505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian593c05c2010-06-02 23:28:45 -0700507 const sp<Client>& client)
Mathias Agopian1b0114f2011-02-15 19:01:06 -0800508 : LayerBase(flinger, display),
509 mHasSurface(false),
510 mClientRef(client),
Mathias Agopian85b8d122010-03-08 19:29:09 -0800511 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512{
Mathias Agopian1473f462009-04-10 14:24:30 -0700513}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515LayerBaseClient::~LayerBaseClient()
516{
Mathias Agopian7623da42010-06-01 15:12:58 -0700517 sp<Client> c(mClientRef.promote());
Mathias Agopian593c05c2010-06-02 23:28:45 -0700518 if (c != 0) {
Mathias Agopian7623da42010-06-01 15:12:58 -0700519 c->detachLayer(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 }
521}
522
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700523sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524{
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700525 class BSurface : public BnSurface, public LayerCleaner {
526 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
527 public:
528 BSurface(const sp<SurfaceFlinger>& flinger,
529 const sp<LayerBaseClient>& layer)
530 : LayerCleaner(flinger, layer) { }
531 };
532 sp<ISurface> sur(new BSurface(mFlinger, this));
533 return sur;
534}
535
536sp<ISurface> LayerBaseClient::getSurface()
537{
538 sp<ISurface> s;
Mathias Agopian1473f462009-04-10 14:24:30 -0700539 Mutex::Autolock _l(mLock);
Mathias Agopian1b0114f2011-02-15 19:01:06 -0800540
541 LOG_ALWAYS_FATAL_IF(mHasSurface,
542 "LayerBaseClient::getSurface() has already been called");
543
544 mHasSurface = true;
545 s = createSurface();
546 mClientSurfaceBinder = s->asBinder();
Mathias Agopian1473f462009-04-10 14:24:30 -0700547 return s;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548}
549
Mathias Agopiand35c6662011-01-25 20:17:45 -0800550wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
551 return mClientSurfaceBinder;
552}
553
Jamie Gennis9b8fc652011-08-17 18:19:00 -0700554wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
555 return 0;
556}
557
Mathias Agopian9bce8732010-04-20 17:55:49 -0700558void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
559{
560 LayerBase::dump(result, buffer, SIZE);
561
Mathias Agopian7623da42010-06-01 15:12:58 -0700562 sp<Client> client(mClientRef.promote());
Mathias Agopian9bce8732010-04-20 17:55:49 -0700563 snprintf(buffer, SIZE,
564 " name=%s\n"
Mathias Agopian593c05c2010-06-02 23:28:45 -0700565 " client=%p, identity=%u\n",
Mathias Agopian9bce8732010-04-20 17:55:49 -0700566 getName().string(),
Mathias Agopian593c05c2010-06-02 23:28:45 -0700567 client.get(), getIdentity());
Mathias Agopian9bce8732010-04-20 17:55:49 -0700568
569 result.append(buffer);
570}
571
Mathias Agopian06a61e22011-01-19 16:15:53 -0800572
573void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
574{
575 LayerBaseClient::dump(result, scratch, size);
576}
577
Mathias Agopian1473f462009-04-10 14:24:30 -0700578// ---------------------------------------------------------------------------
579
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700580LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
581 const sp<LayerBaseClient>& layer)
582 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian1473f462009-04-10 14:24:30 -0700583}
584
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700585LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700586 // destroy client resources
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700587 mFlinger->destroySurface(mLayer);
Mathias Agopian59751db2010-05-07 15:58:44 -0700588}
589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590// ---------------------------------------------------------------------------
591
592}; // namespace android