blob: 44aafdf8c871e2604af893fea995cb6314eb396f [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 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 Agopian7e4a5872009-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 Projectedbf3b62009-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 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 Agopian7e4a5872009-09-29 22:39:22 -0700138 if (mCurrentState.requested_w == w && mCurrentState.requested_h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800139 return false;
Mathias Agopian7e4a5872009-09-29 22:39:22 -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}
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 Agopian7e4a5872009-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 Agopian6656dbc2009-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 Agopian6656dbc2009-09-30 12:48:47 -0700207 }
208
The Android Open Source Projectedbf3b62009-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 Agopiana2fe0a22009-09-23 18:34:53 -0700213
Mathias Agopian733189d2010-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 Agopiana2fe0a22009-09-23 18:34:53 -0700218 }
219
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800220 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700221 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800222 return flags;
223}
224
The Android Open Source Projectedbf3b62009-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 Agopianffcf4652011-07-07 17:30:31 -0700230 const DisplayHardware& hw(graphicPlane(0).displayHardware());
231 const uint32_t hw_h = hw.getHeight();
232
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700233 uint32_t w = s.w;
234 uint32_t h = s.h;
The Android Open Source Projectedbf3b62009-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 Agopianffcf4652011-07-07 17:30:31 -0700239 for (size_t i=0 ; i<4 ; i++)
240 mVertices[i][1] = hw_h - mVertices[i][1];
241
Glenn Kasten99ed2242011-12-15 09:51:17 -0800242 if (CC_UNLIKELY(transformed)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800243 // 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();
Jamie Gennis8d91b422011-09-23 15:54:34 -0700259 mPlaneOrientation = planeTransform.getOrientation();
Mathias Agopiand992db32011-08-18 18:31:00 -0700260 mTransform = tr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800261 mTransformedBounds = tr.makeBounds(w, h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800262}
263
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800264void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800265}
266
267void LayerBase::unlockPageFlip(
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800268 const Transform& planeTransform, Region& outDirtyRegion) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800269}
270
271void LayerBase::drawRegion(const Region& reg) const
272{
Mathias Agopian20f68782009-05-11 00:03:41 -0700273 Region::const_iterator it = reg.begin();
274 Region::const_iterator const end = reg.end();
275 if (it != end) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800276 Rect r;
277 const DisplayHardware& hw(graphicPlane(0).displayHardware());
278 const int32_t fbWidth = hw.getWidth();
279 const int32_t fbHeight = hw.getHeight();
280 const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 },
281 { fbWidth, fbHeight }, { 0, fbHeight } };
282 glVertexPointer(2, GL_SHORT, 0, vertices);
Mathias Agopian20f68782009-05-11 00:03:41 -0700283 while (it != end) {
284 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800285 const GLint sy = fbHeight - (r.top + r.height());
286 glScissor(r.left, sy, r.width(), r.height());
287 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
288 }
289 }
290}
291
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700292void LayerBase::setGeometry(hwc_layer_t* hwcl)
293{
294 hwcl->compositionType = HWC_FRAMEBUFFER;
295 hwcl->hints = 0;
296 hwcl->flags = HWC_SKIP_LAYER;
297 hwcl->transform = 0;
298 hwcl->blending = HWC_BLENDING_NONE;
299
300 // this gives us only the "orientation" component of the transform
301 const State& s(drawingState());
302 const uint32_t finalTransform = s.transform.getOrientation();
303 // we can only handle simple transformation
304 if (finalTransform & Transform::ROT_INVALID) {
305 hwcl->flags = HWC_SKIP_LAYER;
306 } else {
307 hwcl->transform = finalTransform;
308 }
309
310 if (!isOpaque()) {
311 hwcl->blending = mPremultipliedAlpha ?
312 HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE;
313 }
314
315 // scaling is already applied in mTransformedBounds
316 hwcl->displayFrame.left = mTransformedBounds.left;
317 hwcl->displayFrame.top = mTransformedBounds.top;
318 hwcl->displayFrame.right = mTransformedBounds.right;
319 hwcl->displayFrame.bottom = mTransformedBounds.bottom;
320 hwcl->visibleRegionScreen.rects =
321 reinterpret_cast<hwc_rect_t const *>(
322 visibleRegionScreen.getArray(
323 &hwcl->visibleRegionScreen.numRects));
Mathias Agopianc7f33812011-08-30 15:02:41 -0700324
325 hwcl->sourceCrop.left = 0;
326 hwcl->sourceCrop.top = 0;
327 hwcl->sourceCrop.right = mTransformedBounds.width();
328 hwcl->sourceCrop.bottom = mTransformedBounds.height();
Mathias Agopiana350ff92010-08-10 17:14:02 -0700329}
330
331void LayerBase::setPerFrameData(hwc_layer_t* hwcl) {
332 hwcl->compositionType = HWC_FRAMEBUFFER;
333 hwcl->handle = NULL;
334}
335
Mathias Agopianf384cc32011-09-08 18:31:55 -0700336void LayerBase::setOverlay(bool inOverlay) {
337 mInOverlay = inOverlay;
338}
339
340bool LayerBase::isOverlay() const {
341 return mInOverlay;
342}
343
Mathias Agopiana67932f2011-04-20 14:20:59 -0700344void LayerBase::setFiltering(bool filtering)
345{
346 mFiltering = filtering;
347}
348
349bool LayerBase::getFiltering() const
350{
351 return mFiltering;
352}
353
Mathias Agopianbc7e31a2010-08-10 20:42:20 -0700354void LayerBase::draw(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800355{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800356 // reset GL state
357 glEnable(GL_SCISSOR_TEST);
358
359 onDraw(clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800360}
361
Mathias Agopiana67932f2011-04-20 14:20:59 -0700362void LayerBase::drawForSreenShot()
Mathias Agopian74c40c02010-09-29 13:02:36 -0700363{
364 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopiana67932f2011-04-20 14:20:59 -0700365 setFiltering(true);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700366 onDraw( Region(hw.bounds()) );
Mathias Agopiana67932f2011-04-20 14:20:59 -0700367 setFiltering(false);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700368}
369
Mathias Agopian010fccb2010-05-26 22:26:12 -0700370void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
371 GLclampf green, GLclampf blue,
372 GLclampf alpha) 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();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700376 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700377
Mathias Agopianc492e672011-10-18 14:49:27 -0700378 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700379 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800380 glDisable(GL_BLEND);
Mathias Agopian20f68782009-05-11 00:03:41 -0700381
382 Region::const_iterator it = clip.begin();
383 Region::const_iterator const end = clip.end();
Mathias Agopian95a666b2009-09-24 14:57:26 -0700384 glEnable(GL_SCISSOR_TEST);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700385 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopian95a666b2009-09-24 14:57:26 -0700386 while (it != end) {
387 const Rect& r = *it++;
388 const GLint sy = fbHeight - (r.top + r.height());
389 glScissor(r.left, sy, r.width(), r.height());
390 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800391 }
392}
393
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700394void LayerBase::clearWithOpenGL(const Region& clip) const
395{
396 clearWithOpenGL(clip,0,0,0,0);
397}
398
Mathias Agopiana67932f2011-04-20 14:20:59 -0700399void LayerBase::drawWithOpenGL(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800400{
401 const DisplayHardware& hw(graphicPlane(0).displayHardware());
402 const uint32_t fbHeight = hw.getHeight();
403 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800404
Mathias Agopian49753262010-04-12 15:34:55 -0700405 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800406 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700407 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700408 if (mPremultipliedAlpha) {
409 glColor4f(alpha, alpha, alpha, alpha);
410 } else {
411 glColor4f(1, 1, 1, alpha);
412 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800413 glEnable(GL_BLEND);
414 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700415 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800416 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700417 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700418 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700419 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800420 glEnable(GL_BLEND);
421 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
422 } else {
423 glDisable(GL_BLEND);
424 }
425 }
426
Mathias Agopianb661d662010-08-19 17:01:19 -0700427 struct TexCoords {
428 GLfloat u;
429 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700430 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800431
Mathias Agopianb661d662010-08-19 17:01:19 -0700432 TexCoords texCoords[4];
Mathias Agopiana67932f2011-04-20 14:20:59 -0700433 texCoords[0].u = 0;
434 texCoords[0].v = 1;
435 texCoords[1].u = 0;
436 texCoords[1].v = 0;
437 texCoords[2].u = 1;
438 texCoords[2].v = 0;
439 texCoords[3].u = 1;
440 texCoords[3].v = 1;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700441
442 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
443 glVertexPointer(2, GL_FLOAT, 0, mVertices);
444 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
445
Mathias Agopianb661d662010-08-19 17:01:19 -0700446 Region::const_iterator it = clip.begin();
447 Region::const_iterator const end = clip.end();
Mathias Agopian78fd5012010-04-20 14:51:04 -0700448 while (it != end) {
449 const Rect& r = *it++;
450 const GLint sy = fbHeight - (r.top + r.height());
451 glScissor(r.left, sy, r.width(), r.height());
452 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
453 }
454 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700455 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800456}
457
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700458void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
459{
460 const Layer::State& s(drawingState());
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800461 s.transparentRegion.dump(result, "transparentRegion");
462 transparentRegionScreen.dump(result, "transparentRegionScreen");
463 visibleRegionScreen.dump(result, "visibleRegionScreen");
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700464 snprintf(buffer, SIZE,
Mathias Agopian22da60c2011-09-09 00:49:11 -0700465 "+ %s %p (%s)\n"
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700466 " "
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700467 "z=%9d, pos=(%g,%g), size=(%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700468 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700469 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian22da60c2011-09-09 00:49:11 -0700470 getTypeId(), this, getName().string(),
471 s.z, s.transform.tx(), s.transform.ty(), s.w, s.h,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700472 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700473 s.alpha, s.flags,
474 s.transform[0][0], s.transform[0][1],
475 s.transform[1][0], s.transform[1][1]);
476 result.append(buffer);
477}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700478
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800479void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800480 LayerBase::dump(result, scratch, size);
481}
482
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800483void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
484}
485
486void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800487}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800488
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800489// ---------------------------------------------------------------------------
490
Mathias Agopian631f3582010-05-25 17:51:34 -0700491int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700492
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800493LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700494 const sp<Client>& client)
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800495 : LayerBase(flinger, display),
496 mHasSurface(false),
497 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800498 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800499{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700500}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800501
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800502LayerBaseClient::~LayerBaseClient()
503{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700504 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700505 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700506 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800507 }
508}
509
Mathias Agopiana67932f2011-04-20 14:20:59 -0700510sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800511{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700512 class BSurface : public BnSurface, public LayerCleaner {
513 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
514 public:
515 BSurface(const sp<SurfaceFlinger>& flinger,
516 const sp<LayerBaseClient>& layer)
517 : LayerCleaner(flinger, layer) { }
518 };
519 sp<ISurface> sur(new BSurface(mFlinger, this));
520 return sur;
521}
522
523sp<ISurface> LayerBaseClient::getSurface()
524{
525 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700526 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800527
528 LOG_ALWAYS_FATAL_IF(mHasSurface,
529 "LayerBaseClient::getSurface() has already been called");
530
531 mHasSurface = true;
532 s = createSurface();
533 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700534 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800535}
536
Mathias Agopian0d156122011-01-25 20:17:45 -0800537wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
538 return mClientSurfaceBinder;
539}
540
Jamie Gennis582270d2011-08-17 18:19:00 -0700541wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
542 return 0;
543}
544
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700545void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
546{
547 LayerBase::dump(result, buffer, SIZE);
548
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700549 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700550 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700551 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700552 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700553
554 result.append(buffer);
555}
556
Mathias Agopian48b888a2011-01-19 16:15:53 -0800557
558void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
559{
560 LayerBaseClient::dump(result, scratch, size);
561}
562
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700563// ---------------------------------------------------------------------------
564
Mathias Agopiana67932f2011-04-20 14:20:59 -0700565LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
566 const sp<LayerBaseClient>& layer)
567 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700568}
569
Mathias Agopiana67932f2011-04-20 14:20:59 -0700570LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700571 // destroy client resources
Mathias Agopiana67932f2011-04-20 14:20:59 -0700572 mFlinger->destroySurface(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700573}
574
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800575// ---------------------------------------------------------------------------
576
577}; // namespace android