2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-05-06 15:47:07 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2015-05-06 15:47:07 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2015-05-06 15:47:07 +00:00
|
|
|
#include "egl_hwcomposer_backend.h"
|
|
|
|
#include "hwcomposer_backend.h"
|
|
|
|
#include "logging.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
EglHwcomposerBackend::EglHwcomposerBackend(HwcomposerBackend *backend)
|
|
|
|
: AbstractEglBackend()
|
|
|
|
, m_backend(backend)
|
|
|
|
{
|
|
|
|
// EGL is always direct rendering
|
|
|
|
setIsDirectRendering(true);
|
2020-01-09 17:18:22 +00:00
|
|
|
setSyncsToVBlank(true);
|
2015-05-06 15:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EglHwcomposerBackend::~EglHwcomposerBackend()
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EglHwcomposerBackend::initializeEgl()
|
|
|
|
{
|
|
|
|
// cannot use initClientExtensions as that crashes in libhybris
|
|
|
|
qputenv("EGL_PLATFORM", QByteArrayLiteral("hwcomposer"));
|
2016-07-18 08:27:56 +00:00
|
|
|
EGLDisplay display = m_backend->sceneEglDisplay();
|
2015-05-06 15:47:07 +00:00
|
|
|
|
2016-07-18 08:27:56 +00:00
|
|
|
if (display == EGL_NO_DISPLAY) {
|
|
|
|
display = eglGetDisplay(nullptr);
|
|
|
|
}
|
2015-05-06 15:47:07 +00:00
|
|
|
if (display == EGL_NO_DISPLAY) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
setEglDisplay(display);
|
|
|
|
return initEglAPI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglHwcomposerBackend::init()
|
|
|
|
{
|
2015-11-25 12:09:28 +00:00
|
|
|
if (!initializeEgl()) {
|
|
|
|
setFailed("Failed to initialize egl");
|
|
|
|
return;
|
|
|
|
}
|
2015-05-06 15:47:07 +00:00
|
|
|
if (!initRenderingContext()) {
|
|
|
|
setFailed("Could not initialize rendering context");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
initKWinGL();
|
|
|
|
initBufferAge();
|
|
|
|
initWayland();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EglHwcomposerBackend::initBufferConfigs()
|
|
|
|
{
|
|
|
|
const EGLint config_attribs[] = {
|
2015-06-25 13:49:52 +00:00
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
2016-07-19 06:16:54 +00:00
|
|
|
EGL_ALPHA_SIZE, 8,
|
2015-05-06 15:47:07 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
EGLint count;
|
|
|
|
EGLConfig configs[1024];
|
|
|
|
if (eglChooseConfig(eglDisplay(), config_attribs, configs, 1, &count) == EGL_FALSE) {
|
|
|
|
qCCritical(KWIN_HWCOMPOSER) << "choose config failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (count != 1) {
|
|
|
|
qCCritical(KWIN_HWCOMPOSER) << "choose config did not return a config" << count;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
setConfig(configs[0]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EglHwcomposerBackend::initRenderingContext()
|
|
|
|
{
|
|
|
|
if (!initBufferConfigs()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-13 07:29:49 +00:00
|
|
|
if (!createContext()) {
|
2015-05-06 15:47:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_nativeSurface = m_backend->createSurface();
|
|
|
|
EGLSurface surface = eglCreateWindowSurface(eglDisplay(), config(), (EGLNativeWindowType)static_cast<ANativeWindow*>(m_nativeSurface), nullptr);
|
|
|
|
if (surface == EGL_NO_SURFACE) {
|
|
|
|
qCCritical(KWIN_HWCOMPOSER) << "Create surface failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
setSurface(surface);
|
|
|
|
|
|
|
|
return makeContextCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EglHwcomposerBackend::makeContextCurrent()
|
|
|
|
{
|
|
|
|
if (eglMakeCurrent(eglDisplay(), surface(), surface(), context()) == EGL_FALSE) {
|
|
|
|
qCCritical(KWIN_HWCOMPOSER) << "Make Context Current failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint error = eglGetError();
|
|
|
|
if (error != EGL_SUCCESS) {
|
|
|
|
qCWarning(KWIN_HWCOMPOSER) << "Error occurred while creating context " << error;
|
|
|
|
return false;
|
|
|
|
}
|
[platforms/hwcomposer] Add scaling support
Summary:
Despite plasma frameworks doing it's own scaling with fonts, it's been
requested to use kwin/wayland scaling.
Like DRM, when kscreen is not used, scale value is loaded from a config
file.
Config format is
[HWComposerOutputs][0]
Scale=N
The 0 is to map similarly to DRM and support multi-screen, but with a
screen index
rather than a UUID based on EDID.
Because we don't support multi screen this is always 0 for now.
Test Plan: Ran with the config value unset and with the config value at
Scale=3.
Reviewers: #kwin, romangg
Reviewed By: #kwin, romangg
Subscribers: bshah, romangg, nicolasfella, zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18810
2019-02-22 00:44:12 +00:00
|
|
|
|
|
|
|
const QSize overall = m_backend->size();
|
|
|
|
glViewport(0, 0, overall.width(), overall.height());
|
|
|
|
|
2015-05-06 15:47:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglHwcomposerBackend::present()
|
|
|
|
{
|
2015-10-29 13:13:40 +00:00
|
|
|
if (lastDamage().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-06 15:47:07 +00:00
|
|
|
eglSwapBuffers(eglDisplay(), surface());
|
2015-10-29 13:13:40 +00:00
|
|
|
setLastDamage(QRegion());
|
2015-05-06 15:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EglHwcomposerBackend::screenGeometryChanged(const QSize &size)
|
|
|
|
{
|
|
|
|
Q_UNUSED(size)
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion EglHwcomposerBackend::prepareRenderingFrame()
|
|
|
|
{
|
2015-10-29 13:13:40 +00:00
|
|
|
present();
|
|
|
|
|
2015-05-06 15:47:07 +00:00
|
|
|
// TODO: buffer age?
|
|
|
|
startRenderTimer();
|
|
|
|
// triggers always a full repaint
|
|
|
|
return QRegion(QRect(QPoint(0, 0), m_backend->size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EglHwcomposerBackend::endRenderingFrame(const QRegion &renderedRegion, const QRegion &damagedRegion)
|
|
|
|
{
|
|
|
|
Q_UNUSED(damagedRegion)
|
2015-10-29 13:13:40 +00:00
|
|
|
setLastDamage(renderedRegion);
|
2015-05-06 15:47:07 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 20:30:18 +00:00
|
|
|
SceneOpenGLTexturePrivate *EglHwcomposerBackend::createBackendTexture(SceneOpenGLTexture *texture)
|
2015-05-06 15:47:07 +00:00
|
|
|
{
|
|
|
|
return new EglHwcomposerTexture(texture, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EglHwcomposerBackend::usesOverlayWindow() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-08 20:30:18 +00:00
|
|
|
EglHwcomposerTexture::EglHwcomposerTexture(SceneOpenGLTexture *texture, EglHwcomposerBackend *backend)
|
2015-05-06 15:47:07 +00:00
|
|
|
: AbstractEglTexture(texture, backend)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EglHwcomposerTexture::~EglHwcomposerTexture() = default;
|
|
|
|
|
|
|
|
}
|