From 028508cad5ef63ef9fbd42c14e76658e4fd9ebf2 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 25 Jul 2012 21:12:12 -0700 Subject: [PATCH] hopefully fixe a race condition in sf initialization if we received a vsync event during SF init, we could crash as not all objects were ready to go. Change-Id: Ie11b46e3eb1b37a709dd8757843d444f93dd0189 --- .../DisplayHardware/HWComposer.cpp | 17 ++++++----------- services/surfaceflinger/SurfaceFlinger.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 1742f1b2d..0a633f01a 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -118,7 +118,7 @@ HWComposer::HWComposer( property_get("debug.sf.no_hw_vsync", value, "0"); mDebugForceFakeVSync = atoi(value); - bool needVSyncThread = false; + bool needVSyncThread = true; int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule); ALOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID); if (err == 0) { @@ -136,6 +136,11 @@ HWComposer::HWComposer( } if (mHwc) { + if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_0_3)) { + // always turn vsync off when we start + mHwc->methods->eventControl(mHwc, HWC_EVENT_VSYNC, 0); + needVSyncThread = false; + } if (mHwc->registerProcs) { mCBContext->hwc = this; mCBContext->procs.invalidate = &hook_invalidate; @@ -143,17 +148,7 @@ HWComposer::HWComposer( mHwc->registerProcs(mHwc, &mCBContext->procs); memset(mCBContext->procs.zero, 0, sizeof(mCBContext->procs.zero)); } - if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_0_3)) { - if (mDebugForceFakeVSync) { - // make sure to turn h/w vsync off in "fake vsync" mode - mHwc->methods->eventControl(mHwc, HWC_EVENT_VSYNC, 0); - } - } else { - needVSyncThread = true; - } } - } else { - needVSyncThread = true; } if (needVSyncThread) { diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 2ecdeb8e2..992c7798b 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -406,6 +406,10 @@ status_t SurfaceFlinger::readyToRun() EGLSurface surface = hw->getEGLSurface(); initializeGL(display, surface); + // start the EventThread + mEventThread = new EventThread(this); + mEventQueue.setEventThread(mEventThread); + // initialize the H/W composer mHwc = new HWComposer(this, *static_cast(this), @@ -414,10 +418,6 @@ status_t SurfaceFlinger::readyToRun() mHwc->setFrameBuffer(display, surface); } - // start the EventThread - mEventThread = new EventThread(this); - mEventQueue.setEventThread(mEventThread); - // We're now ready to accept clients... mReadyToRunBarrier.open();