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"
|
2022-02-04 18:38:37 +00:00
|
|
|
#include "renderlayer.h"
|
2021-02-04 09:07:20 +00:00
|
|
|
#include "shadowitem.h"
|
|
|
|
#include "surfaceitem.h"
|
|
|
|
#include "unmanaged.h"
|
|
|
|
#include "waylandclient.h"
|
|
|
|
#include "windowitem.h"
|
2021-11-09 10:36:24 +00:00
|
|
|
#include "workspace.h"
|
2021-02-04 09:07:20 +00:00
|
|
|
#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
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "composite.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"
|
2011-03-27 10:33:07 +00:00
|
|
|
#include "shadow.h"
|
2015-11-23 10:33:49 +00:00
|
|
|
#include "wayland_server.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "x11client.h"
|
2021-07-27 17:43:22 +00:00
|
|
|
#include <QtMath>
|
2008-09-18 15:27:13 +00:00
|
|
|
|
2022-02-04 17:38:58 +00:00
|
|
|
#include <KWaylandServer/surface_interface.h>
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
SceneDelegate::SceneDelegate(Scene *scene, QObject *parent)
|
|
|
|
: RenderLayerDelegate(parent)
|
|
|
|
, m_scene(scene)
|
|
|
|
{
|
|
|
|
m_scene->addDelegate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneDelegate::SceneDelegate(Scene *scene, AbstractOutput *output, QObject *parent)
|
|
|
|
: RenderLayerDelegate(parent)
|
|
|
|
, m_scene(scene)
|
|
|
|
, m_output(output)
|
|
|
|
{
|
|
|
|
m_scene->addDelegate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneDelegate::~SceneDelegate()
|
|
|
|
{
|
|
|
|
m_scene->removeDelegate(this);
|
|
|
|
}
|
|
|
|
|
2022-02-16 17:13:57 +00:00
|
|
|
QRegion SceneDelegate::repaints() const
|
|
|
|
{
|
2022-04-05 14:15:57 +00:00
|
|
|
return m_scene->damage().translated(-viewport().topLeft());
|
2022-02-16 17:13:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
SurfaceItem *SceneDelegate::scanoutCandidate() const
|
|
|
|
{
|
|
|
|
return m_scene->scanoutCandidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneDelegate::prePaint()
|
|
|
|
{
|
|
|
|
m_scene->prePaint(m_output);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneDelegate::postPaint()
|
|
|
|
{
|
|
|
|
m_scene->postPaint();
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:16:27 +00:00
|
|
|
void SceneDelegate::paint(RenderTarget *renderTarget, const QRegion ®ion)
|
2022-02-04 18:38:37 +00:00
|
|
|
{
|
2022-04-12 08:16:27 +00:00
|
|
|
m_scene->paint(renderTarget, region.translated(viewport().topLeft()));
|
2022-04-05 14:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect SceneDelegate::viewport() const
|
|
|
|
{
|
|
|
|
return m_output ? m_output->geometry() : m_scene->geometry();
|
2022-02-04 18:38:37 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//****************************************
|
|
|
|
// Scene
|
|
|
|
//****************************************
|
|
|
|
|
2015-02-23 13:41:45 +00:00
|
|
|
Scene::Scene(QObject *parent)
|
|
|
|
: QObject(parent)
|
2022-03-28 15:07:28 +00:00
|
|
|
, m_filter(this)
|
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
|
|
|
|
2021-11-09 10:36:24 +00:00
|
|
|
void Scene::initialize()
|
|
|
|
{
|
2021-11-09 11:20:39 +00:00
|
|
|
connect(workspace(), &Workspace::deletedRemoved, this, &Scene::removeToplevel);
|
|
|
|
|
2021-11-09 10:51:30 +00:00
|
|
|
connect(workspace(), &Workspace::currentActivityChanged, this, &Scene::addRepaintFull);
|
2021-11-09 10:36:24 +00:00
|
|
|
connect(workspace(), &Workspace::currentDesktopChanged, this, &Scene::addRepaintFull);
|
|
|
|
connect(workspace(), &Workspace::stackingOrderChanged, this, &Scene::addRepaintFull);
|
2021-11-24 17:18:31 +00:00
|
|
|
|
|
|
|
setGeometry(workspace()->geometry());
|
|
|
|
connect(workspace(), &Workspace::geometryChanged, this, [this]() {
|
|
|
|
setGeometry(workspace()->geometry());
|
|
|
|
});
|
2021-11-09 10:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::addRepaintFull()
|
|
|
|
{
|
2021-11-24 17:18:31 +00:00
|
|
|
addRepaint(geometry());
|
2021-11-09 10:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::addRepaint(int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
addRepaint(QRegion(x, y, width, height));
|
|
|
|
}
|
|
|
|
|
2020-11-20 09:35:38 +00:00
|
|
|
void Scene::addRepaint(const QRegion ®ion)
|
|
|
|
{
|
2022-02-04 18:38:37 +00:00
|
|
|
for (const auto &delegate : std::as_const(m_delegates)) {
|
2022-04-05 14:15:57 +00:00
|
|
|
const QRect viewport = delegate->viewport();
|
|
|
|
QRegion dirtyRegion = region & viewport;
|
|
|
|
dirtyRegion.translate(-viewport.topLeft());
|
2022-02-04 18:38:37 +00:00
|
|
|
if (!dirtyRegion.isEmpty()) {
|
2022-04-05 14:15:57 +00:00
|
|
|
delegate->layer()->addRepaint(dirtyRegion);
|
2020-11-20 09:35:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-16 17:13:57 +00:00
|
|
|
QRegion Scene::damage() const
|
|
|
|
{
|
|
|
|
return m_paintContext.damage;
|
|
|
|
}
|
|
|
|
|
2021-11-24 17:18:31 +00:00
|
|
|
QRect Scene::geometry() const
|
|
|
|
{
|
|
|
|
return m_geometry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::setGeometry(const QRect &rect)
|
|
|
|
{
|
|
|
|
if (m_geometry != rect) {
|
|
|
|
m_geometry = rect;
|
|
|
|
addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
QList<SceneDelegate *> Scene::delegates() const
|
2020-11-20 09:35:38 +00:00
|
|
|
{
|
2022-02-04 18:38:37 +00:00
|
|
|
return m_delegates;
|
2020-11-20 09:35:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
void Scene::addDelegate(SceneDelegate *delegate)
|
2020-11-20 09:35:38 +00:00
|
|
|
{
|
2022-02-04 18:38:37 +00:00
|
|
|
m_delegates.append(delegate);
|
2020-11-20 09:35:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
void Scene::removeDelegate(SceneDelegate *delegate)
|
2020-11-20 09:35:38 +00:00
|
|
|
{
|
2022-02-04 18:38:37 +00:00
|
|
|
m_delegates.removeOne(delegate);
|
2020-11-20 09:35:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 17:38:58 +00:00
|
|
|
static SurfaceItem *findTopMostSurface(SurfaceItem *item)
|
|
|
|
{
|
|
|
|
const QList<Item *> children = item->childItems();
|
|
|
|
if (children.isEmpty()) {
|
|
|
|
return item;
|
|
|
|
} else {
|
|
|
|
return findTopMostSurface(static_cast<SurfaceItem *>(children.constLast()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceItem *Scene::scanoutCandidate() const
|
|
|
|
{
|
2022-02-21 10:14:31 +00:00
|
|
|
if (!waylandServer()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-02-04 17:38:58 +00:00
|
|
|
SurfaceItem *candidate = nullptr;
|
2022-03-23 10:13:38 +00:00
|
|
|
if (!static_cast<EffectsHandlerImpl *>(effects)->blocksDirectScanout()) {
|
|
|
|
for (int i = stacking_order.count() - 1; i >= 0; i--) {
|
2022-02-04 17:38:58 +00:00
|
|
|
Window *window = stacking_order[i];
|
|
|
|
Toplevel *toplevel = window->window();
|
2022-02-21 10:14:31 +00:00
|
|
|
if (toplevel->isOnOutput(painted_screen) && window->isVisible() && toplevel->opacity() > 0) {
|
2022-03-23 10:13:38 +00:00
|
|
|
AbstractClient *c = dynamic_cast<AbstractClient *>(toplevel);
|
2022-02-21 10:14:31 +00:00
|
|
|
if (!c || !c->isFullScreen() || c->opacity() != 1.0) {
|
2022-02-04 17:38:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!window->surfaceItem()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SurfaceItem *topMost = findTopMostSurface(window->surfaceItem());
|
|
|
|
auto pixmap = topMost->pixmap();
|
|
|
|
if (!pixmap) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pixmap->update();
|
|
|
|
// the subsurface has to be able to cover the whole window
|
|
|
|
if (topMost->position() != QPoint(0, 0)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// and it has to be completely opaque
|
2022-02-21 10:14:31 +00:00
|
|
|
if (pixmap->hasAlphaChannel() && !topMost->opaque().contains(QRect(0, 0, window->width(), window->height()))) {
|
2022-02-04 17:38:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
candidate = topMost;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::prePaint(AbstractOutput *output)
|
|
|
|
{
|
|
|
|
createStackingOrder();
|
2022-02-04 18:38:37 +00:00
|
|
|
|
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11) {
|
|
|
|
painted_screen = kwinApp()->platform()->enabledOutputs().constFirst();
|
|
|
|
setRenderTargetRect(geometry());
|
|
|
|
setRenderTargetScale(1);
|
|
|
|
} else {
|
|
|
|
painted_screen = output;
|
|
|
|
setRenderTargetRect(painted_screen->geometry());
|
|
|
|
setRenderTargetScale(painted_screen->scale());
|
|
|
|
}
|
2022-02-16 17:13:57 +00:00
|
|
|
|
|
|
|
const RenderLoop *renderLoop = painted_screen->renderLoop();
|
|
|
|
const std::chrono::milliseconds presentTime =
|
2022-03-23 10:13:38 +00:00
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(renderLoop->nextPresentationTimestamp());
|
2022-02-16 17:13:57 +00:00
|
|
|
|
|
|
|
if (Q_UNLIKELY(presentTime < m_expectedPresentTimestamp)) {
|
|
|
|
qCDebug(KWIN_CORE,
|
|
|
|
"Provided presentation timestamp is invalid: %lld (current: %lld)",
|
|
|
|
static_cast<long long>(presentTime.count()),
|
|
|
|
static_cast<long long>(m_expectedPresentTimestamp.count()));
|
|
|
|
} else {
|
|
|
|
m_expectedPresentTimestamp = presentTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
// preparation step
|
|
|
|
auto effectsImpl = static_cast<EffectsHandlerImpl *>(effects);
|
|
|
|
effectsImpl->startPaint();
|
|
|
|
|
|
|
|
ScreenPrePaintData prePaintData;
|
|
|
|
prePaintData.mask = 0;
|
|
|
|
prePaintData.screen = EffectScreenImpl::get(painted_screen);
|
|
|
|
|
|
|
|
effects->prePaintScreen(prePaintData, m_expectedPresentTimestamp);
|
|
|
|
m_paintContext.damage = prePaintData.paint;
|
|
|
|
m_paintContext.mask = prePaintData.mask;
|
|
|
|
m_paintContext.phase2Data.clear();
|
|
|
|
|
|
|
|
if (m_paintContext.mask & (PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS)) {
|
|
|
|
preparePaintGenericScreen();
|
|
|
|
} else {
|
|
|
|
preparePaintSimpleScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void resetRepaintsHelper(Item *item, AbstractOutput *output)
|
|
|
|
{
|
|
|
|
item->resetRepaints(output);
|
|
|
|
|
|
|
|
const auto childItems = item->childItems();
|
|
|
|
for (Item *childItem : childItems) {
|
|
|
|
resetRepaintsHelper(childItem, output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void accumulateRepaints(Item *item, AbstractOutput *output, QRegion *repaints)
|
|
|
|
{
|
|
|
|
*repaints += item->repaints(output);
|
|
|
|
item->resetRepaints(output);
|
|
|
|
|
|
|
|
const auto childItems = item->childItems();
|
|
|
|
for (Item *childItem : childItems) {
|
|
|
|
accumulateRepaints(childItem, output, repaints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::preparePaintGenericScreen()
|
|
|
|
{
|
|
|
|
for (Window *sceneWindow : std::as_const(stacking_order)) {
|
|
|
|
resetRepaintsHelper(sceneWindow->windowItem(), painted_screen);
|
|
|
|
|
|
|
|
WindowPrePaintData data;
|
2022-02-20 18:31:22 +00:00
|
|
|
data.mask = m_paintContext.mask;
|
2022-02-16 17:13:57 +00:00
|
|
|
data.paint = infiniteRegion(); // no clipping, so doesn't really matter
|
|
|
|
|
|
|
|
sceneWindow->resetPaintingEnabled();
|
|
|
|
effects->prePaintWindow(effectWindow(sceneWindow), data, m_expectedPresentTimestamp);
|
|
|
|
if (sceneWindow->isPaintingEnabled()) {
|
|
|
|
m_paintContext.phase2Data.append(Phase2Data{
|
|
|
|
.window = sceneWindow,
|
|
|
|
.region = infiniteRegion(),
|
2022-02-23 08:28:32 +00:00
|
|
|
.opaque = data.opaque,
|
2022-02-16 17:13:57 +00:00
|
|
|
.mask = data.mask,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-05 14:15:57 +00:00
|
|
|
m_paintContext.damage = renderTargetRect();
|
2022-02-16 17:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::preparePaintSimpleScreen()
|
|
|
|
{
|
|
|
|
for (Window *sceneWindow : std::as_const(stacking_order)) {
|
|
|
|
const Toplevel *toplevel = sceneWindow->window();
|
|
|
|
WindowPrePaintData data;
|
2022-02-20 18:31:22 +00:00
|
|
|
data.mask = m_paintContext.mask;
|
2022-02-16 17:13:57 +00:00
|
|
|
accumulateRepaints(sceneWindow->windowItem(), painted_screen, &data.paint);
|
|
|
|
|
|
|
|
// Clip out the decoration for opaque windows; the decoration is drawn in the second pass.
|
2022-03-22 14:49:33 +00:00
|
|
|
if (toplevel->opacity() == 1.0) {
|
2022-02-16 17:13:57 +00:00
|
|
|
const SurfaceItem *surfaceItem = sceneWindow->surfaceItem();
|
2022-03-22 14:49:33 +00:00
|
|
|
if (Q_LIKELY(surfaceItem)) {
|
|
|
|
data.opaque = surfaceItem->mapToGlobal(surfaceItem->opaque());
|
2022-02-16 17:13:57 +00:00
|
|
|
}
|
|
|
|
|
2022-03-22 14:49:33 +00:00
|
|
|
const AbstractClient *client = dynamic_cast<const AbstractClient *>(toplevel);
|
|
|
|
if (client && !client->decorationHasAlpha()) {
|
|
|
|
data.opaque |= sceneWindow->decorationShape().translated(sceneWindow->pos());
|
|
|
|
}
|
2022-02-16 17:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sceneWindow->resetPaintingEnabled();
|
|
|
|
effects->prePaintWindow(effectWindow(sceneWindow), data, m_expectedPresentTimestamp);
|
|
|
|
if (sceneWindow->isPaintingEnabled()) {
|
|
|
|
m_paintContext.phase2Data.append(Phase2Data{
|
|
|
|
.window = sceneWindow,
|
|
|
|
.region = data.paint,
|
2022-02-23 08:28:32 +00:00
|
|
|
.opaque = data.opaque,
|
2022-02-16 17:13:57 +00:00
|
|
|
.mask = data.mask,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform an occlusion cull pass, remove surface damage occluded by opaque windows.
|
|
|
|
QRegion opaque;
|
|
|
|
for (int i = m_paintContext.phase2Data.size() - 1; i >= 0; --i) {
|
|
|
|
const auto &paintData = m_paintContext.phase2Data.at(i);
|
2022-04-05 14:15:57 +00:00
|
|
|
m_paintContext.damage += paintData.region - opaque;
|
2022-02-21 17:18:44 +00:00
|
|
|
if (!(paintData.mask & (PAINT_WINDOW_TRANSLUCENT | PAINT_WINDOW_TRANSFORMED))) {
|
2022-02-17 10:16:29 +00:00
|
|
|
opaque += paintData.opaque;
|
2022-02-16 17:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-04 17:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::postPaint()
|
|
|
|
{
|
2022-02-16 17:13:57 +00:00
|
|
|
for (Window *w : std::as_const(stacking_order)) {
|
|
|
|
effects->postPaintWindow(effectWindow(w));
|
|
|
|
}
|
|
|
|
|
|
|
|
effects->postPaintScreen();
|
|
|
|
|
2022-02-04 17:38:58 +00:00
|
|
|
if (waylandServer()) {
|
|
|
|
const std::chrono::milliseconds frameTime =
|
2022-03-23 10:13:38 +00:00
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(painted_screen->renderLoop()->lastPresentationTimestamp());
|
2022-02-04 17:38:58 +00:00
|
|
|
|
|
|
|
for (Window *window : std::as_const(m_windows)) {
|
|
|
|
Toplevel *toplevel = window->window();
|
|
|
|
if (!toplevel->isOnOutput(painted_screen)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (auto surface = toplevel->surface()) {
|
|
|
|
surface->frameRendered(frameTime.count());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clearStackingOrder();
|
|
|
|
}
|
2021-07-28 15:14:25 +00:00
|
|
|
|
2022-02-15 13:10:31 +00:00
|
|
|
static QMatrix4x4 createProjectionMatrix(const QRect &rect)
|
2021-07-28 15:14:25 +00:00
|
|
|
{
|
|
|
|
// Create a perspective projection with a 60° field-of-view,
|
|
|
|
// and an aspect ratio of 1.0.
|
|
|
|
QMatrix4x4 ret;
|
|
|
|
ret.setToIdentity();
|
2022-03-23 10:13:38 +00:00
|
|
|
const float fovY = std::tan(qDegreesToRadians(60.0f) / 2);
|
|
|
|
const float aspect = 1.0f;
|
|
|
|
const float zNear = 0.1f;
|
|
|
|
const float zFar = 100.0f;
|
2021-07-28 15:14:25 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const float yMax = zNear * fovY;
|
|
|
|
const float yMin = -yMax;
|
|
|
|
const float xMin = yMin * aspect;
|
|
|
|
const float xMax = yMax * aspect;
|
2021-07-28 15:14:25 +00:00
|
|
|
|
|
|
|
ret.frustum(xMin, xMax, yMin, yMax, zNear, zFar);
|
|
|
|
|
|
|
|
const float scaleFactor = 1.1 * fovY / yMax;
|
|
|
|
ret.translate(xMin * scaleFactor, yMax * scaleFactor, -1.1);
|
2022-03-23 10:13:38 +00:00
|
|
|
ret.scale((xMax - xMin) * scaleFactor / rect.width(),
|
|
|
|
-(yMax - yMin) * scaleFactor / rect.height(),
|
|
|
|
0.001);
|
2021-07-28 15:14:25 +00:00
|
|
|
ret.translate(-rect.x(), -rect.y());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-02-15 13:10:31 +00:00
|
|
|
QMatrix4x4 Scene::renderTargetProjectionMatrix() const
|
|
|
|
{
|
|
|
|
return m_renderTargetProjectionMatrix;
|
|
|
|
}
|
|
|
|
|
2022-02-06 12:07:48 +00:00
|
|
|
QRect Scene::renderTargetRect() const
|
|
|
|
{
|
|
|
|
return m_renderTargetRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::setRenderTargetRect(const QRect &rect)
|
|
|
|
{
|
|
|
|
m_renderTargetRect = rect;
|
2022-02-15 13:10:31 +00:00
|
|
|
m_renderTargetProjectionMatrix = createProjectionMatrix(rect);
|
2022-02-06 12:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal Scene::renderTargetScale() const
|
|
|
|
{
|
|
|
|
return m_renderTargetScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::setRenderTargetScale(qreal scale)
|
|
|
|
{
|
|
|
|
m_renderTargetScale = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion Scene::mapToRenderTarget(const QRegion ®ion) const
|
|
|
|
{
|
|
|
|
QRegion result;
|
|
|
|
for (const QRect &rect : region) {
|
|
|
|
result += QRect((rect.x() - m_renderTargetRect.x()) * m_renderTargetScale,
|
|
|
|
(rect.y() - m_renderTargetRect.y()) * m_renderTargetScale,
|
|
|
|
rect.width() * m_renderTargetScale,
|
|
|
|
rect.height() * m_renderTargetScale);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-02-16 17:13:57 +00:00
|
|
|
void Scene::paintScreen(const QRegion ®ion)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2022-02-16 17:13:57 +00:00
|
|
|
ScreenPaintData data(m_renderTargetProjectionMatrix, EffectScreenImpl::get(painted_screen));
|
|
|
|
effects->paintScreen(m_paintContext.mask, region, data);
|
2013-11-21 09:44:06 +00:00
|
|
|
|
2020-04-24 17:11:41 +00:00
|
|
|
m_paintScreenCount = 0;
|
2022-02-16 17:13:57 +00:00
|
|
|
Q_EMIT frameRendered();
|
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
|
2022-03-23 10:13:38 +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++;
|
2022-02-16 17:13:57 +00:00
|
|
|
if (mask & (PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS)) {
|
2011-01-30 14:34:42 +00:00
|
|
|
paintGenericScreen(mask, data);
|
2022-02-16 17:13:57 +00:00
|
|
|
} else {
|
2011-01-30 14:34:42 +00:00
|
|
|
paintSimpleScreen(mask, region);
|
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.
|
2022-02-16 17:13:57 +00:00
|
|
|
void Scene::paintGenericScreen(int, const ScreenPaintData &)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2022-02-16 17:13:57 +00:00
|
|
|
if (m_paintContext.mask & PAINT_SCREEN_BACKGROUND_FIRST) {
|
|
|
|
if (m_paintScreenCount == 1) {
|
2020-04-24 17:11:41 +00:00
|
|
|
paintBackground(infiniteRegion());
|
|
|
|
}
|
2022-02-16 17:13:57 +00:00
|
|
|
} else {
|
2020-04-24 17:11:41 +00:00
|
|
|
paintBackground(infiniteRegion());
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2022-02-16 17:13:57 +00:00
|
|
|
for (const Phase2Data &paintData : std::as_const(m_paintContext.phase2Data)) {
|
|
|
|
paintWindow(paintData.window, paintData.mask, paintData.region);
|
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.
|
2022-02-16 17:13:57 +00:00
|
|
|
void Scene::paintSimpleScreen(int, const QRegion ®ion)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-02-18 22:17:46 +00:00
|
|
|
// This is the occlusion culling pass
|
2022-02-16 17:13:57 +00:00
|
|
|
QRegion visible = region;
|
|
|
|
for (int i = m_paintContext.phase2Data.size() - 1; i >= 0; --i) {
|
|
|
|
Phase2Data *data = &m_paintContext.phase2Data[i];
|
2022-02-21 17:18:44 +00:00
|
|
|
data->region = visible;
|
2022-02-16 17:13:57 +00:00
|
|
|
|
2022-02-21 17:18:44 +00:00
|
|
|
if (!(data->mask & PAINT_WINDOW_TRANSFORMED)) {
|
|
|
|
const Item *item = data->window->windowItem();
|
|
|
|
data->region &= item->mapToGlobal(item->boundingRect());
|
|
|
|
|
|
|
|
if (!(data->mask & PAINT_WINDOW_TRANSLUCENT)) {
|
|
|
|
visible -= data->opaque;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-07-06 08:01:23 +00:00
|
|
|
|
2022-02-16 17:13:57 +00:00
|
|
|
paintBackground(visible);
|
2020-04-24 17:11:41 +00:00
|
|
|
|
2022-02-16 17:13:57 +00:00
|
|
|
for (const Phase2Data &paintData : std::as_const(m_paintContext.phase2Data)) {
|
|
|
|
paintWindow(paintData.window, paintData.mask, paintData.region);
|
2013-11-21 09:44:06 +00:00
|
|
|
}
|
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);
|
2022-03-23 10:13:38 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-02-04 17:38:58 +00:00
|
|
|
void Scene::createStackingOrder()
|
2013-06-24 07:53:11 +00:00
|
|
|
{
|
2022-02-04 17:38:58 +00:00
|
|
|
// Create a list of all windows in the stacking order
|
|
|
|
QList<Toplevel *> windows = Workspace::self()->xStackingOrder();
|
|
|
|
|
|
|
|
// Move elevated windows to the top of the stacking order
|
|
|
|
const QList<EffectWindow *> elevatedList = static_cast<EffectsHandlerImpl *>(effects)->elevatedWindows();
|
|
|
|
for (EffectWindow *c : elevatedList) {
|
|
|
|
Toplevel *t = static_cast<EffectWindowImpl *>(c)->window();
|
|
|
|
windows.removeAll(t);
|
|
|
|
windows.append(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip windows that are not yet ready for being painted and if screen is locked skip windows
|
|
|
|
// that are neither lockscreen nor inputmethod windows.
|
|
|
|
//
|
|
|
|
// TODO? This cannot be used so carelessly - needs protections against broken clients, the
|
|
|
|
// window should not get focus before it's displayed, handle unredirected windows properly and
|
|
|
|
// so on.
|
|
|
|
for (Toplevel *win : windows) {
|
|
|
|
if (!win->readyForPainting()) {
|
|
|
|
windows.removeAll(win);
|
|
|
|
}
|
2022-03-28 15:07:28 +00:00
|
|
|
if (!m_filter.filterAcceptsWindow(win)) {
|
|
|
|
windows.removeAll(win);
|
2022-02-04 17:38:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 07:53:11 +00:00
|
|
|
// TODO: cache the stacking_order in case it has not changed
|
2022-02-04 17:38:58 +00:00
|
|
|
for (Toplevel *c : std::as_const(windows)) {
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(m_windows.contains(c));
|
2022-03-23 10:13:38 +00:00
|
|
|
stacking_order.append(m_windows[c]);
|
2013-06-24 07:53:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::clearStackingOrder()
|
|
|
|
{
|
|
|
|
stacking_order.clear();
|
|
|
|
}
|
|
|
|
|
2022-02-21 11:45:46 +00:00
|
|
|
void Scene::paintWindow(Window *w, int mask, const QRegion ®ion)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2022-03-25 12:20:32 +00:00
|
|
|
if (region.isEmpty()) { // completely clipped
|
2007-12-07 17:03:59 +00:00
|
|
|
return;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2007-12-07 17:03:59 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
static_cast<EffectsHandlerImpl *>(effects)->paintDesktop(desktop, mask, region, data);
|
2012-03-29 18:17:57 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// the function that'll be eventually called by paintWindow() above
|
2022-03-23 10:13:38 +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()
|
2022-03-23 10:13:38 +00:00
|
|
|
void Scene::finalDrawWindow(EffectWindowImpl *w, int mask, const QRegion ®ion, WindowPaintData &data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2022-03-28 15:07:28 +00:00
|
|
|
if (!m_filter.filterAcceptsWindow(w->window())) {
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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-11-16 07:38:51 +00:00
|
|
|
} else if (auto internalClient = qobject_cast<InternalClient *>(client)) {
|
|
|
|
m_windowItem.reset(new WindowItemInternal(internalClient));
|
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
|
|
|
{
|
2022-03-25 12:20:32 +00:00
|
|
|
if (toplevel->isDeleted()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
|
|
|
if (!toplevel->isOnCurrentDesktop()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
|
|
|
if (!toplevel->isOnCurrentActivity()) {
|
2010-05-15 20:18:57 +00:00
|
|
|
return false;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
|
|
|
if (AbstractClient *c = dynamic_cast<AbstractClient *>(toplevel)) {
|
2021-11-23 12:13:56 +00:00
|
|
|
return c->isShown();
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
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::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;
|
2022-03-25 12:20:32 +00:00
|
|
|
if (toplevel->isDeleted()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
disable_painting |= PAINT_DISABLED_BY_DELETE;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
if (static_cast<EffectsHandlerImpl *>(effects)->isDesktopRendering()) {
|
|
|
|
if (!toplevel->isOnDesktop(static_cast<EffectsHandlerImpl *>(effects)->currentRenderedDesktop())) {
|
2012-03-29 18:12:34 +00:00
|
|
|
disable_painting |= PAINT_DISABLED_BY_DESKTOP;
|
|
|
|
}
|
|
|
|
} else {
|
2022-03-25 12:20:32 +00:00
|
|
|
if (!toplevel->isOnCurrentDesktop()) {
|
2012-03-29 18:12:34 +00:00
|
|
|
disable_painting |= PAINT_DISABLED_BY_DESKTOP;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2012-03-29 18:12:34 +00:00
|
|
|
}
|
2022-03-25 12:20:32 +00:00
|
|
|
if (!toplevel->isOnCurrentActivity()) {
|
2010-05-15 20:18:57 +00:00
|
|
|
disable_painting |= PAINT_DISABLED_BY_ACTIVITY;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
if (AbstractClient *c = dynamic_cast<AbstractClient *>(toplevel)) {
|
2022-03-25 12:20:32 +00:00
|
|
|
if (c->isMinimized()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
disable_painting |= PAINT_DISABLED_BY_MINIMIZE;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
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
|
|
|
|
//****************************************
|
2022-03-23 10:13:38 +00:00
|
|
|
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
|
|
|
|
2022-03-28 15:07:28 +00:00
|
|
|
//****************************************
|
|
|
|
// ScreenLockerFilter
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
ScreenLockerFilter::ScreenLockerFilter(Scene *s)
|
|
|
|
{
|
|
|
|
QObject::connect(waylandServer(), &WaylandServer::lockStateChanged, s, &Scene::addRepaintFull);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScreenLockerFilter::~ScreenLockerFilter() = default;
|
|
|
|
|
|
|
|
bool ScreenLockerFilter::filterAcceptsWindow(KWin::Toplevel *w) const
|
|
|
|
{
|
2022-04-14 06:29:38 +00:00
|
|
|
return !waylandServer() || !waylandServer()->isScreenLocked() || (w->isLockScreen() || w->isInputMethod());
|
2022-03-28 15:07:28 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|