blob: 416fc93e1798ed83acdd7d8fa0d4fdb42f0812de [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 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 Agopiana67932f2011-04-20 14:20:59 -0700336void LayerBase::setFiltering(bool filtering)
337{
338 mFiltering = filtering;
339}
340
341bool LayerBase::getFiltering() const
342{
343 return mFiltering;
344}
345
Mathias Agopianbc7e31a2010-08-10 20:42:20 -0700346void LayerBase::draw(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800347{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800348 // reset GL state
349 glEnable(GL_SCISSOR_TEST);
350
351 onDraw(clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800352}
353
Mathias Agopiana67932f2011-04-20 14:20:59 -0700354void LayerBase::drawForSreenShot()
Mathias Agopian74c40c02010-09-29 13:02:36 -0700355{
356 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopiana67932f2011-04-20 14:20:59 -0700357 setFiltering(true);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700358 onDraw( Region(hw.bounds()) );
Mathias Agopiana67932f2011-04-20 14:20:59 -0700359 setFiltering(false);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700360}
361
Mathias Agopian010fccb2010-05-26 22:26:12 -0700362void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
363 GLclampf green, GLclampf blue,
364 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800365{
366 const DisplayHardware& hw(graphicPlane(0).displayHardware());
367 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700368 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700369
Mathias Agopianc492e672011-10-18 14:49:27 -0700370 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700371 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800372 glDisable(GL_BLEND);
Mathias Agopian20f68782009-05-11 00:03:41 -0700373
374 Region::const_iterator it = clip.begin();
375 Region::const_iterator const end = clip.end();
Mathias Agopian95a666b2009-09-24 14:57:26 -0700376 glEnable(GL_SCISSOR_TEST);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700377 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopian95a666b2009-09-24 14:57:26 -0700378 while (it != end) {
379 const Rect& r = *it++;
380 const GLint sy = fbHeight - (r.top + r.height());
381 glScissor(r.left, sy, r.width(), r.height());
382 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800383 }
384}
385
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700386void LayerBase::clearWithOpenGL(const Region& clip) const
387{
388 clearWithOpenGL(clip,0,0,0,0);
389}
390
Mathias Agopiana67932f2011-04-20 14:20:59 -0700391void LayerBase::drawWithOpenGL(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800392{
393 const DisplayHardware& hw(graphicPlane(0).displayHardware());
394 const uint32_t fbHeight = hw.getHeight();
395 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800396
Mathias Agopian49753262010-04-12 15:34:55 -0700397 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800398 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700399 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700400 if (mPremultipliedAlpha) {
401 glColor4f(alpha, alpha, alpha, alpha);
402 } else {
403 glColor4f(1, 1, 1, alpha);
404 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800405 glEnable(GL_BLEND);
406 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700407 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800408 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700409 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700410 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700411 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800412 glEnable(GL_BLEND);
413 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
414 } else {
415 glDisable(GL_BLEND);
416 }
417 }
418
Mathias Agopianb661d662010-08-19 17:01:19 -0700419 struct TexCoords {
420 GLfloat u;
421 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700422 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800423
Mathias Agopianb661d662010-08-19 17:01:19 -0700424 TexCoords texCoords[4];
Mathias Agopiana67932f2011-04-20 14:20:59 -0700425 texCoords[0].u = 0;
426 texCoords[0].v = 1;
427 texCoords[1].u = 0;
428 texCoords[1].v = 0;
429 texCoords[2].u = 1;
430 texCoords[2].v = 0;
431 texCoords[3].u = 1;
432 texCoords[3].v = 1;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700433
434 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
435 glVertexPointer(2, GL_FLOAT, 0, mVertices);
436 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
437
Mathias Agopianb661d662010-08-19 17:01:19 -0700438 Region::const_iterator it = clip.begin();
439 Region::const_iterator const end = clip.end();
Mathias Agopian78fd5012010-04-20 14:51:04 -0700440 while (it != end) {
441 const Rect& r = *it++;
442 const GLint sy = fbHeight - (r.top + r.height());
443 glScissor(r.left, sy, r.width(), r.height());
444 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
445 }
446 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700447 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800448}
449
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700450void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
451{
452 const Layer::State& s(drawingState());
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800453
454 snprintf(buffer, SIZE,
455 "+ %s %p (%s)\n",
456 getTypeId(), this, getName().string());
457 result.append(buffer);
458
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800459 s.transparentRegion.dump(result, "transparentRegion");
460 transparentRegionScreen.dump(result, "transparentRegionScreen");
461 visibleRegionScreen.dump(result, "visibleRegionScreen");
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800462
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700463 snprintf(buffer, SIZE,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700464 " "
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700465 "z=%9d, pos=(%g,%g), size=(%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700466 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700467 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian22da60c2011-09-09 00:49:11 -0700468 s.z, s.transform.tx(), s.transform.ty(), s.w, s.h,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700469 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700470 s.alpha, s.flags,
471 s.transform[0][0], s.transform[0][1],
472 s.transform[1][0], s.transform[1][1]);
473 result.append(buffer);
474}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700475
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800476void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800477 LayerBase::dump(result, scratch, size);
478}
479
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800480void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
481}
482
483void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800484}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800485
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800486// ---------------------------------------------------------------------------
487
Mathias Agopian631f3582010-05-25 17:51:34 -0700488int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700489
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800490LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700491 const sp<Client>& client)
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800492 : LayerBase(flinger, display),
493 mHasSurface(false),
494 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800495 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800496{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700497}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800498
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800499LayerBaseClient::~LayerBaseClient()
500{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700501 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700502 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700503 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800504 }
505}
506
Mathias Agopiana67932f2011-04-20 14:20:59 -0700507sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800508{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700509 class BSurface : public BnSurface, public LayerCleaner {
510 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
511 public:
512 BSurface(const sp<SurfaceFlinger>& flinger,
513 const sp<LayerBaseClient>& layer)
514 : LayerCleaner(flinger, layer) { }
515 };
516 sp<ISurface> sur(new BSurface(mFlinger, this));
517 return sur;
518}
519
520sp<ISurface> LayerBaseClient::getSurface()
521{
522 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700523 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800524
525 LOG_ALWAYS_FATAL_IF(mHasSurface,
526 "LayerBaseClient::getSurface() has already been called");
527
528 mHasSurface = true;
529 s = createSurface();
530 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700531 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800532}
533
Mathias Agopian0d156122011-01-25 20:17:45 -0800534wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
535 return mClientSurfaceBinder;
536}
537
Jamie Gennis582270d2011-08-17 18:19:00 -0700538wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
539 return 0;
540}
541
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700542void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
543{
544 LayerBase::dump(result, buffer, SIZE);
545
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700546 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700547 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700548 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700549 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700550
551 result.append(buffer);
552}
553
Mathias Agopian48b888a2011-01-19 16:15:53 -0800554
555void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
556{
557 LayerBaseClient::dump(result, scratch, size);
558}
559
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700560// ---------------------------------------------------------------------------
561
Mathias Agopiana67932f2011-04-20 14:20:59 -0700562LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
563 const sp<LayerBaseClient>& layer)
564 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700565}
566
Mathias Agopiana67932f2011-04-20 14:20:59 -0700567LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700568 // destroy client resources
Mathias Agopiana67932f2011-04-20 14:20:59 -0700569 mFlinger->destroySurface(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700570}
571
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800572// ---------------------------------------------------------------------------
573
574}; // namespace android