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>
|
|
|
|
SPDX-FileCopyrightText: 2009, 2010, 2011 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
Based on glcompmgr code by Felix Bellaby.
|
|
|
|
Using code from Compiz and Beryl.
|
2007-11-27 19:40:25 +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
|
|
|
#include "scene_opengl.h"
|
2021-10-20 14:58:58 +00:00
|
|
|
#include "openglsurfacetexture.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-02-19 08:58:44 +00:00
|
|
|
#include <kwinglplatform.h>
|
2021-11-19 09:19:59 +00:00
|
|
|
#include <kwinoffscreenquickview.h>
|
2010-11-14 19:49:00 +00:00
|
|
|
|
2012-10-05 16:00:49 +00:00
|
|
|
#include "composite.h"
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "decorations/decoratedclient.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "effects.h"
|
2013-06-25 07:53:45 +00:00
|
|
|
#include "main.h"
|
2021-02-04 09:07:20 +00:00
|
|
|
#include "shadowitem.h"
|
|
|
|
#include "surfaceitem.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "utils/common.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2021-04-26 16:38:40 +00:00
|
|
|
#include "windowitem.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-08-05 13:12:08 +00:00
|
|
|
#include <cmath>
|
2019-07-09 19:19:26 +00:00
|
|
|
#include <cstddef>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <QMatrix4x4>
|
2019-07-09 19:19:26 +00:00
|
|
|
#include <QPainter>
|
2012-10-16 20:41:21 +00:00
|
|
|
#include <QStringList>
|
2010-11-14 19:49:00 +00:00
|
|
|
#include <QVector2D>
|
|
|
|
#include <QVector4D>
|
2021-06-08 20:25:40 +00:00
|
|
|
#include <QtMath>
|
2012-10-16 20:41:21 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2012-08-26 15:14:23 +00:00
|
|
|
/************************************************
|
|
|
|
* SceneOpenGL
|
|
|
|
***********************************************/
|
|
|
|
|
2022-06-22 10:33:32 +00:00
|
|
|
SceneOpenGL::SceneOpenGL(OpenGLBackend *backend)
|
|
|
|
: m_backend(backend)
|
2012-08-26 15:14:23 +00:00
|
|
|
{
|
2021-11-03 15:34:51 +00:00
|
|
|
// We only support the OpenGL 2+ shader API, not GL_ARB_shader_objects
|
|
|
|
if (!hasGLVersion(2, 0)) {
|
|
|
|
qCDebug(KWIN_OPENGL) << "OpenGL 2.0 is not supported";
|
|
|
|
init_ok = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is not legal to not have a vertex array object bound in a core context
|
|
|
|
if (!GLPlatform::instance()->isGLES() && hasGLExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) {
|
|
|
|
glGenVertexArrays(1, &vao);
|
|
|
|
glBindVertexArray(vao);
|
|
|
|
}
|
2012-08-26 15:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SceneOpenGL::~SceneOpenGL()
|
|
|
|
{
|
2019-04-22 07:34:49 +00:00
|
|
|
if (init_ok) {
|
|
|
|
makeOpenGLContextCurrent();
|
2012-09-06 15:13:22 +00:00
|
|
|
}
|
2012-08-26 15:14:23 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 10:33:32 +00:00
|
|
|
std::unique_ptr<SceneOpenGL> SceneOpenGL::createScene(OpenGLBackend *backend)
|
2012-09-06 15:13:22 +00:00
|
|
|
{
|
2021-11-08 10:08:06 +00:00
|
|
|
if (SceneOpenGL::supported(backend)) {
|
2022-06-22 10:33:32 +00:00
|
|
|
return std::make_unique<SceneOpenGL>(backend);
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
2012-09-06 15:13:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-30 14:22:09 +00:00
|
|
|
bool SceneOpenGL::initFailed() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-05-30 14:22:09 +00:00
|
|
|
return !init_ok;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-05-30 14:22:09 +00:00
|
|
|
|
2022-04-12 08:16:27 +00:00
|
|
|
void SceneOpenGL::paint(RenderTarget *renderTarget, const QRegion ®ion)
|
2021-02-04 09:07:20 +00:00
|
|
|
{
|
2022-04-12 08:16:27 +00:00
|
|
|
Q_UNUSED(renderTarget)
|
2022-02-04 17:38:58 +00:00
|
|
|
GLVertexBuffer::streamingBuffer()->beginFrame();
|
2022-02-16 17:13:57 +00:00
|
|
|
paintScreen(region);
|
2022-02-04 17:38:58 +00:00
|
|
|
GLVertexBuffer::streamingBuffer()->endOfFrame();
|
2012-08-26 15:14:23 +00:00
|
|
|
}
|
|
|
|
|
2020-03-13 16:41:56 +00:00
|
|
|
void SceneOpenGL::paintBackground(const QRegion ®ion)
|
2011-01-02 08:46:30 +00:00
|
|
|
{
|
2021-06-10 13:46:28 +00:00
|
|
|
if (region == infiniteRegion()) {
|
2022-03-24 13:55:14 +00:00
|
|
|
glClearColor(0, 0, 0, 0);
|
2011-01-02 08:46:30 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2021-06-10 13:46:28 +00:00
|
|
|
} else if (!region.isEmpty()) {
|
|
|
|
QVector<float> verts;
|
|
|
|
verts.reserve(region.rectCount() * 6 * 2);
|
|
|
|
|
2022-07-15 13:36:16 +00:00
|
|
|
const auto scale = renderTargetScale();
|
|
|
|
|
2021-06-10 13:46:28 +00:00
|
|
|
for (const QRect &r : region) {
|
2022-07-15 13:36:16 +00:00
|
|
|
verts << (r.x() + r.width()) * scale << r.y() * scale;
|
|
|
|
verts << r.x() * scale << r.y() * scale;
|
|
|
|
verts << r.x() * scale << (r.y() + r.height()) * scale;
|
|
|
|
verts << r.x() * scale << (r.y() + r.height()) * scale;
|
|
|
|
verts << (r.x() + r.width()) * scale << (r.y() + r.height()) * scale;
|
|
|
|
verts << (r.x() + r.width()) * scale << r.y() * scale;
|
2021-06-10 13:46:28 +00:00
|
|
|
}
|
|
|
|
doPaintBackground(verts);
|
2011-01-02 08:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-19 09:19:59 +00:00
|
|
|
void SceneOpenGL::paintOffscreenQuickView(OffscreenQuickView *w)
|
[libkwineffects] Introduce API to easily show a QtQuick scene in an effect
Summary:
EffectQuickView/Scene is a convenient class to render a QtQuick
scenegraph into an effect.
Current methods (such as present windows) involve creating an underlying
platform window which is expensive, causes a headache to filter out
again in the rest of the code, and only works as an overlay.
The new class exposes things more natively to an effect where we don't
mess with real windows, we can perform the painting anywhere in the view
and we don't have issues with hiding/closing.
QtQuick has both software and hardware accelerated modes, and kwin also
has 3 render backends. Every combination is supported.
* When used in OpenGL mode for both, we render into an FBO export the
texture ID then it's up to the effect to render that into a scene.
* When using software QtQuick rendering we blit into an image, upload
that into a KWinGLTexture which serves as an abstraction layer and
render that into the scene.
* When using GL for QtQuick and XRender/QPainter in kwin everything is
rendered into the internal FBO, blit and exported as an image.
* When using software rendering for both an image gets passed directly.
Mouse and keyboard events can be forwarded, only if the effect
intercepts them.
The class is meant to be generic enough that we can remove all the
QtQuick code from Aurorae.
The intention is also to replace EffectFrameImpl using this backend and
we can kill all of the EffectFrame code throughout the scenes.
The close button in present windows will also be ported to this,
simplifiying that code base.
Classes that handle the rendering and handling QML are intentionally
split so that in the future we can have a declarative effects API create
overlays from within the same context. Similar to how one can
instantiate windows from a typical QML scene.
Notes:
I don't like how I pass the kwin GL context from the backends into the
effect, but I need something that works with the library separation. It
also currently has wayland problem if I create a QOpenGLContext before
the QPA is set up with a scene - but I don't have anything better?
I know for the EffectFrame we need an API to push things through the
effects stack to handle blur/invert etc. Will deal with that when we
port the EffectFrame.
Test Plan: Used in an effect
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24215
2019-09-27 15:06:37 +00:00
|
|
|
{
|
|
|
|
GLTexture *t = w->bufferAsTexture();
|
|
|
|
if (!t) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-16 12:04:23 +00:00
|
|
|
ShaderTraits traits = ShaderTrait::MapTexture;
|
|
|
|
const qreal a = w->opacity();
|
|
|
|
if (a != 1.0) {
|
|
|
|
traits |= ShaderTrait::Modulate;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLShader *shader = ShaderManager::instance()->pushShader(traits);
|
2022-08-04 12:11:53 +00:00
|
|
|
const QRectF rect = scaledRect(w->geometry(), renderTargetScale());
|
2022-02-16 12:04:23 +00:00
|
|
|
|
2022-02-15 13:10:31 +00:00
|
|
|
QMatrix4x4 mvp(renderTargetProjectionMatrix());
|
[libkwineffects] Introduce API to easily show a QtQuick scene in an effect
Summary:
EffectQuickView/Scene is a convenient class to render a QtQuick
scenegraph into an effect.
Current methods (such as present windows) involve creating an underlying
platform window which is expensive, causes a headache to filter out
again in the rest of the code, and only works as an overlay.
The new class exposes things more natively to an effect where we don't
mess with real windows, we can perform the painting anywhere in the view
and we don't have issues with hiding/closing.
QtQuick has both software and hardware accelerated modes, and kwin also
has 3 render backends. Every combination is supported.
* When used in OpenGL mode for both, we render into an FBO export the
texture ID then it's up to the effect to render that into a scene.
* When using software QtQuick rendering we blit into an image, upload
that into a KWinGLTexture which serves as an abstraction layer and
render that into the scene.
* When using GL for QtQuick and XRender/QPainter in kwin everything is
rendered into the internal FBO, blit and exported as an image.
* When using software rendering for both an image gets passed directly.
Mouse and keyboard events can be forwarded, only if the effect
intercepts them.
The class is meant to be generic enough that we can remove all the
QtQuick code from Aurorae.
The intention is also to replace EffectFrameImpl using this backend and
we can kill all of the EffectFrame code throughout the scenes.
The close button in present windows will also be ported to this,
simplifiying that code base.
Classes that handle the rendering and handling QML are intentionally
split so that in the future we can have a declarative effects API create
overlays from within the same context. Similar to how one can
instantiate windows from a typical QML scene.
Notes:
I don't like how I pass the kwin GL context from the backends into the
effect, but I need something that works with the library separation. It
also currently has wayland problem if I create a QOpenGLContext before
the QPA is set up with a scene - but I don't have anything better?
I know for the EffectFrame we need an API to push things through the
effects stack to handle blur/invert etc. Will deal with that when we
port the EffectFrame.
Test Plan: Used in an effect
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24215
2019-09-27 15:06:37 +00:00
|
|
|
mvp.translate(rect.x(), rect.y());
|
|
|
|
shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
|
|
|
|
2022-02-16 12:04:23 +00:00
|
|
|
if (a != 1.0) {
|
|
|
|
shader->setUniform(GLShader::ModulationConstant, QVector4D(a, a, a, a));
|
|
|
|
}
|
|
|
|
|
[libkwineffects] Introduce API to easily show a QtQuick scene in an effect
Summary:
EffectQuickView/Scene is a convenient class to render a QtQuick
scenegraph into an effect.
Current methods (such as present windows) involve creating an underlying
platform window which is expensive, causes a headache to filter out
again in the rest of the code, and only works as an overlay.
The new class exposes things more natively to an effect where we don't
mess with real windows, we can perform the painting anywhere in the view
and we don't have issues with hiding/closing.
QtQuick has both software and hardware accelerated modes, and kwin also
has 3 render backends. Every combination is supported.
* When used in OpenGL mode for both, we render into an FBO export the
texture ID then it's up to the effect to render that into a scene.
* When using software QtQuick rendering we blit into an image, upload
that into a KWinGLTexture which serves as an abstraction layer and
render that into the scene.
* When using GL for QtQuick and XRender/QPainter in kwin everything is
rendered into the internal FBO, blit and exported as an image.
* When using software rendering for both an image gets passed directly.
Mouse and keyboard events can be forwarded, only if the effect
intercepts them.
The class is meant to be generic enough that we can remove all the
QtQuick code from Aurorae.
The intention is also to replace EffectFrameImpl using this backend and
we can kill all of the EffectFrame code throughout the scenes.
The close button in present windows will also be ported to this,
simplifiying that code base.
Classes that handle the rendering and handling QML are intentionally
split so that in the future we can have a declarative effects API create
overlays from within the same context. Similar to how one can
instantiate windows from a typical QML scene.
Notes:
I don't like how I pass the kwin GL context from the backends into the
effect, but I need something that works with the library separation. It
also currently has wayland problem if I create a QOpenGLContext before
the QPA is set up with a scene - but I don't have anything better?
I know for the EffectFrame we need an API to push things through the
effects stack to handle blur/invert etc. Will deal with that when we
port the EffectFrame.
Test Plan: Used in an effect
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24215
2019-09-27 15:06:37 +00:00
|
|
|
glEnable(GL_BLEND);
|
2019-10-02 19:51:47 +00:00
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
[libkwineffects] Introduce API to easily show a QtQuick scene in an effect
Summary:
EffectQuickView/Scene is a convenient class to render a QtQuick
scenegraph into an effect.
Current methods (such as present windows) involve creating an underlying
platform window which is expensive, causes a headache to filter out
again in the rest of the code, and only works as an overlay.
The new class exposes things more natively to an effect where we don't
mess with real windows, we can perform the painting anywhere in the view
and we don't have issues with hiding/closing.
QtQuick has both software and hardware accelerated modes, and kwin also
has 3 render backends. Every combination is supported.
* When used in OpenGL mode for both, we render into an FBO export the
texture ID then it's up to the effect to render that into a scene.
* When using software QtQuick rendering we blit into an image, upload
that into a KWinGLTexture which serves as an abstraction layer and
render that into the scene.
* When using GL for QtQuick and XRender/QPainter in kwin everything is
rendered into the internal FBO, blit and exported as an image.
* When using software rendering for both an image gets passed directly.
Mouse and keyboard events can be forwarded, only if the effect
intercepts them.
The class is meant to be generic enough that we can remove all the
QtQuick code from Aurorae.
The intention is also to replace EffectFrameImpl using this backend and
we can kill all of the EffectFrame code throughout the scenes.
The close button in present windows will also be ported to this,
simplifiying that code base.
Classes that handle the rendering and handling QML are intentionally
split so that in the future we can have a declarative effects API create
overlays from within the same context. Similar to how one can
instantiate windows from a typical QML scene.
Notes:
I don't like how I pass the kwin GL context from the backends into the
effect, but I need something that works with the library separation. It
also currently has wayland problem if I create a QOpenGLContext before
the QPA is set up with a scene - but I don't have anything better?
I know for the EffectFrame we need an API to push things through the
effects stack to handle blur/invert etc. Will deal with that when we
port the EffectFrame.
Test Plan: Used in an effect
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24215
2019-09-27 15:06:37 +00:00
|
|
|
t->bind();
|
2022-08-04 13:26:23 +00:00
|
|
|
t->render(w->geometry(), renderTargetScale());
|
[libkwineffects] Introduce API to easily show a QtQuick scene in an effect
Summary:
EffectQuickView/Scene is a convenient class to render a QtQuick
scenegraph into an effect.
Current methods (such as present windows) involve creating an underlying
platform window which is expensive, causes a headache to filter out
again in the rest of the code, and only works as an overlay.
The new class exposes things more natively to an effect where we don't
mess with real windows, we can perform the painting anywhere in the view
and we don't have issues with hiding/closing.
QtQuick has both software and hardware accelerated modes, and kwin also
has 3 render backends. Every combination is supported.
* When used in OpenGL mode for both, we render into an FBO export the
texture ID then it's up to the effect to render that into a scene.
* When using software QtQuick rendering we blit into an image, upload
that into a KWinGLTexture which serves as an abstraction layer and
render that into the scene.
* When using GL for QtQuick and XRender/QPainter in kwin everything is
rendered into the internal FBO, blit and exported as an image.
* When using software rendering for both an image gets passed directly.
Mouse and keyboard events can be forwarded, only if the effect
intercepts them.
The class is meant to be generic enough that we can remove all the
QtQuick code from Aurorae.
The intention is also to replace EffectFrameImpl using this backend and
we can kill all of the EffectFrame code throughout the scenes.
The close button in present windows will also be ported to this,
simplifiying that code base.
Classes that handle the rendering and handling QML are intentionally
split so that in the future we can have a declarative effects API create
overlays from within the same context. Similar to how one can
instantiate windows from a typical QML scene.
Notes:
I don't like how I pass the kwin GL context from the backends into the
effect, but I need something that works with the library separation. It
also currently has wayland problem if I create a QOpenGLContext before
the QPA is set up with a scene - but I don't have anything better?
I know for the EffectFrame we need an API to push things through the
effects stack to handle blur/invert etc. Will deal with that when we
port the EffectFrame.
Test Plan: Used in an effect
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24215
2019-09-27 15:06:37 +00:00
|
|
|
t->unbind();
|
|
|
|
glDisable(GL_BLEND);
|
2019-10-02 19:31:38 +00:00
|
|
|
|
|
|
|
ShaderManager::instance()->popShader();
|
[libkwineffects] Introduce API to easily show a QtQuick scene in an effect
Summary:
EffectQuickView/Scene is a convenient class to render a QtQuick
scenegraph into an effect.
Current methods (such as present windows) involve creating an underlying
platform window which is expensive, causes a headache to filter out
again in the rest of the code, and only works as an overlay.
The new class exposes things more natively to an effect where we don't
mess with real windows, we can perform the painting anywhere in the view
and we don't have issues with hiding/closing.
QtQuick has both software and hardware accelerated modes, and kwin also
has 3 render backends. Every combination is supported.
* When used in OpenGL mode for both, we render into an FBO export the
texture ID then it's up to the effect to render that into a scene.
* When using software QtQuick rendering we blit into an image, upload
that into a KWinGLTexture which serves as an abstraction layer and
render that into the scene.
* When using GL for QtQuick and XRender/QPainter in kwin everything is
rendered into the internal FBO, blit and exported as an image.
* When using software rendering for both an image gets passed directly.
Mouse and keyboard events can be forwarded, only if the effect
intercepts them.
The class is meant to be generic enough that we can remove all the
QtQuick code from Aurorae.
The intention is also to replace EffectFrameImpl using this backend and
we can kill all of the EffectFrame code throughout the scenes.
The close button in present windows will also be ported to this,
simplifiying that code base.
Classes that handle the rendering and handling QML are intentionally
split so that in the future we can have a declarative effects API create
overlays from within the same context. Similar to how one can
instantiate windows from a typical QML scene.
Notes:
I don't like how I pass the kwin GL context from the backends into the
effect, but I need something that works with the library separation. It
also currently has wayland problem if I create a QOpenGLContext before
the QPA is set up with a scene - but I don't have anything better?
I know for the EffectFrame we need an API to push things through the
effects stack to handle blur/invert etc. Will deal with that when we
port the EffectFrame.
Test Plan: Used in an effect
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24215
2019-09-27 15:06:37 +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 SceneOpenGL::makeOpenGLContextCurrent()
|
|
|
|
{
|
|
|
|
return m_backend->makeCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneOpenGL::doneOpenGLContextCurrent()
|
|
|
|
{
|
|
|
|
m_backend->doneCurrent();
|
|
|
|
}
|
|
|
|
|
2020-10-15 09:27:00 +00:00
|
|
|
bool SceneOpenGL::supportsNativeFence() const
|
|
|
|
{
|
|
|
|
return m_backend->supportsNativeFence();
|
|
|
|
}
|
|
|
|
|
2022-04-28 07:44:11 +00:00
|
|
|
Shadow *SceneOpenGL::createShadow(Window *window)
|
2013-06-24 07:06:50 +00:00
|
|
|
{
|
2022-04-28 07:44:11 +00:00
|
|
|
return new SceneOpenGLShadow(window);
|
2013-06-24 07:06:50 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 16:38:40 +00:00
|
|
|
DecorationRenderer *SceneOpenGL::createDecorationRenderer(Decoration::DecoratedClientImpl *impl)
|
2014-07-22 11:11:19 +00:00
|
|
|
{
|
|
|
|
return new SceneOpenGLDecorationRenderer(impl);
|
|
|
|
}
|
|
|
|
|
2016-08-10 07:24:53 +00:00
|
|
|
bool SceneOpenGL::animationsSupported() const
|
|
|
|
{
|
|
|
|
return !GLPlatform::instance()->isSoftwareEmulation();
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:49:52 +00:00
|
|
|
QVector<QByteArray> SceneOpenGL::openGLPlatformInterfaceExtensions() const
|
|
|
|
{
|
|
|
|
return m_backend->extensions().toVector();
|
|
|
|
}
|
|
|
|
|
2022-05-17 10:36:34 +00:00
|
|
|
std::shared_ptr<GLTexture> SceneOpenGL::textureForOutput(Output *output) const
|
2020-07-22 17:22:36 +00:00
|
|
|
{
|
|
|
|
return m_backend->textureForOutput(output);
|
|
|
|
}
|
|
|
|
|
2022-06-29 11:21:35 +00:00
|
|
|
std::unique_ptr<SurfaceTexture> SceneOpenGL::createSurfaceTextureInternal(SurfacePixmapInternal *pixmap)
|
2021-04-09 07:06:04 +00:00
|
|
|
{
|
2021-10-20 14:58:58 +00:00
|
|
|
return m_backend->createSurfaceTextureInternal(pixmap);
|
2021-04-09 07:06:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 11:21:35 +00:00
|
|
|
std::unique_ptr<SurfaceTexture> SceneOpenGL::createSurfaceTextureWayland(SurfacePixmapWayland *pixmap)
|
2021-04-09 07:06:04 +00:00
|
|
|
{
|
2021-10-20 14:58:58 +00:00
|
|
|
return m_backend->createSurfaceTextureWayland(pixmap);
|
2021-04-09 07:06:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 11:21:35 +00:00
|
|
|
std::unique_ptr<SurfaceTexture> SceneOpenGL::createSurfaceTextureX11(SurfacePixmapX11 *pixmap)
|
2021-04-09 07:06:04 +00:00
|
|
|
{
|
2021-10-20 14:58:58 +00:00
|
|
|
return m_backend->createSurfaceTextureX11(pixmap);
|
2021-04-09 07:06:04 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 15:34:51 +00:00
|
|
|
bool SceneOpenGL::supported(OpenGLBackend *backend)
|
2012-09-06 15:13:22 +00:00
|
|
|
{
|
2012-10-05 16:00:49 +00:00
|
|
|
const QByteArray forceEnv = qgetenv("KWIN_COMPOSE");
|
|
|
|
if (!forceEnv.isEmpty()) {
|
2015-11-02 12:54:53 +00:00
|
|
|
if (qstrcmp(forceEnv, "O2") == 0 || qstrcmp(forceEnv, "O2ES") == 0) {
|
2017-09-08 20:30:18 +00:00
|
|
|
qCDebug(KWIN_OPENGL) << "OpenGL 2 compositing enforced by environment variable";
|
2012-10-05 16:00:49 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// OpenGL 2 disabled by environment variable
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-09-06 15:13:22 +00:00
|
|
|
if (!backend->isDirectRendering()) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-09 12:10:25 +00:00
|
|
|
if (GLPlatform::instance()->recommendedCompositor() < OpenGLCompositing) {
|
|
|
|
qCDebug(KWIN_OPENGL) << "Driver does not recommend OpenGL compositing";
|
2012-09-06 15:13:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
void SceneOpenGL::doPaintBackground(const QVector<float> &vertices)
|
2012-09-06 15:13:22 +00:00
|
|
|
{
|
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
|
|
|
vbo->reset();
|
2022-03-24 13:55:14 +00:00
|
|
|
vbo->setColor(QColor(0, 0, 0, 0));
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
vbo->setData(vertices.count() / 2, 2, vertices.data(), nullptr);
|
2012-09-06 15:13:22 +00:00
|
|
|
|
2015-11-26 08:37:23 +00:00
|
|
|
ShaderBinder binder(ShaderTrait::UniformColor);
|
2022-02-15 13:10:31 +00:00
|
|
|
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, renderTargetProjectionMatrix());
|
2012-09-06 15:13:22 +00:00
|
|
|
|
|
|
|
vbo->render(GL_TRIANGLES);
|
|
|
|
}
|
|
|
|
|
2022-05-07 08:42:41 +00:00
|
|
|
QVector4D SceneOpenGL::modulate(float opacity, float brightness) const
|
2012-09-06 10:25:55 +00:00
|
|
|
{
|
2013-03-17 12:34:26 +00:00
|
|
|
const float a = opacity;
|
|
|
|
const float rgb = opacity * brightness;
|
|
|
|
|
|
|
|
return QVector4D(rgb, rgb, rgb, a);
|
|
|
|
}
|
|
|
|
|
2022-05-07 08:42:41 +00:00
|
|
|
void SceneOpenGL::setBlendEnabled(bool enabled)
|
2013-03-17 12:34:26 +00:00
|
|
|
{
|
2022-03-25 12:20:32 +00:00
|
|
|
if (enabled && !m_blendingEnabled) {
|
2013-03-17 12:34:26 +00:00
|
|
|
glEnable(GL_BLEND);
|
2022-03-25 12:20:32 +00:00
|
|
|
} else if (!enabled && m_blendingEnabled) {
|
2013-03-17 12:34:26 +00:00
|
|
|
glDisable(GL_BLEND);
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2013-03-17 12:34:26 +00:00
|
|
|
|
|
|
|
m_blendingEnabled = enabled;
|
|
|
|
}
|
|
|
|
|
2021-05-21 10:51:23 +00:00
|
|
|
static GLTexture *bindSurfaceTexture(SurfaceItem *surfaceItem)
|
2013-03-18 15:45:53 +00:00
|
|
|
{
|
2021-04-09 07:06:04 +00:00
|
|
|
SurfacePixmap *surfacePixmap = surfaceItem->pixmap();
|
|
|
|
auto platformSurfaceTexture =
|
2022-03-23 10:13:38 +00:00
|
|
|
static_cast<OpenGLSurfaceTexture *>(surfacePixmap->texture());
|
2021-04-09 07:06:04 +00:00
|
|
|
if (surfacePixmap->isDiscarded()) {
|
|
|
|
return platformSurfaceTexture->texture();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (platformSurfaceTexture->texture()) {
|
|
|
|
const QRegion region = surfaceItem->damage();
|
|
|
|
if (!region.isEmpty()) {
|
|
|
|
platformSurfaceTexture->update(region);
|
2021-05-20 11:58:30 +00:00
|
|
|
surfaceItem->resetDamage();
|
2021-04-09 07:06:04 +00:00
|
|
|
}
|
2021-05-21 10:51:23 +00:00
|
|
|
} else {
|
|
|
|
if (!surfacePixmap->isValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!platformSurfaceTexture->create()) {
|
|
|
|
qCDebug(KWIN_OPENGL) << "Failed to bind window";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
surfaceItem->resetDamage();
|
2021-02-04 09:07:20 +00:00
|
|
|
}
|
2021-04-09 07:06:04 +00:00
|
|
|
|
2021-05-21 10:51:23 +00:00
|
|
|
return platformSurfaceTexture->texture();
|
2021-02-04 09:07:20 +00:00
|
|
|
}
|
2020-04-21 10:22:41 +00:00
|
|
|
|
2022-05-07 08:42:41 +00:00
|
|
|
static WindowQuadList clipQuads(const Item *item, const SceneOpenGL::RenderContext *context)
|
2021-06-10 10:32:37 +00:00
|
|
|
{
|
|
|
|
const WindowQuadList quads = item->quads();
|
|
|
|
if (context->clip != infiniteRegion() && !context->hardwareClipping) {
|
2022-07-15 13:36:16 +00:00
|
|
|
// transformStack contains translations in device pixels, but clipping
|
|
|
|
// here happens on WindowQuad which is in logical pixels. So convert
|
|
|
|
// this position back to logical pixels as WindowQuad is only converted
|
|
|
|
// to device pixels when the final conversion to GPU geometry happens.
|
|
|
|
const QPointF offset = context->transformStack.top().map(QPointF(0., 0.)) / context->renderTargetScale;
|
|
|
|
|
2021-06-10 10:32:37 +00:00
|
|
|
WindowQuadList ret;
|
|
|
|
ret.reserve(quads.count());
|
|
|
|
|
|
|
|
// split all quads in bounding rect with the actual rects in the region
|
|
|
|
for (const WindowQuad &quad : qAsConst(quads)) {
|
|
|
|
for (const QRect &r : qAsConst(context->clip)) {
|
2022-09-14 14:21:33 +00:00
|
|
|
const QRectF rf(QRectF(r).translated(-offset));
|
2021-06-10 10:32:37 +00:00
|
|
|
const QRectF quadRect(QPointF(quad.left(), quad.top()), QPointF(quad.right(), quad.bottom()));
|
|
|
|
const QRectF &intersected = rf.intersected(quadRect);
|
|
|
|
if (intersected.isValid()) {
|
|
|
|
if (quadRect == intersected) {
|
|
|
|
// case 1: completely contains, include and do not check other rects
|
|
|
|
ret << quad;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// case 2: intersection
|
|
|
|
ret << quad.makeSubQuad(intersected.left(), intersected.top(), intersected.right(), intersected.bottom());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return quads;
|
|
|
|
}
|
|
|
|
|
2022-05-07 08:42:41 +00:00
|
|
|
void SceneOpenGL::createRenderNode(Item *item, RenderContext *context)
|
2021-02-04 09:07:20 +00:00
|
|
|
{
|
2021-06-19 14:00:19 +00:00
|
|
|
const QList<Item *> sortedChildItems = item->sortedChildItems();
|
|
|
|
|
2021-08-11 15:03:06 +00:00
|
|
|
QMatrix4x4 matrix;
|
2022-07-15 13:36:16 +00:00
|
|
|
const auto logicalPosition = QVector2D(item->position().x(), item->position().y());
|
|
|
|
const auto scale = context->renderTargetScale;
|
|
|
|
matrix.translate(logicalPosition * scale);
|
2021-08-11 15:03:06 +00:00
|
|
|
matrix *= item->transform();
|
2022-05-05 15:48:36 +00:00
|
|
|
context->transformStack.push(context->transformStack.top() * matrix);
|
2021-08-11 15:03:06 +00:00
|
|
|
|
2022-05-05 12:56:36 +00:00
|
|
|
context->opacityStack.push(context->opacityStack.top() * item->opacity());
|
|
|
|
|
2021-06-19 14:00:19 +00:00
|
|
|
for (Item *childItem : sortedChildItems) {
|
|
|
|
if (childItem->z() >= 0) {
|
|
|
|
break;
|
|
|
|
}
|
2022-04-27 11:07:21 +00:00
|
|
|
if (childItem->explicitVisible()) {
|
2021-06-19 14:00:19 +00:00
|
|
|
createRenderNode(childItem, context);
|
|
|
|
}
|
|
|
|
}
|
2021-06-10 11:18:42 +00:00
|
|
|
|
2021-06-19 14:00:19 +00:00
|
|
|
item->preprocess();
|
2021-05-21 10:51:23 +00:00
|
|
|
if (auto shadowItem = qobject_cast<ShadowItem *>(item)) {
|
2021-06-10 10:32:37 +00:00
|
|
|
WindowQuadList quads = clipQuads(item, context);
|
2021-05-21 10:51:23 +00:00
|
|
|
if (!quads.isEmpty()) {
|
|
|
|
SceneOpenGLShadow *shadow = static_cast<SceneOpenGLShadow *>(shadowItem->shadow());
|
|
|
|
context->renderNodes.append(RenderNode{
|
|
|
|
.texture = shadow->shadowTexture(),
|
|
|
|
.quads = quads,
|
2022-05-05 15:48:36 +00:00
|
|
|
.transformMatrix = context->transformStack.top(),
|
2022-05-05 12:56:36 +00:00
|
|
|
.opacity = context->opacityStack.top(),
|
2021-05-21 10:51:23 +00:00
|
|
|
.hasAlpha = true,
|
2021-07-06 13:38:35 +00:00
|
|
|
.coordinateType = UnnormalizedCoordinates,
|
2022-07-15 13:36:16 +00:00
|
|
|
.scale = scale,
|
2021-05-21 10:51:23 +00:00
|
|
|
});
|
2020-04-21 10:22:41 +00:00
|
|
|
}
|
2021-05-21 10:51:23 +00:00
|
|
|
} else if (auto decorationItem = qobject_cast<DecorationItem *>(item)) {
|
2021-06-10 10:32:37 +00:00
|
|
|
WindowQuadList quads = clipQuads(item, context);
|
2021-05-21 10:51:23 +00:00
|
|
|
if (!quads.isEmpty()) {
|
|
|
|
auto renderer = static_cast<const SceneOpenGLDecorationRenderer *>(decorationItem->renderer());
|
|
|
|
context->renderNodes.append(RenderNode{
|
|
|
|
.texture = renderer->texture(),
|
|
|
|
.quads = quads,
|
2022-05-05 15:48:36 +00:00
|
|
|
.transformMatrix = context->transformStack.top(),
|
2022-05-05 12:56:36 +00:00
|
|
|
.opacity = context->opacityStack.top(),
|
2021-05-21 10:51:23 +00:00
|
|
|
.hasAlpha = true,
|
|
|
|
.coordinateType = UnnormalizedCoordinates,
|
2022-07-15 13:36:16 +00:00
|
|
|
.scale = scale,
|
2021-05-21 10:51:23 +00:00
|
|
|
});
|
2021-02-04 09:07:20 +00:00
|
|
|
}
|
2021-05-21 10:51:23 +00:00
|
|
|
} else if (auto surfaceItem = qobject_cast<SurfaceItem *>(item)) {
|
2022-07-28 07:23:56 +00:00
|
|
|
SurfacePixmap *pixmap = surfaceItem->pixmap();
|
|
|
|
if (pixmap) {
|
|
|
|
WindowQuadList quads = clipQuads(item, context);
|
|
|
|
if (!quads.isEmpty()) {
|
2021-08-06 09:01:18 +00:00
|
|
|
// Don't bother with blending if the entire surface is opaque
|
|
|
|
bool hasAlpha = pixmap->hasAlphaChannel() && !surfaceItem->shape().subtracted(surfaceItem->opaque()).isEmpty();
|
2021-05-21 10:51:23 +00:00
|
|
|
context->renderNodes.append(RenderNode{
|
|
|
|
.texture = bindSurfaceTexture(surfaceItem),
|
|
|
|
.quads = quads,
|
2022-05-05 15:48:36 +00:00
|
|
|
.transformMatrix = context->transformStack.top(),
|
2022-05-05 12:56:36 +00:00
|
|
|
.opacity = context->opacityStack.top(),
|
2021-08-06 09:01:18 +00:00
|
|
|
.hasAlpha = hasAlpha,
|
2022-07-05 11:27:48 +00:00
|
|
|
.coordinateType = NormalizedCoordinates,
|
2022-07-15 13:36:16 +00:00
|
|
|
.scale = scale,
|
2021-05-21 10:51:23 +00:00
|
|
|
});
|
2021-02-04 09:07:20 +00:00
|
|
|
}
|
2020-12-13 15:46:22 +00:00
|
|
|
}
|
2021-05-21 10:51:23 +00:00
|
|
|
}
|
2013-05-13 06:17:28 +00:00
|
|
|
|
2021-06-19 14:00:19 +00:00
|
|
|
for (Item *childItem : sortedChildItems) {
|
|
|
|
if (childItem->z() < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-04-27 11:07:21 +00:00
|
|
|
if (childItem->explicitVisible()) {
|
2021-06-10 10:32:37 +00:00
|
|
|
createRenderNode(childItem, context);
|
2020-04-21 10:22:41 +00:00
|
|
|
}
|
2013-05-13 06:17:28 +00:00
|
|
|
}
|
2021-08-11 15:03:06 +00:00
|
|
|
|
2022-05-05 15:48:36 +00:00
|
|
|
context->transformStack.pop();
|
2022-05-05 12:56:36 +00:00
|
|
|
context->opacityStack.pop();
|
2013-03-18 15:45:53 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 09:43:39 +00:00
|
|
|
QMatrix4x4 SceneOpenGL::modelViewProjectionMatrix(const WindowPaintData &data) const
|
2014-04-01 16:08:48 +00:00
|
|
|
{
|
|
|
|
// An effect may want to override the default projection matrix in some cases,
|
|
|
|
// such as when it is rendering a window on a render target that doesn't have
|
|
|
|
// the same dimensions as the default framebuffer.
|
|
|
|
//
|
|
|
|
// Note that the screen transformation is not applied here.
|
2022-06-18 18:15:21 +00:00
|
|
|
const QMatrix4x4 pMatrix = data.projectionMatrix();
|
2022-03-25 12:20:32 +00:00
|
|
|
if (!pMatrix.isIdentity()) {
|
2022-06-15 09:43:39 +00:00
|
|
|
return pMatrix;
|
2022-06-18 18:15:21 +00:00
|
|
|
} else {
|
|
|
|
return renderTargetProjectionMatrix();
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2014-04-01 16:08:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-07 08:42:41 +00:00
|
|
|
void SceneOpenGL::render(Item *item, int mask, const QRegion ®ion, const WindowPaintData &data)
|
2013-03-17 12:34:26 +00:00
|
|
|
{
|
2021-06-10 10:32:37 +00:00
|
|
|
if (region.isEmpty()) {
|
2013-03-17 12:34:26 +00:00
|
|
|
return;
|
2021-06-10 10:32:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
RenderContext renderContext{
|
2021-06-10 10:32:37 +00:00
|
|
|
.clip = region,
|
2021-09-23 13:23:08 +00:00
|
|
|
.hardwareClipping = region != infiniteRegion() && ((mask & Scene::PAINT_WINDOW_TRANSFORMED) || (mask & Scene::PAINT_SCREEN_TRANSFORMED)),
|
2022-10-11 11:51:51 +00:00
|
|
|
.renderTargetScale = data.renderTargetScale().value_or(renderTargetScale()),
|
2021-06-10 10:32:37 +00:00
|
|
|
};
|
2021-08-11 15:03:06 +00:00
|
|
|
|
2022-05-05 15:48:36 +00:00
|
|
|
renderContext.transformStack.push(QMatrix4x4());
|
2022-05-05 12:56:36 +00:00
|
|
|
renderContext.opacityStack.push(data.opacity());
|
2021-08-11 15:03:06 +00:00
|
|
|
|
2022-09-01 11:31:17 +00:00
|
|
|
item->setTransform(data.toMatrix(renderTargetScale()));
|
2021-08-11 15:03:06 +00:00
|
|
|
|
2022-05-07 08:42:41 +00:00
|
|
|
createRenderNode(item, &renderContext);
|
2021-06-10 10:32:37 +00:00
|
|
|
|
|
|
|
int quadCount = 0;
|
|
|
|
for (const RenderNode &node : qAsConst(renderContext.renderNodes)) {
|
|
|
|
quadCount += node.quads.count();
|
|
|
|
}
|
|
|
|
if (!quadCount) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2013-03-21 22:52:03 +00:00
|
|
|
const bool indexedQuads = GLVertexBuffer::supportsIndexedQuads();
|
2014-07-22 10:26:38 +00:00
|
|
|
const GLenum primitiveType = indexedQuads ? GL_QUADS : GL_TRIANGLES;
|
2013-03-21 22:52:03 +00:00
|
|
|
const int verticesPerQuad = indexedQuads ? 4 : 6;
|
2021-06-10 10:32:37 +00:00
|
|
|
const size_t size = verticesPerQuad * quadCount * sizeof(GLVertex2D);
|
|
|
|
|
2022-05-05 12:56:36 +00:00
|
|
|
ShaderTraits shaderTraits = ShaderTrait::MapTexture;
|
|
|
|
|
2022-10-12 08:38:39 +00:00
|
|
|
if (data.brightness() != 1.0) {
|
2022-05-05 12:56:36 +00:00
|
|
|
shaderTraits |= ShaderTrait::Modulate;
|
|
|
|
}
|
|
|
|
if (data.saturation() != 1.0) {
|
|
|
|
shaderTraits |= ShaderTrait::AdjustSaturation;
|
2021-06-10 10:32:37 +00:00
|
|
|
}
|
2013-03-21 22:52:03 +00:00
|
|
|
|
2021-06-10 10:32:37 +00:00
|
|
|
const GLVertexAttrib attribs[] = {
|
2022-03-23 10:13:38 +00:00
|
|
|
{VA_Position, 2, GL_FLOAT, offsetof(GLVertex2D, position)},
|
|
|
|
{VA_TexCoord, 2, GL_FLOAT, offsetof(GLVertex2D, texcoord)},
|
2021-06-10 10:32:37 +00:00
|
|
|
};
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2013-03-18 15:45:53 +00:00
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
2021-06-10 10:32:37 +00:00
|
|
|
vbo->reset();
|
|
|
|
vbo->setAttribLayout(attribs, 2, sizeof(GLVertex2D));
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
GLVertex2D *map = (GLVertex2D *)vbo->map(size);
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2020-04-21 10:22:41 +00:00
|
|
|
for (int i = 0, v = 0; i < renderContext.renderNodes.count(); i++) {
|
|
|
|
RenderNode &renderNode = renderContext.renderNodes[i];
|
2022-03-25 12:20:32 +00:00
|
|
|
if (renderNode.quads.isEmpty() || !renderNode.texture) {
|
2013-03-18 15:45:53 +00:00
|
|
|
continue;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2022-05-05 12:56:36 +00:00
|
|
|
if (renderNode.opacity != 1.0) {
|
|
|
|
shaderTraits |= ShaderTrait::Modulate;
|
|
|
|
}
|
|
|
|
|
2020-04-21 10:22:41 +00:00
|
|
|
renderNode.firstVertex = v;
|
|
|
|
renderNode.vertexCount = renderNode.quads.count() * verticesPerQuad;
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2020-04-21 10:22:41 +00:00
|
|
|
const QMatrix4x4 matrix = renderNode.texture->matrix(renderNode.coordinateType);
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2022-07-15 13:36:16 +00:00
|
|
|
renderNode.quads.makeInterleavedArrays(primitiveType, &map[v], matrix, renderNode.scale);
|
2020-04-21 10:22:41 +00:00
|
|
|
v += renderNode.quads.count() * verticesPerQuad;
|
2013-03-18 15:45:53 +00:00
|
|
|
}
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2013-03-18 15:45:53 +00:00
|
|
|
vbo->unmap();
|
|
|
|
vbo->bindArrays();
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2022-05-05 12:56:36 +00:00
|
|
|
GLShader *shader = data.shader;
|
|
|
|
if (!shader) {
|
|
|
|
shader = ShaderManager::instance()->pushShader(shaderTraits);
|
|
|
|
}
|
|
|
|
shader->setUniform(GLShader::Saturation, data.saturation());
|
|
|
|
|
|
|
|
if (renderContext.hardwareClipping) {
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
|
2013-03-18 15:45:53 +00:00
|
|
|
// Make sure the blend function is set up correctly in case we will be doing blending
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2013-03-18 15:45:53 +00:00
|
|
|
float opacity = -1.0;
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2022-02-06 12:07:48 +00:00
|
|
|
// The scissor region must be in the render target local coordinate system.
|
|
|
|
QRegion scissorRegion = infiniteRegion();
|
|
|
|
if (renderContext.hardwareClipping) {
|
2022-05-07 08:42:41 +00:00
|
|
|
scissorRegion = mapToRenderTarget(region);
|
2022-02-06 12:07:48 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 09:43:39 +00:00
|
|
|
const QMatrix4x4 projectionMatrix = modelViewProjectionMatrix(data);
|
2020-04-21 10:22:41 +00:00
|
|
|
for (int i = 0; i < renderContext.renderNodes.count(); i++) {
|
|
|
|
const RenderNode &renderNode = renderContext.renderNodes[i];
|
2022-03-25 12:20:32 +00:00
|
|
|
if (renderNode.vertexCount == 0) {
|
2013-03-18 15:45:53 +00:00
|
|
|
continue;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2020-04-21 10:22:41 +00:00
|
|
|
setBlendEnabled(renderNode.hasAlpha || renderNode.opacity < 1.0);
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2022-06-15 09:43:39 +00:00
|
|
|
shader->setUniform(GLShader::ModelViewProjectionMatrix, projectionMatrix * renderNode.transformMatrix);
|
2020-04-21 10:22:41 +00:00
|
|
|
if (opacity != renderNode.opacity) {
|
2013-03-18 15:45:53 +00:00
|
|
|
shader->setUniform(GLShader::ModulationConstant,
|
2020-04-21 10:22:41 +00:00
|
|
|
modulate(renderNode.opacity, data.brightness()));
|
|
|
|
opacity = renderNode.opacity;
|
2013-03-17 12:34:26 +00:00
|
|
|
}
|
|
|
|
|
2021-07-06 11:55:10 +00:00
|
|
|
renderNode.texture->setFilter(GL_LINEAR);
|
2020-04-21 10:22:41 +00:00
|
|
|
renderNode.texture->setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
renderNode.texture->bind();
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2022-02-06 12:07:48 +00:00
|
|
|
vbo->draw(scissorRegion, primitiveType, renderNode.firstVertex,
|
2021-06-10 10:32:37 +00:00
|
|
|
renderNode.vertexCount, renderContext.hardwareClipping);
|
2013-03-17 12:34:26 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 15:45:53 +00:00
|
|
|
vbo->unbindArrays();
|
|
|
|
|
2018-01-23 19:27:16 +00:00
|
|
|
setBlendEnabled(false);
|
|
|
|
|
2022-03-25 12:20:32 +00:00
|
|
|
if (!data.shader) {
|
2013-03-17 12:34:26 +00:00
|
|
|
ShaderManager::instance()->popShader();
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2013-03-17 12:34:26 +00:00
|
|
|
|
2021-06-10 10:32:37 +00:00
|
|
|
if (renderContext.hardwareClipping) {
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-03-27 10:33:07 +00:00
|
|
|
//****************************************
|
|
|
|
// SceneOpenGL::Shadow
|
|
|
|
//****************************************
|
2014-12-04 09:36:19 +00:00
|
|
|
class DecorationShadowTextureCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~DecorationShadowTextureCache();
|
2022-03-23 10:13:38 +00:00
|
|
|
DecorationShadowTextureCache(const DecorationShadowTextureCache &) = delete;
|
2014-12-04 09:36:19 +00:00
|
|
|
static DecorationShadowTextureCache &instance();
|
|
|
|
|
|
|
|
void unregister(SceneOpenGLShadow *shadow);
|
2022-05-17 10:36:34 +00:00
|
|
|
std::shared_ptr<GLTexture> getTexture(SceneOpenGLShadow *shadow);
|
2014-12-04 09:36:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DecorationShadowTextureCache() = default;
|
2022-03-23 10:13:38 +00:00
|
|
|
struct Data
|
|
|
|
{
|
2022-05-17 10:36:34 +00:00
|
|
|
std::shared_ptr<GLTexture> texture;
|
2022-03-23 10:13:38 +00:00
|
|
|
QVector<SceneOpenGLShadow *> shadows;
|
2014-12-04 09:36:19 +00:00
|
|
|
};
|
2022-03-23 10:13:38 +00:00
|
|
|
QHash<KDecoration2::DecorationShadow *, Data> m_cache;
|
2014-12-04 09:36:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DecorationShadowTextureCache &DecorationShadowTextureCache::instance()
|
|
|
|
{
|
|
|
|
static DecorationShadowTextureCache s_instance;
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecorationShadowTextureCache::~DecorationShadowTextureCache()
|
|
|
|
{
|
|
|
|
Q_ASSERT(m_cache.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecorationShadowTextureCache::unregister(SceneOpenGLShadow *shadow)
|
|
|
|
{
|
|
|
|
auto it = m_cache.begin();
|
|
|
|
while (it != m_cache.end()) {
|
|
|
|
auto &d = it.value();
|
|
|
|
// check whether the Vector of Shadows contains our shadow and remove all of them
|
|
|
|
auto glIt = d.shadows.begin();
|
|
|
|
while (glIt != d.shadows.end()) {
|
|
|
|
if (*glIt == shadow) {
|
|
|
|
glIt = d.shadows.erase(glIt);
|
|
|
|
} else {
|
|
|
|
glIt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if there are no shadows any more we can erase the cache entry
|
|
|
|
if (d.shadows.isEmpty()) {
|
|
|
|
it = m_cache.erase(it);
|
|
|
|
} else {
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 10:36:34 +00:00
|
|
|
std::shared_ptr<GLTexture> DecorationShadowTextureCache::getTexture(SceneOpenGLShadow *shadow)
|
2014-12-04 09:36:19 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(shadow->hasDecorationShadow());
|
|
|
|
unregister(shadow);
|
2020-03-15 19:59:29 +00:00
|
|
|
const auto &decoShadow = shadow->decorationShadow().toStrongRef();
|
2014-12-04 09:36:19 +00:00
|
|
|
Q_ASSERT(!decoShadow.isNull());
|
|
|
|
auto it = m_cache.find(decoShadow.data());
|
|
|
|
if (it != m_cache.end()) {
|
|
|
|
Q_ASSERT(!it.value().shadows.contains(shadow));
|
|
|
|
it.value().shadows << shadow;
|
|
|
|
return it.value().texture;
|
|
|
|
}
|
|
|
|
Data d;
|
|
|
|
d.shadows << shadow;
|
2022-05-17 10:36:34 +00:00
|
|
|
d.texture = std::make_shared<GLTexture>(shadow->decorationShadowImage());
|
2014-12-04 09:36:19 +00:00
|
|
|
m_cache.insert(decoShadow.data(), d);
|
|
|
|
return d.texture;
|
|
|
|
}
|
|
|
|
|
2022-04-28 07:44:11 +00:00
|
|
|
SceneOpenGLShadow::SceneOpenGLShadow(Window *window)
|
|
|
|
: Shadow(window)
|
2011-03-27 10:33:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneOpenGLShadow::~SceneOpenGLShadow()
|
|
|
|
{
|
2018-12-02 11:59:45 +00:00
|
|
|
Scene *scene = Compositor::self()->scene();
|
|
|
|
if (scene) {
|
|
|
|
scene->makeOpenGLContextCurrent();
|
2015-12-20 23:18:00 +00:00
|
|
|
DecorationShadowTextureCache::instance().unregister(this);
|
|
|
|
m_texture.reset();
|
|
|
|
}
|
2011-03-27 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 17:06:12 +00:00
|
|
|
bool SceneOpenGLShadow::prepareBackend()
|
|
|
|
{
|
2014-07-24 06:39:25 +00:00
|
|
|
if (hasDecorationShadow()) {
|
|
|
|
// simplifies a lot by going directly to
|
2018-12-02 11:59:45 +00:00
|
|
|
Scene *scene = Compositor::self()->scene();
|
|
|
|
scene->makeOpenGLContextCurrent();
|
2014-12-04 09:36:19 +00:00
|
|
|
m_texture = DecorationShadowTextureCache::instance().getTexture(this);
|
2014-07-24 06:39:25 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-25 14:03:21 +00:00
|
|
|
const QSize top(shadowPixmap(ShadowElementTop).size());
|
|
|
|
const QSize topRight(shadowPixmap(ShadowElementTopRight).size());
|
|
|
|
const QSize right(shadowPixmap(ShadowElementRight).size());
|
|
|
|
const QSize bottom(shadowPixmap(ShadowElementBottom).size());
|
|
|
|
const QSize bottomLeft(shadowPixmap(ShadowElementBottomLeft).size());
|
|
|
|
const QSize left(shadowPixmap(ShadowElementLeft).size());
|
|
|
|
const QSize topLeft(shadowPixmap(ShadowElementTopLeft).size());
|
2016-06-07 13:53:39 +00:00
|
|
|
const QSize bottomRight(shadowPixmap(ShadowElementBottomRight).size());
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const int width = std::max({topLeft.width(), left.width(), bottomLeft.width()}) + std::max(top.width(), bottom.width()) + std::max({topRight.width(), right.width(), bottomRight.width()});
|
|
|
|
const int height = std::max({topLeft.height(), top.height(), topRight.height()}) + std::max(left.height(), right.height()) + std::max({bottomLeft.height(), bottom.height(), bottomRight.height()});
|
2011-06-23 17:06:12 +00:00
|
|
|
|
2016-06-07 12:17:51 +00:00
|
|
|
if (width == 0 || height == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-23 17:06:12 +00:00
|
|
|
QImage image(width, height, QImage::Format_ARGB32);
|
|
|
|
image.fill(Qt::transparent);
|
[scenes/opengl] Fix overlaps in shadow texture atlas
Summary:
If the corner shadow tiles(top-left, top-right, and so on) tiles are missing,
then the left/top/right/bottom shadow tiles will overlap.
This diff addresses that problem by changing how the shadow texture
atlas is rendered:
* corner tiles will be drawn in the corners of the atlas(buildQuads
method expects them to be at the corners);
* top, right, bottom, and left tile will be aligned to the top-left
corner of the inner shadow rect.
For majority of desktop themes, the shadow texture atlas looks the same.
For example, here's for Aether:
Before:
{F6190484, layout=center, size=full}
After:
{F6190488, layout=center, size=full}
Depends on D14783
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, abetts, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D14784
2018-08-12 23:52:12 +00:00
|
|
|
|
|
|
|
const int innerRectTop = std::max({topLeft.height(), top.height(), topRight.height()});
|
|
|
|
const int innerRectLeft = std::max({topLeft.width(), left.width(), bottomLeft.width()});
|
|
|
|
|
2011-06-23 17:06:12 +00:00
|
|
|
QPainter p;
|
|
|
|
p.begin(&image);
|
[scenes/opengl] Fix overlaps in shadow texture atlas
Summary:
If the corner shadow tiles(top-left, top-right, and so on) tiles are missing,
then the left/top/right/bottom shadow tiles will overlap.
This diff addresses that problem by changing how the shadow texture
atlas is rendered:
* corner tiles will be drawn in the corners of the atlas(buildQuads
method expects them to be at the corners);
* top, right, bottom, and left tile will be aligned to the top-left
corner of the inner shadow rect.
For majority of desktop themes, the shadow texture atlas looks the same.
For example, here's for Aether:
Before:
{F6190484, layout=center, size=full}
After:
{F6190488, layout=center, size=full}
Depends on D14783
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, abetts, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D14784
2018-08-12 23:52:12 +00:00
|
|
|
|
2020-07-12 00:04:56 +00:00
|
|
|
p.drawPixmap(0, 0, topLeft.width(), topLeft.height(), shadowPixmap(ShadowElementTopLeft));
|
|
|
|
p.drawPixmap(innerRectLeft, 0, top.width(), top.height(), shadowPixmap(ShadowElementTop));
|
|
|
|
p.drawPixmap(width - topRight.width(), 0, topRight.width(), topRight.height(), shadowPixmap(ShadowElementTopRight));
|
[scenes/opengl] Fix overlaps in shadow texture atlas
Summary:
If the corner shadow tiles(top-left, top-right, and so on) tiles are missing,
then the left/top/right/bottom shadow tiles will overlap.
This diff addresses that problem by changing how the shadow texture
atlas is rendered:
* corner tiles will be drawn in the corners of the atlas(buildQuads
method expects them to be at the corners);
* top, right, bottom, and left tile will be aligned to the top-left
corner of the inner shadow rect.
For majority of desktop themes, the shadow texture atlas looks the same.
For example, here's for Aether:
Before:
{F6190484, layout=center, size=full}
After:
{F6190488, layout=center, size=full}
Depends on D14783
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, abetts, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D14784
2018-08-12 23:52:12 +00:00
|
|
|
|
2020-07-12 00:04:56 +00:00
|
|
|
p.drawPixmap(0, innerRectTop, left.width(), left.height(), shadowPixmap(ShadowElementLeft));
|
|
|
|
p.drawPixmap(width - right.width(), innerRectTop, right.width(), right.height(), shadowPixmap(ShadowElementRight));
|
[scenes/opengl] Fix overlaps in shadow texture atlas
Summary:
If the corner shadow tiles(top-left, top-right, and so on) tiles are missing,
then the left/top/right/bottom shadow tiles will overlap.
This diff addresses that problem by changing how the shadow texture
atlas is rendered:
* corner tiles will be drawn in the corners of the atlas(buildQuads
method expects them to be at the corners);
* top, right, bottom, and left tile will be aligned to the top-left
corner of the inner shadow rect.
For majority of desktop themes, the shadow texture atlas looks the same.
For example, here's for Aether:
Before:
{F6190484, layout=center, size=full}
After:
{F6190488, layout=center, size=full}
Depends on D14783
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, abetts, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D14784
2018-08-12 23:52:12 +00:00
|
|
|
|
2020-07-12 00:04:56 +00:00
|
|
|
p.drawPixmap(0, height - bottomLeft.height(), bottomLeft.width(), bottomLeft.height(), shadowPixmap(ShadowElementBottomLeft));
|
|
|
|
p.drawPixmap(innerRectLeft, height - bottom.height(), bottom.width(), bottom.height(), shadowPixmap(ShadowElementBottom));
|
|
|
|
p.drawPixmap(width - bottomRight.width(), height - bottomRight.height(), bottomRight.width(), bottomRight.height(), shadowPixmap(ShadowElementBottomRight));
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2011-06-23 17:06:12 +00:00
|
|
|
p.end();
|
|
|
|
|
2014-12-13 13:43:56 +00:00
|
|
|
// Check if the image is alpha-only in practice, and if so convert it to an 8-bpp format
|
2015-02-18 08:06:37 +00:00
|
|
|
if (!GLPlatform::instance()->isGLES() && GLTexture::supportsSwizzle() && GLTexture::supportsFormatRG()) {
|
2021-08-12 02:49:49 +00:00
|
|
|
QImage alphaImage(image.size(), QImage::Format_Alpha8);
|
2014-12-13 13:43:56 +00:00
|
|
|
bool alphaOnly = true;
|
|
|
|
|
|
|
|
for (ptrdiff_t y = 0; alphaOnly && y < image.height(); y++) {
|
2022-03-23 10:13:38 +00:00
|
|
|
const uint32_t *const src = reinterpret_cast<const uint32_t *>(image.scanLine(y));
|
|
|
|
uint8_t *const dst = reinterpret_cast<uint8_t *>(alphaImage.scanLine(y));
|
2014-12-13 13:43:56 +00:00
|
|
|
|
|
|
|
for (ptrdiff_t x = 0; x < image.width(); x++) {
|
2022-03-25 12:20:32 +00:00
|
|
|
if (src[x] & 0x00ffffff) {
|
2014-12-13 13:43:56 +00:00
|
|
|
alphaOnly = false;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2014-12-13 13:43:56 +00:00
|
|
|
|
|
|
|
dst[x] = qAlpha(src[x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alphaOnly) {
|
|
|
|
image = alphaImage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-02 11:59:45 +00:00
|
|
|
Scene *scene = Compositor::self()->scene();
|
|
|
|
scene->makeOpenGLContextCurrent();
|
2022-05-17 10:36:34 +00:00
|
|
|
m_texture = std::make_shared<GLTexture>(image);
|
2011-11-25 14:03:21 +00:00
|
|
|
|
2014-12-13 13:43:56 +00:00
|
|
|
if (m_texture->internalFormat() == GL_R8) {
|
|
|
|
// Swizzle red to alpha and all other channels to zero
|
|
|
|
m_texture->bind();
|
|
|
|
m_texture->setSwizzle(GL_ZERO, GL_ZERO, GL_ZERO, GL_RED);
|
|
|
|
}
|
|
|
|
|
2011-06-23 17:06:12 +00:00
|
|
|
return true;
|
2011-03-27 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
SceneOpenGLDecorationRenderer::SceneOpenGLDecorationRenderer(Decoration::DecoratedClientImpl *client)
|
2021-04-26 16:38:40 +00:00
|
|
|
: DecorationRenderer(client)
|
2014-07-22 11:11:19 +00:00
|
|
|
, m_texture()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-10 21:37:06 +00:00
|
|
|
SceneOpenGLDecorationRenderer::~SceneOpenGLDecorationRenderer()
|
|
|
|
{
|
|
|
|
if (Scene *scene = Compositor::self()->scene()) {
|
|
|
|
scene->makeOpenGLContextCurrent();
|
|
|
|
}
|
|
|
|
}
|
2014-07-22 11:11:19 +00:00
|
|
|
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
static void clamp_row(int left, int width, int right, const uint32_t *src, uint32_t *dest)
|
|
|
|
{
|
|
|
|
std::fill_n(dest, left, *src);
|
|
|
|
std::copy(src, src + width, dest + left);
|
|
|
|
std::fill_n(dest + left + width, right, *(src + width - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clamp_sides(int left, int width, int right, const uint32_t *src, uint32_t *dest)
|
|
|
|
{
|
|
|
|
std::fill_n(dest, left, *src);
|
|
|
|
std::fill_n(dest + left + width, right, *(src + width - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clamp(QImage &image, const QRect &viewport)
|
|
|
|
{
|
|
|
|
Q_ASSERT(image.depth() == 32);
|
2021-11-17 00:24:10 +00:00
|
|
|
if (viewport.isEmpty()) {
|
|
|
|
image = {};
|
|
|
|
return;
|
|
|
|
}
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
|
|
|
|
const QRect rect = image.rect();
|
|
|
|
|
|
|
|
const int left = viewport.left() - rect.left();
|
|
|
|
const int top = viewport.top() - rect.top();
|
|
|
|
const int right = rect.right() - viewport.right();
|
|
|
|
const int bottom = rect.bottom() - viewport.bottom();
|
|
|
|
|
|
|
|
const int width = rect.width() - left - right;
|
|
|
|
const int height = rect.height() - top - bottom;
|
|
|
|
|
|
|
|
const uint32_t *firstRow = reinterpret_cast<uint32_t *>(image.scanLine(top));
|
|
|
|
const uint32_t *lastRow = reinterpret_cast<uint32_t *>(image.scanLine(top + height - 1));
|
|
|
|
|
|
|
|
for (int i = 0; i < top; ++i) {
|
|
|
|
uint32_t *dest = reinterpret_cast<uint32_t *>(image.scanLine(i));
|
|
|
|
clamp_row(left, width, right, firstRow + left, dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < height; ++i) {
|
|
|
|
uint32_t *dest = reinterpret_cast<uint32_t *>(image.scanLine(top + i));
|
|
|
|
clamp_sides(left, width, right, dest + left, dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < bottom; ++i) {
|
|
|
|
uint32_t *dest = reinterpret_cast<uint32_t *>(image.scanLine(top + height + i));
|
|
|
|
clamp_row(left, width, right, lastRow + left, dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 16:38:40 +00:00
|
|
|
void SceneOpenGLDecorationRenderer::render(const QRegion ®ion)
|
2014-07-22 11:11:19 +00:00
|
|
|
{
|
2020-01-26 13:08:52 +00:00
|
|
|
if (areImageSizesDirty()) {
|
2014-07-22 11:11:19 +00:00
|
|
|
resizeTexture();
|
|
|
|
resetImageSizesDirty();
|
|
|
|
}
|
|
|
|
|
2016-04-11 07:42:22 +00:00
|
|
|
if (!m_texture) {
|
|
|
|
// for invalid sizes we get no texture, see BUG 361551
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
QRectF left, top, right, bottom;
|
2022-04-28 07:44:11 +00:00
|
|
|
client()->window()->layoutDecorationRects(left, top, right, bottom);
|
2014-07-22 11:11:19 +00:00
|
|
|
|
2022-02-07 10:36:25 +00:00
|
|
|
const qreal devicePixelRatio = effectiveDevicePixelRatio();
|
|
|
|
const int topHeight = std::ceil(top.height() * devicePixelRatio);
|
|
|
|
const int bottomHeight = std::ceil(bottom.height() * devicePixelRatio);
|
|
|
|
const int leftWidth = std::ceil(left.width() * devicePixelRatio);
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
|
2021-12-16 16:36:47 +00:00
|
|
|
const QPoint topPosition(0, 0);
|
|
|
|
const QPoint bottomPosition(0, topPosition.y() + topHeight + (2 * TexturePad));
|
|
|
|
const QPoint leftPosition(0, bottomPosition.y() + bottomHeight + (2 * TexturePad));
|
|
|
|
const QPoint rightPosition(0, leftPosition.y() + leftWidth + (2 * TexturePad));
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
|
2021-12-16 16:36:47 +00:00
|
|
|
const QRect dirtyRect = region.boundingRect();
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
renderPart(top.toRect().intersected(dirtyRect), top.toRect(), topPosition, devicePixelRatio);
|
|
|
|
renderPart(bottom.toRect().intersected(dirtyRect), bottom.toRect(), bottomPosition, devicePixelRatio);
|
|
|
|
renderPart(left.toRect().intersected(dirtyRect), left.toRect(), leftPosition, devicePixelRatio, true);
|
|
|
|
renderPart(right.toRect().intersected(dirtyRect), right.toRect(), rightPosition, devicePixelRatio, true);
|
2021-12-16 16:36:47 +00:00
|
|
|
}
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
|
2021-12-16 16:36:47 +00:00
|
|
|
void SceneOpenGLDecorationRenderer::renderPart(const QRect &rect, const QRect &partRect,
|
2022-02-07 10:36:25 +00:00
|
|
|
const QPoint &textureOffset,
|
|
|
|
qreal devicePixelRatio, bool rotated)
|
2021-12-16 16:36:47 +00:00
|
|
|
{
|
|
|
|
if (!rect.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// We allow partial decoration updates and it might just so happen that the
|
|
|
|
// dirty region is completely contained inside the decoration part, i.e.
|
|
|
|
// the dirty region doesn't touch any of the decoration's edges. In that
|
|
|
|
// case, we should **not** pad the dirty region.
|
|
|
|
const QMargins padding = texturePadForPart(rect, partRect);
|
|
|
|
int verticalPadding = padding.top() + padding.bottom();
|
|
|
|
int horizontalPadding = padding.left() + padding.right();
|
|
|
|
|
2022-07-08 12:34:22 +00:00
|
|
|
QSize imageSize(toNativeSize(rect.width()), toNativeSize(rect.height()));
|
2021-12-16 16:36:47 +00:00
|
|
|
if (rotated) {
|
|
|
|
imageSize = QSize(imageSize.height(), imageSize.width());
|
|
|
|
}
|
|
|
|
QSize paddedImageSize = imageSize;
|
|
|
|
paddedImageSize.rheight() += verticalPadding;
|
|
|
|
paddedImageSize.rwidth() += horizontalPadding;
|
|
|
|
QImage image(paddedImageSize, QImage::Format_ARGB32_Premultiplied);
|
2022-02-07 10:36:25 +00:00
|
|
|
image.setDevicePixelRatio(devicePixelRatio);
|
2021-12-16 16:36:47 +00:00
|
|
|
image.fill(Qt::transparent);
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
|
2021-12-16 16:36:47 +00:00
|
|
|
QRect padClip = QRect(padding.left(), padding.top(), imageSize.width(), imageSize.height());
|
|
|
|
QPainter painter(&image);
|
2022-02-07 10:36:25 +00:00
|
|
|
const qreal inverseScale = 1.0 / devicePixelRatio;
|
2021-12-16 16:36:47 +00:00
|
|
|
painter.scale(inverseScale, inverseScale);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setClipRect(padClip);
|
|
|
|
painter.translate(padding.left(), padding.top());
|
|
|
|
if (rotated) {
|
|
|
|
painter.translate(0, imageSize.height());
|
|
|
|
painter.rotate(-90);
|
|
|
|
}
|
2022-02-07 10:36:25 +00:00
|
|
|
painter.scale(devicePixelRatio, devicePixelRatio);
|
2021-12-16 16:36:47 +00:00
|
|
|
painter.translate(-rect.topLeft());
|
|
|
|
renderToPainter(&painter, rect);
|
|
|
|
painter.end();
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
|
2021-12-16 16:36:47 +00:00
|
|
|
// fill padding pixels by copying from the neighbour row
|
|
|
|
clamp(image, padClip);
|
2020-01-26 13:08:52 +00:00
|
|
|
|
2022-02-07 10:36:25 +00:00
|
|
|
QPoint dirtyOffset = (rect.topLeft() - partRect.topLeft()) * devicePixelRatio;
|
2021-12-16 16:36:47 +00:00
|
|
|
if (padding.top() == 0) {
|
|
|
|
dirtyOffset.ry() += TexturePad;
|
|
|
|
}
|
|
|
|
if (padding.left() == 0) {
|
|
|
|
dirtyOffset.rx() += TexturePad;
|
|
|
|
}
|
|
|
|
m_texture->update(image, textureOffset + dirtyOffset);
|
|
|
|
}
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
|
2021-12-16 16:36:47 +00:00
|
|
|
const QMargins SceneOpenGLDecorationRenderer::texturePadForPart(
|
2022-03-23 10:13:38 +00:00
|
|
|
const QRect &rect, const QRect &partRect)
|
2021-12-16 16:36:47 +00:00
|
|
|
{
|
|
|
|
QMargins result = QMargins(0, 0, 0, 0);
|
|
|
|
if (rect.top() == partRect.top()) {
|
|
|
|
result.setTop(TexturePad);
|
|
|
|
}
|
|
|
|
if (rect.bottom() == partRect.bottom()) {
|
|
|
|
result.setBottom(TexturePad);
|
|
|
|
}
|
|
|
|
if (rect.left() == partRect.left()) {
|
|
|
|
result.setLeft(TexturePad);
|
|
|
|
}
|
|
|
|
if (rect.right() == partRect.right()) {
|
|
|
|
result.setRight(TexturePad);
|
|
|
|
}
|
|
|
|
return result;
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int align(int value, int align)
|
|
|
|
{
|
|
|
|
return (value + align - 1) & ~(align - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneOpenGLDecorationRenderer::resizeTexture()
|
|
|
|
{
|
2022-05-16 20:13:39 +00:00
|
|
|
QRectF left, top, right, bottom;
|
2022-04-28 07:44:11 +00:00
|
|
|
client()->window()->layoutDecorationRects(left, top, right, bottom);
|
2014-07-22 11:11:19 +00:00
|
|
|
QSize size;
|
|
|
|
|
2022-07-08 12:34:22 +00:00
|
|
|
size.rwidth() = toNativeSize(qMax(qMax(top.width(), bottom.width()),
|
|
|
|
qMax(left.height(), right.height())));
|
|
|
|
size.rheight() = toNativeSize(top.height()) + toNativeSize(bottom.height()) + toNativeSize(left.width()) + toNativeSize(right.width());
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
|
2021-12-16 16:36:47 +00:00
|
|
|
size.rheight() += 4 * (2 * TexturePad);
|
|
|
|
size.rwidth() += 2 * TexturePad;
|
2014-07-22 11:11:19 +00:00
|
|
|
size.rwidth() = align(size.width(), 128);
|
|
|
|
|
2022-03-25 12:20:32 +00:00
|
|
|
if (m_texture && m_texture->size() == size) {
|
2014-07-22 11:11:19 +00:00
|
|
|
return;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2014-07-22 11:11:19 +00:00
|
|
|
|
|
|
|
if (!size.isEmpty()) {
|
2014-12-13 13:28:33 +00:00
|
|
|
m_texture.reset(new GLTexture(GL_RGBA8, size.width(), size.height()));
|
2014-07-22 11:11:19 +00:00
|
|
|
m_texture->setYInverted(true);
|
|
|
|
m_texture->setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
m_texture->clear();
|
|
|
|
} else {
|
|
|
|
m_texture.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-08 12:34:22 +00:00
|
|
|
int SceneOpenGLDecorationRenderer::toNativeSize(int size) const
|
|
|
|
{
|
|
|
|
return std::ceil(size * effectiveDevicePixelRatio());
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|