blob: a2513a2c0c2929cb94c41c1583a916b68aec2a03 [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 Agopian0f2f5ff2012-07-31 23:09:07 -070036#include "DisplayDevice.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
Mathias Agopian3ee454a2012-08-27 16:28:24 -070044LayerBase::LayerBase(SurfaceFlinger* flinger)
45 : 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;
Mathias Agopian3165cc22012-08-08 19:42:09 -070069 if (flags & ISurfaceComposerClient::eHidden)
70 layerFlags = layer_state_t::eLayerHidden;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071
Mathias Agopian3165cc22012-08-08 19:42:09 -070072 if (flags & ISurfaceComposerClient::eNonPremultiplied)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073 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;
Mathias Agopian87855782012-07-24 21:41:09 -070080 mCurrentState.layerStack = 0;
Mathias Agopian93ffb862012-05-16 17:07:49 -070081 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
Mathias Agopian87855782012-07-24 21:41:09 -0700173bool LayerBase::setLayerStack(uint32_t layerStack) {
174 if (mCurrentState.layerStack == layerStack)
175 return false;
176 mCurrentState.sequence++;
177 mCurrentState.layerStack = layerStack;
178 requestTransaction();
179 return true;
180}
181
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800182void LayerBase::setVisibleRegion(const Region& visibleRegion) {
183 // always called from main thread
Mathias Agopian4fec8732012-06-29 14:12:52 -0700184 this->visibleRegion = visibleRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800185}
186
187void LayerBase::setCoveredRegion(const Region& coveredRegion) {
188 // always called from main thread
Mathias Agopian4fec8732012-06-29 14:12:52 -0700189 this->coveredRegion = coveredRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800190}
191
192uint32_t LayerBase::doTransaction(uint32_t flags)
193{
194 const Layer::State& front(drawingState());
195 const Layer::State& temp(currentState());
196
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700197 // always set active to requested, unless we're asked not to
198 // this is used by Layer, which special cases resizes.
199 if (flags & eDontUpdateGeometryState) {
200 } else {
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700201 Layer::State& editTemp(currentState());
Mathias Agopianb30c4152012-05-16 18:21:32 -0700202 editTemp.active = temp.requested;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700203 }
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700204
Mathias Agopianb30c4152012-05-16 18:21:32 -0700205 if (front.active != temp.active) {
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700206 // invalidate and recompute the visible regions if needed
207 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700208 }
209
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800210 if (temp.sequence != front.sequence) {
211 // invalidate and recompute the visible regions if needed
212 flags |= eVisibleRegion;
213 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700214
Mathias Agopian733189d2010-12-02 21:32:29 -0800215 // we may use linear filtering, if the matrix scales us
216 const uint8_t type = temp.transform.getType();
217 mNeedsFiltering = (!temp.transform.preserveRects() ||
218 (type >= Transform::SCALE));
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700219 }
220
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800221 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700222 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800223 return flags;
224}
225
Mathias Agopian42977342012-08-05 00:40:46 -0700226void LayerBase::computeGeometry(const sp<const DisplayDevice>& hw, LayerMesh* mesh) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800227{
228 const Layer::State& s(drawingState());
Mathias Agopian42977342012-08-05 00:40:46 -0700229 const Transform tr(hw->getTransform() * s.transform);
230 const uint32_t hw_h = hw->getHeight();
Mathias Agopian93ffb862012-05-16 17:07:49 -0700231 const Rect& crop(s.active.crop);
Mathias Agopian93ffb862012-05-16 17:07:49 -0700232 Rect win(s.active.w, s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700233 if (!crop.isEmpty()) {
234 win.intersect(crop, &win);
235 }
Mathias Agopian4fec8732012-06-29 14:12:52 -0700236 if (mesh) {
237 tr.transform(mesh->mVertices[0], win.left, win.top);
238 tr.transform(mesh->mVertices[1], win.left, win.bottom);
239 tr.transform(mesh->mVertices[2], win.right, win.bottom);
240 tr.transform(mesh->mVertices[3], win.right, win.top);
241 for (size_t i=0 ; i<4 ; i++) {
242 mesh->mVertices[i][1] = hw_h - mesh->mVertices[i][1];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800243 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800244 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800245}
246
Mathias Agopian4fec8732012-06-29 14:12:52 -0700247Rect LayerBase::computeBounds() const {
248 const Layer::State& s(drawingState());
249 const Rect& crop(s.active.crop);
250 Rect win(s.active.w, s.active.h);
251 if (!crop.isEmpty()) {
252 win.intersect(crop, &win);
253 }
254 return s.transform.transform(win);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800255}
256
Mathias Agopian4fec8732012-06-29 14:12:52 -0700257Region LayerBase::latchBuffer(bool& recomputeVisibleRegions) {
258 Region result;
259 return result;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800260}
261
Mathias Agopian4fec8732012-06-29 14:12:52 -0700262void LayerBase::setGeometry(
Mathias Agopian42977342012-08-05 00:40:46 -0700263 const sp<const DisplayDevice>& hw,
Mathias Agopian4fec8732012-06-29 14:12:52 -0700264 HWComposer::HWCLayerInterface& layer)
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700265{
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700266 layer.setDefaultState();
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700267
268 // this gives us only the "orientation" component of the transform
269 const State& s(drawingState());
270 const uint32_t finalTransform = s.transform.getOrientation();
271 // we can only handle simple transformation
272 if (finalTransform & Transform::ROT_INVALID) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700273 layer.setTransform(0);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700274 } else {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700275 layer.setTransform(finalTransform);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700276 }
277
278 if (!isOpaque()) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700279 layer.setBlending(mPremultipliedAlpha ?
280 HWC_BLENDING_PREMULT :
281 HWC_BLENDING_COVERAGE);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700282 }
283
Mathias Agopian42977342012-08-05 00:40:46 -0700284 const Transform& tr = hw->getTransform();
Mathias Agopian4fec8732012-06-29 14:12:52 -0700285 Rect transformedBounds(computeBounds());
286 transformedBounds = tr.transform(transformedBounds);
287
288 // scaling is already applied in transformedBounds
289 layer.setFrame(transformedBounds);
290 layer.setCrop(transformedBounds.getBounds());
291 layer.setVisibleRegionScreen(tr.transform(visibleRegion));
Mathias Agopiana350ff92010-08-10 17:14:02 -0700292}
293
Mathias Agopian42977342012-08-05 00:40:46 -0700294void LayerBase::setPerFrameData(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700295 HWComposer::HWCLayerInterface& layer) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700296 layer.setBuffer(0);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700297}
298
Mathias Agopian42977342012-08-05 00:40:46 -0700299void LayerBase::setAcquireFence(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700300 HWComposer::HWCLayerInterface& layer) {
Jesse Hallc5c5a142012-07-02 16:49:28 -0700301 layer.setAcquireFenceFd(-1);
302}
303
Mathias Agopiana67932f2011-04-20 14:20:59 -0700304void LayerBase::setFiltering(bool filtering)
305{
306 mFiltering = filtering;
307}
308
309bool LayerBase::getFiltering() const
310{
311 return mFiltering;
312}
313
Mathias Agopian42977342012-08-05 00:40:46 -0700314void LayerBase::draw(const sp<const DisplayDevice>& hw, const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800315{
Mathias Agopian1b031492012-06-20 17:51:20 -0700316 onDraw(hw, clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800317}
318
Mathias Agopian42977342012-08-05 00:40:46 -0700319void LayerBase::draw(const sp<const DisplayDevice>& hw)
Mathias Agopian74c40c02010-09-29 13:02:36 -0700320{
Mathias Agopian42977342012-08-05 00:40:46 -0700321 onDraw( hw, Region(hw->bounds()) );
Mathias Agopian74c40c02010-09-29 13:02:36 -0700322}
323
Mathias Agopian42977342012-08-05 00:40:46 -0700324void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip,
Mathias Agopian1b031492012-06-20 17:51:20 -0700325 GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800326{
Mathias Agopian42977342012-08-05 00:40:46 -0700327 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 Agopian4fec8732012-06-29 14:12:52 -0700334 LayerMesh mesh;
335 computeGeometry(hw, &mesh);
336
337 glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
338 glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339}
340
Mathias Agopian42977342012-08-05 00:40:46 -0700341void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700342{
Mathias Agopian1b031492012-06-20 17:51:20 -0700343 clearWithOpenGL(hw, clip, 0,0,0,0);
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700344}
345
Mathias Agopian42977342012-08-05 00:40:46 -0700346void LayerBase::drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800347{
Mathias Agopian42977342012-08-05 00:40:46 -0700348 const uint32_t fbHeight = hw->getHeight();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800349 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800350
Mathias Agopian49753262010-04-12 15:34:55 -0700351 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800352 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700353 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700354 if (mPremultipliedAlpha) {
355 glColor4f(alpha, alpha, alpha, alpha);
356 } else {
357 glColor4f(1, 1, 1, alpha);
358 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800359 glEnable(GL_BLEND);
360 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700361 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800362 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700363 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700364 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700365 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800366 glEnable(GL_BLEND);
367 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
368 } else {
369 glDisable(GL_BLEND);
370 }
371 }
372
Mathias Agopian4fec8732012-06-29 14:12:52 -0700373 LayerMesh mesh;
374 computeGeometry(hw, &mesh);
375
376 // TODO: we probably want to generate the texture coords with the mesh
377 // here we assume that we only have 4 vertices
378
Mathias Agopianb661d662010-08-19 17:01:19 -0700379 struct TexCoords {
380 GLfloat u;
381 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700382 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800383
Mathias Agopian93ffb862012-05-16 17:07:49 -0700384 Rect crop(s.active.w, s.active.h);
385 if (!s.active.crop.isEmpty()) {
386 crop = s.active.crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700387 }
Mathias Agopian4fec8732012-06-29 14:12:52 -0700388 GLfloat left = GLfloat(crop.left) / GLfloat(s.active.w);
389 GLfloat top = GLfloat(crop.top) / GLfloat(s.active.h);
390 GLfloat right = GLfloat(crop.right) / GLfloat(s.active.w);
Mathias Agopian93ffb862012-05-16 17:07:49 -0700391 GLfloat bottom = GLfloat(crop.bottom) / GLfloat(s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700392
Mathias Agopianb661d662010-08-19 17:01:19 -0700393 TexCoords texCoords[4];
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700394 texCoords[0].u = left;
395 texCoords[0].v = top;
396 texCoords[1].u = left;
397 texCoords[1].v = bottom;
398 texCoords[2].u = right;
399 texCoords[2].v = bottom;
400 texCoords[3].u = right;
401 texCoords[3].v = top;
402 for (int i = 0; i < 4; i++) {
403 texCoords[i].v = 1.0f - texCoords[i].v;
404 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700405
406 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700407 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
Mathias Agopian4fec8732012-06-29 14:12:52 -0700408 glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
409 glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
Mathias Agopian78fd5012010-04-20 14:51:04 -0700410
Mathias Agopian78fd5012010-04-20 14:51:04 -0700411 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700412 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800413}
414
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700415void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
416{
417 const Layer::State& s(drawingState());
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800418
419 snprintf(buffer, SIZE,
420 "+ %s %p (%s)\n",
421 getTypeId(), this, getName().string());
422 result.append(buffer);
423
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800424 s.transparentRegion.dump(result, "transparentRegion");
Mathias Agopian4fec8732012-06-29 14:12:52 -0700425 visibleRegion.dump(result, "visibleRegion");
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800426
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700427 snprintf(buffer, SIZE,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700428 " "
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700429 "layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700430 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700431 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700432 s.z, s.layerStack, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
Mathias Agopian93ffb862012-05-16 17:07:49 -0700433 s.active.crop.left, s.active.crop.top,
434 s.active.crop.right, s.active.crop.bottom,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700435 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700436 s.alpha, s.flags,
437 s.transform[0][0], s.transform[0][1],
438 s.transform[1][0], s.transform[1][1]);
439 result.append(buffer);
440}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700441
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800442void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800443 LayerBase::dump(result, scratch, size);
444}
445
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800446void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
447}
448
449void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800450}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800451
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700452sp<LayerBaseClient> LayerBase::getLayerBaseClient() const {
453 return 0;
454}
455
456sp<Layer> LayerBase::getLayer() const {
457 return 0;
458}
459
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
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700464LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger,
Mathias Agopian96f08192010-06-02 23:28:45 -0700465 const sp<Client>& client)
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700466 : LayerBase(flinger),
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800467 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 Agopian921e6ac2012-07-23 23:11:29 -0700543 mFlinger->onLayerDestroyed(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