blob: f4eebb2d8c7ab16a30d3dfbf51ceb8b4488e4d32 [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"
Mathias Agopian921e6ac2012-07-23 23:11:29 -070034#include "Layer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035#include "SurfaceFlinger.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070036#include "DisplayHardware.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038namespace android {
39
40// ---------------------------------------------------------------------------
41
Mathias Agopianf6679fc2010-08-10 18:09:09 -070042int32_t LayerBase::sSequence = 1;
43
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display)
45 : dpy(display), contentDirty(false),
Mathias Agopianf6679fc2010-08-10 18:09:09 -070046 sequence(uint32_t(android_atomic_inc(&sSequence))),
Mathias Agopiana67932f2011-04-20 14:20:59 -070047 mFlinger(flinger), mFiltering(false),
Mathias Agopiana2f4e562012-04-15 23:34:59 -070048 mNeedsFiltering(false),
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{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052}
53
54LayerBase::~LayerBase()
55{
56}
57
Mathias Agopiand1296592010-03-09 19:17:47 -080058void LayerBase::setName(const String8& name) {
59 mName = name;
60}
61
62String8 LayerBase::getName() const {
63 return mName;
64}
65
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags)
67{
68 uint32_t layerFlags = 0;
69 if (flags & ISurfaceComposer::eHidden)
70 layerFlags = ISurfaceComposer::eLayerHidden;
71
72 if (flags & ISurfaceComposer::eNonPremultiplied)
73 mPremultipliedAlpha = false;
74
Mathias Agopian93ffb862012-05-16 17:07:49 -070075 mCurrentState.active.w = w;
76 mCurrentState.active.h = h;
77 mCurrentState.active.crop.makeInvalid();
78 mCurrentState.z = 0;
79 mCurrentState.alpha = 0xFF;
80 mCurrentState.flags = layerFlags;
81 mCurrentState.sequence = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082 mCurrentState.transform.set(0, 0);
Mathias Agopian93ffb862012-05-16 17:07:49 -070083 mCurrentState.requested = mCurrentState.active;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084
85 // drawing state & current state are identical
86 mDrawingState = mCurrentState;
87}
88
Mathias Agopianba6be542009-09-29 22:32:36 -070089void LayerBase::commitTransaction() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090 mDrawingState = mCurrentState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091}
92void LayerBase::forceVisibilityTransaction() {
93 // this can be called without SurfaceFlinger.mStateLock, but if we
94 // can atomically increment the sequence number, it doesn't matter.
95 android_atomic_inc(&mCurrentState.sequence);
96 requestTransaction();
97}
98bool LayerBase::requestTransaction() {
99 int32_t old = setTransactionFlags(eTransactionNeeded);
100 return ((old & eTransactionNeeded) == 0);
101}
102uint32_t LayerBase::getTransactionFlags(uint32_t flags) {
103 return android_atomic_and(~flags, &mTransactionFlags) & flags;
104}
105uint32_t LayerBase::setTransactionFlags(uint32_t flags) {
106 return android_atomic_or(flags, &mTransactionFlags);
107}
108
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700109bool LayerBase::setPosition(float x, float y) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110 if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
111 return false;
112 mCurrentState.sequence++;
113 mCurrentState.transform.set(x, y);
114 requestTransaction();
115 return true;
116}
117bool LayerBase::setLayer(uint32_t z) {
118 if (mCurrentState.z == z)
119 return false;
120 mCurrentState.sequence++;
121 mCurrentState.z = z;
122 requestTransaction();
123 return true;
124}
125bool LayerBase::setSize(uint32_t w, uint32_t h) {
Mathias Agopian93ffb862012-05-16 17:07:49 -0700126 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800127 return false;
Mathias Agopian93ffb862012-05-16 17:07:49 -0700128 mCurrentState.requested.w = w;
129 mCurrentState.requested.h = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130 requestTransaction();
131 return true;
132}
133bool LayerBase::setAlpha(uint8_t alpha) {
134 if (mCurrentState.alpha == alpha)
135 return false;
136 mCurrentState.sequence++;
137 mCurrentState.alpha = alpha;
138 requestTransaction();
139 return true;
140}
141bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 mCurrentState.sequence++;
143 mCurrentState.transform.set(
144 matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
145 requestTransaction();
146 return true;
147}
148bool LayerBase::setTransparentRegionHint(const Region& transparent) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800149 mCurrentState.sequence++;
150 mCurrentState.transparentRegion = transparent;
151 requestTransaction();
152 return true;
153}
154bool LayerBase::setFlags(uint8_t flags, uint8_t mask) {
155 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
156 if (mCurrentState.flags == newFlags)
157 return false;
158 mCurrentState.sequence++;
159 mCurrentState.flags = newFlags;
160 requestTransaction();
161 return true;
162}
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700163bool LayerBase::setCrop(const Rect& crop) {
Mathias Agopianb30c4152012-05-16 18:21:32 -0700164 if (mCurrentState.requested.crop == crop)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700165 return false;
166 mCurrentState.sequence++;
Mathias Agopianb30c4152012-05-16 18:21:32 -0700167 mCurrentState.requested.crop = crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700168 requestTransaction();
169 return true;
170}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800171
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800172void LayerBase::setVisibleRegion(const Region& visibleRegion) {
173 // always called from main thread
Mathias Agopian4fec8732012-06-29 14:12:52 -0700174 this->visibleRegion = visibleRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800175}
176
177void LayerBase::setCoveredRegion(const Region& coveredRegion) {
178 // always called from main thread
Mathias Agopian4fec8732012-06-29 14:12:52 -0700179 this->coveredRegion = coveredRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800180}
181
182uint32_t LayerBase::doTransaction(uint32_t flags)
183{
184 const Layer::State& front(drawingState());
185 const Layer::State& temp(currentState());
186
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700187 // always set active to requested, unless we're asked not to
188 // this is used by Layer, which special cases resizes.
189 if (flags & eDontUpdateGeometryState) {
190 } else {
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700191 Layer::State& editTemp(currentState());
Mathias Agopianb30c4152012-05-16 18:21:32 -0700192 editTemp.active = temp.requested;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700193 }
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700194
Mathias Agopianb30c4152012-05-16 18:21:32 -0700195 if (front.active != temp.active) {
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700196 // invalidate and recompute the visible regions if needed
197 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700198 }
199
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800200 if (temp.sequence != front.sequence) {
201 // invalidate and recompute the visible regions if needed
202 flags |= eVisibleRegion;
203 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700204
Mathias Agopian733189d2010-12-02 21:32:29 -0800205 // we may use linear filtering, if the matrix scales us
206 const uint8_t type = temp.transform.getType();
207 mNeedsFiltering = (!temp.transform.preserveRects() ||
208 (type >= Transform::SCALE));
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700209 }
210
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800211 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700212 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800213 return flags;
214}
215
Mathias Agopian4fec8732012-06-29 14:12:52 -0700216void LayerBase::computeGeometry(const DisplayHardware& hw, LayerMesh* mesh) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800217{
218 const Layer::State& s(drawingState());
Mathias Agopian4fec8732012-06-29 14:12:52 -0700219 const Transform tr(hw.getTransform() * s.transform);
Mathias Agopianffcf4652011-07-07 17:30:31 -0700220 const uint32_t hw_h = hw.getHeight();
Mathias Agopian93ffb862012-05-16 17:07:49 -0700221 const Rect& crop(s.active.crop);
Mathias Agopian93ffb862012-05-16 17:07:49 -0700222 Rect win(s.active.w, s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700223 if (!crop.isEmpty()) {
224 win.intersect(crop, &win);
225 }
Mathias Agopian4fec8732012-06-29 14:12:52 -0700226 if (mesh) {
227 tr.transform(mesh->mVertices[0], win.left, win.top);
228 tr.transform(mesh->mVertices[1], win.left, win.bottom);
229 tr.transform(mesh->mVertices[2], win.right, win.bottom);
230 tr.transform(mesh->mVertices[3], win.right, win.top);
231 for (size_t i=0 ; i<4 ; i++) {
232 mesh->mVertices[i][1] = hw_h - mesh->mVertices[i][1];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800233 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800234 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800235}
236
Mathias Agopian4fec8732012-06-29 14:12:52 -0700237Rect LayerBase::computeBounds() const {
238 const Layer::State& s(drawingState());
239 const Rect& crop(s.active.crop);
240 Rect win(s.active.w, s.active.h);
241 if (!crop.isEmpty()) {
242 win.intersect(crop, &win);
243 }
244 return s.transform.transform(win);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800245}
246
Mathias Agopian4fec8732012-06-29 14:12:52 -0700247Region LayerBase::latchBuffer(bool& recomputeVisibleRegions) {
248 Region result;
249 return result;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800250}
251
Mathias Agopian4fec8732012-06-29 14:12:52 -0700252void LayerBase::setGeometry(
253 const DisplayHardware& hw,
254 HWComposer::HWCLayerInterface& layer)
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700255{
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700256 layer.setDefaultState();
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700257
258 // this gives us only the "orientation" component of the transform
259 const State& s(drawingState());
260 const uint32_t finalTransform = s.transform.getOrientation();
261 // we can only handle simple transformation
262 if (finalTransform & Transform::ROT_INVALID) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700263 layer.setTransform(0);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700264 } else {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700265 layer.setTransform(finalTransform);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700266 }
267
268 if (!isOpaque()) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700269 layer.setBlending(mPremultipliedAlpha ?
270 HWC_BLENDING_PREMULT :
271 HWC_BLENDING_COVERAGE);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700272 }
273
Mathias Agopian4fec8732012-06-29 14:12:52 -0700274 const Transform& tr = hw.getTransform();
275 Rect transformedBounds(computeBounds());
276 transformedBounds = tr.transform(transformedBounds);
277
278 // scaling is already applied in transformedBounds
279 layer.setFrame(transformedBounds);
280 layer.setCrop(transformedBounds.getBounds());
281 layer.setVisibleRegionScreen(tr.transform(visibleRegion));
Mathias Agopiana350ff92010-08-10 17:14:02 -0700282}
283
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700284void LayerBase::setPerFrameData(HWComposer::HWCLayerInterface& layer) {
285 layer.setBuffer(0);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700286}
287
Jesse Hallc5c5a142012-07-02 16:49:28 -0700288void LayerBase::setAcquireFence(HWComposer::HWCLayerInterface& layer) {
289 layer.setAcquireFenceFd(-1);
290}
291
Mathias Agopiana67932f2011-04-20 14:20:59 -0700292void LayerBase::setFiltering(bool filtering)
293{
294 mFiltering = filtering;
295}
296
297bool LayerBase::getFiltering() const
298{
299 return mFiltering;
300}
301
Mathias Agopian1b031492012-06-20 17:51:20 -0700302void LayerBase::draw(const DisplayHardware& hw, const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800303{
Mathias Agopian1b031492012-06-20 17:51:20 -0700304 onDraw(hw, clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800305}
306
Mathias Agopian1b031492012-06-20 17:51:20 -0700307void LayerBase::drawForSreenShot(const DisplayHardware& hw)
Mathias Agopian74c40c02010-09-29 13:02:36 -0700308{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700309 setFiltering(true);
Mathias Agopian1b031492012-06-20 17:51:20 -0700310 onDraw( hw, Region(hw.bounds()) );
Mathias Agopiana67932f2011-04-20 14:20:59 -0700311 setFiltering(false);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700312}
313
Mathias Agopian1b031492012-06-20 17:51:20 -0700314void LayerBase::clearWithOpenGL(const DisplayHardware& hw, const Region& clip,
315 GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800316{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800317 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700318 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700319
Mathias Agopianc492e672011-10-18 14:49:27 -0700320 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700321 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800322 glDisable(GL_BLEND);
Mathias Agopian20f68782009-05-11 00:03:41 -0700323
Mathias Agopian4fec8732012-06-29 14:12:52 -0700324 LayerMesh mesh;
325 computeGeometry(hw, &mesh);
326
327 glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
328 glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800329}
330
Mathias Agopian1b031492012-06-20 17:51:20 -0700331void LayerBase::clearWithOpenGL(const DisplayHardware& hw, const Region& clip) const
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700332{
Mathias Agopian1b031492012-06-20 17:51:20 -0700333 clearWithOpenGL(hw, clip, 0,0,0,0);
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700334}
335
Mathias Agopian1b031492012-06-20 17:51:20 -0700336void LayerBase::drawWithOpenGL(const DisplayHardware& hw, 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 const uint32_t fbHeight = hw.getHeight();
339 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800340
Mathias Agopian49753262010-04-12 15:34:55 -0700341 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800342 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700343 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700344 if (mPremultipliedAlpha) {
345 glColor4f(alpha, alpha, alpha, alpha);
346 } else {
347 glColor4f(1, 1, 1, alpha);
348 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800349 glEnable(GL_BLEND);
350 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700351 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800352 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700353 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700354 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700355 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800356 glEnable(GL_BLEND);
357 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
358 } else {
359 glDisable(GL_BLEND);
360 }
361 }
362
Mathias Agopian4fec8732012-06-29 14:12:52 -0700363 LayerMesh mesh;
364 computeGeometry(hw, &mesh);
365
366 // TODO: we probably want to generate the texture coords with the mesh
367 // here we assume that we only have 4 vertices
368
Mathias Agopianb661d662010-08-19 17:01:19 -0700369 struct TexCoords {
370 GLfloat u;
371 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700372 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373
Mathias Agopian93ffb862012-05-16 17:07:49 -0700374 Rect crop(s.active.w, s.active.h);
375 if (!s.active.crop.isEmpty()) {
376 crop = s.active.crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700377 }
Mathias Agopian4fec8732012-06-29 14:12:52 -0700378 GLfloat left = GLfloat(crop.left) / GLfloat(s.active.w);
379 GLfloat top = GLfloat(crop.top) / GLfloat(s.active.h);
380 GLfloat right = GLfloat(crop.right) / GLfloat(s.active.w);
Mathias Agopian93ffb862012-05-16 17:07:49 -0700381 GLfloat bottom = GLfloat(crop.bottom) / GLfloat(s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700382
Mathias Agopianb661d662010-08-19 17:01:19 -0700383 TexCoords texCoords[4];
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700384 texCoords[0].u = left;
385 texCoords[0].v = top;
386 texCoords[1].u = left;
387 texCoords[1].v = bottom;
388 texCoords[2].u = right;
389 texCoords[2].v = bottom;
390 texCoords[3].u = right;
391 texCoords[3].v = top;
392 for (int i = 0; i < 4; i++) {
393 texCoords[i].v = 1.0f - texCoords[i].v;
394 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700395
396 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700397 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
Mathias Agopian4fec8732012-06-29 14:12:52 -0700398 glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
399 glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
Mathias Agopian78fd5012010-04-20 14:51:04 -0700400
Mathias Agopian78fd5012010-04-20 14:51:04 -0700401 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700402 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800403}
404
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700405void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
406{
407 const Layer::State& s(drawingState());
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800408
409 snprintf(buffer, SIZE,
410 "+ %s %p (%s)\n",
411 getTypeId(), this, getName().string());
412 result.append(buffer);
413
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800414 s.transparentRegion.dump(result, "transparentRegion");
Mathias Agopian4fec8732012-06-29 14:12:52 -0700415 visibleRegion.dump(result, "visibleRegion");
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800416
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700417 snprintf(buffer, SIZE,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700418 " "
Mathias Agopian93ffb862012-05-16 17:07:49 -0700419 "z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700420 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700421 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian93ffb862012-05-16 17:07:49 -0700422 s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
423 s.active.crop.left, s.active.crop.top,
424 s.active.crop.right, s.active.crop.bottom,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700425 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700426 s.alpha, s.flags,
427 s.transform[0][0], s.transform[0][1],
428 s.transform[1][0], s.transform[1][1]);
429 result.append(buffer);
430}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700431
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800432void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800433 LayerBase::dump(result, scratch, size);
434}
435
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800436void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
437}
438
439void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800440}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800441
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700442sp<LayerBaseClient> LayerBase::getLayerBaseClient() const {
443 return 0;
444}
445
446sp<Layer> LayerBase::getLayer() const {
447 return 0;
448}
449
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800450// ---------------------------------------------------------------------------
451
Mathias Agopian631f3582010-05-25 17:51:34 -0700452int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700453
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800454LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700455 const sp<Client>& client)
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800456 : LayerBase(flinger, display),
457 mHasSurface(false),
458 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800459 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800460{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700461}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800462
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800463LayerBaseClient::~LayerBaseClient()
464{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700465 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700466 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700467 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800468 }
469}
470
Mathias Agopiana67932f2011-04-20 14:20:59 -0700471sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800472{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700473 class BSurface : public BnSurface, public LayerCleaner {
474 virtual sp<ISurfaceTexture> getSurfaceTexture() const { return 0; }
475 public:
476 BSurface(const sp<SurfaceFlinger>& flinger,
477 const sp<LayerBaseClient>& layer)
478 : LayerCleaner(flinger, layer) { }
479 };
480 sp<ISurface> sur(new BSurface(mFlinger, this));
481 return sur;
482}
483
484sp<ISurface> LayerBaseClient::getSurface()
485{
486 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700487 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800488
489 LOG_ALWAYS_FATAL_IF(mHasSurface,
490 "LayerBaseClient::getSurface() has already been called");
491
492 mHasSurface = true;
493 s = createSurface();
494 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700495 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800496}
497
Mathias Agopian0d156122011-01-25 20:17:45 -0800498wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
499 return mClientSurfaceBinder;
500}
501
Jamie Gennis582270d2011-08-17 18:19:00 -0700502wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
503 return 0;
504}
505
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700506void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
507{
508 LayerBase::dump(result, buffer, SIZE);
509
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700510 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700511 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700512 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700513 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700514
515 result.append(buffer);
516}
517
Mathias Agopian48b888a2011-01-19 16:15:53 -0800518
519void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
520{
521 LayerBaseClient::dump(result, scratch, size);
522}
523
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700524// ---------------------------------------------------------------------------
525
Mathias Agopiana67932f2011-04-20 14:20:59 -0700526LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
527 const sp<LayerBaseClient>& layer)
528 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700529}
530
Mathias Agopiana67932f2011-04-20 14:20:59 -0700531LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700532 // destroy client resources
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700533 mFlinger->onLayerDestroyed(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700534}
535
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800536// ---------------------------------------------------------------------------
537
538}; // namespace android