blob: 91ac915b7fb9160cebc20b4b2b00354981b6192e [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
Mathias Agopianbc7e31a2010-08-10 20:42:20 -0700310void LayerBase::draw(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800311{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800312 // reset GL state
313 glEnable(GL_SCISSOR_TEST);
314
315 onDraw(clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800316}
317
Mathias Agopian010fccb2010-05-26 22:26:12 -0700318void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
319 GLclampf green, GLclampf blue,
320 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800321{
322 const DisplayHardware& hw(graphicPlane(0).displayHardware());
323 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700324 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700325
326 TextureManager::deactivateTextures();
327
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800328 glDisable(GL_BLEND);
329 glDisable(GL_DITHER);
Mathias Agopian20f68782009-05-11 00:03:41 -0700330
331 Region::const_iterator it = clip.begin();
332 Region::const_iterator const end = clip.end();
Mathias Agopian95a666b2009-09-24 14:57:26 -0700333 glEnable(GL_SCISSOR_TEST);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700334 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopian95a666b2009-09-24 14:57:26 -0700335 while (it != end) {
336 const Rect& r = *it++;
337 const GLint sy = fbHeight - (r.top + r.height());
338 glScissor(r.left, sy, r.width(), r.height());
339 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800340 }
341}
342
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700343void LayerBase::clearWithOpenGL(const Region& clip) const
344{
345 clearWithOpenGL(clip,0,0,0,0);
346}
347
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700348void LayerBase::drawWithOpenGL(const Region& clip, const Texture& texture) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800349{
350 const DisplayHardware& hw(graphicPlane(0).displayHardware());
351 const uint32_t fbHeight = hw.getHeight();
352 const State& s(drawingState());
Mathias Agopian0926f502009-05-04 14:17:04 -0700353
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800354 // bind our texture
Mathias Agopian0a917752010-06-14 21:20:00 -0700355 TextureManager::activateTexture(texture, needsFiltering());
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700356 uint32_t width = texture.width;
357 uint32_t height = texture.height;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800358
Mathias Agopian49753262010-04-12 15:34:55 -0700359 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800360 if (UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700361 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700362 if (mPremultipliedAlpha) {
363 glColor4f(alpha, alpha, alpha, alpha);
364 } else {
365 glColor4f(1, 1, 1, alpha);
366 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800367 glEnable(GL_BLEND);
368 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700369 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800370 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700371 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700372 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373 if (needsBlending()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800374 glEnable(GL_BLEND);
375 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
376 } else {
377 glDisable(GL_BLEND);
378 }
379 }
380
Mathias Agopian95a666b2009-09-24 14:57:26 -0700381 Region::const_iterator it = clip.begin();
382 Region::const_iterator const end = clip.end();
Mathias Agopian78fd5012010-04-20 14:51:04 -0700383 const GLfloat texCoords[4][2] = {
384 { 0, 0 },
385 { 0, 1 },
386 { 1, 1 },
387 { 1, 0 }
388 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800389
Mathias Agopian78fd5012010-04-20 14:51:04 -0700390 glMatrixMode(GL_TEXTURE);
391 glLoadIdentity();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800392
Mathias Agopian78fd5012010-04-20 14:51:04 -0700393 // the texture's source is rotated
394 switch (texture.transform) {
395 case HAL_TRANSFORM_ROT_90:
396 glTranslatef(0, 1, 0);
397 glRotatef(-90, 0, 0, 1);
398 break;
399 case HAL_TRANSFORM_ROT_180:
400 glTranslatef(1, 1, 0);
401 glRotatef(-180, 0, 0, 1);
402 break;
403 case HAL_TRANSFORM_ROT_270:
404 glTranslatef(1, 0, 0);
405 glRotatef(-270, 0, 0, 1);
406 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800407 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700408
409 if (texture.NPOTAdjust) {
410 glScalef(texture.wScale, texture.hScale, 1.0f);
411 }
412
Mathias Agopian0a917752010-06-14 21:20:00 -0700413 if (needsDithering()) {
414 glEnable(GL_DITHER);
415 } else {
416 glDisable(GL_DITHER);
417 }
418
Mathias Agopian78fd5012010-04-20 14:51:04 -0700419 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
420 glVertexPointer(2, GL_FLOAT, 0, mVertices);
421 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
422
423 while (it != end) {
424 const Rect& r = *it++;
425 const GLint sy = fbHeight - (r.top + r.height());
426 glScissor(r.left, sy, r.width(), r.height());
427 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
428 }
429 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800430}
431
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700432void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
433{
434 const Layer::State& s(drawingState());
435 snprintf(buffer, SIZE,
436 "+ %s %p\n"
437 " "
438 "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), "
439 "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, "
440 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
441 getTypeId(), this, s.z, tx(), ty(), s.w, s.h,
442 needsBlending(), needsDithering(), contentDirty,
443 s.alpha, s.flags,
444 s.transform[0][0], s.transform[0][1],
445 s.transform[1][0], s.transform[1][1]);
446 result.append(buffer);
447}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700448
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800449// ---------------------------------------------------------------------------
450
Mathias Agopian631f3582010-05-25 17:51:34 -0700451int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700452
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800453LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700454 const sp<Client>& client)
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700455 : LayerBase(flinger, display), mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800456 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800457{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700458}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800459
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800460LayerBaseClient::~LayerBaseClient()
461{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700462 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700463 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700464 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800465 }
466}
467
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700468sp<LayerBaseClient::Surface> LayerBaseClient::getSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800469{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700470 sp<Surface> s;
471 Mutex::Autolock _l(mLock);
472 s = mClientSurface.promote();
473 if (s == 0) {
474 s = createSurface();
475 mClientSurface = s;
476 }
477 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800478}
479
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700480sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const
481{
Mathias Agopian96f08192010-06-02 23:28:45 -0700482 return new Surface(mFlinger, mIdentity,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700483 const_cast<LayerBaseClient *>(this));
484}
485
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700486void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
487{
488 LayerBase::dump(result, buffer, SIZE);
489
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700490 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700491 snprintf(buffer, SIZE,
492 " name=%s\n"
Mathias Agopian96f08192010-06-02 23:28:45 -0700493 " client=%p, identity=%u\n",
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700494 getName().string(),
Mathias Agopian96f08192010-06-02 23:28:45 -0700495 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700496
497 result.append(buffer);
498}
499
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700500// ---------------------------------------------------------------------------
501
Mathias Agopian9a112062009-04-17 19:36:26 -0700502LayerBaseClient::Surface::Surface(
503 const sp<SurfaceFlinger>& flinger,
Mathias Agopian96f08192010-06-02 23:28:45 -0700504 int identity,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700505 const sp<LayerBaseClient>& owner)
Mathias Agopian96f08192010-06-02 23:28:45 -0700506 : mFlinger(flinger), mIdentity(identity), mOwner(owner)
Mathias Agopian9a112062009-04-17 19:36:26 -0700507{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700508}
509
Mathias Agopian9a112062009-04-17 19:36:26 -0700510LayerBaseClient::Surface::~Surface()
511{
512 /*
513 * This is a good place to clean-up all client resources
514 */
515
516 // destroy client resources
517 sp<LayerBaseClient> layer = getOwner();
518 if (layer != 0) {
519 mFlinger->destroySurface(layer);
520 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700521}
522
523sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const {
524 sp<LayerBaseClient> owner(mOwner.promote());
525 return owner;
526}
527
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700528status_t LayerBaseClient::Surface::onTransact(
Mathias Agopian375f5632009-06-15 18:24:59 -0700529 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700530{
531 switch (code) {
532 case REGISTER_BUFFERS:
533 case UNREGISTER_BUFFERS:
534 case CREATE_OVERLAY:
535 {
Mathias Agopian375f5632009-06-15 18:24:59 -0700536 if (!mFlinger->mAccessSurfaceFlinger.checkCalling()) {
537 IPCThreadState* ipc = IPCThreadState::self();
538 const int pid = ipc->getCallingPid();
539 const int uid = ipc->getCallingUid();
540 LOGE("Permission Denial: "
541 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
542 return PERMISSION_DENIED;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700543 }
544 }
545 }
546 return BnSurface::onTransact(code, data, reply, flags);
547}
548
Mathias Agopiana138f892010-05-21 17:24:35 -0700549sp<GraphicBuffer> LayerBaseClient::Surface::requestBuffer(int bufferIdx,
550 uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700551{
552 return NULL;
553}
554
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700555status_t LayerBaseClient::Surface::setBufferCount(int bufferCount)
556{
557 return INVALID_OPERATION;
558}
559
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700560status_t LayerBaseClient::Surface::registerBuffers(
561 const ISurface::BufferHeap& buffers)
562{
563 return INVALID_OPERATION;
564}
565
566void LayerBaseClient::Surface::postBuffer(ssize_t offset)
567{
568}
569
570void LayerBaseClient::Surface::unregisterBuffers()
571{
572}
573
574sp<OverlayRef> LayerBaseClient::Surface::createOverlay(
Chih-Chung Chang52e72002010-01-21 17:31:06 -0800575 uint32_t w, uint32_t h, int32_t format, int32_t orientation)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700576{
577 return NULL;
578};
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800579
580// ---------------------------------------------------------------------------
581
582}; // namespace android