From 9e2463e71796964cfaa06bf09a880875ac3537bc Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 21 Sep 2012 18:26:16 -0700 Subject: [PATCH] add/remove displays properly on hotplug events Bug: 7191563 Change-Id: I8f0fbf3b29658c9479443141798e6f288a1f2d52 --- services/surfaceflinger/DisplayDevice.cpp | 7 +++++++ services/surfaceflinger/DisplayDevice.h | 4 +--- .../surfaceflinger/DisplayHardware/HWComposer.cpp | 7 ++++++- services/surfaceflinger/SurfaceFlinger.cpp | 14 ++++++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index 330e09d73..81ce27e18 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -167,6 +167,13 @@ void DisplayDevice::init(EGLConfig config) setProjection(DisplayState::eOrientationDefault, mViewport, mFrame); } +void DisplayDevice::setDisplayName(const String8& displayName) { + if (!displayName.isEmpty()) { + // never override the name with an empty name + mDisplayName = displayName; + } +} + uint32_t DisplayDevice::getPageFlipCount() const { return mPageFlipCount; } diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index d83625a45..1d7715471 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -119,9 +119,7 @@ public: } inline Rect bounds() const { return getBounds(); } - void setDisplayName(const String8& displayName) { - mDisplayName = displayName; - } + void setDisplayName(const String8& displayName); const String8& getDisplayName() const { return mDisplayName; } static EGLBoolean makeCurrent(EGLDisplay dpy, diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 81078285b..987cc647e 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -337,7 +337,12 @@ status_t HWComposer::queryDisplayProperties(int disp) { return err; } - mHwc->getDisplayAttributes(mHwc, disp, config, DISPLAY_ATTRIBUTES, values); + err = mHwc->getDisplayAttributes(mHwc, disp, config, DISPLAY_ATTRIBUTES, values); + if (err != NO_ERROR) { + // we can't get this display's info. turn it off. + mDisplayData[disp].connected = false; + return err; + } int32_t w = 0, h = 0; for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) { diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 8164d2034..837269101 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -408,10 +408,10 @@ status_t SurfaceFlinger::readyToRun() DisplayDevice::DisplayType type((DisplayDevice::DisplayType)i); mDefaultDisplays[i] = new BBinder(); wp token = mDefaultDisplays[i]; - mCurrentState.displays.add(token, DisplayDeviceState(type)); // set-up the displays that are already connected - if (mHwc->isConnected(i)) { + if (mHwc->isConnected(i) || type==DisplayDevice::DISPLAY_PRIMARY) { + mCurrentState.displays.add(token, DisplayDeviceState(type)); sp fbs = new FramebufferSurface(*mHwc, i); sp stc = new SurfaceTextureClient( static_cast< sp >(fbs->getBufferQueue())); @@ -688,7 +688,17 @@ void SurfaceFlinger::onHotplugReceived(int type, bool connected) { ALOGW("WARNING: EventThread not started, ignoring hotplug"); return; } + if (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) { + Mutex::Autolock _l(mStateLock); + if (connected == false) { + mCurrentState.displays.removeItem(mDefaultDisplays[type]); + } else { + DisplayDeviceState info((DisplayDevice::DisplayType)type); + mCurrentState.displays.add(mDefaultDisplays[type], info); + } + setTransactionFlags(eDisplayTransactionNeeded); + // we should only receive DisplayDevice::DisplayType from the vsync callback mEventThread->onHotplugReceived(type, connected); }