blob: 1f66fd0296e96f271c3af8f0a4392ec267ce7551 [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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display)
43 : dpy(display), contentDirty(false),
44 mFlinger(flinger),
Mathias Agopiana7f66922010-05-26 22:08:52 -070045 mNeedsFiltering(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046 mOrientation(0),
Mathias Agopianca6fab22010-02-19 17:51:58 -080047 mLeft(0), mTop(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048 mTransactionFlags(0),
Mathias Agopian245e4d72010-04-21 15:24:11 -070049 mPremultipliedAlpha(true), mName("unnamed"), mDebug(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050 mInvalidate(0)
51{
52 const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware());
53 mFlags = hw.getFlags();
54}
55
56LayerBase::~LayerBase()
57{
58}
59
Mathias Agopiand1296592010-03-09 19:17:47 -080060void LayerBase::setName(const String8& name) {
61 mName = name;
62}
63
64String8 LayerBase::getName() const {
65 return mName;
66}
67
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068const GraphicPlane& LayerBase::graphicPlane(int dpy) const
69{
70 return mFlinger->graphicPlane(dpy);
71}
72
73GraphicPlane& LayerBase::graphicPlane(int dpy)
74{
75 return mFlinger->graphicPlane(dpy);
76}
77
78void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags)
79{
80 uint32_t layerFlags = 0;
81 if (flags & ISurfaceComposer::eHidden)
82 layerFlags = ISurfaceComposer::eLayerHidden;
83
84 if (flags & ISurfaceComposer::eNonPremultiplied)
85 mPremultipliedAlpha = false;
86
Mathias Agopian7e4a5872009-09-29 22:39:22 -070087 mCurrentState.z = 0;
88 mCurrentState.w = w;
89 mCurrentState.h = h;
90 mCurrentState.requested_w = w;
91 mCurrentState.requested_h = h;
92 mCurrentState.alpha = 0xFF;
93 mCurrentState.flags = layerFlags;
94 mCurrentState.sequence = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095 mCurrentState.transform.set(0, 0);
96
97 // drawing state & current state are identical
98 mDrawingState = mCurrentState;
99}
100
Mathias Agopianba6be542009-09-29 22:32:36 -0700101void LayerBase::commitTransaction() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 mDrawingState = mCurrentState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103}
104void LayerBase::forceVisibilityTransaction() {
105 // this can be called without SurfaceFlinger.mStateLock, but if we
106 // can atomically increment the sequence number, it doesn't matter.
107 android_atomic_inc(&mCurrentState.sequence);
108 requestTransaction();
109}
110bool LayerBase::requestTransaction() {
111 int32_t old = setTransactionFlags(eTransactionNeeded);
112 return ((old & eTransactionNeeded) == 0);
113}
114uint32_t LayerBase::getTransactionFlags(uint32_t flags) {
115 return android_atomic_and(~flags, &mTransactionFlags) & flags;
116}
117uint32_t LayerBase::setTransactionFlags(uint32_t flags) {
118 return android_atomic_or(flags, &mTransactionFlags);
119}
120
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800121bool LayerBase::setPosition(int32_t x, int32_t y) {
122 if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y)
123 return false;
124 mCurrentState.sequence++;
125 mCurrentState.transform.set(x, y);
126 requestTransaction();
127 return true;
128}
129bool LayerBase::setLayer(uint32_t z) {
130 if (mCurrentState.z == z)
131 return false;
132 mCurrentState.sequence++;
133 mCurrentState.z = z;
134 requestTransaction();
135 return true;
136}
137bool LayerBase::setSize(uint32_t w, uint32_t h) {
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700138 if (mCurrentState.requested_w == w && mCurrentState.requested_h == h)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800139 return false;
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700140 mCurrentState.requested_w = w;
141 mCurrentState.requested_h = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 requestTransaction();
143 return true;
144}
145bool LayerBase::setAlpha(uint8_t alpha) {
146 if (mCurrentState.alpha == alpha)
147 return false;
148 mCurrentState.sequence++;
149 mCurrentState.alpha = alpha;
150 requestTransaction();
151 return true;
152}
153bool LayerBase::setMatrix(const layer_state_t::matrix22_t& matrix) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800154 mCurrentState.sequence++;
155 mCurrentState.transform.set(
156 matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
157 requestTransaction();
158 return true;
159}
160bool LayerBase::setTransparentRegionHint(const Region& transparent) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800161 mCurrentState.sequence++;
162 mCurrentState.transparentRegion = transparent;
163 requestTransaction();
164 return true;
165}
166bool LayerBase::setFlags(uint8_t flags, uint8_t mask) {
167 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
168 if (mCurrentState.flags == newFlags)
169 return false;
170 mCurrentState.sequence++;
171 mCurrentState.flags = newFlags;
172 requestTransaction();
173 return true;
174}
175
176Rect LayerBase::visibleBounds() const
177{
178 return mTransformedBounds;
179}
180
181void LayerBase::setVisibleRegion(const Region& visibleRegion) {
182 // always called from main thread
183 visibleRegionScreen = visibleRegion;
184}
185
186void LayerBase::setCoveredRegion(const Region& coveredRegion) {
187 // always called from main thread
188 coveredRegionScreen = coveredRegion;
189}
190
191uint32_t LayerBase::doTransaction(uint32_t flags)
192{
193 const Layer::State& front(drawingState());
194 const Layer::State& temp(currentState());
195
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700196 if ((front.requested_w != temp.requested_w) ||
197 (front.requested_h != temp.requested_h)) {
198 // resize the layer, set the physical size to the requested size
199 Layer::State& editTemp(currentState());
200 editTemp.w = temp.requested_w;
201 editTemp.h = temp.requested_h;
202 }
203
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700204 if ((front.w != temp.w) || (front.h != temp.h)) {
205 // invalidate and recompute the visible regions if needed
206 flags |= Layer::eVisibleRegion;
Mathias Agopian6656dbc2009-09-30 12:48:47 -0700207 }
208
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800209 if (temp.sequence != front.sequence) {
210 // invalidate and recompute the visible regions if needed
211 flags |= eVisibleRegion;
212 this->contentDirty = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700213
Mathias Agopiana7f66922010-05-26 22:08:52 -0700214 mNeedsFiltering = false;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700215 if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
216 // we may use linear filtering, if the matrix scales us
217 const uint8_t type = temp.transform.getType();
218 if (!temp.transform.preserveRects() || (type >= Transform::SCALE)) {
Mathias Agopiana7f66922010-05-26 22:08:52 -0700219 mNeedsFiltering = true;
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700220 }
221 }
222 }
223
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800224 // Commit the transaction
Mathias Agopianba6be542009-09-29 22:32:36 -0700225 commitTransaction();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800226 return flags;
227}
228
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800229void LayerBase::validateVisibility(const Transform& planeTransform)
230{
231 const Layer::State& s(drawingState());
232 const Transform tr(planeTransform * s.transform);
233 const bool transformed = tr.transformed();
234
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700235 uint32_t w = s.w;
236 uint32_t h = s.h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800237 tr.transform(mVertices[0], 0, 0);
238 tr.transform(mVertices[1], 0, h);
239 tr.transform(mVertices[2], w, h);
240 tr.transform(mVertices[3], w, 0);
241 if (UNLIKELY(transformed)) {
242 // NOTE: here we could also punt if we have too many rectangles
243 // in the transparent region
244 if (tr.preserveRects()) {
245 // transform the transparent region
246 transparentRegionScreen = tr.transform(s.transparentRegion);
247 } else {
248 // transformation too complex, can't do the transparent region
249 // optimization.
250 transparentRegionScreen.clear();
251 }
252 } else {
253 transparentRegionScreen = s.transparentRegion;
254 }
255
256 // cache a few things...
257 mOrientation = tr.getOrientation();
258 mTransformedBounds = tr.makeBounds(w, h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800259 mLeft = tr.tx();
260 mTop = tr.ty();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800261}
262
263void LayerBase::lockPageFlip(bool& recomputeVisibleRegions)
264{
265}
266
267void LayerBase::unlockPageFlip(
268 const Transform& planeTransform, Region& outDirtyRegion)
269{
270 if ((android_atomic_and(~1, &mInvalidate)&1) == 1) {
271 outDirtyRegion.orSelf(visibleRegionScreen);
272 }
273}
274
275void LayerBase::finishPageFlip()
276{
277}
278
279void LayerBase::invalidate()
280{
281 if ((android_atomic_or(1, &mInvalidate)&1) == 0) {
282 mFlinger->signalEvent();
283 }
284}
285
286void LayerBase::drawRegion(const Region& reg) const
287{
Mathias Agopian20f68782009-05-11 00:03:41 -0700288 Region::const_iterator it = reg.begin();
289 Region::const_iterator const end = reg.end();
290 if (it != end) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800291 Rect r;
292 const DisplayHardware& hw(graphicPlane(0).displayHardware());
293 const int32_t fbWidth = hw.getWidth();
294 const int32_t fbHeight = hw.getHeight();
295 const GLshort vertices[][2] = { { 0, 0 }, { fbWidth, 0 },
296 { fbWidth, fbHeight }, { 0, fbHeight } };
297 glVertexPointer(2, GL_SHORT, 0, vertices);
Mathias Agopian20f68782009-05-11 00:03:41 -0700298 while (it != end) {
299 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800300 const GLint sy = fbHeight - (r.top + r.height());
301 glScissor(r.left, sy, r.width(), r.height());
302 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
303 }
304 }
305}
306
307void LayerBase::draw(const Region& inClip) const
308{
309 // invalidate the region we'll update
310 Region clip(inClip); // copy-on-write, so no-op most of the time
311
312 // Remove the transparent area from the clipping region
313 const State& s = drawingState();
314 if (LIKELY(!s.transparentRegion.isEmpty())) {
315 clip.subtract(transparentRegionScreen);
316 if (clip.isEmpty()) {
317 // usually this won't happen because this should be taken care of
318 // by SurfaceFlinger::computeVisibleRegions()
319 return;
320 }
321 }
322
323 // reset GL state
324 glEnable(GL_SCISSOR_TEST);
325
326 onDraw(clip);
327
328 /*
329 glDisable(GL_TEXTURE_2D);
330 glDisable(GL_DITHER);
331 glEnable(GL_BLEND);
332 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
333 glColor4x(0, 0x8000, 0, 0x10000);
334 drawRegion(transparentRegionScreen);
335 glDisable(GL_BLEND);
336 */
337}
338
Mathias Agopian010fccb2010-05-26 22:26:12 -0700339void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
340 GLclampf green, GLclampf blue,
341 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800342{
343 const DisplayHardware& hw(graphicPlane(0).displayHardware());
344 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700345 glColor4f(red,green,blue,alpha);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800346 glDisable(GL_TEXTURE_2D);
347 glDisable(GL_BLEND);
348 glDisable(GL_DITHER);
Mathias Agopian20f68782009-05-11 00:03:41 -0700349
350 Region::const_iterator it = clip.begin();
351 Region::const_iterator const end = clip.end();
Mathias Agopian95a666b2009-09-24 14:57:26 -0700352 glEnable(GL_SCISSOR_TEST);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700353 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopian95a666b2009-09-24 14:57:26 -0700354 while (it != end) {
355 const Rect& r = *it++;
356 const GLint sy = fbHeight - (r.top + r.height());
357 glScissor(r.left, sy, r.width(), r.height());
358 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800359 }
360}
361
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700362void LayerBase::clearWithOpenGL(const Region& clip) const
363{
364 clearWithOpenGL(clip,0,0,0,0);
365}
366
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700367void LayerBase::drawWithOpenGL(const Region& clip, const Texture& texture) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800368{
369 const DisplayHardware& hw(graphicPlane(0).displayHardware());
370 const uint32_t fbHeight = hw.getHeight();
371 const State& s(drawingState());
Mathias Agopian0926f502009-05-04 14:17:04 -0700372
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373 // bind our texture
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700374 validateTexture(texture.name);
375 uint32_t width = texture.width;
376 uint32_t height = texture.height;
377
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800378 glEnable(GL_TEXTURE_2D);
379
Mathias Agopian49753262010-04-12 15:34:55 -0700380 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800381 if (UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700382 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700383 if (mPremultipliedAlpha) {
384 glColor4f(alpha, alpha, alpha, alpha);
385 } else {
386 glColor4f(1, 1, 1, alpha);
387 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800388 glEnable(GL_BLEND);
389 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700390 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800391 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700392 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700393 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800394 if (needsBlending()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800395 glEnable(GL_BLEND);
396 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
397 } else {
398 glDisable(GL_BLEND);
399 }
400 }
401
Mathias Agopian95a666b2009-09-24 14:57:26 -0700402 Region::const_iterator it = clip.begin();
403 Region::const_iterator const end = clip.end();
Mathias Agopian78fd5012010-04-20 14:51:04 -0700404 const GLfloat texCoords[4][2] = {
405 { 0, 0 },
406 { 0, 1 },
407 { 1, 1 },
408 { 1, 0 }
409 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800410
Mathias Agopian78fd5012010-04-20 14:51:04 -0700411 glMatrixMode(GL_TEXTURE);
412 glLoadIdentity();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800413
Mathias Agopian78fd5012010-04-20 14:51:04 -0700414 // the texture's source is rotated
415 switch (texture.transform) {
416 case HAL_TRANSFORM_ROT_90:
417 glTranslatef(0, 1, 0);
418 glRotatef(-90, 0, 0, 1);
419 break;
420 case HAL_TRANSFORM_ROT_180:
421 glTranslatef(1, 1, 0);
422 glRotatef(-180, 0, 0, 1);
423 break;
424 case HAL_TRANSFORM_ROT_270:
425 glTranslatef(1, 0, 0);
426 glRotatef(-270, 0, 0, 1);
427 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800428 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700429
430 if (texture.NPOTAdjust) {
431 glScalef(texture.wScale, texture.hScale, 1.0f);
432 }
433
434 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
435 glVertexPointer(2, GL_FLOAT, 0, mVertices);
436 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
437
438 while (it != end) {
439 const Rect& r = *it++;
440 const GLint sy = fbHeight - (r.top + r.height());
441 glScissor(r.left, sy, r.width(), r.height());
442 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
443 }
444 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800445}
446
447void LayerBase::validateTexture(GLint textureName) const
448{
449 glBindTexture(GL_TEXTURE_2D, textureName);
450 // TODO: reload the texture if needed
451 // this is currently done in loadTexture() below
Mathias Agopiana7f66922010-05-26 22:08:52 -0700452 if (needsFiltering()) {
Mathias Agopiana2fe0a22009-09-23 18:34:53 -0700453 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
454 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
455 } else {
456 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
457 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
458 }
Mathias Agopian401c2572009-09-23 19:16:27 -0700459
460 if (needsDithering()) {
461 glEnable(GL_DITHER);
462 } else {
463 glDisable(GL_DITHER);
464 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800465}
466
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700467void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
468{
469 const Layer::State& s(drawingState());
470 snprintf(buffer, SIZE,
471 "+ %s %p\n"
472 " "
473 "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), "
474 "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, "
475 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
476 getTypeId(), this, s.z, tx(), ty(), s.w, s.h,
477 needsBlending(), needsDithering(), contentDirty,
478 s.alpha, s.flags,
479 s.transform[0][0], s.transform[0][1],
480 s.transform[1][0], s.transform[1][1]);
481 result.append(buffer);
482}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700483
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800484// ---------------------------------------------------------------------------
485
Mathias Agopian631f3582010-05-25 17:51:34 -0700486int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700487
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800488LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700489 const sp<Client>& client)
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700490 : LayerBase(flinger, display), mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800491 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800492{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700493}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800494
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800495LayerBaseClient::~LayerBaseClient()
496{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700497 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700498 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700499 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800500 }
501}
502
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700503sp<LayerBaseClient::Surface> LayerBaseClient::getSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800504{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700505 sp<Surface> s;
506 Mutex::Autolock _l(mLock);
507 s = mClientSurface.promote();
508 if (s == 0) {
509 s = createSurface();
510 mClientSurface = s;
511 }
512 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800513}
514
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700515sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const
516{
Mathias Agopian96f08192010-06-02 23:28:45 -0700517 return new Surface(mFlinger, mIdentity,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700518 const_cast<LayerBaseClient *>(this));
519}
520
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700521void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
522{
523 LayerBase::dump(result, buffer, SIZE);
524
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700525 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700526 snprintf(buffer, SIZE,
527 " name=%s\n"
Mathias Agopian96f08192010-06-02 23:28:45 -0700528 " client=%p, identity=%u\n",
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700529 getName().string(),
Mathias Agopian96f08192010-06-02 23:28:45 -0700530 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700531
532 result.append(buffer);
533}
534
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700535// ---------------------------------------------------------------------------
536
Mathias Agopian9a112062009-04-17 19:36:26 -0700537LayerBaseClient::Surface::Surface(
538 const sp<SurfaceFlinger>& flinger,
Mathias Agopian96f08192010-06-02 23:28:45 -0700539 int identity,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700540 const sp<LayerBaseClient>& owner)
Mathias Agopian96f08192010-06-02 23:28:45 -0700541 : mFlinger(flinger), mIdentity(identity), mOwner(owner)
Mathias Agopian9a112062009-04-17 19:36:26 -0700542{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700543}
544
Mathias Agopian9a112062009-04-17 19:36:26 -0700545LayerBaseClient::Surface::~Surface()
546{
547 /*
548 * This is a good place to clean-up all client resources
549 */
550
551 // destroy client resources
552 sp<LayerBaseClient> layer = getOwner();
553 if (layer != 0) {
554 mFlinger->destroySurface(layer);
555 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700556}
557
558sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const {
559 sp<LayerBaseClient> owner(mOwner.promote());
560 return owner;
561}
562
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700563status_t LayerBaseClient::Surface::onTransact(
Mathias Agopian375f5632009-06-15 18:24:59 -0700564 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700565{
566 switch (code) {
567 case REGISTER_BUFFERS:
568 case UNREGISTER_BUFFERS:
569 case CREATE_OVERLAY:
570 {
Mathias Agopian375f5632009-06-15 18:24:59 -0700571 if (!mFlinger->mAccessSurfaceFlinger.checkCalling()) {
572 IPCThreadState* ipc = IPCThreadState::self();
573 const int pid = ipc->getCallingPid();
574 const int uid = ipc->getCallingUid();
575 LOGE("Permission Denial: "
576 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
577 return PERMISSION_DENIED;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700578 }
579 }
580 }
581 return BnSurface::onTransact(code, data, reply, flags);
582}
583
Mathias Agopiana138f892010-05-21 17:24:35 -0700584sp<GraphicBuffer> LayerBaseClient::Surface::requestBuffer(int bufferIdx,
585 uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700586{
587 return NULL;
588}
589
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700590status_t LayerBaseClient::Surface::setBufferCount(int bufferCount)
591{
592 return INVALID_OPERATION;
593}
594
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700595status_t LayerBaseClient::Surface::registerBuffers(
596 const ISurface::BufferHeap& buffers)
597{
598 return INVALID_OPERATION;
599}
600
601void LayerBaseClient::Surface::postBuffer(ssize_t offset)
602{
603}
604
605void LayerBaseClient::Surface::unregisterBuffers()
606{
607}
608
609sp<OverlayRef> LayerBaseClient::Surface::createOverlay(
Chih-Chung Chang52e72002010-01-21 17:31:06 -0800610 uint32_t w, uint32_t h, int32_t format, int32_t orientation)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700611{
612 return NULL;
613};
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800614
615// ---------------------------------------------------------------------------
616
617}; // namespace android