2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
20 #include <sys/types.h>
28 #include <cutils/log.h>
29 #include <cutils/properties.h>
31 #include <binder/IPCThreadState.h>
32 #include <binder/IServiceManager.h>
33 #include <binder/MemoryHeapBase.h>
34 #include <binder/PermissionCache.h>
36 #include <ui/DisplayInfo.h>
38 #include <gui/BitTube.h>
39 #include <gui/BufferQueue.h>
40 #include <gui/GuiConfig.h>
41 #include <gui/IDisplayEventConnection.h>
42 #include <gui/Surface.h>
43 #include <gui/GraphicBufferAlloc.h>
45 #include <ui/GraphicBufferAllocator.h>
46 #include <ui/PixelFormat.h>
47 #include <ui/UiConfig.h>
49 #include <utils/misc.h>
50 #include <utils/String8.h>
51 #include <utils/String16.h>
52 #include <utils/StopWatch.h>
53 #include <utils/Trace.h>
55 #include <private/android_filesystem_config.h>
56 #include <private/gui/SyncFeatures.h>
60 #include "Colorizer.h"
61 #include "DdmConnection.h"
62 #include "DisplayDevice.h"
63 #include "EventThread.h"
64 #include "GLExtensions.h"
67 #include "SurfaceFlinger.h"
69 #include "DisplayHardware/FramebufferSurface.h"
70 #include "DisplayHardware/HWComposer.h"
71 #include "DisplayHardware/VirtualDisplaySurface.h"
73 #define DISPLAY_COUNT 1
75 EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name);
78 // ---------------------------------------------------------------------------
80 const String16 sHardwareTest("android.permission.HARDWARE_TEST");
81 const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER");
82 const String16 sReadFramebuffer("android.permission.READ_FRAME_BUFFER");
83 const String16 sDump("android.permission.DUMP");
85 // ---------------------------------------------------------------------------
87 SurfaceFlinger::SurfaceFlinger()
88 : BnSurfaceComposer(), Thread(false),
90 mTransactionPending(false),
91 mAnimTransactionPending(false),
92 mLayersRemoved(false),
93 mRepaintEverything(0),
94 mBootTime(systemTime()),
95 mVisibleRegionsDirty(false),
96 mHwWorkListDirty(false),
97 mAnimCompositionPending(false),
101 mDebugDisableTransformHint(0),
102 mDebugInSwapBuffers(0),
103 mLastSwapBufferTime(0),
104 mDebugInTransaction(0),
105 mLastTransactionTime(0),
108 ALOGI("SurfaceFlinger is starting");
110 // debugging stuff...
111 char value[PROPERTY_VALUE_MAX];
113 property_get("ro.bq.gpu_to_cpu_unsupported", value, "0");
114 mGpuToCpuSupported = !atoi(value);
116 property_get("debug.sf.showupdates", value, "0");
117 mDebugRegion = atoi(value);
119 property_get("debug.sf.ddms", value, "0");
120 mDebugDDMS = atoi(value);
122 if (!startDdmConnection()) {
123 // start failed, and DDMS debugging not enabled
127 ALOGI_IF(mDebugRegion, "showupdates enabled");
128 ALOGI_IF(mDebugDDMS, "DDMS debugging enabled");
131 void SurfaceFlinger::onFirstRef()
133 mEventQueue.init(this);
135 run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY);
137 // Wait for the main thread to be done with its initialization
138 mReadyToRunBarrier.wait();
142 SurfaceFlinger::~SurfaceFlinger()
144 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
145 eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
146 eglTerminate(display);
149 void SurfaceFlinger::binderDied(const wp<IBinder>& who)
151 // the window manager died on us. prepare its eulogy.
153 // restore initial conditions (default device unblank, etc)
154 initializeDisplays();
156 // restart the boot-animation
160 sp<ISurfaceComposerClient> SurfaceFlinger::createConnection()
162 sp<ISurfaceComposerClient> bclient;
163 sp<Client> client(new Client(this));
164 status_t err = client->initCheck();
165 if (err == NO_ERROR) {
171 sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName,
174 class DisplayToken : public BBinder {
175 sp<SurfaceFlinger> flinger;
176 virtual ~DisplayToken() {
177 // no more references, this display must be terminated
178 Mutex::Autolock _l(flinger->mStateLock);
179 flinger->mCurrentState.displays.removeItem(this);
180 flinger->setTransactionFlags(eDisplayTransactionNeeded);
183 DisplayToken(const sp<SurfaceFlinger>& flinger)
188 sp<BBinder> token = new DisplayToken(this);
190 Mutex::Autolock _l(mStateLock);
191 DisplayDeviceState info(DisplayDevice::DISPLAY_VIRTUAL);
192 info.displayName = displayName;
193 info.isSecure = secure;
194 mCurrentState.displays.add(token, info);
199 void SurfaceFlinger::createBuiltinDisplayLocked(DisplayDevice::DisplayType type) {
200 ALOGW_IF(mBuiltinDisplays[type],
201 "Overwriting display token for display type %d", type);
202 mBuiltinDisplays[type] = new BBinder();
203 DisplayDeviceState info(type);
204 // All non-virtual displays are currently considered secure.
205 info.isSecure = true;
206 mCurrentState.displays.add(mBuiltinDisplays[type], info);
209 sp<IBinder> SurfaceFlinger::getBuiltInDisplay(int32_t id) {
210 if (uint32_t(id) >= DisplayDevice::NUM_DISPLAY_TYPES) {
211 ALOGE("getDefaultDisplay: id=%d is not a valid default display id", id);
214 return mBuiltinDisplays[id];
217 sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc()
219 sp<GraphicBufferAlloc> gba(new GraphicBufferAlloc());
223 void SurfaceFlinger::bootFinished()
225 const nsecs_t now = systemTime();
226 const nsecs_t duration = now - mBootTime;
227 ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );
228 mBootFinished = true;
230 // wait patiently for the window manager death
231 const String16 name("window");
232 sp<IBinder> window(defaultServiceManager()->getService(name));
234 window->linkToDeath(static_cast<IBinder::DeathRecipient*>(this));
237 // stop boot animation
238 // formerly we would just kill the process, but we now ask it to exit so it
239 // can choose where to stop the animation.
240 property_set("service.bootanim.exit", "1");
243 void SurfaceFlinger::deleteTextureAsync(GLuint texture) {
244 class MessageDestroyGLTexture : public MessageBase {
247 MessageDestroyGLTexture(GLuint texture)
250 virtual bool handler() {
251 glDeleteTextures(1, &texture);
255 postMessageAsync(new MessageDestroyGLTexture(texture));
258 status_t SurfaceFlinger::selectConfigForAttribute(
261 EGLint attribute, EGLint wanted,
262 EGLConfig* outConfig)
264 EGLConfig config = NULL;
265 EGLint numConfigs = -1, n=0;
266 eglGetConfigs(dpy, NULL, 0, &numConfigs);
267 EGLConfig* const configs = new EGLConfig[numConfigs];
268 eglChooseConfig(dpy, attrs, configs, numConfigs, &n);
271 if (attribute != EGL_NONE) {
272 for (int i=0 ; i<n ; i++) {
274 eglGetConfigAttrib(dpy, configs[i], attribute, &value);
275 if (wanted == value) {
276 *outConfig = configs[i];
282 // just pick the first one
283 *outConfig = configs[0];
289 return NAME_NOT_FOUND;
292 class EGLAttributeVector {
296 KeyedVector<Attribute, EGLint> mList;
299 Attribute(EGLint v) : v(v) { }
301 bool operator < (const Attribute& other) const {
302 // this places EGL_NONE at the end
305 if (lhs == EGL_NONE) lhs = 0x7FFFFFFF;
306 if (rhs == EGL_NONE) rhs = 0x7FFFFFFF;
311 friend class EGLAttributeVector;
312 EGLAttributeVector& v;
314 Adder(EGLAttributeVector& v, EGLint attribute)
315 : v(v), attribute(attribute) {
318 void operator = (EGLint value) {
319 if (attribute != EGL_NONE) {
320 v.mList.add(attribute, value);
323 operator EGLint () const { return v.mList[attribute]; }
326 EGLAttributeVector() {
327 mList.add(EGL_NONE, EGL_NONE);
329 void remove(EGLint attribute) {
330 if (attribute != EGL_NONE) {
331 mList.removeItem(attribute);
334 Adder operator [] (EGLint attribute) {
335 return Adder(*this, attribute);
337 EGLint operator [] (EGLint attribute) const {
338 return mList[attribute];
340 // cast-operator to (EGLint const*)
341 operator EGLint const* () const { return &mList.keyAt(0).v; }
344 EGLConfig SurfaceFlinger::selectEGLConfig(EGLDisplay display, EGLint nativeVisualId) {
345 // select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
346 // it is to be used with WIFI displays
351 EGLAttributeVector attribs;
352 attribs[EGL_SURFACE_TYPE] = EGL_WINDOW_BIT;
353 attribs[EGL_RECORDABLE_ANDROID] = EGL_TRUE;
354 attribs[EGL_FRAMEBUFFER_TARGET_ANDROID] = EGL_TRUE;
355 attribs[EGL_RED_SIZE] = 8;
356 attribs[EGL_GREEN_SIZE] = 8;
357 attribs[EGL_BLUE_SIZE] = 8;
359 err = selectConfigForAttribute(display, attribs, EGL_NONE, EGL_NONE, &config);
363 // maybe we failed because of EGL_FRAMEBUFFER_TARGET_ANDROID
364 ALOGW("no suitable EGLConfig found, trying without EGL_FRAMEBUFFER_TARGET_ANDROID");
365 attribs.remove(EGL_FRAMEBUFFER_TARGET_ANDROID);
366 err = selectConfigForAttribute(display, attribs,
367 EGL_NATIVE_VISUAL_ID, nativeVisualId, &config);
371 // maybe we failed because of EGL_RECORDABLE_ANDROID
372 ALOGW("no suitable EGLConfig found, trying without EGL_RECORDABLE_ANDROID");
373 attribs.remove(EGL_RECORDABLE_ANDROID);
374 err = selectConfigForAttribute(display, attribs,
375 EGL_NATIVE_VISUAL_ID, nativeVisualId, &config);
379 // allow less than 24-bit color; the non-gpu-accelerated emulator only
380 // supports 16-bit color
381 ALOGW("no suitable EGLConfig found, trying with 16-bit color allowed");
382 attribs.remove(EGL_RED_SIZE);
383 attribs.remove(EGL_GREEN_SIZE);
384 attribs.remove(EGL_BLUE_SIZE);
385 err = selectConfigForAttribute(display, attribs,
386 EGL_NATIVE_VISUAL_ID, nativeVisualId, &config);
390 // this EGL is too lame for Android
391 ALOGE("no suitable EGLConfig found, giving up");
396 if (eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT, &dummy))
397 ALOGW_IF(dummy == EGL_SLOW_CONFIG, "EGL_SLOW_CONFIG selected!");
401 EGLContext SurfaceFlinger::createGLContext(EGLDisplay display, EGLConfig config) {
402 // Also create our EGLContext
403 EGLint contextAttributes[] = {
404 #ifdef EGL_IMG_context_priority
405 #ifdef HAS_CONTEXT_PRIORITY
406 #warning "using EGL_IMG_context_priority"
407 EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG,
412 EGLContext ctxt = eglCreateContext(display, config, NULL, contextAttributes);
413 ALOGE_IF(ctxt==EGL_NO_CONTEXT, "EGLContext creation failed");
417 static GlesVersion parseGlesVersion(const char* str) {
419 if (sscanf(str, "OpenGL ES-CM %d.%d", &major, &minor) != 2) {
420 ALOGW("Unable to parse GL_VERSION string: \"%s\"", str);
421 return GLES_VERSION_1_0;
424 if (major == 1 && minor == 0) return GLES_VERSION_1_0;
425 if (major == 1 && minor >= 1) return GLES_VERSION_1_1;
426 if (major == 2 && minor >= 0) return GLES_VERSION_2_0;
427 if (major == 3 && minor >= 0) return GLES_VERSION_3_0;
429 ALOGW("Unrecognized OpenGL ES version: %d.%d", major, minor);
430 return GLES_VERSION_1_0;
433 void SurfaceFlinger::initializeGL(EGLDisplay display) {
434 GLExtensions& extensions(GLExtensions::getInstance());
435 extensions.initWithGLStrings(
436 glGetString(GL_VENDOR),
437 glGetString(GL_RENDERER),
438 glGetString(GL_VERSION),
439 glGetString(GL_EXTENSIONS),
440 eglQueryString(display, EGL_VENDOR),
441 eglQueryString(display, EGL_VERSION),
442 eglQueryString(display, EGL_EXTENSIONS));
444 mGlesVersion = parseGlesVersion(extensions.getVersion());
446 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
447 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims);
449 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
450 glPixelStorei(GL_PACK_ALIGNMENT, 4);
451 glEnableClientState(GL_VERTEX_ARRAY);
452 glShadeModel(GL_FLAT);
453 glDisable(GL_DITHER);
454 glDisable(GL_CULL_FACE);
457 inline uint16_t operator() (int r, int g, int b) const {
458 return (r<<11)|(g<<5)|b;
462 const uint16_t protTexData[] = { pack565(0x03, 0x03, 0x03) };
463 glGenTextures(1, &mProtectedTexName);
464 glBindTexture(GL_TEXTURE_2D, mProtectedTexName);
465 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
466 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
467 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
468 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
469 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0,
470 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, protTexData);
472 // print some debugging info
474 eglGetConfigAttrib(display, mEGLConfig, EGL_RED_SIZE, &r);
475 eglGetConfigAttrib(display, mEGLConfig, EGL_GREEN_SIZE, &g);
476 eglGetConfigAttrib(display, mEGLConfig, EGL_BLUE_SIZE, &b);
477 eglGetConfigAttrib(display, mEGLConfig, EGL_ALPHA_SIZE, &a);
478 ALOGI("EGL informations:");
479 ALOGI("vendor : %s", extensions.getEglVendor());
480 ALOGI("version : %s", extensions.getEglVersion());
481 ALOGI("extensions: %s", extensions.getEglExtension());
482 ALOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS)?:"Not Supported");
483 ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, mEGLConfig);
484 ALOGI("OpenGL ES informations:");
485 ALOGI("vendor : %s", extensions.getVendor());
486 ALOGI("renderer : %s", extensions.getRenderer());
487 ALOGI("version : %s", extensions.getVersion());
488 ALOGI("extensions: %s", extensions.getExtension());
489 ALOGI("GL_MAX_TEXTURE_SIZE = %d", mMaxTextureSize);
490 ALOGI("GL_MAX_VIEWPORT_DIMS = %d x %d", mMaxViewportDims[0], mMaxViewportDims[1]);
493 status_t SurfaceFlinger::readyToRun()
495 ALOGI( "SurfaceFlinger's main thread ready to run. "
496 "Initializing graphics H/W...");
498 Mutex::Autolock _l(mStateLock);
500 // initialize EGL for the default display
501 mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
502 eglInitialize(mEGLDisplay, NULL, NULL);
504 // Initialize the H/W composer object. There may or may not be an
505 // actual hardware composer underneath.
506 mHwc = new HWComposer(this,
507 *static_cast<HWComposer::EventHandler *>(this));
509 // initialize the config and context
510 EGLint format = mHwc->getVisualID();
511 mEGLConfig = selectEGLConfig(mEGLDisplay, format);
512 mEGLContext = createGLContext(mEGLDisplay, mEGLConfig);
514 // figure out which format we got
515 eglGetConfigAttrib(mEGLDisplay, mEGLConfig,
516 EGL_NATIVE_VISUAL_ID, &mEGLNativeVisualId);
518 LOG_ALWAYS_FATAL_IF(mEGLContext == EGL_NO_CONTEXT,
519 "couldn't create EGLContext");
521 // initialize our non-virtual displays
522 for (size_t i=0 ; i<DisplayDevice::NUM_DISPLAY_TYPES ; i++) {
523 DisplayDevice::DisplayType type((DisplayDevice::DisplayType)i);
524 // set-up the displays that are already connected
525 if (mHwc->isConnected(i) || type==DisplayDevice::DISPLAY_PRIMARY) {
526 // All non-virtual displays are currently considered secure.
527 bool isSecure = true;
528 createBuiltinDisplayLocked(type);
529 wp<IBinder> token = mBuiltinDisplays[i];
531 sp<DisplayDevice> hw = new DisplayDevice(this,
532 type, allocateHwcDisplayId(type), isSecure, token,
533 new FramebufferSurface(*mHwc, i),
535 if (i > DisplayDevice::DISPLAY_PRIMARY) {
536 // FIXME: currently we don't get blank/unblank requests
537 // for displays other than the main display, so we always
538 // assume a connected display is unblanked.
539 ALOGD("marking display %d as acquired/unblanked", i);
542 mDisplays.add(token, hw);
546 // we need a GL context current in a few places, when initializing
547 // OpenGL ES (see below), or creating a layer,
548 // or when a texture is (asynchronously) destroyed, and for that
549 // we need a valid surface, so it's convenient to use the main display
551 sp<const DisplayDevice> hw(getDefaultDisplayDevice());
553 // initialize OpenGL ES
554 DisplayDevice::makeCurrent(mEGLDisplay, hw, mEGLContext);
555 initializeGL(mEGLDisplay);
557 // start the EventThread
558 mEventThread = new EventThread(this);
559 mEventQueue.setEventThread(mEventThread);
561 // initialize our drawing state
562 mDrawingState = mCurrentState;
565 // We're now ready to accept clients...
566 mReadyToRunBarrier.open();
568 // set initial conditions (e.g. unblank default device)
569 initializeDisplays();
571 // start boot animation
577 int32_t SurfaceFlinger::allocateHwcDisplayId(DisplayDevice::DisplayType type) {
578 return (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) ?
579 type : mHwc->allocateDisplayId();
582 void SurfaceFlinger::startBootAnim() {
583 // start boot animation
584 property_set("service.bootanim.exit", "0");
585 property_set("ctl.start", "bootanim");
588 uint32_t SurfaceFlinger::getMaxTextureSize() const {
589 return mMaxTextureSize;
592 uint32_t SurfaceFlinger::getMaxViewportDims() const {
593 return mMaxViewportDims[0] < mMaxViewportDims[1] ?
594 mMaxViewportDims[0] : mMaxViewportDims[1];
597 // ----------------------------------------------------------------------------
599 bool SurfaceFlinger::authenticateSurfaceTexture(
600 const sp<IGraphicBufferProducer>& bufferProducer) const {
601 Mutex::Autolock _l(mStateLock);
602 sp<IBinder> surfaceTextureBinder(bufferProducer->asBinder());
603 return mGraphicBufferProducerList.indexOf(surfaceTextureBinder) >= 0;
606 status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
607 int32_t type = NAME_NOT_FOUND;
608 for (int i=0 ; i<DisplayDevice::NUM_DISPLAY_TYPES ; i++) {
609 if (display == mBuiltinDisplays[i]) {
619 const HWComposer& hwc(getHwComposer());
620 float xdpi = hwc.getDpiX(type);
621 float ydpi = hwc.getDpiY(type);
623 // TODO: Not sure if display density should handled by SF any longer
625 static int getDensityFromProperty(char const* propName) {
626 char property[PROPERTY_VALUE_MAX];
628 if (property_get(propName, property, NULL) > 0) {
629 density = atoi(property);
634 static int getEmuDensity() {
635 return getDensityFromProperty("qemu.sf.lcd_density"); }
636 static int getBuildDensity() {
637 return getDensityFromProperty("ro.sf.lcd_density"); }
640 if (type == DisplayDevice::DISPLAY_PRIMARY) {
641 // The density of the device is provided by a build property
642 float density = Density::getBuildDensity() / 160.0f;
644 // the build doesn't provide a density -- this is wrong!
646 ALOGE("ro.sf.lcd_density must be defined as a build property");
647 density = xdpi / 160.0f;
649 if (Density::getEmuDensity()) {
650 // if "qemu.sf.lcd_density" is specified, it overrides everything
651 xdpi = ydpi = density = Density::getEmuDensity();
654 info->density = density;
656 // TODO: this needs to go away (currently needed only by webkit)
657 sp<const DisplayDevice> hw(getDefaultDisplayDevice());
658 info->orientation = hw->getOrientation();
659 getPixelFormatInfo(hw->getFormat(), &info->pixelFormatInfo);
661 // TODO: where should this value come from?
662 static const int TV_DENSITY = 213;
663 info->density = TV_DENSITY / 160.0f;
664 info->orientation = 0;
667 info->w = hwc.getWidth(type);
668 info->h = hwc.getHeight(type);
671 info->fps = float(1e9 / hwc.getRefreshPeriod(type));
673 // All non-virtual displays are currently considered secure.
679 // ----------------------------------------------------------------------------
681 sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection() {
682 return mEventThread->createEventConnection();
685 // ----------------------------------------------------------------------------
687 void SurfaceFlinger::waitForEvent() {
688 mEventQueue.waitMessage();
691 void SurfaceFlinger::signalTransaction() {
692 mEventQueue.invalidate();
695 void SurfaceFlinger::signalLayerUpdate() {
696 mEventQueue.invalidate();
699 void SurfaceFlinger::signalRefresh() {
700 mEventQueue.refresh();
703 status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg,
704 nsecs_t reltime, uint32_t flags) {
705 return mEventQueue.postMessage(msg, reltime);
708 status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg,
709 nsecs_t reltime, uint32_t flags) {
710 status_t res = mEventQueue.postMessage(msg, reltime);
711 if (res == NO_ERROR) {
717 bool SurfaceFlinger::threadLoop() {
722 void SurfaceFlinger::onVSyncReceived(int type, nsecs_t timestamp) {
723 if (mEventThread == NULL) {
724 // This is a temporary workaround for b/7145521. A non-null pointer
725 // does not mean EventThread has finished initializing, so this
726 // is not a correct fix.
727 ALOGW("WARNING: EventThread not started, ignoring vsync");
730 if (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) {
731 // we should only receive DisplayDevice::DisplayType from the vsync callback
732 mEventThread->onVSyncReceived(type, timestamp);
736 void SurfaceFlinger::onHotplugReceived(int type, bool connected) {
737 if (mEventThread == NULL) {
738 // This is a temporary workaround for b/7145521. A non-null pointer
739 // does not mean EventThread has finished initializing, so this
740 // is not a correct fix.
741 ALOGW("WARNING: EventThread not started, ignoring hotplug");
745 if (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) {
746 Mutex::Autolock _l(mStateLock);
748 createBuiltinDisplayLocked((DisplayDevice::DisplayType)type);
750 mCurrentState.displays.removeItem(mBuiltinDisplays[type]);
751 mBuiltinDisplays[type].clear();
753 setTransactionFlags(eDisplayTransactionNeeded);
755 // Defer EventThread notification until SF has updated mDisplays.
759 void SurfaceFlinger::eventControl(int disp, int event, int enabled) {
760 getHwComposer().eventControl(disp, event, enabled);
763 void SurfaceFlinger::onMessageReceived(int32_t what) {
766 case MessageQueue::TRANSACTION:
767 handleMessageTransaction();
769 case MessageQueue::INVALIDATE:
770 handleMessageTransaction();
771 handleMessageInvalidate();
774 case MessageQueue::REFRESH:
775 handleMessageRefresh();
780 void SurfaceFlinger::handleMessageTransaction() {
781 uint32_t transactionFlags = peekTransactionFlags(eTransactionMask);
782 if (transactionFlags) {
783 handleTransaction(transactionFlags);
787 void SurfaceFlinger::handleMessageInvalidate() {
792 void SurfaceFlinger::handleMessageRefresh() {
795 rebuildLayerStacks();
797 doDebugFlashRegions();
802 void SurfaceFlinger::doDebugFlashRegions()
804 // is debugging enabled
805 if (CC_LIKELY(!mDebugRegion))
808 const bool repaintEverything = mRepaintEverything;
809 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
810 const sp<DisplayDevice>& hw(mDisplays[dpy]);
812 // transform the dirty region into this screen's coordinate space
813 const Region dirtyRegion(hw->getDirtyRegion(repaintEverything));
814 if (!dirtyRegion.isEmpty()) {
815 // redraw the whole screen
816 doComposeSurfaces(hw, Region(hw->bounds()));
818 // and draw the dirty region
819 glDisable(GL_TEXTURE_EXTERNAL_OES);
820 glDisable(GL_TEXTURE_2D);
822 glColor4f(1, 0, 1, 1);
823 const int32_t height = hw->getHeight();
824 Region::const_iterator it = dirtyRegion.begin();
825 Region::const_iterator const end = dirtyRegion.end();
827 const Rect& r = *it++;
828 GLfloat vertices[][2] = {
829 { (GLfloat) r.left, (GLfloat) (height - r.top) },
830 { (GLfloat) r.left, (GLfloat) (height - r.bottom) },
831 { (GLfloat) r.right, (GLfloat) (height - r.bottom) },
832 { (GLfloat) r.right, (GLfloat) (height - r.top) }
834 glVertexPointer(2, GL_FLOAT, 0, vertices);
835 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
837 hw->compositionComplete();
838 hw->swapBuffers(getHwComposer());
845 if (mDebugRegion > 1) {
846 usleep(mDebugRegion * 1000);
849 HWComposer& hwc(getHwComposer());
850 if (hwc.initCheck() == NO_ERROR) {
851 status_t err = hwc.prepare();
852 ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
856 void SurfaceFlinger::preComposition()
858 bool needExtraInvalidate = false;
859 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
860 const size_t count = currentLayers.size();
861 for (size_t i=0 ; i<count ; i++) {
862 if (currentLayers[i]->onPreComposition()) {
863 needExtraInvalidate = true;
866 if (needExtraInvalidate) {
871 void SurfaceFlinger::postComposition()
873 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
874 const size_t count = currentLayers.size();
875 for (size_t i=0 ; i<count ; i++) {
876 currentLayers[i]->onPostComposition();
879 if (mAnimCompositionPending) {
880 mAnimCompositionPending = false;
882 const HWComposer& hwc = getHwComposer();
883 sp<Fence> presentFence = hwc.getDisplayFence(HWC_DISPLAY_PRIMARY);
884 if (presentFence->isValid()) {
885 mAnimFrameTracker.setActualPresentFence(presentFence);
887 // The HWC doesn't support present fences, so use the refresh
888 // timestamp instead.
889 nsecs_t presentTime = hwc.getRefreshTimestamp(HWC_DISPLAY_PRIMARY);
890 mAnimFrameTracker.setActualPresentTime(presentTime);
892 mAnimFrameTracker.advanceFrame();
896 void SurfaceFlinger::rebuildLayerStacks() {
897 // rebuild the visible layer list per screen
898 if (CC_UNLIKELY(mVisibleRegionsDirty)) {
900 mVisibleRegionsDirty = false;
901 invalidateHwcGeometry();
903 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
904 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
907 Vector< sp<Layer> > layersSortedByZ;
908 const sp<DisplayDevice>& hw(mDisplays[dpy]);
909 const Transform& tr(hw->getTransform());
910 const Rect bounds(hw->getBounds());
912 SurfaceFlinger::computeVisibleRegions(currentLayers,
913 hw->getLayerStack(), dirtyRegion, opaqueRegion);
915 const size_t count = currentLayers.size();
916 for (size_t i=0 ; i<count ; i++) {
917 const sp<Layer>& layer(currentLayers[i]);
918 const Layer::State& s(layer->drawingState());
919 if (s.layerStack == hw->getLayerStack()) {
920 Region drawRegion(tr.transform(
921 layer->visibleNonTransparentRegion));
922 drawRegion.andSelf(bounds);
923 if (!drawRegion.isEmpty()) {
924 layersSortedByZ.add(layer);
929 hw->setVisibleLayersSortedByZ(layersSortedByZ);
930 hw->undefinedRegion.set(bounds);
931 hw->undefinedRegion.subtractSelf(tr.transform(opaqueRegion));
932 hw->dirtyRegion.orSelf(dirtyRegion);
937 void SurfaceFlinger::setUpHWComposer() {
938 HWComposer& hwc(getHwComposer());
939 if (hwc.initCheck() == NO_ERROR) {
940 // build the h/w work list
941 if (CC_UNLIKELY(mHwWorkListDirty)) {
942 mHwWorkListDirty = false;
943 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
944 sp<const DisplayDevice> hw(mDisplays[dpy]);
945 const int32_t id = hw->getHwcDisplayId();
947 const Vector< sp<Layer> >& currentLayers(
948 hw->getVisibleLayersSortedByZ());
949 const size_t count = currentLayers.size();
950 if (hwc.createWorkList(id, count) == NO_ERROR) {
951 HWComposer::LayerListIterator cur = hwc.begin(id);
952 const HWComposer::LayerListIterator end = hwc.end(id);
953 for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
954 const sp<Layer>& layer(currentLayers[i]);
955 layer->setGeometry(hw, *cur);
956 if (mDebugDisableHWC || mDebugRegion) {
965 // set the per-frame data
966 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
967 sp<const DisplayDevice> hw(mDisplays[dpy]);
968 const int32_t id = hw->getHwcDisplayId();
970 const Vector< sp<Layer> >& currentLayers(
971 hw->getVisibleLayersSortedByZ());
972 const size_t count = currentLayers.size();
973 HWComposer::LayerListIterator cur = hwc.begin(id);
974 const HWComposer::LayerListIterator end = hwc.end(id);
975 for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
977 * update the per-frame h/w composer data for each layer
978 * and build the transparent region of the FB
980 const sp<Layer>& layer(currentLayers[i]);
981 layer->setPerFrameData(hw, *cur);
986 status_t err = hwc.prepare();
987 ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
991 void SurfaceFlinger::doComposition() {
993 const bool repaintEverything = android_atomic_and(0, &mRepaintEverything);
994 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
995 const sp<DisplayDevice>& hw(mDisplays[dpy]);
997 // transform the dirty region into this screen's coordinate space
998 const Region dirtyRegion(hw->getDirtyRegion(repaintEverything));
1000 // repaint the framebuffer (if needed)
1001 doDisplayComposition(hw, dirtyRegion);
1003 hw->dirtyRegion.clear();
1004 hw->flip(hw->swapRegion);
1005 hw->swapRegion.clear();
1007 // inform the h/w that we're done compositing
1008 hw->compositionComplete();
1013 void SurfaceFlinger::postFramebuffer()
1017 const nsecs_t now = systemTime();
1018 mDebugInSwapBuffers = now;
1020 HWComposer& hwc(getHwComposer());
1021 if (hwc.initCheck() == NO_ERROR) {
1022 if (!hwc.supportsFramebufferTarget()) {
1024 // "surface must be bound to the calling thread's current context,
1025 // for the current rendering API."
1026 DisplayDevice::makeCurrent(mEGLDisplay,
1027 getDefaultDisplayDevice(), mEGLContext);
1032 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
1033 sp<const DisplayDevice> hw(mDisplays[dpy]);
1034 const Vector< sp<Layer> >& currentLayers(hw->getVisibleLayersSortedByZ());
1035 hw->onSwapBuffersCompleted(hwc);
1036 const size_t count = currentLayers.size();
1037 int32_t id = hw->getHwcDisplayId();
1038 if (id >=0 && hwc.initCheck() == NO_ERROR) {
1039 HWComposer::LayerListIterator cur = hwc.begin(id);
1040 const HWComposer::LayerListIterator end = hwc.end(id);
1041 for (size_t i = 0; cur != end && i < count; ++i, ++cur) {
1042 currentLayers[i]->onLayerDisplayed(hw, &*cur);
1045 for (size_t i = 0; i < count; i++) {
1046 currentLayers[i]->onLayerDisplayed(hw, NULL);
1051 mLastSwapBufferTime = systemTime() - now;
1052 mDebugInSwapBuffers = 0;
1055 void SurfaceFlinger::handleTransaction(uint32_t transactionFlags)
1059 Mutex::Autolock _l(mStateLock);
1060 const nsecs_t now = systemTime();
1061 mDebugInTransaction = now;
1063 // Here we're guaranteed that some transaction flags are set
1064 // so we can call handleTransactionLocked() unconditionally.
1065 // We call getTransactionFlags(), which will also clear the flags,
1066 // with mStateLock held to guarantee that mCurrentState won't change
1067 // until the transaction is committed.
1069 transactionFlags = getTransactionFlags(eTransactionMask);
1070 handleTransactionLocked(transactionFlags);
1072 mLastTransactionTime = systemTime() - now;
1073 mDebugInTransaction = 0;
1074 invalidateHwcGeometry();
1075 // here the transaction has been committed
1078 void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
1080 const LayerVector& currentLayers(mCurrentState.layersSortedByZ);
1081 const size_t count = currentLayers.size();
1084 * Traversal of the children
1085 * (perform the transaction for each of them if needed)
1088 if (transactionFlags & eTraversalNeeded) {
1089 for (size_t i=0 ; i<count ; i++) {
1090 const sp<Layer>& layer(currentLayers[i]);
1091 uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded);
1092 if (!trFlags) continue;
1094 const uint32_t flags = layer->doTransaction(0);
1095 if (flags & Layer::eVisibleRegion)
1096 mVisibleRegionsDirty = true;
1101 * Perform display own transactions if needed
1104 if (transactionFlags & eDisplayTransactionNeeded) {
1105 // here we take advantage of Vector's copy-on-write semantics to
1106 // improve performance by skipping the transaction entirely when
1107 // know that the lists are identical
1108 const KeyedVector< wp<IBinder>, DisplayDeviceState>& curr(mCurrentState.displays);
1109 const KeyedVector< wp<IBinder>, DisplayDeviceState>& draw(mDrawingState.displays);
1110 if (!curr.isIdenticalTo(draw)) {
1111 mVisibleRegionsDirty = true;
1112 const size_t cc = curr.size();
1113 size_t dc = draw.size();
1115 // find the displays that were removed
1116 // (ie: in drawing state but not in current state)
1117 // also handle displays that changed
1118 // (ie: displays that are in both lists)
1119 for (size_t i=0 ; i<dc ; i++) {
1120 const ssize_t j = curr.indexOfKey(draw.keyAt(i));
1122 // in drawing state but not in current state
1123 if (!draw[i].isMainDisplay()) {
1124 // Call makeCurrent() on the primary display so we can
1125 // be sure that nothing associated with this display
1127 const sp<const DisplayDevice> defaultDisplay(getDefaultDisplayDevice());
1128 DisplayDevice::makeCurrent(mEGLDisplay, defaultDisplay, mEGLContext);
1129 sp<DisplayDevice> hw(getDisplayDevice(draw.keyAt(i)));
1131 hw->disconnect(getHwComposer());
1132 if (draw[i].type < DisplayDevice::NUM_DISPLAY_TYPES)
1133 mEventThread->onHotplugReceived(draw[i].type, false);
1134 mDisplays.removeItem(draw.keyAt(i));
1136 ALOGW("trying to remove the main display");
1139 // this display is in both lists. see if something changed.
1140 const DisplayDeviceState& state(curr[j]);
1141 const wp<IBinder>& display(curr.keyAt(j));
1142 if (state.surface->asBinder() != draw[i].surface->asBinder()) {
1143 // changing the surface is like destroying and
1144 // recreating the DisplayDevice, so we just remove it
1145 // from the drawing state, so that it get re-added
1147 sp<DisplayDevice> hw(getDisplayDevice(display));
1149 hw->disconnect(getHwComposer());
1150 mDisplays.removeItem(display);
1151 mDrawingState.displays.removeItemsAt(i);
1153 // at this point we must loop to the next item
1157 const sp<DisplayDevice> disp(getDisplayDevice(display));
1159 if (state.layerStack != draw[i].layerStack) {
1160 disp->setLayerStack(state.layerStack);
1162 if ((state.orientation != draw[i].orientation)
1163 || (state.viewport != draw[i].viewport)
1164 || (state.frame != draw[i].frame))
1166 disp->setProjection(state.orientation,
1167 state.viewport, state.frame);
1173 // find displays that were added
1174 // (ie: in current state but not in drawing state)
1175 for (size_t i=0 ; i<cc ; i++) {
1176 if (draw.indexOfKey(curr.keyAt(i)) < 0) {
1177 const DisplayDeviceState& state(curr[i]);
1179 sp<DisplaySurface> dispSurface;
1180 int32_t hwcDisplayId = -1;
1181 if (state.isVirtualDisplay()) {
1182 // Virtual displays without a surface are dormant:
1183 // they have external state (layer stack, projection,
1184 // etc.) but no internal state (i.e. a DisplayDevice).
1185 if (state.surface != NULL) {
1186 hwcDisplayId = allocateHwcDisplayId(state.type);
1187 dispSurface = new VirtualDisplaySurface(
1188 *mHwc, hwcDisplayId, state.surface,
1192 ALOGE_IF(state.surface!=NULL,
1193 "adding a supported display, but rendering "
1194 "surface is provided (%p), ignoring it",
1195 state.surface.get());
1196 hwcDisplayId = allocateHwcDisplayId(state.type);
1197 // for supported (by hwc) displays we provide our
1198 // own rendering surface
1199 dispSurface = new FramebufferSurface(*mHwc, state.type);
1202 const wp<IBinder>& display(curr.keyAt(i));
1203 if (dispSurface != NULL) {
1204 sp<DisplayDevice> hw = new DisplayDevice(this,
1205 state.type, hwcDisplayId, state.isSecure,
1206 display, dispSurface, mEGLConfig);
1207 hw->setLayerStack(state.layerStack);
1208 hw->setProjection(state.orientation,
1209 state.viewport, state.frame);
1210 hw->setDisplayName(state.displayName);
1211 mDisplays.add(display, hw);
1212 if (state.isVirtualDisplay()) {
1213 if (hwcDisplayId >= 0) {
1214 mHwc->setVirtualDisplayProperties(hwcDisplayId,
1215 hw->getWidth(), hw->getHeight(),
1219 mEventThread->onHotplugReceived(state.type, true);
1227 if (transactionFlags & (eTraversalNeeded|eDisplayTransactionNeeded)) {
1228 // The transform hint might have changed for some layers
1229 // (either because a display has changed, or because a layer
1232 // Walk through all the layers in currentLayers,
1233 // and update their transform hint.
1235 // If a layer is visible only on a single display, then that
1236 // display is used to calculate the hint, otherwise we use the
1239 // NOTE: we do this here, rather than in rebuildLayerStacks() so that
1240 // the hint is set before we acquire a buffer from the surface texture.
1242 // NOTE: layer transactions have taken place already, so we use their
1243 // drawing state. However, SurfaceFlinger's own transaction has not
1244 // happened yet, so we must use the current state layer list
1245 // (soon to become the drawing state list).
1247 sp<const DisplayDevice> disp;
1248 uint32_t currentlayerStack = 0;
1249 for (size_t i=0; i<count; i++) {
1250 // NOTE: we rely on the fact that layers are sorted by
1251 // layerStack first (so we don't have to traverse the list
1252 // of displays for every layer).
1253 const sp<Layer>& layer(currentLayers[i]);
1254 uint32_t layerStack = layer->drawingState().layerStack;
1255 if (i==0 || currentlayerStack != layerStack) {
1256 currentlayerStack = layerStack;
1257 // figure out if this layerstack is mirrored
1258 // (more than one display) if so, pick the default display,
1259 // if not, pick the only display it's on.
1261 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
1262 sp<const DisplayDevice> hw(mDisplays[dpy]);
1263 if (hw->getLayerStack() == currentlayerStack) {
1274 // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to
1275 // redraw after transform hint changes. See bug 8508397.
1277 // could be null when this layer is using a layerStack
1278 // that is not visible on any display. Also can occur at
1279 // screen off/on times.
1280 disp = getDefaultDisplayDevice();
1282 layer->updateTransformHint(disp);
1288 * Perform our own transaction if needed
1291 const LayerVector& previousLayers(mDrawingState.layersSortedByZ);
1292 if (currentLayers.size() > previousLayers.size()) {
1293 // layers have been added
1294 mVisibleRegionsDirty = true;
1297 // some layers might have been removed, so
1298 // we need to update the regions they're exposing.
1299 if (mLayersRemoved) {
1300 mLayersRemoved = false;
1301 mVisibleRegionsDirty = true;
1302 const size_t count = previousLayers.size();
1303 for (size_t i=0 ; i<count ; i++) {
1304 const sp<Layer>& layer(previousLayers[i]);
1305 if (currentLayers.indexOf(layer) < 0) {
1306 // this layer is not visible anymore
1307 // TODO: we could traverse the tree from front to back and
1308 // compute the actual visible region
1309 // TODO: we could cache the transformed region
1310 const Layer::State& s(layer->drawingState());
1311 Region visibleReg = s.transform.transform(
1312 Region(Rect(s.active.w, s.active.h)));
1313 invalidateLayerStack(s.layerStack, visibleReg);
1318 commitTransaction();
1321 void SurfaceFlinger::commitTransaction()
1323 if (!mLayersPendingRemoval.isEmpty()) {
1324 // Notify removed layers now that they can't be drawn from
1325 for (size_t i = 0; i < mLayersPendingRemoval.size(); i++) {
1326 mLayersPendingRemoval[i]->onRemoved();
1328 mLayersPendingRemoval.clear();
1331 // If this transaction is part of a window animation then the next frame
1332 // we composite should be considered an animation as well.
1333 mAnimCompositionPending = mAnimTransactionPending;
1335 mDrawingState = mCurrentState;
1336 mTransactionPending = false;
1337 mAnimTransactionPending = false;
1338 mTransactionCV.broadcast();
1341 void SurfaceFlinger::computeVisibleRegions(
1342 const LayerVector& currentLayers, uint32_t layerStack,
1343 Region& outDirtyRegion, Region& outOpaqueRegion)
1347 Region aboveOpaqueLayers;
1348 Region aboveCoveredLayers;
1351 outDirtyRegion.clear();
1353 size_t i = currentLayers.size();
1355 const sp<Layer>& layer = currentLayers[i];
1357 // start with the whole surface at its current location
1358 const Layer::State& s(layer->drawingState());
1360 // only consider the layers on the given layer stack
1361 if (s.layerStack != layerStack)
1365 * opaqueRegion: area of a surface that is fully opaque.
1367 Region opaqueRegion;
1370 * visibleRegion: area of a surface that is visible on screen
1371 * and not fully transparent. This is essentially the layer's
1372 * footprint minus the opaque regions above it.
1373 * Areas covered by a translucent surface are considered visible.
1375 Region visibleRegion;
1378 * coveredRegion: area of a surface that is covered by all
1379 * visible regions above it (which includes the translucent areas).
1381 Region coveredRegion;
1384 * transparentRegion: area of a surface that is hinted to be completely
1385 * transparent. This is only used to tell when the layer has no visible
1386 * non-transparent regions and can be removed from the layer list. It
1387 * does not affect the visibleRegion of this layer or any layers
1388 * beneath it. The hint may not be correct if apps don't respect the
1389 * SurfaceView restrictions (which, sadly, some don't).
1391 Region transparentRegion;
1394 // handle hidden surfaces by setting the visible region to empty
1395 if (CC_LIKELY(layer->isVisible())) {
1396 const bool translucent = !layer->isOpaque();
1397 Rect bounds(s.transform.transform(layer->computeBounds()));
1398 visibleRegion.set(bounds);
1399 if (!visibleRegion.isEmpty()) {
1400 // Remove the transparent area from the visible region
1402 const Transform tr(s.transform);
1403 if (tr.transformed()) {
1404 if (tr.preserveRects()) {
1405 // transform the transparent region
1406 transparentRegion = tr.transform(s.activeTransparentRegion);
1408 // transformation too complex, can't do the
1409 // transparent region optimization.
1410 transparentRegion.clear();
1413 transparentRegion = s.activeTransparentRegion;
1417 // compute the opaque region
1418 const int32_t layerOrientation = s.transform.getOrientation();
1419 if (s.alpha==255 && !translucent &&
1420 ((layerOrientation & Transform::ROT_INVALID) == false)) {
1421 // the opaque region is the layer's footprint
1422 opaqueRegion = visibleRegion;
1427 // Clip the covered region to the visible region
1428 coveredRegion = aboveCoveredLayers.intersect(visibleRegion);
1430 // Update aboveCoveredLayers for next (lower) layer
1431 aboveCoveredLayers.orSelf(visibleRegion);
1433 // subtract the opaque region covered by the layers above us
1434 visibleRegion.subtractSelf(aboveOpaqueLayers);
1436 // compute this layer's dirty region
1437 if (layer->contentDirty) {
1438 // we need to invalidate the whole region
1439 dirty = visibleRegion;
1440 // as well, as the old visible region
1441 dirty.orSelf(layer->visibleRegion);
1442 layer->contentDirty = false;
1444 /* compute the exposed region:
1445 * the exposed region consists of two components:
1446 * 1) what's VISIBLE now and was COVERED before
1447 * 2) what's EXPOSED now less what was EXPOSED before
1449 * note that (1) is conservative, we start with the whole
1450 * visible region but only keep what used to be covered by
1451 * something -- which mean it may have been exposed.
1453 * (2) handles areas that were not covered by anything but got
1454 * exposed because of a resize.
1456 const Region newExposed = visibleRegion - coveredRegion;
1457 const Region oldVisibleRegion = layer->visibleRegion;
1458 const Region oldCoveredRegion = layer->coveredRegion;
1459 const Region oldExposed = oldVisibleRegion - oldCoveredRegion;
1460 dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed);
1462 dirty.subtractSelf(aboveOpaqueLayers);
1464 // accumulate to the screen dirty region
1465 outDirtyRegion.orSelf(dirty);
1467 // Update aboveOpaqueLayers for next (lower) layer
1468 aboveOpaqueLayers.orSelf(opaqueRegion);
1470 // Store the visible region in screen space
1471 layer->setVisibleRegion(visibleRegion);
1472 layer->setCoveredRegion(coveredRegion);
1473 layer->setVisibleNonTransparentRegion(
1474 visibleRegion.subtract(transparentRegion));
1477 outOpaqueRegion = aboveOpaqueLayers;
1480 void SurfaceFlinger::invalidateLayerStack(uint32_t layerStack,
1481 const Region& dirty) {
1482 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
1483 const sp<DisplayDevice>& hw(mDisplays[dpy]);
1484 if (hw->getLayerStack() == layerStack) {
1485 hw->dirtyRegion.orSelf(dirty);
1490 void SurfaceFlinger::handlePageFlip()
1494 bool visibleRegions = false;
1495 const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
1496 const size_t count = currentLayers.size();
1497 for (size_t i=0 ; i<count ; i++) {
1498 const sp<Layer>& layer(currentLayers[i]);
1499 const Region dirty(layer->latchBuffer(visibleRegions));
1500 const Layer::State& s(layer->drawingState());
1501 invalidateLayerStack(s.layerStack, dirty);
1504 mVisibleRegionsDirty |= visibleRegions;
1507 void SurfaceFlinger::invalidateHwcGeometry()
1509 mHwWorkListDirty = true;
1513 void SurfaceFlinger::doDisplayComposition(const sp<const DisplayDevice>& hw,
1514 const Region& inDirtyRegion)
1516 Region dirtyRegion(inDirtyRegion);
1518 // compute the invalid region
1519 hw->swapRegion.orSelf(dirtyRegion);
1521 uint32_t flags = hw->getFlags();
1522 if (flags & DisplayDevice::SWAP_RECTANGLE) {
1523 // we can redraw only what's dirty, but since SWAP_RECTANGLE only
1524 // takes a rectangle, we must make sure to update that whole
1525 // rectangle in that case
1526 dirtyRegion.set(hw->swapRegion.bounds());
1528 if (flags & DisplayDevice::PARTIAL_UPDATES) {
1529 // We need to redraw the rectangle that will be updated
1530 // (pushed to the framebuffer).
1531 // This is needed because PARTIAL_UPDATES only takes one
1532 // rectangle instead of a region (see DisplayDevice::flip())
1533 dirtyRegion.set(hw->swapRegion.bounds());
1535 // we need to redraw everything (the whole screen)
1536 dirtyRegion.set(hw->bounds());
1537 hw->swapRegion = dirtyRegion;
1541 doComposeSurfaces(hw, dirtyRegion);
1543 // update the swap region and clear the dirty region
1544 hw->swapRegion.orSelf(dirtyRegion);
1546 // swap buffers (presentation)
1547 hw->swapBuffers(getHwComposer());
1550 void SurfaceFlinger::doComposeSurfaces(const sp<const DisplayDevice>& hw, const Region& dirty)
1552 const int32_t id = hw->getHwcDisplayId();
1553 HWComposer& hwc(getHwComposer());
1554 HWComposer::LayerListIterator cur = hwc.begin(id);
1555 const HWComposer::LayerListIterator end = hwc.end(id);
1557 const bool hasGlesComposition = hwc.hasGlesComposition(id) || (cur==end);
1558 if (hasGlesComposition) {
1559 if (!DisplayDevice::makeCurrent(mEGLDisplay, hw, mEGLContext)) {
1560 ALOGW("DisplayDevice::makeCurrent failed. Aborting surface composition for display %s",
1561 hw->getDisplayName().string());
1565 // set the frame buffer
1566 glMatrixMode(GL_MODELVIEW);
1569 // Never touch the framebuffer if we don't have any framebuffer layers
1570 const bool hasHwcComposition = hwc.hasHwcComposition(id);
1571 if (hasHwcComposition) {
1572 // when using overlays, we assume a fully transparent framebuffer
1573 // NOTE: we could reduce how much we need to clear, for instance
1574 // remove where there are opaque FB layers. however, on some
1575 // GPUs doing a "clean slate" glClear might be more efficient.
1576 // We'll revisit later if needed.
1577 glClearColor(0, 0, 0, 0);
1578 glClear(GL_COLOR_BUFFER_BIT);
1580 // we start with the whole screen area
1581 const Region bounds(hw->getBounds());
1583 // we remove the scissor part
1584 // we're left with the letterbox region
1585 // (common case is that letterbox ends-up being empty)
1586 const Region letterbox(bounds.subtract(hw->getScissor()));
1588 // compute the area to clear
1589 Region region(hw->undefinedRegion.merge(letterbox));
1591 // but limit it to the dirty region
1592 region.andSelf(dirty);
1594 // screen is already cleared here
1595 if (!region.isEmpty()) {
1596 // can happen with SurfaceView
1597 drawWormhole(hw, region);
1601 if (hw->getDisplayType() != DisplayDevice::DISPLAY_PRIMARY) {
1602 // just to be on the safe side, we don't set the
1603 // scissor on the main display. It should never be needed
1604 // anyways (though in theory it could since the API allows it).
1605 const Rect& bounds(hw->getBounds());
1606 const Rect& scissor(hw->getScissor());
1607 if (scissor != bounds) {
1608 // scissor doesn't match the screen's dimensions, so we
1609 // need to clear everything outside of it and enable
1610 // the GL scissor so we don't draw anything where we shouldn't
1611 const GLint height = hw->getHeight();
1612 glScissor(scissor.left, height - scissor.bottom,
1613 scissor.getWidth(), scissor.getHeight());
1614 // enable scissor for this frame
1615 glEnable(GL_SCISSOR_TEST);
1621 * and then, render the layers targeted at the framebuffer
1624 const Vector< sp<Layer> >& layers(hw->getVisibleLayersSortedByZ());
1625 const size_t count = layers.size();
1626 const Transform& tr = hw->getTransform();
1628 // we're using h/w composer
1629 for (size_t i=0 ; i<count && cur!=end ; ++i, ++cur) {
1630 const sp<Layer>& layer(layers[i]);
1631 const Region clip(dirty.intersect(tr.transform(layer->visibleRegion)));
1632 if (!clip.isEmpty()) {
1633 switch (cur->getCompositionType()) {
1635 if ((cur->getHints() & HWC_HINT_CLEAR_FB)
1637 && layer->isOpaque()
1638 && hasGlesComposition) {
1639 // never clear the very first layer since we're
1640 // guaranteed the FB is already cleared
1641 layer->clearWithOpenGL(hw, clip);
1645 case HWC_FRAMEBUFFER: {
1646 layer->draw(hw, clip);
1649 case HWC_FRAMEBUFFER_TARGET: {
1650 // this should not happen as the iterator shouldn't
1651 // let us get there.
1652 ALOGW("HWC_FRAMEBUFFER_TARGET found in hwc list (index=%d)", i);
1657 layer->setAcquireFence(hw, *cur);
1660 // we're not using h/w composer
1661 for (size_t i=0 ; i<count ; ++i) {
1662 const sp<Layer>& layer(layers[i]);
1663 const Region clip(dirty.intersect(
1664 tr.transform(layer->visibleRegion)));
1665 if (!clip.isEmpty()) {
1666 layer->draw(hw, clip);
1671 // disable scissor at the end of the frame
1672 glDisable(GL_SCISSOR_TEST);
1675 void SurfaceFlinger::drawWormhole(const sp<const DisplayDevice>& hw,
1676 const Region& region) const
1678 glDisable(GL_TEXTURE_EXTERNAL_OES);
1679 glDisable(GL_TEXTURE_2D);
1680 glDisable(GL_BLEND);
1683 const int32_t height = hw->getHeight();
1684 Region::const_iterator it = region.begin();
1685 Region::const_iterator const end = region.end();
1687 const Rect& r = *it++;
1688 GLfloat vertices[][2] = {
1689 { (GLfloat) r.left, (GLfloat) (height - r.top) },
1690 { (GLfloat) r.left, (GLfloat) (height - r.bottom) },
1691 { (GLfloat) r.right, (GLfloat) (height - r.bottom) },
1692 { (GLfloat) r.right, (GLfloat) (height - r.top) }
1694 glVertexPointer(2, GL_FLOAT, 0, vertices);
1695 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1699 void SurfaceFlinger::addClientLayer(const sp<Client>& client,
1700 const sp<IBinder>& handle,
1701 const sp<IGraphicBufferProducer>& gbc,
1702 const sp<Layer>& lbc)
1704 // attach this layer to the client
1705 client->attachLayer(handle, lbc);
1707 // add this layer to the current state list
1708 Mutex::Autolock _l(mStateLock);
1709 mCurrentState.layersSortedByZ.add(lbc);
1710 mGraphicBufferProducerList.add(gbc->asBinder());
1713 status_t SurfaceFlinger::removeLayer(const sp<Layer>& layer)
1715 Mutex::Autolock _l(mStateLock);
1716 ssize_t index = mCurrentState.layersSortedByZ.remove(layer);
1718 mLayersPendingRemoval.push(layer);
1719 mLayersRemoved = true;
1720 setTransactionFlags(eTransactionNeeded);
1723 return status_t(index);
1726 uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t flags)
1728 return android_atomic_release_load(&mTransactionFlags);
1731 uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags)
1733 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1736 uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags)
1738 uint32_t old = android_atomic_or(flags, &mTransactionFlags);
1739 if ((old & flags)==0) { // wake the server up
1740 signalTransaction();
1745 void SurfaceFlinger::setTransactionState(
1746 const Vector<ComposerState>& state,
1747 const Vector<DisplayState>& displays,
1751 Mutex::Autolock _l(mStateLock);
1752 uint32_t transactionFlags = 0;
1754 if (flags & eAnimation) {
1755 // For window updates that are part of an animation we must wait for
1756 // previous animation "frames" to be handled.
1757 while (mAnimTransactionPending) {
1758 status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5));
1759 if (CC_UNLIKELY(err != NO_ERROR)) {
1760 // just in case something goes wrong in SF, return to the
1761 // caller after a few seconds.
1762 ALOGW_IF(err == TIMED_OUT, "setTransactionState timed out "
1763 "waiting for previous animation frame");
1764 mAnimTransactionPending = false;
1770 size_t count = displays.size();
1771 for (size_t i=0 ; i<count ; i++) {
1772 const DisplayState& s(displays[i]);
1773 transactionFlags |= setDisplayStateLocked(s);
1776 count = state.size();
1777 for (size_t i=0 ; i<count ; i++) {
1778 const ComposerState& s(state[i]);
1779 // Here we need to check that the interface we're given is indeed
1780 // one of our own. A malicious client could give us a NULL
1781 // IInterface, or one of its own or even one of our own but a
1782 // different type. All these situations would cause us to crash.
1784 // NOTE: it would be better to use RTTI as we could directly check
1785 // that we have a Client*. however, RTTI is disabled in Android.
1786 if (s.client != NULL) {
1787 sp<IBinder> binder = s.client->asBinder();
1788 if (binder != NULL) {
1789 String16 desc(binder->getInterfaceDescriptor());
1790 if (desc == ISurfaceComposerClient::descriptor) {
1791 sp<Client> client( static_cast<Client *>(s.client.get()) );
1792 transactionFlags |= setClientStateLocked(client, s.state);
1798 if (transactionFlags) {
1799 // this triggers the transaction
1800 setTransactionFlags(transactionFlags);
1802 // if this is a synchronous transaction, wait for it to take effect
1803 // before returning.
1804 if (flags & eSynchronous) {
1805 mTransactionPending = true;
1807 if (flags & eAnimation) {
1808 mAnimTransactionPending = true;
1810 while (mTransactionPending) {
1811 status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5));
1812 if (CC_UNLIKELY(err != NO_ERROR)) {
1813 // just in case something goes wrong in SF, return to the
1814 // called after a few seconds.
1815 ALOGW_IF(err == TIMED_OUT, "setTransactionState timed out!");
1816 mTransactionPending = false;
1823 uint32_t SurfaceFlinger::setDisplayStateLocked(const DisplayState& s)
1825 ssize_t dpyIdx = mCurrentState.displays.indexOfKey(s.token);
1830 DisplayDeviceState& disp(mCurrentState.displays.editValueAt(dpyIdx));
1831 if (disp.isValid()) {
1832 const uint32_t what = s.what;
1833 if (what & DisplayState::eSurfaceChanged) {
1834 if (disp.surface->asBinder() != s.surface->asBinder()) {
1835 disp.surface = s.surface;
1836 flags |= eDisplayTransactionNeeded;
1839 if (what & DisplayState::eLayerStackChanged) {
1840 if (disp.layerStack != s.layerStack) {
1841 disp.layerStack = s.layerStack;
1842 flags |= eDisplayTransactionNeeded;
1845 if (what & DisplayState::eDisplayProjectionChanged) {
1846 if (disp.orientation != s.orientation) {
1847 disp.orientation = s.orientation;
1848 flags |= eDisplayTransactionNeeded;
1850 if (disp.frame != s.frame) {
1851 disp.frame = s.frame;
1852 flags |= eDisplayTransactionNeeded;
1854 if (disp.viewport != s.viewport) {
1855 disp.viewport = s.viewport;
1856 flags |= eDisplayTransactionNeeded;
1863 uint32_t SurfaceFlinger::setClientStateLocked(
1864 const sp<Client>& client,
1865 const layer_state_t& s)
1868 sp<Layer> layer(client->getLayerUser(s.surface));
1870 const uint32_t what = s.what;
1871 if (what & layer_state_t::ePositionChanged) {
1872 if (layer->setPosition(s.x, s.y))
1873 flags |= eTraversalNeeded;
1875 if (what & layer_state_t::eLayerChanged) {
1876 // NOTE: index needs to be calculated before we update the state
1877 ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
1878 if (layer->setLayer(s.z)) {
1879 mCurrentState.layersSortedByZ.removeAt(idx);
1880 mCurrentState.layersSortedByZ.add(layer);
1881 // we need traversal (state changed)
1882 // AND transaction (list changed)
1883 flags |= eTransactionNeeded|eTraversalNeeded;
1886 if (what & layer_state_t::eSizeChanged) {
1887 if (layer->setSize(s.w, s.h)) {
1888 flags |= eTraversalNeeded;
1891 if (what & layer_state_t::eAlphaChanged) {
1892 if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f)))
1893 flags |= eTraversalNeeded;
1895 if (what & layer_state_t::eMatrixChanged) {
1896 if (layer->setMatrix(s.matrix))
1897 flags |= eTraversalNeeded;
1899 if (what & layer_state_t::eTransparentRegionChanged) {
1900 if (layer->setTransparentRegionHint(s.transparentRegion))
1901 flags |= eTraversalNeeded;
1903 if (what & layer_state_t::eVisibilityChanged) {
1904 if (layer->setFlags(s.flags, s.mask))
1905 flags |= eTraversalNeeded;
1907 if (what & layer_state_t::eCropChanged) {
1908 if (layer->setCrop(s.crop))
1909 flags |= eTraversalNeeded;
1911 if (what & layer_state_t::eLayerStackChanged) {
1912 // NOTE: index needs to be calculated before we update the state
1913 ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
1914 if (layer->setLayerStack(s.layerStack)) {
1915 mCurrentState.layersSortedByZ.removeAt(idx);
1916 mCurrentState.layersSortedByZ.add(layer);
1917 // we need traversal (state changed)
1918 // AND transaction (list changed)
1919 flags |= eTransactionNeeded|eTraversalNeeded;
1926 status_t SurfaceFlinger::createLayer(
1927 const String8& name,
1928 const sp<Client>& client,
1929 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags,
1930 sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp)
1932 //ALOGD("createLayer for (%d x %d), name=%s", w, h, name.string());
1933 if (int32_t(w|h) < 0) {
1934 ALOGE("createLayer() failed, w or h is negative (w=%d, h=%d)",
1939 status_t result = NO_ERROR;
1943 switch (flags & ISurfaceComposerClient::eFXSurfaceMask) {
1944 case ISurfaceComposerClient::eFXSurfaceNormal:
1945 result = createNormalLayer(client,
1946 name, w, h, flags, format,
1947 handle, gbp, &layer);
1949 case ISurfaceComposerClient::eFXSurfaceDim:
1950 result = createDimLayer(client,
1952 handle, gbp, &layer);
1959 if (result == NO_ERROR) {
1960 addClientLayer(client, *handle, *gbp, layer);
1961 setTransactionFlags(eTransactionNeeded);
1966 status_t SurfaceFlinger::createNormalLayer(const sp<Client>& client,
1967 const String8& name, uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format,
1968 sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer)
1970 // initialize the surfaces
1972 case PIXEL_FORMAT_TRANSPARENT:
1973 case PIXEL_FORMAT_TRANSLUCENT:
1974 format = PIXEL_FORMAT_RGBA_8888;
1976 case PIXEL_FORMAT_OPAQUE:
1978 format = PIXEL_FORMAT_RGB_565;
1980 format = PIXEL_FORMAT_RGBX_8888;
1986 if (format == PIXEL_FORMAT_RGBX_8888)
1987 format = PIXEL_FORMAT_RGBA_8888;
1990 *outLayer = new Layer(this, client, name, w, h, flags);
1991 status_t err = (*outLayer)->setBuffers(w, h, format, flags);
1992 if (err == NO_ERROR) {
1993 *handle = (*outLayer)->getHandle();
1994 *gbp = (*outLayer)->getBufferQueue();
1997 ALOGE_IF(err, "createNormalLayer() failed (%s)", strerror(-err));
2001 status_t SurfaceFlinger::createDimLayer(const sp<Client>& client,
2002 const String8& name, uint32_t w, uint32_t h, uint32_t flags,
2003 sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp, sp<Layer>* outLayer)
2005 *outLayer = new LayerDim(this, client, name, w, h, flags);
2006 *handle = (*outLayer)->getHandle();
2007 *gbp = (*outLayer)->getBufferQueue();
2011 status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle)
2013 // called by the window manager when it wants to remove a Layer
2014 status_t err = NO_ERROR;
2015 sp<Layer> l(client->getLayerUser(handle));
2017 err = removeLayer(l);
2018 ALOGE_IF(err<0 && err != NAME_NOT_FOUND,
2019 "error removing layer=%p (%s)", l.get(), strerror(-err));
2024 status_t SurfaceFlinger::onLayerDestroyed(const wp<Layer>& layer)
2026 // called by ~LayerCleaner() when all references to the IBinder (handle)
2028 status_t err = NO_ERROR;
2029 sp<Layer> l(layer.promote());
2031 err = removeLayer(l);
2032 ALOGE_IF(err<0 && err != NAME_NOT_FOUND,
2033 "error removing layer=%p (%s)", l.get(), strerror(-err));
2038 // ---------------------------------------------------------------------------
2040 void SurfaceFlinger::onInitializeDisplays() {
2041 // reset screen orientation and use primary layer stack
2042 Vector<ComposerState> state;
2043 Vector<DisplayState> displays;
2045 d.what = DisplayState::eDisplayProjectionChanged |
2046 DisplayState::eLayerStackChanged;
2047 d.token = mBuiltinDisplays[DisplayDevice::DISPLAY_PRIMARY];
2049 d.orientation = DisplayState::eOrientationDefault;
2050 d.frame.makeInvalid();
2051 d.viewport.makeInvalid();
2053 setTransactionState(state, displays, 0);
2054 onScreenAcquired(getDefaultDisplayDevice());
2057 void SurfaceFlinger::initializeDisplays() {
2058 class MessageScreenInitialized : public MessageBase {
2059 SurfaceFlinger* flinger;
2061 MessageScreenInitialized(SurfaceFlinger* flinger) : flinger(flinger) { }
2062 virtual bool handler() {
2063 flinger->onInitializeDisplays();
2067 sp<MessageBase> msg = new MessageScreenInitialized(this);
2068 postMessageAsync(msg); // we may be called from main thread, use async message
2072 void SurfaceFlinger::onScreenAcquired(const sp<const DisplayDevice>& hw) {
2073 ALOGD("Screen acquired, type=%d flinger=%p", hw->getDisplayType(), this);
2074 if (hw->isScreenAcquired()) {
2075 // this is expected, e.g. when power manager wakes up during boot
2076 ALOGD(" screen was previously acquired");
2080 hw->acquireScreen();
2081 int32_t type = hw->getDisplayType();
2082 if (type < DisplayDevice::NUM_DISPLAY_TYPES) {
2083 // built-in display, tell the HWC
2084 getHwComposer().acquire(type);
2086 if (type == DisplayDevice::DISPLAY_PRIMARY) {
2087 // FIXME: eventthread only knows about the main display right now
2088 mEventThread->onScreenAcquired();
2091 mVisibleRegionsDirty = true;
2092 repaintEverything();
2095 void SurfaceFlinger::onScreenReleased(const sp<const DisplayDevice>& hw) {
2096 ALOGD("Screen released, type=%d flinger=%p", hw->getDisplayType(), this);
2097 if (!hw->isScreenAcquired()) {
2098 ALOGD(" screen was previously released");
2102 hw->releaseScreen();
2103 int32_t type = hw->getDisplayType();
2104 if (type < DisplayDevice::NUM_DISPLAY_TYPES) {
2105 if (type == DisplayDevice::DISPLAY_PRIMARY) {
2106 // FIXME: eventthread only knows about the main display right now
2107 mEventThread->onScreenReleased();
2110 // built-in display, tell the HWC
2111 getHwComposer().release(type);
2113 mVisibleRegionsDirty = true;
2114 // from this point on, SF will stop drawing on this display
2117 void SurfaceFlinger::unblank(const sp<IBinder>& display) {
2118 class MessageScreenAcquired : public MessageBase {
2119 SurfaceFlinger& mFlinger;
2120 sp<IBinder> mDisplay;
2122 MessageScreenAcquired(SurfaceFlinger& flinger,
2123 const sp<IBinder>& disp) : mFlinger(flinger), mDisplay(disp) { }
2124 virtual bool handler() {
2125 const sp<DisplayDevice> hw(mFlinger.getDisplayDevice(mDisplay));
2127 ALOGE("Attempt to unblank null display %p", mDisplay.get());
2128 } else if (hw->getDisplayType() >= DisplayDevice::NUM_DISPLAY_TYPES) {
2129 ALOGW("Attempt to unblank virtual display");
2131 mFlinger.onScreenAcquired(hw);
2136 sp<MessageBase> msg = new MessageScreenAcquired(*this, display);
2137 postMessageSync(msg);
2140 void SurfaceFlinger::blank(const sp<IBinder>& display) {
2141 class MessageScreenReleased : public MessageBase {
2142 SurfaceFlinger& mFlinger;
2143 sp<IBinder> mDisplay;
2145 MessageScreenReleased(SurfaceFlinger& flinger,
2146 const sp<IBinder>& disp) : mFlinger(flinger), mDisplay(disp) { }
2147 virtual bool handler() {
2148 const sp<DisplayDevice> hw(mFlinger.getDisplayDevice(mDisplay));
2150 ALOGE("Attempt to blank null display %p", mDisplay.get());
2151 } else if (hw->getDisplayType() >= DisplayDevice::NUM_DISPLAY_TYPES) {
2152 ALOGW("Attempt to blank virtual display");
2154 mFlinger.onScreenReleased(hw);
2159 sp<MessageBase> msg = new MessageScreenReleased(*this, display);
2160 postMessageSync(msg);
2163 // ---------------------------------------------------------------------------
2165 status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args)
2169 IPCThreadState* ipc = IPCThreadState::self();
2170 const int pid = ipc->getCallingPid();
2171 const int uid = ipc->getCallingUid();
2172 if ((uid != AID_SHELL) &&
2173 !PermissionCache::checkPermission(sDump, pid, uid)) {
2174 result.appendFormat("Permission Denial: "
2175 "can't dump SurfaceFlinger from pid=%d, uid=%d\n", pid, uid);
2177 // Try to get the main lock, but don't insist if we can't
2178 // (this would indicate SF is stuck, but we want to be able to
2179 // print something in dumpsys).
2181 while (mStateLock.tryLock()<0 && --retry>=0) {
2184 const bool locked(retry >= 0);
2187 "SurfaceFlinger appears to be unresponsive, "
2188 "dumping anyways (no locks held)\n");
2191 bool dumpAll = true;
2193 size_t numArgs = args.size();
2195 if ((index < numArgs) &&
2196 (args[index] == String16("--list"))) {
2198 listLayersLocked(args, index, result);
2202 if ((index < numArgs) &&
2203 (args[index] == String16("--latency"))) {
2205 dumpStatsLocked(args, index, result);
2209 if ((index < numArgs) &&
2210 (args[index] == String16("--latency-clear"))) {
2212 clearStatsLocked(args, index, result);
2218 dumpAllLocked(args, index, result);
2222 mStateLock.unlock();
2225 write(fd, result.string(), result.size());
2229 void SurfaceFlinger::listLayersLocked(const Vector<String16>& args, size_t& index,
2230 String8& result) const
2232 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
2233 const size_t count = currentLayers.size();
2234 for (size_t i=0 ; i<count ; i++) {
2235 const sp<Layer>& layer(currentLayers[i]);
2236 result.appendFormat("%s\n", layer->getName().string());
2240 void SurfaceFlinger::dumpStatsLocked(const Vector<String16>& args, size_t& index,
2241 String8& result) const
2244 if (index < args.size()) {
2245 name = String8(args[index]);
2249 const nsecs_t period =
2250 getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY);
2251 result.appendFormat("%lld\n", period);
2253 if (name.isEmpty()) {
2254 mAnimFrameTracker.dump(result);
2256 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
2257 const size_t count = currentLayers.size();
2258 for (size_t i=0 ; i<count ; i++) {
2259 const sp<Layer>& layer(currentLayers[i]);
2260 if (name == layer->getName()) {
2261 layer->dumpStats(result);
2267 void SurfaceFlinger::clearStatsLocked(const Vector<String16>& args, size_t& index,
2271 if (index < args.size()) {
2272 name = String8(args[index]);
2276 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
2277 const size_t count = currentLayers.size();
2278 for (size_t i=0 ; i<count ; i++) {
2279 const sp<Layer>& layer(currentLayers[i]);
2280 if (name.isEmpty() || (name == layer->getName())) {
2281 layer->clearStats();
2285 mAnimFrameTracker.clear();
2288 /*static*/ void SurfaceFlinger::appendSfConfigString(String8& result)
2290 static const char* config =
2295 #ifdef HAS_CONTEXT_PRIORITY
2296 " HAS_CONTEXT_PRIORITY"
2298 #ifdef NEVER_DEFAULT_TO_ASYNC_MODE
2299 " NEVER_DEFAULT_TO_ASYNC_MODE"
2301 #ifdef TARGET_DISABLE_TRIPLE_BUFFERING
2302 " TARGET_DISABLE_TRIPLE_BUFFERING"
2305 result.append(config);
2308 void SurfaceFlinger::dumpAllLocked(const Vector<String16>& args, size_t& index,
2309 String8& result) const
2311 bool colorize = false;
2312 if (index < args.size()
2313 && (args[index] == String16("--color"))) {
2318 Colorizer colorizer(colorize);
2320 // figure out if we're stuck somewhere
2321 const nsecs_t now = systemTime();
2322 const nsecs_t inSwapBuffers(mDebugInSwapBuffers);
2323 const nsecs_t inTransaction(mDebugInTransaction);
2324 nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0;
2325 nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0;
2328 * Dump library configuration.
2331 colorizer.bold(result);
2332 result.append("Build configuration:");
2333 colorizer.reset(result);
2334 appendSfConfigString(result);
2335 appendUiConfigString(result);
2336 appendGuiConfigString(result);
2337 result.append("\n");
2339 colorizer.bold(result);
2340 result.append("Sync configuration: ");
2341 colorizer.reset(result);
2342 result.append(SyncFeatures::getInstance().toString());
2343 result.append("\n");
2346 * Dump the visible layer list
2348 const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
2349 const size_t count = currentLayers.size();
2350 colorizer.bold(result);
2351 result.appendFormat("Visible layers (count = %d)\n", count);
2352 colorizer.reset(result);
2353 for (size_t i=0 ; i<count ; i++) {
2354 const sp<Layer>& layer(currentLayers[i]);
2355 layer->dump(result, colorizer);
2359 * Dump Display state
2362 colorizer.bold(result);
2363 result.appendFormat("Displays (%d entries)\n", mDisplays.size());
2364 colorizer.reset(result);
2365 for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
2366 const sp<const DisplayDevice>& hw(mDisplays[dpy]);
2371 * Dump SurfaceFlinger global state
2374 colorizer.bold(result);
2375 result.append("SurfaceFlinger global state:\n");
2376 colorizer.reset(result);
2378 HWComposer& hwc(getHwComposer());
2379 sp<const DisplayDevice> hw(getDefaultDisplayDevice());
2380 const GLExtensions& extensions(GLExtensions::getInstance());
2382 colorizer.bold(result);
2383 result.appendFormat("EGL implementation : %s\n",
2384 eglQueryStringImplementationANDROID(mEGLDisplay, EGL_VERSION));
2385 colorizer.reset(result);
2386 result.appendFormat("%s\n",
2387 eglQueryStringImplementationANDROID(mEGLDisplay, EGL_EXTENSIONS));
2389 colorizer.bold(result);
2390 result.appendFormat("GLES: %s, %s, %s\n",
2391 extensions.getVendor(),
2392 extensions.getRenderer(),
2393 extensions.getVersion());
2394 colorizer.reset(result);
2395 result.appendFormat("%s\n", extensions.getExtension());
2397 hw->undefinedRegion.dump(result, "undefinedRegion");
2398 result.appendFormat(" orientation=%d, canDraw=%d\n",
2399 hw->getOrientation(), hw->canDraw());
2400 result.appendFormat(
2401 " last eglSwapBuffers() time: %f us\n"
2402 " last transaction time : %f us\n"
2403 " transaction-flags : %08x\n"
2404 " refresh-rate : %f fps\n"
2407 " EGL_NATIVE_VISUAL_ID : %d\n"
2408 " gpu_to_cpu_unsupported : %d\n"
2410 mLastSwapBufferTime/1000.0,
2411 mLastTransactionTime/1000.0,
2413 1e9 / hwc.getRefreshPeriod(HWC_DISPLAY_PRIMARY),
2414 hwc.getDpiX(HWC_DISPLAY_PRIMARY),
2415 hwc.getDpiY(HWC_DISPLAY_PRIMARY),
2417 !mGpuToCpuSupported);
2419 result.appendFormat(" eglSwapBuffers time: %f us\n",
2420 inSwapBuffersDuration/1000.0);
2422 result.appendFormat(" transaction time: %f us\n",
2423 inTransactionDuration/1000.0);
2428 mEventThread->dump(result);
2431 * Dump HWComposer state
2433 colorizer.bold(result);
2434 result.append("h/w composer state:\n");
2435 colorizer.reset(result);
2436 result.appendFormat(" h/w composer %s and %s\n",
2437 hwc.initCheck()==NO_ERROR ? "present" : "not present",
2438 (mDebugDisableHWC || mDebugRegion) ? "disabled" : "enabled");
2442 * Dump gralloc state
2444 const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get());
2448 const Vector< sp<Layer> >&
2449 SurfaceFlinger::getLayerSortedByZForHwcDisplay(int id) {
2450 // Note: mStateLock is held here
2452 for (size_t i=0 ; i<mDisplays.size() ; i++) {
2453 if (mDisplays.valueAt(i)->getHwcDisplayId() == id) {
2454 dpy = mDisplays.keyAt(i);
2459 ALOGE("getLayerSortedByZForHwcDisplay: invalid hwc display id %d", id);
2460 // Just use the primary display so we have something to return
2461 dpy = getBuiltInDisplay(DisplayDevice::DISPLAY_PRIMARY);
2463 return getDisplayDevice(dpy)->getVisibleLayersSortedByZ();
2466 bool SurfaceFlinger::startDdmConnection()
2468 void* libddmconnection_dso =
2469 dlopen("libsurfaceflinger_ddmconnection.so", RTLD_NOW);
2470 if (!libddmconnection_dso) {
2473 void (*DdmConnection_start)(const char* name);
2474 DdmConnection_start =
2475 (typeof DdmConnection_start)dlsym(libddmconnection_dso, "DdmConnection_start");
2476 if (!DdmConnection_start) {
2477 dlclose(libddmconnection_dso);
2480 (*DdmConnection_start)(getServiceName());
2484 status_t SurfaceFlinger::onTransact(
2485 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
2488 case CREATE_CONNECTION:
2489 case CREATE_DISPLAY:
2490 case SET_TRANSACTION_STATE:
2495 // codes that require permission check
2496 IPCThreadState* ipc = IPCThreadState::self();
2497 const int pid = ipc->getCallingPid();
2498 const int uid = ipc->getCallingUid();
2499 if ((uid != AID_GRAPHICS) &&
2500 !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) {
2501 ALOGE("Permission Denial: "
2502 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
2503 return PERMISSION_DENIED;
2507 case CAPTURE_SCREEN:
2509 // codes that require permission check
2510 IPCThreadState* ipc = IPCThreadState::self();
2511 const int pid = ipc->getCallingPid();
2512 const int uid = ipc->getCallingUid();
2513 if ((uid != AID_GRAPHICS) &&
2514 !PermissionCache::checkPermission(sReadFramebuffer, pid, uid)) {
2515 ALOGE("Permission Denial: "
2516 "can't read framebuffer pid=%d, uid=%d", pid, uid);
2517 return PERMISSION_DENIED;
2523 status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags);
2524 if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
2525 CHECK_INTERFACE(ISurfaceComposer, data, reply);
2526 if (CC_UNLIKELY(!PermissionCache::checkCallingPermission(sHardwareTest))) {
2527 IPCThreadState* ipc = IPCThreadState::self();
2528 const int pid = ipc->getCallingPid();
2529 const int uid = ipc->getCallingUid();
2530 ALOGE("Permission Denial: "
2531 "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
2532 return PERMISSION_DENIED;
2536 case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE
2537 case 1001: // SHOW_FPS, NOT SUPPORTED ANYMORE
2539 case 1002: // SHOW_UPDATES
2540 n = data.readInt32();
2541 mDebugRegion = n ? n : (mDebugRegion ? 0 : 1);
2542 invalidateHwcGeometry();
2543 repaintEverything();
2545 case 1004:{ // repaint everything
2546 repaintEverything();
2549 case 1005:{ // force transaction
2550 setTransactionFlags(
2552 eDisplayTransactionNeeded|
2556 case 1006:{ // send empty update
2560 case 1008: // toggle use of hw composer
2561 n = data.readInt32();
2562 mDebugDisableHWC = n ? 1 : 0;
2563 invalidateHwcGeometry();
2564 repaintEverything();
2566 case 1009: // toggle use of transform hint
2567 n = data.readInt32();
2568 mDebugDisableTransformHint = n ? 1 : 0;
2569 invalidateHwcGeometry();
2570 repaintEverything();
2572 case 1010: // interrogate.
2573 reply->writeInt32(0);
2574 reply->writeInt32(0);
2575 reply->writeInt32(mDebugRegion);
2576 reply->writeInt32(0);
2577 reply->writeInt32(mDebugDisableHWC);
2580 Mutex::Autolock _l(mStateLock);
2581 sp<const DisplayDevice> hw(getDefaultDisplayDevice());
2582 reply->writeInt32(hw->getPageFlipCount());
2590 void SurfaceFlinger::repaintEverything() {
2591 android_atomic_or(1, &mRepaintEverything);
2592 signalTransaction();
2595 // ---------------------------------------------------------------------------
2596 // Capture screen into an IGraphiBufferProducer
2597 // ---------------------------------------------------------------------------
2599 status_t SurfaceFlinger::captureScreen(const sp<IBinder>& display,
2600 const sp<IGraphicBufferProducer>& producer,
2601 uint32_t reqWidth, uint32_t reqHeight,
2602 uint32_t minLayerZ, uint32_t maxLayerZ,
2603 bool isCpuConsumer) {
2605 if (CC_UNLIKELY(display == 0))
2608 if (CC_UNLIKELY(producer == 0))
2611 class MessageCaptureScreen : public MessageBase {
2612 SurfaceFlinger* flinger;
2613 sp<IBinder> display;
2614 sp<IGraphicBufferProducer> producer;
2615 uint32_t reqWidth, reqHeight;
2616 uint32_t minLayerZ,maxLayerZ;
2620 MessageCaptureScreen(SurfaceFlinger* flinger,
2621 const sp<IBinder>& display,
2622 const sp<IGraphicBufferProducer>& producer,
2623 uint32_t reqWidth, uint32_t reqHeight,
2624 uint32_t minLayerZ, uint32_t maxLayerZ, bool isCpuConsumer)
2625 : flinger(flinger), display(display), producer(producer),
2626 reqWidth(reqWidth), reqHeight(reqHeight),
2627 minLayerZ(minLayerZ), maxLayerZ(maxLayerZ),
2628 isCpuConsumer(isCpuConsumer),
2629 result(PERMISSION_DENIED)
2632 status_t getResult() const {
2635 virtual bool handler() {
2636 Mutex::Autolock _l(flinger->mStateLock);
2637 sp<const DisplayDevice> hw(flinger->getDisplayDevice(display));
2638 bool useReadPixels = isCpuConsumer && !flinger->mGpuToCpuSupported;
2639 result = flinger->captureScreenImplLocked(hw,
2640 producer, reqWidth, reqHeight, minLayerZ, maxLayerZ,
2647 // make sure to process transactions before screenshots -- a transaction
2648 // might already be pending but scheduled for VSYNC; this guarantees we
2649 // will handle it before the screenshot. When VSYNC finally arrives
2650 // the scheduled transaction will be a no-op. If no transactions are
2651 // scheduled at this time, this will end-up being a no-op as well.
2652 mEventQueue.invalidateTransactionNow();
2654 sp<MessageBase> msg = new MessageCaptureScreen(this,
2655 display, producer, reqWidth, reqHeight, minLayerZ, maxLayerZ,
2657 status_t res = postMessageSync(msg);
2658 if (res == NO_ERROR) {
2659 res = static_cast<MessageCaptureScreen*>( msg.get() )->getResult();
2665 void SurfaceFlinger::renderScreenImplLocked(
2666 const sp<const DisplayDevice>& hw,
2667 uint32_t reqWidth, uint32_t reqHeight,
2668 uint32_t minLayerZ, uint32_t maxLayerZ,
2673 // get screen geometry
2674 const uint32_t hw_w = hw->getWidth();
2675 const uint32_t hw_h = hw->getHeight();
2677 const bool filtering = reqWidth != hw_w || reqWidth != hw_h;
2679 // make sure to clear all GL error flags
2680 while ( glGetError() != GL_NO_ERROR ) ;
2682 // set-up our viewport
2683 glViewport(0, 0, reqWidth, reqHeight);
2684 glMatrixMode(GL_PROJECTION);
2686 if (yswap) glOrthof(0, hw_w, hw_h, 0, 0, 1);
2687 else glOrthof(0, hw_w, 0, hw_h, 0, 1);
2688 glMatrixMode(GL_MODELVIEW);
2691 // redraw the screen entirely...
2692 glDisable(GL_SCISSOR_TEST);
2693 glClearColor(0,0,0,1);
2694 glClear(GL_COLOR_BUFFER_BIT);
2695 glDisable(GL_TEXTURE_EXTERNAL_OES);
2696 glDisable(GL_TEXTURE_2D);
2698 const LayerVector& layers( mDrawingState.layersSortedByZ );
2699 const size_t count = layers.size();
2700 for (size_t i=0 ; i<count ; ++i) {
2701 const sp<Layer>& layer(layers[i]);
2702 const Layer::State& state(layer->drawingState());
2703 if (state.layerStack == hw->getLayerStack()) {
2704 if (state.z >= minLayerZ && state.z <= maxLayerZ) {
2705 if (layer->isVisible()) {
2706 if (filtering) layer->setFiltering(true);
2708 if (filtering) layer->setFiltering(false);
2714 // compositionComplete is needed for older driver
2715 hw->compositionComplete();
2719 status_t SurfaceFlinger::captureScreenImplLocked(
2720 const sp<const DisplayDevice>& hw,
2721 const sp<IGraphicBufferProducer>& producer,
2722 uint32_t reqWidth, uint32_t reqHeight,
2723 uint32_t minLayerZ, uint32_t maxLayerZ,
2728 if (!GLExtensions::getInstance().haveFramebufferObject()) {
2729 return INVALID_OPERATION;
2732 // get screen geometry
2733 const uint32_t hw_w = hw->getWidth();
2734 const uint32_t hw_h = hw->getHeight();
2736 // if we have secure windows on this display, never allow the screen capture
2737 if (hw->getSecureLayerVisible()) {
2738 ALOGW("FB is protected: PERMISSION_DENIED");
2739 return PERMISSION_DENIED;
2742 if ((reqWidth > hw_w) || (reqHeight > hw_h)) {
2743 ALOGE("size mismatch (%d, %d) > (%d, %d)",
2744 reqWidth, reqHeight, hw_w, hw_h);
2748 reqWidth = (!reqWidth) ? hw_w : reqWidth;
2749 reqHeight = (!reqHeight) ? hw_h : reqHeight;
2751 // create a surface (because we're a producer, and we need to
2752 // dequeue/queue a buffer)
2753 sp<Surface> sur = new Surface(producer);
2754 ANativeWindow* window = sur.get();
2756 status_t result = NO_ERROR;
2757 if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) == NO_ERROR) {
2758 uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
2759 if (!useReadPixels) {
2760 usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
2764 err = native_window_set_buffers_dimensions(window, reqWidth, reqHeight);
2765 err |= native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_RGBA_8888);
2766 err |= native_window_set_usage(window, usage);
2768 if (err == NO_ERROR) {
2769 ANativeWindowBuffer* buffer;
2770 /* TODO: Once we have the sync framework everywhere this can use
2771 * server-side waits on the fence that dequeueBuffer returns.
2773 result = native_window_dequeue_buffer_and_wait(window, &buffer);
2774 if (result == NO_ERROR) {
2775 // create an EGLImage from the buffer so we can later
2776 // turn it into a texture
2777 EGLImageKHR image = eglCreateImageKHR(mEGLDisplay, EGL_NO_CONTEXT,
2778 EGL_NATIVE_BUFFER_ANDROID, buffer, NULL);
2779 if (image != EGL_NO_IMAGE_KHR) {
2781 if (!useReadPixels) {
2782 // turn our EGLImage into a texture
2783 glGenTextures(1, &tname);
2784 glBindTexture(GL_TEXTURE_2D, tname);
2785 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)image);
2786 // create a Framebuffer Object to render into
2787 glGenFramebuffersOES(1, &name);
2788 glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
2789 glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES,
2790 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tname, 0);
2792 // since we're going to use glReadPixels() anyways,
2793 // use an intermediate renderbuffer instead
2794 glGenRenderbuffersOES(1, &tname);
2795 glBindRenderbufferOES(GL_RENDERBUFFER_OES, tname);
2796 glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, reqWidth, reqHeight);
2797 // create a FBO to render into
2798 glGenFramebuffersOES(1, &name);
2799 glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
2800 glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
2801 GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, tname);
2804 GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
2805 if (status == GL_FRAMEBUFFER_COMPLETE_OES) {
2806 // this will in fact render into our dequeued buffer
2807 // via an FBO, which means we didn't have to create
2808 // an EGLSurface and therefore we're not
2809 // dependent on the context's EGLConfig.
2810 renderScreenImplLocked(hw, reqWidth, reqHeight,
2811 minLayerZ, maxLayerZ, true);
2813 if (useReadPixels) {
2814 sp<GraphicBuffer> buf = static_cast<GraphicBuffer*>(buffer);
2816 if (buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, &vaddr) == NO_ERROR) {
2817 glReadPixels(0, 0, buffer->stride, reqHeight,
2818 GL_RGBA, GL_UNSIGNED_BYTE, vaddr);
2823 ALOGE("got GL_FRAMEBUFFER_COMPLETE_OES error while taking screenshot");
2824 result = INVALID_OPERATION;
2827 // back to main framebuffer
2828 glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
2829 glDeleteFramebuffersOES(1, &name);
2830 if (!useReadPixels) {
2831 glDeleteTextures(1, &tname);
2833 glDeleteRenderbuffersOES(1, &tname);
2835 // destroy our image
2836 eglDestroyImageKHR(mEGLDisplay, image);
2840 window->queueBuffer(window, buffer, -1);
2845 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
2848 DisplayDevice::setViewportAndProjection(hw);
2853 // ---------------------------------------------------------------------------
2855 SurfaceFlinger::LayerVector::LayerVector() {
2858 SurfaceFlinger::LayerVector::LayerVector(const LayerVector& rhs)
2859 : SortedVector<sp<Layer> >(rhs) {
2862 int SurfaceFlinger::LayerVector::do_compare(const void* lhs,
2863 const void* rhs) const
2865 // sort layers per layer-stack, then by z-order and finally by sequence
2866 const sp<Layer>& l(*reinterpret_cast<const sp<Layer>*>(lhs));
2867 const sp<Layer>& r(*reinterpret_cast<const sp<Layer>*>(rhs));
2869 uint32_t ls = l->currentState().layerStack;
2870 uint32_t rs = r->currentState().layerStack;
2874 uint32_t lz = l->currentState().z;
2875 uint32_t rz = r->currentState().z;
2879 return l->sequence - r->sequence;
2882 // ---------------------------------------------------------------------------
2884 SurfaceFlinger::DisplayDeviceState::DisplayDeviceState()
2885 : type(DisplayDevice::DISPLAY_ID_INVALID) {
2888 SurfaceFlinger::DisplayDeviceState::DisplayDeviceState(DisplayDevice::DisplayType type)
2889 : type(type), layerStack(DisplayDevice::NO_LAYER_STACK), orientation(0) {
2890 viewport.makeInvalid();
2891 frame.makeInvalid();
2894 // ---------------------------------------------------------------------------
2896 }; // namespace android