From d2cb445f4c3b677a004b3be1c931ae60cf1049e7 Mon Sep 17 00:00:00 2001 From: Martin Graesslin Date: Mon, 19 Oct 2015 08:13:04 +0000 Subject: [PATCH] Delay enabling vsync till first frame is rendered According to the hwcomposer documentation: "It is a (silent) error to have HWC_EVENT_VSYNC enabled when calling hwc_composer_device.set(..., 0, 0, 0) (screen off)". Because of that we may not enable vsync directly after toggling the output, but need to wait till after calling the set call. Reviewed-by: Bhushan Shah --- backends/hwcomposer/hwcomposer_backend.cpp | 15 ++++++++++++++- backends/hwcomposer/hwcomposer_backend.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/backends/hwcomposer/hwcomposer_backend.cpp b/backends/hwcomposer/hwcomposer_backend.cpp index 691749e6f4..8d5b706ac3 100644 --- a/backends/hwcomposer/hwcomposer_backend.cpp +++ b/backends/hwcomposer/hwcomposer_backend.cpp @@ -164,7 +164,10 @@ void HwcomposerBackend::toggleBlankOutput() } m_outputBlank = !m_outputBlank; m_device->blank(m_device, 0, m_outputBlank ? 1 : 0); - m_device->eventControl(m_device, 0, HWC_EVENT_VSYNC, m_outputBlank ? 0 : 1); + // only disable Vsycn, enable happens after next frame rendered + if (m_outputBlank) { + enableVSync(false); + } // enable/disable compositor repainting when blanked if (Compositor *compositor = Compositor::self()) { if (m_outputBlank) { @@ -176,6 +179,15 @@ void HwcomposerBackend::toggleBlankOutput() } } +void HwcomposerBackend::enableVSync(bool enable) +{ + if (m_hasVsync == enable) { + return; + } + const int result = m_device->eventControl(m_device, 0, HWC_EVENT_VSYNC, enable ? 1: 0); + m_hasVsync = enable && (result == 0); +} + HwcomposerWindow *HwcomposerBackend::createSurface() { return new HwcomposerWindow(this); @@ -282,6 +294,7 @@ void HwcomposerWindow::present(HWComposerNativeWindowBuffer *buffer) err = device->set(device, 1, m_list); assert(err == 0); + m_backend->enableVSync(true); setFenceBufferFd(buffer, fblayer->releaseFenceFd); if (m_list[0]->retireFenceFd != -1) { diff --git a/backends/hwcomposer/hwcomposer_backend.h b/backends/hwcomposer/hwcomposer_backend.h index ca3da143ac..54b1bfa430 100644 --- a/backends/hwcomposer/hwcomposer_backend.h +++ b/backends/hwcomposer/hwcomposer_backend.h @@ -65,6 +65,7 @@ public: int refreshRate() const { return m_refreshRate; } + void enableVSync(bool enable); public Q_SLOTS: void vsync(); @@ -79,6 +80,7 @@ private: bool m_pageFlipPending = false; int m_refreshRate = 60000; QTimer *m_vsyncFailSafeTimer; + bool m_hasVsync = false; }; class HwcomposerWindow : public HWComposerNativeWindow