blob: 4ee176c92a56329a0a38a42496f1ce8a64ec9f9e [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 <stdio.h>
19#include <stdint.h>
20#include <unistd.h>
21#include <fcntl.h>
22#include <errno.h>
23#include <math.h>
Jean-Baptiste Querua837ba72009-01-26 11:51:12 -080024#include <limits.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025#include <sys/types.h>
26#include <sys/stat.h>
27#include <sys/ioctl.h>
28
29#include <cutils/log.h>
30#include <cutils/properties.h>
31
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070032#include <binder/IPCThreadState.h>
33#include <binder/IServiceManager.h>
Mathias Agopian7303c6b2009-07-02 18:11:53 -070034#include <binder/MemoryHeapBase.h>
35
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036#include <utils/String8.h>
37#include <utils/String16.h>
38#include <utils/StopWatch.h>
39
40#include <ui/PixelFormat.h>
41#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
43#include <pixelflinger/pixelflinger.h>
44#include <GLES/gl.h>
45
46#include "clz.h"
Mathias Agopiancbb288b2009-09-07 16:32:45 -070047#include "Buffer.h"
Mathias Agopian076b1cc2009-04-10 14:24:30 -070048#include "BufferAllocator.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049#include "Layer.h"
50#include "LayerBlur.h"
51#include "LayerBuffer.h"
52#include "LayerDim.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054
55#include "DisplayHardware/DisplayHardware.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056
Mathias Agopiana1ecca92009-05-21 19:21:59 -070057/* ideally AID_GRAPHICS would be in a semi-public header
58 * or there would be a way to map a user/group name to its id
59 */
60#ifndef AID_GRAPHICS
61#define AID_GRAPHICS 1003
62#endif
63
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064#define DISPLAY_COUNT 1
65
66namespace android {
67
68// ---------------------------------------------------------------------------
69
70void SurfaceFlinger::instantiate() {
71 defaultServiceManager()->addService(
72 String16("SurfaceFlinger"), new SurfaceFlinger());
73}
74
75void SurfaceFlinger::shutdown() {
76 // we should unregister here, but not really because
77 // when (if) the service manager goes away, all the services
78 // it has a reference to will leave too.
79}
80
81// ---------------------------------------------------------------------------
82
83SurfaceFlinger::LayerVector::LayerVector(const SurfaceFlinger::LayerVector& rhs)
84 : lookup(rhs.lookup), layers(rhs.layers)
85{
86}
87
88ssize_t SurfaceFlinger::LayerVector::indexOf(
Mathias Agopian076b1cc2009-04-10 14:24:30 -070089 const sp<LayerBase>& key, size_t guess) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090{
91 if (guess<size() && lookup.keyAt(guess) == key)
92 return guess;
93 const ssize_t i = lookup.indexOfKey(key);
94 if (i>=0) {
95 const size_t idx = lookup.valueAt(i);
Mathias Agopian076b1cc2009-04-10 14:24:30 -070096 LOGE_IF(layers[idx]!=key,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097 "LayerVector[%p]: layers[%d]=%p, key=%p",
Mathias Agopian076b1cc2009-04-10 14:24:30 -070098 this, int(idx), layers[idx].get(), key.get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099 return idx;
100 }
101 return i;
102}
103
104ssize_t SurfaceFlinger::LayerVector::add(
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700105 const sp<LayerBase>& layer,
106 Vector< sp<LayerBase> >::compar_t cmp)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107{
108 size_t count = layers.size();
109 ssize_t l = 0;
110 ssize_t h = count-1;
111 ssize_t mid;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700112 sp<LayerBase> const* a = layers.array();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113 while (l <= h) {
114 mid = l + (h - l)/2;
115 const int c = cmp(a+mid, &layer);
116 if (c == 0) { l = mid; break; }
117 else if (c<0) { l = mid+1; }
118 else { h = mid-1; }
119 }
120 size_t order = l;
121 while (order<count && !cmp(&layer, a+order)) {
122 order++;
123 }
124 count = lookup.size();
125 for (size_t i=0 ; i<count ; i++) {
126 if (lookup.valueAt(i) >= order) {
127 lookup.editValueAt(i)++;
128 }
129 }
130 layers.insertAt(layer, order);
131 lookup.add(layer, order);
132 return order;
133}
134
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700135ssize_t SurfaceFlinger::LayerVector::remove(const sp<LayerBase>& layer)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800136{
137 const ssize_t keyIndex = lookup.indexOfKey(layer);
138 if (keyIndex >= 0) {
139 const size_t index = lookup.valueAt(keyIndex);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700140 LOGE_IF(layers[index]!=layer,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141 "LayerVector[%p]: layers[%u]=%p, layer=%p",
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700142 this, int(index), layers[index].get(), layer.get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 layers.removeItemsAt(index);
144 lookup.removeItemsAt(keyIndex);
145 const size_t count = lookup.size();
146 for (size_t i=0 ; i<count ; i++) {
147 if (lookup.valueAt(i) >= size_t(index)) {
148 lookup.editValueAt(i)--;
149 }
150 }
151 return index;
152 }
153 return NAME_NOT_FOUND;
154}
155
156ssize_t SurfaceFlinger::LayerVector::reorder(
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700157 const sp<LayerBase>& layer,
158 Vector< sp<LayerBase> >::compar_t cmp)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800159{
160 // XXX: it's a little lame. but oh well...
161 ssize_t err = remove(layer);
162 if (err >=0)
163 err = add(layer, cmp);
164 return err;
165}
166
167// ---------------------------------------------------------------------------
168#if 0
169#pragma mark -
170#endif
171
172SurfaceFlinger::SurfaceFlinger()
173 : BnSurfaceComposer(), Thread(false),
174 mTransactionFlags(0),
175 mTransactionCount(0),
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700176 mResizeTransationPending(false),
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700177 mLayersRemoved(false),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800178 mBootTime(systemTime()),
Mathias Agopian375f5632009-06-15 18:24:59 -0700179 mHardwareTest("android.permission.HARDWARE_TEST"),
180 mAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"),
181 mDump("android.permission.DUMP"),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800182 mVisibleRegionsDirty(false),
183 mDeferReleaseConsole(false),
184 mFreezeDisplay(false),
185 mFreezeCount(0),
The Android Open Source Projectbcef13b2009-03-11 12:11:56 -0700186 mFreezeDisplayTime(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800187 mDebugRegion(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800188 mDebugBackground(0),
Mathias Agopian9795c422009-08-26 16:36:26 -0700189 mDebugInSwapBuffers(0),
190 mLastSwapBufferTime(0),
191 mDebugInTransaction(0),
192 mLastTransactionTime(0),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800193 mConsoleSignals(0),
194 mSecureFrameBuffer(0)
195{
196 init();
197}
198
199void SurfaceFlinger::init()
200{
201 LOGI("SurfaceFlinger is starting");
202
203 // debugging stuff...
204 char value[PROPERTY_VALUE_MAX];
205 property_get("debug.sf.showupdates", value, "0");
206 mDebugRegion = atoi(value);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800207 property_get("debug.sf.showbackground", value, "0");
208 mDebugBackground = atoi(value);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800209
210 LOGI_IF(mDebugRegion, "showupdates enabled");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800211 LOGI_IF(mDebugBackground, "showbackground enabled");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800212}
213
214SurfaceFlinger::~SurfaceFlinger()
215{
216 glDeleteTextures(1, &mWormholeTexName);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800217}
218
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800219overlay_control_device_t* SurfaceFlinger::getOverlayEngine() const
220{
221 return graphicPlane(0).displayHardware().getOverlayEngine();
222}
223
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700224sp<IMemoryHeap> SurfaceFlinger::getCblk() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800225{
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700226 return mServerHeap;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800227}
228
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800229sp<ISurfaceFlingerClient> SurfaceFlinger::createConnection()
230{
231 Mutex::Autolock _l(mStateLock);
232 uint32_t token = mTokens.acquire();
233
Mathias Agopianf9d93272009-06-19 17:00:27 -0700234 sp<Client> client = new Client(token, this);
235 if (client->ctrlblk == 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800236 mTokens.release(token);
237 return 0;
238 }
239 status_t err = mClientsMap.add(token, client);
240 if (err < 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800241 mTokens.release(token);
242 return 0;
243 }
244 sp<BClient> bclient =
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700245 new BClient(this, token, client->getControlBlockMemory());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800246 return bclient;
247}
248
249void SurfaceFlinger::destroyConnection(ClientID cid)
250{
251 Mutex::Autolock _l(mStateLock);
Mathias Agopianf9d93272009-06-19 17:00:27 -0700252 sp<Client> client = mClientsMap.valueFor(cid);
253 if (client != 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800254 // free all the layers this client owns
Mathias Agopian3d579642009-06-04 18:46:21 -0700255 Vector< wp<LayerBaseClient> > layers(client->getLayers());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800256 const size_t count = layers.size();
257 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700258 sp<LayerBaseClient> layer(layers[i].promote());
259 if (layer != 0) {
Mathias Agopian3d579642009-06-04 18:46:21 -0700260 purgatorizeLayer_l(layer);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700261 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800262 }
263
264 // the resources associated with this client will be freed
265 // during the next transaction, after these surfaces have been
266 // properly removed from the screen
267
268 // remove this client from our ClientID->Client mapping.
269 mClientsMap.removeItem(cid);
270
271 // and add it to the list of disconnected clients
272 mDisconnectedClients.add(client);
273
274 // request a transaction
275 setTransactionFlags(eTransactionNeeded);
276 }
277}
278
279const GraphicPlane& SurfaceFlinger::graphicPlane(int dpy) const
280{
281 LOGE_IF(uint32_t(dpy) >= DISPLAY_COUNT, "Invalid DisplayID %d", dpy);
282 const GraphicPlane& plane(mGraphicPlanes[dpy]);
283 return plane;
284}
285
286GraphicPlane& SurfaceFlinger::graphicPlane(int dpy)
287{
288 return const_cast<GraphicPlane&>(
289 const_cast<SurfaceFlinger const *>(this)->graphicPlane(dpy));
290}
291
292void SurfaceFlinger::bootFinished()
293{
294 const nsecs_t now = systemTime();
295 const nsecs_t duration = now - mBootTime;
Mathias Agopiana1ecca92009-05-21 19:21:59 -0700296 LOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );
297 property_set("ctl.stop", "bootanim");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800298}
299
300void SurfaceFlinger::onFirstRef()
301{
302 run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY);
303
304 // Wait for the main thread to be done with its initialization
305 mReadyToRunBarrier.wait();
306}
307
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800308static inline uint16_t pack565(int r, int g, int b) {
309 return (r<<11)|(g<<5)|b;
310}
311
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800312status_t SurfaceFlinger::readyToRun()
313{
314 LOGI( "SurfaceFlinger's main thread ready to run. "
315 "Initializing graphics H/W...");
316
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800317 // we only support one display currently
318 int dpy = 0;
319
320 {
321 // initialize the main display
322 GraphicPlane& plane(graphicPlane(dpy));
323 DisplayHardware* const hw = new DisplayHardware(this, dpy);
324 plane.setDisplayHardware(hw);
325 }
326
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700327 // create the shared control-block
328 mServerHeap = new MemoryHeapBase(4096,
329 MemoryHeapBase::READ_ONLY, "SurfaceFlinger read-only heap");
330 LOGE_IF(mServerHeap==0, "can't create shared memory dealer");
331
332 mServerCblk = static_cast<surface_flinger_cblk_t*>(mServerHeap->getBase());
333 LOGE_IF(mServerCblk==0, "can't get to shared control block's address");
334
335 new(mServerCblk) surface_flinger_cblk_t;
336
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800337 // initialize primary screen
338 // (other display should be initialized in the same manner, but
339 // asynchronously, as they could come and go. None of this is supported
340 // yet).
341 const GraphicPlane& plane(graphicPlane(dpy));
342 const DisplayHardware& hw = plane.displayHardware();
343 const uint32_t w = hw.getWidth();
344 const uint32_t h = hw.getHeight();
345 const uint32_t f = hw.getFormat();
346 hw.makeCurrent();
347
348 // initialize the shared control block
349 mServerCblk->connected |= 1<<dpy;
350 display_cblk_t* dcblk = mServerCblk->displays + dpy;
351 memset(dcblk, 0, sizeof(display_cblk_t));
352 dcblk->w = w;
353 dcblk->h = h;
354 dcblk->format = f;
355 dcblk->orientation = ISurfaceComposer::eOrientationDefault;
356 dcblk->xdpi = hw.getDpiX();
357 dcblk->ydpi = hw.getDpiY();
358 dcblk->fps = hw.getRefreshRate();
359 dcblk->density = hw.getDensity();
360 asm volatile ("":::"memory");
361
362 // Initialize OpenGL|ES
363 glActiveTexture(GL_TEXTURE0);
364 glBindTexture(GL_TEXTURE_2D, 0);
365 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
366 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
367 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
368 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
369 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
370 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
371 glPixelStorei(GL_PACK_ALIGNMENT, 4);
372 glEnableClientState(GL_VERTEX_ARRAY);
373 glEnable(GL_SCISSOR_TEST);
374 glShadeModel(GL_FLAT);
375 glDisable(GL_DITHER);
376 glDisable(GL_CULL_FACE);
377
378 const uint16_t g0 = pack565(0x0F,0x1F,0x0F);
379 const uint16_t g1 = pack565(0x17,0x2f,0x17);
380 const uint16_t textureData[4] = { g0, g1, g1, g0 };
381 glGenTextures(1, &mWormholeTexName);
382 glBindTexture(GL_TEXTURE_2D, mWormholeTexName);
383 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
384 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
385 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
386 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
387 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0,
388 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, textureData);
389
390 glViewport(0, 0, w, h);
391 glMatrixMode(GL_PROJECTION);
392 glLoadIdentity();
393 glOrthof(0, w, h, 0, 0, 1);
394
395 LayerDim::initDimmer(this, w, h);
396
397 mReadyToRunBarrier.open();
398
399 /*
400 * We're now ready to accept clients...
401 */
402
Mathias Agopiana1ecca92009-05-21 19:21:59 -0700403 // start boot animation
404 property_set("ctl.start", "bootanim");
405
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800406 return NO_ERROR;
407}
408
409// ----------------------------------------------------------------------------
410#if 0
411#pragma mark -
412#pragma mark Events Handler
413#endif
414
415void SurfaceFlinger::waitForEvent()
416{
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700417 while (true) {
418 nsecs_t timeout = -1;
419 if (UNLIKELY(isFrozen())) {
420 // wait 5 seconds
421 const nsecs_t freezeDisplayTimeout = ms2ns(5000);
422 const nsecs_t now = systemTime();
423 if (mFreezeDisplayTime == 0) {
424 mFreezeDisplayTime = now;
425 }
426 nsecs_t waitTime = freezeDisplayTimeout - (now - mFreezeDisplayTime);
427 timeout = waitTime>0 ? waitTime : 0;
The Android Open Source Projectbcef13b2009-03-11 12:11:56 -0700428 }
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700429
Mathias Agopianb6683b52009-04-28 03:17:50 -0700430 MessageList::value_type msg = mEventQueue.waitMessage(timeout);
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700431 if (msg != 0) {
432 mFreezeDisplayTime = 0;
433 switch (msg->what) {
434 case MessageQueue::INVALIDATE:
435 // invalidate message, just return to the main loop
436 return;
437 }
438 } else {
439 // we timed out
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800440 if (isFrozen()) {
441 // we timed out and are still frozen
442 LOGW("timeout expired mFreezeDisplay=%d, mFreezeCount=%d",
443 mFreezeDisplay, mFreezeCount);
444 mFreezeCount = 0;
The Android Open Source Projectbcef13b2009-03-11 12:11:56 -0700445 mFreezeDisplay = false;
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700446 return;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800447 }
448 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800449 }
450}
451
452void SurfaceFlinger::signalEvent() {
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700453 mEventQueue.invalidate();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800454}
455
456void SurfaceFlinger::signal() const {
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700457 // this is the IPC call
458 const_cast<SurfaceFlinger*>(this)->signalEvent();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800459}
460
461void SurfaceFlinger::signalDelayedEvent(nsecs_t delay)
462{
Mathias Agopianf1d8e872009-04-20 19:39:12 -0700463 mEventQueue.postMessage( new MessageBase(MessageQueue::INVALIDATE), delay);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800464}
465
466// ----------------------------------------------------------------------------
467#if 0
468#pragma mark -
469#pragma mark Main loop
470#endif
471
472bool SurfaceFlinger::threadLoop()
473{
474 waitForEvent();
475
476 // check for transactions
477 if (UNLIKELY(mConsoleSignals)) {
478 handleConsoleEvents();
479 }
480
481 if (LIKELY(mTransactionCount == 0)) {
482 // if we're in a global transaction, don't do anything.
483 const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
484 uint32_t transactionFlags = getTransactionFlags(mask);
485 if (LIKELY(transactionFlags)) {
486 handleTransaction(transactionFlags);
487 }
488 }
489
490 // post surfaces (if needed)
491 handlePageFlip();
492
493 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopian8a77baa2009-09-27 22:47:27 -0700494 if (LIKELY(hw.canDraw() && !isFrozen())) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800495 // repaint the framebuffer (if needed)
496 handleRepaint();
497
Mathias Agopian74faca22009-09-17 16:18:16 -0700498 // inform the h/w that we're done compositing
499 hw.compositionComplete();
500
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800501 // release the clients before we flip ('cause flip might block)
502 unlockClients();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800503
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800504 postFramebuffer();
505 } else {
506 // pretend we did the post
507 unlockClients();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800508 usleep(16667); // 60 fps period
509 }
510 return true;
511}
512
513void SurfaceFlinger::postFramebuffer()
514{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800515 if (!mInvalidRegion.isEmpty()) {
516 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopian9795c422009-08-26 16:36:26 -0700517 const nsecs_t now = systemTime();
518 mDebugInSwapBuffers = now;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800519 hw.flip(mInvalidRegion);
Mathias Agopian9795c422009-08-26 16:36:26 -0700520 mLastSwapBufferTime = systemTime() - now;
521 mDebugInSwapBuffers = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800522 mInvalidRegion.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800523 }
524}
525
526void SurfaceFlinger::handleConsoleEvents()
527{
528 // something to do with the console
529 const DisplayHardware& hw = graphicPlane(0).displayHardware();
530
531 int what = android_atomic_and(0, &mConsoleSignals);
532 if (what & eConsoleAcquired) {
533 hw.acquireScreen();
534 }
535
536 if (mDeferReleaseConsole && hw.canDraw()) {
Mathias Agopian62b74442009-04-14 23:02:51 -0700537 // We got the release signal before the acquire signal
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800538 mDeferReleaseConsole = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800539 hw.releaseScreen();
540 }
541
542 if (what & eConsoleReleased) {
543 if (hw.canDraw()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800544 hw.releaseScreen();
545 } else {
546 mDeferReleaseConsole = true;
547 }
548 }
549
550 mDirtyRegion.set(hw.bounds());
551}
552
553void SurfaceFlinger::handleTransaction(uint32_t transactionFlags)
554{
Mathias Agopian3d579642009-06-04 18:46:21 -0700555 Vector< sp<LayerBase> > ditchedLayers;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800556
Mathias Agopian3d579642009-06-04 18:46:21 -0700557 { // scope for the lock
558 Mutex::Autolock _l(mStateLock);
Mathias Agopian9795c422009-08-26 16:36:26 -0700559 const nsecs_t now = systemTime();
560 mDebugInTransaction = now;
Mathias Agopian3d579642009-06-04 18:46:21 -0700561 handleTransactionLocked(transactionFlags, ditchedLayers);
Mathias Agopian9795c422009-08-26 16:36:26 -0700562 mLastTransactionTime = systemTime() - now;
563 mDebugInTransaction = 0;
Mathias Agopian3d579642009-06-04 18:46:21 -0700564 }
565
566 // do this without lock held
567 const size_t count = ditchedLayers.size();
568 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian0852e672009-09-04 19:50:23 -0700569 if (ditchedLayers[i] != 0) {
570 //LOGD("ditching layer %p", ditchedLayers[i].get());
571 ditchedLayers[i]->ditch();
572 }
Mathias Agopian3d579642009-06-04 18:46:21 -0700573 }
574}
575
576void SurfaceFlinger::handleTransactionLocked(
577 uint32_t transactionFlags, Vector< sp<LayerBase> >& ditchedLayers)
578{
579 const LayerVector& currentLayers(mCurrentState.layersSortedByZ);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800580 const size_t count = currentLayers.size();
581
582 /*
583 * Traversal of the children
584 * (perform the transaction for each of them if needed)
585 */
586
587 const bool layersNeedTransaction = transactionFlags & eTraversalNeeded;
588 if (layersNeedTransaction) {
589 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700590 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800591 uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded);
592 if (!trFlags) continue;
593
594 const uint32_t flags = layer->doTransaction(0);
595 if (flags & Layer::eVisibleRegion)
596 mVisibleRegionsDirty = true;
597
598 if (flags & Layer::eRestartTransaction) {
599 // restart the transaction, but back-off a little
600 layer->setTransactionFlags(eTransactionNeeded);
601 setTransactionFlags(eTraversalNeeded, ms2ns(8));
602 }
603 }
604 }
605
606 /*
607 * Perform our own transaction if needed
608 */
609
610 if (transactionFlags & eTransactionNeeded) {
611 if (mCurrentState.orientation != mDrawingState.orientation) {
612 // the orientation has changed, recompute all visible regions
613 // and invalidate everything.
614
615 const int dpy = 0;
616 const int orientation = mCurrentState.orientation;
Mathias Agopianc08731e2009-03-27 18:11:38 -0700617 const uint32_t type = mCurrentState.orientationType;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800618 GraphicPlane& plane(graphicPlane(dpy));
619 plane.setOrientation(orientation);
620
621 // update the shared control block
622 const DisplayHardware& hw(plane.displayHardware());
623 volatile display_cblk_t* dcblk = mServerCblk->displays + dpy;
624 dcblk->orientation = orientation;
625 if (orientation & eOrientationSwapMask) {
626 // 90 or 270 degrees orientation
627 dcblk->w = hw.getHeight();
628 dcblk->h = hw.getWidth();
629 } else {
630 dcblk->w = hw.getWidth();
631 dcblk->h = hw.getHeight();
632 }
633
634 mVisibleRegionsDirty = true;
635 mDirtyRegion.set(hw.bounds());
Mathias Agopianc08731e2009-03-27 18:11:38 -0700636 mFreezeDisplayTime = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800637 }
638
639 if (mCurrentState.freezeDisplay != mDrawingState.freezeDisplay) {
640 // freezing or unfreezing the display -> trigger animation if needed
641 mFreezeDisplay = mCurrentState.freezeDisplay;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800642 }
643
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700644 if (currentLayers.size() > mDrawingState.layersSortedByZ.size()) {
645 // layers have been added
646 mVisibleRegionsDirty = true;
647 }
648
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800649 // some layers might have been removed, so
650 // we need to update the regions they're exposing.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700651 if (mLayersRemoved) {
Mathias Agopian48d819a2009-09-10 19:41:18 -0700652 mLayersRemoved = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800653 mVisibleRegionsDirty = true;
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700654 const LayerVector& previousLayers(mDrawingState.layersSortedByZ);
Mathias Agopian3d579642009-06-04 18:46:21 -0700655 const size_t count = previousLayers.size();
656 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700657 const sp<LayerBase>& layer(previousLayers[i]);
658 if (currentLayers.indexOf( layer ) < 0) {
659 // this layer is not visible anymore
Mathias Agopian3d579642009-06-04 18:46:21 -0700660 ditchedLayers.add(layer);
Mathias Agopian5d7126b2009-07-28 14:20:21 -0700661 mDirtyRegionRemovedLayer.orSelf(layer->visibleRegionScreen);
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700662 }
663 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800664 }
665
666 // get rid of all resources we don't need anymore
667 // (layers and clients)
668 free_resources_l();
669 }
670
671 commitTransaction();
672}
673
674sp<FreezeLock> SurfaceFlinger::getFreezeLock() const
675{
676 return new FreezeLock(const_cast<SurfaceFlinger *>(this));
677}
678
679void SurfaceFlinger::computeVisibleRegions(
680 LayerVector& currentLayers, Region& dirtyRegion, Region& opaqueRegion)
681{
682 const GraphicPlane& plane(graphicPlane(0));
683 const Transform& planeTransform(plane.transform());
684
685 Region aboveOpaqueLayers;
686 Region aboveCoveredLayers;
687 Region dirty;
688
689 bool secureFrameBuffer = false;
690
691 size_t i = currentLayers.size();
692 while (i--) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700693 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800694 layer->validateVisibility(planeTransform);
695
696 // start with the whole surface at its current location
Mathias Agopian97011222009-07-28 10:57:27 -0700697 const Layer::State& s(layer->drawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800698
699 // handle hidden surfaces by setting the visible region to empty
700 Region opaqueRegion;
701 Region visibleRegion;
702 Region coveredRegion;
Mathias Agopian97011222009-07-28 10:57:27 -0700703 if (LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800704 const bool translucent = layer->needsBlending();
Mathias Agopian97011222009-07-28 10:57:27 -0700705 const Rect bounds(layer->visibleBounds());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800706 visibleRegion.set(bounds);
707 coveredRegion = visibleRegion;
708
709 // Remove the transparent area from the visible region
710 if (translucent) {
711 visibleRegion.subtractSelf(layer->transparentRegionScreen);
712 }
713
714 // compute the opaque region
715 if (s.alpha==255 && !translucent && layer->getOrientation()>=0) {
716 // the opaque region is the visible region
717 opaqueRegion = visibleRegion;
718 }
719 }
720
721 // subtract the opaque region covered by the layers above us
722 visibleRegion.subtractSelf(aboveOpaqueLayers);
723 coveredRegion.andSelf(aboveCoveredLayers);
724
725 // compute this layer's dirty region
726 if (layer->contentDirty) {
727 // we need to invalidate the whole region
728 dirty = visibleRegion;
729 // as well, as the old visible region
730 dirty.orSelf(layer->visibleRegionScreen);
731 layer->contentDirty = false;
732 } else {
Mathias Agopiana8d44f72009-06-28 02:54:16 -0700733 /* compute the exposed region:
734 * exposed = what's VISIBLE and NOT COVERED now
735 * but was COVERED before
736 */
737 dirty = (visibleRegion - coveredRegion) & layer->coveredRegionScreen;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800738 }
739 dirty.subtractSelf(aboveOpaqueLayers);
740
741 // accumulate to the screen dirty region
742 dirtyRegion.orSelf(dirty);
743
Mathias Agopian62b74442009-04-14 23:02:51 -0700744 // Update aboveOpaqueLayers/aboveCoveredLayers for next (lower) layer
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800745 aboveOpaqueLayers.orSelf(opaqueRegion);
Mathias Agopiana8d44f72009-06-28 02:54:16 -0700746 aboveCoveredLayers.orSelf(visibleRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800747
748 // Store the visible region is screen space
749 layer->setVisibleRegion(visibleRegion);
750 layer->setCoveredRegion(coveredRegion);
751
Mathias Agopian97011222009-07-28 10:57:27 -0700752 // If a secure layer is partially visible, lock-down the screen!
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800753 if (layer->isSecure() && !visibleRegion.isEmpty()) {
754 secureFrameBuffer = true;
755 }
756 }
757
Mathias Agopian97011222009-07-28 10:57:27 -0700758 // invalidate the areas where a layer was removed
759 dirtyRegion.orSelf(mDirtyRegionRemovedLayer);
760 mDirtyRegionRemovedLayer.clear();
761
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800762 mSecureFrameBuffer = secureFrameBuffer;
763 opaqueRegion = aboveOpaqueLayers;
764}
765
766
767void SurfaceFlinger::commitTransaction()
768{
769 mDrawingState = mCurrentState;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700770 mResizeTransationPending = false;
771 mTransactionCV.broadcast();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800772}
773
774void SurfaceFlinger::handlePageFlip()
775{
776 bool visibleRegions = mVisibleRegionsDirty;
777 LayerVector& currentLayers = const_cast<LayerVector&>(mDrawingState.layersSortedByZ);
778 visibleRegions |= lockPageFlip(currentLayers);
779
780 const DisplayHardware& hw = graphicPlane(0).displayHardware();
781 const Region screenRegion(hw.bounds());
782 if (visibleRegions) {
783 Region opaqueRegion;
784 computeVisibleRegions(currentLayers, mDirtyRegion, opaqueRegion);
785 mWormholeRegion = screenRegion.subtract(opaqueRegion);
786 mVisibleRegionsDirty = false;
787 }
788
789 unlockPageFlip(currentLayers);
790 mDirtyRegion.andSelf(screenRegion);
791}
792
793bool SurfaceFlinger::lockPageFlip(const LayerVector& currentLayers)
794{
795 bool recomputeVisibleRegions = false;
796 size_t count = currentLayers.size();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700797 sp<LayerBase> const* layers = currentLayers.array();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800798 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700799 const sp<LayerBase>& layer = layers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800800 layer->lockPageFlip(recomputeVisibleRegions);
801 }
802 return recomputeVisibleRegions;
803}
804
805void SurfaceFlinger::unlockPageFlip(const LayerVector& currentLayers)
806{
807 const GraphicPlane& plane(graphicPlane(0));
808 const Transform& planeTransform(plane.transform());
809 size_t count = currentLayers.size();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700810 sp<LayerBase> const* layers = currentLayers.array();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800811 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700812 const sp<LayerBase>& layer = layers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800813 layer->unlockPageFlip(planeTransform, mDirtyRegion);
814 }
815}
816
Mathias Agopianb8a55602009-06-26 19:06:36 -0700817
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800818void SurfaceFlinger::handleRepaint()
819{
Mathias Agopianb8a55602009-06-26 19:06:36 -0700820 // compute the invalid region
821 mInvalidRegion.orSelf(mDirtyRegion);
822 if (mInvalidRegion.isEmpty()) {
823 // nothing to do
824 return;
825 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800826
827 if (UNLIKELY(mDebugRegion)) {
828 debugFlashRegions();
829 }
830
Mathias Agopianb8a55602009-06-26 19:06:36 -0700831 // set the frame buffer
832 const DisplayHardware& hw(graphicPlane(0).displayHardware());
833 glMatrixMode(GL_MODELVIEW);
834 glLoadIdentity();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800835
836 uint32_t flags = hw.getFlags();
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700837 if ((flags & DisplayHardware::SWAP_RECTANGLE) ||
838 (flags & DisplayHardware::BUFFER_PRESERVED))
839 {
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700840 // we can redraw only what's dirty, but since SWAP_RECTANGLE only
841 // takes a rectangle, we must make sure to update that whole
842 // rectangle in that case
843 if (flags & DisplayHardware::SWAP_RECTANGLE) {
844 // FIXME: we really should be able to pass a region to
845 // SWAP_RECTANGLE so that we don't have to redraw all this.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800846 mDirtyRegion.set(mInvalidRegion.bounds());
847 } else {
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700848 // in the BUFFER_PRESERVED case, obviously, we can update only
849 // what's needed and nothing more.
850 // NOTE: this is NOT a common case, as preserving the backbuffer
851 // is costly and usually involves copying the whole update back.
852 }
853 } else {
Mathias Agopian95a666b2009-09-24 14:57:26 -0700854 if (flags & DisplayHardware::PARTIAL_UPDATES) {
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700855 // We need to redraw the rectangle that will be updated
856 // (pushed to the framebuffer).
Mathias Agopian95a666b2009-09-24 14:57:26 -0700857 // This is needed because PARTIAL_UPDATES only takes one
Mathias Agopian29d06ac2009-06-29 18:49:56 -0700858 // rectangle instead of a region (see DisplayHardware::flip())
859 mDirtyRegion.set(mInvalidRegion.bounds());
860 } else {
861 // we need to redraw everything (the whole screen)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800862 mDirtyRegion.set(hw.bounds());
863 mInvalidRegion = mDirtyRegion;
864 }
865 }
866
867 // compose all surfaces
868 composeSurfaces(mDirtyRegion);
869
870 // clear the dirty regions
871 mDirtyRegion.clear();
872}
873
874void SurfaceFlinger::composeSurfaces(const Region& dirty)
875{
876 if (UNLIKELY(!mWormholeRegion.isEmpty())) {
877 // should never happen unless the window manager has a bug
878 // draw something...
879 drawWormhole();
880 }
881 const SurfaceFlinger& flinger(*this);
882 const LayerVector& drawingLayers(mDrawingState.layersSortedByZ);
883 const size_t count = drawingLayers.size();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700884 sp<LayerBase> const* const layers = drawingLayers.array();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800885 for (size_t i=0 ; i<count ; ++i) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700886 const sp<LayerBase>& layer = layers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800887 const Region& visibleRegion(layer->visibleRegionScreen);
888 if (!visibleRegion.isEmpty()) {
889 const Region clip(dirty.intersect(visibleRegion));
890 if (!clip.isEmpty()) {
891 layer->draw(clip);
892 }
893 }
894 }
895}
896
897void SurfaceFlinger::unlockClients()
898{
899 const LayerVector& drawingLayers(mDrawingState.layersSortedByZ);
900 const size_t count = drawingLayers.size();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700901 sp<LayerBase> const* const layers = drawingLayers.array();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800902 for (size_t i=0 ; i<count ; ++i) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700903 const sp<LayerBase>& layer = layers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800904 layer->finishPageFlip();
905 }
906}
907
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800908void SurfaceFlinger::debugFlashRegions()
909{
Mathias Agopian0926f502009-05-04 14:17:04 -0700910 const DisplayHardware& hw(graphicPlane(0).displayHardware());
911 const uint32_t flags = hw.getFlags();
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700912
913 if (!((flags & DisplayHardware::SWAP_RECTANGLE) ||
914 (flags & DisplayHardware::BUFFER_PRESERVED))) {
Mathias Agopian95a666b2009-09-24 14:57:26 -0700915 const Region repaint((flags & DisplayHardware::PARTIAL_UPDATES) ?
Mathias Agopian0926f502009-05-04 14:17:04 -0700916 mDirtyRegion.bounds() : hw.bounds());
917 composeSurfaces(repaint);
918 }
919
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800920 glDisable(GL_TEXTURE_2D);
921 glDisable(GL_BLEND);
922 glDisable(GL_DITHER);
923 glDisable(GL_SCISSOR_TEST);
924
Mathias Agopian0926f502009-05-04 14:17:04 -0700925 static int toggle = 0;
926 toggle = 1 - toggle;
927 if (toggle) {
928 glColor4x(0x10000, 0, 0x10000, 0x10000);
929 } else {
930 glColor4x(0x10000, 0x10000, 0, 0x10000);
931 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800932
Mathias Agopian20f68782009-05-11 00:03:41 -0700933 Region::const_iterator it = mDirtyRegion.begin();
934 Region::const_iterator const end = mDirtyRegion.end();
935 while (it != end) {
936 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800937 GLfloat vertices[][2] = {
938 { r.left, r.top },
939 { r.left, r.bottom },
940 { r.right, r.bottom },
941 { r.right, r.top }
942 };
943 glVertexPointer(2, GL_FLOAT, 0, vertices);
944 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
945 }
Mathias Agopian0926f502009-05-04 14:17:04 -0700946
Mathias Agopianb8a55602009-06-26 19:06:36 -0700947 if (mInvalidRegion.isEmpty()) {
948 mDirtyRegion.dump("mDirtyRegion");
949 mInvalidRegion.dump("mInvalidRegion");
950 }
951 hw.flip(mInvalidRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800952
953 if (mDebugRegion > 1)
954 usleep(mDebugRegion * 1000);
955
956 glEnable(GL_SCISSOR_TEST);
957 //mDirtyRegion.dump("mDirtyRegion");
958}
959
960void SurfaceFlinger::drawWormhole() const
961{
962 const Region region(mWormholeRegion.intersect(mDirtyRegion));
963 if (region.isEmpty())
964 return;
965
966 const DisplayHardware& hw(graphicPlane(0).displayHardware());
967 const int32_t width = hw.getWidth();
968 const int32_t height = hw.getHeight();
969
970 glDisable(GL_BLEND);
971 glDisable(GL_DITHER);
972
973 if (LIKELY(!mDebugBackground)) {
974 glClearColorx(0,0,0,0);
Mathias Agopian20f68782009-05-11 00:03:41 -0700975 Region::const_iterator it = region.begin();
976 Region::const_iterator const end = region.end();
977 while (it != end) {
978 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800979 const GLint sy = height - (r.top + r.height());
980 glScissor(r.left, sy, r.width(), r.height());
981 glClear(GL_COLOR_BUFFER_BIT);
982 }
983 } else {
984 const GLshort vertices[][2] = { { 0, 0 }, { width, 0 },
985 { width, height }, { 0, height } };
986 const GLshort tcoords[][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } };
987 glVertexPointer(2, GL_SHORT, 0, vertices);
988 glTexCoordPointer(2, GL_SHORT, 0, tcoords);
989 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
990 glEnable(GL_TEXTURE_2D);
991 glBindTexture(GL_TEXTURE_2D, mWormholeTexName);
992 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
993 glMatrixMode(GL_TEXTURE);
994 glLoadIdentity();
995 glScalef(width*(1.0f/32.0f), height*(1.0f/32.0f), 1);
Mathias Agopian20f68782009-05-11 00:03:41 -0700996 Region::const_iterator it = region.begin();
997 Region::const_iterator const end = region.end();
998 while (it != end) {
999 const Rect& r = *it++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001000 const GLint sy = height - (r.top + r.height());
1001 glScissor(r.left, sy, r.width(), r.height());
1002 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1003 }
1004 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1005 }
1006}
1007
1008void SurfaceFlinger::debugShowFPS() const
1009{
1010 static int mFrameCount;
1011 static int mLastFrameCount = 0;
1012 static nsecs_t mLastFpsTime = 0;
1013 static float mFps = 0;
1014 mFrameCount++;
1015 nsecs_t now = systemTime();
1016 nsecs_t diff = now - mLastFpsTime;
1017 if (diff > ms2ns(250)) {
1018 mFps = ((mFrameCount - mLastFrameCount) * float(s2ns(1))) / diff;
1019 mLastFpsTime = now;
1020 mLastFrameCount = mFrameCount;
1021 }
1022 // XXX: mFPS has the value we want
1023 }
1024
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001025status_t SurfaceFlinger::addLayer(const sp<LayerBase>& layer)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001026{
1027 Mutex::Autolock _l(mStateLock);
1028 addLayer_l(layer);
1029 setTransactionFlags(eTransactionNeeded|eTraversalNeeded);
1030 return NO_ERROR;
1031}
1032
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001033status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001034{
1035 Mutex::Autolock _l(mStateLock);
Mathias Agopian3d579642009-06-04 18:46:21 -07001036 status_t err = purgatorizeLayer_l(layer);
1037 if (err == NO_ERROR)
1038 setTransactionFlags(eTransactionNeeded);
1039 return err;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001040}
1041
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001042status_t SurfaceFlinger::invalidateLayerVisibility(const sp<LayerBase>& layer)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001043{
1044 layer->forceVisibilityTransaction();
1045 setTransactionFlags(eTraversalNeeded);
1046 return NO_ERROR;
1047}
1048
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001049status_t SurfaceFlinger::addLayer_l(const sp<LayerBase>& layer)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001050{
Mathias Agopian0852e672009-09-04 19:50:23 -07001051 if (layer == 0)
1052 return BAD_VALUE;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001053 ssize_t i = mCurrentState.layersSortedByZ.add(
1054 layer, &LayerBase::compareCurrentStateZ);
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001055 sp<LayerBaseClient> lbc = LayerBase::dynamicCast< LayerBaseClient* >(layer.get());
1056 if (lbc != 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001057 mLayerMap.add(lbc->serverIndex(), lbc);
1058 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001059 return NO_ERROR;
1060}
1061
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001062status_t SurfaceFlinger::removeLayer_l(const sp<LayerBase>& layerBase)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001063{
1064 ssize_t index = mCurrentState.layersSortedByZ.remove(layerBase);
1065 if (index >= 0) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001066 mLayersRemoved = true;
Mathias Agopian9a112062009-04-17 19:36:26 -07001067 sp<LayerBaseClient> layer =
1068 LayerBase::dynamicCast< LayerBaseClient* >(layerBase.get());
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001069 if (layer != 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001070 mLayerMap.removeItem(layer->serverIndex());
1071 }
1072 return NO_ERROR;
1073 }
Mathias Agopian3d579642009-06-04 18:46:21 -07001074 return status_t(index);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001075}
1076
Mathias Agopian9a112062009-04-17 19:36:26 -07001077status_t SurfaceFlinger::purgatorizeLayer_l(const sp<LayerBase>& layerBase)
1078{
Mathias Agopian8c0a3d72009-09-23 16:44:00 -07001079 // remove the layer from the main list (through a transaction).
Mathias Agopian9a112062009-04-17 19:36:26 -07001080 ssize_t err = removeLayer_l(layerBase);
Mathias Agopian8c0a3d72009-09-23 16:44:00 -07001081
Mathias Agopian3d579642009-06-04 18:46:21 -07001082 // it's possible that we don't find a layer, because it might
1083 // have been destroyed already -- this is not technically an error
1084 // from the user because there is a race between BClient::destroySurface(),
1085 // ~BClient() and ~ISurface().
Mathias Agopian9a112062009-04-17 19:36:26 -07001086 return (err == NAME_NOT_FOUND) ? status_t(NO_ERROR) : err;
1087}
1088
1089
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001090void SurfaceFlinger::free_resources_l()
1091{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001092 // free resources associated with disconnected clients
Mathias Agopianf9d93272009-06-19 17:00:27 -07001093 Vector< sp<Client> >& disconnectedClients(mDisconnectedClients);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001094 const size_t count = disconnectedClients.size();
1095 for (size_t i=0 ; i<count ; i++) {
Mathias Agopianf9d93272009-06-19 17:00:27 -07001096 sp<Client> client = disconnectedClients[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001097 mTokens.release(client->cid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001098 }
1099 disconnectedClients.clear();
1100}
1101
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001102uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags)
1103{
1104 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1105}
1106
1107uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags, nsecs_t delay)
1108{
1109 uint32_t old = android_atomic_or(flags, &mTransactionFlags);
1110 if ((old & flags)==0) { // wake the server up
1111 if (delay > 0) {
1112 signalDelayedEvent(delay);
1113 } else {
1114 signalEvent();
1115 }
1116 }
1117 return old;
1118}
1119
1120void SurfaceFlinger::openGlobalTransaction()
1121{
1122 android_atomic_inc(&mTransactionCount);
1123}
1124
1125void SurfaceFlinger::closeGlobalTransaction()
1126{
1127 if (android_atomic_dec(&mTransactionCount) == 1) {
1128 signalEvent();
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001129
1130 // if there is a transaction with a resize, wait for it to
1131 // take effect before returning.
1132 Mutex::Autolock _l(mStateLock);
1133 while (mResizeTransationPending) {
1134 mTransactionCV.wait(mStateLock);
1135 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001136 }
1137}
1138
1139status_t SurfaceFlinger::freezeDisplay(DisplayID dpy, uint32_t flags)
1140{
1141 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
1142 return BAD_VALUE;
1143
1144 Mutex::Autolock _l(mStateLock);
1145 mCurrentState.freezeDisplay = 1;
1146 setTransactionFlags(eTransactionNeeded);
1147
1148 // flags is intended to communicate some sort of animation behavior
Mathias Agopian62b74442009-04-14 23:02:51 -07001149 // (for instance fading)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001150 return NO_ERROR;
1151}
1152
1153status_t SurfaceFlinger::unfreezeDisplay(DisplayID dpy, uint32_t flags)
1154{
1155 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
1156 return BAD_VALUE;
1157
1158 Mutex::Autolock _l(mStateLock);
1159 mCurrentState.freezeDisplay = 0;
1160 setTransactionFlags(eTransactionNeeded);
1161
1162 // flags is intended to communicate some sort of animation behavior
Mathias Agopian62b74442009-04-14 23:02:51 -07001163 // (for instance fading)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001164 return NO_ERROR;
1165}
1166
Mathias Agopianc08731e2009-03-27 18:11:38 -07001167int SurfaceFlinger::setOrientation(DisplayID dpy,
1168 int orientation, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001169{
1170 if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
1171 return BAD_VALUE;
1172
1173 Mutex::Autolock _l(mStateLock);
1174 if (mCurrentState.orientation != orientation) {
1175 if (uint32_t(orientation)<=eOrientation270 || orientation==42) {
Mathias Agopianc08731e2009-03-27 18:11:38 -07001176 mCurrentState.orientationType = flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001177 mCurrentState.orientation = orientation;
1178 setTransactionFlags(eTransactionNeeded);
1179 mTransactionCV.wait(mStateLock);
1180 } else {
1181 orientation = BAD_VALUE;
1182 }
1183 }
1184 return orientation;
1185}
1186
1187sp<ISurface> SurfaceFlinger::createSurface(ClientID clientId, int pid,
1188 ISurfaceFlingerClient::surface_data_t* params,
1189 DisplayID d, uint32_t w, uint32_t h, PixelFormat format,
1190 uint32_t flags)
1191{
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001192 sp<LayerBaseClient> layer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001193 sp<LayerBaseClient::Surface> surfaceHandle;
Mathias Agopian6e2d6482009-07-09 18:16:43 -07001194
1195 if (int32_t(w|h) < 0) {
1196 LOGE("createSurface() failed, w or h is negative (w=%d, h=%d)",
1197 int(w), int(h));
1198 return surfaceHandle;
1199 }
1200
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001201 Mutex::Autolock _l(mStateLock);
Mathias Agopianf9d93272009-06-19 17:00:27 -07001202 sp<Client> client = mClientsMap.valueFor(clientId);
1203 if (UNLIKELY(client == 0)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001204 LOGE("createSurface() failed, client not found (id=%d)", clientId);
1205 return surfaceHandle;
1206 }
1207
1208 //LOGD("createSurface for pid %d (%d x %d)", pid, w, h);
Mathias Agopianf9d93272009-06-19 17:00:27 -07001209 int32_t id = client->generateId(pid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001210 if (uint32_t(id) >= NUM_LAYERS_MAX) {
1211 LOGE("createSurface() failed, generateId = %d", id);
1212 return surfaceHandle;
1213 }
1214
1215 switch (flags & eFXSurfaceMask) {
1216 case eFXSurfaceNormal:
1217 if (UNLIKELY(flags & ePushBuffers)) {
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001218 layer = createPushBuffersSurfaceLocked(client, d, id,
1219 w, h, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001220 } else {
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001221 layer = createNormalSurfaceLocked(client, d, id,
1222 w, h, flags, format);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001223 }
1224 break;
1225 case eFXSurfaceBlur:
Mathias Agopianf9d93272009-06-19 17:00:27 -07001226 layer = createBlurSurfaceLocked(client, d, id, w, h, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001227 break;
1228 case eFXSurfaceDim:
Mathias Agopianf9d93272009-06-19 17:00:27 -07001229 layer = createDimSurfaceLocked(client, d, id, w, h, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001230 break;
1231 }
1232
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001233 if (layer != 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001234 setTransactionFlags(eTransactionNeeded);
1235 surfaceHandle = layer->getSurface();
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001236 if (surfaceHandle != 0) {
1237 params->token = surfaceHandle->getToken();
1238 params->identity = surfaceHandle->getIdentity();
1239 params->width = w;
1240 params->height = h;
1241 params->format = format;
1242 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001243 }
1244
1245 return surfaceHandle;
1246}
1247
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001248sp<LayerBaseClient> SurfaceFlinger::createNormalSurfaceLocked(
Mathias Agopianf9d93272009-06-19 17:00:27 -07001249 const sp<Client>& client, DisplayID display,
Mathias Agopian1c97d2e2009-08-19 17:46:26 -07001250 int32_t id, uint32_t w, uint32_t h, uint32_t flags,
1251 PixelFormat& format)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001252{
1253 // initialize the surfaces
1254 switch (format) { // TODO: take h/w into account
1255 case PIXEL_FORMAT_TRANSPARENT:
1256 case PIXEL_FORMAT_TRANSLUCENT:
1257 format = PIXEL_FORMAT_RGBA_8888;
1258 break;
1259 case PIXEL_FORMAT_OPAQUE:
1260 format = PIXEL_FORMAT_RGB_565;
1261 break;
1262 }
1263
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001264 sp<Layer> layer = new Layer(this, display, client, id);
Mathias Agopianf9d93272009-06-19 17:00:27 -07001265 status_t err = layer->setBuffers(w, h, format, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001266 if (LIKELY(err == NO_ERROR)) {
1267 layer->initStates(w, h, flags);
1268 addLayer_l(layer);
1269 } else {
1270 LOGE("createNormalSurfaceLocked() failed (%s)", strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001271 layer.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001272 }
1273 return layer;
1274}
1275
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001276sp<LayerBaseClient> SurfaceFlinger::createBlurSurfaceLocked(
Mathias Agopianf9d93272009-06-19 17:00:27 -07001277 const sp<Client>& client, DisplayID display,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001278 int32_t id, uint32_t w, uint32_t h, uint32_t flags)
1279{
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001280 sp<LayerBlur> layer = new LayerBlur(this, display, client, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001281 layer->initStates(w, h, flags);
1282 addLayer_l(layer);
1283 return layer;
1284}
1285
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001286sp<LayerBaseClient> SurfaceFlinger::createDimSurfaceLocked(
Mathias Agopianf9d93272009-06-19 17:00:27 -07001287 const sp<Client>& client, DisplayID display,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001288 int32_t id, uint32_t w, uint32_t h, uint32_t flags)
1289{
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001290 sp<LayerDim> layer = new LayerDim(this, display, client, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001291 layer->initStates(w, h, flags);
1292 addLayer_l(layer);
1293 return layer;
1294}
1295
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001296sp<LayerBaseClient> SurfaceFlinger::createPushBuffersSurfaceLocked(
Mathias Agopianf9d93272009-06-19 17:00:27 -07001297 const sp<Client>& client, DisplayID display,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001298 int32_t id, uint32_t w, uint32_t h, uint32_t flags)
1299{
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001300 sp<LayerBuffer> layer = new LayerBuffer(this, display, client, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001301 layer->initStates(w, h, flags);
1302 addLayer_l(layer);
1303 return layer;
1304}
1305
Mathias Agopian9a112062009-04-17 19:36:26 -07001306status_t SurfaceFlinger::removeSurface(SurfaceID index)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001307{
Mathias Agopian9a112062009-04-17 19:36:26 -07001308 /*
1309 * called by the window manager, when a surface should be marked for
1310 * destruction.
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001311 *
1312 * The surface is removed from the current and drawing lists, but placed
1313 * in the purgatory queue, so it's not destroyed right-away (we need
1314 * to wait for all client's references to go away first).
Mathias Agopian9a112062009-04-17 19:36:26 -07001315 */
Mathias Agopian9a112062009-04-17 19:36:26 -07001316
Mathias Agopian48d819a2009-09-10 19:41:18 -07001317 status_t err = NAME_NOT_FOUND;
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001318 Mutex::Autolock _l(mStateLock);
1319 sp<LayerBaseClient> layer = getLayerUser_l(index);
Mathias Agopian48d819a2009-09-10 19:41:18 -07001320 if (layer != 0) {
1321 err = purgatorizeLayer_l(layer);
1322 if (err == NO_ERROR) {
1323 layer->onRemoved();
1324 setTransactionFlags(eTransactionNeeded);
1325 }
Mathias Agopian9a112062009-04-17 19:36:26 -07001326 }
1327 return err;
1328}
1329
1330status_t SurfaceFlinger::destroySurface(const sp<LayerBaseClient>& layer)
1331{
Mathias Agopian759fdb22009-07-02 17:33:40 -07001332 // called by ~ISurface() when all references are gone
Mathias Agopian9a112062009-04-17 19:36:26 -07001333
Mathias Agopianf1d8e872009-04-20 19:39:12 -07001334 class MessageDestroySurface : public MessageBase {
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001335 SurfaceFlinger* flinger;
Mathias Agopianf1d8e872009-04-20 19:39:12 -07001336 sp<LayerBaseClient> layer;
1337 public:
Mathias Agopian0aa758d2009-04-22 15:23:34 -07001338 MessageDestroySurface(
1339 SurfaceFlinger* flinger, const sp<LayerBaseClient>& layer)
1340 : flinger(flinger), layer(layer) { }
Mathias Agopianf1d8e872009-04-20 19:39:12 -07001341 virtual bool handler() {
Mathias Agopiancd8c5e22009-06-19 16:24:02 -07001342 sp<LayerBaseClient> l(layer);
1343 layer.clear(); // clear it outside of the lock;
Mathias Agopianf1d8e872009-04-20 19:39:12 -07001344 Mutex::Autolock _l(flinger->mStateLock);
Mathias Agopian759fdb22009-07-02 17:33:40 -07001345 /*
1346 * remove the layer from the current list -- chances are that it's
1347 * not in the list anyway, because it should have been removed
1348 * already upon request of the client (eg: window manager).
1349 * However, a buggy client could have not done that.
1350 * Since we know we don't have any more clients, we don't need
1351 * to use the purgatory.
1352 */
Mathias Agopiancd8c5e22009-06-19 16:24:02 -07001353 status_t err = flinger->removeLayer_l(l);
Mathias Agopian8c0a3d72009-09-23 16:44:00 -07001354 LOGE_IF(err<0 && err != NAME_NOT_FOUND,
1355 "error removing layer=%p (%s)", l.get(), strerror(-err));
Mathias Agopianf1d8e872009-04-20 19:39:12 -07001356 return true;
1357 }
1358 };
Mathias Agopian3d579642009-06-04 18:46:21 -07001359
Mathias Agopianf1d8e872009-04-20 19:39:12 -07001360 mEventQueue.postMessage( new MessageDestroySurface(this, layer) );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001361 return NO_ERROR;
1362}
1363
1364status_t SurfaceFlinger::setClientState(
1365 ClientID cid,
1366 int32_t count,
1367 const layer_state_t* states)
1368{
1369 Mutex::Autolock _l(mStateLock);
1370 uint32_t flags = 0;
1371 cid <<= 16;
1372 for (int i=0 ; i<count ; i++) {
1373 const layer_state_t& s = states[i];
Mathias Agopian3d579642009-06-04 18:46:21 -07001374 sp<LayerBaseClient> layer(getLayerUser_l(s.surface | cid));
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001375 if (layer != 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001376 const uint32_t what = s.what;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001377 if (what & ePositionChanged) {
1378 if (layer->setPosition(s.x, s.y))
1379 flags |= eTraversalNeeded;
1380 }
1381 if (what & eLayerChanged) {
1382 if (layer->setLayer(s.z)) {
1383 mCurrentState.layersSortedByZ.reorder(
1384 layer, &Layer::compareCurrentStateZ);
1385 // we need traversal (state changed)
1386 // AND transaction (list changed)
1387 flags |= eTransactionNeeded|eTraversalNeeded;
1388 }
1389 }
1390 if (what & eSizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001391 if (layer->setSize(s.w, s.h)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001392 flags |= eTraversalNeeded;
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001393 mResizeTransationPending = true;
1394 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001395 }
1396 if (what & eAlphaChanged) {
1397 if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f)))
1398 flags |= eTraversalNeeded;
1399 }
1400 if (what & eMatrixChanged) {
1401 if (layer->setMatrix(s.matrix))
1402 flags |= eTraversalNeeded;
1403 }
1404 if (what & eTransparentRegionChanged) {
1405 if (layer->setTransparentRegionHint(s.transparentRegion))
1406 flags |= eTraversalNeeded;
1407 }
1408 if (what & eVisibilityChanged) {
1409 if (layer->setFlags(s.flags, s.mask))
1410 flags |= eTraversalNeeded;
1411 }
1412 }
1413 }
1414 if (flags) {
1415 setTransactionFlags(flags);
1416 }
1417 return NO_ERROR;
1418}
1419
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001420sp<LayerBaseClient> SurfaceFlinger::getLayerUser_l(SurfaceID s) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001421{
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001422 sp<LayerBaseClient> layer = mLayerMap.valueFor(s);
1423 return layer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001424}
1425
1426void SurfaceFlinger::screenReleased(int dpy)
1427{
1428 // this may be called by a signal handler, we can't do too much in here
1429 android_atomic_or(eConsoleReleased, &mConsoleSignals);
1430 signalEvent();
1431}
1432
1433void SurfaceFlinger::screenAcquired(int dpy)
1434{
1435 // this may be called by a signal handler, we can't do too much in here
1436 android_atomic_or(eConsoleAcquired, &mConsoleSignals);
1437 signalEvent();
1438}
1439
1440status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args)
1441{
1442 const size_t SIZE = 1024;
1443 char buffer[SIZE];
1444 String8 result;
Mathias Agopian375f5632009-06-15 18:24:59 -07001445 if (!mDump.checkCalling()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001446 snprintf(buffer, SIZE, "Permission Denial: "
1447 "can't dump SurfaceFlinger from pid=%d, uid=%d\n",
1448 IPCThreadState::self()->getCallingPid(),
1449 IPCThreadState::self()->getCallingUid());
1450 result.append(buffer);
1451 } else {
Mathias Agopian9795c422009-08-26 16:36:26 -07001452
1453 // figure out if we're stuck somewhere
1454 const nsecs_t now = systemTime();
1455 const nsecs_t inSwapBuffers(mDebugInSwapBuffers);
1456 const nsecs_t inTransaction(mDebugInTransaction);
1457 nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0;
1458 nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0;
1459
1460 // Try to get the main lock, but don't insist if we can't
1461 // (this would indicate SF is stuck, but we want to be able to
1462 // print something in dumpsys).
1463 int retry = 3;
1464 while (mStateLock.tryLock()<0 && --retry>=0) {
1465 usleep(1000000);
1466 }
1467 const bool locked(retry >= 0);
1468 if (!locked) {
1469 snprintf(buffer, SIZE,
1470 "SurfaceFlinger appears to be unresponsive, "
1471 "dumping anyways (no locks held)\n");
1472 result.append(buffer);
1473 }
1474
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001475 size_t s = mClientsMap.size();
1476 char name[64];
1477 for (size_t i=0 ; i<s ; i++) {
Mathias Agopianf9d93272009-06-19 17:00:27 -07001478 sp<Client> client = mClientsMap.valueAt(i);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001479 sprintf(name, " Client (id=0x%08x)", client->cid);
1480 client->dump(name);
1481 }
1482 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
1483 const size_t count = currentLayers.size();
1484 for (size_t i=0 ; i<count ; i++) {
1485 /*** LayerBase ***/
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001486 const sp<LayerBase>& layer = currentLayers[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001487 const Layer::State& s = layer->drawingState();
1488 snprintf(buffer, SIZE,
1489 "+ %s %p\n"
1490 " "
1491 "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), "
Mathias Agopian401c2572009-09-23 19:16:27 -07001492 "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, "
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001493 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n",
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001494 layer->getTypeID(), layer.get(),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001495 s.z, layer->tx(), layer->ty(), s.w, s.h,
Mathias Agopian401c2572009-09-23 19:16:27 -07001496 layer->needsBlending(), layer->needsDithering(),
1497 layer->contentDirty,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001498 s.alpha, s.flags,
1499 s.transform[0], s.transform[1],
1500 s.transform[2], s.transform[3]);
1501 result.append(buffer);
1502 buffer[0] = 0;
1503 /*** LayerBaseClient ***/
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001504 sp<LayerBaseClient> lbc =
1505 LayerBase::dynamicCast< LayerBaseClient* >(layer.get());
1506 if (lbc != 0) {
Mathias Agopianf9d93272009-06-19 17:00:27 -07001507 sp<Client> client(lbc->client.promote());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001508 snprintf(buffer, SIZE,
1509 " "
1510 "id=0x%08x, client=0x%08x, identity=%u\n",
Mathias Agopianf9d93272009-06-19 17:00:27 -07001511 lbc->clientIndex(), client.get() ? client->cid : 0,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001512 lbc->getIdentity());
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001513
1514 result.append(buffer);
1515 buffer[0] = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001516 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001517 /*** Layer ***/
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001518 sp<Layer> l = LayerBase::dynamicCast< Layer* >(layer.get());
1519 if (l != 0) {
Mathias Agopian86f73292009-09-17 01:35:28 -07001520 SharedBufferStack::Statistics stats = l->lcblk->getStats();
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001521 result.append( l->lcblk->dump(" ") );
1522 sp<const Buffer> buf0(l->getBuffer(0));
1523 sp<const Buffer> buf1(l->getBuffer(1));
Mathias Agopian4790a3c2009-09-14 15:59:16 -07001524 uint32_t w0=0, h0=0, s0=0;
1525 uint32_t w1=0, h1=0, s1=0;
1526 if (buf0 != 0) {
1527 w0 = buf0->getWidth();
1528 h0 = buf0->getHeight();
1529 s0 = buf0->getStride();
1530 }
1531 if (buf1 != 0) {
1532 w1 = buf1->getWidth();
1533 h1 = buf1->getHeight();
1534 s1 = buf1->getStride();
1535 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001536 snprintf(buffer, SIZE,
1537 " "
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001538 "format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u],"
Mathias Agopian86f73292009-09-17 01:35:28 -07001539 " freezeLock=%p, dq-q-time=%u us\n",
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001540 l->pixelFormat(),
Mathias Agopian4790a3c2009-09-14 15:59:16 -07001541 w0, h0, s0, w1, h1, s1,
Mathias Agopian86f73292009-09-17 01:35:28 -07001542 l->getFreezeLock().get(), stats.totalTime);
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001543 result.append(buffer);
1544 buffer[0] = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001545 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001546 s.transparentRegion.dump(result, "transparentRegion");
1547 layer->transparentRegionScreen.dump(result, "transparentRegionScreen");
1548 layer->visibleRegionScreen.dump(result, "visibleRegionScreen");
1549 }
1550 mWormholeRegion.dump(result, "WormholeRegion");
1551 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1552 snprintf(buffer, SIZE,
1553 " display frozen: %s, freezeCount=%d, orientation=%d, canDraw=%d\n",
1554 mFreezeDisplay?"yes":"no", mFreezeCount,
1555 mCurrentState.orientation, hw.canDraw());
1556 result.append(buffer);
Mathias Agopian9795c422009-08-26 16:36:26 -07001557 snprintf(buffer, SIZE,
1558 " last eglSwapBuffers() time: %f us\n"
1559 " last transaction time : %f us\n",
1560 mLastSwapBufferTime/1000.0, mLastTransactionTime/1000.0);
1561 result.append(buffer);
1562 if (inSwapBuffersDuration || !locked) {
1563 snprintf(buffer, SIZE, " eglSwapBuffers time: %f us\n",
1564 inSwapBuffersDuration/1000.0);
1565 result.append(buffer);
1566 }
1567 if (inTransactionDuration || !locked) {
1568 snprintf(buffer, SIZE, " transaction time: %f us\n",
1569 inTransactionDuration/1000.0);
1570 result.append(buffer);
1571 }
Mathias Agopian759fdb22009-07-02 17:33:40 -07001572 snprintf(buffer, SIZE, " client count: %d\n", mClientsMap.size());
Mathias Agopian3d579642009-06-04 18:46:21 -07001573 result.append(buffer);
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001574 const BufferAllocator& alloc(BufferAllocator::get());
1575 alloc.dump(result);
Mathias Agopian9795c422009-08-26 16:36:26 -07001576
1577 if (locked) {
1578 mStateLock.unlock();
1579 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001580 }
1581 write(fd, result.string(), result.size());
1582 return NO_ERROR;
1583}
1584
1585status_t SurfaceFlinger::onTransact(
1586 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1587{
1588 switch (code) {
1589 case CREATE_CONNECTION:
1590 case OPEN_GLOBAL_TRANSACTION:
1591 case CLOSE_GLOBAL_TRANSACTION:
1592 case SET_ORIENTATION:
1593 case FREEZE_DISPLAY:
1594 case UNFREEZE_DISPLAY:
1595 case BOOT_FINISHED:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001596 {
1597 // codes that require permission check
1598 IPCThreadState* ipc = IPCThreadState::self();
1599 const int pid = ipc->getCallingPid();
Mathias Agopiana1ecca92009-05-21 19:21:59 -07001600 const int uid = ipc->getCallingUid();
Mathias Agopian375f5632009-06-15 18:24:59 -07001601 if ((uid != AID_GRAPHICS) && !mAccessSurfaceFlinger.check(pid, uid)) {
1602 LOGE("Permission Denial: "
1603 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
1604 return PERMISSION_DENIED;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001605 }
1606 }
1607 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001608 status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags);
1609 if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
Mathias Agopianb8a55602009-06-26 19:06:36 -07001610 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Mathias Agopian375f5632009-06-15 18:24:59 -07001611 if (UNLIKELY(!mHardwareTest.checkCalling())) {
1612 IPCThreadState* ipc = IPCThreadState::self();
1613 const int pid = ipc->getCallingPid();
1614 const int uid = ipc->getCallingUid();
1615 LOGE("Permission Denial: "
1616 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001617 return PERMISSION_DENIED;
1618 }
1619 int n;
1620 switch (code) {
Mathias Agopian01b76682009-04-16 20:04:08 -07001621 case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001622 return NO_ERROR;
Mathias Agopiancbc93ca2009-04-21 18:28:33 -07001623 case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001624 return NO_ERROR;
1625 case 1002: // SHOW_UPDATES
1626 n = data.readInt32();
1627 mDebugRegion = n ? n : (mDebugRegion ? 0 : 1);
1628 return NO_ERROR;
1629 case 1003: // SHOW_BACKGROUND
1630 n = data.readInt32();
1631 mDebugBackground = n ? 1 : 0;
1632 return NO_ERROR;
1633 case 1004:{ // repaint everything
1634 Mutex::Autolock _l(mStateLock);
1635 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1636 mDirtyRegion.set(hw.bounds()); // careful that's not thread-safe
1637 signalEvent();
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001638 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001639 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001640 case 1005:{ // force transaction
1641 setTransactionFlags(eTransactionNeeded|eTraversalNeeded);
1642 return NO_ERROR;
1643 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001644 case 1007: // set mFreezeCount
1645 mFreezeCount = data.readInt32();
1646 return NO_ERROR;
1647 case 1010: // interrogate.
Mathias Agopian01b76682009-04-16 20:04:08 -07001648 reply->writeInt32(0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001649 reply->writeInt32(0);
1650 reply->writeInt32(mDebugRegion);
1651 reply->writeInt32(mDebugBackground);
1652 return NO_ERROR;
1653 case 1013: {
1654 Mutex::Autolock _l(mStateLock);
1655 const DisplayHardware& hw(graphicPlane(0).displayHardware());
1656 reply->writeInt32(hw.getPageFlipCount());
1657 }
1658 return NO_ERROR;
1659 }
1660 }
1661 return err;
1662}
1663
1664// ---------------------------------------------------------------------------
1665#if 0
1666#pragma mark -
1667#endif
1668
1669Client::Client(ClientID clientID, const sp<SurfaceFlinger>& flinger)
1670 : ctrlblk(0), cid(clientID), mPid(0), mBitmap(0), mFlinger(flinger)
1671{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001672 const int pgsize = getpagesize();
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001673 const int cblksize = ((sizeof(SharedClient)+(pgsize-1))&~(pgsize-1));
Mathias Agopian7303c6b2009-07-02 18:11:53 -07001674
1675 mCblkHeap = new MemoryHeapBase(cblksize, 0,
1676 "SurfaceFlinger Client control-block");
1677
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001678 ctrlblk = static_cast<SharedClient *>(mCblkHeap->getBase());
Mathias Agopian7303c6b2009-07-02 18:11:53 -07001679 if (ctrlblk) { // construct the shared structure in-place.
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001680 new(ctrlblk) SharedClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001681 }
1682}
1683
1684Client::~Client() {
1685 if (ctrlblk) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001686 ctrlblk->~SharedClient(); // destroy our shared-structure.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001687 }
1688}
1689
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001690int32_t Client::generateId(int pid)
1691{
1692 const uint32_t i = clz( ~mBitmap );
1693 if (i >= NUM_LAYERS_MAX) {
1694 return NO_MEMORY;
1695 }
1696 mPid = pid;
1697 mInUse.add(uint8_t(i));
1698 mBitmap |= 1<<(31-i);
1699 return i;
1700}
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001701
1702status_t Client::bindLayer(const sp<LayerBaseClient>& layer, int32_t id)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001703{
1704 ssize_t idx = mInUse.indexOf(id);
1705 if (idx < 0)
1706 return NAME_NOT_FOUND;
1707 return mLayers.insertAt(layer, idx);
1708}
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001709
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001710void Client::free(int32_t id)
1711{
1712 ssize_t idx = mInUse.remove(uint8_t(id));
1713 if (idx >= 0) {
1714 mBitmap &= ~(1<<(31-id));
1715 mLayers.removeItemsAt(idx);
1716 }
1717}
1718
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001719bool Client::isValid(int32_t i) const {
1720 return (uint32_t(i)<NUM_LAYERS_MAX) && (mBitmap & (1<<(31-i)));
1721}
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001722
1723sp<LayerBaseClient> Client::getLayerUser(int32_t i) const {
1724 sp<LayerBaseClient> lbc;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001725 ssize_t idx = mInUse.indexOf(uint8_t(i));
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001726 if (idx >= 0) {
1727 lbc = mLayers[idx].promote();
1728 LOGE_IF(lbc==0, "getLayerUser(i=%d), idx=%d is dead", int(i), int(idx));
1729 }
1730 return lbc;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001731}
1732
1733void Client::dump(const char* what)
1734{
1735}
1736
1737// ---------------------------------------------------------------------------
1738#if 0
1739#pragma mark -
1740#endif
1741
Mathias Agopian7303c6b2009-07-02 18:11:53 -07001742BClient::BClient(SurfaceFlinger *flinger, ClientID cid, const sp<IMemoryHeap>& cblk)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001743 : mId(cid), mFlinger(flinger), mCblk(cblk)
1744{
1745}
1746
1747BClient::~BClient() {
1748 // destroy all resources attached to this client
1749 mFlinger->destroyConnection(mId);
1750}
1751
Mathias Agopian7303c6b2009-07-02 18:11:53 -07001752sp<IMemoryHeap> BClient::getControlBlock() const {
1753 return mCblk;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001754}
1755
1756sp<ISurface> BClient::createSurface(
1757 ISurfaceFlingerClient::surface_data_t* params, int pid,
1758 DisplayID display, uint32_t w, uint32_t h, PixelFormat format,
1759 uint32_t flags)
1760{
1761 return mFlinger->createSurface(mId, pid, params, display, w, h, format, flags);
1762}
1763
1764status_t BClient::destroySurface(SurfaceID sid)
1765{
1766 sid |= (mId << 16); // add the client-part to id
Mathias Agopian9a112062009-04-17 19:36:26 -07001767 return mFlinger->removeSurface(sid);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001768}
1769
1770status_t BClient::setState(int32_t count, const layer_state_t* states)
1771{
1772 return mFlinger->setClientState(mId, count, states);
1773}
1774
1775// ---------------------------------------------------------------------------
1776
1777GraphicPlane::GraphicPlane()
1778 : mHw(0)
1779{
1780}
1781
1782GraphicPlane::~GraphicPlane() {
1783 delete mHw;
1784}
1785
1786bool GraphicPlane::initialized() const {
1787 return mHw ? true : false;
1788}
1789
1790void GraphicPlane::setDisplayHardware(DisplayHardware *hw) {
1791 mHw = hw;
1792}
1793
1794void GraphicPlane::setTransform(const Transform& tr) {
1795 mTransform = tr;
1796 mGlobalTransform = mOrientationTransform * mTransform;
1797}
1798
1799status_t GraphicPlane::orientationToTransfrom(
1800 int orientation, int w, int h, Transform* tr)
1801{
1802 float a, b, c, d, x, y;
1803 switch (orientation) {
1804 case ISurfaceComposer::eOrientationDefault:
1805 a=1; b=0; c=0; d=1; x=0; y=0;
1806 break;
1807 case ISurfaceComposer::eOrientation90:
1808 a=0; b=-1; c=1; d=0; x=w; y=0;
1809 break;
1810 case ISurfaceComposer::eOrientation180:
1811 a=-1; b=0; c=0; d=-1; x=w; y=h;
1812 break;
1813 case ISurfaceComposer::eOrientation270:
1814 a=0; b=1; c=-1; d=0; x=0; y=h;
1815 break;
1816 default:
1817 return BAD_VALUE;
1818 }
1819 tr->set(a, b, c, d);
1820 tr->set(x, y);
1821 return NO_ERROR;
1822}
1823
1824status_t GraphicPlane::setOrientation(int orientation)
1825{
1826 const DisplayHardware& hw(displayHardware());
1827 const float w = hw.getWidth();
1828 const float h = hw.getHeight();
1829
1830 if (orientation == ISurfaceComposer::eOrientationDefault) {
1831 // make sure the default orientation is optimal
1832 mOrientationTransform.reset();
Mathias Agopian0d1318b2009-03-27 17:58:20 -07001833 mOrientation = orientation;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001834 mGlobalTransform = mTransform;
1835 return NO_ERROR;
1836 }
1837
1838 // If the rotation can be handled in hardware, this is where
1839 // the magic should happen.
1840 if (UNLIKELY(orientation == 42)) {
1841 float a, b, c, d, x, y;
1842 const float r = (3.14159265f / 180.0f) * 42.0f;
1843 const float si = sinf(r);
1844 const float co = cosf(r);
1845 a=co; b=-si; c=si; d=co;
1846 x = si*(h*0.5f) + (1-co)*(w*0.5f);
1847 y =-si*(w*0.5f) + (1-co)*(h*0.5f);
1848 mOrientationTransform.set(a, b, c, d);
1849 mOrientationTransform.set(x, y);
1850 } else {
1851 GraphicPlane::orientationToTransfrom(orientation, w, h,
1852 &mOrientationTransform);
1853 }
Mathias Agopian0d1318b2009-03-27 17:58:20 -07001854 mOrientation = orientation;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001855 mGlobalTransform = mOrientationTransform * mTransform;
1856 return NO_ERROR;
1857}
1858
1859const DisplayHardware& GraphicPlane::displayHardware() const {
1860 return *mHw;
1861}
1862
1863const Transform& GraphicPlane::transform() const {
1864 return mGlobalTransform;
1865}
1866
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001867EGLDisplay GraphicPlane::getEGLDisplay() const {
1868 return mHw->getEGLDisplay();
1869}
1870
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001871// ---------------------------------------------------------------------------
1872
1873}; // namespace android