blob: 31ef941749cd3a8c2b6286d220400cb819599989 [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 Agopianeba8c682012-09-19 23:14:45 -070090bool LayerBase::needsFiltering(const sp<const DisplayDevice>& hw) const {
91 return mNeedsFiltering || hw->needsFiltering();
92}
93
Mathias Agopianba6be542009-09-29 22:32:36 -070094void LayerBase::commitTransaction() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095 mDrawingState = mCurrentState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096}
97void LayerBase::forceVisibilityTransaction() {
98 // this can be called without SurfaceFlinger.mStateLock, but if we
99 // can atomically increment the sequence number, it doesn't matter.
100 android_atomic_inc(&mCurrentState.sequence);
101 requestTransaction();
102}
103bool LayerBase::requestTransaction() {
104 int32_t old = setTransactionFlags(eTransactionNeeded);
105 return ((old & eTransactionNeeded) == 0);
106}
107uint32_t LayerBase::getTransactionFlags(uint32_t flags) {
108 return android_atomic_and(~flags, &mTransactionFlags) & flags;
109}
110uint32_t LayerBase::setTransactionFlags(uint32_t flags) {
111 return android_atomic_or(flags, &mTransactionFlags);
112}
113
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700114bool LayerBase::setPosition(float x, float y) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800115 if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
116 return false;
117 mCurrentState.sequence++;
118 mCurrentState.transform.set(x, y);
119 requestTransaction();
120 return true;
121}
122bool LayerBase::setLayer(uint32_t z) {
123 if (mCurrentState.z == z)
124 return false;
125 mCurrentState.sequence++;
126 mCurrentState.z = z;
127 requestTransaction();
128 return true;
129}
130bool LayerBase::setSize(uint32_t w, uint32_t h) {
Mathias Agopian93ffb862012-05-16 17:07:49 -0700131 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800132 return false;
Mathias Agopian93ffb862012-05-16 17:07:49 -0700133 mCurrentState.requested.w = w;
134 mCurrentState.requested.h = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135 requestTransaction();
136 return true;
137}
138bool LayerBase::setAlpha(uint8_t alpha) {
139 if (mCurrentState.alpha == alpha)
140 return false;
141 mCurrentState.sequence++;
142 mCurrentState.alpha = alpha;
143 requestTransaction();
144 return true;
145}
146bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800147 mCurrentState.sequence++;
148 mCurrentState.transform.set(
149 matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
150 requestTransaction();
151 return true;
152}
153bool LayerBase::setTransparentRegionHint(const Region& transparent) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800154 mCurrentState.sequence++;
155 mCurrentState.transparentRegion = transparent;
156 requestTransaction();
157 return true;
158}
159bool LayerBase::setFlags(uint8_t flags, uint8_t mask) {
160 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
161 if (mCurrentState.flags == newFlags)
162 return false;
163 mCurrentState.sequence++;
164 mCurrentState.flags = newFlags;
165 requestTransaction();
166 return true;
167}
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700168bool LayerBase::setCrop(const Rect& crop) {
Mathias Agopianb30c4152012-05-16 18:21:32 -0700169 if (mCurrentState.requested.crop == crop)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700170 return false;
171 mCurrentState.sequence++;
Mathias Agopianb30c4152012-05-16 18:21:32 -0700172 mCurrentState.requested.crop = crop;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700173 requestTransaction();
174 return true;
175}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800176
Mathias Agopian87855782012-07-24 21:41:09 -0700177bool LayerBase::setLayerStack(uint32_t layerStack) {
178 if (mCurrentState.layerStack == layerStack)
179 return false;
180 mCurrentState.sequence++;
181 mCurrentState.layerStack = layerStack;
182 requestTransaction();
183 return true;
184}
185
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800186void LayerBase::setVisibleRegion(const Region& visibleRegion) {
187 // always called from main thread
Mathias Agopian4fec8732012-06-29 14:12:52 -0700188 this->visibleRegion = visibleRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800189}
190
191void LayerBase::setCoveredRegion(const Region& coveredRegion) {
192 // always called from main thread
Mathias Agopian4fec8732012-06-29 14:12:52 -0700193 this->coveredRegion = coveredRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800194}
195
Jesse Halla8026d22012-09-25 13:25:04 -0700196void LayerBase::setVisibleNonTransparentRegion(const Region&
197 setVisibleNonTransparentRegion) {
198 // always called from main thread
199 this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
200}
201
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800202uint32_t LayerBase::doTransaction(uint32_t flags)
203{
204 const Layer::State& front(drawingState());
205 const Layer::State& temp(currentState());
206
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700207 // always set active to requested, unless we're asked not to
208 // this is used by Layer, which special cases resizes.
209 if (flags & eDontUpdateGeometryState) {
210 } else {
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700211 Layer::State& editTemp(currentState());
Mathias Agopianb30c4152012-05-16 18:21:32 -0700212 editTemp.active = temp.requested;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700213 }
Mathias Agopian05cec9d2012-05-23 14:35:49 -0700214
Mathias Agopianb30c4152012-05-16 18:21:32 -0700215 if (front.active != temp.active) {
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700216 // invalidate and recompute the visible regions if needed
217 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700218 }
219
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800220 if (temp.sequence != front.sequence) {
221 // invalidate and recompute the visible regions if needed
222 flags |= eVisibleRegion;
223 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700224
Mathias Agopian733189d2010-12-02 21:32:29 -0800225 // we may use linear filtering, if the matrix scales us
226 const uint8_t type = temp.transform.getType();
227 mNeedsFiltering = (!temp.transform.preserveRects() ||
228 (type >= Transform::SCALE));
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700229 }
230
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800231 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700232 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800233 return flags;
234}
235
Mathias Agopian42977342012-08-05 00:40:46 -0700236void LayerBase::computeGeometry(const sp<const DisplayDevice>& hw, LayerMesh* mesh) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800237{
238 const Layer::State& s(drawingState());
Mathias Agopian42977342012-08-05 00:40:46 -0700239 const Transform tr(hw->getTransform() * s.transform);
240 const uint32_t hw_h = hw->getHeight();
Mathias Agopian93ffb862012-05-16 17:07:49 -0700241 Rect win(s.active.w, s.active.h);
Mathias Agopiana046dd92012-09-24 22:01:01 -0700242 if (!s.active.crop.isEmpty()) {
243 win.intersect(s.active.crop, &win);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700244 }
Mathias Agopian4fec8732012-06-29 14:12:52 -0700245 if (mesh) {
246 tr.transform(mesh->mVertices[0], win.left, win.top);
247 tr.transform(mesh->mVertices[1], win.left, win.bottom);
248 tr.transform(mesh->mVertices[2], win.right, win.bottom);
249 tr.transform(mesh->mVertices[3], win.right, win.top);
250 for (size_t i=0 ; i<4 ; i++) {
251 mesh->mVertices[i][1] = hw_h - mesh->mVertices[i][1];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800252 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800253 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800254}
255
Mathias Agopian4fec8732012-06-29 14:12:52 -0700256Rect LayerBase::computeBounds() const {
257 const Layer::State& s(drawingState());
Mathias Agopian4fec8732012-06-29 14:12:52 -0700258 Rect win(s.active.w, s.active.h);
Mathias Agopiana046dd92012-09-24 22:01:01 -0700259 if (!s.active.crop.isEmpty()) {
260 win.intersect(s.active.crop, &win);
Mathias Agopian4fec8732012-06-29 14:12:52 -0700261 }
262 return s.transform.transform(win);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800263}
264
Mathias Agopian4fec8732012-06-29 14:12:52 -0700265Region LayerBase::latchBuffer(bool& recomputeVisibleRegions) {
266 Region result;
267 return result;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800268}
269
Mathias Agopian4fec8732012-06-29 14:12:52 -0700270void LayerBase::setGeometry(
Mathias Agopian42977342012-08-05 00:40:46 -0700271 const sp<const DisplayDevice>& hw,
Mathias Agopian4fec8732012-06-29 14:12:52 -0700272 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
Mathias Agopian42977342012-08-05 00:40:46 -0700292 const Transform& tr = hw->getTransform();
Mathias Agopian4fec8732012-06-29 14:12:52 -0700293 Rect transformedBounds(computeBounds());
294 transformedBounds = tr.transform(transformedBounds);
295
296 // scaling is already applied in transformedBounds
297 layer.setFrame(transformedBounds);
298 layer.setCrop(transformedBounds.getBounds());
Mathias Agopiana350ff92010-08-10 17:14:02 -0700299}
300
Mathias Agopian42977342012-08-05 00:40:46 -0700301void LayerBase::setPerFrameData(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700302 HWComposer::HWCLayerInterface& layer) {
Mathias Agopianee932d02012-11-14 14:41:42 -0800303 layer.setPerFrameDefaultState();
Mathias Agopianc3973602012-08-31 17:51:25 -0700304 // we have to set the visible region on every frame because
305 // we currently free it during onLayerDisplayed(), which is called
306 // after HWComposer::commit() -- every frame.
307 const Transform& tr = hw->getTransform();
308 layer.setVisibleRegionScreen(tr.transform(visibleRegion));
Mathias Agopiana350ff92010-08-10 17:14:02 -0700309}
310
Mathias Agopian42977342012-08-05 00:40:46 -0700311void LayerBase::setAcquireFence(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700312 HWComposer::HWCLayerInterface& layer) {
Jesse Hallc5c5a142012-07-02 16:49:28 -0700313 layer.setAcquireFenceFd(-1);
314}
315
Mathias Agopianc3973602012-08-31 17:51:25 -0700316void LayerBase::onLayerDisplayed(const sp<const DisplayDevice>& hw,
317 HWComposer::HWCLayerInterface* layer) {
318 if (layer) {
319 layer->onDisplayed();
320 }
321}
322
Mathias Agopiana67932f2011-04-20 14:20:59 -0700323void LayerBase::setFiltering(bool filtering)
324{
325 mFiltering = filtering;
326}
327
328bool LayerBase::getFiltering() const
329{
330 return mFiltering;
331}
332
Mathias Agopianda27af92012-09-13 18:17:13 -0700333bool LayerBase::isVisible() const {
334 const Layer::State& s(mDrawingState);
335 return !(s.flags & layer_state_t::eLayerHidden) && s.alpha;
336}
337
Mathias Agopian42977342012-08-05 00:40:46 -0700338void LayerBase::draw(const sp<const DisplayDevice>& hw, const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339{
Mathias Agopian1b031492012-06-20 17:51:20 -0700340 onDraw(hw, clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800341}
342
Mathias Agopian42977342012-08-05 00:40:46 -0700343void LayerBase::draw(const sp<const DisplayDevice>& hw)
Mathias Agopian74c40c02010-09-29 13:02:36 -0700344{
Mathias Agopian42977342012-08-05 00:40:46 -0700345 onDraw( hw, Region(hw->bounds()) );
Mathias Agopian74c40c02010-09-29 13:02:36 -0700346}
347
Mathias Agopian42977342012-08-05 00:40:46 -0700348void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip,
Mathias Agopian1b031492012-06-20 17:51:20 -0700349 GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800350{
Mathias Agopian42977342012-08-05 00:40:46 -0700351 const uint32_t fbHeight = hw->getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700352 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700353
Mathias Agopianc492e672011-10-18 14:49:27 -0700354 glDisable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700355 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800356 glDisable(GL_BLEND);
Mathias Agopian20f68782009-05-11 00:03:41 -0700357
Mathias Agopian4fec8732012-06-29 14:12:52 -0700358 LayerMesh mesh;
359 computeGeometry(hw, &mesh);
360
361 glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
362 glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800363}
364
Mathias Agopian42977342012-08-05 00:40:46 -0700365void LayerBase::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700366{
Mathias Agopian1b031492012-06-20 17:51:20 -0700367 clearWithOpenGL(hw, clip, 0,0,0,0);
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700368}
369
Mathias Agopian42977342012-08-05 00:40:46 -0700370void LayerBase::drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800371{
Mathias Agopian42977342012-08-05 00:40:46 -0700372 const uint32_t fbHeight = hw->getHeight();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373 const State& s(drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800374
Mathias Agopian49753262010-04-12 15:34:55 -0700375 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
Glenn Kasten99ed2242011-12-15 09:51:17 -0800376 if (CC_UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700377 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700378 if (mPremultipliedAlpha) {
379 glColor4f(alpha, alpha, alpha, alpha);
380 } else {
381 glColor4f(1, 1, 1, alpha);
382 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800383 glEnable(GL_BLEND);
384 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700385 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800386 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700387 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700388 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700389 if (!isOpaque()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800390 glEnable(GL_BLEND);
391 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
392 } else {
393 glDisable(GL_BLEND);
394 }
395 }
396
Mathias Agopian4fec8732012-06-29 14:12:52 -0700397 LayerMesh mesh;
398 computeGeometry(hw, &mesh);
399
400 // TODO: we probably want to generate the texture coords with the mesh
401 // here we assume that we only have 4 vertices
402
Mathias Agopianb661d662010-08-19 17:01:19 -0700403 struct TexCoords {
404 GLfloat u;
405 GLfloat v;
Mathias Agopian78fd5012010-04-20 14:51:04 -0700406 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800407
Mathias Agopiana046dd92012-09-24 22:01:01 -0700408 Rect win(s.active.w, s.active.h);
Mathias Agopian93ffb862012-05-16 17:07:49 -0700409 if (!s.active.crop.isEmpty()) {
Mathias Agopiana046dd92012-09-24 22:01:01 -0700410 win.intersect(s.active.crop, &win);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700411 }
Mathias Agopiana046dd92012-09-24 22:01:01 -0700412
413 GLfloat left = GLfloat(win.left) / GLfloat(s.active.w);
414 GLfloat top = GLfloat(win.top) / GLfloat(s.active.h);
415 GLfloat right = GLfloat(win.right) / GLfloat(s.active.w);
416 GLfloat bottom = GLfloat(win.bottom) / GLfloat(s.active.h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700417
Mathias Agopianb661d662010-08-19 17:01:19 -0700418 TexCoords texCoords[4];
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700419 texCoords[0].u = left;
420 texCoords[0].v = top;
421 texCoords[1].u = left;
422 texCoords[1].v = bottom;
423 texCoords[2].u = right;
424 texCoords[2].v = bottom;
425 texCoords[3].u = right;
426 texCoords[3].v = top;
427 for (int i = 0; i < 4; i++) {
428 texCoords[i].v = 1.0f - texCoords[i].v;
429 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700430
431 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700432 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
Mathias Agopian4fec8732012-06-29 14:12:52 -0700433 glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
434 glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
Mathias Agopian78fd5012010-04-20 14:51:04 -0700435
Mathias Agopian78fd5012010-04-20 14:51:04 -0700436 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopianc492e672011-10-18 14:49:27 -0700437 glDisable(GL_BLEND);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800438}
439
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700440void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
441{
442 const Layer::State& s(drawingState());
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800443
444 snprintf(buffer, SIZE,
445 "+ %s %p (%s)\n",
446 getTypeId(), this, getName().string());
447 result.append(buffer);
448
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800449 s.transparentRegion.dump(result, "transparentRegion");
Mathias Agopian4fec8732012-06-29 14:12:52 -0700450 visibleRegion.dump(result, "visibleRegion");
Mathias Agopianc95dbdc2012-02-05 00:19:27 -0800451
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700452 snprintf(buffer, SIZE,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700453 " "
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700454 "layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), crop=(%4d,%4d,%4d,%4d), "
Mathias Agopiana67932f2011-04-20 14:20:59 -0700455 "isOpaque=%1d, needsDithering=%1d, invalidate=%1d, "
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700456 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian791da602012-09-11 20:52:46 -0700457 s.layerStack, s.z, s.transform.tx(), s.transform.ty(), s.active.w, s.active.h,
Mathias Agopian93ffb862012-05-16 17:07:49 -0700458 s.active.crop.left, s.active.crop.top,
459 s.active.crop.right, s.active.crop.bottom,
Mathias Agopiana67932f2011-04-20 14:20:59 -0700460 isOpaque(), needsDithering(), contentDirty,
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700461 s.alpha, s.flags,
462 s.transform[0][0], s.transform[0][1],
463 s.transform[1][0], s.transform[1][1]);
464 result.append(buffer);
465}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700466
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800467void LayerBase::shortDump(String8& result, char* scratch, size_t size) const {
Mathias Agopian48b888a2011-01-19 16:15:53 -0800468 LayerBase::dump(result, scratch, size);
469}
470
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800471void LayerBase::dumpStats(String8& result, char* scratch, size_t SIZE) const {
472}
473
474void LayerBase::clearStats() {
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800475}
Mathias Agopian48b888a2011-01-19 16:15:53 -0800476
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700477sp<LayerBaseClient> LayerBase::getLayerBaseClient() const {
478 return 0;
479}
480
481sp<Layer> LayerBase::getLayer() const {
482 return 0;
483}
484
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800485// ---------------------------------------------------------------------------
486
Mathias Agopian631f3582010-05-25 17:51:34 -0700487int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700488
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700489LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger,
Mathias Agopian96f08192010-06-02 23:28:45 -0700490 const sp<Client>& client)
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700491 : LayerBase(flinger),
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800492 mHasSurface(false),
493 mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800494 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800495{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700496}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800497
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800498LayerBaseClient::~LayerBaseClient()
499{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700500 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700501 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700502 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800503 }
504}
505
Mathias Agopiana67932f2011-04-20 14:20:59 -0700506sp<ISurface> LayerBaseClient::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800507{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700508 class BSurface : public BnSurface, public LayerCleaner {
Andy McFadden2adaf042012-12-18 09:49:45 -0800509 virtual sp<IGraphicBufferProducer> getSurfaceTexture() const { return 0; }
Mathias Agopiana67932f2011-04-20 14:20:59 -0700510 public:
511 BSurface(const sp<SurfaceFlinger>& flinger,
512 const sp<LayerBaseClient>& layer)
513 : LayerCleaner(flinger, layer) { }
514 };
515 sp<ISurface> sur(new BSurface(mFlinger, this));
516 return sur;
517}
518
519sp<ISurface> LayerBaseClient::getSurface()
520{
521 sp<ISurface> s;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700522 Mutex::Autolock _l(mLock);
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800523
524 LOG_ALWAYS_FATAL_IF(mHasSurface,
525 "LayerBaseClient::getSurface() has already been called");
526
527 mHasSurface = true;
528 s = createSurface();
529 mClientSurfaceBinder = s->asBinder();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700530 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800531}
532
Mathias Agopian0d156122011-01-25 20:17:45 -0800533wp<IBinder> LayerBaseClient::getSurfaceBinder() const {
534 return mClientSurfaceBinder;
535}
536
Jamie Gennis582270d2011-08-17 18:19:00 -0700537wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
538 return 0;
539}
540
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700541void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
542{
543 LayerBase::dump(result, buffer, SIZE);
544
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700545 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700546 snprintf(buffer, SIZE,
Mathias Agopian96f08192010-06-02 23:28:45 -0700547 " client=%p, identity=%u\n",
Mathias Agopian96f08192010-06-02 23:28:45 -0700548 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700549
550 result.append(buffer);
551}
552
Mathias Agopian48b888a2011-01-19 16:15:53 -0800553
554void LayerBaseClient::shortDump(String8& result, char* scratch, size_t size) const
555{
556 LayerBaseClient::dump(result, scratch, size);
557}
558
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700559// ---------------------------------------------------------------------------
560
Mathias Agopiana67932f2011-04-20 14:20:59 -0700561LayerBaseClient::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
562 const sp<LayerBaseClient>& layer)
563 : mFlinger(flinger), mLayer(layer) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700564}
565
Mathias Agopiana67932f2011-04-20 14:20:59 -0700566LayerBaseClient::LayerCleaner::~LayerCleaner() {
Mathias Agopian9a112062009-04-17 19:36:26 -0700567 // destroy client resources
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700568 mFlinger->onLayerDestroyed(mLayer);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700569}
570
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800571// ---------------------------------------------------------------------------
572
573}; // namespace android