Commit 5ec2a4f1 authored by Martin Flöser's avatar Martin Flöser
Browse files

[kwin_wayland] Create a dedicated Surface class

A Surface class is split out which holds a wl_surface and supports
attaching a buffer, setting the damage and emitting a signal when the
frame callback got called.

It doesn't come with a unit test yet as it first needs the ShmPool
and Buffer properly split out to easily set it up.
parent 83348411
......@@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "fullscreen_shell.h"
#include "surface.h"
#include "output.h"
#include <QDebug>
......@@ -92,5 +94,12 @@ void FullscreenShell::present(wl_surface *surface, wl_output *output)
_wl_fullscreen_shell_present_surface(m_shell, surface, _WL_FULLSCREEN_SHELL_PRESENT_METHOD_DEFAULT, output);
}
void FullscreenShell::present(Surface *surface, Output *output)
{
Q_ASSERT(surface);
Q_ASSERT(output);
present(*surface, *output);
}
}
}
......@@ -30,6 +30,9 @@ namespace KWin
namespace Wayland
{
class Surface;
class Output;
class FullscreenShell : public QObject
{
Q_OBJECT
......@@ -52,6 +55,7 @@ public:
}
void setup(_wl_fullscreen_shell *shell);
void present(wl_surface *surface, wl_output *output);
void present(Surface *surface, Output *output);
static void capabilitiesAnnounce(void *data, struct _wl_fullscreen_shell *shell, uint32_t capability);
......
......@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "shell.h"
#include "output.h"
#include "surface.h"
namespace KWin
{
......@@ -73,6 +74,12 @@ ShellSurface *Shell::createSurface(wl_surface *surface, QObject *parent)
return s;
}
ShellSurface *Shell::createSurface(Surface *surface, QObject *parent)
{
Q_ASSERT(surface);
return createSurface(*surface, parent);
}
ShellSurface::ShellSurface(QObject *parent)
: QObject(parent)
, m_surface(nullptr)
......
......@@ -31,6 +31,7 @@ namespace Wayland
{
class ShellSurface;
class Output;
class Surface;
class Shell : public QObject
{
......@@ -47,6 +48,7 @@ public:
void setup(wl_shell *shell);
ShellSurface *createSurface(wl_surface *surface, QObject *parent = nullptr);
ShellSurface *createSurface(Surface *surface, QObject *parent = nullptr);
operator wl_shell*() {
return m_shell;
......
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2014 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 2 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/>.
*********************************************************************/
#include "surface.h"
#include <QRegion>
#include <QVector>
namespace KWin
{
namespace Wayland
{
Surface::Surface(QObject *parent)
: QObject(parent)
, m_surface(nullptr)
, m_frameCallbackInstalled(false)
{
}
Surface::~Surface()
{
release();
}
void Surface::release()
{
if (!m_surface) {
return;
}
wl_surface_destroy(m_surface);
m_surface = nullptr;
}
void Surface::destroy()
{
if (!m_surface) {
return;
}
free(m_surface);
m_surface = nullptr;
}
void Surface::setup(wl_surface *surface)
{
Q_ASSERT(surface);
Q_ASSERT(!m_surface);
m_surface = surface;
}
void Surface::frameCallback(void *data, wl_callback *callback, uint32_t time)
{
Q_UNUSED(time)
Surface *s = reinterpret_cast<Surface*>(data);
if (callback) {
wl_callback_destroy(callback);
}
s->handleFrameCallback();
}
void Surface::handleFrameCallback()
{
m_frameCallbackInstalled = false;
frameRendered();
}
const struct wl_callback_listener Surface::s_listener = {
Surface::frameCallback
};
void Surface::setupFrameCallback()
{
Q_ASSERT(isValid());
Q_ASSERT(!m_frameCallbackInstalled);
wl_callback *callback = wl_surface_frame(m_surface);
wl_callback_add_listener(callback, &s_listener, this);
m_frameCallbackInstalled = true;
}
void Surface::commit(Surface::CommitFlag flag)
{
Q_ASSERT(isValid());
if (flag == CommitFlag::FrameCallback) {
setupFrameCallback();
}
wl_surface_commit(m_surface);
}
void Surface::damage(const QRegion &region)
{
for (const QRect &r : region.rects()) {
damage(r);
}
}
void Surface::damage(const QRect &rect)
{
Q_ASSERT(isValid());
wl_surface_damage(m_surface, rect.x(), rect.y(), rect.width(), rect.height());
}
void Surface::attachBuffer(wl_buffer *buffer, const QPoint &offset)
{
Q_ASSERT(isValid());
wl_surface_attach(m_surface, buffer, offset.x(), offset.y());
}
}
}
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2014 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 2 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_WAYLAND_SURFACE_H
#define KWIN_WAYLAND_SURFACE_H
#include <QObject>
#include <QPoint>
#include <wayland-client-protocol.h>
namespace KWin
{
namespace Wayland
{
class Surface : public QObject
{
Q_OBJECT
public:
explicit Surface(QObject *parent = nullptr);
virtual ~Surface();
void setup(wl_surface *surface);
void release();
void destroy();
bool isValid() const {
return m_surface != nullptr;
}
void setupFrameCallback();
enum class CommitFlag {
None,
FrameCallback
};
void commit(CommitFlag flag = CommitFlag::FrameCallback);
void damage(const QRect &rect);
void damage(const QRegion &region);
void attachBuffer(wl_buffer *buffer, const QPoint &offset = QPoint());
operator wl_surface*() {
return m_surface;
}
operator wl_surface*() const {
return m_surface;
}
static void frameCallback(void *data, wl_callback *callback, uint32_t time);
Q_SIGNALS:
void frameRendered();
private:
void handleFrameCallback();
static const wl_callback_listener s_listener;
wl_surface *m_surface;
bool m_frameCallbackInstalled;
};
}
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment