[server] Add a bool SubSurfaceInterface::isSynchronized() const

The mode is not sufficient to determine whether a SubSurface is in
synchronized mode.

Quoting spec:
"Even if a sub-surface is in desynchronized mode, it will behave as in
synchronized mode, if its parent surface behaves as in synchronized mode.
This rule is applied recursively throughout the tree of surfaces.
This means, that one can set a sub-surface into synchronized mode, and
then assume that all its child and grand-child sub-surfaces are
synchronized, too, without explicitly setting them."
This commit is contained in:
Martin Gräßlin 2016-03-18 10:41:56 +01:00
parent 05993458e2
commit 8323d217a6
2 changed files with 30 additions and 0 deletions

View file

@ -288,6 +288,24 @@ SubSurfaceInterface::Mode SubSurfaceInterface::mode() const
return d->mode; return d->mode;
} }
bool SubSurfaceInterface::isSynchronized() const
{
Q_D();
if (d->mode == Mode::Synchronized) {
return true;
}
if (d->parent.isNull()) {
// that shouldn't happen, but let's assume false
return false;
}
if (!d->parent->subSurface().isNull()) {
// follow parent's mode
return d->parent->subSurface()->isSynchronized();
}
// parent is no subsurface, thus parent is in desync mode and this surface is in desync mode
return false;
}
SubSurfaceInterface::Private *SubSurfaceInterface::d_func() const SubSurfaceInterface::Private *SubSurfaceInterface::d_func() const
{ {
return reinterpret_cast<SubSurfaceInterface::Private*>(d.data()); return reinterpret_cast<SubSurfaceInterface::Private*>(d.data());

View file

@ -70,6 +70,18 @@ public:
}; };
Mode mode() const; Mode mode() const;
/**
* Whether this SubSurfaceInterface is in synchronized mode.
* A SubSurface is in synchronized mode if either @link mode is
* @c Mode::Synchronized or if the parent surface is in synchronized
* mode. If a SubSurfaceInterface is in synchronized mode all child
* SubSurfaceInterfaces are also in synchronized mode ignoring the actual mode.
* @returns Whether this SubSurfaceInterface is in synchronized mode.
* @see mode
* @since 5.7
**/
bool isSynchronized() const;
QPointer<SurfaceInterface> surface(); QPointer<SurfaceInterface> surface();
QPointer<SurfaceInterface> parentSurface(); QPointer<SurfaceInterface> parentSurface();