blob: 043d54d9621064bc1db500195b9875ad0afcaa63 [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 Agopiana350ff92010-08-10 17:14:02 -0700310void LayerBase::setGeometry(hwc_layer_t* hwcl) {
311 hwcl->flags |= HWC_SKIP_LAYER;
312}
313
314void LayerBase::setPerFrameData(hwc_layer_t* hwcl) {
315 hwcl->compositionType = HWC_FRAMEBUFFER;
316 hwcl->handle = NULL;
317}
318
Mathias Agopianbc7e31a2010-08-10 20:42:20 -0700319void LayerBase::draw(const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800320{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800321 // reset GL state
322 glEnable(GL_SCISSOR_TEST);
323
324 onDraw(clip);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800325}
326
Mathias Agopian010fccb2010-05-26 22:26:12 -0700327void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
328 GLclampf green, GLclampf blue,
329 GLclampf alpha) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800330{
331 const DisplayHardware& hw(graphicPlane(0).displayHardware());
332 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian010fccb2010-05-26 22:26:12 -0700333 glColor4f(red,green,blue,alpha);
Mathias Agopian0a917752010-06-14 21:20:00 -0700334
335 TextureManager::deactivateTextures();
336
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800337 glDisable(GL_BLEND);
338 glDisable(GL_DITHER);
Mathias Agopian20f68782009-05-11 00:03:41 -0700339
340 Region::const_iterator it = clip.begin();
341 Region::const_iterator const end = clip.end();
Mathias Agopian95a666b2009-09-24 14:57:26 -0700342 glEnable(GL_SCISSOR_TEST);
Mathias Agopian78fd5012010-04-20 14:51:04 -0700343 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopian95a666b2009-09-24 14:57:26 -0700344 while (it != end) {
345 const Rect& r = *it++;
346 const GLint sy = fbHeight - (r.top + r.height());
347 glScissor(r.left, sy, r.width(), r.height());
348 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800349 }
350}
351
Rebecca Schultz Zavin29aa74c2009-09-01 23:06:45 -0700352void LayerBase::clearWithOpenGL(const Region& clip) const
353{
354 clearWithOpenGL(clip,0,0,0,0);
355}
356
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700357void LayerBase::drawWithOpenGL(const Region& clip, const Texture& texture) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800358{
359 const DisplayHardware& hw(graphicPlane(0).displayHardware());
360 const uint32_t fbHeight = hw.getHeight();
361 const State& s(drawingState());
Mathias Agopian0926f502009-05-04 14:17:04 -0700362
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800363 // bind our texture
Mathias Agopian0a917752010-06-14 21:20:00 -0700364 TextureManager::activateTexture(texture, needsFiltering());
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700365 uint32_t width = texture.width;
366 uint32_t height = texture.height;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800367
Mathias Agopian49753262010-04-12 15:34:55 -0700368 GLenum src = mPremultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800369 if (UNLIKELY(s.alpha < 0xFF)) {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700370 const GLfloat alpha = s.alpha * (1.0f/255.0f);
Mathias Agopian49753262010-04-12 15:34:55 -0700371 if (mPremultipliedAlpha) {
372 glColor4f(alpha, alpha, alpha, alpha);
373 } else {
374 glColor4f(1, 1, 1, alpha);
375 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800376 glEnable(GL_BLEND);
377 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopian49753262010-04-12 15:34:55 -0700378 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800379 } else {
Mathias Agopian78fd5012010-04-20 14:51:04 -0700380 glColor4f(1, 1, 1, 1);
Mathias Agopian49753262010-04-12 15:34:55 -0700381 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800382 if (needsBlending()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800383 glEnable(GL_BLEND);
384 glBlendFunc(src, GL_ONE_MINUS_SRC_ALPHA);
385 } else {
386 glDisable(GL_BLEND);
387 }
388 }
389
Mathias Agopian95a666b2009-09-24 14:57:26 -0700390 Region::const_iterator it = clip.begin();
391 Region::const_iterator const end = clip.end();
Mathias Agopian78fd5012010-04-20 14:51:04 -0700392 const GLfloat texCoords[4][2] = {
393 { 0, 0 },
394 { 0, 1 },
395 { 1, 1 },
396 { 1, 0 }
397 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800398
Mathias Agopian78fd5012010-04-20 14:51:04 -0700399 glMatrixMode(GL_TEXTURE);
400 glLoadIdentity();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800401
Mathias Agopian78fd5012010-04-20 14:51:04 -0700402 // the texture's source is rotated
403 switch (texture.transform) {
404 case HAL_TRANSFORM_ROT_90:
405 glTranslatef(0, 1, 0);
406 glRotatef(-90, 0, 0, 1);
407 break;
408 case HAL_TRANSFORM_ROT_180:
409 glTranslatef(1, 1, 0);
410 glRotatef(-180, 0, 0, 1);
411 break;
412 case HAL_TRANSFORM_ROT_270:
413 glTranslatef(1, 0, 0);
414 glRotatef(-270, 0, 0, 1);
415 break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800416 }
Mathias Agopian78fd5012010-04-20 14:51:04 -0700417
418 if (texture.NPOTAdjust) {
419 glScalef(texture.wScale, texture.hScale, 1.0f);
420 }
421
Mathias Agopian0a917752010-06-14 21:20:00 -0700422 if (needsDithering()) {
423 glEnable(GL_DITHER);
424 } else {
425 glDisable(GL_DITHER);
426 }
427
Mathias Agopian78fd5012010-04-20 14:51:04 -0700428 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
429 glVertexPointer(2, GL_FLOAT, 0, mVertices);
430 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
431
432 while (it != end) {
433 const Rect& r = *it++;
434 const GLint sy = fbHeight - (r.top + r.height());
435 glScissor(r.left, sy, r.width(), r.height());
436 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
437 }
438 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800439}
440
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700441void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
442{
443 const Layer::State& s(drawingState());
444 snprintf(buffer, SIZE,
445 "+ %s %p\n"
446 " "
447 "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), "
448 "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, "
449 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
450 getTypeId(), this, s.z, tx(), ty(), s.w, s.h,
451 needsBlending(), needsDithering(), contentDirty,
452 s.alpha, s.flags,
453 s.transform[0][0], s.transform[0][1],
454 s.transform[1][0], s.transform[1][1]);
455 result.append(buffer);
456}
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700457
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800458// ---------------------------------------------------------------------------
459
Mathias Agopian631f3582010-05-25 17:51:34 -0700460int32_t LayerBaseClient::sIdentity = 1;
Mathias Agopian2e123242009-06-23 20:06:46 -0700461
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800462LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -0700463 const sp<Client>& client)
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700464 : LayerBase(flinger, display), mClientRef(client),
Mathias Agopian948d69f2010-03-08 19:29:09 -0800465 mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800466{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700467}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800468
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800469LayerBaseClient::~LayerBaseClient()
470{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700471 sp<Client> c(mClientRef.promote());
Mathias Agopian96f08192010-06-02 23:28:45 -0700472 if (c != 0) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700473 c->detachLayer(this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800474 }
475}
476
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700477sp<LayerBaseClient::Surface> LayerBaseClient::getSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800478{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700479 sp<Surface> s;
480 Mutex::Autolock _l(mLock);
481 s = mClientSurface.promote();
482 if (s == 0) {
483 s = createSurface();
484 mClientSurface = s;
485 }
486 return s;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800487}
488
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700489sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const
490{
Mathias Agopian96f08192010-06-02 23:28:45 -0700491 return new Surface(mFlinger, mIdentity,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700492 const_cast<LayerBaseClient *>(this));
493}
494
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700495void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
496{
497 LayerBase::dump(result, buffer, SIZE);
498
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700499 sp<Client> client(mClientRef.promote());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700500 snprintf(buffer, SIZE,
501 " name=%s\n"
Mathias Agopian96f08192010-06-02 23:28:45 -0700502 " client=%p, identity=%u\n",
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700503 getName().string(),
Mathias Agopian96f08192010-06-02 23:28:45 -0700504 client.get(), getIdentity());
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700505
506 result.append(buffer);
507}
508
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700509// ---------------------------------------------------------------------------
510
Mathias Agopian9a112062009-04-17 19:36:26 -0700511LayerBaseClient::Surface::Surface(
512 const sp<SurfaceFlinger>& flinger,
Mathias Agopian96f08192010-06-02 23:28:45 -0700513 int identity,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700514 const sp<LayerBaseClient>& owner)
Mathias Agopian96f08192010-06-02 23:28:45 -0700515 : mFlinger(flinger), mIdentity(identity), mOwner(owner)
Mathias Agopian9a112062009-04-17 19:36:26 -0700516{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700517}
518
Mathias Agopian9a112062009-04-17 19:36:26 -0700519LayerBaseClient::Surface::~Surface()
520{
521 /*
522 * This is a good place to clean-up all client resources
523 */
524
525 // destroy client resources
526 sp<LayerBaseClient> layer = getOwner();
527 if (layer != 0) {
528 mFlinger->destroySurface(layer);
529 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700530}
531
532sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const {
533 sp<LayerBaseClient> owner(mOwner.promote());
534 return owner;
535}
536
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700537status_t LayerBaseClient::Surface::onTransact(
Mathias Agopian375f5632009-06-15 18:24:59 -0700538 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700539{
540 switch (code) {
541 case REGISTER_BUFFERS:
542 case UNREGISTER_BUFFERS:
543 case CREATE_OVERLAY:
544 {
Mathias Agopian375f5632009-06-15 18:24:59 -0700545 if (!mFlinger->mAccessSurfaceFlinger.checkCalling()) {
546 IPCThreadState* ipc = IPCThreadState::self();
547 const int pid = ipc->getCallingPid();
548 const int uid = ipc->getCallingUid();
549 LOGE("Permission Denial: "
550 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
551 return PERMISSION_DENIED;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700552 }
553 }
554 }
555 return BnSurface::onTransact(code, data, reply, flags);
556}
557
Mathias Agopiana138f892010-05-21 17:24:35 -0700558sp<GraphicBuffer> LayerBaseClient::Surface::requestBuffer(int bufferIdx,
559 uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700560{
561 return NULL;
562}
563
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700564status_t LayerBaseClient::Surface::setBufferCount(int bufferCount)
565{
566 return INVALID_OPERATION;
567}
568
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700569status_t LayerBaseClient::Surface::registerBuffers(
570 const ISurface::BufferHeap& buffers)
571{
572 return INVALID_OPERATION;
573}
574
575void LayerBaseClient::Surface::postBuffer(ssize_t offset)
576{
577}
578
579void LayerBaseClient::Surface::unregisterBuffers()
580{
581}
582
583sp<OverlayRef> LayerBaseClient::Surface::createOverlay(
Chih-Chung Chang52e72002010-01-21 17:31:06 -0800584 uint32_t w, uint32_t h, int32_t format, int32_t orientation)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700585{
586 return NULL;
587};
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800588
589// ---------------------------------------------------------------------------
590
591}; // namespace android