f906e21f3d
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
147 lines
4 KiB
C++
147 lines
4 KiB
C++
/********************************************************************
|
|
KWin - the KDE window manager
|
|
This file is part of the KDE project.
|
|
|
|
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*********************************************************************/
|
|
#ifndef KWIN_HWCOMPOSER_BACKEND_H
|
|
#define KWIN_HWCOMPOSER_BACKEND_H
|
|
#include "platform.h"
|
|
#include "input.h"
|
|
|
|
#include <QElapsedTimer>
|
|
#include <QMutex>
|
|
#include <QWaitCondition>
|
|
|
|
// libhybris
|
|
#include <hwcomposer_window.h>
|
|
// needed as hwcomposer_window.h includes EGL which on non-arm includes Xlib
|
|
#include <fixx11h.h>
|
|
|
|
typedef struct hwc_display_contents_1 hwc_display_contents_1_t;
|
|
typedef struct hwc_layer_1 hwc_layer_1_t;
|
|
typedef struct hwc_composer_device_1 hwc_composer_device_1_t;
|
|
struct light_device_t;
|
|
|
|
class HWComposerNativeWindowBuffer;
|
|
|
|
namespace KWin
|
|
{
|
|
|
|
class HwcomposerWindow;
|
|
class BacklightInputEventFilter;
|
|
|
|
class HwcomposerBackend : public Platform
|
|
{
|
|
Q_OBJECT
|
|
Q_INTERFACES(KWin::Platform)
|
|
Q_PLUGIN_METADATA(IID "org.kde.kwin.Platform" FILE "hwcomposer.json")
|
|
public:
|
|
explicit HwcomposerBackend(QObject *parent = nullptr);
|
|
virtual ~HwcomposerBackend();
|
|
|
|
void init() override;
|
|
Screens *createScreens(QObject *parent = nullptr) override;
|
|
OpenGLBackend *createOpenGLBackend() override;
|
|
|
|
QSize screenSize() const override {
|
|
return m_displaySize;
|
|
}
|
|
|
|
HwcomposerWindow *createSurface();
|
|
|
|
QSize size() const {
|
|
return m_displaySize;
|
|
}
|
|
|
|
hwc_composer_device_1_t *device() const {
|
|
return m_device;
|
|
}
|
|
int refreshRate() const {
|
|
return m_refreshRate;
|
|
}
|
|
void enableVSync(bool enable);
|
|
void waitVSync();
|
|
void wakeVSync();
|
|
|
|
bool isBacklightOff() const {
|
|
return m_outputBlank;
|
|
}
|
|
|
|
Q_SIGNALS:
|
|
void outputBlankChanged();
|
|
|
|
private Q_SLOTS:
|
|
void toggleBlankOutput();
|
|
void screenBrightnessChanged(int brightness) {
|
|
m_oldScreenBrightness = brightness;
|
|
}
|
|
|
|
private:
|
|
void initLights();
|
|
void toggleScreenBrightness();
|
|
QSize m_displaySize;
|
|
hwc_composer_device_1_t *m_device = nullptr;
|
|
light_device_t *m_lights = nullptr;
|
|
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;
|
|
QWaitCondition m_vsyncWaitCondition;
|
|
QScopedPointer<BacklightInputEventFilter> m_filter;
|
|
};
|
|
|
|
class HwcomposerWindow : public HWComposerNativeWindow
|
|
{
|
|
public:
|
|
virtual ~HwcomposerWindow();
|
|
|
|
void present(HWComposerNativeWindowBuffer *buffer);
|
|
|
|
private:
|
|
friend HwcomposerBackend;
|
|
HwcomposerWindow(HwcomposerBackend *backend);
|
|
HwcomposerBackend *m_backend;
|
|
hwc_display_contents_1_t **m_list;
|
|
};
|
|
|
|
class BacklightInputEventFilter : public InputEventFilter
|
|
{
|
|
public:
|
|
BacklightInputEventFilter(HwcomposerBackend *backend);
|
|
virtual ~BacklightInputEventFilter();
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override;
|
|
bool wheelEvent(QWheelEvent *event) override;
|
|
bool keyEvent(QKeyEvent *event) override;
|
|
bool touchDown(quint32 id, const QPointF &pos, quint32 time) override;
|
|
bool touchMotion(quint32 id, const QPointF &pos, quint32 time) override;
|
|
bool touchUp(quint32 id, quint32 time) override;
|
|
|
|
private:
|
|
void toggleBacklight();
|
|
HwcomposerBackend *m_backend;
|
|
QElapsedTimer m_doubleTapTimer;
|
|
QVector<qint32> m_touchPoints;
|
|
bool m_secondTap = false;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|