diff --git a/src/screencast.cpp b/src/screencast.cpp
index 0de2692..26a9b3f 100644
--- a/src/screencast.cpp
+++ b/src/screencast.cpp
@@ -1,168 +1,171 @@
/*
* Copyright © 2018 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*
* Authors:
* Jan Grulich
*/
#include "screencast.h"
#include "screencastcommon.h"
#include "screenchooserdialog.h"
#include "session.h"
#include "waylandintegration.h"
#include
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeScreenCast, "xdp-kde-screencast")
ScreenCastPortal::ScreenCastPortal(QObject *parent)
: QDBusAbstractAdaptor(parent)
, m_screenCastCommon(new ScreenCastCommon())
-
{
}
ScreenCastPortal::~ScreenCastPortal()
{
if (m_screenCastCommon) {
delete m_screenCastCommon;
}
}
uint ScreenCastPortal::CreateSession(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QString &app_id,
const QVariantMap &options,
QVariantMap &results)
{
Q_UNUSED(results)
qCDebug(XdgDesktopPortalKdeScreenCast) << "CreateSession called with parameters:";
qCDebug(XdgDesktopPortalKdeScreenCast) << " handle: " << handle.path();
qCDebug(XdgDesktopPortalKdeScreenCast) << " session_handle: " << session_handle.path();
qCDebug(XdgDesktopPortalKdeScreenCast) << " app_id: " << app_id;
qCDebug(XdgDesktopPortalKdeScreenCast) << " options: " << options;
Session *session = Session::createSession(this, Session::ScreenCast, app_id, session_handle.path());
if (!session) {
return 2;
}
connect(session, &Session::closed, [this] () {
if (m_screenCastCommon) {
m_screenCastCommon->stopStreaming();
}
});
return 0;
}
uint ScreenCastPortal::SelectSources(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QString &app_id,
const QVariantMap &options,
QVariantMap &results)
{
Q_UNUSED(results)
qCDebug(XdgDesktopPortalKdeScreenCast) << "SelectSource called with parameters:";
qCDebug(XdgDesktopPortalKdeScreenCast) << " handle: " << handle.path();
qCDebug(XdgDesktopPortalKdeScreenCast) << " session_handle: " << session_handle.path();
qCDebug(XdgDesktopPortalKdeScreenCast) << " app_id: " << app_id;
qCDebug(XdgDesktopPortalKdeScreenCast) << " options: " << options;
uint types = Monitor;
ScreenCastSession *session = qobject_cast(Session::getSession(session_handle.path()));
if (!session) {
qCWarning(XdgDesktopPortalKdeScreenCast) << "Tried to select sources on non-existing session " << session_handle.path();
return 2;
}
if (options.contains(QLatin1String("multiple"))) {
session->setMultipleSources(options.value(QLatin1String("multiple")).toBool());
}
if (options.contains(QLatin1String("types"))) {
types = (SourceType)(options.value(QLatin1String("types")).toUInt());
}
if (types == Window) {
qCWarning(XdgDesktopPortalKdeScreenCast) << "Screen cast of a window is not implemented";
return 2;
}
// Might be also a RemoteDesktopSession
if (session->type() == Session::RemoteDesktop) {
RemoteDesktopSession *remoteDesktopSession = qobject_cast(session);
if (remoteDesktopSession) {
remoteDesktopSession->setScreenSharingEnabled(true);
}
}
return 0;
}
uint ScreenCastPortal::Start(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QString &app_id,
const QString &parent_window,
const QVariantMap &options,
QVariantMap &results)
{
Q_UNUSED(results)
qCDebug(XdgDesktopPortalKdeScreenCast) << "Start called with parameters:";
qCDebug(XdgDesktopPortalKdeScreenCast) << " handle: " << handle.path();
qCDebug(XdgDesktopPortalKdeScreenCast) << " session_handle: " << session_handle.path();
qCDebug(XdgDesktopPortalKdeScreenCast) << " app_id: " << app_id;
qCDebug(XdgDesktopPortalKdeScreenCast) << " parent_window: " << parent_window;
qCDebug(XdgDesktopPortalKdeScreenCast) << " options: " << options;
ScreenCastSession *session = qobject_cast(Session::getSession(session_handle.path()));
if (!session) {
qCWarning(XdgDesktopPortalKdeScreenCast) << "Tried to call start on non-existing session " << session_handle.path();
return 2;
}
- // TODO check whether we got some outputs?
if (WaylandIntegration::screens().isEmpty()) {
qCWarning(XdgDesktopPortalKdeScreenCast) << "Failed to show dialog as there is no screen to select";
return 2;
}
+ if (!WaylandIntegration::isEGLInitialized()) {
+ qCWarning(XdgDesktopPortalKdeScreenCast) << "EGL is not properly initialized";
+ return 2;
+ }
+
QScopedPointer screenDialog(new ScreenChooserDialog(app_id, session->multipleSources()));
if (screenDialog->exec()) {
WaylandIntegration::WaylandOutput selectedOutput = WaylandIntegration::screens().value(screenDialog->selectedScreens().first());
QVariant streams = m_screenCastCommon->startStreaming(selectedOutput);
if (!streams.isValid()) {
qCWarning(XdgDesktopPortalKdeScreenCast) << "Pipewire stream is not ready to be streamed";
return 2;
}
results.insert(QLatin1String("streams"), streams);
return 0;
}
return 0;
}
diff --git a/src/waylandintegration.cpp b/src/waylandintegration.cpp
index e08443e..5a702b9 100644
--- a/src/waylandintegration.cpp
+++ b/src/waylandintegration.cpp
@@ -1,416 +1,442 @@
/*
* Copyright © 2018 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*
* Authors:
* Jan Grulich
*/
#include "waylandintegration.h"
#include "waylandintegration_p.h"
#include
#include
#include
#include
#include
// KWayland
#include
#include
#include
#include
#include
// system
#include
#include
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeWaylandIntegration, "xdp-kde-wayland-integration")
Q_GLOBAL_STATIC(WaylandIntegration::WaylandIntegrationPrivate, globalWaylandIntegration)
void WaylandIntegration::init()
{
globalWaylandIntegration->initDrm();
- globalWaylandIntegration->initEGL();
globalWaylandIntegration->initWayland();
}
+bool WaylandIntegration::isEGLInitialized()
+{
+ return globalWaylandIntegration->isEGLInitialized();
+}
+
void WaylandIntegration::bindOutput(int outputName, int outputVersion)
{
globalWaylandIntegration->bindOutput(outputName, outputVersion);
}
void WaylandIntegration::startStreaming()
{
globalWaylandIntegration->startStreaming();
}
void WaylandIntegration::stopStreaming()
{
globalWaylandIntegration->stopStreaming();
}
QMap WaylandIntegration::screens()
{
return globalWaylandIntegration->screens();
}
WaylandIntegration::WaylandIntegration * WaylandIntegration::waylandIntegration()
{
return globalWaylandIntegration;
}
static const char * formatGLError(GLenum err)
{
switch(err) {
case GL_NO_ERROR:
return "GL_NO_ERROR";
case GL_INVALID_ENUM:
return "GL_INVALID_ENUM";
case GL_INVALID_VALUE:
return "GL_INVALID_VALUE";
case GL_INVALID_OPERATION:
return "GL_INVALID_OPERATION";
case GL_STACK_OVERFLOW:
return "GL_STACK_OVERFLOW";
case GL_STACK_UNDERFLOW:
return "GL_STACK_UNDERFLOW";
case GL_OUT_OF_MEMORY:
return "GL_OUT_OF_MEMORY";
default:
return (QLatin1String("0x") + QString::number(err, 16)).toLocal8Bit().constData();
}
}
// Thank you kscreen
void WaylandIntegration::WaylandOutput::setOutputType(const QString &type)
{
const auto embedded = { QLatin1String("LVDS"),
QLatin1String("IDP"),
QLatin1String("EDP"),
QLatin1String("LCD") };
for (const QLatin1String &pre : embedded) {
if (type.toUpper().startsWith(pre)) {
m_outputType = OutputType::Laptop;
return;
}
}
if (type.contains(QLatin1String("VGA")) || type.contains(QLatin1String("DVI")) || type.contains(QLatin1String("HDMI")) || type.contains(QLatin1String("Panel")) ||
type.contains(QLatin1String("DisplayPort")) || type.startsWith(QLatin1String("DP")) || type.contains(QLatin1String("unknown"))) {
m_outputType = OutputType::Monitor;
} else if (type.contains(QLatin1String("TV"))) {
m_outputType = OutputType::Television;
} else {
m_outputType = OutputType::Monitor;
}
}
WaylandIntegration::WaylandIntegrationPrivate::WaylandIntegrationPrivate()
: WaylandIntegration()
+ , m_eglInitialized(false)
, m_registryInitialized(false)
, m_connection(nullptr)
, m_queue(nullptr)
, m_registry(nullptr)
, m_remoteAccessManager(nullptr)
{
}
WaylandIntegration::WaylandIntegrationPrivate::~WaylandIntegrationPrivate()
{
if (m_remoteAccessManager) {
m_remoteAccessManager->destroy();
}
if (m_drmFd) {
gbm_device_destroy(m_gbmDevice);
}
}
+bool WaylandIntegration::WaylandIntegrationPrivate::isEGLInitialized() const
+{
+ return m_eglInitialized;
+}
+
void WaylandIntegration::WaylandIntegrationPrivate::bindOutput(int outputName, int outputVersion)
{
KWayland::Client::Output *output = new KWayland::Client::Output(this);
output->setup(m_registry->bindOutput(outputName, outputVersion));
m_bindOutputs << output;
}
void WaylandIntegration::WaylandIntegrationPrivate::startStreaming()
{
m_streamingEnabled = true;
if (!m_registryInitialized) {
qCWarning(XdgDesktopPortalKdeWaylandIntegration) << "Cannot start stream because registry is not initialized yet";
return;
}
if (m_registry->hasInterface(KWayland::Client::Registry::Interface::RemoteAccessManager)) {
KWayland::Client::Registry::AnnouncedInterface interface = m_registry->interface(KWayland::Client::Registry::Interface::RemoteAccessManager);
if (!interface.name && !interface.version) {
qCWarning(XdgDesktopPortalKdeWaylandIntegration) << "Cannot start stream because remote access interface is not initialized yet";
return;
}
m_remoteAccessManager = m_registry->createRemoteAccessManager(interface.name, interface.version);
connect(m_remoteAccessManager, &KWayland::Client::RemoteAccessManager::bufferReady, this, [this] (const void *output, const KWayland::Client::RemoteBuffer * rbuf) {
Q_UNUSED(output);
connect(rbuf, &KWayland::Client::RemoteBuffer::parametersObtained, this, [this, rbuf] {
processBuffer(rbuf);
});
});
}
}
void WaylandIntegration::WaylandIntegrationPrivate::stopStreaming()
{
if (m_remoteAccessManager) {
m_remoteAccessManager->release();
m_remoteAccessManager->destroy();
}
m_streamingEnabled = false;
qDeleteAll(m_bindOutputs);
m_bindOutputs.clear();
}
QMap WaylandIntegration::WaylandIntegrationPrivate::screens()
{
return m_outputMap;
}
void WaylandIntegration::WaylandIntegrationPrivate::initDrm()
{
m_drmFd = open("/dev/dri/renderD128", O_RDWR);
+
+ if (m_drmFd == -1) {
+ qCWarning(XdgDesktopPortalKdeWaylandIntegration) << "Cannot open render node: " << strerror(errno);
+ return;
+ }
+
m_gbmDevice = gbm_create_device(m_drmFd);
if (!m_gbmDevice) {
- qFatal("Cannot create GBM device: %s", strerror(errno));
+ qCWarning(XdgDesktopPortalKdeWaylandIntegration) << "Cannot create GBM device: " << strerror(errno);
}
+
+ initEGL();
}
void WaylandIntegration::WaylandIntegrationPrivate::initEGL()
{
- // Get the list of client extensions
+ // 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.
- qFatal("No client extensions defined! %s", formatGLError(eglGetError()));
+ qCWarning(XdgDesktopPortalKdeWaylandIntegration) << "No client extensions defined! " << formatGLError(eglGetError());
+ return;
}
m_egl.extensions = clientExtensionsString.split(' ');
// Use eglGetPlatformDisplayEXT() to get the display pointer
// if the implementation supports it.
if (!m_egl.extensions.contains(QByteArrayLiteral("EGL_EXT_platform_base")) ||
!m_egl.extensions.contains(QByteArrayLiteral("EGL_MESA_platform_gbm"))) {
- qFatal("One of required EGL extensions is missing");
+ qCWarning(XdgDesktopPortalKdeWaylandIntegration) << "One of required EGL extensions is missing";
+ return;
}
m_egl.display = eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_MESA, m_gbmDevice, nullptr);
if (m_egl.display == EGL_NO_DISPLAY) {
- qFatal("Error during obtaining EGL display: %s", formatGLError(eglGetError()));
+ qCWarning(XdgDesktopPortalKdeWaylandIntegration) << "Error during obtaining EGL display: " << formatGLError(eglGetError());
+ return;
}
EGLint major, minor;
if (eglInitialize(m_egl.display, &major, &minor) == EGL_FALSE) {
- qFatal("Error during eglInitialize: %s", formatGLError(eglGetError()));
+ qCWarning(XdgDesktopPortalKdeWaylandIntegration) << "Error during eglInitialize: " << formatGLError(eglGetError());
+ return;
}
if (eglBindAPI(EGL_OPENGL_API) == EGL_FALSE) {
- qFatal("bind OpenGL API failed");
+ qCWarning(XdgDesktopPortalKdeWaylandIntegration) << "bind OpenGL API failed";
+ return;
}
m_egl.context = eglCreateContext(m_egl.display, nullptr, EGL_NO_CONTEXT, nullptr);
if (m_egl.context == EGL_NO_CONTEXT) {
- qFatal("Couldn't create EGL context: %s", formatGLError(eglGetError()));
+ qCWarning(XdgDesktopPortalKdeWaylandIntegration) << "Couldn't create EGL context: " << formatGLError(eglGetError());
+ return;
}
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << "Egl initialization succeeded";
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << QStringLiteral("EGL version: %1.%2").arg(major).arg(minor);
+
+ m_eglInitialized = true;
}
void WaylandIntegration::WaylandIntegrationPrivate::initWayland()
{
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << "InitWayland()";
m_thread = new QThread(this);
m_connection = new KWayland::Client::ConnectionThread;
connect(m_connection, &KWayland::Client::ConnectionThread::connected, this, &WaylandIntegrationPrivate::setupRegistry, Qt::QueuedConnection);
connect(m_connection, &KWayland::Client::ConnectionThread::connectionDied, this, [this] {
if (m_queue) {
delete m_queue;
m_queue = nullptr;
}
m_connection->deleteLater();
m_connection = nullptr;
if (m_thread) {
m_thread->quit();
if (!m_thread->wait(3000)) {
m_thread->terminate();
m_thread->wait();
}
delete m_thread;
m_thread = nullptr;
}
});
connect(m_connection, &KWayland::Client::ConnectionThread::failed, this, [this] {
m_thread->quit();
m_thread->wait();
});
m_thread->start();
m_connection->moveToThread(m_thread);
m_connection->initConnection();
}
void WaylandIntegration::WaylandIntegrationPrivate::addOutput(quint32 name, quint32 version)
{
KWayland::Client::Output *output = new KWayland::Client::Output(this);
output->setup(m_registry->bindOutput(name, version));
connect(output, &KWayland::Client::Output::changed, this, [this, name, version, output] () {
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << "Adding output:";
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << " manufacturer: " << output->manufacturer();
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << " model: " << output->model();
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << " resolution: " << output->pixelSize();
WaylandOutput portalOutput;
portalOutput.setManufacturer(output->manufacturer());
portalOutput.setModel(output->model());
portalOutput.setOutputType(output->model());
portalOutput.setResolution(output->pixelSize());
portalOutput.setWaylandOutputName(name);
portalOutput.setWaylandOutputVersion(version);
m_outputMap.insert(name, portalOutput);
delete output;
});
}
void WaylandIntegration::WaylandIntegrationPrivate::removeOutput(quint32 name)
{
WaylandOutput output = m_outputMap.take(name);
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << "Removing output:";
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << " manufacturer: " << output.manufacturer();
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << " model: " << output.model();
}
void WaylandIntegration::WaylandIntegrationPrivate::processBuffer(const KWayland::Client::RemoteBuffer* rbuf)
{
QScopedPointer guard(rbuf);
auto gbmHandle = rbuf->fd();
auto width = rbuf->width();
auto height = rbuf->height();
auto stride = rbuf->stride();
auto format = rbuf->format();
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << QStringLiteral("Incoming GBM fd %1, %2x%3, stride %4, fourcc 0x%5").arg(gbmHandle).arg(width).arg(height).arg(stride).arg(QString::number(format, 16));
if (!m_streamingEnabled) {
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << "Streaming is disabled";
close(gbmHandle);
return;
}
if (!gbm_device_is_format_supported(m_gbmDevice, format, GBM_BO_USE_SCANOUT)) {
qCritical() << "GBM format is not supported by device!";
}
// import GBM buffer that was passed from KWin
gbm_import_fd_data importInfo = {gbmHandle, width, height, stride, format};
gbm_bo *imported = gbm_bo_import(m_gbmDevice, GBM_BO_IMPORT_FD, &importInfo, GBM_BO_USE_SCANOUT);
if (!imported) {
qCritical() << "Cannot import passed GBM fd:" << strerror(errno);
}
// bind context to render thread
eglMakeCurrent(m_egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, m_egl.context);
// create EGL image from imported BO
EGLImageKHR image = eglCreateImageKHR(m_egl.display, nullptr, EGL_NATIVE_PIXMAP_KHR, imported, nullptr);
if (image == EGL_NO_IMAGE_KHR) {
qCritical() << "Error creating EGLImageKHR" << formatGLError(glGetError());
return;
}
// create GL 2D texture for framebuffer
GLuint texture;
glGenTextures(1, &texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, texture);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
// bind framebuffer to copy pixels from
GLuint framebuffer;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
const GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
qCritical() << "glCheckFramebufferStatus failed:" << formatGLError(glGetError());
glDeleteTextures(1, &texture);
glDeleteFramebuffers(1, &framebuffer);
eglDestroyImageKHR(m_egl.display, image);
return;
}
auto capture = new QImage(QSize(width, height), QImage::Format_RGBA8888);
glViewport(0, 0, width, height);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, capture->bits());
Q_EMIT newBuffer(capture->bits());
gbm_bo_destroy(imported);
glDeleteTextures(1, &texture);
glDeleteFramebuffers(1, &framebuffer);
eglDestroyImageKHR(m_egl.display, image);
delete capture;
close(gbmHandle);
}
void WaylandIntegration::WaylandIntegrationPrivate::setupRegistry()
{
m_queue = new KWayland::Client::EventQueue(this);
m_queue->setup(m_connection);
m_registry = new KWayland::Client::Registry(this);
connect(m_registry, &KWayland::Client::Registry::outputAnnounced, this, &WaylandIntegrationPrivate::addOutput);
connect(m_registry, &KWayland::Client::Registry::outputRemoved, this, &WaylandIntegrationPrivate::removeOutput);
connect(m_registry, &KWayland::Client::Registry::interfacesAnnounced, this, [this] {
m_registryInitialized = true;
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << "Registry initialized";
});
m_registry->create(m_connection);
m_registry->setEventQueue(m_queue);
m_registry->setup();
}
diff --git a/src/waylandintegration.h b/src/waylandintegration.h
index c94beee..1395f5e 100644
--- a/src/waylandintegration.h
+++ b/src/waylandintegration.h
@@ -1,89 +1,91 @@
/*
* Copyright © 2018 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*
* Authors:
* Jan Grulich
*/
#ifndef XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_H
#define XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_H
#include
#include
#include
namespace WaylandIntegration
{
class WaylandOutput
{
public:
enum OutputType {
Laptop,
Monitor,
Television
};
void setManufacturer(const QString &manufacturer) { m_manufacturer = manufacturer; }
QString manufacturer() const { return m_manufacturer; }
void setModel(const QString &model) { m_model = model; }
QString model() const { return m_model; }
void setResolution(const QSize &resolution) { m_resolution = resolution; }
QSize resolution() const { return m_resolution; }
void setOutputType(const QString &type);
OutputType outputType() const { return m_outputType; }
void setWaylandOutputName(int outputName) { m_waylandOutputName = outputName; }
int waylandOutputName() const { return m_waylandOutputName; }
void setWaylandOutputVersion(int outputVersion) { m_waylandOutputVersion = outputVersion; }
int waylandOutputVersion() const { return m_waylandOutputVersion; }
private:
QString m_manufacturer;
QString m_model;
QSize m_resolution;
OutputType m_outputType;
// Needed for later output binding
int m_waylandOutputName;
int m_waylandOutputVersion;
};
class WaylandIntegration : public QObject
{
Q_OBJECT
Q_SIGNALS:
void newBuffer(uint8_t *screenData);
};
void init();
+ bool isEGLInitialized();
+
void bindOutput(int outputName, int outputVersion);
void startStreaming();
void stopStreaming();
QMap screens();
WaylandIntegration *waylandIntegration();
}
#endif // XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_H
diff --git a/src/waylandintegration_p.h b/src/waylandintegration_p.h
index d2e00b5..afc14fc 100644
--- a/src/waylandintegration_p.h
+++ b/src/waylandintegration_p.h
@@ -1,98 +1,101 @@
/*
* Copyright © 2018 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*
* Authors:
* Jan Grulich
*/
#ifndef XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_P_H
#define XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_P_H
#include "waylandintegration.h"
#include
#include
#include
#include
#include
namespace KWayland {
namespace Client {
class ConnectionThread;
class EventQueue;
class OutputDevice;
class Registry;
class RemoteAccessManager;
class RemoteBuffer;
class Output;
}
}
namespace WaylandIntegration
{
class WaylandIntegrationPrivate : public WaylandIntegration::WaylandIntegration
{
Q_OBJECT
public:
WaylandIntegrationPrivate();
~WaylandIntegrationPrivate();
void initDrm();
void initEGL();
void initWayland();
+ bool isEGLInitialized() const;
+
void bindOutput(int outputName, int outputVersion);
void startStreaming();
void stopStreaming();
QMap screens();
protected Q_SLOTS:
void addOutput(quint32 name, quint32 version);
void removeOutput(quint32 name);
void processBuffer(const KWayland::Client::RemoteBuffer *rbuf);
void setupRegistry();
private:
+ bool m_eglInitialized;
bool m_streamingEnabled;
bool m_registryInitialized;
QThread *m_thread;
QMap m_outputMap;
QList m_bindOutputs;
KWayland::Client::ConnectionThread *m_connection;
KWayland::Client::EventQueue *m_queue;
KWayland::Client::Registry *m_registry;
KWayland::Client::RemoteAccessManager *m_remoteAccessManager;
qint32 m_drmFd = 0; // for GBM buffer mmap
gbm_device *m_gbmDevice = nullptr; // for passed GBM buffer retrieval
struct {
QList extensions;
EGLDisplay display = EGL_NO_DISPLAY;
EGLContext context = EGL_NO_CONTEXT;
} m_egl;
};
}
#endif // XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_P_H