blob: fd4c2239406164c08781f7fc6b27a56ff77ee407 [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"
Mathias Agopiandb403e82012-06-18 16:47:56 -070032#include "Client.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033#include "LayerBase.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034#include "SurfaceFlinger.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070035#include "DisplayHardware.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037namespace android {
38
39// ---------------------------------------------------------------------------
40
Mathias Agopianf6679fc2010-08-10 18:09:09 -070041int32_t LayerBase::sSequence = 1;
42
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display)
44 : dpy(display), contentDirty(false),
Mathias Agopianf6679fc2010-08-10 18:09:09 -070045 sequence(uint32_t(android_atomic_inc(&sSequence))),
Mathias Agopiana67932f2011-04-20 14:20:59 -070046 mFlinger(flinger), mFiltering(false),
Mathias Agopiana2f4e562012-04-15 23:34:59 -070047 mNeedsFiltering(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048 mOrientation(0),
Jamie Gennis8d91b422011-09-23 15:54:34 -070049 mPlaneOrientation(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050 mTransactionFlags(0),
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080051 mPremultipliedAlpha(true), mName("unnamed"), mDebug(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053}
54
55LayerBase::~LayerBase()
56{
57}
58
Mathias Agopiand1296592010-03-09 19:17:47 -080059void LayerBase::setName(const String8& name) {
60 mName = name;
61}
62
63String8 LayerBase::getName() const {
64 return mName;
65}
66
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags)
68{
69 uint32_t layerFlags = 0;
70 if (flags & ISurfaceComposer::eHidden)
71 layerFlags = ISurfaceComposer::eLayerHidden;
72
73 if (flags & ISurfaceComposer::eNonPremultiplied)
74 mPremultipliedAlpha = false;
75
Mathias Agopian93ffb862012-05-16 17:07:49 -070076 mCurrentState.active.w = w;
77 mCurrentState.active.h = h;
78 mCurrentState.active.crop.makeInvalid();
79 mCurrentState.z = 0;
80 mCurrentState.alpha = 0xFF;
81 mCurrentState.flags = layerFlags;
82 mCurrentState.sequence = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083 mCurrentState.transform.set(0, 0);
Mathias Agopian93ffb862012-05-16 17:07:49 -070084 mCurrentState.requested = mCurrentState.active;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085
86 // drawing state & current state are identical
87 mDrawingState = mCurrentState;
88}
89
Mathias Agopianba6be542009-09-29 22:32:36 -070090void LayerBase::commitTransaction() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091 mDrawingState = mCurrentState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080092}
93void LayerBase::forceVisibilityTransaction() {
94 // this can be called without SurfaceFlinger.mStateLock, but if we
95 // can atomically increment the sequence number, it doesn't matter.
96 android_atomic_inc(&mCurrentState.sequence);
97 requestTransaction();
98}
99bool LayerBase::requestTransaction() {
100 int32_t old = setTransactionFlags(eTransactionNeeded);
101 return ((old & eTransactionNeeded) == 0);
102}
103uint32_t LayerBase::getTransactionFlags(uint32_t flags) {
104 return android_atomic_and(~flags, &mTransactionFlags) & flags;
105}
106uint32_t LayerBase::setTransactionFlags(uint32_t flags) {
107 return android_atomic_or(flags, &mTransactionFlags);
108}
109
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700110bool LayerBase::setPosition(float x, float y) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111 if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
112 return false;
113 mCurrentState.sequence++;
114 mCurrentState.transform.set(x, y);
115 requestTransaction();
116 return true;
117}
118bool LayerBase::setLayer(uint32_t z) {
119 if (mCurrentState.z == z)
120 return false;
121 mCurrentState.sequence++;
122 mCurrentState.z = z;
123 requestTransaction();
124 return true;
125}
126bool LayerBase::setSize(uint32_t w, uint32_t h) {
Mathias Agopian93ffb862012-05-16 17:07:49 -0700127 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128 return false;
Mathias Agopian93ffb862012-05-16 17:07:49 -0700129 mCurrentState.requested.w = w;
130 mCurrentState.requested.h = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800131 requestTransaction();
132 return true;
133}
134bool LayerBase::setAlpha(uint8_t alpha) {
135 if (mCurrentState.alpha == alpha)
136 return false;
137 mCurrentState.sequence++;
138 mCurrentState.alpha = alpha;
139 requestTransaction();
140 return true;
141}
142bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 mCurrentState.sequence++;
144 mCurrentState.transform.set(
145 matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
146 requestTransaction();
147 return true;
148}
149bool LayerBase::setTransparentRegionHint(const Region& transparent) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800150 mCurrentState.sequence++;
151 mCurrentState.transparentRegion = transparent;
152 requestTransaction();
153 return true;
154}
155bool LayerBase::setFlags(uint8_t flags, uint8_t mask) {
156 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
157 if (mCurrentState.flags == newFlags)
158 return false;
159 mCurrentState.sequence++;
160 mCurrentState.flags = newFlags;
161 requestTransaction();
162 return true;
163}
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700164bool LayerBase::setCrop(const Rect& crop) {
Mathias Agopianb30c4152012-05-16 18:21:32 -0700165 if (mCurrentState.requested.crop == crop)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700166 return false;
167 mCurrentState.sequence++;
Mathias Agopianb30c4152012-05-16 18:21:32 -0700168 mCurrentState.requested.crop = crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700169 requestTransaction();
170 return true;
171}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800172
173Rect LayerBase::visibleBounds() const
174{
175 return mTransformedBounds;
176}
177
178void LayerBase::setVisibleRegion(const Region& visibleRegion) {
179 // always called from main thread
180 visibleRegionScreen = visibleRegion;
181}
182
183void LayerBase::setCoveredRegion(const Region& coveredRegion) {
184 // always called from main thread
185 coveredRegionScreen = coveredRegion;
186}
187
188uint32_t LayerBase::doTransaction(uint32_t flags)
189{
190 const Layer::State& front(drawingState());
191 const Layer::State& temp(currentState());
192
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700193 // always set active to requested, unless we're asked not to
194 // this is used by Layer, which special cases resizes.
195 if (flags & eDontUpdateGeometryState) {
196 } else {
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700197 Layer::State& editTemp(currentState());
Mathias Agopianb30c4152012-05-16 18:21:32 -0700198 editTemp.active = temp.requested;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700199 }
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700200
Mathias Agopianb30c4152012-05-16 18:21:32 -0700201 if (front.active != temp.active) {
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700202 // invalidate and recompute the visible regions if needed
203 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700204 }
205
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206 if (temp.sequence != front.sequence) {
207 // invalidate and recompute the visible regions if needed
208 flags |= eVisibleRegion;
209 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700210
Mathias Agopian733189d2010-12-02 21:32:29 -0800211 // we may use linear filtering, if the matrix scales us
212 const uint8_t type = temp.transform.getType();
213 mNeedsFiltering = (!temp.transform.preserveRects() ||
214 (type >= Transform::SCALE));
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700215 }
216
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800217 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700218 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800219 return flags;
220}
221
Mathias Agopian1b031492012-06-20 17:51:20 -0700222void LayerBase::validateVisibility(const Transform& planeTransform, const DisplayHardware& hw)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800223{
224 const Layer::State& s(drawingState());
225 const Transform tr(planeTransform * s.transform);
226 const bool transformed = tr.transformed();
Mathias Agopianffcf4652011-07-07 17:30:31 -0700227 const uint32_t hw_h = hw.getHeight();
Mathias Agopian93ffb862012-05-16 17:07:49 -0700228 const Rect& crop(s.active.crop);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700229
Mathias Agopian93ffb862012-05-16 17:07:49 -0700230 Rect win(s.active.w, s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700231 if (!crop.isEmpty()) {
232 win.intersect(crop, &win);
233 }
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700234
235 mNumVertices = 4;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700236 tr.transform(mVertices[0], win.left, win.top);
237 tr.transform(mVertices[1], win.left, win.bottom);
238 tr.transform(mVertices[2], win.right, win.bottom);
239 tr.transform(mVertices[3], win.right, win.top);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700240 for (size_t i=0 ; i<4 ; i++)
241 mVertices[i][1] = hw_h - mVertices[i][1];
242
Glenn Kasten99ed2242011-12-15 09:51:17 -0800243 if (CC_UNLIKELY(transformed)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800244 // NOTE: here we could also punt if we have too many rectangles
245 // in the transparent region
246 if (tr.preserveRects()) {
247 // transform the transparent region
248 transparentRegionScreen = tr.transform(s.transparentRegion);
249 } else {
250 // transformation too complex, can't do the transparent region
251 // optimization.
252 transparentRegionScreen.clear();
253 }
254 } else {
255 transparentRegionScreen = s.transparentRegion;
256 }
257
258 // cache a few things...
259 mOrientation = tr.getOrientation();
Jamie Gennis8d91b422011-09-23 15:54:34 -0700260 mPlaneOrientation = planeTransform.getOrientation();
Mathias Agopiand992db32011-08-18 18:31:00 -0700261 mTransform = tr;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700262 mTransformedBounds = tr.transform(win);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800263}
264
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800265void LayerBase::lockPageFlip(bool& recomputeVisibleRegions) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800266}
267
268void LayerBase::unlockPageFlip(
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800269 const Transform& planeTransform, Region& outDirtyRegion) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800270}
271
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700272void LayerBase::setGeometry(HWComposer::HWCLayerInterface& layer)
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700273{
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700274 layer.setDefaultState();
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700275
276 // this gives us only the "orientation" component of the transform
277 const State& s(drawingState());
278 const uint32_t finalTransform = s.transform.getOrientation();
279 // we can only handle simple transformation
280 if (finalTransform & Transform::ROT_INVALID) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700281 layer.setTransform(0);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700282 } else {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700283 layer.setTransform(finalTransform);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700284 }
285
286 if (!isOpaque()) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700287 layer.setBlending(mPremultipliedAlpha ?
288 HWC_BLENDING_PREMULT :
289 HWC_BLENDING_COVERAGE);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700290 }
291
292 // scaling is already applied in mTransformedBounds
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700293 layer.setFrame(mTransformedBounds);
294 layer.setVisibleRegionScreen(visibleRegionScreen);
295 layer.setCrop(mTransformedBounds.getBounds());
Mathias Agopiana350ff92010-08-10 17:14:02 -0700296}
297
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700298void LayerBase::setPerFrameData(HWComposer::HWCLayerInterface& layer) {
299 layer.setBuffer(0);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700300}
301
Mathias Agopiana67932f2011-04-20 14:20:59 -0700302void LayerBase::setFiltering(bool filtering)
303{
304 mFiltering = filtering;
305}
306
307bool LayerBase::getFiltering() const
308{
309 return mFiltering;
310}
311
Mathias Agopian1b031492012-06-20 17:51:20 -0700312void LayerBase::draw(const DisplayHardware& hw, const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800313{
Mathias Agopian1b031492012-06-20 17:51:20 -0700314 onDraw(hw, clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800315}
316
Mathias Agopian1b031492012-06-20 17:51:20 -0700317void LayerBase::drawForSreenShot(const DisplayHardware& hw)
Mathias Agopian74c40c02010-09-29 13:02:36 -0700318{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700319 setFiltering(true);
Mathias Agopian1b031492012-06-20 17:51:20 -0700320 onDraw( hw, Region(hw.bounds()) );
Mathias Agopiana67932f2011-04-20 14:20:59 -0700321 setFiltering(false);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700322}
323
Mathias Agopian1b031492012-06-20 17:51:20 -0700324void LayerBase::clearWithOpenGL(const DisplayHardware& hw, const Region& clip,
325 GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800326{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800327 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700328 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700329
Mathias Agopianc492e672011-10-18 14:49:27 -0700330 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700331 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800332 glDisable(GL_BLEND);
Mathias Agopian20f68782009-05-11 00:03:41 -0700333
Mathias Agopian78fd5012010-04-20 14:51:04 -0700334 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700335 glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800336}
337
Mathias Agopian1b031492012-06-20 17:51:20 -0700338void LayerBase::clearWithOpenGL(const DisplayHardware& hw, const Region& clip) const
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700339{
Mathias Agopian1b031492012-06-20 17:51:20 -0700340 clearWithOpenGL(hw, clip, 0,0,0,0);
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700341}
342
Mathias Agopian1b031492012-06-20 17:51:20 -0700343void LayerBase::drawWithOpenGL(const DisplayHardware& hw, const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800344{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800345 const uint32_t fbHeight = hw.getHeight();
346 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800347
Mathias Agopian49753262010-04-12 15:34:55 -0700348 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800349 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700350 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700351 if (mPremultipliedAlpha) {
352 glColor4f(alpha, alpha, alpha, alpha);
353 } else {
354 glColor4f(1, 1, 1, alpha);
355 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800356 glEnable(GL_BLEND);
357 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700358 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800359 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700360 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700361 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700362 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800363 glEnable(GL_BLEND);
364 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
365 } else {
366 glDisable(GL_BLEND);
367 }
368 }
369
Mathias Agopianb661d662010-08-19 17:01:19 -0700370 struct TexCoords {
371 GLfloat u;
372 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700373 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800374
Mathias Agopian93ffb862012-05-16 17:07:49 -0700375 Rect crop(s.active.w, s.active.h);
376 if (!s.active.crop.isEmpty()) {
377 crop = s.active.crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700378 }
Mathias Agopian93ffb862012-05-16 17:07:49 -0700379 GLfloat left = GLfloat(crop.left) / GLfloat(s.active.w);
380 GLfloat top = GLfloat(crop.top) / GLfloat(s.active.h);
381 GLfloat right = GLfloat(crop.right) / GLfloat(s.active.w);
382 GLfloat bottom = GLfloat(crop.bottom) / GLfloat(s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700383
Mathias Agopianb661d662010-08-19 17:01:19 -0700384 TexCoords texCoords[4];
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700385 texCoords[0].u = left;
386 texCoords[0].v = top;
387 texCoords[1].u = left;
388 texCoords[1].v = bottom;
389 texCoords[2].u = right;
390 texCoords[2].v = bottom;
391 texCoords[3].u = right;
392 texCoords[3].v = top;
393 for (int i = 0; i < 4; i++) {
394 texCoords[i].v = 1.0f - texCoords[i].v;
395 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700396
397 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
398 glVertexPointer(2, GL_FLOAT, 0, mVertices);
399 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
Mathias Agopianf74e8e02012-04-16 03:14:05 -0700400 glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700401
Mathias Agopian78fd5012010-04-20 14:51:04 -0700402 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700403 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800404}
405
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700406void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
407{
408 const Layer::State& s(drawingState());
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800409
410 snprintf(buffer, SIZE,
411 "+ %s %p (%s)\n",
412 getTypeId(), this, getName().string());
413 result.append(buffer);
414
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800415 s.transparentRegion.dump(result, "transparentRegion");
416 transparentRegionScreen.dump(result, "transparentRegionScreen");
417 visibleRegionScreen.dump(result, "visibleRegionScreen");
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800418
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700419 snprintf(buffer, SIZE,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700420 " "
Mathias Agopian93ffb862012-05-16 17:07:49 -0700421 "z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700422 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700423 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian93ffb862012-05-16 17:07:49 -0700424 s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
425 s.active.crop.left, s.active.crop.top,
426 s.active.crop.right, s.active.crop.bottom,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700427 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700428 s.alpha, s.flags,
429 s.transform[0][0], s.transform[0][1],
430 s.transform[1][0], s.transform[1][1]);
431 result.append(buffer);
432}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700433
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800434void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800435 LayerBase::dump(result, scratch, size);
436}
437
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800438void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
439}
440
441void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800442}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800443
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800444// ---------------------------------------------------------------------------
445
Mathias Agopian631f3582010-05-25 17:51:34 -0700446int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700447
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800448LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700449 const sp<Client>& client)
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800450 : LayerBase(flinger, display),
451 mHasSurface(false),
452 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800453 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800454{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700455}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800456
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800457LayerBaseClient::~LayerBaseClient()
458{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700459 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700460 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700461 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800462 }
463}
464
Mathias Agopiana67932f2011-04-20 14:20:59 -0700465sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800466{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700467 class BSurface : public BnSurface, public LayerCleaner {
468 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
469 public:
470 BSurface(const sp<SurfaceFlinger>& flinger,
471 const sp<LayerBaseClient>& layer)
472 : LayerCleaner(flinger, layer) { }
473 };
474 sp<ISurface> sur(new BSurface(mFlinger, this));
475 return sur;
476}
477
478sp<ISurface> LayerBaseClient::getSurface()
479{
480 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700481 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800482
483 LOG_ALWAYS_FATAL_IF(mHasSurface,
484 "LayerBaseClient::getSurface() has already been called");
485
486 mHasSurface = true;
487 s = createSurface();
488 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700489 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800490}
491
Mathias Agopian0d156122011-01-25 20:17:45 -0800492wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
493 return mClientSurfaceBinder;
494}
495
Jamie Gennis582270d2011-08-17 18:19:00 -0700496wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
497 return 0;
498}
499
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700500void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
501{
502 LayerBase::dump(result, buffer, SIZE);
503
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700504 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700505 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700506 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700507 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700508
509 result.append(buffer);
510}
511
Mathias Agopian48b888a2011-01-19 16:15:53 -0800512
513void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
514{
515 LayerBaseClient::dump(result, scratch, size);
516}
517
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700518// ---------------------------------------------------------------------------
519
Mathias Agopiana67932f2011-04-20 14:20:59 -0700520LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
521 const sp<LayerBaseClient>& layer)
522 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700523}
524
Mathias Agopiana67932f2011-04-20 14:20:59 -0700525LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700526 // destroy client resources
Mathias Agopiana67932f2011-04-20 14:20:59 -0700527 mFlinger->destroySurface(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700528}
529
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800530// ---------------------------------------------------------------------------
531
532}; // namespace android