kwin/src/wayland/surface_interface_p.h

151 lines
5.5 KiB
C
Raw Normal View History

/*
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef WAYLAND_SERVER_SURFACE_INTERFACE_P_H
#define WAYLAND_SERVER_SURFACE_INTERFACE_P_H
#include "surface_interface.h"
#include "utils.h"
// Qt
#include <QHash>
#include <QVector>
// Wayland
#include "qwayland-server-wayland.h"
2020-04-29 14:56:38 +00:00
namespace KWaylandServer
{
class IdleInhibitorV1Interface;
class SurfaceRole;
class ViewportInterface;
class KWaylandFrameCallback : public QtWaylandServer::wl_callback
{
public:
KWaylandFrameCallback(wl_resource *resource, SurfaceInterface *surface);
void destroy();
QPointer<SurfaceInterface> surface;
protected:
void callback_destroy_resource(Resource *resource) override;
};
class SurfaceInterfacePrivate : public QtWaylandServer::wl_surface
{
public:
struct State {
QRegion damage = QRegion();
QRegion bufferDamage = QRegion();
QRegion opaque = QRegion();
QRegion input = infiniteRegion();
QRectF sourceGeometry = QRectF();
QSize destinationSize = QSize();
QSize size = QSize();
bool sourceGeometryIsSet = false;
bool destinationSizeIsSet = false;
bool inputIsSet = false;
bool opaqueIsSet = false;
bool bufferIsSet = false;
bool shadowIsSet = false;
bool blurIsSet = false;
bool contrastIsSet = false;
bool slideIsSet = false;
bool childrenChanged = false;
bool bufferScaleIsSet = false;
bool bufferTransformIsSet = false;
qint32 bufferScale = 1;
OutputInterface::Transform bufferTransform = OutputInterface::Transform::Normal;
QList<KWaylandFrameCallback *> frameCallbacks;
QPoint offset = QPoint();
BufferInterface *buffer = nullptr;
// stacking order: bottom (first) -> top (last)
QList<QPointer<SubSurfaceInterface>> children;
QPointer<ShadowInterface> shadow;
QPointer<BlurInterface> blur;
QPointer<ContrastInterface> contrast;
QPointer<SlideInterface> slide;
};
static SurfaceInterfacePrivate *get(SurfaceInterface *surface) { return surface->d.data(); }
explicit SurfaceInterfacePrivate(SurfaceInterface *q);
~SurfaceInterfacePrivate() override;
void addChild(QPointer<SubSurfaceInterface> subsurface);
void removeChild(QPointer<SubSurfaceInterface> subsurface);
bool raiseChild(QPointer<SubSurfaceInterface> subsurface, SurfaceInterface *sibling);
bool lowerChild(QPointer<SubSurfaceInterface> subsurface, SurfaceInterface *sibling);
void setShadow(const QPointer<ShadowInterface> &shadow);
void setBlur(const QPointer<BlurInterface> &blur);
void setContrast(const QPointer<ContrastInterface> &contrast);
void setSlide(const QPointer<SlideInterface> &slide);
void installPointerConstraint(LockedPointerInterface *lock);
void installPointerConstraint(ConfinedPointerInterface *confinement);
void installIdleInhibitor(IdleInhibitorV1Interface *inhibitor);
void commitSubSurface();
void commit();
QMatrix4x4 buildSurfaceToBufferMatrix(const State *state);
CompositorInterface *compositor;
SurfaceInterface *q;
SurfaceRole *role = nullptr;
State current;
State pending;
State cached;
QPointer<SubSurfaceInterface> subSurface;
QRegion trackedDamage;
QMatrix4x4 surfaceToBufferMatrix;
QMatrix4x4 bufferToSurfaceMatrix;
QSize bufferSize;
QRegion inputRegion;
[server] Workaround for QtWayland bug https://bugreports.qt.io/browse/QTBUG-52192 Summary: QtWayland doesn't map the parent sub-surfaces in a sub-surface tree. According to the spec this would mean also the child sub-surface is not mapped. But being strict according to the spec will make applications like SystemSettings fail badly. Embedded child windows will not be rendered and QtWayland is going to hard freeze. This is not acceptable, thus we need to workaround this QtWayland bug till it's fixed. It's worth mentioning that Weston as the reference compositor also doesn't handle this situation according to spec and renders the sub-surface. See https://bugs.freedesktop.org/show_bug.cgi?id=94735 The difficult part for the workaround is to determine whether a surface should be considered unmapped. E.g. when the parent gets unmapped we need to really unmap it. But what's the difference between an unmapped parent surface which should be considered mapped and an unmapped parent surface which should be considered unmapped? The implementation goes with considering a new sub-surface always as mapped - independently of whether it ever got a buffer attached. As soon as it had a buffer attached and it gets unmapped again, it will go back to a standard conform way. The behavior now is not standard conform, thus the autotest is adjusted to have QEXPECT_FAIL for the now no longer standard conform areas. Reviewers: #plasma Subscribers: plasma-devel Projects: #plasma Differential Revision: https://phabricator.kde.org/D1250
2016-03-29 13:54:18 +00:00
// workaround for https://bugreports.qt.io/browse/QTBUG-52192
// A subsurface needs to be considered mapped even if it doesn't have a buffer attached
// Otherwise Qt's sub-surfaces will never be visible and the client will freeze due to
// waiting on the frame callback of the never visible surface
bool subSurfaceIsMapped = true;
QVector<OutputInterface *> outputs;
QPointer<LockedPointerInterface> lockedPointer;
QPointer<ConfinedPointerInterface> confinedPointer;
QHash<OutputInterface*, QMetaObject::Connection> outputDestroyedConnections;
QVector<IdleInhibitorV1Interface*> idleInhibitors;
ViewportInterface *viewportExtension = nullptr;
SurfaceInterface *dataProxy = nullptr;
static QList<SurfaceInterface *> surfaces;
ClientConnection *client = nullptr;
protected:
void surface_destroy_resource(Resource *resource) override;
void surface_destroy(Resource *resource) override;
void surface_attach(Resource *resource, struct ::wl_resource *buffer, int32_t x, int32_t y) override;
void surface_damage(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
void surface_frame(Resource *resource, uint32_t callback) override;
void surface_set_opaque_region(Resource *resource, struct ::wl_resource *region) override;
void surface_set_input_region(Resource *resource, struct ::wl_resource *region) override;
void surface_commit(Resource *resource) override;
void surface_set_buffer_transform(Resource *resource, int32_t transform) override;
void surface_set_buffer_scale(Resource *resource, int32_t scale) override;
void surface_damage_buffer(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
private:
void swapStates(State *source, State *target, bool emitChanged);
QMetaObject::Connection constrainsOneShotConnection;
QMetaObject::Connection constrainsUnboundConnection;
};
} // namespace KWaylandServer
#endif