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: 2007 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
|
|
|
|
SPDX-FileCopyrightText: 2011 Martin Gräßlin <mgraesslin@kde.org>
|
2020-08-02 22:10:35 +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 "magnifier.h"
|
2012-09-13 20:25:18 +00:00
|
|
|
// KConfigSkeleton
|
|
|
|
#include "magnifierconfig.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-08-14 19:13:12 +00:00
|
|
|
#include <QAction>
|
2008-05-30 17:47:24 +00:00
|
|
|
#include <kwinconfig.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kstandardaction.h>
|
|
|
|
|
2011-01-06 13:29:13 +00:00
|
|
|
#include <kwinglutils.h>
|
2012-05-26 07:05:05 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2012-03-09 01:20:01 +00:00
|
|
|
#include <kwinxrenderutils.h>
|
2013-01-28 18:54:27 +00:00
|
|
|
#include <xcb/render.h>
|
2012-05-26 07:05:05 +00:00
|
|
|
#endif
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KGlobalAccel>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
const int FRAME_WIDTH = 5;
|
|
|
|
|
|
|
|
MagnifierEffect::MagnifierEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
: zoom(1)
|
|
|
|
, target_zoom(1)
|
|
|
|
, polling(false)
|
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
|
|
|
, m_texture(nullptr)
|
|
|
|
, m_fbo(nullptr)
|
2013-01-28 18:54:27 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
, m_pixmap(XCB_PIXMAP_NONE)
|
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-12-02 19:27:43 +00:00
|
|
|
initConfig<MagnifierConfig>();
|
2013-08-14 19:13:12 +00:00
|
|
|
QAction* a;
|
2013-12-10 10:45:33 +00:00
|
|
|
a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this);
|
2013-08-14 19:13:12 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal);
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal);
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(Qt::META + Qt::Key_Equal, a);
|
2013-08-14 19:13:12 +00:00
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
a = KStandardAction::zoomOut(this, SLOT(zoomOut()), this);
|
2013-08-14 19:13:12 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Minus);
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Minus);
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(Qt::META + Qt::Key_Minus, a);
|
2013-08-14 19:13:12 +00:00
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
a = KStandardAction::actualSize(this, SLOT(toggle()), this);
|
2013-08-14 19:13:12 +00:00
|
|
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_0);
|
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_0);
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(Qt::META + Qt::Key_0, a);
|
2013-08-14 19:13:12 +00:00
|
|
|
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(effects, &EffectsHandler::mouseChanged, this, &MagnifierEffect::slotMouseChanged);
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
|
|
|
}
|
2007-11-13 16:20:52 +00:00
|
|
|
|
2011-08-20 08:53:36 +00:00
|
|
|
MagnifierEffect::~MagnifierEffect()
|
|
|
|
{
|
|
|
|
delete m_fbo;
|
|
|
|
delete m_texture;
|
2013-01-28 18:54:27 +00:00
|
|
|
destroyPixmap();
|
2012-04-13 10:05:23 +00:00
|
|
|
// Save the zoom value.
|
2016-11-11 10:10:05 +00:00
|
|
|
MagnifierConfig::setInitialZoom(target_zoom);
|
|
|
|
MagnifierConfig::self()->save();
|
2011-08-20 08:53:36 +00:00
|
|
|
}
|
|
|
|
|
2013-01-28 18:54:27 +00:00
|
|
|
void MagnifierEffect::destroyPixmap()
|
|
|
|
{
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
if (effects->compositingType() != XRenderCompositing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_picture.reset();
|
|
|
|
if (m_pixmap != XCB_PIXMAP_NONE) {
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_free_pixmap(xcbConnection(), m_pixmap);
|
2013-03-11 15:17:52 +00:00
|
|
|
m_pixmap = XCB_PIXMAP_NONE;
|
2013-01-28 18:54:27 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-06-26 16:51:08 +00:00
|
|
|
bool MagnifierEffect::supported()
|
|
|
|
{
|
2012-03-09 01:20:01 +00:00
|
|
|
return effects->compositingType() == XRenderCompositing ||
|
2012-09-20 09:33:32 +00:00
|
|
|
(effects->isOpenGLCompositing() && GLRenderTarget::blitSupported());
|
2011-06-26 16:51:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void MagnifierEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2014-03-25 15:29:03 +00:00
|
|
|
MagnifierConfig::self()->read();
|
2007-11-13 16:20:52 +00:00
|
|
|
int width, height;
|
2012-09-13 20:25:18 +00:00
|
|
|
width = MagnifierConfig::width();
|
|
|
|
height = MagnifierConfig::height();
|
2011-01-30 14:34:42 +00:00
|
|
|
magnifier_size = QSize(width, height);
|
2012-04-13 10:05:23 +00:00
|
|
|
// Load the saved zoom value.
|
2012-09-13 20:25:18 +00:00
|
|
|
target_zoom = MagnifierConfig::initialZoom();
|
2012-04-13 10:05:23 +00:00
|
|
|
if (target_zoom != zoom)
|
|
|
|
toggle();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void MagnifierEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (zoom != target_zoom) {
|
|
|
|
double diff = time / animationTime(500.0);
|
|
|
|
if (target_zoom > zoom)
|
|
|
|
zoom = qMin(zoom * qMax(1 + diff, 1.2), target_zoom);
|
2011-09-07 07:31:31 +00:00
|
|
|
else {
|
2011-01-30 14:34:42 +00:00
|
|
|
zoom = qMax(zoom * qMin(1 - diff, 0.8), target_zoom);
|
2011-09-07 07:31:31 +00:00
|
|
|
if (zoom == 1.0) {
|
|
|
|
// zoom ended - delete FBO and texture
|
|
|
|
delete m_fbo;
|
|
|
|
delete m_texture;
|
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
|
|
|
m_fbo = nullptr;
|
|
|
|
m_texture = nullptr;
|
2013-01-28 18:54:27 +00:00
|
|
|
destroyPixmap();
|
2011-09-07 07:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
if (zoom != 1.0)
|
|
|
|
data.paint |= magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void MagnifierEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data); // paint normal screen
|
|
|
|
if (zoom != 1.0) {
|
2011-08-20 08:53:36 +00:00
|
|
|
// get the right area from the current rendered screen
|
|
|
|
const QRect area = magnifierArea();
|
|
|
|
const QPoint cursor = cursorPos();
|
2012-03-09 01:20:01 +00:00
|
|
|
|
|
|
|
QRect srcArea(cursor.x() - (double)area.width() / (zoom*2),
|
|
|
|
cursor.y() - (double)area.height() / (zoom*2),
|
|
|
|
(double)area.width() / zoom, (double)area.height() / zoom);
|
2012-09-20 09:33:32 +00:00
|
|
|
if (effects->isOpenGLCompositing()) {
|
2012-03-09 01:20:01 +00:00
|
|
|
m_fbo->blitFromFramebuffer(srcArea);
|
|
|
|
// paint magnifier
|
|
|
|
m_texture->bind();
|
2015-08-27 20:16:49 +00:00
|
|
|
auto s = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
|
|
|
QMatrix4x4 mvp;
|
|
|
|
const QSize size = effects->virtualScreenSize();
|
|
|
|
mvp.ortho(0, size.width(), size.height(), 0, 0, 65535);
|
|
|
|
mvp.translate(area.x(), area.y());
|
|
|
|
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
2012-03-09 01:20:01 +00:00
|
|
|
m_texture->render(infiniteRegion(), area);
|
2015-08-27 20:16:49 +00:00
|
|
|
ShaderManager::instance()->popShader();
|
2012-03-09 01:20:01 +00:00
|
|
|
m_texture->unbind();
|
|
|
|
QVector<float> verts;
|
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
|
|
|
vbo->reset();
|
|
|
|
vbo->setColor(QColor(0, 0, 0));
|
[effects/magnifier] Fix 1 px gap between magnified area and frame
Summary:
The x-coordinate of the area's left edge and y-coordinate of the area's
top edge are adjusted by 1px leading to a gap between the frame and
magnified area. Because area has type of QRect, we have to adjust only
coordinates of the right and bottom edge by 1 px.
Because QRectF::right() == QRectF::x() + QRectF::width(), we can use
QRectF, which leads to more cleaner code because we don't need to do 1px
adjustments.
Test Plan:
Before:
{F6235388, layout=center, size=full}
After:
{F6235439, layout=center, size=full}
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15275
2018-09-04 18:03:36 +00:00
|
|
|
const QRectF areaF = area;
|
2012-03-09 01:20:01 +00:00
|
|
|
// top frame
|
[effects/magnifier] Fix 1 px gap between magnified area and frame
Summary:
The x-coordinate of the area's left edge and y-coordinate of the area's
top edge are adjusted by 1px leading to a gap between the frame and
magnified area. Because area has type of QRect, we have to adjust only
coordinates of the right and bottom edge by 1 px.
Because QRectF::right() == QRectF::x() + QRectF::width(), we can use
QRectF, which leads to more cleaner code because we don't need to do 1px
adjustments.
Test Plan:
Before:
{F6235388, layout=center, size=full}
After:
{F6235439, layout=center, size=full}
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15275
2018-09-04 18:03:36 +00:00
|
|
|
verts << areaF.right() + FRAME_WIDTH << areaF.top() - FRAME_WIDTH;
|
|
|
|
verts << areaF.left() - FRAME_WIDTH << areaF.top() - FRAME_WIDTH;
|
|
|
|
verts << areaF.left() - FRAME_WIDTH << areaF.top();
|
|
|
|
verts << areaF.left() - FRAME_WIDTH << areaF.top();
|
|
|
|
verts << areaF.right() + FRAME_WIDTH << areaF.top();
|
|
|
|
verts << areaF.right() + FRAME_WIDTH << areaF.top() - FRAME_WIDTH;
|
2012-03-09 01:20:01 +00:00
|
|
|
// left frame
|
[effects/magnifier] Fix 1 px gap between magnified area and frame
Summary:
The x-coordinate of the area's left edge and y-coordinate of the area's
top edge are adjusted by 1px leading to a gap between the frame and
magnified area. Because area has type of QRect, we have to adjust only
coordinates of the right and bottom edge by 1 px.
Because QRectF::right() == QRectF::x() + QRectF::width(), we can use
QRectF, which leads to more cleaner code because we don't need to do 1px
adjustments.
Test Plan:
Before:
{F6235388, layout=center, size=full}
After:
{F6235439, layout=center, size=full}
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15275
2018-09-04 18:03:36 +00:00
|
|
|
verts << areaF.left() << areaF.top() - FRAME_WIDTH;
|
|
|
|
verts << areaF.left() - FRAME_WIDTH << areaF.top() - FRAME_WIDTH;
|
|
|
|
verts << areaF.left() - FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH;
|
|
|
|
verts << areaF.left() - FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH;
|
|
|
|
verts << areaF.left() << areaF.bottom() + FRAME_WIDTH;
|
|
|
|
verts << areaF.left() << areaF.top() - FRAME_WIDTH;
|
2012-03-09 01:20:01 +00:00
|
|
|
// right frame
|
[effects/magnifier] Fix 1 px gap between magnified area and frame
Summary:
The x-coordinate of the area's left edge and y-coordinate of the area's
top edge are adjusted by 1px leading to a gap between the frame and
magnified area. Because area has type of QRect, we have to adjust only
coordinates of the right and bottom edge by 1 px.
Because QRectF::right() == QRectF::x() + QRectF::width(), we can use
QRectF, which leads to more cleaner code because we don't need to do 1px
adjustments.
Test Plan:
Before:
{F6235388, layout=center, size=full}
After:
{F6235439, layout=center, size=full}
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15275
2018-09-04 18:03:36 +00:00
|
|
|
verts << areaF.right() + FRAME_WIDTH << areaF.top() - FRAME_WIDTH;
|
|
|
|
verts << areaF.right() << areaF.top() - FRAME_WIDTH;
|
|
|
|
verts << areaF.right() << areaF.bottom() + FRAME_WIDTH;
|
|
|
|
verts << areaF.right() << areaF.bottom() + FRAME_WIDTH;
|
|
|
|
verts << areaF.right() + FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH;
|
|
|
|
verts << areaF.right() + FRAME_WIDTH << areaF.top() - FRAME_WIDTH;
|
2012-03-09 01:20:01 +00:00
|
|
|
// bottom frame
|
[effects/magnifier] Fix 1 px gap between magnified area and frame
Summary:
The x-coordinate of the area's left edge and y-coordinate of the area's
top edge are adjusted by 1px leading to a gap between the frame and
magnified area. Because area has type of QRect, we have to adjust only
coordinates of the right and bottom edge by 1 px.
Because QRectF::right() == QRectF::x() + QRectF::width(), we can use
QRectF, which leads to more cleaner code because we don't need to do 1px
adjustments.
Test Plan:
Before:
{F6235388, layout=center, size=full}
After:
{F6235439, layout=center, size=full}
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15275
2018-09-04 18:03:36 +00:00
|
|
|
verts << areaF.right() + FRAME_WIDTH << areaF.bottom();
|
|
|
|
verts << areaF.left() - FRAME_WIDTH << areaF.bottom();
|
|
|
|
verts << areaF.left() - FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH;
|
|
|
|
verts << areaF.left() - FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH;
|
|
|
|
verts << areaF.right() + FRAME_WIDTH << areaF.bottom() + FRAME_WIDTH;
|
|
|
|
verts << areaF.right() + FRAME_WIDTH << areaF.bottom();
|
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(verts.size() / 2, 2, verts.constData(), nullptr);
|
2012-09-21 09:25:08 +00:00
|
|
|
|
2015-11-26 15:58:02 +00:00
|
|
|
ShaderBinder binder(ShaderTrait::UniformColor);
|
|
|
|
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, data.projectionMatrix());
|
2012-03-09 01:20:01 +00:00
|
|
|
vbo->render(GL_TRIANGLES);
|
2011-01-06 13:29:13 +00:00
|
|
|
}
|
2012-03-09 01:20:01 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing) {
|
2012-05-26 07:05:05 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2013-01-28 18:54:27 +00:00
|
|
|
if (m_pixmap == XCB_PIXMAP_NONE || m_pixmapSize != srcArea.size()) {
|
|
|
|
destroyPixmap();
|
2014-04-16 13:58:06 +00:00
|
|
|
m_pixmap = xcb_generate_id(xcbConnection());
|
2013-01-28 18:54:27 +00:00
|
|
|
m_pixmapSize = srcArea.size();
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_create_pixmap(xcbConnection(), 32, m_pixmap, x11RootWindow(), m_pixmapSize.width(), m_pixmapSize.height());
|
2013-01-28 18:54:27 +00:00
|
|
|
m_picture.reset(new XRenderPicture(m_pixmap, 32));
|
2012-03-09 01:20:01 +00:00
|
|
|
}
|
2013-01-28 18:54:27 +00:00
|
|
|
#define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536))
|
2014-09-27 18:30:49 +00:00
|
|
|
static const xcb_render_transform_t identity = {
|
2013-01-28 18:54:27 +00:00
|
|
|
DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0),
|
|
|
|
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0),
|
|
|
|
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1)
|
|
|
|
};
|
|
|
|
static xcb_render_transform_t xform = {
|
|
|
|
DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0),
|
|
|
|
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0),
|
|
|
|
DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1)
|
2012-03-09 01:20:01 +00:00
|
|
|
};
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_composite(xcbConnection(), XCB_RENDER_PICT_OP_SRC, effects->xrenderBufferPicture(), 0, *m_picture,
|
2013-01-28 18:54:27 +00:00
|
|
|
srcArea.x(), srcArea.y(), 0, 0, 0, 0, srcArea.width(), srcArea.height());
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_flush(xcbConnection());
|
2013-01-28 18:54:27 +00:00
|
|
|
xform.matrix11 = DOUBLE_TO_FIXED(1.0/zoom);
|
|
|
|
xform.matrix22 = DOUBLE_TO_FIXED(1.0/zoom);
|
|
|
|
#undef DOUBLE_TO_FIXED
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_set_picture_transform(xcbConnection(), *m_picture, xform);
|
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
|
|
|
xcb_render_set_picture_filter(xcbConnection(), *m_picture, 4, const_cast<char*>("good"), 0, nullptr);
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_composite(xcbConnection(), XCB_RENDER_PICT_OP_SRC, *m_picture, 0, effects->xrenderBufferPicture(),
|
2013-01-28 18:54:27 +00:00
|
|
|
0, 0, 0, 0, area.x(), area.y(), area.width(), area.height() );
|
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
|
|
|
xcb_render_set_picture_filter(xcbConnection(), *m_picture, 4, const_cast<char*>("fast"), 0, nullptr);
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_set_picture_transform(xcbConnection(), *m_picture, identity);
|
2013-01-28 18:54:27 +00:00
|
|
|
const xcb_rectangle_t rects[4] = {
|
|
|
|
{ int16_t(area.x()+FRAME_WIDTH), int16_t(area.y()), uint16_t(area.width()-FRAME_WIDTH), uint16_t(FRAME_WIDTH)},
|
|
|
|
{ int16_t(area.right()-FRAME_WIDTH), int16_t(area.y()+FRAME_WIDTH), uint16_t(FRAME_WIDTH), uint16_t(area.height()-FRAME_WIDTH)},
|
|
|
|
{ int16_t(area.x()), int16_t(area.bottom()-FRAME_WIDTH), uint16_t(area.width()-FRAME_WIDTH), uint16_t(FRAME_WIDTH)},
|
|
|
|
{ int16_t(area.x()), int16_t(area.y()), uint16_t(FRAME_WIDTH), uint16_t(area.height()-FRAME_WIDTH)}
|
2012-03-09 01:20:01 +00:00
|
|
|
};
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_fill_rectangles(xcbConnection(), XCB_RENDER_PICT_OP_SRC, effects->xrenderBufferPicture(),
|
2013-02-12 09:57:27 +00:00
|
|
|
preMultiply(QColor(0,0,0,255)), 4, rects);
|
2012-05-26 07:05:05 +00:00
|
|
|
#endif
|
2011-01-06 13:29:13 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void MagnifierEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (zoom != target_zoom) {
|
|
|
|
QRect framedarea = magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH);
|
|
|
|
effects->addRepaint(framedarea);
|
2007-09-14 13:40:26 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->postPaintScreen();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRect MagnifierEffect::magnifierArea(QPoint pos) const
|
|
|
|
{
|
|
|
|
return QRect(pos.x() - magnifier_size.width() / 2, pos.y() - magnifier_size.height() / 2,
|
|
|
|
magnifier_size.width(), magnifier_size.height());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void MagnifierEffect::zoomIn()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
target_zoom *= 1.2;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!polling) {
|
2009-02-01 15:16:52 +00:00
|
|
|
polling = true;
|
|
|
|
effects->startMousePolling();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2013-07-25 17:13:51 +00:00
|
|
|
if (effects->isOpenGLCompositing() && !m_texture) {
|
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
|
|
|
effects->makeOpenGLContextCurrent();
|
2014-12-13 13:28:33 +00:00
|
|
|
m_texture = new GLTexture(GL_RGBA8, magnifier_size.width(), magnifier_size.height());
|
2011-08-20 08:53:36 +00:00
|
|
|
m_texture->setYInverted(false);
|
2011-07-17 15:57:30 +00:00
|
|
|
m_fbo = new GLRenderTarget(*m_texture);
|
2011-08-20 08:53:36 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaint(magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH));
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void MagnifierEffect::zoomOut()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
target_zoom /= 1.2;
|
2013-07-25 17:12:30 +00:00
|
|
|
if (target_zoom <= 1) {
|
2009-04-27 20:20:05 +00:00
|
|
|
target_zoom = 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (polling) {
|
2009-04-27 20:20:05 +00:00
|
|
|
polling = false;
|
|
|
|
effects->stopMousePolling();
|
2009-02-01 15:16:52 +00:00
|
|
|
}
|
2011-09-07 07:31:31 +00:00
|
|
|
if (zoom == target_zoom) {
|
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
|
|
|
effects->makeOpenGLContextCurrent();
|
2011-09-07 07:31:31 +00:00
|
|
|
delete m_fbo;
|
|
|
|
delete m_texture;
|
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
|
|
|
m_fbo = nullptr;
|
|
|
|
m_texture = nullptr;
|
2013-01-28 18:54:27 +00:00
|
|
|
destroyPixmap();
|
2011-09-07 07:31:31 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaint(magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH));
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void MagnifierEffect::toggle()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-04-13 10:05:23 +00:00
|
|
|
if (zoom == 1.0) {
|
|
|
|
if (target_zoom == 1.0) {
|
|
|
|
target_zoom = 2;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!polling) {
|
2009-04-27 20:20:05 +00:00
|
|
|
polling = true;
|
|
|
|
effects->startMousePolling();
|
|
|
|
}
|
2013-07-25 17:13:51 +00:00
|
|
|
if (effects->isOpenGLCompositing() && !m_texture) {
|
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
|
|
|
effects->makeOpenGLContextCurrent();
|
2014-12-13 13:28:33 +00:00
|
|
|
m_texture = new GLTexture(GL_RGBA8, magnifier_size.width(), magnifier_size.height());
|
2011-08-20 08:53:36 +00:00
|
|
|
m_texture->setYInverted(false);
|
2011-07-17 15:57:30 +00:00
|
|
|
m_fbo = new GLRenderTarget(*m_texture);
|
2011-08-20 08:53:36 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2007-04-29 17:35:43 +00:00
|
|
|
target_zoom = 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (polling) {
|
2009-04-27 20:20:05 +00:00
|
|
|
polling = false;
|
|
|
|
effects->stopMousePolling();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaint(magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH));
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-03-12 13:37:30 +00:00
|
|
|
void MagnifierEffect::slotMouseChanged(const QPoint& pos, const QPoint& old,
|
2011-01-30 14:34:42 +00:00
|
|
|
Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers)
|
|
|
|
{
|
|
|
|
if (pos != old && zoom != 1)
|
2009-04-27 17:36:20 +00:00
|
|
|
// need full repaint as we might lose some change events on fast mouse movements
|
|
|
|
// see Bug 187658
|
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool MagnifierEffect::isActive() const
|
|
|
|
{
|
|
|
|
return zoom != 1.0 || zoom != target_zoom;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
|
|
|
|