blob: 2070cb9719499d079de7a47767edd79d66bc15cf [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 mTransactionFlags(0),
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080049 mPremultipliedAlpha(true), mName("unnamed"), mDebug(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051}
52
53LayerBase::~LayerBase()
54{
55}
56
Mathias Agopiand1296592010-03-09 19:17:47 -080057void LayerBase::setName(const String8& name) {
58 mName = name;
59}
60
61String8 LayerBase::getName() const {
62 return mName;
63}
64
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags)
66{
67 uint32_t layerFlags = 0;
68 if (flags & ISurfaceComposer::eHidden)
69 layerFlags = ISurfaceComposer::eLayerHidden;
70
71 if (flags & ISurfaceComposer::eNonPremultiplied)
72 mPremultipliedAlpha = false;
73
Mathias Agopian93ffb862012-05-16 17:07:49 -070074 mCurrentState.active.w = w;
75 mCurrentState.active.h = h;
76 mCurrentState.active.crop.makeInvalid();
77 mCurrentState.z = 0;
78 mCurrentState.alpha = 0xFF;
79 mCurrentState.flags = layerFlags;
80 mCurrentState.sequence = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081 mCurrentState.transform.set(0, 0);
Mathias Agopian93ffb862012-05-16 17:07:49 -070082 mCurrentState.requested = mCurrentState.active;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083
84 // drawing state & current state are identical
85 mDrawingState = mCurrentState;
86}
87
Mathias Agopianba6be542009-09-29 22:32:36 -070088void LayerBase::commitTransaction() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 mDrawingState = mCurrentState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090}
91void LayerBase::forceVisibilityTransaction() {
92 // this can be called without SurfaceFlinger.mStateLock, but if we
93 // can atomically increment the sequence number, it doesn't matter.
94 android_atomic_inc(&mCurrentState.sequence);
95 requestTransaction();
96}
97bool LayerBase::requestTransaction() {
98 int32_t old = setTransactionFlags(eTransactionNeeded);
99 return ((old & eTransactionNeeded) == 0);
100}
101uint32_t LayerBase::getTransactionFlags(uint32_t flags) {
102 return android_atomic_and(~flags, &mTransactionFlags) & flags;
103}
104uint32_t LayerBase::setTransactionFlags(uint32_t flags) {
105 return android_atomic_or(flags, &mTransactionFlags);
106}
107
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700108bool LayerBase::setPosition(float x, float y) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109 if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
110 return false;
111 mCurrentState.sequence++;
112 mCurrentState.transform.set(x, y);
113 requestTransaction();
114 return true;
115}
116bool LayerBase::setLayer(uint32_t z) {
117 if (mCurrentState.z == z)
118 return false;
119 mCurrentState.sequence++;
120 mCurrentState.z = z;
121 requestTransaction();
122 return true;
123}
124bool LayerBase::setSize(uint32_t w, uint32_t h) {
Mathias Agopian93ffb862012-05-16 17:07:49 -0700125 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800126 return false;
Mathias Agopian93ffb862012-05-16 17:07:49 -0700127 mCurrentState.requested.w = w;
128 mCurrentState.requested.h = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800129 requestTransaction();
130 return true;
131}
132bool LayerBase::setAlpha(uint8_t alpha) {
133 if (mCurrentState.alpha == alpha)
134 return false;
135 mCurrentState.sequence++;
136 mCurrentState.alpha = alpha;
137 requestTransaction();
138 return true;
139}
140bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141 mCurrentState.sequence++;
142 mCurrentState.transform.set(
143 matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
144 requestTransaction();
145 return true;
146}
147bool LayerBase::setTransparentRegionHint(const Region& transparent) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800148 mCurrentState.sequence++;
149 mCurrentState.transparentRegion = transparent;
150 requestTransaction();
151 return true;
152}
153bool LayerBase::setFlags(uint8_t flags, uint8_t mask) {
154 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
155 if (mCurrentState.flags == newFlags)
156 return false;
157 mCurrentState.sequence++;
158 mCurrentState.flags = newFlags;
159 requestTransaction();
160 return true;
161}
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700162bool LayerBase::setCrop(const Rect& crop) {
Mathias Agopianb30c4152012-05-16 18:21:32 -0700163 if (mCurrentState.requested.crop == crop)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700164 return false;
165 mCurrentState.sequence++;
Mathias Agopianb30c4152012-05-16 18:21:32 -0700166 mCurrentState.requested.crop = crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700167 requestTransaction();
168 return true;
169}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800170
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800171void LayerBase::setVisibleRegion(const Region& visibleRegion) {
172 // always called from main thread
Mathias Agopian4fec8732012-06-29 14:12:52 -0700173 this->visibleRegion = visibleRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800174}
175
176void LayerBase::setCoveredRegion(const Region& coveredRegion) {
177 // always called from main thread
Mathias Agopian4fec8732012-06-29 14:12:52 -0700178 this->coveredRegion = coveredRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800179}
180
181uint32_t LayerBase::doTransaction(uint32_t flags)
182{
183 const Layer::State& front(drawingState());
184 const Layer::State& temp(currentState());
185
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700186 // always set active to requested, unless we're asked not to
187 // this is used by Layer, which special cases resizes.
188 if (flags & eDontUpdateGeometryState) {
189 } else {
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700190 Layer::State& editTemp(currentState());
Mathias Agopianb30c4152012-05-16 18:21:32 -0700191 editTemp.active = temp.requested;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700192 }
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700193
Mathias Agopianb30c4152012-05-16 18:21:32 -0700194 if (front.active != temp.active) {
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700195 // invalidate and recompute the visible regions if needed
196 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700197 }
198
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800199 if (temp.sequence != front.sequence) {
200 // invalidate and recompute the visible regions if needed
201 flags |= eVisibleRegion;
202 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700203
Mathias Agopian733189d2010-12-02 21:32:29 -0800204 // we may use linear filtering, if the matrix scales us
205 const uint8_t type = temp.transform.getType();
206 mNeedsFiltering = (!temp.transform.preserveRects() ||
207 (type >= Transform::SCALE));
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700208 }
209
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800210 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700211 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800212 return flags;
213}
214
Mathias Agopian4fec8732012-06-29 14:12:52 -0700215void LayerBase::computeGeometry(const DisplayHardware& hw, LayerMesh* mesh) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800216{
217 const Layer::State& s(drawingState());
Mathias Agopian4fec8732012-06-29 14:12:52 -0700218 const Transform tr(hw.getTransform() * s.transform);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700219 const uint32_t hw_h = hw.getHeight();
Mathias Agopian93ffb862012-05-16 17:07:49 -0700220 const Rect& crop(s.active.crop);
Mathias Agopian93ffb862012-05-16 17:07:49 -0700221 Rect win(s.active.w, s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700222 if (!crop.isEmpty()) {
223 win.intersect(crop, &win);
224 }
Mathias Agopian4fec8732012-06-29 14:12:52 -0700225 if (mesh) {
226 tr.transform(mesh->mVertices[0], win.left, win.top);
227 tr.transform(mesh->mVertices[1], win.left, win.bottom);
228 tr.transform(mesh->mVertices[2], win.right, win.bottom);
229 tr.transform(mesh->mVertices[3], win.right, win.top);
230 for (size_t i=0 ; i<4 ; i++) {
231 mesh->mVertices[i][1] = hw_h - mesh->mVertices[i][1];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800232 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800233 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800234}
235
Mathias Agopian4fec8732012-06-29 14:12:52 -0700236Rect LayerBase::computeBounds() const {
237 const Layer::State& s(drawingState());
238 const Rect& crop(s.active.crop);
239 Rect win(s.active.w, s.active.h);
240 if (!crop.isEmpty()) {
241 win.intersect(crop, &win);
242 }
243 return s.transform.transform(win);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800244}
245
Mathias Agopian4fec8732012-06-29 14:12:52 -0700246Region LayerBase::latchBuffer(bool& recomputeVisibleRegions) {
247 Region result;
248 return result;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800249}
250
Mathias Agopian4fec8732012-06-29 14:12:52 -0700251void LayerBase::setGeometry(
252 const DisplayHardware& hw,
253 HWComposer::HWCLayerInterface& layer)
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700254{
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700255 layer.setDefaultState();
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700256
257 // this gives us only the "orientation" component of the transform
258 const State& s(drawingState());
259 const uint32_t finalTransform = s.transform.getOrientation();
260 // we can only handle simple transformation
261 if (finalTransform & Transform::ROT_INVALID) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700262 layer.setTransform(0);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700263 } else {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700264 layer.setTransform(finalTransform);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700265 }
266
267 if (!isOpaque()) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700268 layer.setBlending(mPremultipliedAlpha ?
269 HWC_BLENDING_PREMULT :
270 HWC_BLENDING_COVERAGE);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700271 }
272
Mathias Agopian4fec8732012-06-29 14:12:52 -0700273 const Transform& tr = hw.getTransform();
274 Rect transformedBounds(computeBounds());
275 transformedBounds = tr.transform(transformedBounds);
276
277 // scaling is already applied in transformedBounds
278 layer.setFrame(transformedBounds);
279 layer.setCrop(transformedBounds.getBounds());
280 layer.setVisibleRegionScreen(tr.transform(visibleRegion));
Mathias Agopiana350ff92010-08-10 17:14:02 -0700281}
282
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700283void LayerBase::setPerFrameData(HWComposer::HWCLayerInterface& layer) {
284 layer.setBuffer(0);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700285}
286
Jesse Hallc5c5a142012-07-02 16:49:28 -0700287void LayerBase::setAcquireFence(HWComposer::HWCLayerInterface& layer) {
288 layer.setAcquireFenceFd(-1);
289}
290
Mathias Agopiana67932f2011-04-20 14:20:59 -0700291void LayerBase::setFiltering(bool filtering)
292{
293 mFiltering = filtering;
294}
295
296bool LayerBase::getFiltering() const
297{
298 return mFiltering;
299}
300
Mathias Agopian1b031492012-06-20 17:51:20 -0700301void LayerBase::draw(const DisplayHardware& hw, const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800302{
Mathias Agopian1b031492012-06-20 17:51:20 -0700303 onDraw(hw, clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800304}
305
Mathias Agopian1b031492012-06-20 17:51:20 -0700306void LayerBase::drawForSreenShot(const DisplayHardware& hw)
Mathias Agopian74c40c02010-09-29 13:02:36 -0700307{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700308 setFiltering(true);
Mathias Agopian1b031492012-06-20 17:51:20 -0700309 onDraw( hw, Region(hw.bounds()) );
Mathias Agopiana67932f2011-04-20 14:20:59 -0700310 setFiltering(false);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700311}
312
Mathias Agopian1b031492012-06-20 17:51:20 -0700313void LayerBase::clearWithOpenGL(const DisplayHardware& hw, const Region& clip,
314 GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800315{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800316 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700317 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700318
Mathias Agopianc492e672011-10-18 14:49:27 -0700319 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700320 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800321 glDisable(GL_BLEND);
Mathias Agopian20f68782009-05-11 00:03:41 -0700322
Mathias Agopian4fec8732012-06-29 14:12:52 -0700323 LayerMesh mesh;
324 computeGeometry(hw, &mesh);
325
326 glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
327 glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800328}
329
Mathias Agopian1b031492012-06-20 17:51:20 -0700330void LayerBase::clearWithOpenGL(const DisplayHardware& hw, const Region& clip) const
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700331{
Mathias Agopian1b031492012-06-20 17:51:20 -0700332 clearWithOpenGL(hw, clip, 0,0,0,0);
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700333}
334
Mathias Agopian1b031492012-06-20 17:51:20 -0700335void LayerBase::drawWithOpenGL(const DisplayHardware& hw, const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800336{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800337 const uint32_t fbHeight = hw.getHeight();
338 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339
Mathias Agopian49753262010-04-12 15:34:55 -0700340 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800341 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700342 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700343 if (mPremultipliedAlpha) {
344 glColor4f(alpha, alpha, alpha, alpha);
345 } else {
346 glColor4f(1, 1, 1, alpha);
347 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800348 glEnable(GL_BLEND);
349 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700350 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800351 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700352 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700353 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700354 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800355 glEnable(GL_BLEND);
356 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
357 } else {
358 glDisable(GL_BLEND);
359 }
360 }
361
Mathias Agopian4fec8732012-06-29 14:12:52 -0700362 LayerMesh mesh;
363 computeGeometry(hw, &mesh);
364
365 // TODO: we probably want to generate the texture coords with the mesh
366 // here we assume that we only have 4 vertices
367
Mathias Agopianb661d662010-08-19 17:01:19 -0700368 struct TexCoords {
369 GLfloat u;
370 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700371 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800372
Mathias Agopian93ffb862012-05-16 17:07:49 -0700373 Rect crop(s.active.w, s.active.h);
374 if (!s.active.crop.isEmpty()) {
375 crop = s.active.crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700376 }
Mathias Agopian4fec8732012-06-29 14:12:52 -0700377 GLfloat left = GLfloat(crop.left) / GLfloat(s.active.w);
378 GLfloat top = GLfloat(crop.top) / GLfloat(s.active.h);
379 GLfloat right = GLfloat(crop.right) / GLfloat(s.active.w);
Mathias Agopian93ffb862012-05-16 17:07:49 -0700380 GLfloat bottom = GLfloat(crop.bottom) / GLfloat(s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700381
Mathias Agopianb661d662010-08-19 17:01:19 -0700382 TexCoords texCoords[4];
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700383 texCoords[0].u = left;
384 texCoords[0].v = top;
385 texCoords[1].u = left;
386 texCoords[1].v = bottom;
387 texCoords[2].u = right;
388 texCoords[2].v = bottom;
389 texCoords[3].u = right;
390 texCoords[3].v = top;
391 for (int i = 0; i < 4; i++) {
392 texCoords[i].v = 1.0f - texCoords[i].v;
393 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700394
395 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700396 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
Mathias Agopian4fec8732012-06-29 14:12:52 -0700397 glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
398 glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
Mathias Agopian78fd5012010-04-20 14:51:04 -0700399
Mathias Agopian78fd5012010-04-20 14:51:04 -0700400 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700401 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800402}
403
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700404void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
405{
406 const Layer::State& s(drawingState());
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800407
408 snprintf(buffer, SIZE,
409 "+ %s %p (%s)\n",
410 getTypeId(), this, getName().string());
411 result.append(buffer);
412
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800413 s.transparentRegion.dump(result, "transparentRegion");
Mathias Agopian4fec8732012-06-29 14:12:52 -0700414 visibleRegion.dump(result, "visibleRegion");
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800415
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700416 snprintf(buffer, SIZE,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700417 " "
Mathias Agopian93ffb862012-05-16 17:07:49 -0700418 "z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700419 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700420 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian93ffb862012-05-16 17:07:49 -0700421 s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
422 s.active.crop.left, s.active.crop.top,
423 s.active.crop.right, s.active.crop.bottom,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700424 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700425 s.alpha, s.flags,
426 s.transform[0][0], s.transform[0][1],
427 s.transform[1][0], s.transform[1][1]);
428 result.append(buffer);
429}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700430
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800431void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800432 LayerBase::dump(result, scratch, size);
433}
434
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800435void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
436}
437
438void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800439}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800440
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800441// ---------------------------------------------------------------------------
442
Mathias Agopian631f3582010-05-25 17:51:34 -0700443int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700444
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800445LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700446 const sp<Client>& client)
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800447 : LayerBase(flinger, display),
448 mHasSurface(false),
449 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800450 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800451{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700452}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800453
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800454LayerBaseClient::~LayerBaseClient()
455{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700456 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700457 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700458 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800459 }
460}
461
Mathias Agopiana67932f2011-04-20 14:20:59 -0700462sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800463{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700464 class BSurface : public BnSurface, public LayerCleaner {
465 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
466 public:
467 BSurface(const sp<SurfaceFlinger>& flinger,
468 const sp<LayerBaseClient>& layer)
469 : LayerCleaner(flinger, layer) { }
470 };
471 sp<ISurface> sur(new BSurface(mFlinger, this));
472 return sur;
473}
474
475sp<ISurface> LayerBaseClient::getSurface()
476{
477 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700478 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800479
480 LOG_ALWAYS_FATAL_IF(mHasSurface,
481 "LayerBaseClient::getSurface() has already been called");
482
483 mHasSurface = true;
484 s = createSurface();
485 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700486 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800487}
488
Mathias Agopian0d156122011-01-25 20:17:45 -0800489wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
490 return mClientSurfaceBinder;
491}
492
Jamie Gennis582270d2011-08-17 18:19:00 -0700493wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
494 return 0;
495}
496
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700497void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
498{
499 LayerBase::dump(result, buffer, SIZE);
500
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700501 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700502 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700503 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700504 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700505
506 result.append(buffer);
507}
508
Mathias Agopian48b888a2011-01-19 16:15:53 -0800509
510void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
511{
512 LayerBaseClient::dump(result, scratch, size);
513}
514
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700515// ---------------------------------------------------------------------------
516
Mathias Agopiana67932f2011-04-20 14:20:59 -0700517LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
518 const sp<LayerBaseClient>& layer)
519 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700520}
521
Mathias Agopiana67932f2011-04-20 14:20:59 -0700522LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700523 // destroy client resources
Mathias Agopiana67932f2011-04-20 14:20:59 -0700524 mFlinger->destroySurface(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700525}
526
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800527// ---------------------------------------------------------------------------
528
529}; // namespace android