diff --git a/src/wayland/subcompositor_interface.cpp b/src/wayland/subcompositor_interface.cpp index c6e298cc66..dd90962361 100644 --- a/src/wayland/subcompositor_interface.cpp +++ b/src/wayland/subcompositor_interface.cpp @@ -174,37 +174,17 @@ void SubSurfaceInterfacePrivate::subsurface_set_desync(Resource *) } mode = SubSurfaceInterface::Mode::Desynchronized; if (!q->isSynchronized()) { - synchronizedCommit(); + auto surfacePrivate = SurfaceInterfacePrivate::get(surface); + surfacePrivate->commitFromCache(); } Q_EMIT q->modeChanged(SubSurfaceInterface::Mode::Desynchronized); } void SubSurfaceInterfacePrivate::commit() { - SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface); - - if (q->isSynchronized()) { - commitToCache(); - } else { - if (hasCacheState) { - commitToCache(); - commitFromCache(); - } else { - surfacePrivate->swapStates(&surfacePrivate->pending, &surfacePrivate->current, true); - } - - for (SubSurfaceInterface *subsurface : qAsConst(surfacePrivate->current.below)) { - SubSurfaceInterfacePrivate *subsurfacePrivate = SubSurfaceInterfacePrivate::get(subsurface); - subsurfacePrivate->parentCommit(); - } - for (SubSurfaceInterface *subsurface : qAsConst(surfacePrivate->current.above)) { - SubSurfaceInterfacePrivate *subsurfacePrivate = SubSurfaceInterfacePrivate::get(subsurface); - subsurfacePrivate->parentCommit(); - } - } } -void SubSurfaceInterfacePrivate::parentCommit(bool synchronized) +void SubSurfaceInterfacePrivate::parentCommit() { if (hasPendingPosition) { hasPendingPosition = false; @@ -212,40 +192,12 @@ void SubSurfaceInterfacePrivate::parentCommit(bool synchronized) Q_EMIT q->positionChanged(position); } - if (synchronized || mode == SubSurfaceInterface::Mode::Synchronized) { - synchronizedCommit(); + if (mode == SubSurfaceInterface::Mode::Synchronized) { + auto surfacePrivate = SurfaceInterfacePrivate::get(surface); + surfacePrivate->commitFromCache(); } } -void SubSurfaceInterfacePrivate::synchronizedCommit() -{ - const SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface); - commitFromCache(); - - for (SubSurfaceInterface *subsurface : qAsConst(surfacePrivate->current.below)) { - SubSurfaceInterfacePrivate *subsurfacePrivate = SubSurfaceInterfacePrivate::get(subsurface); - subsurfacePrivate->parentCommit(true); - } - for (SubSurfaceInterface *subsurface : qAsConst(surfacePrivate->current.above)) { - SubSurfaceInterfacePrivate *subsurfacePrivate = SubSurfaceInterfacePrivate::get(subsurface); - subsurfacePrivate->parentCommit(true); - } -} - -void SubSurfaceInterfacePrivate::commitToCache() -{ - SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface); - surfacePrivate->swapStates(&surfacePrivate->pending, &surfacePrivate->cached, false); - hasCacheState = true; -} - -void SubSurfaceInterfacePrivate::commitFromCache() -{ - SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface); - surfacePrivate->swapStates(&surfacePrivate->cached, &surfacePrivate->current, true); - hasCacheState = false; -} - SubSurfaceInterface::SubSurfaceInterface(SurfaceInterface *surface, SurfaceInterface *parent, wl_resource *resource) : d(new SubSurfaceInterfacePrivate(this, surface, parent, resource)) diff --git a/src/wayland/subsurface_interface_p.h b/src/wayland/subsurface_interface_p.h index 4750ed1dc2..860e9fc26c 100644 --- a/src/wayland/subsurface_interface_p.h +++ b/src/wayland/subsurface_interface_p.h @@ -41,12 +41,7 @@ public: SurfaceInterface *parent, ::wl_resource *resource); void commit() override; - - void parentCommit(bool synchronized = false); - void synchronizedCommit(); - - void commitToCache(); - void commitFromCache(); + void parentCommit(); SubSurfaceInterface *q; QPoint position = QPoint(0, 0); @@ -54,7 +49,6 @@ public: SubSurfaceInterface::Mode mode = SubSurfaceInterface::Mode::Synchronized; QPointer surface; QPointer parent; - bool hasCacheState = false; bool hasPendingPosition = false; protected: diff --git a/src/wayland/surface_interface.cpp b/src/wayland/surface_interface.cpp index f018cb129f..53aea984cd 100644 --- a/src/wayland/surface_interface.cpp +++ b/src/wayland/surface_interface.cpp @@ -649,29 +649,54 @@ void SurfaceInterfacePrivate::swapStates(SurfaceState *source, SurfaceState *tar if (childrenChanged) { Q_EMIT q->childSubSurfacesChanged(); } + // 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(); } void SurfaceInterfacePrivate::commit() { - if (!subSurface) { + if (subSurface) { + commitSubSurface(); + } else { swapStates(&pending, ¤t, true); + } +} - // 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(); +void SurfaceInterfacePrivate::commitSubSurface() +{ + if (subSurface->isSynchronized()) { + commitToCache(); + } else { + if (hasCacheState) { + commitToCache(); + commitFromCache(); + } else { + swapStates(&pending, ¤t, true); } } +} - if (role) { - role->commit(); - } +void SurfaceInterfacePrivate::commitToCache() +{ + swapStates(&pending, &cached, false); + hasCacheState = true; +} - Q_EMIT q->committed(); +void SurfaceInterfacePrivate::commitFromCache() +{ + swapStates(&cached, ¤t, true); + hasCacheState = false; } QRegion SurfaceInterface::damage() const diff --git a/src/wayland/surface_interface_p.h b/src/wayland/surface_interface_p.h index 2d182a0845..599b8130ce 100644 --- a/src/wayland/surface_interface_p.h +++ b/src/wayland/surface_interface_p.h @@ -95,7 +95,11 @@ public: void installPointerConstraint(ConfinedPointerV1Interface *confinement); void installIdleInhibitor(IdleInhibitorV1Interface *inhibitor); + void commitToCache(); + void commitFromCache(); + void commit(); + void commitSubSurface(); QMatrix4x4 buildSurfaceToBufferMatrix(const SurfaceState *state); void swapStates(SurfaceState *source, SurfaceState *target, bool emitChanged); @@ -110,6 +114,7 @@ public: QMatrix4x4 bufferToSurfaceMatrix; QSize bufferSize; QRegion inputRegion; + bool hasCacheState = false; // 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