blob: fe15dc90a26de2416a650bfe758e0f474ee83aad [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 Agopian05cec9d2012-05-23 14:35:49 -0700204 // always set active to requested, unless we're asked not to
205 // this is used by Layer, which special cases resizes.
206 if (flags & eDontUpdateGeometryState) {
207 } else {
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700208 Layer::State& editTemp(currentState());
Mathias Agopianb30c4152012-05-16 18:21:32 -0700209 editTemp.active = temp.requested;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700210 }
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700211
Mathias Agopianb30c4152012-05-16 18:21:32 -0700212 if (front.active != temp.active) {
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700213 // invalidate and recompute the visible regions if needed
214 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700215 }
216
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800217 if (temp.sequence != front.sequence) {
218 // invalidate and recompute the visible regions if needed
219 flags |= eVisibleRegion;
220 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700221
Mathias Agopian733189d2010-12-02 21:32:29 -0800222 // we may use linear filtering, if the matrix scales us
223 const uint8_t type = temp.transform.getType();
224 mNeedsFiltering = (!temp.transform.preserveRects() ||
225 (type >= Transform::SCALE));
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700226 }
227
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800228 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700229 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800230 return flags;
231}
232
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800233void LayerBase::validateVisibility(const Transform& planeTransform)
234{
235 const Layer::State& s(drawingState());
236 const Transform tr(planeTransform * s.transform);
237 const bool transformed = tr.transformed();
Mathias Agopianffcf4652011-07-07 17:30:31 -0700238 const DisplayHardware& hw(graphicPlane(0).displayHardware());
239 const uint32_t hw_h = hw.getHeight();
Mathias Agopian93ffb862012-05-16 17:07:49 -0700240 const Rect& crop(s.active.crop);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700241
Mathias Agopian93ffb862012-05-16 17:07:49 -0700242 Rect win(s.active.w, s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700243 if (!crop.isEmpty()) {
244 win.intersect(crop, &win);
245 }
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700246
247 mNumVertices = 4;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700248 tr.transform(mVertices[0], win.left, win.top);
249 tr.transform(mVertices[1], win.left, win.bottom);
250 tr.transform(mVertices[2], win.right, win.bottom);
251 tr.transform(mVertices[3], win.right, win.top);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700252 for (size_t i=0 ; i<4 ; i++)
253 mVertices[i][1] = hw_h - mVertices[i][1];
254
Glenn Kasten99ed2242011-12-15 09:51:17 -0800255 if (CC_UNLIKELY(transformed)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800256 // NOTE: here we could also punt if we have too many rectangles
257 // in the transparent region
258 if (tr.preserveRects()) {
259 // transform the transparent region
260 transparentRegionScreen = tr.transform(s.transparentRegion);
261 } else {
262 // transformation too complex, can't do the transparent region
263 // optimization.
264 transparentRegionScreen.clear();
265 }
266 } else {
267 transparentRegionScreen = s.transparentRegion;
268 }
269
270 // cache a few things...
271 mOrientation = tr.getOrientation();
Jamie Gennis8d91b422011-09-23 15:54:34 -0700272 mPlaneOrientation = planeTransform.getOrientation();
Mathias Agopiand992db32011-08-18 18:31:00 -0700273 mTransform = tr;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700274 mTransformedBounds = tr.transform(win);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800275}
276
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800277void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800278}
279
280void LayerBase::unlockPageFlip(
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800281 const Transform& planeTransform, Region& outDirtyRegion) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800282}
283
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700284void LayerBase::setGeometry(HWComposer::HWCLayerInterface& layer)
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700285{
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700286 layer.setDefaultState();
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700287
288 // this gives us only the "orientation" component of the transform
289 const State& s(drawingState());
290 const uint32_t finalTransform = s.transform.getOrientation();
291 // we can only handle simple transformation
292 if (finalTransform & Transform::ROT_INVALID) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700293 layer.setTransform(0);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700294 } else {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700295 layer.setTransform(finalTransform);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700296 }
297
298 if (!isOpaque()) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700299 layer.setBlending(mPremultipliedAlpha ?
300 HWC_BLENDING_PREMULT :
301 HWC_BLENDING_COVERAGE);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700302 }
303
304 // scaling is already applied in mTransformedBounds
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700305 layer.setFrame(mTransformedBounds);
306 layer.setVisibleRegionScreen(visibleRegionScreen);
307 layer.setCrop(mTransformedBounds.getBounds());
Mathias Agopiana350ff92010-08-10 17:14:02 -0700308}
309
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700310void LayerBase::setPerFrameData(HWComposer::HWCLayerInterface& layer) {
311 layer.setBuffer(0);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700312}
313
Mathias Agopiana67932f2011-04-20 14:20:59 -0700314void LayerBase::setFiltering(bool filtering)
315{
316 mFiltering = filtering;
317}
318
319bool LayerBase::getFiltering() const
320{
321 return mFiltering;
322}
323
Mathias Agopianbc7e31a2010-08-10 20:42:20 -0700324void LayerBase::draw(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800325{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800326 onDraw(clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800327}
328
Mathias Agopiana67932f2011-04-20 14:20:59 -0700329void LayerBase::drawForSreenShot()
Mathias Agopian74c40c02010-09-29 13:02:36 -0700330{
331 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopiana67932f2011-04-20 14:20:59 -0700332 setFiltering(true);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700333 onDraw( Region(hw.bounds()) );
Mathias Agopiana67932f2011-04-20 14:20:59 -0700334 setFiltering(false);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700335}
336
Mathias Agopian010fccb2010-05-26 22:26:12 -0700337void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
338 GLclampf green, GLclampf blue,
339 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800340{
341 const DisplayHardware& hw(graphicPlane(0).displayHardware());
342 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700343 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700344
Mathias Agopianc492e672011-10-18 14:49:27 -0700345 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700346 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800347 glDisable(GL_BLEND);
Mathias Agopian20f68782009-05-11 00:03:41 -0700348
Mathias Agopian78fd5012010-04-20 14:51:04 -0700349 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700350 glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800351}
352
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700353void LayerBase::clearWithOpenGL(const Region& clip) const
354{
355 clearWithOpenGL(clip,0,0,0,0);
356}
357
Mathias Agopiana67932f2011-04-20 14:20:59 -0700358void LayerBase::drawWithOpenGL(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800359{
360 const DisplayHardware& hw(graphicPlane(0).displayHardware());
361 const uint32_t fbHeight = hw.getHeight();
362 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800363
Mathias Agopian49753262010-04-12 15:34:55 -0700364 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800365 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700366 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700367 if (mPremultipliedAlpha) {
368 glColor4f(alpha, alpha, alpha, alpha);
369 } else {
370 glColor4f(1, 1, 1, alpha);
371 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800372 glEnable(GL_BLEND);
373 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700374 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800375 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700376 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700377 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700378 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800379 glEnable(GL_BLEND);
380 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
381 } else {
382 glDisable(GL_BLEND);
383 }
384 }
385
Mathias Agopianb661d662010-08-19 17:01:19 -0700386 struct TexCoords {
387 GLfloat u;
388 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700389 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800390
Mathias Agopian93ffb862012-05-16 17:07:49 -0700391 Rect crop(s.active.w, s.active.h);
392 if (!s.active.crop.isEmpty()) {
393 crop = s.active.crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700394 }
Mathias Agopian93ffb862012-05-16 17:07:49 -0700395 GLfloat left = GLfloat(crop.left) / GLfloat(s.active.w);
396 GLfloat top = GLfloat(crop.top) / GLfloat(s.active.h);
397 GLfloat right = GLfloat(crop.right) / GLfloat(s.active.w);
398 GLfloat bottom = GLfloat(crop.bottom) / GLfloat(s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700399
Mathias Agopianb661d662010-08-19 17:01:19 -0700400 TexCoords texCoords[4];
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700401 texCoords[0].u = left;
402 texCoords[0].v = top;
403 texCoords[1].u = left;
404 texCoords[1].v = bottom;
405 texCoords[2].u = right;
406 texCoords[2].v = bottom;
407 texCoords[3].u = right;
408 texCoords[3].v = top;
409 for (int i = 0; i < 4; i++) {
410 texCoords[i].v = 1.0f - texCoords[i].v;
411 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700412
413 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
414 glVertexPointer(2, GL_FLOAT, 0, mVertices);
415 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700416 glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700417
Mathias Agopian78fd5012010-04-20 14:51:04 -0700418 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700419 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800420}
421
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700422void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
423{
424 const Layer::State& s(drawingState());
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800425
426 snprintf(buffer, SIZE,
427 "+ %s %p (%s)\n",
428 getTypeId(), this, getName().string());
429 result.append(buffer);
430
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800431 s.transparentRegion.dump(result, "transparentRegion");
432 transparentRegionScreen.dump(result, "transparentRegionScreen");
433 visibleRegionScreen.dump(result, "visibleRegionScreen");
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800434
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700435 snprintf(buffer, SIZE,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700436 " "
Mathias Agopian93ffb862012-05-16 17:07:49 -0700437 "z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700438 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700439 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian93ffb862012-05-16 17:07:49 -0700440 s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
441 s.active.crop.left, s.active.crop.top,
442 s.active.crop.right, s.active.crop.bottom,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700443 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700444 s.alpha, s.flags,
445 s.transform[0][0], s.transform[0][1],
446 s.transform[1][0], s.transform[1][1]);
447 result.append(buffer);
448}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700449
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800450void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800451 LayerBase::dump(result, scratch, size);
452}
453
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800454void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
455}
456
457void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800458}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800459
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800460// ---------------------------------------------------------------------------
461
Mathias Agopian631f3582010-05-25 17:51:34 -0700462int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700463
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800464LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700465 const sp<Client>& client)
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800466 : LayerBase(flinger, display),
467 mHasSurface(false),
468 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800469 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800470{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700471}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800472
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800473LayerBaseClient::~LayerBaseClient()
474{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700475 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700476 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700477 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800478 }
479}
480
Mathias Agopiana67932f2011-04-20 14:20:59 -0700481sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800482{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700483 class BSurface : public BnSurface, public LayerCleaner {
484 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
485 public:
486 BSurface(const sp<SurfaceFlinger>& flinger,
487 const sp<LayerBaseClient>& layer)
488 : LayerCleaner(flinger, layer) { }
489 };
490 sp<ISurface> sur(new BSurface(mFlinger, this));
491 return sur;
492}
493
494sp<ISurface> LayerBaseClient::getSurface()
495{
496 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700497 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800498
499 LOG_ALWAYS_FATAL_IF(mHasSurface,
500 "LayerBaseClient::getSurface() has already been called");
501
502 mHasSurface = true;
503 s = createSurface();
504 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700505 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800506}
507
Mathias Agopian0d156122011-01-25 20:17:45 -0800508wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
509 return mClientSurfaceBinder;
510}
511
Jamie Gennis582270d2011-08-17 18:19:00 -0700512wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
513 return 0;
514}
515
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700516void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
517{
518 LayerBase::dump(result, buffer, SIZE);
519
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700520 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700521 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700522 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700523 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700524
525 result.append(buffer);
526}
527
Mathias Agopian48b888a2011-01-19 16:15:53 -0800528
529void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
530{
531 LayerBaseClient::dump(result, scratch, size);
532}
533
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700534// ---------------------------------------------------------------------------
535
Mathias Agopiana67932f2011-04-20 14:20:59 -0700536LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
537 const sp<LayerBaseClient>& layer)
538 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700539}
540
Mathias Agopiana67932f2011-04-20 14:20:59 -0700541LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700542 // destroy client resources
Mathias Agopiana67932f2011-04-20 14:20:59 -0700543 mFlinger->destroySurface(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700544}
545
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800546// ---------------------------------------------------------------------------
547
548}; // namespace android