blob: 75a9db512ea95051509ec54a930439cc34dee540 [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"
32#include "LayerBase.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033#include "SurfaceFlinger.h"
34#include "DisplayHardware/DisplayHardware.h"
Mathias Agopiand606de62010-05-10 20:06:11 -070035#include "TextureManager.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036
37
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))),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047 mFlinger(flinger),
Mathias Agopiana7f66922010-05-26 22:08:52 -070048 mNeedsFiltering(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049 mOrientation(0),
Mathias Agopianca6fab22010-02-19 17:51:58 -080050 mLeft(0), mTop(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051 mTransactionFlags(0),
Mathias Agopian245e4d72010-04-21 15:24:11 -070052 mPremultipliedAlpha(true), mName("unnamed"), mDebug(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 mInvalidate(0)
54{
55 const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware());
56 mFlags = hw.getFlags();
57}
58
59LayerBase::~LayerBase()
60{
61}
62
Mathias Agopiand1296592010-03-09 19:17:47 -080063void LayerBase::setName(const String8& name) {
64 mName = name;
65}
66
67String8 LayerBase::getName() const {
68 return mName;
69}
70
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071const GraphicPlane& LayerBase::graphicPlane(int dpy) const
72{
73 return mFlinger->graphicPlane(dpy);
74}
75
76GraphicPlane& LayerBase::graphicPlane(int dpy)
77{
78 return mFlinger->graphicPlane(dpy);
79}
80
81void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags)
82{
83 uint32_t layerFlags = 0;
84 if (flags & ISurfaceComposer::eHidden)
85 layerFlags = ISurfaceComposer::eLayerHidden;
86
87 if (flags & ISurfaceComposer::eNonPremultiplied)
88 mPremultipliedAlpha = false;
89
Mathias Agopian7e4a5872009-09-29 22:39:22 -070090 mCurrentState.z = 0;
91 mCurrentState.w = w;
92 mCurrentState.h = h;
93 mCurrentState.requested_w = w;
94 mCurrentState.requested_h = h;
95 mCurrentState.alpha = 0xFF;
96 mCurrentState.flags = layerFlags;
97 mCurrentState.sequence = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098 mCurrentState.transform.set(0, 0);
99
100 // drawing state & current state are identical
101 mDrawingState = mCurrentState;
102}
103
Mathias Agopianba6be542009-09-29 22:32:36 -0700104void LayerBase::commitTransaction() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105 mDrawingState = mCurrentState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106}
107void LayerBase::forceVisibilityTransaction() {
108 // this can be called without SurfaceFlinger.mStateLock, but if we
109 // can atomically increment the sequence number, it doesn't matter.
110 android_atomic_inc(&mCurrentState.sequence);
111 requestTransaction();
112}
113bool LayerBase::requestTransaction() {
114 int32_t old = setTransactionFlags(eTransactionNeeded);
115 return ((old & eTransactionNeeded) == 0);
116}
117uint32_t LayerBase::getTransactionFlags(uint32_t flags) {
118 return android_atomic_and(~flags, &mTransactionFlags) & flags;
119}
120uint32_t LayerBase::setTransactionFlags(uint32_t flags) {
121 return android_atomic_or(flags, &mTransactionFlags);
122}
123
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124bool LayerBase::setPosition(int32_t x, int32_t y) {
125 if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
126 return false;
127 mCurrentState.sequence++;
128 mCurrentState.transform.set(x, y);
129 requestTransaction();
130 return true;
131}
132bool LayerBase::setLayer(uint32_t z) {
133 if (mCurrentState.z == z)
134 return false;
135 mCurrentState.sequence++;
136 mCurrentState.z = z;
137 requestTransaction();
138 return true;
139}
140bool LayerBase::setSize(uint32_t w, uint32_t h) {
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700141 if (mCurrentState.requested_w == w && mCurrentState.requested_h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 return false;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700143 mCurrentState.requested_w = w;
144 mCurrentState.requested_h = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145 requestTransaction();
146 return true;
147}
148bool LayerBase::setAlpha(uint8_t alpha) {
149 if (mCurrentState.alpha == alpha)
150 return false;
151 mCurrentState.sequence++;
152 mCurrentState.alpha = alpha;
153 requestTransaction();
154 return true;
155}
156bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800157 mCurrentState.sequence++;
158 mCurrentState.transform.set(
159 matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
160 requestTransaction();
161 return true;
162}
163bool LayerBase::setTransparentRegionHint(const Region& transparent) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800164 mCurrentState.sequence++;
165 mCurrentState.transparentRegion = transparent;
166 requestTransaction();
167 return true;
168}
169bool LayerBase::setFlags(uint8_t flags, uint8_t mask) {
170 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
171 if (mCurrentState.flags == newFlags)
172 return false;
173 mCurrentState.sequence++;
174 mCurrentState.flags = newFlags;
175 requestTransaction();
176 return true;
177}
178
179Rect LayerBase::visibleBounds() const
180{
181 return mTransformedBounds;
182}
183
184void LayerBase::setVisibleRegion(const Region& visibleRegion) {
185 // always called from main thread
186 visibleRegionScreen = visibleRegion;
187}
188
189void LayerBase::setCoveredRegion(const Region& coveredRegion) {
190 // always called from main thread
191 coveredRegionScreen = coveredRegion;
192}
193
194uint32_t LayerBase::doTransaction(uint32_t flags)
195{
196 const Layer::State& front(drawingState());
197 const Layer::State& temp(currentState());
198
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700199 if ((front.requested_w != temp.requested_w) ||
200 (front.requested_h != temp.requested_h)) {
201 // resize the layer, set the physical size to the requested size
202 Layer::State& editTemp(currentState());
203 editTemp.w = temp.requested_w;
204 editTemp.h = temp.requested_h;
205 }
206
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700207 if ((front.w != temp.w) || (front.h != temp.h)) {
208 // invalidate and recompute the visible regions if needed
209 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700210 }
211
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800212 if (temp.sequence != front.sequence) {
213 // invalidate and recompute the visible regions if needed
214 flags |= eVisibleRegion;
215 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700216
Mathias Agopiana7f66922010-05-26 22:08:52 -0700217 mNeedsFiltering = false;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700218 if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
219 // we may use linear filtering, if the matrix scales us
220 const uint8_t type = temp.transform.getType();
221 if (!temp.transform.preserveRects() || (type >= Transform::SCALE)) {
Mathias Agopiana7f66922010-05-26 22:08:52 -0700222 mNeedsFiltering = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700223 }
224 }
225 }
226
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800227 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700228 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800229 return flags;
230}
231
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800232void LayerBase::validateVisibility(const Transform& planeTransform)
233{
234 const Layer::State& s(drawingState());
235 const Transform tr(planeTransform * s.transform);
236 const bool transformed = tr.transformed();
237
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700238 uint32_t w = s.w;
239 uint32_t h = s.h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800240 tr.transform(mVertices[0], 0, 0);
241 tr.transform(mVertices[1], 0, h);
242 tr.transform(mVertices[2], w, h);
243 tr.transform(mVertices[3], w, 0);
244 if (UNLIKELY(transformed)) {
245 // NOTE: here we could also punt if we have too many rectangles
246 // in the transparent region
247 if (tr.preserveRects()) {
248 // transform the transparent region
249 transparentRegionScreen = tr.transform(s.transparentRegion);
250 } else {
251 // transformation too complex, can't do the transparent region
252 // optimization.
253 transparentRegionScreen.clear();
254 }
255 } else {
256 transparentRegionScreen = s.transparentRegion;
257 }
258
259 // cache a few things...
260 mOrientation = tr.getOrientation();
261 mTransformedBounds = tr.makeBounds(w, h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800262 mLeft = tr.tx();
263 mTop = tr.ty();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800264}
265
266void LayerBase::lockPageFlip(bool& recomputeVisibleRegions)
267{
268}
269
270void LayerBase::unlockPageFlip(
271 const Transform& planeTransform, Region& outDirtyRegion)
272{
273 if ((android_atomic_and(~1, &mInvalidate)&1) == 1) {
274 outDirtyRegion.orSelf(visibleRegionScreen);
275 }
276}
277
278void LayerBase::finishPageFlip()
279{
280}
281
282void LayerBase::invalidate()
283{
284 if ((android_atomic_or(1, &mInvalidate)&1) == 0) {
285 mFlinger->signalEvent();
286 }
287}
288
289void LayerBase::drawRegion(const Region& reg) const
290{
Mathias Agopian20f68782009-05-11 00:03:41 -0700291 Region::const_iterator it = reg.begin();
292 Region::const_iterator const end = reg.end();
293 if (it != end) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800294 Rect r;
295 const DisplayHardware& hw(graphicPlane(0).displayHardware());
296 const int32_t fbWidth = hw.getWidth();
297 const int32_t fbHeight = hw.getHeight();
298 const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 },
299 { fbWidth, fbHeight }, { 0, fbHeight } };
300 glVertexPointer(2, GL_SHORT, 0, vertices);
Mathias Agopian20f68782009-05-11 00:03:41 -0700301 while (it != end) {
302 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800303 const GLint sy = fbHeight - (r.top + r.height());
304 glScissor(r.left, sy, r.width(), r.height());
305 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
306 }
307 }
308}
309
310void LayerBase::draw(const Region& inClip) const
311{
312 // invalidate the region we'll update
313 Region clip(inClip); // copy-on-write, so no-op most of the time
314
315 // Remove the transparent area from the clipping region
316 const State& s = drawingState();
317 if (LIKELY(!s.transparentRegion.isEmpty())) {
318 clip.subtract(transparentRegionScreen);
319 if (clip.isEmpty()) {
320 // usually this won't happen because this should be taken care of
321 // by SurfaceFlinger::computeVisibleRegions()
322 return;
323 }
324 }
325
326 // reset GL state
327 glEnable(GL_SCISSOR_TEST);
328
329 onDraw(clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800330}
331
Mathias Agopian010fccb2010-05-26 22:26:12 -0700332void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
333 GLclampf green, GLclampf blue,
334 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800335{
336 const DisplayHardware& hw(graphicPlane(0).displayHardware());
337 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700338 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700339
340 TextureManager::deactivateTextures();
341
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800342 glDisable(GL_BLEND);
343 glDisable(GL_DITHER);
Mathias Agopian20f68782009-05-11 00:03:41 -0700344
345 Region::const_iterator it = clip.begin();
346 Region::const_iterator const end = clip.end();
Mathias Agopian95a666b2009-09-24 14:57:26 -0700347 glEnable(GL_SCISSOR_TEST);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700348 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopian95a666b2009-09-24 14:57:26 -0700349 while (it != end) {
350 const Rect& r = *it++;
351 const GLint sy = fbHeight - (r.top + r.height());
352 glScissor(r.left, sy, r.width(), r.height());
353 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800354 }
355}
356
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700357void LayerBase::clearWithOpenGL(const Region& clip) const
358{
359 clearWithOpenGL(clip,0,0,0,0);
360}
361
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700362void LayerBase::drawWithOpenGL(const Region& clip, const Texture& texture) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800363{
364 const DisplayHardware& hw(graphicPlane(0).displayHardware());
365 const uint32_t fbHeight = hw.getHeight();
366 const State& s(drawingState());
Mathias Agopian0926f502009-05-04 14:17:04 -0700367
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800368 // bind our texture
Mathias Agopian0a917752010-06-14 21:20:00 -0700369 TextureManager::activateTexture(texture, needsFiltering());
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700370 uint32_t width = texture.width;
371 uint32_t height = texture.height;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800372
Mathias Agopian49753262010-04-12 15:34:55 -0700373 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800374 if (UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700375 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700376 if (mPremultipliedAlpha) {
377 glColor4f(alpha, alpha, alpha, alpha);
378 } else {
379 glColor4f(1, 1, 1, alpha);
380 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800381 glEnable(GL_BLEND);
382 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700383 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800384 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700385 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700386 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800387 if (needsBlending()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800388 glEnable(GL_BLEND);
389 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
390 } else {
391 glDisable(GL_BLEND);
392 }
393 }
394
Mathias Agopian95a666b2009-09-24 14:57:26 -0700395 Region::const_iterator it = clip.begin();
396 Region::const_iterator const end = clip.end();
Mathias Agopian78fd5012010-04-20 14:51:04 -0700397 const GLfloat texCoords[4][2] = {
398 { 0, 0 },
399 { 0, 1 },
400 { 1, 1 },
401 { 1, 0 }
402 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800403
Mathias Agopian78fd5012010-04-20 14:51:04 -0700404 glMatrixMode(GL_TEXTURE);
405 glLoadIdentity();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800406
Mathias Agopian78fd5012010-04-20 14:51:04 -0700407 // the texture's source is rotated
408 switch (texture.transform) {
409 case HAL_TRANSFORM_ROT_90:
410 glTranslatef(0, 1, 0);
411 glRotatef(-90, 0, 0, 1);
412 break;
413 case HAL_TRANSFORM_ROT_180:
414 glTranslatef(1, 1, 0);
415 glRotatef(-180, 0, 0, 1);
416 break;
417 case HAL_TRANSFORM_ROT_270:
418 glTranslatef(1, 0, 0);
419 glRotatef(-270, 0, 0, 1);
420 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800421 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700422
423 if (texture.NPOTAdjust) {
424 glScalef(texture.wScale, texture.hScale, 1.0f);
425 }
426
Mathias Agopian0a917752010-06-14 21:20:00 -0700427 if (needsDithering()) {
428 glEnable(GL_DITHER);
429 } else {
430 glDisable(GL_DITHER);
431 }
432
Mathias Agopian78fd5012010-04-20 14:51:04 -0700433 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
434 glVertexPointer(2, GL_FLOAT, 0, mVertices);
435 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
436
437 while (it != end) {
438 const Rect& r = *it++;
439 const GLint sy = fbHeight - (r.top + r.height());
440 glScissor(r.left, sy, r.width(), r.height());
441 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
442 }
443 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800444}
445
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700446void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
447{
448 const Layer::State& s(drawingState());
449 snprintf(buffer, SIZE,
450 "+ %s %p\n"
451 " "
452 "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), "
453 "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, "
454 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
455 getTypeId(), this, s.z, tx(), ty(), s.w, s.h,
456 needsBlending(), needsDithering(), contentDirty,
457 s.alpha, s.flags,
458 s.transform[0][0], s.transform[0][1],
459 s.transform[1][0], s.transform[1][1]);
460 result.append(buffer);
461}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700462
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800463// ---------------------------------------------------------------------------
464
Mathias Agopian631f3582010-05-25 17:51:34 -0700465int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700466
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800467LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700468 const sp<Client>& client)
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700469 : LayerBase(flinger, display), mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800470 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800471{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700472}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800473
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800474LayerBaseClient::~LayerBaseClient()
475{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700476 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700477 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700478 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800479 }
480}
481
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700482sp<LayerBaseClient::Surface> LayerBaseClient::getSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800483{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700484 sp<Surface> s;
485 Mutex::Autolock _l(mLock);
486 s = mClientSurface.promote();
487 if (s == 0) {
488 s = createSurface();
489 mClientSurface = s;
490 }
491 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800492}
493
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700494sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const
495{
Mathias Agopian96f08192010-06-02 23:28:45 -0700496 return new Surface(mFlinger, mIdentity,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700497 const_cast<LayerBaseClient *>(this));
498}
499
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700500void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
501{
502 LayerBase::dump(result, buffer, SIZE);
503
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700504 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700505 snprintf(buffer, SIZE,
506 " name=%s\n"
Mathias Agopian96f08192010-06-02 23:28:45 -0700507 " client=%p, identity=%u\n",
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700508 getName().string(),
Mathias Agopian96f08192010-06-02 23:28:45 -0700509 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700510
511 result.append(buffer);
512}
513
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700514// ---------------------------------------------------------------------------
515
Mathias Agopian9a112062009-04-17 19:36:26 -0700516LayerBaseClient::Surface::Surface(
517 const sp<SurfaceFlinger>& flinger,
Mathias Agopian96f08192010-06-02 23:28:45 -0700518 int identity,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700519 const sp<LayerBaseClient>& owner)
Mathias Agopian96f08192010-06-02 23:28:45 -0700520 : mFlinger(flinger), mIdentity(identity), mOwner(owner)
Mathias Agopian9a112062009-04-17 19:36:26 -0700521{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700522}
523
Mathias Agopian9a112062009-04-17 19:36:26 -0700524LayerBaseClient::Surface::~Surface()
525{
526 /*
527 * This is a good place to clean-up all client resources
528 */
529
530 // destroy client resources
531 sp<LayerBaseClient> layer = getOwner();
532 if (layer != 0) {
533 mFlinger->destroySurface(layer);
534 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700535}
536
537sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const {
538 sp<LayerBaseClient> owner(mOwner.promote());
539 return owner;
540}
541
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700542status_t LayerBaseClient::Surface::onTransact(
Mathias Agopian375f5632009-06-15 18:24:59 -0700543 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700544{
545 switch (code) {
546 case REGISTER_BUFFERS:
547 case UNREGISTER_BUFFERS:
548 case CREATE_OVERLAY:
549 {
Mathias Agopian375f5632009-06-15 18:24:59 -0700550 if (!mFlinger->mAccessSurfaceFlinger.checkCalling()) {
551 IPCThreadState* ipc = IPCThreadState::self();
552 const int pid = ipc->getCallingPid();
553 const int uid = ipc->getCallingUid();
554 LOGE("Permission Denial: "
555 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
556 return PERMISSION_DENIED;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700557 }
558 }
559 }
560 return BnSurface::onTransact(code, data, reply, flags);
561}
562
Mathias Agopiana138f892010-05-21 17:24:35 -0700563sp<GraphicBuffer> LayerBaseClient::Surface::requestBuffer(int bufferIdx,
564 uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700565{
566 return NULL;
567}
568
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700569status_t LayerBaseClient::Surface::setBufferCount(int bufferCount)
570{
571 return INVALID_OPERATION;
572}
573
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700574status_t LayerBaseClient::Surface::registerBuffers(
575 const ISurface::BufferHeap& buffers)
576{
577 return INVALID_OPERATION;
578}
579
580void LayerBaseClient::Surface::postBuffer(ssize_t offset)
581{
582}
583
584void LayerBaseClient::Surface::unregisterBuffers()
585{
586}
587
588sp<OverlayRef> LayerBaseClient::Surface::createOverlay(
Chih-Chung Chang52e72002010-01-21 17:31:06 -0800589 uint32_t w, uint32_t h, int32_t format, int32_t orientation)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700590{
591 return NULL;
592};
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800593
594// ---------------------------------------------------------------------------
595
596}; // namespace android