2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2013-06-21 08:03:31 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2013-06-21 08:03:31 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2013-06-21 08:03:31 +00:00
|
|
|
#include "scene_qpainter.h"
|
|
|
|
// KWin
|
2020-05-23 15:07:54 +00:00
|
|
|
#include "abstract_client.h"
|
2013-06-21 08:03:31 +00:00
|
|
|
#include "composite.h"
|
2015-04-01 13:36:40 +00:00
|
|
|
#include "cursor.h"
|
2013-06-21 08:03:31 +00:00
|
|
|
#include "deleted.h"
|
|
|
|
#include "effects.h"
|
2013-06-25 07:53:45 +00:00
|
|
|
#include "main.h"
|
2015-04-17 09:17:06 +00:00
|
|
|
#include "screens.h"
|
2013-06-21 08:03:31 +00:00
|
|
|
#include "toplevel.h"
|
2016-04-07 07:24:17 +00:00
|
|
|
#include "platform.h"
|
2015-03-23 13:29:07 +00:00
|
|
|
#include "wayland_server.h"
|
[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
|
|
|
|
|
|
|
#include <kwineffectquickview.h>
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
#include <KWaylandServer/buffer_interface.h>
|
|
|
|
#include <KWaylandServer/subcompositor_interface.h>
|
|
|
|
#include <KWaylandServer/surface_interface.h>
|
2014-07-22 11:11:19 +00:00
|
|
|
#include "decorations/decoratedclient.h"
|
2013-06-21 08:03:31 +00:00
|
|
|
// Qt
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QPainter>
|
2014-07-22 11:11:19 +00:00
|
|
|
#include <KDecoration2/Decoration>
|
2013-06-21 08:03:31 +00:00
|
|
|
|
2018-06-07 09:08:15 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// SceneQPainter
|
|
|
|
//****************************************
|
2015-02-23 13:41:45 +00:00
|
|
|
SceneQPainter *SceneQPainter::createScene(QObject *parent)
|
2013-06-21 08:03:31 +00:00
|
|
|
{
|
2016-04-15 09:37:43 +00:00
|
|
|
QScopedPointer<QPainterBackend> backend(kwinApp()->platform()->createQPainterBackend());
|
|
|
|
if (backend.isNull()) {
|
|
|
|
return nullptr;
|
2013-06-21 08:03:31 +00:00
|
|
|
}
|
2016-04-15 09:37:43 +00:00
|
|
|
if (backend->isFailed()) {
|
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
|
|
|
return nullptr;
|
2016-04-15 09:37:43 +00:00
|
|
|
}
|
|
|
|
return new SceneQPainter(backend.take(), parent);
|
2013-06-21 08:03:31 +00:00
|
|
|
}
|
|
|
|
|
2015-02-23 13:41:45 +00:00
|
|
|
SceneQPainter::SceneQPainter(QPainterBackend *backend, QObject *parent)
|
|
|
|
: Scene(parent)
|
2013-06-21 08:03:31 +00:00
|
|
|
, m_backend(backend)
|
|
|
|
, m_painter(new QPainter())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneQPainter::~SceneQPainter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositingType SceneQPainter::compositingType() const
|
|
|
|
{
|
|
|
|
return QPainterCompositing;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SceneQPainter::initFailed() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-13 16:41:56 +00:00
|
|
|
void SceneQPainter::paintGenericScreen(int mask, const ScreenPaintData &data)
|
2013-06-21 08:03:31 +00:00
|
|
|
{
|
|
|
|
m_painter->save();
|
|
|
|
m_painter->translate(data.xTranslation(), data.yTranslation());
|
|
|
|
m_painter->scale(data.xScale(), data.yScale());
|
|
|
|
Scene::paintGenericScreen(mask, data);
|
|
|
|
m_painter->restore();
|
|
|
|
}
|
|
|
|
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
void SceneQPainter::paint(int screenId, const QRegion &_damage, const QList<Toplevel *> &toplevels,
|
|
|
|
std::chrono::milliseconds presentTime)
|
2013-06-21 08:03:31 +00:00
|
|
|
{
|
2020-11-09 12:19:15 +00:00
|
|
|
Q_ASSERT(kwinApp()->platform()->isPerScreenRenderingEnabled());
|
2020-11-09 14:10:03 +00:00
|
|
|
painted_screen = screenId;
|
2013-06-21 08:03:31 +00:00
|
|
|
|
|
|
|
createStackingOrder(toplevels);
|
2020-03-13 16:41:56 +00:00
|
|
|
QRegion damage = _damage;
|
2013-06-21 08:03:31 +00:00
|
|
|
|
2020-11-09 14:10:03 +00:00
|
|
|
int mask = 0;
|
|
|
|
|
2020-11-09 14:31:26 +00:00
|
|
|
m_backend->beginFrame(screenId);
|
2020-11-09 14:10:03 +00:00
|
|
|
const bool needsFullRepaint = m_backend->needsFullRepaint(screenId);
|
|
|
|
if (needsFullRepaint) {
|
|
|
|
mask |= Scene::PAINT_SCREEN_BACKGROUND_FIRST;
|
|
|
|
damage = screens()->geometry(screenId);
|
|
|
|
}
|
|
|
|
const QRect geometry = screens()->geometry(screenId);
|
|
|
|
QImage *buffer = m_backend->bufferForScreen(screenId);
|
|
|
|
if (buffer && !buffer->isNull()) {
|
2020-11-10 08:39:08 +00:00
|
|
|
m_painter->begin(buffer);
|
|
|
|
m_painter->setWindow(geometry);
|
2013-06-21 08:03:31 +00:00
|
|
|
|
2020-11-10 08:39:08 +00:00
|
|
|
QRegion updateRegion, validRegion;
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
paintScreen(&mask, damage.intersected(geometry), QRegion(), &updateRegion, &validRegion,
|
|
|
|
presentTime);
|
2020-10-26 07:39:55 +00:00
|
|
|
paintCursor(updateRegion);
|
2015-04-17 09:17:06 +00:00
|
|
|
|
|
|
|
m_painter->end();
|
2020-11-09 14:31:26 +00:00
|
|
|
m_backend->endFrame(screenId, mask, updateRegion);
|
2015-04-17 09:17:06 +00:00
|
|
|
}
|
2013-06-21 08:03:31 +00:00
|
|
|
|
|
|
|
// do cleanup
|
|
|
|
clearStackingOrder();
|
|
|
|
}
|
|
|
|
|
2020-03-13 16:41:56 +00:00
|
|
|
void SceneQPainter::paintBackground(const QRegion ®ion)
|
2013-06-21 08:03:31 +00:00
|
|
|
{
|
|
|
|
m_painter->setBrush(Qt::black);
|
2019-07-09 20:08:47 +00:00
|
|
|
for (const QRect &rect : region) {
|
|
|
|
m_painter->drawRect(rect);
|
|
|
|
}
|
2013-06-21 08:03:31 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 07:39:55 +00:00
|
|
|
void SceneQPainter::paintCursor(const QRegion &rendered)
|
2016-06-28 08:37:02 +00:00
|
|
|
{
|
|
|
|
if (!kwinApp()->platform()->usesSoftwareCursor()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-02 16:18:01 +00:00
|
|
|
|
|
|
|
Cursor* cursor = Cursors::self()->currentCursor();
|
|
|
|
const QImage img = cursor->image();
|
2016-06-28 08:37:02 +00:00
|
|
|
if (img.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-10-26 07:39:55 +00:00
|
|
|
|
|
|
|
m_painter->save();
|
|
|
|
m_painter->setClipRegion(rendered.intersected(cursor->geometry()));
|
|
|
|
m_painter->drawImage(cursor->geometry(), img);
|
|
|
|
m_painter->restore();
|
2016-06-28 08:37:02 +00:00
|
|
|
}
|
|
|
|
|
[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
|
|
|
void SceneQPainter::paintEffectQuickView(EffectQuickView *w)
|
|
|
|
{
|
|
|
|
QPainter *painter = effects->scenePainter();
|
|
|
|
const QImage buffer = w->bufferAsImage();
|
|
|
|
if (buffer.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
painter->drawImage(w->geometry(), buffer);
|
|
|
|
}
|
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
Scene::Window *SceneQPainter::createWindow(Toplevel *toplevel)
|
|
|
|
{
|
|
|
|
return new SceneQPainter::Window(this, toplevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
Scene::EffectFrame *SceneQPainter::createEffectFrame(EffectFrameImpl *frame)
|
|
|
|
{
|
|
|
|
return new QPainterEffectFrame(frame, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Shadow *SceneQPainter::createShadow(Toplevel *toplevel)
|
|
|
|
{
|
|
|
|
return new SceneQPainterShadow(toplevel);
|
|
|
|
}
|
|
|
|
|
2015-03-19 07:29:34 +00:00
|
|
|
void SceneQPainter::screenGeometryChanged(const QSize &size)
|
|
|
|
{
|
|
|
|
Scene::screenGeometryChanged(size);
|
|
|
|
m_backend->screenGeometryChanged(size);
|
|
|
|
}
|
|
|
|
|
2020-11-09 13:39:36 +00:00
|
|
|
QImage *SceneQPainter::qpainterRenderBuffer(int screenId) const
|
2017-08-11 12:59:09 +00:00
|
|
|
{
|
2020-11-09 13:39:36 +00:00
|
|
|
return m_backend->bufferForScreen(screenId);
|
2017-08-11 12:59:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
//****************************************
|
|
|
|
// SceneQPainter::Window
|
|
|
|
//****************************************
|
|
|
|
SceneQPainter::Window::Window(SceneQPainter *scene, Toplevel *c)
|
|
|
|
: Scene::Window(c)
|
|
|
|
, m_scene(scene)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneQPainter::Window::~Window()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-13 16:41:56 +00:00
|
|
|
void SceneQPainter::Window::performPaint(int mask, const QRegion &_region, const WindowPaintData &data)
|
2013-06-21 08:03:31 +00:00
|
|
|
{
|
2020-03-13 16:41:56 +00:00
|
|
|
QRegion region = _region;
|
2013-06-21 08:03:31 +00:00
|
|
|
if (!(mask & (PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED)))
|
|
|
|
region &= toplevel->visibleRect();
|
|
|
|
|
|
|
|
if (region.isEmpty())
|
|
|
|
return;
|
|
|
|
QPainterWindowPixmap *pixmap = windowPixmap<QPainterWindowPixmap>();
|
|
|
|
if (!pixmap || !pixmap->isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-21 08:55:51 +00:00
|
|
|
toplevel->resetDamage();
|
2013-06-21 08:03:31 +00:00
|
|
|
|
2017-08-09 04:56:23 +00:00
|
|
|
QPainter *scenePainter = m_scene->scenePainter();
|
2013-06-21 08:03:31 +00:00
|
|
|
QPainter *painter = scenePainter;
|
2016-06-28 06:38:30 +00:00
|
|
|
painter->save();
|
2013-06-21 08:03:31 +00:00
|
|
|
painter->setClipRegion(region);
|
|
|
|
painter->setClipping(true);
|
|
|
|
|
|
|
|
painter->translate(x(), y());
|
|
|
|
if (mask & PAINT_WINDOW_TRANSFORMED) {
|
|
|
|
painter->translate(data.xTranslation(), data.yTranslation());
|
|
|
|
painter->scale(data.xScale(), data.yScale());
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool opaque = qFuzzyCompare(1.0, data.opacity());
|
|
|
|
QImage tempImage;
|
|
|
|
QPainter tempPainter;
|
|
|
|
if (!opaque) {
|
|
|
|
// need a temp render target which we later on blit to the screen
|
|
|
|
tempImage = QImage(toplevel->visibleRect().size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
tempImage.fill(Qt::transparent);
|
|
|
|
tempPainter.begin(&tempImage);
|
|
|
|
tempPainter.save();
|
2019-09-27 10:01:10 +00:00
|
|
|
tempPainter.translate(toplevel->frameGeometry().topLeft() - toplevel->visibleRect().topLeft());
|
2013-06-21 08:03:31 +00:00
|
|
|
painter = &tempPainter;
|
|
|
|
}
|
|
|
|
renderShadow(painter);
|
|
|
|
renderWindowDecorations(painter);
|
2020-05-23 15:07:54 +00:00
|
|
|
renderWindowPixmap(painter, pixmap);
|
2016-03-21 15:42:30 +00:00
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
if (!opaque) {
|
|
|
|
tempPainter.restore();
|
|
|
|
tempPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
|
|
|
QColor translucent(Qt::transparent);
|
|
|
|
translucent.setAlphaF(data.opacity());
|
|
|
|
tempPainter.fillRect(QRect(QPoint(0, 0), toplevel->visibleRect().size()), translucent);
|
|
|
|
tempPainter.end();
|
|
|
|
painter = scenePainter;
|
2019-09-27 10:01:10 +00:00
|
|
|
painter->drawImage(toplevel->visibleRect().topLeft() - toplevel->frameGeometry().topLeft(), tempImage);
|
2013-06-21 08:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
|
2020-05-23 15:07:54 +00:00
|
|
|
void SceneQPainter::Window::renderWindowPixmap(QPainter *painter, QPainterWindowPixmap *windowPixmap)
|
|
|
|
{
|
|
|
|
const QRegion shape = windowPixmap->shape();
|
2020-08-26 17:24:02 +00:00
|
|
|
for (const QRectF rect : shape) {
|
2020-05-23 15:07:54 +00:00
|
|
|
const QPointF windowTopLeft = windowPixmap->mapToWindow(rect.topLeft());
|
|
|
|
const QPointF windowBottomRight = windowPixmap->mapToWindow(rect.bottomRight());
|
|
|
|
|
|
|
|
const QPointF bufferTopLeft = windowPixmap->mapToBuffer(rect.topLeft());
|
|
|
|
const QPointF bufferBottomRight = windowPixmap->mapToBuffer(rect.bottomRight());
|
|
|
|
|
|
|
|
painter->drawImage(QRectF(windowTopLeft, windowBottomRight),
|
|
|
|
windowPixmap->image(),
|
|
|
|
QRectF(bufferTopLeft, bufferBottomRight));
|
|
|
|
}
|
|
|
|
|
|
|
|
const QVector<WindowPixmap *> children = windowPixmap->children();
|
|
|
|
for (WindowPixmap *child : children) {
|
|
|
|
QPainterWindowPixmap *scenePixmap = static_cast<QPainterWindowPixmap *>(child);
|
|
|
|
if (scenePixmap->isValid()) {
|
|
|
|
renderWindowPixmap(painter, scenePixmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
void SceneQPainter::Window::renderShadow(QPainter* painter)
|
|
|
|
{
|
|
|
|
if (!toplevel->shadow()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SceneQPainterShadow *shadow = static_cast<SceneQPainterShadow *>(toplevel->shadow());
|
2018-06-07 09:08:15 +00:00
|
|
|
|
|
|
|
const QImage &shadowTexture = shadow->shadowTexture();
|
|
|
|
const WindowQuadList &shadowQuads = shadow->shadowQuads();
|
|
|
|
|
|
|
|
for (const auto &q : shadowQuads) {
|
|
|
|
auto topLeft = q[0];
|
|
|
|
auto bottomRight = q[2];
|
|
|
|
QRectF target(topLeft.x(), topLeft.y(),
|
|
|
|
bottomRight.x() - topLeft.x(),
|
|
|
|
bottomRight.y() - topLeft.y());
|
|
|
|
QRectF source(topLeft.textureX(), topLeft.textureY(),
|
|
|
|
bottomRight.textureX() - topLeft.textureX(),
|
|
|
|
bottomRight.textureY() - topLeft.textureY());
|
|
|
|
painter->drawImage(target, shadowTexture, source);
|
|
|
|
}
|
2013-06-21 08:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneQPainter::Window::renderWindowDecorations(QPainter *painter)
|
|
|
|
{
|
|
|
|
// TODO: custom decoration opacity
|
2015-12-03 16:42:38 +00:00
|
|
|
AbstractClient *client = dynamic_cast<AbstractClient*>(toplevel);
|
2013-06-21 08:03:31 +00:00
|
|
|
Deleted *deleted = dynamic_cast<Deleted*>(toplevel);
|
|
|
|
if (!client && !deleted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-23 07:20:28 +00:00
|
|
|
const SceneQPainterDecorationRenderer *renderer = nullptr;
|
2013-06-21 08:03:31 +00:00
|
|
|
QRect dtr, dlr, drr, dbr;
|
2020-11-04 07:22:32 +00:00
|
|
|
if (client && client->isDecorated()) {
|
|
|
|
if (SceneQPainterDecorationRenderer *r = static_cast<SceneQPainterDecorationRenderer *>(client->decoratedClient()->renderer())) {
|
|
|
|
r->render();
|
|
|
|
renderer = r;
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
2014-07-25 10:55:28 +00:00
|
|
|
client->layoutDecorationRects(dlr, dtr, drr, dbr);
|
2020-11-04 07:22:32 +00:00
|
|
|
} else if (deleted && deleted->wasDecorated()) {
|
2013-06-21 08:03:31 +00:00
|
|
|
deleted->layoutDecorationRects(dlr, dtr, drr, dbr);
|
2014-07-23 07:20:28 +00:00
|
|
|
renderer = static_cast<const SceneQPainterDecorationRenderer *>(deleted->decorationRenderer());
|
2013-06-21 08:03:31 +00:00
|
|
|
}
|
2020-11-04 07:22:32 +00:00
|
|
|
if (!renderer) {
|
2013-06-21 08:03:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
painter->drawImage(dtr, renderer->image(SceneQPainterDecorationRenderer::DecorationPart::Top));
|
|
|
|
painter->drawImage(dlr, renderer->image(SceneQPainterDecorationRenderer::DecorationPart::Left));
|
|
|
|
painter->drawImage(drr, renderer->image(SceneQPainterDecorationRenderer::DecorationPart::Right));
|
|
|
|
painter->drawImage(dbr, renderer->image(SceneQPainterDecorationRenderer::DecorationPart::Bottom));
|
2013-06-21 08:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WindowPixmap *SceneQPainter::Window::createWindowPixmap()
|
|
|
|
{
|
|
|
|
return new QPainterWindowPixmap(this);
|
|
|
|
}
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
Decoration::Renderer *SceneQPainter::createDecorationRenderer(Decoration::DecoratedClientImpl *impl)
|
|
|
|
{
|
|
|
|
return new SceneQPainterDecorationRenderer(impl);
|
|
|
|
}
|
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
//****************************************
|
|
|
|
// QPainterWindowPixmap
|
|
|
|
//****************************************
|
|
|
|
QPainterWindowPixmap::QPainterWindowPixmap(Scene::Window *window)
|
|
|
|
: WindowPixmap(window)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-10-31 15:09:34 +00:00
|
|
|
QPainterWindowPixmap::QPainterWindowPixmap(KWaylandServer::SubSurfaceInterface *subSurface, WindowPixmap *parent)
|
2016-03-21 15:42:30 +00:00
|
|
|
: WindowPixmap(subSurface, parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
QPainterWindowPixmap::~QPainterWindowPixmap()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void QPainterWindowPixmap::create()
|
|
|
|
{
|
2015-02-09 17:56:05 +00:00
|
|
|
if (isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-06-21 08:03:31 +00:00
|
|
|
KWin::WindowPixmap::create();
|
|
|
|
if (!isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
if (!surface()) {
|
|
|
|
// That's an internal client.
|
|
|
|
m_image = internalImage();
|
|
|
|
return;
|
|
|
|
}
|
2016-03-21 16:11:35 +00:00
|
|
|
// performing deep copy, this could probably be improved
|
|
|
|
m_image = buffer()->data().copy();
|
2016-03-31 08:22:14 +00:00
|
|
|
if (auto s = surface()) {
|
|
|
|
s->resetTrackedDamage();
|
|
|
|
}
|
2013-06-21 08:03:31 +00:00
|
|
|
}
|
|
|
|
|
2020-10-31 15:09:34 +00:00
|
|
|
WindowPixmap *QPainterWindowPixmap::createChild(KWaylandServer::SubSurfaceInterface *subSurface)
|
2013-06-21 08:03:31 +00:00
|
|
|
{
|
2016-03-21 15:42:30 +00:00
|
|
|
return new QPainterWindowPixmap(subSurface, this);
|
|
|
|
}
|
|
|
|
|
2020-04-21 08:55:51 +00:00
|
|
|
void QPainterWindowPixmap::update()
|
2016-03-21 15:42:30 +00:00
|
|
|
{
|
|
|
|
const auto oldBuffer = buffer();
|
2020-04-21 08:55:51 +00:00
|
|
|
WindowPixmap::update();
|
2016-03-21 15:42:30 +00:00
|
|
|
const auto &b = buffer();
|
2019-08-26 07:44:04 +00:00
|
|
|
if (!surface()) {
|
|
|
|
// That's an internal client.
|
|
|
|
m_image = internalImage();
|
|
|
|
return;
|
|
|
|
}
|
2020-09-18 22:40:57 +00:00
|
|
|
if (!b) {
|
2016-03-21 15:42:30 +00:00
|
|
|
m_image = QImage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (b == oldBuffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// perform deep copy
|
|
|
|
m_image = b->data().copy();
|
2016-03-31 08:22:14 +00:00
|
|
|
if (auto s = surface()) {
|
|
|
|
s->resetTrackedDamage();
|
2013-06-21 08:03:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 07:41:05 +00:00
|
|
|
bool QPainterWindowPixmap::isValid() const
|
|
|
|
{
|
|
|
|
if (!m_image.isNull()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return WindowPixmap::isValid();
|
|
|
|
}
|
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
QPainterEffectFrame::QPainterEffectFrame(EffectFrameImpl *frame, SceneQPainter *scene)
|
|
|
|
: Scene::EffectFrame(frame)
|
|
|
|
, m_scene(scene)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainterEffectFrame::~QPainterEffectFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-13 16:41:56 +00:00
|
|
|
void QPainterEffectFrame::render(const QRegion ®ion, double opacity, double frameOpacity)
|
2013-06-21 08:03:31 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(region)
|
|
|
|
Q_UNUSED(opacity)
|
|
|
|
// TODO: adjust opacity
|
|
|
|
if (m_effectFrame->geometry().isEmpty()) {
|
|
|
|
return; // Nothing to display
|
|
|
|
}
|
2017-08-09 04:56:23 +00:00
|
|
|
QPainter *painter = m_scene->scenePainter();
|
2013-06-21 08:03:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Render the actual frame
|
|
|
|
if (m_effectFrame->style() == EffectFrameUnstyled) {
|
|
|
|
painter->save();
|
|
|
|
painter->setPen(Qt::NoPen);
|
|
|
|
QColor color(Qt::black);
|
|
|
|
color.setAlphaF(frameOpacity);
|
|
|
|
painter->setBrush(color);
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter->drawRoundedRect(m_effectFrame->geometry().adjusted(-5, -5, 5, 5), 5.0, 5.0);
|
|
|
|
painter->restore();
|
|
|
|
} else if (m_effectFrame->style() == EffectFrameStyled) {
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
m_effectFrame->frame().getMargins(left, top, right, bottom); // m_geometry is the inner geometry
|
|
|
|
QRect geom = m_effectFrame->geometry().adjusted(-left, -top, right, bottom);
|
|
|
|
painter->drawPixmap(geom, m_effectFrame->frame().framePixmap());
|
|
|
|
}
|
|
|
|
if (!m_effectFrame->selection().isNull()) {
|
|
|
|
painter->drawPixmap(m_effectFrame->selection(), m_effectFrame->selectionFrame().framePixmap());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render icon
|
|
|
|
if (!m_effectFrame->icon().isNull() && !m_effectFrame->iconSize().isEmpty()) {
|
|
|
|
const QPoint topLeft(m_effectFrame->geometry().x(),
|
|
|
|
m_effectFrame->geometry().center().y() - m_effectFrame->iconSize().height() / 2);
|
|
|
|
|
|
|
|
const QRect geom = QRect(topLeft, m_effectFrame->iconSize());
|
|
|
|
painter->drawPixmap(geom, m_effectFrame->icon().pixmap(m_effectFrame->iconSize()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render text
|
|
|
|
if (!m_effectFrame->text().isEmpty()) {
|
|
|
|
// Determine position on texture to paint text
|
|
|
|
QRect rect(QPoint(0, 0), m_effectFrame->geometry().size());
|
|
|
|
if (!m_effectFrame->icon().isNull() && !m_effectFrame->iconSize().isEmpty()) {
|
|
|
|
rect.setLeft(m_effectFrame->iconSize().width());
|
|
|
|
}
|
|
|
|
|
|
|
|
// If static size elide text as required
|
|
|
|
QString text = m_effectFrame->text();
|
|
|
|
if (m_effectFrame->isStatic()) {
|
|
|
|
QFontMetrics metrics(m_effectFrame->text());
|
|
|
|
text = metrics.elidedText(text, Qt::ElideRight, rect.width());
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
painter->setFont(m_effectFrame->font());
|
|
|
|
if (m_effectFrame->style() == EffectFrameStyled) {
|
|
|
|
painter->setPen(m_effectFrame->styledTextColor());
|
|
|
|
} else {
|
|
|
|
// TODO: What about no frame? Custom color setting required
|
|
|
|
painter->setPen(Qt::white);
|
|
|
|
}
|
|
|
|
painter->drawText(rect.translated(m_effectFrame->geometry().topLeft()), m_effectFrame->alignment(), text);
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// QPainterShadow
|
|
|
|
//****************************************
|
|
|
|
SceneQPainterShadow::SceneQPainterShadow(Toplevel* toplevel)
|
|
|
|
: Shadow(toplevel)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneQPainterShadow::~SceneQPainterShadow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-07 09:08:15 +00:00
|
|
|
void SceneQPainterShadow::buildQuads()
|
|
|
|
{
|
|
|
|
// Do not draw shadows if window width or window height is less than
|
|
|
|
// 5 px. 5 is an arbitrary choice.
|
|
|
|
if (topLevel()->width() < 5 || topLevel()->height() < 5) {
|
|
|
|
m_shadowQuads.clear();
|
|
|
|
setShadowRegion(QRegion());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QSizeF top(elementSize(ShadowElementTop));
|
|
|
|
const QSizeF topRight(elementSize(ShadowElementTopRight));
|
|
|
|
const QSizeF right(elementSize(ShadowElementRight));
|
|
|
|
const QSizeF bottomRight(elementSize(ShadowElementBottomRight));
|
|
|
|
const QSizeF bottom(elementSize(ShadowElementBottom));
|
|
|
|
const QSizeF bottomLeft(elementSize(ShadowElementBottomLeft));
|
|
|
|
const QSizeF left(elementSize(ShadowElementLeft));
|
|
|
|
const QSizeF topLeft(elementSize(ShadowElementTopLeft));
|
|
|
|
|
|
|
|
const QRectF outerRect(QPointF(-leftOffset(), -topOffset()),
|
|
|
|
QPointF(topLevel()->width() + rightOffset(),
|
|
|
|
topLevel()->height() + bottomOffset()));
|
|
|
|
|
|
|
|
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()});
|
|
|
|
|
|
|
|
QRectF topLeftRect(outerRect.topLeft(), topLeft);
|
|
|
|
QRectF topRightRect(outerRect.topRight() - QPointF(topRight.width(), 0), topRight);
|
|
|
|
QRectF bottomRightRect(
|
|
|
|
outerRect.bottomRight() - QPointF(bottomRight.width(), bottomRight.height()),
|
|
|
|
bottomRight);
|
|
|
|
QRectF bottomLeftRect(outerRect.bottomLeft() - QPointF(0, bottomLeft.height()), bottomLeft);
|
|
|
|
|
|
|
|
// Re-distribute the corner tiles so no one of them is overlapping with others.
|
|
|
|
// By doing this, we assume that shadow's corner tiles are symmetric
|
|
|
|
// and it is OK to not draw top/right/bottom/left tile between corners.
|
|
|
|
// For example, let's say top-left and top-right tiles are overlapping.
|
|
|
|
// In that case, the right side of the top-left tile will be shifted to left,
|
|
|
|
// the left side of the top-right tile will shifted to right, and the top
|
|
|
|
// tile won't be rendered.
|
|
|
|
bool drawTop = true;
|
|
|
|
if (topLeftRect.right() >= topRightRect.left()) {
|
|
|
|
const float halfOverlap = qAbs(topLeftRect.right() - topRightRect.left()) / 2;
|
|
|
|
topLeftRect.setRight(topLeftRect.right() - std::floor(halfOverlap));
|
|
|
|
topRightRect.setLeft(topRightRect.left() + std::ceil(halfOverlap));
|
|
|
|
drawTop = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool drawRight = true;
|
|
|
|
if (topRightRect.bottom() >= bottomRightRect.top()) {
|
|
|
|
const float halfOverlap = qAbs(topRightRect.bottom() - bottomRightRect.top()) / 2;
|
|
|
|
topRightRect.setBottom(topRightRect.bottom() - std::floor(halfOverlap));
|
|
|
|
bottomRightRect.setTop(bottomRightRect.top() + std::ceil(halfOverlap));
|
|
|
|
drawRight = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool drawBottom = true;
|
|
|
|
if (bottomLeftRect.right() >= bottomRightRect.left()) {
|
|
|
|
const float halfOverlap = qAbs(bottomLeftRect.right() - bottomRightRect.left()) / 2;
|
|
|
|
bottomLeftRect.setRight(bottomLeftRect.right() - std::floor(halfOverlap));
|
|
|
|
bottomRightRect.setLeft(bottomRightRect.left() + std::ceil(halfOverlap));
|
|
|
|
drawBottom = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool drawLeft = true;
|
|
|
|
if (topLeftRect.bottom() >= bottomLeftRect.top()) {
|
|
|
|
const float halfOverlap = qAbs(topLeftRect.bottom() - bottomLeftRect.top()) / 2;
|
|
|
|
topLeftRect.setBottom(topLeftRect.bottom() - std::floor(halfOverlap));
|
|
|
|
bottomLeftRect.setTop(bottomLeftRect.top() + std::ceil(halfOverlap));
|
|
|
|
drawLeft = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal tx1 = 0.0,
|
|
|
|
tx2 = 0.0,
|
|
|
|
ty1 = 0.0,
|
|
|
|
ty2 = 0.0;
|
|
|
|
|
|
|
|
m_shadowQuads.clear();
|
|
|
|
|
|
|
|
tx1 = 0.0;
|
|
|
|
ty1 = 0.0;
|
|
|
|
tx2 = topLeftRect.width();
|
|
|
|
ty2 = topLeftRect.height();
|
|
|
|
WindowQuad topLeftQuad(WindowQuadShadow);
|
|
|
|
topLeftQuad[0] = WindowVertex(topLeftRect.left(), topLeftRect.top(), tx1, ty1);
|
|
|
|
topLeftQuad[1] = WindowVertex(topLeftRect.right(), topLeftRect.top(), tx2, ty1);
|
|
|
|
topLeftQuad[2] = WindowVertex(topLeftRect.right(), topLeftRect.bottom(), tx2, ty2);
|
|
|
|
topLeftQuad[3] = WindowVertex(topLeftRect.left(), topLeftRect.bottom(), tx1, ty2);
|
|
|
|
m_shadowQuads.append(topLeftQuad);
|
|
|
|
|
|
|
|
tx1 = width - topRightRect.width();
|
|
|
|
ty1 = 0.0;
|
|
|
|
tx2 = width;
|
|
|
|
ty2 = topRightRect.height();
|
|
|
|
WindowQuad topRightQuad(WindowQuadShadow);
|
|
|
|
topRightQuad[0] = WindowVertex(topRightRect.left(), topRightRect.top(), tx1, ty1);
|
|
|
|
topRightQuad[1] = WindowVertex(topRightRect.right(), topRightRect.top(), tx2, ty1);
|
|
|
|
topRightQuad[2] = WindowVertex(topRightRect.right(), topRightRect.bottom(), tx2, ty2);
|
|
|
|
topRightQuad[3] = WindowVertex(topRightRect.left(), topRightRect.bottom(), tx1, ty2);
|
|
|
|
m_shadowQuads.append(topRightQuad);
|
|
|
|
|
|
|
|
tx1 = width - bottomRightRect.width();
|
|
|
|
tx2 = width;
|
|
|
|
ty1 = height - bottomRightRect.height();
|
|
|
|
ty2 = height;
|
|
|
|
WindowQuad bottomRightQuad(WindowQuadShadow);
|
|
|
|
bottomRightQuad[0] = WindowVertex(bottomRightRect.left(), bottomRightRect.top(), tx1, ty1);
|
|
|
|
bottomRightQuad[1] = WindowVertex(bottomRightRect.right(), bottomRightRect.top(), tx2, ty1);
|
|
|
|
bottomRightQuad[2] = WindowVertex(bottomRightRect.right(), bottomRightRect.bottom(), tx2, ty2);
|
|
|
|
bottomRightQuad[3] = WindowVertex(bottomRightRect.left(), bottomRightRect.bottom(), tx1, ty2);
|
|
|
|
m_shadowQuads.append(bottomRightQuad);
|
|
|
|
|
|
|
|
tx1 = 0.0;
|
|
|
|
tx2 = bottomLeftRect.width();
|
|
|
|
ty1 = height - bottomLeftRect.height();
|
|
|
|
ty2 = height;
|
|
|
|
WindowQuad bottomLeftQuad(WindowQuadShadow);
|
|
|
|
bottomLeftQuad[0] = WindowVertex(bottomLeftRect.left(), bottomLeftRect.top(), tx1, ty1);
|
|
|
|
bottomLeftQuad[1] = WindowVertex(bottomLeftRect.right(), bottomLeftRect.top(), tx2, ty1);
|
|
|
|
bottomLeftQuad[2] = WindowVertex(bottomLeftRect.right(), bottomLeftRect.bottom(), tx2, ty2);
|
|
|
|
bottomLeftQuad[3] = WindowVertex(bottomLeftRect.left(), bottomLeftRect.bottom(), tx1, ty2);
|
|
|
|
m_shadowQuads.append(bottomLeftQuad);
|
|
|
|
|
|
|
|
if (drawTop) {
|
|
|
|
QRectF topRect(
|
|
|
|
topLeftRect.topRight(),
|
|
|
|
topRightRect.bottomLeft());
|
|
|
|
tx1 = topLeft.width();
|
|
|
|
ty1 = 0.0;
|
|
|
|
tx2 = width - topRight.width();
|
|
|
|
ty2 = topRect.height();
|
|
|
|
WindowQuad topQuad(WindowQuadShadow);
|
|
|
|
topQuad[0] = WindowVertex(topRect.left(), topRect.top(), tx1, ty1);
|
|
|
|
topQuad[1] = WindowVertex(topRect.right(), topRect.top(), tx2, ty1);
|
|
|
|
topQuad[2] = WindowVertex(topRect.right(), topRect.bottom(), tx2, ty2);
|
|
|
|
topQuad[3] = WindowVertex(topRect.left(), topRect.bottom(), tx1, ty2);
|
|
|
|
m_shadowQuads.append(topQuad);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drawRight) {
|
|
|
|
QRectF rightRect(
|
|
|
|
topRightRect.bottomLeft(),
|
|
|
|
bottomRightRect.topRight());
|
|
|
|
tx1 = width - rightRect.width();
|
|
|
|
ty1 = topRight.height();
|
|
|
|
tx2 = width;
|
|
|
|
ty2 = height - bottomRight.height();
|
|
|
|
WindowQuad rightQuad(WindowQuadShadow);
|
|
|
|
rightQuad[0] = WindowVertex(rightRect.left(), rightRect.top(), tx1, ty1);
|
|
|
|
rightQuad[1] = WindowVertex(rightRect.right(), rightRect.top(), tx2, ty1);
|
|
|
|
rightQuad[2] = WindowVertex(rightRect.right(), rightRect.bottom(), tx2, ty2);
|
|
|
|
rightQuad[3] = WindowVertex(rightRect.left(), rightRect.bottom(), tx1, ty2);
|
|
|
|
m_shadowQuads.append(rightQuad);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drawBottom) {
|
|
|
|
QRectF bottomRect(
|
|
|
|
bottomLeftRect.topRight(),
|
|
|
|
bottomRightRect.bottomLeft());
|
|
|
|
tx1 = bottomLeft.width();
|
|
|
|
ty1 = height - bottomRect.height();
|
|
|
|
tx2 = width - bottomRight.width();
|
|
|
|
ty2 = height;
|
|
|
|
WindowQuad bottomQuad(WindowQuadShadow);
|
|
|
|
bottomQuad[0] = WindowVertex(bottomRect.left(), bottomRect.top(), tx1, ty1);
|
|
|
|
bottomQuad[1] = WindowVertex(bottomRect.right(), bottomRect.top(), tx2, ty1);
|
|
|
|
bottomQuad[2] = WindowVertex(bottomRect.right(), bottomRect.bottom(), tx2, ty2);
|
|
|
|
bottomQuad[3] = WindowVertex(bottomRect.left(), bottomRect.bottom(), tx1, ty2);
|
|
|
|
m_shadowQuads.append(bottomQuad);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drawLeft) {
|
|
|
|
QRectF leftRect(
|
|
|
|
topLeftRect.bottomLeft(),
|
|
|
|
bottomLeftRect.topRight());
|
|
|
|
tx1 = 0.0;
|
|
|
|
ty1 = topLeft.height();
|
|
|
|
tx2 = leftRect.width();
|
|
|
|
ty2 = height - bottomRight.height();
|
|
|
|
WindowQuad leftQuad(WindowQuadShadow);
|
|
|
|
leftQuad[0] = WindowVertex(leftRect.left(), leftRect.top(), tx1, ty1);
|
|
|
|
leftQuad[1] = WindowVertex(leftRect.right(), leftRect.top(), tx2, ty1);
|
|
|
|
leftQuad[2] = WindowVertex(leftRect.right(), leftRect.bottom(), tx2, ty2);
|
|
|
|
leftQuad[3] = WindowVertex(leftRect.left(), leftRect.bottom(), tx1, ty2);
|
|
|
|
m_shadowQuads.append(leftQuad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
bool SceneQPainterShadow::prepareBackend()
|
|
|
|
{
|
2014-07-24 06:39:25 +00:00
|
|
|
if (hasDecorationShadow()) {
|
2018-06-07 09:08:15 +00:00
|
|
|
m_texture = decorationShadowImage();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QPixmap &topLeft = shadowPixmap(ShadowElementTopLeft);
|
|
|
|
const QPixmap &top = shadowPixmap(ShadowElementTop);
|
|
|
|
const QPixmap &topRight = shadowPixmap(ShadowElementTopRight);
|
|
|
|
const QPixmap &bottomLeft = shadowPixmap(ShadowElementBottomLeft);
|
|
|
|
const QPixmap &bottom = shadowPixmap(ShadowElementBottom);
|
|
|
|
const QPixmap &bottomRight = shadowPixmap(ShadowElementBottomRight);
|
|
|
|
const QPixmap &left = shadowPixmap(ShadowElementLeft);
|
|
|
|
const QPixmap &right = shadowPixmap(ShadowElementRight);
|
|
|
|
|
|
|
|
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()});
|
|
|
|
|
|
|
|
if (width == 0 || height == 0) {
|
2014-07-24 06:39:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-06-07 09:08:15 +00:00
|
|
|
|
|
|
|
QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter painter;
|
|
|
|
painter.begin(&image);
|
2020-07-12 00:04:56 +00:00
|
|
|
painter.drawPixmap(0, 0, topLeft.width(), topLeft.height(), topLeft);
|
|
|
|
painter.drawPixmap(topLeft.width(), 0, top.width(), top.height(), top);
|
|
|
|
painter.drawPixmap(width - topRight.width(), 0, topRight.width(), topRight.height(), topRight);
|
|
|
|
painter.drawPixmap(0, height - bottomLeft.height(), bottomLeft.width(), bottomLeft.height(), bottomLeft);
|
|
|
|
painter.drawPixmap(bottomLeft.width(), height - bottom.height(), bottom.width(), bottom.height(), bottom);
|
|
|
|
painter.drawPixmap(width - bottomRight.width(), height - bottomRight.height(), bottomRight.width(), bottomRight.height(), bottomRight);
|
|
|
|
painter.drawPixmap(0, topLeft.height(), left.width(), left.height(), left);
|
|
|
|
painter.drawPixmap(width - right.width(), topRight.height(), right.width(), right.height(), right);
|
2018-06-07 09:08:15 +00:00
|
|
|
painter.end();
|
|
|
|
|
|
|
|
m_texture = image;
|
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
//****************************************
|
|
|
|
// QPainterDecorationRenderer
|
|
|
|
//****************************************
|
|
|
|
SceneQPainterDecorationRenderer::SceneQPainterDecorationRenderer(Decoration::DecoratedClientImpl *client)
|
|
|
|
: Renderer(client)
|
|
|
|
{
|
2015-12-03 16:12:25 +00:00
|
|
|
connect(this, &Renderer::renderScheduled, client->client(), static_cast<void (AbstractClient::*)(const QRect&)>(&AbstractClient::addRepaint));
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SceneQPainterDecorationRenderer::~SceneQPainterDecorationRenderer() = default;
|
|
|
|
|
|
|
|
QImage SceneQPainterDecorationRenderer::image(SceneQPainterDecorationRenderer::DecorationPart part) const
|
|
|
|
{
|
|
|
|
Q_ASSERT(part != DecorationPart::Count);
|
|
|
|
return m_images[int(part)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneQPainterDecorationRenderer::render()
|
|
|
|
{
|
|
|
|
const QRegion scheduled = getScheduled();
|
|
|
|
if (scheduled.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (areImageSizesDirty()) {
|
|
|
|
resizeImages();
|
|
|
|
resetImageSizesDirty();
|
|
|
|
}
|
|
|
|
|
2017-10-30 13:27:48 +00:00
|
|
|
auto imageSize = [this](DecorationPart part) {
|
|
|
|
return m_images[int(part)].size() / m_images[int(part)].devicePixelRatio();
|
|
|
|
};
|
|
|
|
|
|
|
|
const QRect top(QPoint(0, 0), imageSize(DecorationPart::Top));
|
|
|
|
const QRect left(QPoint(0, top.height()), imageSize(DecorationPart::Left));
|
|
|
|
const QRect right(QPoint(top.width() - imageSize(DecorationPart::Right).width(), top.height()), imageSize(DecorationPart::Right));
|
|
|
|
const QRect bottom(QPoint(0, left.y() + left.height()), imageSize(DecorationPart::Bottom));
|
2014-07-22 11:11:19 +00:00
|
|
|
|
|
|
|
const QRect geometry = scheduled.boundingRect();
|
|
|
|
auto renderPart = [this](const QRect &rect, const QRect &partRect, int index) {
|
|
|
|
if (rect.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QPainter painter(&m_images[index]);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
2017-10-30 13:27:48 +00:00
|
|
|
painter.setWindow(QRect(partRect.topLeft(), partRect.size() * m_images[index].devicePixelRatio()));
|
2014-07-22 11:11:19 +00:00
|
|
|
painter.setClipRect(rect);
|
|
|
|
painter.save();
|
|
|
|
// clear existing part
|
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
2015-04-02 15:39:02 +00:00
|
|
|
painter.fillRect(rect, Qt::transparent);
|
2014-07-22 11:11:19 +00:00
|
|
|
painter.restore();
|
2014-11-11 08:39:45 +00:00
|
|
|
client()->decoration()->paint(&painter, rect);
|
2014-07-22 11:11:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
renderPart(left.intersected(geometry), left, int(DecorationPart::Left));
|
|
|
|
renderPart(top.intersected(geometry), top, int(DecorationPart::Top));
|
|
|
|
renderPart(right.intersected(geometry), right, int(DecorationPart::Right));
|
|
|
|
renderPart(bottom.intersected(geometry), bottom, int(DecorationPart::Bottom));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneQPainterDecorationRenderer::resizeImages()
|
|
|
|
{
|
|
|
|
QRect left, top, right, bottom;
|
2014-07-25 10:55:28 +00:00
|
|
|
client()->client()->layoutDecorationRects(left, top, right, bottom);
|
2014-07-22 11:11:19 +00:00
|
|
|
|
|
|
|
auto checkAndCreate = [this](int index, const QSize &size) {
|
2017-11-01 17:54:21 +00:00
|
|
|
auto dpr = client()->client()->screenScale();
|
2017-10-30 13:27:48 +00:00
|
|
|
if (m_images[index].size() != size * dpr ||
|
|
|
|
m_images[index].devicePixelRatio() != dpr)
|
|
|
|
{
|
|
|
|
m_images[index] = QImage(size * dpr, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
m_images[index].setDevicePixelRatio(dpr);
|
2014-07-22 11:11:19 +00:00
|
|
|
m_images[index].fill(Qt::transparent);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
checkAndCreate(int(DecorationPart::Left), left.size());
|
|
|
|
checkAndCreate(int(DecorationPart::Right), right.size());
|
|
|
|
checkAndCreate(int(DecorationPart::Top), top.size());
|
|
|
|
checkAndCreate(int(DecorationPart::Bottom), bottom.size());
|
|
|
|
}
|
|
|
|
|
2014-07-23 07:20:28 +00:00
|
|
|
void SceneQPainterDecorationRenderer::reparent(Deleted *deleted)
|
|
|
|
{
|
|
|
|
render();
|
|
|
|
Renderer::reparent(deleted);
|
|
|
|
}
|
|
|
|
|
2017-08-11 19:40:49 +00:00
|
|
|
|
|
|
|
QPainterFactory::QPainterFactory(QObject *parent)
|
|
|
|
: SceneFactory(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainterFactory::~QPainterFactory() = default;
|
|
|
|
|
|
|
|
Scene *QPainterFactory::create(QObject *parent) const
|
|
|
|
{
|
|
|
|
auto s = SceneQPainter::createScene(parent);
|
|
|
|
if (s && s->initFailed()) {
|
|
|
|
delete s;
|
|
|
|
s = nullptr;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-06-21 08:03:31 +00:00
|
|
|
} // KWin
|