kwin/src/wayland/surface_interface_p.h

161 lines
5.7 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
*/
2021-03-10 16:08:30 +00:00
#pragma once
#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;
};
struct SurfaceState
{
void mergeInto(SurfaceState *target);
QRegion damage = QRegion();
QRegion bufferDamage = QRegion();
QRegion opaque = QRegion();
QRegion input = infiniteRegion();
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();
QPointer<ClientBuffer> buffer;
QPointer<ShadowInterface> shadow;
QPointer<BlurInterface> blur;
QPointer<ContrastInterface> contrast;
QPointer<SlideInterface> slide;
// Subsurfaces are stored in two lists. The below list contains subsurfaces that
// are below their parent surface; the above list contains subsurfaces that are
// placed above the parent surface.
QList<SubSurfaceInterface *> below;
QList<SubSurfaceInterface *> above;
struct {
QRectF sourceGeometry = QRectF();
QSize destinationSize = QSize();
bool sourceGeometryIsSet = false;
bool destinationSizeIsSet = false;
} viewport;
};
class SurfaceInterfacePrivate : public QtWaylandServer::wl_surface
{
public:
static SurfaceInterfacePrivate *get(SurfaceInterface *surface) { return surface->d.data(); }
explicit SurfaceInterfacePrivate(SurfaceInterface *q);
~SurfaceInterfacePrivate() override;
void addChild(SubSurfaceInterface *subsurface);
void removeChild(SubSurfaceInterface *subsurface);
bool raiseChild(SubSurfaceInterface *subsurface, SurfaceInterface *anchor);
bool lowerChild(SubSurfaceInterface *subsurface, SurfaceInterface *anchor);
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(LockedPointerV1Interface *lock);
void installPointerConstraint(ConfinedPointerV1Interface *confinement);
void installIdleInhibitor(IdleInhibitorV1Interface *inhibitor);
void commitToCache();
void commitFromCache();
void commitSubSurface();
QMatrix4x4 buildSurfaceToBufferMatrix();
void applyState(SurfaceState *next);
CompositorInterface *compositor;
SurfaceInterface *q;
SurfaceRole *role = nullptr;
SurfaceState current;
SurfaceState pending;
SurfaceState cached;
SubSurfaceInterface *subSurface = nullptr;
QMatrix4x4 surfaceToBufferMatrix;
QMatrix4x4 bufferToSurfaceMatrix;
QSize bufferSize;
QSize surfaceSize;
QRegion inputRegion;
ClientBuffer *bufferRef = nullptr;
bool hasCacheState = false;
[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;
LockedPointerV1Interface *lockedPointer = nullptr;
ConfinedPointerV1Interface *confinedPointer = nullptr;
QHash<OutputInterface*, QMetaObject::Connection> outputDestroyedConnections;
QHash<OutputInterface*, QMetaObject::Connection> outputBoundConnections;
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:
QMetaObject::Connection constrainsOneShotConnection;
QMetaObject::Connection constrainsUnboundConnection;
};
} // namespace KWaylandServer