blob: d5aa53f9f178e66f9902499784a3e7b90110eacf [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);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800327}
328
Mathias Agopian010fccb2010-05-26 22:26:12 -0700329void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
330 GLclampf green, GLclampf blue,
331 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800332{
333 const DisplayHardware& hw(graphicPlane(0).displayHardware());
334 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700335 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700336
337 TextureManager::deactivateTextures();
338
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339 glDisable(GL_BLEND);
340 glDisable(GL_DITHER);
Mathias Agopian20f68782009-05-11 00:03:41 -0700341
342 Region::const_iterator it = clip.begin();
343 Region::const_iterator const end = clip.end();
Mathias Agopian95a666b2009-09-24 14:57:26 -0700344 glEnable(GL_SCISSOR_TEST);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700345 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopian95a666b2009-09-24 14:57:26 -0700346 while (it != end) {
347 const Rect& r = *it++;
348 const GLint sy = fbHeight - (r.top + r.height());
349 glScissor(r.left, sy, r.width(), r.height());
350 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800351 }
352}
353
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700354void LayerBase::clearWithOpenGL(const Region& clip) const
355{
356 clearWithOpenGL(clip,0,0,0,0);
357}
358
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700359void LayerBase::drawWithOpenGL(const Region& clip, const Texture& texture) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800360{
361 const DisplayHardware& hw(graphicPlane(0).displayHardware());
362 const uint32_t fbHeight = hw.getHeight();
363 const State& s(drawingState());
Mathias Agopian0926f502009-05-04 14:17:04 -0700364
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800365 // bind our texture
Mathias Agopian0a917752010-06-14 21:20:00 -0700366 TextureManager::activateTexture(texture, needsFiltering());
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700367 uint32_t width = texture.width;
368 uint32_t height = texture.height;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800369
Mathias Agopian49753262010-04-12 15:34:55 -0700370 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800371 if (UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700372 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700373 if (mPremultipliedAlpha) {
374 glColor4f(alpha, alpha, alpha, alpha);
375 } else {
376 glColor4f(1, 1, 1, alpha);
377 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800378 glEnable(GL_BLEND);
379 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700380 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800381 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700382 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700383 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800384 if (needsBlending()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800385 glEnable(GL_BLEND);
386 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
387 } else {
388 glDisable(GL_BLEND);
389 }
390 }
391
Mathias Agopian95a666b2009-09-24 14:57:26 -0700392 Region::const_iterator it = clip.begin();
393 Region::const_iterator const end = clip.end();
Mathias Agopian78fd5012010-04-20 14:51:04 -0700394 const GLfloat texCoords[4][2] = {
395 { 0, 0 },
396 { 0, 1 },
397 { 1, 1 },
398 { 1, 0 }
399 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800400
Mathias Agopian78fd5012010-04-20 14:51:04 -0700401 glMatrixMode(GL_TEXTURE);
402 glLoadIdentity();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800403
Mathias Agopian78fd5012010-04-20 14:51:04 -0700404 // the texture's source is rotated
405 switch (texture.transform) {
406 case HAL_TRANSFORM_ROT_90:
407 glTranslatef(0, 1, 0);
408 glRotatef(-90, 0, 0, 1);
409 break;
410 case HAL_TRANSFORM_ROT_180:
411 glTranslatef(1, 1, 0);
412 glRotatef(-180, 0, 0, 1);
413 break;
414 case HAL_TRANSFORM_ROT_270:
415 glTranslatef(1, 0, 0);
416 glRotatef(-270, 0, 0, 1);
417 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800418 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700419
420 if (texture.NPOTAdjust) {
421 glScalef(texture.wScale, texture.hScale, 1.0f);
422 }
423
Mathias Agopian0a917752010-06-14 21:20:00 -0700424 if (needsDithering()) {
425 glEnable(GL_DITHER);
426 } else {
427 glDisable(GL_DITHER);
428 }
429
Mathias Agopian78fd5012010-04-20 14:51:04 -0700430 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
431 glVertexPointer(2, GL_FLOAT, 0, mVertices);
432 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
433
434 while (it != end) {
435 const Rect& r = *it++;
436 const GLint sy = fbHeight - (r.top + r.height());
437 glScissor(r.left, sy, r.width(), r.height());
438 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
439 }
440 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800441}
442
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700443void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
444{
445 const Layer::State& s(drawingState());
446 snprintf(buffer, SIZE,
447 "+ %s %p\n"
448 " "
449 "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), "
450 "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, "
451 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
452 getTypeId(), this, s.z, tx(), ty(), s.w, s.h,
453 needsBlending(), needsDithering(), contentDirty,
454 s.alpha, s.flags,
455 s.transform[0][0], s.transform[0][1],
456 s.transform[1][0], s.transform[1][1]);
457 result.append(buffer);
458}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700459
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800460// ---------------------------------------------------------------------------
461
Mathias Agopian631f3582010-05-25 17:51:34 -0700462int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700463
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800464LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700465 const sp<Client>& client)
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700466 : LayerBase(flinger, display), mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800467 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800468{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700469}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800470
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800471LayerBaseClient::~LayerBaseClient()
472{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700473 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700474 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700475 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800476 }
477}
478
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700479sp<LayerBaseClient::Surface> LayerBaseClient::getSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800480{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700481 sp<Surface> s;
482 Mutex::Autolock _l(mLock);
483 s = mClientSurface.promote();
484 if (s == 0) {
485 s = createSurface();
486 mClientSurface = s;
487 }
488 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800489}
490
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700491sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const
492{
Mathias Agopian96f08192010-06-02 23:28:45 -0700493 return new Surface(mFlinger, mIdentity,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700494 const_cast<LayerBaseClient *>(this));
495}
496
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700497void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
498{
499 LayerBase::dump(result, buffer, SIZE);
500
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700501 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700502 snprintf(buffer, SIZE,
503 " name=%s\n"
Mathias Agopian96f08192010-06-02 23:28:45 -0700504 " client=%p, identity=%u\n",
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700505 getName().string(),
Mathias Agopian96f08192010-06-02 23:28:45 -0700506 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700507
508 result.append(buffer);
509}
510
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700511// ---------------------------------------------------------------------------
512
Mathias Agopian9a112062009-04-17 19:36:26 -0700513LayerBaseClient::Surface::Surface(
514 const sp<SurfaceFlinger>& flinger,
Mathias Agopian96f08192010-06-02 23:28:45 -0700515 int identity,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700516 const sp<LayerBaseClient>& owner)
Mathias Agopian96f08192010-06-02 23:28:45 -0700517 : mFlinger(flinger), mIdentity(identity), mOwner(owner)
Mathias Agopian9a112062009-04-17 19:36:26 -0700518{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700519}
520
Mathias Agopian9a112062009-04-17 19:36:26 -0700521LayerBaseClient::Surface::~Surface()
522{
523 /*
524 * This is a good place to clean-up all client resources
525 */
526
527 // destroy client resources
528 sp<LayerBaseClient> layer = getOwner();
529 if (layer != 0) {
530 mFlinger->destroySurface(layer);
531 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700532}
533
534sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const {
535 sp<LayerBaseClient> owner(mOwner.promote());
536 return owner;
537}
538
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700539status_t LayerBaseClient::Surface::onTransact(
Mathias Agopian375f5632009-06-15 18:24:59 -0700540 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700541{
542 switch (code) {
543 case REGISTER_BUFFERS:
544 case UNREGISTER_BUFFERS:
545 case CREATE_OVERLAY:
546 {
Mathias Agopian375f5632009-06-15 18:24:59 -0700547 if (!mFlinger->mAccessSurfaceFlinger.checkCalling()) {
548 IPCThreadState* ipc = IPCThreadState::self();
549 const int pid = ipc->getCallingPid();
550 const int uid = ipc->getCallingUid();
551 LOGE("Permission Denial: "
552 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
553 return PERMISSION_DENIED;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700554 }
555 }
556 }
557 return BnSurface::onTransact(code, data, reply, flags);
558}
559
Mathias Agopiana138f892010-05-21 17:24:35 -0700560sp<GraphicBuffer> LayerBaseClient::Surface::requestBuffer(int bufferIdx,
561 uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700562{
563 return NULL;
564}
565
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700566status_t LayerBaseClient::Surface::setBufferCount(int bufferCount)
567{
568 return INVALID_OPERATION;
569}
570
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700571status_t LayerBaseClient::Surface::registerBuffers(
572 const ISurface::BufferHeap& buffers)
573{
574 return INVALID_OPERATION;
575}
576
577void LayerBaseClient::Surface::postBuffer(ssize_t offset)
578{
579}
580
581void LayerBaseClient::Surface::unregisterBuffers()
582{
583}
584
585sp<OverlayRef> LayerBaseClient::Surface::createOverlay(
Chih-Chung Chang52e72002010-01-21 17:31:06 -0800586 uint32_t w, uint32_t h, int32_t format, int32_t orientation)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700587{
588 return NULL;
589};
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800590
591// ---------------------------------------------------------------------------
592
593}; // namespace android