2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-03-19 13:46:39 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2015-03-19 13:46:39 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-03-19 13:46:39 +00:00
|
|
|
#include "abstract_egl_backend.h"
|
2019-10-26 03:40:01 +00:00
|
|
|
#include "egl_dmabuf.h"
|
2020-05-29 13:01:27 +00:00
|
|
|
#include "kwineglext.h"
|
2017-09-03 08:26:20 +00:00
|
|
|
#include "composite.h"
|
2017-06-26 04:56:55 +00:00
|
|
|
#include "egl_context_attribute_builder.h"
|
2015-03-19 13:46:39 +00:00
|
|
|
#include "options.h"
|
2016-07-18 08:27:56 +00:00
|
|
|
#include "platform.h"
|
2017-09-08 20:30:18 +00:00
|
|
|
#include "scene.h"
|
2015-03-19 13:46:39 +00:00
|
|
|
#include "wayland_server.h"
|
2020-07-22 17:22:36 +00:00
|
|
|
#include "abstract_wayland_output.h"
|
2020-04-29 15:18:41 +00:00
|
|
|
#include <KWaylandServer/buffer_interface.h>
|
|
|
|
#include <KWaylandServer/display.h>
|
|
|
|
#include <KWaylandServer/surface_interface.h>
|
2015-03-19 13:46:39 +00:00
|
|
|
// kwin libs
|
2017-09-08 20:30:18 +00:00
|
|
|
#include <logging.h>
|
2015-03-19 13:46:39 +00:00
|
|
|
#include <kwinglplatform.h>
|
2017-09-08 20:30:18 +00:00
|
|
|
#include <kwinglutils.h>
|
2015-03-19 13:46:39 +00:00
|
|
|
// Qt
|
|
|
|
#include <QOpenGLContext>
|
2015-08-18 12:40:26 +00:00
|
|
|
#include <QOpenGLFramebufferObject>
|
2015-03-19 13:46:39 +00:00
|
|
|
|
2017-06-26 04:56:55 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef GLboolean(*eglBindWaylandDisplayWL_func)(EGLDisplay dpy, wl_display *display);
|
|
|
|
typedef GLboolean(*eglUnbindWaylandDisplayWL_func)(EGLDisplay dpy, wl_display *display);
|
|
|
|
typedef GLboolean(*eglQueryWaylandBufferWL_func)(EGLDisplay dpy, struct wl_resource *buffer, EGLint attribute, EGLint *value);
|
|
|
|
eglBindWaylandDisplayWL_func eglBindWaylandDisplayWL = nullptr;
|
|
|
|
eglUnbindWaylandDisplayWL_func eglUnbindWaylandDisplayWL = nullptr;
|
|
|
|
eglQueryWaylandBufferWL_func eglQueryWaylandBufferWL = nullptr;
|
|
|
|
|
2020-10-16 14:57:35 +00:00
|
|
|
static EGLContext s_globalShareContext = EGL_NO_CONTEXT;
|
|
|
|
|
|
|
|
static bool isOpenGLES_helper()
|
|
|
|
{
|
|
|
|
if (qstrcmp(qgetenv("KWIN_COMPOSE"), "O2ES") == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ensureGlobalShareContext()
|
|
|
|
{
|
|
|
|
const EGLDisplay eglDisplay = kwinApp()->platform()->sceneEglDisplay();
|
|
|
|
const EGLConfig eglConfig = kwinApp()->platform()->sceneEglConfig();
|
|
|
|
|
|
|
|
if (s_globalShareContext != EGL_NO_CONTEXT) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> attribs;
|
|
|
|
if (isOpenGLES_helper()) {
|
|
|
|
EglOpenGLESContextAttributeBuilder builder;
|
|
|
|
builder.setVersion(2);
|
|
|
|
attribs = builder.build();
|
|
|
|
} else {
|
|
|
|
EglContextAttributeBuilder builder;
|
|
|
|
attribs = builder.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
s_globalShareContext = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, attribs.data());
|
|
|
|
if (s_globalShareContext == EGL_NO_CONTEXT) {
|
|
|
|
qCWarning(KWIN_OPENGL, "Failed to create global share context: 0x%x", eglGetError());
|
|
|
|
}
|
|
|
|
|
|
|
|
kwinApp()->platform()->setSceneEglGlobalShareContext(s_globalShareContext);
|
|
|
|
|
|
|
|
return s_globalShareContext != EGL_NO_CONTEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroyGlobalShareContext()
|
|
|
|
{
|
|
|
|
const EGLDisplay eglDisplay = kwinApp()->platform()->sceneEglDisplay();
|
|
|
|
if (eglDisplay == EGL_NO_DISPLAY || s_globalShareContext == EGL_NO_CONTEXT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
eglDestroyContext(eglDisplay, s_globalShareContext);
|
|
|
|
s_globalShareContext = EGL_NO_CONTEXT;
|
|
|
|
kwinApp()->platform()->setSceneEglGlobalShareContext(EGL_NO_CONTEXT);
|
|
|
|
}
|
|
|
|
|
2020-11-28 17:53:41 +00:00
|
|
|
AbstractEglBackend *AbstractEglBackend::s_primaryBackend = nullptr;
|
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
AbstractEglBackend::AbstractEglBackend()
|
2017-09-03 08:26:20 +00:00
|
|
|
: QObject(nullptr)
|
|
|
|
, OpenGLBackend()
|
2015-03-19 13:46:39 +00:00
|
|
|
{
|
2020-11-28 17:53:41 +00:00
|
|
|
if (s_primaryBackend == nullptr) {
|
|
|
|
setPrimaryBackend(this);
|
|
|
|
}
|
2020-10-16 14:57:35 +00:00
|
|
|
connect(Compositor::self(), &Compositor::aboutToDestroy, this, &AbstractEglBackend::teardown);
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 19:45:04 +00:00
|
|
|
AbstractEglBackend::~AbstractEglBackend()
|
|
|
|
{
|
|
|
|
delete m_dmaBuf;
|
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
|
2020-10-16 14:57:35 +00:00
|
|
|
void AbstractEglBackend::teardown()
|
2015-03-19 13:46:39 +00:00
|
|
|
{
|
2017-09-03 08:26:20 +00:00
|
|
|
if (eglUnbindWaylandDisplayWL && m_display != EGL_NO_DISPLAY) {
|
|
|
|
eglUnbindWaylandDisplayWL(m_display, *(WaylandServer::self()->display()));
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
2020-10-16 14:57:35 +00:00
|
|
|
destroyGlobalShareContext();
|
2016-07-18 08:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractEglBackend::cleanup()
|
|
|
|
{
|
2015-03-19 13:46:39 +00:00
|
|
|
cleanupGL();
|
|
|
|
doneCurrent();
|
|
|
|
eglDestroyContext(m_display, m_context);
|
2015-04-17 13:48:55 +00:00
|
|
|
cleanupSurfaces();
|
2015-03-19 13:46:39 +00:00
|
|
|
eglReleaseThread();
|
2017-09-05 18:37:40 +00:00
|
|
|
kwinApp()->platform()->setSceneEglContext(EGL_NO_CONTEXT);
|
|
|
|
kwinApp()->platform()->setSceneEglConfig(nullptr);
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
|
|
|
|
2015-04-17 13:48:55 +00:00
|
|
|
void AbstractEglBackend::cleanupSurfaces()
|
|
|
|
{
|
|
|
|
if (m_surface != EGL_NO_SURFACE) {
|
|
|
|
eglDestroySurface(m_display, m_surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
bool AbstractEglBackend::initEglAPI()
|
|
|
|
{
|
|
|
|
EGLint major, minor;
|
|
|
|
if (eglInitialize(m_display, &major, &minor) == EGL_FALSE) {
|
2017-09-08 20:30:18 +00:00
|
|
|
qCWarning(KWIN_OPENGL) << "eglInitialize failed";
|
2016-07-15 08:04:39 +00:00
|
|
|
EGLint error = eglGetError();
|
|
|
|
if (error != EGL_SUCCESS) {
|
2017-09-08 20:30:18 +00:00
|
|
|
qCWarning(KWIN_OPENGL) << "Error during eglInitialize " << error;
|
2016-07-15 08:04:39 +00:00
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EGLint error = eglGetError();
|
|
|
|
if (error != EGL_SUCCESS) {
|
2017-09-08 20:30:18 +00:00
|
|
|
qCWarning(KWIN_OPENGL) << "Error during eglInitialize " << error;
|
2015-03-19 13:46:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-08 20:30:18 +00:00
|
|
|
qCDebug(KWIN_OPENGL) << "Egl Initialize succeeded";
|
2015-03-19 13:46:39 +00:00
|
|
|
|
2015-10-30 11:56:03 +00:00
|
|
|
if (eglBindAPI(isOpenGLES() ? EGL_OPENGL_ES_API : EGL_OPENGL_API) == EGL_FALSE) {
|
2017-09-08 20:30:18 +00:00
|
|
|
qCCritical(KWIN_OPENGL) << "bind OpenGL API failed";
|
2015-03-19 13:46:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-08 20:30:18 +00:00
|
|
|
qCDebug(KWIN_OPENGL) << "EGL version: " << major << "." << minor;
|
2016-11-17 06:51:04 +00:00
|
|
|
const QByteArray eglExtensions = eglQueryString(m_display, EGL_EXTENSIONS);
|
|
|
|
setExtensions(eglExtensions.split(' '));
|
2020-10-12 06:45:05 +00:00
|
|
|
setSupportsSurfacelessContext(hasExtension(QByteArrayLiteral("EGL_KHR_surfaceless_context")));
|
2020-10-15 09:27:00 +00:00
|
|
|
setSupportsNativeFence(hasExtension(QByteArrayLiteral("EGL_ANDROID_native_fence_sync")));
|
2015-03-19 13:46:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-11 08:16:23 +00:00
|
|
|
typedef void (*eglFuncPtr)();
|
|
|
|
static eglFuncPtr getProcAddress(const char* name)
|
|
|
|
{
|
|
|
|
return eglGetProcAddress(name);
|
|
|
|
}
|
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
void AbstractEglBackend::initKWinGL()
|
|
|
|
{
|
|
|
|
GLPlatform *glPlatform = GLPlatform::instance();
|
|
|
|
glPlatform->detect(EglPlatformInterface);
|
|
|
|
options->setGlPreferBufferSwap(options->glPreferBufferSwap()); // resolve autosetting
|
|
|
|
if (options->glPreferBufferSwap() == Options::AutoSwapStrategy)
|
|
|
|
options->setGlPreferBufferSwap('e'); // for unknown drivers - should not happen
|
|
|
|
glPlatform->printResults();
|
2016-11-11 08:16:23 +00:00
|
|
|
initGL(&getProcAddress);
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractEglBackend::initBufferAge()
|
|
|
|
{
|
|
|
|
setSupportsBufferAge(false);
|
|
|
|
|
2016-11-17 06:51:04 +00:00
|
|
|
if (hasExtension(QByteArrayLiteral("EGL_EXT_buffer_age"))) {
|
2015-03-19 13:46:39 +00:00
|
|
|
const QByteArray useBufferAge = qgetenv("KWIN_USE_BUFFER_AGE");
|
|
|
|
|
2020-11-24 05:58:11 +00:00
|
|
|
if (useBufferAge != "0") {
|
2015-03-19 13:46:39 +00:00
|
|
|
setSupportsBufferAge(true);
|
2020-11-24 05:58:11 +00:00
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
2020-04-24 17:11:41 +00:00
|
|
|
|
2020-11-24 05:53:37 +00:00
|
|
|
if (hasExtension(QByteArrayLiteral("EGL_KHR_partial_update"))) {
|
|
|
|
const QByteArray usePartialUpdate = qgetenv("KWIN_USE_PARTIAL_UPDATE");
|
|
|
|
if (usePartialUpdate != "0") {
|
|
|
|
setSupportsPartialUpdate(true);
|
|
|
|
}
|
|
|
|
}
|
2020-04-24 17:11:41 +00:00
|
|
|
setSupportsSwapBuffersWithDamage(hasExtension(QByteArrayLiteral("EGL_EXT_swap_buffers_with_damage")));
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractEglBackend::initWayland()
|
|
|
|
{
|
|
|
|
if (!WaylandServer::self()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-17 06:51:04 +00:00
|
|
|
if (hasExtension(QByteArrayLiteral("EGL_WL_bind_wayland_display"))) {
|
2015-03-19 13:46:39 +00:00
|
|
|
eglBindWaylandDisplayWL = (eglBindWaylandDisplayWL_func)eglGetProcAddress("eglBindWaylandDisplayWL");
|
|
|
|
eglUnbindWaylandDisplayWL = (eglUnbindWaylandDisplayWL_func)eglGetProcAddress("eglUnbindWaylandDisplayWL");
|
|
|
|
eglQueryWaylandBufferWL = (eglQueryWaylandBufferWL_func)eglGetProcAddress("eglQueryWaylandBufferWL");
|
2016-07-18 08:27:56 +00:00
|
|
|
// only bind if not already done
|
|
|
|
if (waylandServer()->display()->eglDisplay() != eglDisplay()) {
|
|
|
|
if (!eglBindWaylandDisplayWL(eglDisplay(), *(WaylandServer::self()->display()))) {
|
|
|
|
eglUnbindWaylandDisplayWL = nullptr;
|
|
|
|
eglQueryWaylandBufferWL = nullptr;
|
|
|
|
} else {
|
|
|
|
waylandServer()->display()->setEglDisplay(eglDisplay());
|
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
[wayland] Add support for zwp_linux_dmabuf
Summary: This adds support for LinuxDmabufUnstableV1Interface in kwin.
Test Plan: Session starts. `weston-simple-dmabuf-egl` and `weston-simple-dmabuf-drm` execute without errors.
Reviewers: #kwin, #plasma, davidedmundson, mart, graesslin, fredrik
Subscribers: meven, zzag, romangg, anthonyfieroni, plasma-devel, kwin
Tags: #kwin
Maniphest Tasks: T8067
Differential Revision: https://phabricator.kde.org/D10750
2019-06-30 23:13:26 +00:00
|
|
|
|
2019-11-27 19:45:04 +00:00
|
|
|
Q_ASSERT(!m_dmaBuf);
|
|
|
|
m_dmaBuf = EglDmabuf::factory(this);
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractEglBackend::initClientExtensions()
|
|
|
|
{
|
|
|
|
// Get the list of client extensions
|
|
|
|
const char* clientExtensionsCString = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
|
|
|
|
const QByteArray clientExtensionsString = QByteArray::fromRawData(clientExtensionsCString, qstrlen(clientExtensionsCString));
|
|
|
|
if (clientExtensionsString.isEmpty()) {
|
|
|
|
// If eglQueryString() returned NULL, the implementation doesn't support
|
|
|
|
// EGL_EXT_client_extensions. Expect an EGL_BAD_DISPLAY error.
|
|
|
|
(void) eglGetError();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_clientExtensions = clientExtensionsString.split(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractEglBackend::hasClientExtension(const QByteArray &ext) const
|
|
|
|
{
|
|
|
|
return m_clientExtensions.contains(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractEglBackend::makeCurrent()
|
|
|
|
{
|
|
|
|
if (QOpenGLContext *context = QOpenGLContext::currentContext()) {
|
|
|
|
// Workaround to tell Qt that no QOpenGLContext is current
|
|
|
|
context->doneCurrent();
|
|
|
|
}
|
|
|
|
const bool current = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractEglBackend::doneCurrent()
|
|
|
|
{
|
|
|
|
eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
}
|
|
|
|
|
2015-10-30 11:56:03 +00:00
|
|
|
bool AbstractEglBackend::isOpenGLES() const
|
|
|
|
{
|
2020-10-16 14:57:35 +00:00
|
|
|
return isOpenGLES_helper();
|
2015-10-30 11:56:03 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 07:29:49 +00:00
|
|
|
bool AbstractEglBackend::createContext()
|
|
|
|
{
|
2020-10-16 14:57:35 +00:00
|
|
|
if (!ensureGlobalShareContext()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-17 06:51:04 +00:00
|
|
|
const bool haveRobustness = hasExtension(QByteArrayLiteral("EGL_EXT_create_context_robustness"));
|
|
|
|
const bool haveCreateContext = hasExtension(QByteArrayLiteral("EGL_KHR_create_context"));
|
2018-03-22 09:20:37 +00:00
|
|
|
const bool haveContextPriority = hasExtension(QByteArrayLiteral("EGL_IMG_context_priority"));
|
2015-11-13 08:45:11 +00:00
|
|
|
|
2017-06-26 04:56:55 +00:00
|
|
|
std::vector<std::unique_ptr<AbstractOpenGLContextAttributeBuilder>> candidates;
|
2015-11-13 07:29:49 +00:00
|
|
|
if (isOpenGLES()) {
|
2018-03-22 09:20:37 +00:00
|
|
|
if (haveCreateContext && haveRobustness && haveContextPriority) {
|
2020-10-12 05:44:44 +00:00
|
|
|
auto glesRobustPriority = std::make_unique<EglOpenGLESContextAttributeBuilder>();
|
2018-03-22 09:20:37 +00:00
|
|
|
glesRobustPriority->setVersion(2);
|
|
|
|
glesRobustPriority->setRobust(true);
|
|
|
|
glesRobustPriority->setHighPriority(true);
|
|
|
|
candidates.push_back(std::move(glesRobustPriority));
|
|
|
|
}
|
2015-11-13 08:45:11 +00:00
|
|
|
if (haveCreateContext && haveRobustness) {
|
2020-10-12 05:44:44 +00:00
|
|
|
auto glesRobust = std::make_unique<EglOpenGLESContextAttributeBuilder>();
|
2017-06-26 04:56:55 +00:00
|
|
|
glesRobust->setVersion(2);
|
|
|
|
glesRobust->setRobust(true);
|
|
|
|
candidates.push_back(std::move(glesRobust));
|
2015-11-13 08:45:11 +00:00
|
|
|
}
|
2018-03-22 09:20:37 +00:00
|
|
|
if (haveContextPriority) {
|
2020-10-12 05:44:44 +00:00
|
|
|
auto glesPriority = std::make_unique<EglOpenGLESContextAttributeBuilder>();
|
2018-03-22 09:20:37 +00:00
|
|
|
glesPriority->setVersion(2);
|
|
|
|
glesPriority->setHighPriority(true);
|
|
|
|
candidates.push_back(std::move(glesPriority));
|
|
|
|
}
|
2020-10-12 05:44:44 +00:00
|
|
|
auto gles = std::make_unique<EglOpenGLESContextAttributeBuilder>();
|
2017-06-26 04:56:55 +00:00
|
|
|
gles->setVersion(2);
|
|
|
|
candidates.push_back(std::move(gles));
|
2015-11-13 07:29:49 +00:00
|
|
|
} else {
|
2015-11-13 08:45:11 +00:00
|
|
|
if (options->glCoreProfile() && haveCreateContext) {
|
2018-03-22 09:20:37 +00:00
|
|
|
if (haveRobustness && haveContextPriority) {
|
2020-10-12 05:44:44 +00:00
|
|
|
auto robustCorePriority = std::make_unique<EglContextAttributeBuilder>();
|
2018-03-22 09:20:37 +00:00
|
|
|
robustCorePriority->setVersion(3, 1);
|
|
|
|
robustCorePriority->setRobust(true);
|
|
|
|
robustCorePriority->setHighPriority(true);
|
|
|
|
candidates.push_back(std::move(robustCorePriority));
|
|
|
|
}
|
2015-11-13 08:45:11 +00:00
|
|
|
if (haveRobustness) {
|
2020-10-12 05:44:44 +00:00
|
|
|
auto robustCore = std::make_unique<EglContextAttributeBuilder>();
|
2017-06-26 04:56:55 +00:00
|
|
|
robustCore->setVersion(3, 1);
|
|
|
|
robustCore->setRobust(true);
|
|
|
|
candidates.push_back(std::move(robustCore));
|
2015-11-13 08:45:11 +00:00
|
|
|
}
|
2018-03-22 09:20:37 +00:00
|
|
|
if (haveContextPriority) {
|
2020-10-12 05:44:44 +00:00
|
|
|
auto corePriority = std::make_unique<EglContextAttributeBuilder>();
|
2018-03-22 09:20:37 +00:00
|
|
|
corePriority->setVersion(3, 1);
|
|
|
|
corePriority->setHighPriority(true);
|
|
|
|
candidates.push_back(std::move(corePriority));
|
|
|
|
}
|
2020-10-12 05:44:44 +00:00
|
|
|
auto core = std::make_unique<EglContextAttributeBuilder>();
|
2017-06-26 04:56:55 +00:00
|
|
|
core->setVersion(3, 1);
|
|
|
|
candidates.push_back(std::move(core));
|
2015-11-13 08:45:11 +00:00
|
|
|
}
|
2018-03-22 09:20:37 +00:00
|
|
|
if (haveRobustness && haveCreateContext && haveContextPriority) {
|
2020-10-12 05:44:44 +00:00
|
|
|
auto robustPriority = std::make_unique<EglContextAttributeBuilder>();
|
2018-03-22 09:20:37 +00:00
|
|
|
robustPriority->setRobust(true);
|
|
|
|
robustPriority->setHighPriority(true);
|
|
|
|
candidates.push_back(std::move(robustPriority));
|
|
|
|
}
|
2017-06-26 04:56:55 +00:00
|
|
|
if (haveRobustness && haveCreateContext) {
|
2020-10-12 05:44:44 +00:00
|
|
|
auto robust = std::make_unique<EglContextAttributeBuilder>();
|
2017-06-26 04:56:55 +00:00
|
|
|
robust->setRobust(true);
|
|
|
|
candidates.push_back(std::move(robust));
|
2015-11-13 08:45:11 +00:00
|
|
|
}
|
2017-06-26 04:56:55 +00:00
|
|
|
candidates.emplace_back(new EglContextAttributeBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLContext ctx = EGL_NO_CONTEXT;
|
|
|
|
for (auto it = candidates.begin(); it != candidates.end(); it++) {
|
|
|
|
const auto attribs = (*it)->build();
|
2020-10-16 14:57:35 +00:00
|
|
|
ctx = eglCreateContext(m_display, config(), s_globalShareContext, attribs.data());
|
2017-06-26 04:56:55 +00:00
|
|
|
if (ctx != EGL_NO_CONTEXT) {
|
2017-09-08 20:30:18 +00:00
|
|
|
qCDebug(KWIN_OPENGL) << "Created EGL context with attributes:" << (*it).get();
|
2017-06-26 04:56:55 +00:00
|
|
|
break;
|
2015-11-13 08:45:11 +00:00
|
|
|
}
|
2015-11-13 07:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx == EGL_NO_CONTEXT) {
|
2017-09-08 20:30:18 +00:00
|
|
|
qCCritical(KWIN_OPENGL) << "Create Context failed";
|
2015-11-13 07:29:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_context = ctx;
|
2020-11-28 17:53:41 +00:00
|
|
|
if (isPrimary()) {
|
|
|
|
kwinApp()->platform()->setSceneEglContext(m_context);
|
|
|
|
}
|
2015-11-13 07:29:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-18 08:27:56 +00:00
|
|
|
void AbstractEglBackend::setEglDisplay(const EGLDisplay &display) {
|
|
|
|
m_display = display;
|
2020-11-28 17:53:41 +00:00
|
|
|
if (isPrimary()) {
|
|
|
|
kwinApp()->platform()->setSceneEglDisplay(display);
|
|
|
|
}
|
2016-07-18 08:27:56 +00:00
|
|
|
}
|
|
|
|
|
2017-09-05 18:37:40 +00:00
|
|
|
void AbstractEglBackend::setConfig(const EGLConfig &config)
|
|
|
|
{
|
|
|
|
m_config = config;
|
2020-11-28 17:53:41 +00:00
|
|
|
if (isPrimary()) {
|
|
|
|
kwinApp()->platform()->setSceneEglConfig(config);
|
|
|
|
}
|
2017-09-05 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractEglBackend::setSurface(const EGLSurface &surface)
|
|
|
|
{
|
|
|
|
m_surface = surface;
|
|
|
|
}
|
|
|
|
|
2020-07-22 17:22:36 +00:00
|
|
|
QSharedPointer<GLTexture> AbstractEglBackend::textureForOutput(AbstractOutput *requestedOutput) const
|
|
|
|
{
|
|
|
|
QSharedPointer<GLTexture> texture(new GLTexture(GL_RGBA8, requestedOutput->pixelSize()));
|
|
|
|
GLRenderTarget renderTarget(*texture);
|
|
|
|
|
|
|
|
const QRect geo = requestedOutput->geometry();
|
|
|
|
QRect invGeo(geo.left(), geo.bottom(), geo.width(), -geo.height());
|
|
|
|
renderTarget.blitFromFramebuffer(invGeo);
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2017-09-08 20:30:18 +00:00
|
|
|
AbstractEglTexture::AbstractEglTexture(SceneOpenGLTexture *texture, AbstractEglBackend *backend)
|
|
|
|
: SceneOpenGLTexturePrivate()
|
2015-03-19 13:46:39 +00:00
|
|
|
, q(texture)
|
|
|
|
, m_backend(backend)
|
2015-10-09 10:26:17 +00:00
|
|
|
, m_image(EGL_NO_IMAGE_KHR)
|
2015-03-19 13:46:39 +00:00
|
|
|
{
|
|
|
|
m_target = GL_TEXTURE_2D;
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractEglTexture::~AbstractEglTexture()
|
|
|
|
{
|
|
|
|
if (m_image != EGL_NO_IMAGE_KHR) {
|
|
|
|
eglDestroyImageKHR(m_backend->eglDisplay(), m_image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenGLBackend *AbstractEglTexture::backend()
|
|
|
|
{
|
|
|
|
return m_backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractEglTexture::loadTexture(WindowPixmap *pixmap)
|
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
// FIXME: Refactor this method.
|
|
|
|
|
2020-09-18 22:40:57 +00:00
|
|
|
const auto buffer = pixmap->buffer();
|
|
|
|
if (!buffer) {
|
2015-08-18 12:40:26 +00:00
|
|
|
if (updateFromFBO(pixmap->fbo())) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
if (loadInternalImageObject(pixmap)) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-14 07:01:42 +00:00
|
|
|
return false;
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
|
|
|
// try Wayland loading
|
2016-04-01 07:52:56 +00:00
|
|
|
if (auto s = pixmap->surface()) {
|
|
|
|
s->resetTrackedDamage();
|
|
|
|
}
|
[wayland] Add support for zwp_linux_dmabuf
Summary: This adds support for LinuxDmabufUnstableV1Interface in kwin.
Test Plan: Session starts. `weston-simple-dmabuf-egl` and `weston-simple-dmabuf-drm` execute without errors.
Reviewers: #kwin, #plasma, davidedmundson, mart, graesslin, fredrik
Subscribers: meven, zzag, romangg, anthonyfieroni, plasma-devel, kwin
Tags: #kwin
Maniphest Tasks: T8067
Differential Revision: https://phabricator.kde.org/D10750
2019-06-30 23:13:26 +00:00
|
|
|
if (buffer->linuxDmabufBuffer()) {
|
|
|
|
return loadDmabufTexture(buffer);
|
|
|
|
} else if (buffer->shmBuffer()) {
|
2015-03-19 13:46:39 +00:00
|
|
|
return loadShmTexture(buffer);
|
|
|
|
}
|
[wayland] Add support for zwp_linux_dmabuf
Summary: This adds support for LinuxDmabufUnstableV1Interface in kwin.
Test Plan: Session starts. `weston-simple-dmabuf-egl` and `weston-simple-dmabuf-drm` execute without errors.
Reviewers: #kwin, #plasma, davidedmundson, mart, graesslin, fredrik
Subscribers: meven, zzag, romangg, anthonyfieroni, plasma-devel, kwin
Tags: #kwin
Maniphest Tasks: T8067
Differential Revision: https://phabricator.kde.org/D10750
2019-06-30 23:13:26 +00:00
|
|
|
return loadEglTexture(buffer);
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractEglTexture::updateTexture(WindowPixmap *pixmap)
|
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
// FIXME: Refactor this method.
|
|
|
|
|
2020-09-18 22:40:57 +00:00
|
|
|
const auto buffer = pixmap->buffer();
|
|
|
|
if (!buffer) {
|
2019-08-26 07:44:04 +00:00
|
|
|
if (updateFromFBO(pixmap->fbo())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (updateFromInternalImageObject(pixmap)) {
|
2015-08-18 12:40:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-01 07:52:56 +00:00
|
|
|
auto s = pixmap->surface();
|
2019-10-26 03:40:01 +00:00
|
|
|
if (EglDmabufBuffer *dmabuf = static_cast<EglDmabufBuffer *>(buffer->linuxDmabufBuffer())) {
|
[wayland] Add support for zwp_linux_dmabuf
Summary: This adds support for LinuxDmabufUnstableV1Interface in kwin.
Test Plan: Session starts. `weston-simple-dmabuf-egl` and `weston-simple-dmabuf-drm` execute without errors.
Reviewers: #kwin, #plasma, davidedmundson, mart, graesslin, fredrik
Subscribers: meven, zzag, romangg, anthonyfieroni, plasma-devel, kwin
Tags: #kwin
Maniphest Tasks: T8067
Differential Revision: https://phabricator.kde.org/D10750
2019-06-30 23:13:26 +00:00
|
|
|
q->bind();
|
|
|
|
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES) dmabuf->images()[0]); //TODO
|
|
|
|
q->unbind();
|
|
|
|
if (m_image != EGL_NO_IMAGE_KHR) {
|
|
|
|
eglDestroyImageKHR(m_backend->eglDisplay(), m_image);
|
|
|
|
}
|
|
|
|
m_image = EGL_NO_IMAGE_KHR; // The wl_buffer has ownership of the image
|
|
|
|
// The origin in a dmabuf-buffer is at the upper-left corner, so the meaning
|
|
|
|
// of Y-inverted is the inverse of OpenGL.
|
2020-10-07 08:13:17 +00:00
|
|
|
q->setYInverted(!(dmabuf->flags() & KWaylandServer::LinuxDmabufUnstableV1Interface::YInverted));
|
[wayland] Add support for zwp_linux_dmabuf
Summary: This adds support for LinuxDmabufUnstableV1Interface in kwin.
Test Plan: Session starts. `weston-simple-dmabuf-egl` and `weston-simple-dmabuf-drm` execute without errors.
Reviewers: #kwin, #plasma, davidedmundson, mart, graesslin, fredrik
Subscribers: meven, zzag, romangg, anthonyfieroni, plasma-devel, kwin
Tags: #kwin
Maniphest Tasks: T8067
Differential Revision: https://phabricator.kde.org/D10750
2019-06-30 23:13:26 +00:00
|
|
|
if (s) {
|
|
|
|
s->resetTrackedDamage();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
if (!buffer->shmBuffer()) {
|
|
|
|
q->bind();
|
|
|
|
EGLImageKHR image = attach(buffer);
|
|
|
|
q->unbind();
|
|
|
|
if (image != EGL_NO_IMAGE_KHR) {
|
[wayland] Add support for zwp_linux_dmabuf
Summary: This adds support for LinuxDmabufUnstableV1Interface in kwin.
Test Plan: Session starts. `weston-simple-dmabuf-egl` and `weston-simple-dmabuf-drm` execute without errors.
Reviewers: #kwin, #plasma, davidedmundson, mart, graesslin, fredrik
Subscribers: meven, zzag, romangg, anthonyfieroni, plasma-devel, kwin
Tags: #kwin
Maniphest Tasks: T8067
Differential Revision: https://phabricator.kde.org/D10750
2019-06-30 23:13:26 +00:00
|
|
|
if (m_image != EGL_NO_IMAGE_KHR) {
|
|
|
|
eglDestroyImageKHR(m_backend->eglDisplay(), m_image);
|
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
m_image = image;
|
|
|
|
}
|
2016-04-01 07:52:56 +00:00
|
|
|
if (s) {
|
|
|
|
s->resetTrackedDamage();
|
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// shm fallback
|
|
|
|
const QImage &image = buffer->data();
|
2016-04-01 07:52:56 +00:00
|
|
|
if (image.isNull() || !s) {
|
2015-03-19 13:46:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Q_ASSERT(image.size() == m_size);
|
2020-05-23 18:19:11 +00:00
|
|
|
const QRegion damage = s->mapToBuffer(s->trackedDamage());
|
2016-04-01 07:52:56 +00:00
|
|
|
s->resetTrackedDamage();
|
2015-03-19 13:46:39 +00:00
|
|
|
|
|
|
|
// TODO: this should be shared with GLTexture::update
|
2020-05-23 18:19:11 +00:00
|
|
|
createTextureSubImage(image, damage);
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 17:55:16 +00:00
|
|
|
bool AbstractEglTexture::createTextureImage(const QImage &image)
|
2015-03-19 13:46:39 +00:00
|
|
|
{
|
|
|
|
if (image.isNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
glGenTextures(1, &m_texture);
|
|
|
|
q->setFilter(GL_LINEAR);
|
2020-04-09 17:55:16 +00:00
|
|
|
q->setWrapMode(GL_CLAMP_TO_EDGE);
|
2015-03-19 13:46:39 +00:00
|
|
|
|
|
|
|
const QSize &size = image.size();
|
2020-04-09 17:55:16 +00:00
|
|
|
q->bind();
|
2015-03-19 13:46:39 +00:00
|
|
|
GLenum format = 0;
|
|
|
|
switch (image.format()) {
|
|
|
|
case QImage::Format_ARGB32:
|
|
|
|
case QImage::Format_ARGB32_Premultiplied:
|
|
|
|
format = GL_RGBA8;
|
|
|
|
break;
|
|
|
|
case QImage::Format_RGB32:
|
|
|
|
format = GL_RGB8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-11 09:11:16 +00:00
|
|
|
if (GLPlatform::instance()->isGLES()) {
|
|
|
|
if (s_supportsARGB32 && format == GL_RGBA8) {
|
|
|
|
const QImage im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
|
|
|
glTexImage2D(m_target, 0, GL_BGRA_EXT, im.width(), im.height(),
|
|
|
|
0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, im.bits());
|
|
|
|
} else {
|
|
|
|
const QImage im = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
|
|
|
|
glTexImage2D(m_target, 0, GL_RGBA, im.width(), im.height(),
|
|
|
|
0, GL_RGBA, GL_UNSIGNED_BYTE, im.bits());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
glTexImage2D(m_target, 0, format, size.width(), size.height(), 0,
|
|
|
|
GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
|
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
q->unbind();
|
|
|
|
q->setYInverted(true);
|
|
|
|
m_size = size;
|
|
|
|
updateMatrix();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-23 18:19:11 +00:00
|
|
|
void AbstractEglTexture::createTextureSubImage(const QImage &image, const QRegion &damage)
|
2020-04-09 17:55:16 +00:00
|
|
|
{
|
|
|
|
q->bind();
|
|
|
|
if (GLPlatform::instance()->isGLES()) {
|
|
|
|
if (s_supportsARGB32 && (image.format() == QImage::Format_ARGB32 || image.format() == QImage::Format_ARGB32_Premultiplied)) {
|
|
|
|
const QImage im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
|
|
|
for (const QRect &rect : damage) {
|
2020-05-23 18:19:11 +00:00
|
|
|
glTexSubImage2D(m_target, 0, rect.x(), rect.y(), rect.width(), rect.height(),
|
|
|
|
GL_BGRA_EXT, GL_UNSIGNED_BYTE, im.copy(rect).bits());
|
2020-04-09 17:55:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const QImage im = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
|
|
|
|
for (const QRect &rect : damage) {
|
2020-05-23 18:19:11 +00:00
|
|
|
glTexSubImage2D(m_target, 0, rect.x(), rect.y(), rect.width(), rect.height(),
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, im.copy(rect).bits());
|
2020-04-09 17:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const QImage im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
|
|
|
for (const QRect &rect : damage) {
|
2020-05-23 18:19:11 +00:00
|
|
|
glTexSubImage2D(m_target, 0, rect.x(), rect.y(), rect.width(), rect.height(),
|
|
|
|
GL_BGRA, GL_UNSIGNED_BYTE, im.copy(rect).bits());
|
2020-04-09 17:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
q->unbind();
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
bool AbstractEglTexture::loadShmTexture(const QPointer< KWaylandServer::BufferInterface > &buffer)
|
2020-04-09 17:55:16 +00:00
|
|
|
{
|
|
|
|
return createTextureImage(buffer->data());
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
bool AbstractEglTexture::loadEglTexture(const QPointer< KWaylandServer::BufferInterface > &buffer)
|
2015-03-19 13:46:39 +00:00
|
|
|
{
|
|
|
|
if (!eglQueryWaylandBufferWL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!buffer->resource()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
glGenTextures(1, &m_texture);
|
|
|
|
q->setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
q->setFilter(GL_LINEAR);
|
|
|
|
q->bind();
|
|
|
|
m_image = attach(buffer);
|
|
|
|
q->unbind();
|
|
|
|
|
|
|
|
if (EGL_NO_IMAGE_KHR == m_image) {
|
2017-09-08 20:30:18 +00:00
|
|
|
qCDebug(KWIN_OPENGL) << "failed to create egl image";
|
2015-03-19 13:46:39 +00:00
|
|
|
q->discard();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
bool AbstractEglTexture::loadDmabufTexture(const QPointer< KWaylandServer::BufferInterface > &buffer)
|
[wayland] Add support for zwp_linux_dmabuf
Summary: This adds support for LinuxDmabufUnstableV1Interface in kwin.
Test Plan: Session starts. `weston-simple-dmabuf-egl` and `weston-simple-dmabuf-drm` execute without errors.
Reviewers: #kwin, #plasma, davidedmundson, mart, graesslin, fredrik
Subscribers: meven, zzag, romangg, anthonyfieroni, plasma-devel, kwin
Tags: #kwin
Maniphest Tasks: T8067
Differential Revision: https://phabricator.kde.org/D10750
2019-06-30 23:13:26 +00:00
|
|
|
{
|
2019-10-26 03:40:01 +00:00
|
|
|
auto *dmabuf = static_cast<EglDmabufBuffer *>(buffer->linuxDmabufBuffer());
|
[wayland] Add support for zwp_linux_dmabuf
Summary: This adds support for LinuxDmabufUnstableV1Interface in kwin.
Test Plan: Session starts. `weston-simple-dmabuf-egl` and `weston-simple-dmabuf-drm` execute without errors.
Reviewers: #kwin, #plasma, davidedmundson, mart, graesslin, fredrik
Subscribers: meven, zzag, romangg, anthonyfieroni, plasma-devel, kwin
Tags: #kwin
Maniphest Tasks: T8067
Differential Revision: https://phabricator.kde.org/D10750
2019-06-30 23:13:26 +00:00
|
|
|
if (!dmabuf || dmabuf->images()[0] == EGL_NO_IMAGE_KHR) {
|
|
|
|
qCritical(KWIN_OPENGL) << "Invalid dmabuf-based wl_buffer";
|
|
|
|
q->discard();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(m_image == EGL_NO_IMAGE_KHR);
|
[wayland] Add support for zwp_linux_dmabuf
Summary: This adds support for LinuxDmabufUnstableV1Interface in kwin.
Test Plan: Session starts. `weston-simple-dmabuf-egl` and `weston-simple-dmabuf-drm` execute without errors.
Reviewers: #kwin, #plasma, davidedmundson, mart, graesslin, fredrik
Subscribers: meven, zzag, romangg, anthonyfieroni, plasma-devel, kwin
Tags: #kwin
Maniphest Tasks: T8067
Differential Revision: https://phabricator.kde.org/D10750
2019-06-30 23:13:26 +00:00
|
|
|
|
|
|
|
glGenTextures(1, &m_texture);
|
|
|
|
q->setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
q->setFilter(GL_NEAREST);
|
|
|
|
q->bind();
|
|
|
|
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES) dmabuf->images()[0]);
|
|
|
|
q->unbind();
|
|
|
|
|
|
|
|
m_size = dmabuf->size();
|
2020-04-29 15:18:41 +00:00
|
|
|
q->setYInverted(!(dmabuf->flags() & KWaylandServer::LinuxDmabufUnstableV1Interface::YInverted));
|
2020-10-07 08:13:17 +00:00
|
|
|
updateMatrix();
|
[wayland] Add support for zwp_linux_dmabuf
Summary: This adds support for LinuxDmabufUnstableV1Interface in kwin.
Test Plan: Session starts. `weston-simple-dmabuf-egl` and `weston-simple-dmabuf-drm` execute without errors.
Reviewers: #kwin, #plasma, davidedmundson, mart, graesslin, fredrik
Subscribers: meven, zzag, romangg, anthonyfieroni, plasma-devel, kwin
Tags: #kwin
Maniphest Tasks: T8067
Differential Revision: https://phabricator.kde.org/D10750
2019-06-30 23:13:26 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
bool AbstractEglTexture::loadInternalImageObject(WindowPixmap *pixmap)
|
|
|
|
{
|
2020-04-09 17:55:16 +00:00
|
|
|
return createTextureImage(pixmap->internalImage());
|
2019-08-26 07:44:04 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
EGLImageKHR AbstractEglTexture::attach(const QPointer< KWaylandServer::BufferInterface > &buffer)
|
2015-03-19 13:46:39 +00:00
|
|
|
{
|
2015-03-03 09:18:51 +00:00
|
|
|
EGLint format, yInverted;
|
2015-03-19 13:46:39 +00:00
|
|
|
eglQueryWaylandBufferWL(m_backend->eglDisplay(), buffer->resource(), EGL_TEXTURE_FORMAT, &format);
|
|
|
|
if (format != EGL_TEXTURE_RGB && format != EGL_TEXTURE_RGBA) {
|
2017-09-08 20:30:18 +00:00
|
|
|
qCDebug(KWIN_OPENGL) << "Unsupported texture format: " << format;
|
2015-03-19 13:46:39 +00:00
|
|
|
return EGL_NO_IMAGE_KHR;
|
|
|
|
}
|
2015-05-21 13:49:46 +00:00
|
|
|
if (!eglQueryWaylandBufferWL(m_backend->eglDisplay(), buffer->resource(), EGL_WAYLAND_Y_INVERTED_WL, &yInverted)) {
|
|
|
|
// if EGL_WAYLAND_Y_INVERTED_WL is not supported wl_buffer should be treated as if value were EGL_TRUE
|
|
|
|
yInverted = EGL_TRUE;
|
|
|
|
}
|
2015-03-19 13:46:39 +00:00
|
|
|
|
|
|
|
const EGLint attribs[] = {
|
|
|
|
EGL_WAYLAND_PLANE_WL, 0,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
EGLImageKHR image = eglCreateImageKHR(m_backend->eglDisplay(), EGL_NO_CONTEXT, EGL_WAYLAND_BUFFER_WL,
|
|
|
|
(EGLClientBuffer)buffer->resource(), attribs);
|
|
|
|
if (image != EGL_NO_IMAGE_KHR) {
|
|
|
|
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)image);
|
2015-03-03 09:18:51 +00:00
|
|
|
m_size = buffer->size();
|
2015-03-19 13:46:39 +00:00
|
|
|
updateMatrix();
|
|
|
|
q->setYInverted(yInverted);
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2015-08-18 12:40:26 +00:00
|
|
|
bool AbstractEglTexture::updateFromFBO(const QSharedPointer<QOpenGLFramebufferObject> &fbo)
|
|
|
|
{
|
|
|
|
if (fbo.isNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_texture = fbo->texture();
|
|
|
|
m_size = fbo->size();
|
|
|
|
q->setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
q->setFilter(GL_LINEAR);
|
|
|
|
q->setYInverted(false);
|
|
|
|
updateMatrix();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-23 18:19:11 +00:00
|
|
|
static QRegion scale(const QRegion ®ion, qreal scaleFactor)
|
|
|
|
{
|
|
|
|
if (scaleFactor == 1) {
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion scaled;
|
|
|
|
for (const QRect &rect : region) {
|
|
|
|
scaled += QRect(rect.topLeft() * scaleFactor, rect.size() * scaleFactor);
|
|
|
|
}
|
|
|
|
return scaled;
|
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
bool AbstractEglTexture::updateFromInternalImageObject(WindowPixmap *pixmap)
|
|
|
|
{
|
|
|
|
const QImage image = pixmap->internalImage();
|
|
|
|
if (image.isNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_size != image.size()) {
|
|
|
|
glDeleteTextures(1, &m_texture);
|
|
|
|
return loadInternalImageObject(pixmap);
|
|
|
|
}
|
|
|
|
|
2020-05-23 18:19:11 +00:00
|
|
|
createTextureSubImage(image, scale(pixmap->toplevel()->damage(), image.devicePixelRatio()));
|
2019-08-26 07:44:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-19 13:46:39 +00:00
|
|
|
}
|