2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2020-07-04 07:51:33 +00:00
|
|
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2014-08-28 07:52:35 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2014-08-28 07:52:35 +00:00
|
|
|
#include "surface_interface.h"
|
2014-10-14 12:04:35 +00:00
|
|
|
#include "surface_interface_p.h"
|
2014-08-28 12:22:53 +00:00
|
|
|
#include "buffer_interface.h"
|
2014-11-19 15:53:56 +00:00
|
|
|
#include "clientconnection.h"
|
2014-08-28 07:52:35 +00:00
|
|
|
#include "compositor_interface.h"
|
2020-07-04 07:51:33 +00:00
|
|
|
#include "display.h"
|
2020-07-23 20:09:20 +00:00
|
|
|
#include "idleinhibit_v1_interface_p.h"
|
2020-11-03 18:44:32 +00:00
|
|
|
#include "pointerconstraints_v1_interface_p.h"
|
2021-03-10 21:33:40 +00:00
|
|
|
#include "region_interface_p.h"
|
2014-10-14 12:04:35 +00:00
|
|
|
#include "subcompositor_interface.h"
|
|
|
|
#include "subsurface_interface_p.h"
|
2019-09-05 10:57:35 +00:00
|
|
|
#include "surfacerole_p.h"
|
2020-11-03 22:50:38 +00:00
|
|
|
#include "utils.h"
|
2014-10-14 12:04:35 +00:00
|
|
|
// std
|
|
|
|
#include <algorithm>
|
2014-08-28 07:52:35 +00:00
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
namespace KWaylandServer
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
QList<SurfaceInterface *> SurfaceInterfacePrivate::surfaces;
|
|
|
|
|
|
|
|
KWaylandFrameCallback::KWaylandFrameCallback(wl_resource *resource, SurfaceInterface *surface)
|
|
|
|
: QtWaylandServer::wl_callback(resource)
|
|
|
|
, surface(surface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWaylandFrameCallback::destroy()
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
2020-07-04 07:51:33 +00:00
|
|
|
wl_resource_destroy(resource()->handle);
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
void KWaylandFrameCallback::callback_destroy_resource(Resource *)
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
2020-07-04 07:51:33 +00:00
|
|
|
if (surface) {
|
|
|
|
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
|
|
|
|
surfacePrivate->current.frameCallbacks.removeOne(this);
|
|
|
|
surfacePrivate->pending.frameCallbacks.removeOne(this);
|
2020-07-04 12:13:47 +00:00
|
|
|
surfacePrivate->cached.frameCallbacks.removeOne(this);
|
2020-07-04 07:51:33 +00:00
|
|
|
}
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterfacePrivate::SurfaceInterfacePrivate(SurfaceInterface *q)
|
|
|
|
: q(q)
|
|
|
|
{
|
|
|
|
surfaces.append(q);
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterfacePrivate::~SurfaceInterfacePrivate()
|
|
|
|
{
|
2020-10-02 05:56:06 +00:00
|
|
|
// Need a copy to avoid hitting invalidated iterators in the for loop.
|
|
|
|
const QList<KWaylandFrameCallback *> currentFrameCallbacks = current.frameCallbacks;
|
|
|
|
for (KWaylandFrameCallback *frameCallback : currentFrameCallbacks) {
|
2020-07-04 07:51:33 +00:00
|
|
|
frameCallback->destroy();
|
|
|
|
}
|
2020-10-02 05:56:06 +00:00
|
|
|
|
|
|
|
const QList<KWaylandFrameCallback *> pendingFrameCallbacks = pending.frameCallbacks;
|
|
|
|
for (KWaylandFrameCallback *frameCallback : pendingFrameCallbacks) {
|
2020-07-04 07:51:33 +00:00
|
|
|
frameCallback->destroy();
|
|
|
|
}
|
2020-10-02 05:56:06 +00:00
|
|
|
|
|
|
|
const QList<KWaylandFrameCallback *> cachedFrameCallbacks = cached.frameCallbacks;
|
|
|
|
for (KWaylandFrameCallback *frameCallback : cachedFrameCallbacks) {
|
2020-07-04 07:51:33 +00:00
|
|
|
frameCallback->destroy();
|
|
|
|
}
|
2020-10-02 05:56:06 +00:00
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
if (current.buffer) {
|
|
|
|
current.buffer->unref();
|
|
|
|
}
|
|
|
|
surfaces.removeOne(q);
|
2014-09-19 05:06:31 +00:00
|
|
|
}
|
|
|
|
|
2020-10-31 14:03:30 +00:00
|
|
|
void SurfaceInterfacePrivate::addChild(SubSurfaceInterface *child)
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
2016-03-21 14:53:13 +00:00
|
|
|
// protocol is not precise on how to handle the addition of new sub surfaces
|
2021-06-01 10:50:33 +00:00
|
|
|
pending.above.append(child);
|
|
|
|
cached.above.append(child);
|
|
|
|
current.above.append(child);
|
2020-11-16 16:21:43 +00:00
|
|
|
child->surface()->setOutputs(outputs);
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->childSubSurfaceAdded(child);
|
|
|
|
Q_EMIT q->childSubSurfacesChanged();
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
2020-10-31 14:03:30 +00:00
|
|
|
void SurfaceInterfacePrivate::removeChild(SubSurfaceInterface *child)
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
2016-03-21 14:53:13 +00:00
|
|
|
// protocol is not precise on how to handle the addition of new sub surfaces
|
2021-06-01 10:50:33 +00:00
|
|
|
pending.below.removeAll(child);
|
|
|
|
pending.above.removeAll(child);
|
|
|
|
cached.below.removeAll(child);
|
|
|
|
cached.above.removeAll(child);
|
|
|
|
current.below.removeAll(child);
|
|
|
|
current.above.removeAll(child);
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->childSubSurfaceRemoved(child);
|
|
|
|
Q_EMIT q->childSubSurfacesChanged();
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 10:50:33 +00:00
|
|
|
bool SurfaceInterfacePrivate::raiseChild(SubSurfaceInterface *subsurface, SurfaceInterface *anchor)
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
2021-06-01 10:50:33 +00:00
|
|
|
Q_ASSERT(subsurface->parentSurface() == q);
|
|
|
|
|
|
|
|
QList<SubSurfaceInterface *> *anchorList;
|
|
|
|
int anchorIndex;
|
|
|
|
|
|
|
|
pending.below.removeOne(subsurface);
|
|
|
|
pending.above.removeOne(subsurface);
|
|
|
|
|
|
|
|
if (anchor == q) {
|
|
|
|
// Pretend as if the parent surface were before the first child in the above list.
|
|
|
|
anchorList = &pending.above;
|
|
|
|
anchorIndex = -1;
|
|
|
|
} else if (anchorIndex = pending.above.indexOf(anchor->subSurface()); anchorIndex != -1) {
|
|
|
|
anchorList = &pending.above;
|
|
|
|
} else if (anchorIndex = pending.below.indexOf(anchor->subSurface()); anchorIndex != -1) {
|
|
|
|
anchorList = &pending.below;
|
|
|
|
} else {
|
|
|
|
return false; // The anchor belongs to other sub-surface tree.
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
2021-06-01 10:50:33 +00:00
|
|
|
|
|
|
|
anchorList->insert(anchorIndex + 1, subsurface);
|
2016-03-18 08:57:46 +00:00
|
|
|
pending.childrenChanged = true;
|
2014-10-14 12:04:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-01 10:50:33 +00:00
|
|
|
bool SurfaceInterfacePrivate::lowerChild(SubSurfaceInterface *subsurface, SurfaceInterface *anchor)
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
2021-06-01 10:50:33 +00:00
|
|
|
Q_ASSERT(subsurface->parentSurface() == q);
|
|
|
|
|
|
|
|
QList<SubSurfaceInterface *> *anchorList;
|
|
|
|
int anchorIndex;
|
|
|
|
|
|
|
|
pending.below.removeOne(subsurface);
|
|
|
|
pending.above.removeOne(subsurface);
|
|
|
|
|
|
|
|
if (anchor == q) {
|
|
|
|
// Pretend as if the parent surface were after the last child in the below list.
|
|
|
|
anchorList = &pending.below;
|
|
|
|
anchorIndex = pending.below.count();
|
|
|
|
} else if (anchorIndex = pending.above.indexOf(anchor->subSurface()); anchorIndex != -1) {
|
|
|
|
anchorList = &pending.above;
|
|
|
|
} else if (anchorIndex = pending.below.indexOf(anchor->subSurface()); anchorIndex != -1) {
|
|
|
|
anchorList = &pending.below;
|
|
|
|
} else {
|
|
|
|
return false; // The anchor belongs to other sub-surface tree.
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
2021-06-01 10:50:33 +00:00
|
|
|
|
|
|
|
anchorList->insert(anchorIndex, subsurface);
|
2016-03-18 08:57:46 +00:00
|
|
|
pending.childrenChanged = true;
|
2014-10-14 12:04:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
void SurfaceInterfacePrivate::setShadow(const QPointer<ShadowInterface> &shadow)
|
2015-07-15 09:07:50 +00:00
|
|
|
{
|
|
|
|
pending.shadow = shadow;
|
|
|
|
pending.shadowIsSet = true;
|
|
|
|
}
|
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
void SurfaceInterfacePrivate::setBlur(const QPointer<BlurInterface> &blur)
|
2015-08-26 12:42:58 +00:00
|
|
|
{
|
|
|
|
pending.blur = blur;
|
|
|
|
pending.blurIsSet = true;
|
|
|
|
}
|
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
void SurfaceInterfacePrivate::setSlide(const QPointer<SlideInterface> &slide)
|
2015-09-09 11:04:11 +00:00
|
|
|
{
|
|
|
|
pending.slide = slide;
|
|
|
|
pending.slideIsSet = true;
|
|
|
|
}
|
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
void SurfaceInterfacePrivate::setContrast(const QPointer<ContrastInterface> &contrast)
|
2015-09-02 16:13:25 +00:00
|
|
|
{
|
|
|
|
pending.contrast = contrast;
|
|
|
|
pending.contrastIsSet = true;
|
|
|
|
}
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
void SurfaceInterfacePrivate::installPointerConstraint(LockedPointerV1Interface *lock)
|
2016-11-08 13:17:15 +00:00
|
|
|
{
|
2020-11-03 18:44:32 +00:00
|
|
|
Q_ASSERT(!lockedPointer);
|
|
|
|
Q_ASSERT(!confinedPointer);
|
|
|
|
|
|
|
|
lockedPointer = lock;
|
2018-05-29 08:35:28 +00:00
|
|
|
|
|
|
|
auto cleanUp = [this]() {
|
2020-11-03 18:44:32 +00:00
|
|
|
lockedPointer = nullptr;
|
2020-07-04 07:51:33 +00:00
|
|
|
QObject::disconnect(constrainsOneShotConnection);
|
2018-05-29 08:35:28 +00:00
|
|
|
constrainsOneShotConnection = QMetaObject::Connection();
|
2020-07-04 07:51:33 +00:00
|
|
|
QObject::disconnect(constrainsUnboundConnection);
|
2018-05-29 08:35:28 +00:00
|
|
|
constrainsUnboundConnection = QMetaObject::Connection();
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->pointerConstraintsChanged();
|
2018-05-29 08:35:28 +00:00
|
|
|
};
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
if (lock->lifeTime() == LockedPointerV1Interface::LifeTime::OneShot) {
|
|
|
|
constrainsOneShotConnection = QObject::connect(lock, &LockedPointerV1Interface::lockedChanged, q,
|
2018-05-29 08:35:28 +00:00
|
|
|
[this, cleanUp] {
|
2020-11-03 18:44:32 +00:00
|
|
|
if (lockedPointer->isLocked()) {
|
2016-11-08 13:17:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-05-29 08:35:28 +00:00
|
|
|
cleanUp();
|
2016-11-08 13:17:15 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-11-03 18:44:32 +00:00
|
|
|
constrainsUnboundConnection = QObject::connect(lock, &LockedPointerV1Interface::destroyed, q, cleanUp);
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->pointerConstraintsChanged();
|
2016-11-08 13:17:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
void SurfaceInterfacePrivate::installPointerConstraint(ConfinedPointerV1Interface *confinement)
|
2016-11-08 13:17:15 +00:00
|
|
|
{
|
2020-11-03 18:44:32 +00:00
|
|
|
Q_ASSERT(!lockedPointer);
|
|
|
|
Q_ASSERT(!confinedPointer);
|
|
|
|
|
|
|
|
confinedPointer = confinement;
|
2018-05-29 08:35:28 +00:00
|
|
|
|
|
|
|
auto cleanUp = [this]() {
|
2020-11-03 18:44:32 +00:00
|
|
|
confinedPointer = nullptr;
|
2020-07-04 07:51:33 +00:00
|
|
|
QObject::disconnect(constrainsOneShotConnection);
|
2018-05-29 08:35:28 +00:00
|
|
|
constrainsOneShotConnection = QMetaObject::Connection();
|
2020-07-04 07:51:33 +00:00
|
|
|
QObject::disconnect(constrainsUnboundConnection);
|
2018-05-29 08:35:28 +00:00
|
|
|
constrainsUnboundConnection = QMetaObject::Connection();
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->pointerConstraintsChanged();
|
2018-05-29 08:35:28 +00:00
|
|
|
};
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
if (confinement->lifeTime() == ConfinedPointerV1Interface::LifeTime::OneShot) {
|
|
|
|
constrainsOneShotConnection = QObject::connect(confinement, &ConfinedPointerV1Interface::confinedChanged, q,
|
2018-05-29 08:35:28 +00:00
|
|
|
[this, cleanUp] {
|
2020-11-03 18:44:32 +00:00
|
|
|
if (confinedPointer->isConfined()) {
|
2016-11-08 13:17:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-05-29 08:35:28 +00:00
|
|
|
cleanUp();
|
2016-11-08 13:17:15 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-11-03 18:44:32 +00:00
|
|
|
constrainsUnboundConnection = QObject::connect(confinement, &ConfinedPointerV1Interface::destroyed, q, cleanUp);
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->pointerConstraintsChanged();
|
2016-11-08 13:17:15 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 20:09:20 +00:00
|
|
|
void SurfaceInterfacePrivate::installIdleInhibitor(IdleInhibitorV1Interface *inhibitor)
|
2018-05-29 08:35:28 +00:00
|
|
|
{
|
|
|
|
idleInhibitors << inhibitor;
|
2020-07-23 20:09:20 +00:00
|
|
|
QObject::connect(inhibitor, &IdleInhibitorV1Interface::destroyed, q,
|
2018-05-29 08:35:28 +00:00
|
|
|
[this, inhibitor] {
|
|
|
|
idleInhibitors.removeOne(inhibitor);
|
|
|
|
if (idleInhibitors.isEmpty()) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->inhibitsIdleChanged();
|
2018-05-29 08:35:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (idleInhibitors.count() == 1) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->inhibitsIdleChanged();
|
2020-07-04 07:51:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceInterfacePrivate::surface_destroy_resource(Resource *)
|
|
|
|
{
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->aboutToBeDestroyed();
|
2020-07-04 07:51:33 +00:00
|
|
|
delete q;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceInterfacePrivate::surface_destroy(Resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy(resource->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceInterfacePrivate::surface_attach(Resource *resource, struct ::wl_resource *buffer, int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
pending.bufferIsSet = true;
|
|
|
|
pending.offset = QPoint(x, y);
|
|
|
|
if (!buffer) {
|
|
|
|
// got a null buffer, deletes content in next frame
|
|
|
|
pending.buffer = nullptr;
|
|
|
|
pending.damage = QRegion();
|
|
|
|
pending.bufferDamage = QRegion();
|
|
|
|
return;
|
|
|
|
}
|
2020-09-21 11:31:08 +00:00
|
|
|
pending.buffer = BufferInterface::get(compositor->display(), buffer);
|
2020-10-29 12:48:21 +00:00
|
|
|
QObject::connect(pending.buffer, &BufferInterface::aboutToBeDestroyed, q, &SurfaceInterface::handleBufferRemoved, Qt::UniqueConnection);
|
2020-07-04 07:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceInterfacePrivate::surface_damage(Resource *, int32_t x, int32_t y, int32_t width, int32_t height)
|
|
|
|
{
|
2020-09-21 18:18:55 +00:00
|
|
|
pending.damage |= QRect(x, y, width, height);
|
2020-07-04 07:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceInterfacePrivate::surface_frame(Resource *resource, uint32_t callback)
|
|
|
|
{
|
|
|
|
wl_resource *callbackResource = wl_resource_create(resource->client(), &wl_callback_interface,
|
|
|
|
/* version */ 1, callback);
|
|
|
|
if (!callbackResource) {
|
|
|
|
wl_resource_post_no_memory(resource->handle);
|
|
|
|
return;
|
2018-05-29 08:35:28 +00:00
|
|
|
}
|
2020-07-04 07:51:33 +00:00
|
|
|
pending.frameCallbacks.append(new KWaylandFrameCallback(callbackResource, q));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceInterfacePrivate::surface_set_opaque_region(Resource *resource, struct ::wl_resource *region)
|
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
RegionInterface *r = RegionInterface::get(region);
|
|
|
|
pending.opaque = r ? r->region() : QRegion();
|
|
|
|
pending.opaqueIsSet = true;
|
|
|
|
|
2018-05-29 08:35:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
void SurfaceInterfacePrivate::surface_set_input_region(Resource *resource, struct ::wl_resource *region)
|
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
RegionInterface *r = RegionInterface::get(region);
|
2020-10-17 10:16:28 +00:00
|
|
|
pending.input = r ? r->region() : infiniteRegion();
|
2020-07-04 07:51:33 +00:00
|
|
|
pending.inputIsSet = true;
|
|
|
|
}
|
2014-09-19 05:06:31 +00:00
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
void SurfaceInterfacePrivate::surface_commit(Resource *resource)
|
2014-09-19 05:06:31 +00:00
|
|
|
{
|
2020-07-04 07:51:33 +00:00
|
|
|
Q_UNUSED(resource)
|
|
|
|
commit();
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
void SurfaceInterfacePrivate::surface_set_buffer_transform(Resource *resource, int32_t transform)
|
|
|
|
{
|
2021-02-11 08:10:12 +00:00
|
|
|
if (transform < 0 || transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) {
|
|
|
|
wl_resource_post_error(resource->handle, error_invalid_transform,
|
|
|
|
"buffer transform must be a valid transform (%d specified)", transform);
|
|
|
|
return;
|
|
|
|
}
|
2020-07-04 07:51:33 +00:00
|
|
|
pending.bufferTransform = OutputInterface::Transform(transform);
|
|
|
|
pending.bufferTransformIsSet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceInterfacePrivate::surface_set_buffer_scale(Resource *resource, int32_t scale)
|
|
|
|
{
|
2021-02-11 08:10:12 +00:00
|
|
|
if (scale < 1) {
|
|
|
|
wl_resource_post_error(resource->handle, error_invalid_scale,
|
|
|
|
"buffer scale must be at least one (%d specified)", scale);
|
|
|
|
return;
|
|
|
|
}
|
2020-07-04 07:51:33 +00:00
|
|
|
pending.bufferScale = scale;
|
|
|
|
pending.bufferScaleIsSet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceInterfacePrivate::surface_damage_buffer(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
2020-09-21 18:18:55 +00:00
|
|
|
pending.bufferDamage |= QRect(x, y, width, height);
|
2020-07-04 07:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterface::SurfaceInterface(CompositorInterface *compositor, wl_resource *resource)
|
|
|
|
: QObject(compositor)
|
|
|
|
, d(new SurfaceInterfacePrivate(this))
|
|
|
|
{
|
|
|
|
d->compositor = compositor;
|
|
|
|
d->init(resource);
|
2020-07-15 22:22:40 +00:00
|
|
|
d->client = compositor->display()->getConnection(d->resource()->client());
|
2020-07-04 07:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterface::~SurfaceInterface()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SurfaceInterface::id() const
|
|
|
|
{
|
|
|
|
return wl_resource_get_id(resource());
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientConnection *SurfaceInterface::client() const
|
|
|
|
{
|
2020-07-15 21:51:42 +00:00
|
|
|
return d->client;
|
2020-07-04 07:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wl_resource *SurfaceInterface::resource() const
|
|
|
|
{
|
|
|
|
return d->resource()->handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositorInterface *SurfaceInterface::compositor() const
|
|
|
|
{
|
|
|
|
return d->compositor;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<SurfaceInterface *> SurfaceInterface::surfaces()
|
|
|
|
{
|
|
|
|
return SurfaceInterfacePrivate::surfaces;
|
|
|
|
}
|
2014-09-19 05:06:31 +00:00
|
|
|
|
2014-08-28 07:52:35 +00:00
|
|
|
void SurfaceInterface::frameRendered(quint32 msec)
|
|
|
|
{
|
|
|
|
// notify all callbacks
|
2020-07-04 07:51:33 +00:00
|
|
|
while (!d->current.frameCallbacks.isEmpty()) {
|
|
|
|
KWaylandFrameCallback *frameCallback = d->current.frameCallbacks.takeFirst();
|
|
|
|
frameCallback->send_done(msec);
|
|
|
|
frameCallback->destroy();
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
2021-06-01 10:50:33 +00:00
|
|
|
for (SubSurfaceInterface *subsurface : qAsConst(d->current.below)) {
|
|
|
|
subsurface->surface()->frameRendered(msec);
|
|
|
|
}
|
|
|
|
for (SubSurfaceInterface *subsurface : qAsConst(d->current.above)) {
|
|
|
|
subsurface->surface()->frameRendered(msec);
|
2016-03-18 08:13:27 +00:00
|
|
|
}
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 12:51:21 +00:00
|
|
|
bool SurfaceInterface::hasFrameCallbacks() const
|
|
|
|
{
|
|
|
|
return !d->current.frameCallbacks.isEmpty();
|
|
|
|
}
|
|
|
|
|
2021-04-24 09:35:39 +00:00
|
|
|
QMatrix4x4 SurfaceInterfacePrivate::buildSurfaceToBufferMatrix(const SurfaceState *state)
|
2020-06-10 07:42:16 +00:00
|
|
|
{
|
|
|
|
// The order of transforms is reversed, i.e. the viewport transform is the first one.
|
|
|
|
|
|
|
|
QMatrix4x4 surfaceToBufferMatrix;
|
|
|
|
|
|
|
|
if (!state->buffer) {
|
|
|
|
return surfaceToBufferMatrix;
|
|
|
|
}
|
|
|
|
|
2020-06-19 06:58:40 +00:00
|
|
|
surfaceToBufferMatrix.scale(state->bufferScale, state->bufferScale);
|
2020-06-10 07:42:16 +00:00
|
|
|
|
2020-06-19 06:58:40 +00:00
|
|
|
switch (state->bufferTransform) {
|
2020-06-10 07:42:16 +00:00
|
|
|
case OutputInterface::Transform::Normal:
|
|
|
|
case OutputInterface::Transform::Flipped:
|
|
|
|
break;
|
|
|
|
case OutputInterface::Transform::Rotated90:
|
|
|
|
case OutputInterface::Transform::Flipped90:
|
2020-06-19 06:58:40 +00:00
|
|
|
surfaceToBufferMatrix.translate(0, state->buffer->height() / state->bufferScale);
|
2020-06-10 07:42:16 +00:00
|
|
|
surfaceToBufferMatrix.rotate(-90, 0, 0, 1);
|
|
|
|
break;
|
|
|
|
case OutputInterface::Transform::Rotated180:
|
|
|
|
case OutputInterface::Transform::Flipped180:
|
2020-06-19 06:58:40 +00:00
|
|
|
surfaceToBufferMatrix.translate(state->buffer->width() / state->bufferScale,
|
|
|
|
state->buffer->height() / state->bufferScale);
|
2020-06-10 07:42:16 +00:00
|
|
|
surfaceToBufferMatrix.rotate(-180, 0, 0, 1);
|
|
|
|
break;
|
|
|
|
case OutputInterface::Transform::Rotated270:
|
|
|
|
case OutputInterface::Transform::Flipped270:
|
2020-06-19 06:58:40 +00:00
|
|
|
surfaceToBufferMatrix.translate(state->buffer->width() / state->bufferScale, 0);
|
2020-06-10 07:42:16 +00:00
|
|
|
surfaceToBufferMatrix.rotate(-270, 0, 0, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-19 06:58:40 +00:00
|
|
|
switch (state->bufferTransform) {
|
2020-06-10 07:42:16 +00:00
|
|
|
case OutputInterface::Transform::Flipped:
|
|
|
|
case OutputInterface::Transform::Flipped180:
|
2020-06-19 06:58:40 +00:00
|
|
|
surfaceToBufferMatrix.translate(state->buffer->width() / state->bufferScale, 0);
|
2020-06-10 07:42:16 +00:00
|
|
|
surfaceToBufferMatrix.scale(-1, 1);
|
|
|
|
break;
|
|
|
|
case OutputInterface::Transform::Flipped90:
|
|
|
|
case OutputInterface::Transform::Flipped270:
|
2020-06-19 06:58:40 +00:00
|
|
|
surfaceToBufferMatrix.translate(state->buffer->height() / state->bufferScale, 0);
|
2020-06-10 07:42:16 +00:00
|
|
|
surfaceToBufferMatrix.scale(-1, 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-04-24 09:40:01 +00:00
|
|
|
if (state->viewport.sourceGeometry.isValid()) {
|
|
|
|
surfaceToBufferMatrix.translate(state->viewport.sourceGeometry.x(), state->viewport.sourceGeometry.y());
|
|
|
|
surfaceToBufferMatrix.scale(state->viewport.sourceGeometry.width() / state->size.width(),
|
|
|
|
state->viewport.sourceGeometry.height() / state->size.height());
|
2020-06-10 07:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return surfaceToBufferMatrix;
|
|
|
|
}
|
|
|
|
|
2021-04-24 09:35:39 +00:00
|
|
|
void SurfaceInterfacePrivate::swapStates(SurfaceState *source, SurfaceState *target, bool emitChanged)
|
2014-08-28 07:52:35 +00:00
|
|
|
{
|
2020-05-24 15:27:38 +00:00
|
|
|
const bool bufferChanged = source->bufferIsSet;
|
2016-03-18 08:57:46 +00:00
|
|
|
const bool opaqueRegionChanged = source->opaqueIsSet;
|
|
|
|
const bool inputRegionChanged = source->inputIsSet;
|
2020-06-19 06:58:40 +00:00
|
|
|
const bool scaleFactorChanged = source->bufferScaleIsSet && (target->bufferScale != source->bufferScale);
|
|
|
|
const bool transformChanged = source->bufferTransformIsSet && (target->bufferTransform != source->bufferTransform);
|
2016-03-18 08:57:46 +00:00
|
|
|
const bool shadowChanged = source->shadowIsSet;
|
|
|
|
const bool blurChanged = source->blurIsSet;
|
|
|
|
const bool contrastChanged = source->contrastIsSet;
|
|
|
|
const bool slideChanged = source->slideIsSet;
|
|
|
|
const bool childrenChanged = source->childrenChanged;
|
2020-05-04 11:55:15 +00:00
|
|
|
const bool visibilityChanged = bufferChanged && (bool(source->buffer) != bool(target->buffer));
|
2020-05-24 10:46:27 +00:00
|
|
|
const QSize oldSize = target->size;
|
2020-06-30 06:06:53 +00:00
|
|
|
const QSize oldBufferSize = bufferSize;
|
2020-06-10 07:42:16 +00:00
|
|
|
const QMatrix4x4 oldSurfaceToBufferMatrix = surfaceToBufferMatrix;
|
2020-10-17 10:16:28 +00:00
|
|
|
const QRegion oldInputRegion = inputRegion;
|
2014-11-28 07:33:32 +00:00
|
|
|
if (bufferChanged) {
|
2016-03-18 08:57:46 +00:00
|
|
|
// TODO: is the reffing correct for subsurfaces?
|
|
|
|
if (target->buffer) {
|
|
|
|
if (emitChanged) {
|
|
|
|
target->buffer->unref();
|
|
|
|
} else {
|
|
|
|
target->buffer = nullptr;
|
|
|
|
}
|
2014-11-28 07:33:32 +00:00
|
|
|
}
|
2016-03-18 08:57:46 +00:00
|
|
|
if (source->buffer) {
|
|
|
|
if (emitChanged) {
|
|
|
|
source->buffer->ref();
|
|
|
|
}
|
2014-11-28 07:33:32 +00:00
|
|
|
}
|
2020-05-24 10:46:27 +00:00
|
|
|
target->buffer = source->buffer;
|
2020-02-06 11:20:44 +00:00
|
|
|
target->offset = source->offset;
|
2016-03-18 08:57:46 +00:00
|
|
|
target->damage = source->damage;
|
2019-05-08 07:38:37 +00:00
|
|
|
target->bufferDamage = source->bufferDamage;
|
2016-03-18 08:57:46 +00:00
|
|
|
target->bufferIsSet = source->bufferIsSet;
|
|
|
|
}
|
2021-04-24 09:40:01 +00:00
|
|
|
if (source->viewport.sourceGeometryIsSet) {
|
|
|
|
target->viewport.sourceGeometry = source->viewport.sourceGeometry;
|
|
|
|
target->viewport.sourceGeometryIsSet = true;
|
2020-05-24 10:46:27 +00:00
|
|
|
}
|
2021-04-24 09:40:01 +00:00
|
|
|
if (source->viewport.destinationSizeIsSet) {
|
|
|
|
target->viewport.destinationSize = source->viewport.destinationSize;
|
|
|
|
target->viewport.destinationSizeIsSet = true;
|
2020-05-24 10:46:27 +00:00
|
|
|
}
|
2016-03-18 08:57:46 +00:00
|
|
|
if (childrenChanged) {
|
|
|
|
target->childrenChanged = source->childrenChanged;
|
2021-06-01 10:50:33 +00:00
|
|
|
target->below = source->below;
|
|
|
|
target->above = source->above;
|
2014-08-28 12:22:53 +00:00
|
|
|
}
|
2020-07-04 07:51:33 +00:00
|
|
|
target->frameCallbacks.append(source->frameCallbacks);
|
2016-03-18 08:57:46 +00:00
|
|
|
|
2015-07-15 09:07:50 +00:00
|
|
|
if (shadowChanged) {
|
2016-03-18 08:57:46 +00:00
|
|
|
target->shadow = source->shadow;
|
|
|
|
target->shadowIsSet = true;
|
2015-07-15 09:07:50 +00:00
|
|
|
}
|
2015-08-26 12:42:58 +00:00
|
|
|
if (blurChanged) {
|
2016-03-18 08:57:46 +00:00
|
|
|
target->blur = source->blur;
|
|
|
|
target->blurIsSet = true;
|
2015-08-26 12:42:58 +00:00
|
|
|
}
|
2015-09-02 16:13:25 +00:00
|
|
|
if (contrastChanged) {
|
2016-03-18 08:57:46 +00:00
|
|
|
target->contrast = source->contrast;
|
|
|
|
target->contrastIsSet = true;
|
2015-09-02 16:13:25 +00:00
|
|
|
}
|
2015-09-09 11:04:11 +00:00
|
|
|
if (slideChanged) {
|
2016-03-18 08:57:46 +00:00
|
|
|
target->slide = source->slide;
|
|
|
|
target->slideIsSet = true;
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
2016-03-18 08:57:46 +00:00
|
|
|
if (inputRegionChanged) {
|
|
|
|
target->input = source->input;
|
|
|
|
target->inputIsSet = true;
|
|
|
|
}
|
|
|
|
if (opaqueRegionChanged) {
|
|
|
|
target->opaque = source->opaque;
|
|
|
|
target->opaqueIsSet = true;
|
|
|
|
}
|
|
|
|
if (scaleFactorChanged) {
|
2020-06-19 06:58:40 +00:00
|
|
|
target->bufferScale = source->bufferScale;
|
|
|
|
target->bufferScaleIsSet = true;
|
2016-03-18 08:57:46 +00:00
|
|
|
}
|
2016-03-23 13:34:51 +00:00
|
|
|
if (transformChanged) {
|
2020-06-19 06:58:40 +00:00
|
|
|
target->bufferTransform = source->bufferTransform;
|
|
|
|
target->bufferTransformIsSet = true;
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
2020-11-03 18:44:32 +00:00
|
|
|
if (lockedPointer) {
|
|
|
|
auto lockedPointerPrivate = LockedPointerV1InterfacePrivate::get(lockedPointer);
|
|
|
|
lockedPointerPrivate->commit();
|
2016-11-08 13:17:15 +00:00
|
|
|
}
|
2020-11-03 18:44:32 +00:00
|
|
|
if (confinedPointer) {
|
|
|
|
auto confinedPointerPrivate = ConfinedPointerV1InterfacePrivate::get(confinedPointer);
|
|
|
|
confinedPointerPrivate->commit();
|
2016-11-08 13:17:15 +00:00
|
|
|
}
|
2016-03-18 08:57:46 +00:00
|
|
|
|
2021-04-24 09:35:39 +00:00
|
|
|
*source = SurfaceState{};
|
2021-06-01 10:50:33 +00:00
|
|
|
source->below = target->below;
|
|
|
|
source->above = target->above;
|
2020-05-24 15:27:38 +00:00
|
|
|
|
|
|
|
if (!emitChanged) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-10 07:42:16 +00:00
|
|
|
// TODO: Refactor the state management code because it gets more clumsy.
|
2020-05-24 10:46:27 +00:00
|
|
|
if (target->buffer) {
|
2020-06-30 06:06:53 +00:00
|
|
|
bufferSize = target->buffer->size();
|
2021-04-24 09:40:01 +00:00
|
|
|
if (target->viewport.destinationSize.isValid()) {
|
|
|
|
target->size = target->viewport.destinationSize;
|
|
|
|
} else if (target->viewport.sourceGeometry.isValid()) {
|
|
|
|
target->size = target->viewport.sourceGeometry.size().toSize();
|
2020-05-24 10:46:27 +00:00
|
|
|
} else {
|
2020-06-19 06:58:40 +00:00
|
|
|
target->size = target->buffer->size() / target->bufferScale;
|
|
|
|
switch (target->bufferTransform) {
|
2020-06-10 07:42:16 +00:00
|
|
|
case OutputInterface::Transform::Rotated90:
|
|
|
|
case OutputInterface::Transform::Rotated270:
|
|
|
|
case OutputInterface::Transform::Flipped90:
|
|
|
|
case OutputInterface::Transform::Flipped270:
|
|
|
|
target->size.transpose();
|
|
|
|
break;
|
|
|
|
case OutputInterface::Transform::Normal:
|
|
|
|
case OutputInterface::Transform::Rotated180:
|
|
|
|
case OutputInterface::Transform::Flipped:
|
|
|
|
case OutputInterface::Transform::Flipped180:
|
|
|
|
break;
|
|
|
|
}
|
2020-05-24 10:46:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
target->size = QSize();
|
2020-06-30 06:06:53 +00:00
|
|
|
bufferSize = QSize();
|
2020-05-24 10:46:27 +00:00
|
|
|
}
|
2020-06-10 07:42:16 +00:00
|
|
|
surfaceToBufferMatrix = buildSurfaceToBufferMatrix(target);
|
|
|
|
bufferToSurfaceMatrix = surfaceToBufferMatrix.inverted();
|
2020-10-17 10:16:28 +00:00
|
|
|
inputRegion = target->input & QRect(QPoint(0, 0), target->size);
|
2014-08-28 07:52:35 +00:00
|
|
|
if (opaqueRegionChanged) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->opaqueChanged(target->opaque);
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
2020-10-17 10:16:28 +00:00
|
|
|
if (oldInputRegion != inputRegion) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->inputChanged(inputRegion);
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
if (scaleFactorChanged) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->bufferScaleChanged(target->bufferScale);
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
2016-03-23 13:34:51 +00:00
|
|
|
if (transformChanged) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->bufferTransformChanged(target->bufferTransform);
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
2020-05-24 15:27:38 +00:00
|
|
|
if (visibilityChanged) {
|
|
|
|
if (target->buffer) {
|
|
|
|
subSurfaceIsMapped = true;
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->mapped();
|
2020-05-24 15:27:38 +00:00
|
|
|
} else {
|
|
|
|
subSurfaceIsMapped = false;
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->unmapped();
|
2020-05-24 15:27:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bufferChanged) {
|
2019-05-08 07:38:37 +00:00
|
|
|
if (target->buffer && (!target->damage.isEmpty() || !target->bufferDamage.isEmpty())) {
|
2015-05-26 09:37:00 +00:00
|
|
|
const QRegion windowRegion = QRegion(0, 0, q->size().width(), q->size().height());
|
2020-06-10 07:42:16 +00:00
|
|
|
const QRegion bufferDamage = q->mapFromBuffer(target->bufferDamage);
|
2020-06-10 07:53:36 +00:00
|
|
|
target->damage = windowRegion.intersected(target->damage.united(bufferDamage));
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->damaged(target->damage);
|
2014-11-28 07:33:32 +00:00
|
|
|
}
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
2020-06-10 07:42:16 +00:00
|
|
|
if (surfaceToBufferMatrix != oldSurfaceToBufferMatrix) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->surfaceToBufferMatrixChanged();
|
2020-06-10 07:42:16 +00:00
|
|
|
}
|
2020-06-30 06:06:53 +00:00
|
|
|
if (bufferSize != oldBufferSize) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->bufferSizeChanged();
|
2020-06-30 06:06:53 +00:00
|
|
|
}
|
2020-05-24 10:46:27 +00:00
|
|
|
if (target->size != oldSize) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->sizeChanged();
|
2015-03-03 09:16:11 +00:00
|
|
|
}
|
2015-07-15 09:07:50 +00:00
|
|
|
if (shadowChanged) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->shadowChanged();
|
2015-07-15 09:07:50 +00:00
|
|
|
}
|
2015-08-26 12:42:58 +00:00
|
|
|
if (blurChanged) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->blurChanged();
|
2015-08-26 12:42:58 +00:00
|
|
|
}
|
2015-09-02 16:13:25 +00:00
|
|
|
if (contrastChanged) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->contrastChanged();
|
2015-09-02 16:13:25 +00:00
|
|
|
}
|
2015-09-09 11:04:11 +00:00
|
|
|
if (slideChanged) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->slideOnShowHideChanged();
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
2016-03-21 13:32:31 +00:00
|
|
|
if (childrenChanged) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->childSubSurfacesChanged();
|
2016-03-21 13:32:31 +00:00
|
|
|
}
|
2021-07-16 08:09:53 +00:00
|
|
|
// The position of a sub-surface is applied when its parent is committed.
|
|
|
|
for (SubSurfaceInterface *subsurface : qAsConst(current.below)) {
|
|
|
|
auto subsurfacePrivate = SubSurfaceInterfacePrivate::get(subsurface);
|
|
|
|
subsurfacePrivate->parentCommit();
|
|
|
|
}
|
|
|
|
for (SubSurfaceInterface *subsurface : qAsConst(current.above)) {
|
|
|
|
auto subsurfacePrivate = SubSurfaceInterfacePrivate::get(subsurface);
|
|
|
|
subsurfacePrivate->parentCommit();
|
|
|
|
}
|
|
|
|
if (role) {
|
|
|
|
role->commit();
|
|
|
|
}
|
|
|
|
Q_EMIT q->committed();
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
void SurfaceInterfacePrivate::commit()
|
2016-03-18 08:57:46 +00:00
|
|
|
{
|
2021-07-16 08:09:53 +00:00
|
|
|
if (subSurface) {
|
|
|
|
commitSubSurface();
|
|
|
|
} else {
|
2016-03-18 08:57:46 +00:00
|
|
|
swapStates(&pending, ¤t, true);
|
2021-07-16 08:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-31 14:03:30 +00:00
|
|
|
|
2021-07-16 08:09:53 +00:00
|
|
|
void SurfaceInterfacePrivate::commitSubSurface()
|
|
|
|
{
|
|
|
|
if (subSurface->isSynchronized()) {
|
|
|
|
commitToCache();
|
|
|
|
} else {
|
|
|
|
if (hasCacheState) {
|
|
|
|
commitToCache();
|
|
|
|
commitFromCache();
|
|
|
|
} else {
|
|
|
|
swapStates(&pending, ¤t, true);
|
2016-03-18 08:57:46 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-16 08:09:53 +00:00
|
|
|
}
|
2020-10-31 14:03:30 +00:00
|
|
|
|
2021-07-16 08:09:53 +00:00
|
|
|
void SurfaceInterfacePrivate::commitToCache()
|
|
|
|
{
|
|
|
|
swapStates(&pending, &cached, false);
|
|
|
|
hasCacheState = true;
|
|
|
|
}
|
2016-03-18 08:57:46 +00:00
|
|
|
|
2021-07-16 08:09:53 +00:00
|
|
|
void SurfaceInterfacePrivate::commitFromCache()
|
|
|
|
{
|
|
|
|
swapStates(&cached, ¤t, true);
|
|
|
|
hasCacheState = false;
|
2016-03-18 08:57:46 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 05:06:31 +00:00
|
|
|
QRegion SurfaceInterface::damage() const
|
|
|
|
{
|
|
|
|
return d->current.damage;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion SurfaceInterface::opaque() const
|
|
|
|
{
|
|
|
|
return d->current.opaque;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion SurfaceInterface::input() const
|
|
|
|
{
|
2020-10-17 10:16:28 +00:00
|
|
|
return d->inputRegion;
|
2014-10-16 12:59:01 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 06:58:40 +00:00
|
|
|
qint32 SurfaceInterface::bufferScale() const
|
2014-09-19 05:06:31 +00:00
|
|
|
{
|
2020-06-19 06:58:40 +00:00
|
|
|
return d->current.bufferScale;
|
2014-09-19 05:06:31 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 06:58:40 +00:00
|
|
|
OutputInterface::Transform SurfaceInterface::bufferTransform() const
|
2014-09-19 05:06:31 +00:00
|
|
|
{
|
2020-06-19 06:58:40 +00:00
|
|
|
return d->current.bufferTransform;
|
2014-09-19 05:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BufferInterface *SurfaceInterface::buffer()
|
|
|
|
{
|
|
|
|
return d->current.buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint SurfaceInterface::offset() const
|
|
|
|
{
|
|
|
|
return d->current.offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterface *SurfaceInterface::get(wl_resource *native)
|
|
|
|
{
|
2020-11-03 22:50:38 +00:00
|
|
|
if (auto surfacePrivate = resource_cast<SurfaceInterfacePrivate *>(native)) {
|
|
|
|
return surfacePrivate->q;
|
2020-07-04 07:51:33 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
2014-08-28 07:52:35 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 07:41:48 +00:00
|
|
|
SurfaceInterface *SurfaceInterface::get(quint32 id, const ClientConnection *client)
|
2015-02-09 13:31:20 +00:00
|
|
|
{
|
2020-07-04 07:51:33 +00:00
|
|
|
const QList<SurfaceInterface *> candidates = surfaces();
|
|
|
|
for (SurfaceInterface *surface : candidates) {
|
|
|
|
if (surface->client() == client && surface->id() == id) {
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
2015-02-09 13:31:20 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 10:50:33 +00:00
|
|
|
QList<SubSurfaceInterface *> SurfaceInterface::below() const
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
2021-06-01 10:50:33 +00:00
|
|
|
return d->current.below;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<SubSurfaceInterface *> SurfaceInterface::above() const
|
|
|
|
{
|
|
|
|
return d->current.above;
|
2014-10-14 12:04:35 +00:00
|
|
|
}
|
|
|
|
|
2020-10-31 14:03:30 +00:00
|
|
|
SubSurfaceInterface *SurfaceInterface::subSurface() const
|
2014-10-14 12:04:35 +00:00
|
|
|
{
|
|
|
|
return d->subSurface;
|
|
|
|
}
|
|
|
|
|
2015-03-03 09:16:11 +00:00
|
|
|
QSize SurfaceInterface::size() const
|
|
|
|
{
|
2020-05-24 10:46:27 +00:00
|
|
|
return d->current.size;
|
|
|
|
}
|
|
|
|
|
2020-02-21 10:16:38 +00:00
|
|
|
QRect SurfaceInterface::boundingRect() const
|
|
|
|
{
|
|
|
|
QRect rect(QPoint(0, 0), size());
|
|
|
|
|
2021-06-01 10:50:33 +00:00
|
|
|
for (const SubSurfaceInterface *subSurface : qAsConst(d->current.below)) {
|
|
|
|
const SurfaceInterface *childSurface = subSurface->surface();
|
|
|
|
rect |= childSurface->boundingRect().translated(subSurface->position());
|
|
|
|
}
|
|
|
|
for (const SubSurfaceInterface *subSurface : qAsConst(d->current.above)) {
|
2020-02-21 10:16:38 +00:00
|
|
|
const SurfaceInterface *childSurface = subSurface->surface();
|
|
|
|
rect |= childSurface->boundingRect().translated(subSurface->position());
|
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2015-07-15 09:07:50 +00:00
|
|
|
QPointer< ShadowInterface > SurfaceInterface::shadow() const
|
|
|
|
{
|
|
|
|
return d->current.shadow;
|
|
|
|
}
|
|
|
|
|
2015-08-26 12:42:58 +00:00
|
|
|
QPointer< BlurInterface > SurfaceInterface::blur() const
|
|
|
|
{
|
|
|
|
return d->current.blur;
|
|
|
|
}
|
|
|
|
|
2015-09-02 16:13:25 +00:00
|
|
|
QPointer< ContrastInterface > SurfaceInterface::contrast() const
|
|
|
|
{
|
|
|
|
return d->current.contrast;
|
|
|
|
}
|
|
|
|
|
2015-09-09 11:04:11 +00:00
|
|
|
QPointer< SlideInterface > SurfaceInterface::slideOnShowHide() const
|
|
|
|
{
|
|
|
|
return d->current.slide;
|
|
|
|
}
|
|
|
|
|
2016-03-29 10:05:05 +00:00
|
|
|
bool SurfaceInterface::isMapped() const
|
|
|
|
{
|
|
|
|
if (d->subSurface) {
|
|
|
|
// from spec:
|
|
|
|
// "A sub-surface becomes mapped, when a non-NULL wl_buffer is applied and the parent surface is mapped."
|
2020-10-31 14:03:30 +00:00
|
|
|
return d->subSurfaceIsMapped && d->subSurface->parentSurface() && d->subSurface->parentSurface()->isMapped();
|
2016-03-29 10:05:05 +00:00
|
|
|
}
|
|
|
|
return d->current.buffer != nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-22 12:18:23 +00:00
|
|
|
QVector<OutputInterface *> SurfaceInterface::outputs() const
|
|
|
|
{
|
|
|
|
return d->outputs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceInterface::setOutputs(const QVector<OutputInterface *> &outputs)
|
|
|
|
{
|
|
|
|
QVector<OutputInterface *> removedOutputs = d->outputs;
|
|
|
|
for (auto it = outputs.constBegin(), end = outputs.constEnd(); it != end; ++it) {
|
|
|
|
const auto o = *it;
|
|
|
|
removedOutputs.removeOne(o);
|
|
|
|
}
|
|
|
|
for (auto it = removedOutputs.constBegin(), end = removedOutputs.constEnd(); it != end; ++it) {
|
|
|
|
const auto resources = (*it)->clientResources(client());
|
2020-07-04 07:51:33 +00:00
|
|
|
for (wl_resource *outputResource : resources) {
|
|
|
|
d->send_leave(outputResource);
|
2016-08-22 12:18:23 +00:00
|
|
|
}
|
2017-08-26 10:53:09 +00:00
|
|
|
disconnect(d->outputDestroyedConnections.take(*it));
|
2021-01-12 11:10:50 +00:00
|
|
|
disconnect(d->outputBoundConnections.take(*it));
|
2016-08-22 12:18:23 +00:00
|
|
|
}
|
|
|
|
QVector<OutputInterface *> addedOutputsOutputs = outputs;
|
|
|
|
for (auto it = d->outputs.constBegin(), end = d->outputs.constEnd(); it != end; ++it) {
|
|
|
|
const auto o = *it;
|
|
|
|
addedOutputsOutputs.removeOne(o);
|
|
|
|
}
|
|
|
|
for (auto it = addedOutputsOutputs.constBegin(), end = addedOutputsOutputs.constEnd(); it != end; ++it) {
|
2017-08-26 10:53:09 +00:00
|
|
|
const auto o = *it;
|
|
|
|
const auto resources = o->clientResources(client());
|
2020-07-04 07:51:33 +00:00
|
|
|
for (wl_resource *outputResource : resources) {
|
|
|
|
d->send_enter(outputResource);
|
2016-08-22 12:18:23 +00:00
|
|
|
}
|
2021-05-02 14:46:13 +00:00
|
|
|
d->outputDestroyedConnections[o] = connect(o, &OutputInterface::removed, this, [this, o] {
|
2017-08-26 10:53:09 +00:00
|
|
|
auto outputs = d->outputs;
|
|
|
|
if (outputs.removeOne(o)) {
|
|
|
|
setOutputs(outputs);
|
|
|
|
}});
|
2021-01-12 11:10:50 +00:00
|
|
|
|
|
|
|
Q_ASSERT(!d->outputBoundConnections.contains(o));
|
|
|
|
d->outputBoundConnections[o] = connect(o, &OutputInterface::bound, this, [this](ClientConnection *c, wl_resource *outputResource) {
|
|
|
|
if (c != client()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->send_enter(outputResource);
|
|
|
|
});
|
2016-08-22 12:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
d->outputs = outputs;
|
2021-06-01 10:50:33 +00:00
|
|
|
for (auto child : qAsConst(d->current.below)) {
|
|
|
|
child->surface()->setOutputs(outputs);
|
|
|
|
}
|
|
|
|
for (auto child : qAsConst(d->current.above)) {
|
2020-11-16 16:21:43 +00:00
|
|
|
child->surface()->setOutputs(outputs);
|
|
|
|
}
|
2016-08-22 12:18:23 +00:00
|
|
|
}
|
|
|
|
|
2016-04-05 12:26:53 +00:00
|
|
|
SurfaceInterface *SurfaceInterface::surfaceAt(const QPointF &position)
|
|
|
|
{
|
|
|
|
if (!isMapped()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-06-01 10:50:33 +00:00
|
|
|
|
|
|
|
for (auto it = d->current.above.crbegin(); it != d->current.above.crend(); ++it) {
|
|
|
|
const SubSurfaceInterface *current = *it;
|
|
|
|
SurfaceInterface *surface = current->surface();
|
2016-04-05 12:26:53 +00:00
|
|
|
if (auto s = surface->surfaceAt(position - current->position())) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
2021-06-01 10:50:33 +00:00
|
|
|
|
2016-04-05 12:26:53 +00:00
|
|
|
// check whether the geometry contains the pos
|
|
|
|
if (!size().isEmpty() && QRectF(QPoint(0, 0), size()).contains(position)) {
|
|
|
|
return this;
|
|
|
|
}
|
2021-06-01 10:50:33 +00:00
|
|
|
|
|
|
|
for (auto it = d->current.below.crbegin(); it != d->current.below.crend(); ++it) {
|
|
|
|
const SubSurfaceInterface *current = *it;
|
|
|
|
SurfaceInterface *surface = current->surface();
|
|
|
|
if (auto s = surface->surfaceAt(position - current->position())) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
2016-04-05 12:26:53 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-10-02 16:11:52 +00:00
|
|
|
SurfaceInterface *SurfaceInterface::inputSurfaceAt(const QPointF &position)
|
|
|
|
{
|
|
|
|
// TODO: Most of this is very similar to SurfaceInterface::surfaceAt
|
|
|
|
// Is there a way to reduce the code duplication?
|
|
|
|
if (!isMapped()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-06-01 10:50:33 +00:00
|
|
|
|
|
|
|
for (auto it = d->current.above.crbegin(); it != d->current.above.crend(); ++it) {
|
|
|
|
const SubSurfaceInterface *current = *it;
|
2018-10-02 16:11:52 +00:00
|
|
|
auto surface = current->surface();
|
|
|
|
if (auto s = surface->inputSurfaceAt(position - current->position())) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
2021-06-01 10:50:33 +00:00
|
|
|
|
2018-10-02 16:11:52 +00:00
|
|
|
// check whether the geometry and input region contain the pos
|
|
|
|
if (!size().isEmpty() && QRectF(QPoint(0, 0), size()).contains(position) &&
|
2020-10-17 10:16:28 +00:00
|
|
|
input().contains(position.toPoint())) {
|
2018-10-02 16:11:52 +00:00
|
|
|
return this;
|
|
|
|
}
|
2021-06-01 10:50:33 +00:00
|
|
|
|
|
|
|
for (auto it = d->current.below.crbegin(); it != d->current.below.crend(); ++it) {
|
|
|
|
const SubSurfaceInterface *current = *it;
|
|
|
|
auto surface = current->surface();
|
|
|
|
if (auto s = surface->inputSurfaceAt(position - current->position())) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 16:11:52 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
LockedPointerV1Interface *SurfaceInterface::lockedPointer() const
|
2016-11-08 13:17:15 +00:00
|
|
|
{
|
|
|
|
return d->lockedPointer;
|
|
|
|
}
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
ConfinedPointerV1Interface *SurfaceInterface::confinedPointer() const
|
2016-11-08 13:17:15 +00:00
|
|
|
{
|
|
|
|
return d->confinedPointer;
|
|
|
|
}
|
|
|
|
|
2017-10-20 16:28:25 +00:00
|
|
|
bool SurfaceInterface::inhibitsIdle() const
|
|
|
|
{
|
|
|
|
return !d->idleInhibitors.isEmpty();
|
|
|
|
}
|
|
|
|
|
2019-02-06 08:26:43 +00:00
|
|
|
void SurfaceInterface::setDataProxy(SurfaceInterface *surface)
|
|
|
|
{
|
|
|
|
d->dataProxy = surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterface* SurfaceInterface::dataProxy() const
|
|
|
|
{
|
|
|
|
return d->dataProxy;
|
|
|
|
}
|
|
|
|
|
2020-05-23 18:12:36 +00:00
|
|
|
QPointF SurfaceInterface::mapToBuffer(const QPointF &point) const
|
|
|
|
{
|
2020-06-10 07:42:16 +00:00
|
|
|
return d->surfaceToBufferMatrix.map(point);
|
2020-05-23 18:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPointF SurfaceInterface::mapFromBuffer(const QPointF &point) const
|
|
|
|
{
|
2020-06-10 07:42:16 +00:00
|
|
|
return d->bufferToSurfaceMatrix.map(point);
|
2020-05-23 18:12:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 07:42:16 +00:00
|
|
|
static QRegion map_helper(const QMatrix4x4 &matrix, const QRegion ®ion)
|
2020-05-23 18:12:36 +00:00
|
|
|
{
|
2020-06-10 07:42:16 +00:00
|
|
|
QRegion result;
|
|
|
|
for (const QRect &rect : region) {
|
|
|
|
result += matrix.mapRect(rect);
|
|
|
|
}
|
|
|
|
return result;
|
2020-05-23 18:12:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 07:42:16 +00:00
|
|
|
QRegion SurfaceInterface::mapToBuffer(const QRegion ®ion) const
|
2020-05-23 18:12:36 +00:00
|
|
|
{
|
2020-06-10 07:42:16 +00:00
|
|
|
return map_helper(d->surfaceToBufferMatrix, region);
|
2020-05-23 18:12:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 07:42:16 +00:00
|
|
|
QRegion SurfaceInterface::mapFromBuffer(const QRegion ®ion) const
|
2020-05-23 18:12:36 +00:00
|
|
|
{
|
2020-06-10 07:42:16 +00:00
|
|
|
return map_helper(d->bufferToSurfaceMatrix, region);
|
2020-05-23 18:12:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 07:42:16 +00:00
|
|
|
QMatrix4x4 SurfaceInterface::surfaceToBufferMatrix() const
|
2020-05-23 18:12:36 +00:00
|
|
|
{
|
2020-06-10 07:42:16 +00:00
|
|
|
return d->surfaceToBufferMatrix;
|
2020-05-23 18:12:36 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 12:48:21 +00:00
|
|
|
void SurfaceInterface::handleBufferRemoved(BufferInterface *buffer)
|
|
|
|
{
|
|
|
|
if (d->pending.buffer == buffer) {
|
|
|
|
d->pending.buffer = nullptr;
|
|
|
|
}
|
|
|
|
if (d->cached.buffer == buffer) {
|
|
|
|
d->cached.buffer = nullptr;
|
|
|
|
}
|
|
|
|
if (d->current.buffer == buffer) {
|
|
|
|
d->current.buffer->unref();
|
|
|
|
d->current.buffer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 12:17:37 +00:00
|
|
|
QPointF SurfaceInterface::mapToChild(SurfaceInterface *child, const QPointF &point) const
|
|
|
|
{
|
|
|
|
QPointF local = point;
|
|
|
|
SurfaceInterface *surface = child;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (surface == this) {
|
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubSurfaceInterface *subsurface = surface->subSurface();
|
|
|
|
if (Q_UNLIKELY(!subsurface)) {
|
|
|
|
return QPointF();
|
|
|
|
}
|
|
|
|
|
|
|
|
local -= subsurface->position();
|
|
|
|
surface = subsurface->parentSurface();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QPointF();
|
|
|
|
}
|
|
|
|
|
2021-03-11 12:49:38 +00:00
|
|
|
|
|
|
|
QSize SurfaceInterface::bufferSize() const
|
|
|
|
{
|
|
|
|
return d->bufferSize;
|
|
|
|
}
|
|
|
|
|
2020-07-04 07:51:33 +00:00
|
|
|
} // namespace KWaylandServer
|