2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Design:
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
When compositing is turned on, XComposite extension is used to redirect
|
|
|
|
drawing of windows to pixmaps and XDamage extension is used to get informed
|
|
|
|
about damage (changes) to window contents. This code is mostly in composite.cpp .
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2012-12-27 06:52:58 +00:00
|
|
|
Compositor::performCompositing() starts one painting pass. Painting is done
|
2007-04-29 17:35:43 +00:00
|
|
|
by painting the screen, which in turn paints every window. Painting can be affected
|
|
|
|
using effects, which are chained. E.g. painting a screen means that actually
|
|
|
|
paintScreen() of the first effect is called, which possibly does modifications
|
|
|
|
and calls next effect's paintScreen() and so on, until Scene::finalPaintScreen()
|
|
|
|
is called.
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
There are 3 phases of every paint (not necessarily done together):
|
|
|
|
The pre-paint phase, the paint phase and the post-paint phase.
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
The pre-paint phase is used to find out about how the painting will be actually
|
|
|
|
done (i.e. what the effects will do). For example when only a part of the screen
|
|
|
|
needs to be updated and no effect will do any transformation it is possible to use
|
|
|
|
an optimized paint function. How the painting will be done is controlled
|
|
|
|
by the mask argument, see PAINT_WINDOW_* and PAINT_SCREEN_* flags in scene.h .
|
|
|
|
For example an effect that decides to paint a normal windows as translucent
|
|
|
|
will need to modify the mask in its prePaintWindow() to include
|
|
|
|
the PAINT_WINDOW_TRANSLUCENT flag. The paintWindow() function will then get
|
|
|
|
the mask with this flag turned on and will also paint using transparency.
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
The paint pass does the actual painting, based on the information collected
|
|
|
|
using the pre-paint pass. After running through the effects' paintScreen()
|
|
|
|
either paintGenericScreen() or optimized paintSimpleScreen() are called.
|
|
|
|
Those call paintWindow() on windows (not necessarily all), possibly using
|
|
|
|
clipping to optimize performance and calling paintWindow() first with only
|
|
|
|
PAINT_WINDOW_OPAQUE to paint the opaque parts and then later
|
|
|
|
with PAINT_WINDOW_TRANSLUCENT to paint the transparent parts. Function
|
|
|
|
paintWindow() again goes through effects' paintWindow() until
|
|
|
|
finalPaintWindow() is called, which calls the window's performPaint() to
|
|
|
|
do the actual painting.
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
The post-paint can be used for cleanups and is also used for scheduling
|
|
|
|
repaints during the next painting pass for animations. Effects wanting to
|
|
|
|
repaint certain parts can manually damage them during post-paint and repaint
|
|
|
|
of these parts will be done during the next paint pass.
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "scene.h"
|
2020-11-20 09:35:38 +00:00
|
|
|
#include "abstract_output.h"
|
2021-02-04 09:07:20 +00:00
|
|
|
#include "internal_client.h"
|
2020-11-09 12:19:15 +00:00
|
|
|
#include "platform.h"
|
2021-02-04 09:07:20 +00:00
|
|
|
#include "shadowitem.h"
|
|
|
|
#include "surfaceitem.h"
|
|
|
|
#include "unmanaged.h"
|
|
|
|
#include "waylandclient.h"
|
|
|
|
#include "windowitem.h"
|
|
|
|
#include "x11client.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-08-08 09:39:39 +00:00
|
|
|
#include <QQuickWindow>
|
2012-03-29 18:17:57 +00:00
|
|
|
#include <QVector2D>
|
2012-03-25 18:06:26 +00:00
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
#include "x11client.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "deleted.h"
|
|
|
|
#include "effects.h"
|
2020-11-28 20:01:45 +00:00
|
|
|
#include "renderloop.h"
|
2014-11-25 07:40:23 +00:00
|
|
|
#include "screens.h"
|
2011-03-27 10:33:07 +00:00
|
|
|
#include "shadow.h"
|
2015-11-23 10:33:49 +00:00
|
|
|
#include "wayland_server.h"
|
2020-10-29 18:25:39 +00:00
|
|
|
#include "composite.h"
|
2021-07-27 17:43:22 +00:00
|
|
|
#include <QtMath>
|
2008-09-18 15:27:13 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Scene
|
|
|
|
//****************************************
|
|
|
|
|
2015-02-23 13:41:45 +00:00
|
|
|
Scene::Scene(QObject *parent)
|
|
|
|
: QObject(parent)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2021-08-24 20:55:42 +00:00
|
|
|
connect(kwinApp()->platform(), &Platform::outputDisabled, this, &Scene::removeRepaints);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
Scene::~Scene()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-03-05 12:25:20 +00:00
|
|
|
Q_ASSERT(m_windows.isEmpty());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-11-20 09:35:38 +00:00
|
|
|
void Scene::addRepaint(const QRegion ®ion)
|
|
|
|
{
|
|
|
|
if (kwinApp()->platform()->isPerScreenRenderingEnabled()) {
|
2021-01-19 18:26:18 +00:00
|
|
|
const QVector<AbstractOutput *> outputs = kwinApp()->platform()->enabledOutputs();
|
2021-08-24 20:55:42 +00:00
|
|
|
for (const auto &output : outputs) {
|
2020-11-20 09:35:38 +00:00
|
|
|
const QRegion dirtyRegion = region & output->geometry();
|
|
|
|
if (!dirtyRegion.isEmpty()) {
|
2021-08-24 20:55:42 +00:00
|
|
|
m_repaints[output] += dirtyRegion;
|
2020-11-28 20:01:45 +00:00
|
|
|
output->renderLoop()->scheduleRepaint();
|
2020-11-20 09:35:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_repaints[0] += region;
|
2020-11-28 20:01:45 +00:00
|
|
|
kwinApp()->platform()->renderLoop()->scheduleRepaint();
|
2020-11-20 09:35:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
QRegion Scene::repaints(AbstractOutput *output) const
|
2020-11-20 09:35:38 +00:00
|
|
|
{
|
2021-08-24 20:55:42 +00:00
|
|
|
return m_repaints.value(output, infiniteRegion());
|
2020-11-20 09:35:38 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
void Scene::resetRepaints(AbstractOutput *output)
|
2020-11-20 09:35:38 +00:00
|
|
|
{
|
2021-08-24 20:55:42 +00:00
|
|
|
m_repaints.insert(output, QRegion());
|
2020-11-20 09:35:38 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
void Scene::removeRepaints(AbstractOutput *output)
|
2020-11-20 09:35:38 +00:00
|
|
|
{
|
2021-08-24 20:55:42 +00:00
|
|
|
m_repaints.remove(output);
|
2020-11-20 09:35:38 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 15:14:25 +00:00
|
|
|
|
|
|
|
QMatrix4x4 Scene::createProjectionMatrix(const QRect &rect)
|
|
|
|
{
|
|
|
|
// Create a perspective projection with a 60° field-of-view,
|
|
|
|
// and an aspect ratio of 1.0.
|
|
|
|
QMatrix4x4 ret;
|
|
|
|
ret.setToIdentity();
|
|
|
|
const float fovY = std::tan(qDegreesToRadians(60.0f) / 2);
|
|
|
|
const float aspect = 1.0f;
|
|
|
|
const float zNear = 0.1f;
|
|
|
|
const float zFar = 100.0f;
|
|
|
|
|
|
|
|
const float yMax = zNear * fovY;
|
|
|
|
const float yMin = -yMax;
|
|
|
|
const float xMin = yMin * aspect;
|
|
|
|
const float xMax = yMax * aspect;
|
|
|
|
|
|
|
|
ret.frustum(xMin, xMax, yMin, yMax, zNear, zFar);
|
|
|
|
|
|
|
|
const float scaleFactor = 1.1 * fovY / yMax;
|
|
|
|
ret.translate(xMin * scaleFactor, yMax * scaleFactor, -1.1);
|
|
|
|
ret.scale( (xMax - xMin) * scaleFactor / rect.width(),
|
|
|
|
-(yMax - yMin) * scaleFactor / rect.height(),
|
|
|
|
0.001);
|
|
|
|
ret.translate(-rect.x(), -rect.y());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::paintScreen(AbstractOutput *output, const QList<Toplevel *> &toplevels)
|
|
|
|
{
|
|
|
|
createStackingOrder(toplevels);
|
|
|
|
|
|
|
|
const QRect geo = output->geometry();
|
|
|
|
QRegion update = geo, repaint = geo, valid;
|
|
|
|
|
|
|
|
paintScreen(geo, repaint, &update, &valid, output->renderLoop(), createProjectionMatrix(output->geometry()));
|
|
|
|
clearStackingOrder();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
// returns mask and possibly modified region
|
2021-07-24 13:18:03 +00:00
|
|
|
void Scene::paintScreen(const QRegion &damage, const QRegion &repaint,
|
2021-01-26 12:18:29 +00:00
|
|
|
QRegion *updateRegion, QRegion *validRegion, RenderLoop *renderLoop,
|
2021-03-01 09:45:52 +00:00
|
|
|
const QMatrix4x4 &projection)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-11-25 07:40:23 +00:00
|
|
|
const QSize &screenSize = screens()->size();
|
|
|
|
const QRegion displayRegion(0, 0, screenSize.width(), screenSize.height());
|
2013-02-18 22:17:46 +00:00
|
|
|
|
2021-01-26 12:18:29 +00:00
|
|
|
const std::chrono::milliseconds presentTime =
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(renderLoop->nextPresentationTimestamp());
|
|
|
|
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
if (Q_UNLIKELY(presentTime < m_expectedPresentTimestamp)) {
|
2021-10-06 19:49:21 +00:00
|
|
|
qCDebug(KWIN_CORE,
|
|
|
|
"Provided presentation timestamp is invalid: %lld (current: %lld)",
|
|
|
|
static_cast<long long>(presentTime.count()),
|
|
|
|
static_cast<long long>(m_expectedPresentTimestamp.count()));
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
} else {
|
|
|
|
m_expectedPresentTimestamp = presentTime;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// preparation step
|
2021-10-01 07:23:30 +00:00
|
|
|
auto effectsImpl = static_cast<EffectsHandlerImpl *>(effects);
|
|
|
|
effectsImpl->startPaint();
|
2011-07-06 08:01:23 +00:00
|
|
|
|
2013-11-23 14:08:17 +00:00
|
|
|
QRegion region = damage;
|
|
|
|
|
2021-10-01 07:23:30 +00:00
|
|
|
auto screen = painted_screen ? EffectScreenImpl::get(painted_screen) : nullptr;
|
2007-07-07 14:01:32 +00:00
|
|
|
ScreenPrePaintData pdata;
|
2021-07-24 13:18:03 +00:00
|
|
|
pdata.mask = (damage == displayRegion) ? 0 : PAINT_SCREEN_REGION;
|
2013-11-23 14:08:17 +00:00
|
|
|
pdata.paint = region;
|
2021-07-26 15:07:29 +00:00
|
|
|
pdata.screen = screen;
|
2011-07-06 08:01:23 +00:00
|
|
|
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
effects->prePaintScreen(pdata, m_expectedPresentTimestamp);
|
2013-11-23 14:08:17 +00:00
|
|
|
region = pdata.paint;
|
2011-07-06 08:01:23 +00:00
|
|
|
|
2021-07-24 13:18:03 +00:00
|
|
|
int mask = pdata.mask;
|
|
|
|
if (mask & (PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS)) {
|
2011-01-30 14:34:42 +00:00
|
|
|
// Region painting is not possible with transformations,
|
|
|
|
// because screen damage doesn't match transformed positions.
|
2021-07-24 13:18:03 +00:00
|
|
|
mask &= ~PAINT_SCREEN_REGION;
|
2013-11-23 14:08:17 +00:00
|
|
|
region = infiniteRegion();
|
2021-07-24 13:18:03 +00:00
|
|
|
} else if (mask & PAINT_SCREEN_REGION) {
|
2011-01-30 14:34:42 +00:00
|
|
|
// make sure not to go outside visible screen
|
2013-11-23 14:08:17 +00:00
|
|
|
region &= displayRegion;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
// whole screen, not transformed, force region to be full
|
2013-11-23 14:08:17 +00:00
|
|
|
region = displayRegion;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2013-11-23 14:08:17 +00:00
|
|
|
|
|
|
|
painted_region = region;
|
2013-11-21 09:44:06 +00:00
|
|
|
repaint_region = repaint;
|
2013-11-23 14:08:17 +00:00
|
|
|
|
2021-07-26 15:07:29 +00:00
|
|
|
ScreenPaintData data(projection, screen);
|
2021-07-24 13:18:03 +00:00
|
|
|
effects->paintScreen(mask, region, data);
|
2013-11-23 14:08:17 +00:00
|
|
|
|
2021-06-03 08:45:29 +00:00
|
|
|
Q_EMIT frameRendered();
|
|
|
|
|
2021-11-03 11:55:31 +00:00
|
|
|
for (Window *w : qAsConst(stacking_order)) {
|
2012-01-29 17:20:50 +00:00
|
|
|
effects->postPaintWindow(effectWindow(w));
|
|
|
|
}
|
2013-11-23 14:08:17 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->postPaintScreen();
|
2013-11-23 14:08:17 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// make sure not to go outside of the screen area
|
2013-11-21 09:44:06 +00:00
|
|
|
*updateRegion = damaged_region;
|
2013-11-23 14:08:17 +00:00
|
|
|
*validRegion = (region | painted_region) & displayRegion;
|
|
|
|
|
2013-11-21 09:44:06 +00:00
|
|
|
repaint_region = QRegion();
|
|
|
|
damaged_region = QRegion();
|
|
|
|
|
2020-04-24 17:11:41 +00:00
|
|
|
m_paintScreenCount = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// the function that'll be eventually called by paintScreen() above
|
2020-03-13 16:41:56 +00:00
|
|
|
void Scene::finalPaintScreen(int mask, const QRegion ®ion, ScreenPaintData& data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2020-04-24 17:11:41 +00:00
|
|
|
m_paintScreenCount++;
|
2012-01-29 16:25:20 +00:00
|
|
|
if (mask & (PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS))
|
2011-01-30 14:34:42 +00:00
|
|
|
paintGenericScreen(mask, data);
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
paintSimpleScreen(mask, region);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
static void resetRepaintsHelper(Item *item, AbstractOutput *output)
|
2021-04-30 08:42:54 +00:00
|
|
|
{
|
2021-08-24 20:55:42 +00:00
|
|
|
item->resetRepaints(output);
|
2021-04-30 08:42:54 +00:00
|
|
|
|
|
|
|
const auto childItems = item->childItems();
|
|
|
|
for (Item *childItem : childItems) {
|
2021-08-24 20:55:42 +00:00
|
|
|
resetRepaintsHelper(childItem, output);
|
2021-04-30 08:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// The generic painting code that can handle even transformations.
|
|
|
|
// It simply paints bottom-to-top.
|
2020-03-13 16:41:56 +00:00
|
|
|
void Scene::paintGenericScreen(int orig_mask, const ScreenPaintData &)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-01-11 19:55:04 +00:00
|
|
|
QVector<Phase2Data> phase2;
|
2019-01-12 13:39:16 +00:00
|
|
|
phase2.reserve(stacking_order.size());
|
2021-11-03 11:55:31 +00:00
|
|
|
for (Window * w : qAsConst(stacking_order)) { // bottom to top
|
2011-07-06 08:01:23 +00:00
|
|
|
// Reset the repaint_region.
|
|
|
|
// This has to be done here because many effects schedule a repaint for
|
|
|
|
// the next frame within Effects::prePaintWindow.
|
2021-04-30 08:42:54 +00:00
|
|
|
resetRepaintsHelper(w->windowItem(), painted_screen);
|
2011-07-06 08:01:23 +00:00
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
WindowPrePaintData data;
|
2011-01-30 14:34:42 +00:00
|
|
|
data.mask = orig_mask | (w->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT);
|
2007-04-29 17:35:43 +00:00
|
|
|
w->resetPaintingEnabled();
|
2007-07-07 14:01:32 +00:00
|
|
|
data.paint = infiniteRegion(); // no clipping, so doesn't really matter
|
|
|
|
data.clip = QRegion();
|
2007-04-29 17:35:43 +00:00
|
|
|
// preparation step
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
effects->prePaintWindow(effectWindow(w), data, m_expectedPresentTimestamp);
|
2012-01-29 17:20:50 +00:00
|
|
|
if (!w->isPaintingEnabled()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
continue;
|
2012-01-29 17:20:50 +00:00
|
|
|
}
|
2021-06-10 10:32:37 +00:00
|
|
|
phase2.append({w, infiniteRegion(), data.clip, data.mask,});
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 17:11:41 +00:00
|
|
|
damaged_region = QRegion(QRect {{}, screens()->size()});
|
|
|
|
if (m_paintScreenCount == 1) {
|
2020-10-30 07:39:17 +00:00
|
|
|
aboutToStartPainting(painted_screen, damaged_region);
|
2020-04-24 17:11:41 +00:00
|
|
|
|
|
|
|
if (orig_mask & PAINT_SCREEN_BACKGROUND_FIRST) {
|
|
|
|
paintBackground(infiniteRegion());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(orig_mask & PAINT_SCREEN_BACKGROUND_FIRST)) {
|
|
|
|
paintBackground(infiniteRegion());
|
|
|
|
}
|
2021-11-03 11:55:31 +00:00
|
|
|
for (const Phase2Data &d : qAsConst(phase2)) {
|
2021-06-10 10:32:37 +00:00
|
|
|
paintWindow(d.window, d.mask, d.region);
|
2012-01-29 16:25:20 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
static void accumulateRepaints(Item *item, AbstractOutput *output, QRegion *repaints)
|
2021-04-30 08:42:54 +00:00
|
|
|
{
|
2021-08-24 20:55:42 +00:00
|
|
|
*repaints += item->repaints(output);
|
|
|
|
item->resetRepaints(output);
|
2021-04-30 08:42:54 +00:00
|
|
|
|
|
|
|
const auto childItems = item->childItems();
|
|
|
|
for (Item *childItem : childItems) {
|
2021-08-24 20:55:42 +00:00
|
|
|
accumulateRepaints(childItem, output, repaints);
|
2021-04-30 08:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// The optimized case without any transformations at all.
|
|
|
|
// It can paint only the requested region and can use clipping
|
|
|
|
// to reduce painting and improve performance.
|
2020-03-13 16:41:56 +00:00
|
|
|
void Scene::paintSimpleScreen(int orig_mask, const QRegion ®ion)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT((orig_mask & (PAINT_SCREEN_TRANSFORMED
|
2012-01-29 16:25:20 +00:00
|
|
|
| PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS)) == 0);
|
2019-01-11 16:26:22 +00:00
|
|
|
QVector<Phase2Data> phase2data;
|
2019-01-12 13:39:16 +00:00
|
|
|
phase2data.reserve(stacking_order.size());
|
2011-07-06 08:01:23 +00:00
|
|
|
|
|
|
|
QRegion dirtyArea = region;
|
2019-09-27 13:59:44 +00:00
|
|
|
bool opaqueFullscreen = false;
|
|
|
|
|
|
|
|
// Traverse the scene windows from bottom to top.
|
|
|
|
for (int i = 0; i < stacking_order.count(); ++i) {
|
|
|
|
Window *window = stacking_order[i];
|
|
|
|
Toplevel *toplevel = window->window();
|
2007-07-07 14:01:32 +00:00
|
|
|
WindowPrePaintData data;
|
2019-09-27 13:59:44 +00:00
|
|
|
data.mask = orig_mask | (window->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT);
|
|
|
|
window->resetPaintingEnabled();
|
2007-07-07 14:01:32 +00:00
|
|
|
data.paint = region;
|
2021-04-30 08:42:54 +00:00
|
|
|
accumulateRepaints(window->windowItem(), painted_screen, &data.paint);
|
2011-07-06 08:01:23 +00:00
|
|
|
|
2009-04-22 17:29:56 +00:00
|
|
|
// Clip out the decoration for opaque windows; the decoration is drawn in the second pass
|
2013-02-18 22:17:46 +00:00
|
|
|
opaqueFullscreen = false; // TODO: do we care about unmanged windows here (maybe input windows?)
|
2020-09-25 17:42:34 +00:00
|
|
|
AbstractClient *client = dynamic_cast<AbstractClient *>(toplevel);
|
2019-09-27 13:59:44 +00:00
|
|
|
if (window->isOpaque()) {
|
|
|
|
if (client) {
|
|
|
|
opaqueFullscreen = client->isFullScreen();
|
2012-10-12 09:34:05 +00:00
|
|
|
}
|
2020-09-25 17:42:34 +00:00
|
|
|
|
2021-02-04 09:07:20 +00:00
|
|
|
const SurfaceItem *surfaceItem = window->surfaceItem();
|
|
|
|
if (surfaceItem) {
|
|
|
|
data.clip |= surfaceItem->mapToGlobal(surfaceItem->shape());
|
2020-09-08 14:27:14 +00:00
|
|
|
}
|
2019-09-27 13:59:44 +00:00
|
|
|
} else if (toplevel->hasAlpha() && toplevel->opacity() == 1.0) {
|
2021-02-04 09:07:20 +00:00
|
|
|
const SurfaceItem *surfaceItem = window->surfaceItem();
|
|
|
|
if (surfaceItem) {
|
|
|
|
const QRegion shape = surfaceItem->shape();
|
|
|
|
const QRegion opaque = surfaceItem->opaque();
|
|
|
|
data.clip = surfaceItem->mapToGlobal(shape & opaque);
|
2020-09-23 20:32:33 +00:00
|
|
|
|
|
|
|
if (opaque == shape) {
|
|
|
|
data.mask = orig_mask | PAINT_WINDOW_OPAQUE;
|
|
|
|
}
|
2020-09-08 14:27:14 +00:00
|
|
|
}
|
2011-10-22 09:02:49 +00:00
|
|
|
} else {
|
|
|
|
data.clip = QRegion();
|
|
|
|
}
|
2020-09-25 17:42:34 +00:00
|
|
|
|
|
|
|
if (client && !client->decorationHasAlpha() && toplevel->opacity() == 1.0) {
|
|
|
|
data.clip |= window->decorationShape().translated(window->pos());
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// preparation step
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
effects->prePaintWindow(effectWindow(window), data, m_expectedPresentTimestamp);
|
2019-09-27 13:59:44 +00:00
|
|
|
if (!window->isPaintingEnabled()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-07-14 12:17:33 +00:00
|
|
|
dirtyArea |= data.paint;
|
2007-12-07 17:03:59 +00:00
|
|
|
// Schedule the window for painting
|
2021-06-10 10:32:37 +00:00
|
|
|
phase2data.append({ window, data.paint, data.clip, data.mask, });
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2012-01-10 17:56:14 +00:00
|
|
|
|
2013-11-21 09:44:06 +00:00
|
|
|
// Save the part of the repaint region that's exclusively rendered to
|
|
|
|
// bring a reused back buffer up to date. Then union the dirty region
|
|
|
|
// with the repaint region.
|
|
|
|
const QRegion repaintClip = repaint_region - dirtyArea;
|
|
|
|
dirtyArea |= repaint_region;
|
2013-02-18 22:17:46 +00:00
|
|
|
|
2014-11-25 07:40:23 +00:00
|
|
|
const QSize &screenSize = screens()->size();
|
|
|
|
const QRegion displayRegion(0, 0, screenSize.width(), screenSize.height());
|
2013-02-18 22:17:46 +00:00
|
|
|
bool fullRepaint(dirtyArea == displayRegion); // spare some expensive region operations
|
|
|
|
if (!fullRepaint) {
|
|
|
|
extendPaintRegion(dirtyArea, opaqueFullscreen);
|
|
|
|
fullRepaint = (dirtyArea == displayRegion);
|
|
|
|
}
|
|
|
|
|
2011-07-06 08:01:23 +00:00
|
|
|
QRegion allclips, upperTranslucentDamage;
|
2013-11-21 09:44:06 +00:00
|
|
|
upperTranslucentDamage = repaint_region;
|
|
|
|
|
2013-02-18 22:17:46 +00:00
|
|
|
// This is the occlusion culling pass
|
2012-01-10 17:56:14 +00:00
|
|
|
for (int i = phase2data.count() - 1; i >= 0; --i) {
|
2019-01-11 16:26:22 +00:00
|
|
|
Phase2Data *data = &phase2data[i];
|
2011-07-06 08:01:23 +00:00
|
|
|
|
2019-09-27 13:59:44 +00:00
|
|
|
if (fullRepaint) {
|
2013-02-18 22:17:46 +00:00
|
|
|
data->region = displayRegion;
|
2019-09-27 13:59:44 +00:00
|
|
|
} else {
|
2013-02-18 22:17:46 +00:00
|
|
|
data->region |= upperTranslucentDamage;
|
2019-09-27 13:59:44 +00:00
|
|
|
}
|
2012-02-07 16:01:41 +00:00
|
|
|
|
2012-01-10 17:56:14 +00:00
|
|
|
// subtract the parts which will possibly been drawn as part of
|
2011-07-06 08:01:23 +00:00
|
|
|
// a higher opaque window
|
|
|
|
data->region -= allclips;
|
|
|
|
|
2011-10-22 09:02:49 +00:00
|
|
|
// Here we rely on WindowPrePaintData::setTranslucent() to remove
|
|
|
|
// the clip if needed.
|
2019-01-13 21:25:43 +00:00
|
|
|
if (!data->clip.isEmpty() && !(data->mask & PAINT_WINDOW_TRANSLUCENT)) {
|
2012-01-10 17:56:14 +00:00
|
|
|
// clip away the opaque regions for all windows below this one
|
2011-07-06 08:01:23 +00:00
|
|
|
allclips |= data->clip;
|
2012-01-10 17:56:14 +00:00
|
|
|
// extend the translucent damage for windows below this by remaining (translucent) regions
|
2019-09-27 13:59:44 +00:00
|
|
|
if (!fullRepaint) {
|
2013-02-18 22:17:46 +00:00
|
|
|
upperTranslucentDamage |= data->region - data->clip;
|
2019-09-27 13:59:44 +00:00
|
|
|
}
|
2013-02-18 22:17:46 +00:00
|
|
|
} else if (!fullRepaint) {
|
2012-01-10 17:56:14 +00:00
|
|
|
upperTranslucentDamage |= data->region;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-07-06 08:01:23 +00:00
|
|
|
|
2012-01-10 17:56:14 +00:00
|
|
|
QRegion paintedArea;
|
2011-07-06 08:01:23 +00:00
|
|
|
// Fill any areas of the root window not covered by opaque windows
|
2020-04-24 17:11:41 +00:00
|
|
|
if (m_paintScreenCount == 1) {
|
2020-10-30 07:39:17 +00:00
|
|
|
aboutToStartPainting(painted_screen, dirtyArea);
|
2020-04-24 17:11:41 +00:00
|
|
|
|
|
|
|
if (orig_mask & PAINT_SCREEN_BACKGROUND_FIRST) {
|
|
|
|
paintBackground(infiniteRegion());
|
|
|
|
}
|
|
|
|
}
|
2011-07-06 08:01:23 +00:00
|
|
|
if (!(orig_mask & PAINT_SCREEN_BACKGROUND_FIRST)) {
|
2012-01-10 17:56:14 +00:00
|
|
|
paintedArea = dirtyArea - allclips;
|
|
|
|
paintBackground(paintedArea);
|
2011-07-06 08:01:23 +00:00
|
|
|
}
|
|
|
|
|
2012-01-10 17:56:14 +00:00
|
|
|
// Now walk the list bottom to top and draw the windows.
|
|
|
|
for (int i = 0; i < phase2data.count(); ++i) {
|
2019-01-11 16:26:22 +00:00
|
|
|
Phase2Data *data = &phase2data[i];
|
2011-07-06 08:01:23 +00:00
|
|
|
|
2012-01-10 17:56:14 +00:00
|
|
|
// add all regions which have been drawn so far
|
|
|
|
paintedArea |= data->region;
|
|
|
|
data->region = paintedArea;
|
2011-07-06 08:01:23 +00:00
|
|
|
|
2021-06-10 10:32:37 +00:00
|
|
|
paintWindow(data->window, data->mask, data->region);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2013-11-21 09:44:06 +00:00
|
|
|
|
|
|
|
if (fullRepaint) {
|
2013-02-18 22:17:46 +00:00
|
|
|
painted_region = displayRegion;
|
2020-04-14 02:35:09 +00:00
|
|
|
damaged_region = displayRegion - repaintClip;
|
2013-11-21 09:44:06 +00:00
|
|
|
} else {
|
2013-02-18 22:17:46 +00:00
|
|
|
painted_region |= paintedArea;
|
2013-11-21 09:44:06 +00:00
|
|
|
|
|
|
|
// Clip the repainted region from the damaged region.
|
|
|
|
// It's important that we don't add the union of the damaged region
|
|
|
|
// and the repainted region to the damage history. Otherwise the
|
|
|
|
// repaint region will grow with every frame until it eventually
|
|
|
|
// covers the whole back buffer, at which point we're always doing
|
|
|
|
// full repaints.
|
|
|
|
damaged_region = paintedArea - repaintClip;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-01-11 18:55:17 +00:00
|
|
|
void Scene::addToplevel(Toplevel *c)
|
2013-06-24 07:53:11 +00:00
|
|
|
{
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(!m_windows.contains(c));
|
2013-06-24 07:53:11 +00:00
|
|
|
Scene::Window *w = createWindow(c);
|
|
|
|
m_windows[ c ] = w;
|
2020-04-22 11:59:42 +00:00
|
|
|
|
2020-09-23 18:39:59 +00:00
|
|
|
connect(c, &Toplevel::windowClosed, this, &Scene::windowClosed);
|
2020-04-23 09:09:07 +00:00
|
|
|
|
2013-06-24 07:53:11 +00:00
|
|
|
c->effectWindow()->setSceneWindow(w);
|
|
|
|
}
|
|
|
|
|
2019-01-11 18:55:17 +00:00
|
|
|
void Scene::removeToplevel(Toplevel *toplevel)
|
2013-06-24 07:53:11 +00:00
|
|
|
{
|
2019-01-11 18:55:17 +00:00
|
|
|
Q_ASSERT(m_windows.contains(toplevel));
|
|
|
|
delete m_windows.take(toplevel);
|
|
|
|
toplevel->effectWindow()->setSceneWindow(nullptr);
|
2013-06-24 07:53:11 +00:00
|
|
|
}
|
|
|
|
|
2019-01-11 18:55:17 +00:00
|
|
|
void Scene::windowClosed(Toplevel *toplevel, Deleted *deleted)
|
2013-06-24 07:53:11 +00:00
|
|
|
{
|
2019-01-11 18:55:17 +00:00
|
|
|
if (!deleted) {
|
|
|
|
removeToplevel(toplevel);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(m_windows.contains(toplevel));
|
|
|
|
Window *window = m_windows.take(toplevel);
|
|
|
|
window->updateToplevel(deleted);
|
|
|
|
m_windows[deleted] = window;
|
2013-06-24 07:53:11 +00:00
|
|
|
}
|
|
|
|
|
2020-03-13 16:41:56 +00:00
|
|
|
void Scene::createStackingOrder(const QList<Toplevel *> &toplevels)
|
2013-06-24 07:53:11 +00:00
|
|
|
{
|
|
|
|
// TODO: cache the stacking_order in case it has not changed
|
2021-11-03 11:55:31 +00:00
|
|
|
for (Toplevel *c : toplevels) {
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(m_windows.contains(c));
|
2013-06-24 07:53:11 +00:00
|
|
|
stacking_order.append(m_windows[ c ]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::clearStackingOrder()
|
|
|
|
{
|
|
|
|
stacking_order.clear();
|
|
|
|
}
|
|
|
|
|
2021-06-10 10:32:37 +00:00
|
|
|
void Scene::paintWindow(Window* w, int mask, const QRegion &_region)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-12-07 17:03:59 +00:00
|
|
|
// no painting outside visible screen (and no transformations)
|
2020-03-13 16:41:56 +00:00
|
|
|
const QRegion region = _region & QRect({0, 0}, screens()->size());
|
2011-01-30 14:34:42 +00:00
|
|
|
if (region.isEmpty()) // completely clipped
|
2007-12-07 17:03:59 +00:00
|
|
|
return;
|
|
|
|
|
2015-11-30 13:35:12 +00:00
|
|
|
WindowPaintData data(w->window()->effectWindow(), screenProjectionMatrix());
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(effectWindow(w), mask, region, data);
|
2012-03-29 18:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::paintDesktop(int desktop, int mask, const QRegion ®ion, ScreenPaintData &data)
|
|
|
|
{
|
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->paintDesktop(desktop, mask, region, data);
|
|
|
|
}
|
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
void Scene::aboutToStartPainting(AbstractOutput *output, const QRegion &damage)
|
2020-04-24 17:11:41 +00:00
|
|
|
{
|
2021-08-24 20:55:42 +00:00
|
|
|
Q_UNUSED(output)
|
2020-04-24 17:11:41 +00:00
|
|
|
Q_UNUSED(damage)
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// the function that'll be eventually called by paintWindow() above
|
2020-03-13 16:41:56 +00:00
|
|
|
void Scene::finalPaintWindow(EffectWindowImpl* w, int mask, const QRegion ®ion, WindowPaintData& data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
effects->drawWindow(w, mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// will be eventually called from drawWindow()
|
2020-03-13 16:41:56 +00:00
|
|
|
void Scene::finalDrawWindow(EffectWindowImpl* w, int mask, const QRegion ®ion, WindowPaintData& data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2015-12-04 15:12:59 +00:00
|
|
|
if (waylandServer() && waylandServer()->isScreenLocked() && !w->window()->isLockScreen() && !w->window()->isInputMethod()) {
|
2015-11-23 10:33:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-13 20:41:02 +00:00
|
|
|
w->sceneWindow()->performPaint(mask, region, data);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-02-18 22:17:46 +00:00
|
|
|
void Scene::extendPaintRegion(QRegion ®ion, bool opaqueFullscreen)
|
|
|
|
{
|
|
|
|
Q_UNUSED(region);
|
|
|
|
Q_UNUSED(opaqueFullscreen);
|
|
|
|
}
|
|
|
|
|
Better handling for making the compositing OpenGL context current
With QtQuick2 it's possible that the scene graph rendering context either
lives in an own thread or uses the main GUI thread. In the latter case
it's the same thread as our compositing OpenGL context lives in. This
means our basic assumption that between two rendering passes the context
stays current does not hold.
The code already ensured that before we start a rendering pass the
context is made current, but there are many more possible cases. If we
use OpenGL in areas not triggered by the rendering loop but in response
to other events the context needs to be made current. This includes the
loading and unloading of effects (some effects use OpenGL in the static
effect check, in the ctor and dtor), background loading of texture data,
lazy loading after first usage invoked by shortcut, etc. etc.
To properly handle these cases new methods are added to EffectsHandler
to make the compositing OpenGL context current. These calls delegate down
into the scene. On non-OpenGL scenes they are noop, but on OpenGL they go
into the backend and make the context current. In addition they ensure
that Qt doesn't think that it's QOpenGLContext is current by calling
doneCurrent() on the QOpenGLContext::currentContext(). This unfortunately
causes an additional call to makeCurrent with a null context, but there
is no other way to tell Qt - it doesn't notice when a different context
is made current with low level API calls. In the multi-threaded
architecture this doesn't matter as ::currentContext() returns null.
A short evaluation showed that a transition to QOpenGLContext doesn't
seem feasible. Qt only supports either GLX or EGL while KWin supports
both and when entering the transition phase for Wayland, it would become
extremely tricky if our native platform is X11, but we want a Wayland
EGL context. A future solution might be to have a "KWin-QPA plugin" which
uses either xcb or Wayland and hides everything from Qt.
The API documentation is extended to describe when the effects-framework
ensures that an OpenGL context is current. The effects are changed to
make the context current in cases where it's not guaranteed. This has
been done by looking for creation or deletion of GLTextures and Shaders.
If there are other OpenGL usages outside the rendering loop, ctor/dtor
this needs to be changed, too.
2013-11-22 14:05:36 +00:00
|
|
|
bool Scene::makeOpenGLContextCurrent()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::doneOpenGLContextCurrent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-10-15 09:27:00 +00:00
|
|
|
bool Scene::supportsNativeFence() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-30 13:35:12 +00:00
|
|
|
QMatrix4x4 Scene::screenProjectionMatrix() const
|
|
|
|
{
|
|
|
|
return QMatrix4x4();
|
|
|
|
}
|
|
|
|
|
2017-08-09 04:56:23 +00:00
|
|
|
QPainter *Scene::scenePainter() const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
QImage *Scene::qpainterRenderBuffer(AbstractOutput *output) const
|
2017-08-11 12:59:09 +00:00
|
|
|
{
|
2021-08-24 20:55:42 +00:00
|
|
|
Q_UNUSED(output)
|
2017-08-11 12:59:09 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:49:52 +00:00
|
|
|
QVector<QByteArray> Scene::openGLPlatformInterfaceExtensions() const
|
|
|
|
{
|
|
|
|
return QVector<QByteArray>{};
|
|
|
|
}
|
|
|
|
|
2021-10-20 14:58:58 +00:00
|
|
|
SurfaceTexture *Scene::createSurfaceTextureInternal(SurfacePixmapInternal *pixmap)
|
2021-04-09 07:06:04 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(pixmap)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-10-20 14:58:58 +00:00
|
|
|
SurfaceTexture *Scene::createSurfaceTextureX11(SurfacePixmapX11 *pixmap)
|
2021-04-09 07:06:04 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(pixmap)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-10-20 14:58:58 +00:00
|
|
|
SurfaceTexture *Scene::createSurfaceTextureWayland(SurfacePixmapWayland *pixmap)
|
2021-04-09 07:06:04 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(pixmap)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//****************************************
|
|
|
|
// Scene::Window
|
|
|
|
//****************************************
|
|
|
|
|
2020-06-10 06:13:35 +00:00
|
|
|
Scene::Window::Window(Toplevel *client, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, toplevel(client)
|
2011-01-30 14:34:42 +00:00
|
|
|
, disable_painting(0)
|
|
|
|
{
|
2021-02-04 09:07:20 +00:00
|
|
|
if (qobject_cast<WaylandClient *>(client)) {
|
2021-08-12 09:07:38 +00:00
|
|
|
m_windowItem.reset(new WindowItemWayland(toplevel));
|
2021-02-04 09:07:20 +00:00
|
|
|
} else if (qobject_cast<X11Client *>(client) || qobject_cast<Unmanaged *>(client)) {
|
2021-08-12 09:07:38 +00:00
|
|
|
m_windowItem.reset(new WindowItemX11(toplevel));
|
2021-02-04 09:07:20 +00:00
|
|
|
} else if (qobject_cast<InternalClient *>(client)) {
|
2021-08-12 09:07:38 +00:00
|
|
|
m_windowItem.reset(new WindowItemInternal(toplevel));
|
2021-02-04 09:07:20 +00:00
|
|
|
} else {
|
|
|
|
Q_UNREACHABLE();
|
2020-11-03 11:18:09 +00:00
|
|
|
}
|
2020-11-03 11:23:13 +00:00
|
|
|
|
2021-02-04 09:07:20 +00:00
|
|
|
connect(toplevel, &Toplevel::frameGeometryChanged, this, &Window::updateWindowPosition);
|
|
|
|
updateWindowPosition();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
Scene::Window::~Window()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-11-03 11:18:09 +00:00
|
|
|
void Scene::Window::updateToplevel(Deleted *deleted)
|
|
|
|
{
|
|
|
|
toplevel = deleted;
|
|
|
|
}
|
|
|
|
|
2013-05-10 10:07:56 +00:00
|
|
|
void Scene::Window::referencePreviousPixmap()
|
|
|
|
{
|
2021-02-04 09:07:20 +00:00
|
|
|
if (surfaceItem()) {
|
|
|
|
referencePreviousPixmap_helper(surfaceItem());
|
2013-05-10 10:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 09:07:20 +00:00
|
|
|
void Scene::Window::referencePreviousPixmap_helper(SurfaceItem *item)
|
2013-05-10 10:07:56 +00:00
|
|
|
{
|
2021-02-04 09:07:20 +00:00
|
|
|
item->referencePreviousPixmap();
|
|
|
|
|
|
|
|
const QList<Item *> children = item->childItems();
|
|
|
|
for (Item *child : children) {
|
|
|
|
referencePreviousPixmap_helper(static_cast<SurfaceItem *>(child));
|
2013-05-10 10:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 09:07:20 +00:00
|
|
|
void Scene::Window::unreferencePreviousPixmap()
|
2013-05-10 10:07:56 +00:00
|
|
|
{
|
2021-02-04 09:07:20 +00:00
|
|
|
if (surfaceItem()) {
|
|
|
|
unreferencePreviousPixmap_helper(surfaceItem());
|
2013-05-10 10:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 09:07:20 +00:00
|
|
|
void Scene::Window::unreferencePreviousPixmap_helper(SurfaceItem *item)
|
[x11] Fix visual artifacts during interactive resize
Summary:
When a window is being interactively resized, its contents may jump. The
reason why that happens is because KWin renders partially resized client
window. Composite extension spec says that a window will get a new pixmap
each time it is resized or mapped. This applies to the frame window, but
not to the client window itself. If the client window is resized,
off-screen storage for the frame window won't be reallocated. Therefore,
KWin may render partially resized client window if the client doesn't
attempt to be in sync with our rendering loop. Currently, the only way
to do that is to use extended frame counters, which are not supported by
KWin.
So, in order to fix visual artifacts during interactive resize, we need
somehow forcefully re-allocate off-screen storage for the frame window.
Unfortunately, Composite extension doesn't provide any request to do
that, so the only option we have is to resize the frame window.
BUG: 415839
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: davidedmundson, ngraham, alexde, fredrik, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D26914
2020-02-03 11:29:43 +00:00
|
|
|
{
|
2021-02-04 09:07:20 +00:00
|
|
|
item->unreferencePreviousPixmap();
|
|
|
|
|
|
|
|
const QList<Item *> children = item->childItems();
|
|
|
|
for (Item *child : children) {
|
|
|
|
unreferencePreviousPixmap_helper(static_cast<SurfaceItem *>(child));
|
[x11] Fix visual artifacts during interactive resize
Summary:
When a window is being interactively resized, its contents may jump. The
reason why that happens is because KWin renders partially resized client
window. Composite extension spec says that a window will get a new pixmap
each time it is resized or mapped. This applies to the frame window, but
not to the client window itself. If the client window is resized,
off-screen storage for the frame window won't be reallocated. Therefore,
KWin may render partially resized client window if the client doesn't
attempt to be in sync with our rendering loop. Currently, the only way
to do that is to use extended frame counters, which are not supported by
KWin.
So, in order to fix visual artifacts during interactive resize, we need
somehow forcefully re-allocate off-screen storage for the frame window.
Unfortunately, Composite extension doesn't provide any request to do
that, so the only option we have is to resize the frame window.
BUG: 415839
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: davidedmundson, ngraham, alexde, fredrik, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D26914
2020-02-03 11:29:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-27 10:33:42 +00:00
|
|
|
QRegion Scene::Window::decorationShape() const
|
|
|
|
{
|
2021-08-12 11:56:39 +00:00
|
|
|
const QRect decorationInnerRect = toplevel->rect() - toplevel->frameMargins();
|
|
|
|
return QRegion(toplevel->rect()) - decorationInnerRect;
|
2019-09-27 10:33:42 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
bool Scene::Window::isVisible() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-09-07 07:40:44 +00:00
|
|
|
if (toplevel->isDeleted())
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!toplevel->isOnCurrentDesktop())
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!toplevel->isOnCurrentActivity())
|
2010-05-15 20:18:57 +00:00
|
|
|
return false;
|
2015-06-03 19:19:00 +00:00
|
|
|
if (AbstractClient *c = dynamic_cast<AbstractClient*>(toplevel))
|
|
|
|
return c->isShown(true);
|
2007-04-29 17:35:43 +00:00
|
|
|
return true; // Unmanaged is always visible
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool Scene::Window::isOpaque() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return toplevel->opacity() == 1.0 && !toplevel->hasAlpha();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool Scene::Window::isPaintingEnabled() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return !disable_painting;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void Scene::Window::resetPaintingEnabled()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
disable_painting = 0;
|
2012-09-07 07:40:44 +00:00
|
|
|
if (toplevel->isDeleted())
|
2007-04-29 17:35:43 +00:00
|
|
|
disable_painting |= PAINT_DISABLED_BY_DELETE;
|
2012-03-29 18:12:34 +00:00
|
|
|
if (static_cast<EffectsHandlerImpl*>(effects)->isDesktopRendering()) {
|
|
|
|
if (!toplevel->isOnDesktop(static_cast<EffectsHandlerImpl*>(effects)->currentRenderedDesktop())) {
|
|
|
|
disable_painting |= PAINT_DISABLED_BY_DESKTOP;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!toplevel->isOnCurrentDesktop())
|
|
|
|
disable_painting |= PAINT_DISABLED_BY_DESKTOP;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!toplevel->isOnCurrentActivity())
|
2010-05-15 20:18:57 +00:00
|
|
|
disable_painting |= PAINT_DISABLED_BY_ACTIVITY;
|
2015-09-14 11:53:46 +00:00
|
|
|
if (AbstractClient *c = dynamic_cast<AbstractClient*>(toplevel)) {
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c->isMinimized())
|
2007-04-29 17:35:43 +00:00
|
|
|
disable_painting |= PAINT_DISABLED_BY_MINIMIZE;
|
2016-07-04 13:06:20 +00:00
|
|
|
if (c->isHiddenInternal()) {
|
|
|
|
disable_painting |= PAINT_DISABLED;
|
2015-09-14 11:53:46 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Scene::Window::enablePainting(int reason)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
disable_painting &= ~reason;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Scene::Window::disablePainting(int reason)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
disable_painting |= reason;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2021-02-04 09:07:20 +00:00
|
|
|
WindowItem *Scene::Window::windowItem() const
|
|
|
|
{
|
|
|
|
return m_windowItem.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceItem *Scene::Window::surfaceItem() const
|
|
|
|
{
|
|
|
|
return m_windowItem->surfaceItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
ShadowItem *Scene::Window::shadowItem() const
|
|
|
|
{
|
|
|
|
return m_windowItem->shadowItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::Window::updateWindowPosition()
|
2021-02-02 13:16:33 +00:00
|
|
|
{
|
2021-02-04 09:07:20 +00:00
|
|
|
m_windowItem->setPosition(pos());
|
2021-02-02 13:16:33 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 16:32:37 +00:00
|
|
|
//****************************************
|
|
|
|
// Scene::EffectFrame
|
|
|
|
//****************************************
|
|
|
|
Scene::EffectFrame::EffectFrame(EffectFrameImpl* frame)
|
2011-01-30 14:34:42 +00:00
|
|
|
: m_effectFrame(frame)
|
|
|
|
{
|
|
|
|
}
|
2010-07-18 16:32:37 +00:00
|
|
|
|
|
|
|
Scene::EffectFrame::~EffectFrame()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2010-07-18 16:32:37 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|