blob: 7c6a28afb7a9e6c8d545d59ed0735f568d82c7e3 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080017#include <stdlib.h>
18#include <stdint.h>
19#include <sys/types.h>
20
21#include <utils/Errors.h>
22#include <utils/Log.h>
Mathias Agopian310f8da2009-05-22 01:27:01 -070023#include <binder/IPCThreadState.h>
24#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025
26#include <GLES/gl.h>
27#include <GLES/glext.h>
28
29#include <hardware/hardware.h>
30
31#include "clz.h"
32#include "LayerBase.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033#include "SurfaceFlinger.h"
34#include "DisplayHardware/DisplayHardware.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036namespace android {
37
38// ---------------------------------------------------------------------------
39
Mathias Agopianf6679fc2010-08-10 18:09:09 -070040int32_t LayerBase::sSequence = 1;
41
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display)
43 : dpy(display), contentDirty(false),
Mathias Agopianf6679fc2010-08-10 18:09:09 -070044 sequence(uint32_t(android_atomic_inc(&sSequence))),
Mathias Agopiana67932f2011-04-20 14:20:59 -070045 mFlinger(flinger), mFiltering(false),
Mathias Agopiana2f4e562012-04-15 23:34:59 -070046 mNeedsFiltering(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047 mOrientation(0),
Jamie Gennis8d91b422011-09-23 15:54:34 -070048 mPlaneOrientation(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049 mTransactionFlags(0),
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080050 mPremultipliedAlpha(true), mName("unnamed"), mDebug(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051{
52 const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware());
53 mFlags = hw.getFlags();
54}
55
56LayerBase::~LayerBase()
57{
58}
59
Mathias Agopiand1296592010-03-09 19:17:47 -080060void LayerBase::setName(const String8& name) {
61 mName = name;
62}
63
64String8 LayerBase::getName() const {
65 return mName;
66}
67
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068const GraphicPlane& LayerBase::graphicPlane(int dpy) const
69{
70 return mFlinger->graphicPlane(dpy);
71}
72
73GraphicPlane& LayerBase::graphicPlane(int dpy)
74{
75 return mFlinger->graphicPlane(dpy);
76}
77
78void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags)
79{
80 uint32_t layerFlags = 0;
81 if (flags & ISurfaceComposer::eHidden)
82 layerFlags = ISurfaceComposer::eLayerHidden;
83
84 if (flags & ISurfaceComposer::eNonPremultiplied)
85 mPremultipliedAlpha = false;
86
Mathias Agopian93ffb862012-05-16 17:07:49 -070087 mCurrentState.active.w = w;
88 mCurrentState.active.h = h;
89 mCurrentState.active.crop.makeInvalid();
90 mCurrentState.z = 0;
91 mCurrentState.alpha = 0xFF;
92 mCurrentState.flags = layerFlags;
93 mCurrentState.sequence = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094 mCurrentState.transform.set(0, 0);
Mathias Agopian93ffb862012-05-16 17:07:49 -070095 mCurrentState.requested = mCurrentState.active;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096
97 // drawing state & current state are identical
98 mDrawingState = mCurrentState;
99}
100
Mathias Agopianba6be542009-09-29 22:32:36 -0700101void LayerBase::commitTransaction() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 mDrawingState = mCurrentState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103}
104void LayerBase::forceVisibilityTransaction() {
105 // this can be called without SurfaceFlinger.mStateLock, but if we
106 // can atomically increment the sequence number, it doesn't matter.
107 android_atomic_inc(&mCurrentState.sequence);
108 requestTransaction();
109}
110bool LayerBase::requestTransaction() {
111 int32_t old = setTransactionFlags(eTransactionNeeded);
112 return ((old & eTransactionNeeded) == 0);
113}
114uint32_t LayerBase::getTransactionFlags(uint32_t flags) {
115 return android_atomic_and(~flags, &mTransactionFlags) & flags;
116}
117uint32_t LayerBase::setTransactionFlags(uint32_t flags) {
118 return android_atomic_or(flags, &mTransactionFlags);
119}
120
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700121bool LayerBase::setPosition(float x, float y) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800122 if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
123 return false;
124 mCurrentState.sequence++;
125 mCurrentState.transform.set(x, y);
126 requestTransaction();
127 return true;
128}
129bool LayerBase::setLayer(uint32_t z) {
130 if (mCurrentState.z == z)
131 return false;
132 mCurrentState.sequence++;
133 mCurrentState.z = z;
134 requestTransaction();
135 return true;
136}
137bool LayerBase::setSize(uint32_t w, uint32_t h) {
Mathias Agopian93ffb862012-05-16 17:07:49 -0700138 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800139 return false;
Mathias Agopian93ffb862012-05-16 17:07:49 -0700140 mCurrentState.requested.w = w;
141 mCurrentState.requested.h = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 requestTransaction();
143 return true;
144}
145bool LayerBase::setAlpha(uint8_t alpha) {
146 if (mCurrentState.alpha == alpha)
147 return false;
148 mCurrentState.sequence++;
149 mCurrentState.alpha = alpha;
150 requestTransaction();
151 return true;
152}
153bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800154 mCurrentState.sequence++;
155 mCurrentState.transform.set(
156 matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
157 requestTransaction();
158 return true;
159}
160bool LayerBase::setTransparentRegionHint(const Region& transparent) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800161 mCurrentState.sequence++;
162 mCurrentState.transparentRegion = transparent;
163 requestTransaction();
164 return true;
165}
166bool LayerBase::setFlags(uint8_t flags, uint8_t mask) {
167 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
168 if (mCurrentState.flags == newFlags)
169 return false;
170 mCurrentState.sequence++;
171 mCurrentState.flags = newFlags;
172 requestTransaction();
173 return true;
174}
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700175bool LayerBase::setCrop(const Rect& crop) {
Mathias Agopianb30c4152012-05-16 18:21:32 -0700176 if (mCurrentState.requested.crop == crop)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700177 return false;
178 mCurrentState.sequence++;
Mathias Agopianb30c4152012-05-16 18:21:32 -0700179 mCurrentState.requested.crop = crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700180 requestTransaction();
181 return true;
182}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800183
184Rect LayerBase::visibleBounds() const
185{
186 return mTransformedBounds;
187}
188
189void LayerBase::setVisibleRegion(const Region& visibleRegion) {
190 // always called from main thread
191 visibleRegionScreen = visibleRegion;
192}
193
194void LayerBase::setCoveredRegion(const Region& coveredRegion) {
195 // always called from main thread
196 coveredRegionScreen = coveredRegion;
197}
198
199uint32_t LayerBase::doTransaction(uint32_t flags)
200{
201 const Layer::State& front(drawingState());
202 const Layer::State& temp(currentState());
203
Mathias Agopianb30c4152012-05-16 18:21:32 -0700204 if (front.requested != temp.requested) {
205 // geometry of the layer has changed, set the active geometry
206 // to the requested geometry.
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700207 Layer::State& editTemp(currentState());
Mathias Agopianb30c4152012-05-16 18:21:32 -0700208 editTemp.active = temp.requested;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700209 }
Mathias Agopianb30c4152012-05-16 18:21:32 -0700210 if (front.active != temp.active) {
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700211 // invalidate and recompute the visible regions if needed
212 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700213 }
214
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800215 if (temp.sequence != front.sequence) {
216 // invalidate and recompute the visible regions if needed
217 flags |= eVisibleRegion;
218 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700219
Mathias Agopian733189d2010-12-02 21:32:29 -0800220 // we may use linear filtering, if the matrix scales us
221 const uint8_t type = temp.transform.getType();
222 mNeedsFiltering = (!temp.transform.preserveRects() ||
223 (type >= Transform::SCALE));
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700224 }
225
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800226 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700227 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800228 return flags;
229}
230
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800231void LayerBase::validateVisibility(const Transform& planeTransform)
232{
233 const Layer::State& s(drawingState());
234 const Transform tr(planeTransform * s.transform);
235 const bool transformed = tr.transformed();
Mathias Agopianffcf4652011-07-07 17:30:31 -0700236 const DisplayHardware& hw(graphicPlane(0).displayHardware());
237 const uint32_t hw_h = hw.getHeight();
Mathias Agopian93ffb862012-05-16 17:07:49 -0700238 const Rect& crop(s.active.crop);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700239
Mathias Agopian93ffb862012-05-16 17:07:49 -0700240 Rect win(s.active.w, s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700241 if (!crop.isEmpty()) {
242 win.intersect(crop, &win);
243 }
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700244
245 mNumVertices = 4;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700246 tr.transform(mVertices[0], win.left, win.top);
247 tr.transform(mVertices[1], win.left, win.bottom);
248 tr.transform(mVertices[2], win.right, win.bottom);
249 tr.transform(mVertices[3], win.right, win.top);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700250 for (size_t i=0 ; i<4 ; i++)
251 mVertices[i][1] = hw_h - mVertices[i][1];
252
Glenn Kasten99ed2242011-12-15 09:51:17 -0800253 if (CC_UNLIKELY(transformed)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800254 // NOTE: here we could also punt if we have too many rectangles
255 // in the transparent region
256 if (tr.preserveRects()) {
257 // transform the transparent region
258 transparentRegionScreen = tr.transform(s.transparentRegion);
259 } else {
260 // transformation too complex, can't do the transparent region
261 // optimization.
262 transparentRegionScreen.clear();
263 }
264 } else {
265 transparentRegionScreen = s.transparentRegion;
266 }
267
268 // cache a few things...
269 mOrientation = tr.getOrientation();
Jamie Gennis8d91b422011-09-23 15:54:34 -0700270 mPlaneOrientation = planeTransform.getOrientation();
Mathias Agopiand992db32011-08-18 18:31:00 -0700271 mTransform = tr;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700272 mTransformedBounds = tr.transform(win);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800273}
274
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800275void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800276}
277
278void LayerBase::unlockPageFlip(
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800279 const Transform& planeTransform, Region& outDirtyRegion) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800280}
281
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700282void LayerBase::setGeometry(hwc_layer_t* hwcl)
283{
284 hwcl->compositionType = HWC_FRAMEBUFFER;
285 hwcl->hints = 0;
286 hwcl->flags = HWC_SKIP_LAYER;
287 hwcl->transform = 0;
288 hwcl->blending = HWC_BLENDING_NONE;
289
290 // this gives us only the "orientation" component of the transform
291 const State& s(drawingState());
292 const uint32_t finalTransform = s.transform.getOrientation();
293 // we can only handle simple transformation
294 if (finalTransform & Transform::ROT_INVALID) {
295 hwcl->flags = HWC_SKIP_LAYER;
296 } else {
297 hwcl->transform = finalTransform;
298 }
299
300 if (!isOpaque()) {
301 hwcl->blending = mPremultipliedAlpha ?
302 HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE;
303 }
304
305 // scaling is already applied in mTransformedBounds
306 hwcl->displayFrame.left = mTransformedBounds.left;
307 hwcl->displayFrame.top = mTransformedBounds.top;
308 hwcl->displayFrame.right = mTransformedBounds.right;
309 hwcl->displayFrame.bottom = mTransformedBounds.bottom;
310 hwcl->visibleRegionScreen.rects =
311 reinterpret_cast<hwc_rect_t const *>(
312 visibleRegionScreen.getArray(
313 &hwcl->visibleRegionScreen.numRects));
Mathias Agopianc7f33812011-08-30 15:02:41 -0700314
315 hwcl->sourceCrop.left = 0;
316 hwcl->sourceCrop.top = 0;
317 hwcl->sourceCrop.right = mTransformedBounds.width();
318 hwcl->sourceCrop.bottom = mTransformedBounds.height();
Mathias Agopiana350ff92010-08-10 17:14:02 -0700319}
320
321void LayerBase::setPerFrameData(hwc_layer_t* hwcl) {
322 hwcl->compositionType = HWC_FRAMEBUFFER;
323 hwcl->handle = NULL;
324}
325
Mathias Agopiana67932f2011-04-20 14:20:59 -0700326void LayerBase::setFiltering(bool filtering)
327{
328 mFiltering = filtering;
329}
330
331bool LayerBase::getFiltering() const
332{
333 return mFiltering;
334}
335
Mathias Agopianbc7e31a2010-08-10 20:42:20 -0700336void LayerBase::draw(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800337{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800338 onDraw(clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339}
340
Mathias Agopiana67932f2011-04-20 14:20:59 -0700341void LayerBase::drawForSreenShot()
Mathias Agopian74c40c02010-09-29 13:02:36 -0700342{
343 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopiana67932f2011-04-20 14:20:59 -0700344 setFiltering(true);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700345 onDraw( Region(hw.bounds()) );
Mathias Agopiana67932f2011-04-20 14:20:59 -0700346 setFiltering(false);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700347}
348
Mathias Agopian010fccb2010-05-26 22:26:12 -0700349void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
350 GLclampf green, GLclampf blue,
351 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800352{
353 const DisplayHardware& hw(graphicPlane(0).displayHardware());
354 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700355 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700356
Mathias Agopianc492e672011-10-18 14:49:27 -0700357 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700358 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800359 glDisable(GL_BLEND);
Mathias Agopian20f68782009-05-11 00:03:41 -0700360
Mathias Agopian78fd5012010-04-20 14:51:04 -0700361 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700362 glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800363}
364
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700365void LayerBase::clearWithOpenGL(const Region& clip) const
366{
367 clearWithOpenGL(clip,0,0,0,0);
368}
369
Mathias Agopiana67932f2011-04-20 14:20:59 -0700370void LayerBase::drawWithOpenGL(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800371{
372 const DisplayHardware& hw(graphicPlane(0).displayHardware());
373 const uint32_t fbHeight = hw.getHeight();
374 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800375
Mathias Agopian49753262010-04-12 15:34:55 -0700376 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800377 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700378 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700379 if (mPremultipliedAlpha) {
380 glColor4f(alpha, alpha, alpha, alpha);
381 } else {
382 glColor4f(1, 1, 1, alpha);
383 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800384 glEnable(GL_BLEND);
385 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700386 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800387 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700388 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700389 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700390 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800391 glEnable(GL_BLEND);
392 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
393 } else {
394 glDisable(GL_BLEND);
395 }
396 }
397
Mathias Agopianb661d662010-08-19 17:01:19 -0700398 struct TexCoords {
399 GLfloat u;
400 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700401 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800402
Mathias Agopian93ffb862012-05-16 17:07:49 -0700403 Rect crop(s.active.w, s.active.h);
404 if (!s.active.crop.isEmpty()) {
405 crop = s.active.crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700406 }
Mathias Agopian93ffb862012-05-16 17:07:49 -0700407 GLfloat left = GLfloat(crop.left) / GLfloat(s.active.w);
408 GLfloat top = GLfloat(crop.top) / GLfloat(s.active.h);
409 GLfloat right = GLfloat(crop.right) / GLfloat(s.active.w);
410 GLfloat bottom = GLfloat(crop.bottom) / GLfloat(s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700411
Mathias Agopianb661d662010-08-19 17:01:19 -0700412 TexCoords texCoords[4];
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700413 texCoords[0].u = left;
414 texCoords[0].v = top;
415 texCoords[1].u = left;
416 texCoords[1].v = bottom;
417 texCoords[2].u = right;
418 texCoords[2].v = bottom;
419 texCoords[3].u = right;
420 texCoords[3].v = top;
421 for (int i = 0; i < 4; i++) {
422 texCoords[i].v = 1.0f - texCoords[i].v;
423 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700424
425 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
426 glVertexPointer(2, GL_FLOAT, 0, mVertices);
427 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700428 glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700429
Mathias Agopian78fd5012010-04-20 14:51:04 -0700430 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700431 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800432}
433
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700434void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
435{
436 const Layer::State& s(drawingState());
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800437
438 snprintf(buffer, SIZE,
439 "+ %s %p (%s)\n",
440 getTypeId(), this, getName().string());
441 result.append(buffer);
442
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800443 s.transparentRegion.dump(result, "transparentRegion");
444 transparentRegionScreen.dump(result, "transparentRegionScreen");
445 visibleRegionScreen.dump(result, "visibleRegionScreen");
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800446
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700447 snprintf(buffer, SIZE,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700448 " "
Mathias Agopian93ffb862012-05-16 17:07:49 -0700449 "z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700450 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700451 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian93ffb862012-05-16 17:07:49 -0700452 s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
453 s.active.crop.left, s.active.crop.top,
454 s.active.crop.right, s.active.crop.bottom,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700455 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700456 s.alpha, s.flags,
457 s.transform[0][0], s.transform[0][1],
458 s.transform[1][0], s.transform[1][1]);
459 result.append(buffer);
460}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700461
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800462void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800463 LayerBase::dump(result, scratch, size);
464}
465
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800466void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
467}
468
469void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800470}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800471
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800472// ---------------------------------------------------------------------------
473
Mathias Agopian631f3582010-05-25 17:51:34 -0700474int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700475
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800476LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700477 const sp<Client>& client)
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800478 : LayerBase(flinger, display),
479 mHasSurface(false),
480 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800481 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800482{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700483}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800484
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800485LayerBaseClient::~LayerBaseClient()
486{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700487 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700488 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700489 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800490 }
491}
492
Mathias Agopiana67932f2011-04-20 14:20:59 -0700493sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800494{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700495 class BSurface : public BnSurface, public LayerCleaner {
496 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
497 public:
498 BSurface(const sp<SurfaceFlinger>& flinger,
499 const sp<LayerBaseClient>& layer)
500 : LayerCleaner(flinger, layer) { }
501 };
502 sp<ISurface> sur(new BSurface(mFlinger, this));
503 return sur;
504}
505
506sp<ISurface> LayerBaseClient::getSurface()
507{
508 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700509 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800510
511 LOG_ALWAYS_FATAL_IF(mHasSurface,
512 "LayerBaseClient::getSurface() has already been called");
513
514 mHasSurface = true;
515 s = createSurface();
516 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700517 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800518}
519
Mathias Agopian0d156122011-01-25 20:17:45 -0800520wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
521 return mClientSurfaceBinder;
522}
523
Jamie Gennis582270d2011-08-17 18:19:00 -0700524wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
525 return 0;
526}
527
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700528void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
529{
530 LayerBase::dump(result, buffer, SIZE);
531
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700532 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700533 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700534 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700535 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700536
537 result.append(buffer);
538}
539
Mathias Agopian48b888a2011-01-19 16:15:53 -0800540
541void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
542{
543 LayerBaseClient::dump(result, scratch, size);
544}
545
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700546// ---------------------------------------------------------------------------
547
Mathias Agopiana67932f2011-04-20 14:20:59 -0700548LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
549 const sp<LayerBaseClient>& layer)
550 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700551}
552
Mathias Agopiana67932f2011-04-20 14:20:59 -0700553LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700554 // destroy client resources
Mathias Agopiana67932f2011-04-20 14:20:59 -0700555 mFlinger->destroySurface(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700556}
557
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800558// ---------------------------------------------------------------------------
559
560}; // namespace android