From f906e21f3dacdf747b1b26522f9a141cb1bf2171 Mon Sep 17 00:00:00 2001 From: Bhushan Shah Date: Thu, 15 Dec 2016 19:32:49 +0530 Subject: [PATCH] [platforms/hwcomposer] Support for hwcomposer 1.4 and 1.5 version Summary: HWcomposer version 1.4 introduced setPowerMode, which replaces the blank(). This adds support for it. There are various code paths possible, - If KWin is built against hwcomposer 1.3 headers, then setPowerMode code is not compiled in, and it will use blank to turn display off. - If KWin is built against hwcomposer 1.4 headers, it will have setPowerMode code path compiled in. It will be used only on devices with 1.4 and 1.5 version of hwcomposer. This is slightly insane, because Android can report hwcomposer 1.5 even when headers are of 1.4 version.. Test Plan: Tested this on Nexus 5X which reports 1.5 version of hwcomposer Reviewers: graesslin, #plasma Reviewed By: graesslin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D3686 --- .../hwcomposer/hwcomposer_backend.cpp | 19 +++++++++++++++++-- .../platforms/hwcomposer/hwcomposer_backend.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/platforms/hwcomposer/hwcomposer_backend.cpp b/plugins/platforms/hwcomposer/hwcomposer_backend.cpp index 0dc26b80b5..97a75d054a 100644 --- a/plugins/platforms/hwcomposer/hwcomposer_backend.cpp +++ b/plugins/platforms/hwcomposer/hwcomposer_backend.cpp @@ -223,6 +223,14 @@ void HwcomposerBackend::init() // unblank, setPowerMode? m_device = hwcDevice; + m_hwcVersion = m_device->common.version; + if ((m_hwcVersion & 0xffff0000) == 0) { + // Assume header version is always 1 + uint32_t header_version = 1; + // Legacy version encoding + m_hwcVersion = (m_hwcVersion << 16) | header_version; + } + // register callbacks hwc_procs_t *procs = new hwc_procs_t; procs->invalidate = [] (const struct hwc_procs* procs) { @@ -309,8 +317,15 @@ void HwcomposerBackend::toggleBlankOutput() } m_outputBlank = !m_outputBlank; toggleScreenBrightness(); - m_device->blank(m_device, 0, m_outputBlank ? 1 : 0); - // only disable Vsycn, enable happens after next frame rendered + +#if defined(HWC_DEVICE_API_VERSION_1_4) || defined(HWC_DEVICE_API_VERSION_1_5) + if (m_hwcVersion > HWC_DEVICE_API_VERSION_1_3) + m_device->setPowerMode(m_device, 0, m_outputBlank ? 0 : 2); + else +#endif + m_device->blank(m_device, 0, m_outputBlank ? 1 : 0); + + // only disable Vsync, enable happens after next frame rendered if (m_outputBlank) { enableVSync(false); } diff --git a/plugins/platforms/hwcomposer/hwcomposer_backend.h b/plugins/platforms/hwcomposer/hwcomposer_backend.h index 69a11b9b45..5730c5c7a5 100644 --- a/plugins/platforms/hwcomposer/hwcomposer_backend.h +++ b/plugins/platforms/hwcomposer/hwcomposer_backend.h @@ -99,6 +99,7 @@ private: bool m_outputBlank = true; int m_refreshRate = 60000; int m_vsyncInterval = 16; + uint32_t m_hwcVersion; int m_oldScreenBrightness = 0x7f; bool m_hasVsync = false; QMutex m_vsyncMutex;