Commit e8efa834 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

scene: Pass non-trivial classes by const&

Summary:
This will save the copy of some objects, especially PaintData classes that are
not copy-on-write.
It also follows the practice on other parts of the system.

Test Plan: Running it right now

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D28031
parent a97d4e09
......@@ -614,7 +614,7 @@ void SceneOpenGL2::paintCursor()
glDisable(GL_BLEND);
}
qint64 SceneOpenGL::paint(QRegion damage, QList<Toplevel *> toplevels)
qint64 SceneOpenGL::paint(const QRegion &damage, const QList<Toplevel *> &toplevels)
{
// actually paint the frame, flushed with the NEXT frame
createStackingOrder(toplevels);
......@@ -734,7 +734,7 @@ QMatrix4x4 SceneOpenGL::transformation(int mask, const ScreenPaintData &data) co
return matrix;
}
void SceneOpenGL::paintBackground(QRegion region)
void SceneOpenGL::paintBackground(const QRegion &region)
{
PaintClipper pc(region);
if (!PaintClipper::clip()) {
......@@ -1000,14 +1000,14 @@ void SceneOpenGL2::updateProjectionMatrix()
m_projectionMatrix = createProjectionMatrix();
}
void SceneOpenGL2::paintSimpleScreen(int mask, QRegion region)
void SceneOpenGL2::paintSimpleScreen(int mask, const QRegion &region)
{
m_screenProjectionMatrix = m_projectionMatrix;
Scene::paintSimpleScreen(mask, region);
}
void SceneOpenGL2::paintGenericScreen(int mask, ScreenPaintData data)
void SceneOpenGL2::paintGenericScreen(int mask, const ScreenPaintData &data)
{
const QMatrix4x4 screenMatrix = transformation(mask, data);
......@@ -1034,7 +1034,7 @@ Scene::Window *SceneOpenGL2::createWindow(Toplevel *t)
return new OpenGLWindow(t, this);
}
void SceneOpenGL2::finalDrawWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data)
void SceneOpenGL2::finalDrawWindow(EffectWindowImpl* w, int mask, const QRegion &region, WindowPaintData& data)
{
if (waylandServer() && waylandServer()->isScreenLocked() && !w->window()->isLockScreen() && !w->window()->isInputMethod()) {
return;
......@@ -1042,7 +1042,7 @@ void SceneOpenGL2::finalDrawWindow(EffectWindowImpl* w, int mask, QRegion region
performPaintWindow(w, mask, region, data);
}
void SceneOpenGL2::performPaintWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data)
void SceneOpenGL2::performPaintWindow(EffectWindowImpl* w, int mask, const QRegion &region, WindowPaintData& data)
{
if (mask & PAINT_WINDOW_LANCZOS) {
if (!m_lanczosFilter) {
......@@ -1332,8 +1332,9 @@ void OpenGLWindow::renderSubSurface(GLShader *shader, const QMatrix4x4 &mvp, con
}
}
void OpenGLWindow::performPaint(int mask, QRegion region, WindowPaintData data)
void OpenGLWindow::performPaint(int mask, const QRegion &region, const WindowPaintData &_data)
{
WindowPaintData data = _data;
if (!beginRenderWindow(mask, region, data))
return;
......@@ -1710,12 +1711,13 @@ void SceneOpenGL::EffectFrame::crossFadeText()
m_textTexture = nullptr;
}
void SceneOpenGL::EffectFrame::render(QRegion region, double opacity, double frameOpacity)
void SceneOpenGL::EffectFrame::render(const QRegion &_region, double opacity, double frameOpacity)
{
if (m_effectFrame->geometry().isEmpty())
return; // Nothing to display
region = infiniteRegion(); // TODO: Old region doesn't seem to work with OpenGL
Q_UNUSED(_region);
const QRegion region = infiniteRegion(); // TODO: Old region doesn't seem to work with OpenGL
GLShader* shader = m_effectFrame->shader();
if (!shader) {
......
......@@ -46,7 +46,7 @@ public:
~SceneOpenGL() override;
bool initFailed() const override;
bool hasPendingFlush() const override;
qint64 paint(QRegion damage, QList<Toplevel *> windows) override;
qint64 paint(const QRegion &damage, const QList<Toplevel *> &windows) override;
Scene::EffectFrame *createEffectFrame(EffectFrameImpl *frame) override;
Shadow *createShadow(Toplevel *toplevel) override;
void screenGeometryChanged(const QSize &size) override;
......@@ -85,7 +85,7 @@ public:
protected:
SceneOpenGL(OpenGLBackend *backend, QObject *parent = nullptr);
void paintBackground(QRegion region) override;
void paintBackground(const QRegion &region) override;
void extendPaintRegion(QRegion &region, bool opaqueFullscreen) override;
QMatrix4x4 transformation(int mask, const ScreenPaintData &data) const;
void paintDesktop(int desktop, int mask, const QRegion &region, ScreenPaintData &data) override;
......@@ -123,16 +123,16 @@ public:
QMatrix4x4 screenProjectionMatrix() const override { return m_screenProjectionMatrix; }
protected:
void paintSimpleScreen(int mask, QRegion region) override;
void paintGenericScreen(int mask, ScreenPaintData data) override;
void paintSimpleScreen(int mask, const QRegion &region) override;
void paintGenericScreen(int mask, const ScreenPaintData &data) override;
void doPaintBackground(const QVector< float >& vertices) override;
Scene::Window *createWindow(Toplevel *t) override;
void finalDrawWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data) override;
void finalDrawWindow(EffectWindowImpl* w, int mask, const QRegion &region, WindowPaintData& data) override;
void updateProjectionMatrix() override;
void paintCursor() override;
private:
void performPaintWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data);
void performPaintWindow(EffectWindowImpl* w, int mask, const QRegion &region, WindowPaintData& data);
QMatrix4x4 createProjectionMatrix() const;
private:
......@@ -174,7 +174,7 @@ public:
~OpenGLWindow() override;
WindowPixmap *createWindowPixmap() override;
void performPaint(int mask, QRegion region, WindowPaintData data) override;
void performPaint(int mask, const QRegion &region, const WindowPaintData &data) override;
private:
QMatrix4x4 transformation(int mask, const WindowPaintData &data) const;
......@@ -222,7 +222,7 @@ public:
void freeTextFrame() override;
void freeSelection() override;
void render(QRegion region, double opacity, double frameOpacity) override;
void render(const QRegion &region, double opacity, double frameOpacity) override;
void crossFadeIcon() override;
void crossFadeText() override;
......
......@@ -82,7 +82,7 @@ bool SceneQPainter::initFailed() const
return false;
}
void SceneQPainter::paintGenericScreen(int mask, ScreenPaintData data)
void SceneQPainter::paintGenericScreen(int mask, const ScreenPaintData &data)
{
m_painter->save();
m_painter->translate(data.xTranslation(), data.yTranslation());
......@@ -91,12 +91,13 @@ void SceneQPainter::paintGenericScreen(int mask, ScreenPaintData data)
m_painter->restore();
}
qint64 SceneQPainter::paint(QRegion damage, QList<Toplevel *> toplevels)
qint64 SceneQPainter::paint(const QRegion &_damage, const QList<Toplevel *> &toplevels)
{
QElapsedTimer renderTimer;
renderTimer.start();
createStackingOrder(toplevels);
QRegion damage = _damage;
int mask = 0;
m_backend->prepareRenderingFrame();
......@@ -153,7 +154,7 @@ qint64 SceneQPainter::paint(QRegion damage, QList<Toplevel *> toplevels)
return renderTimer.nsecsElapsed();
}
void SceneQPainter::paintBackground(QRegion region)
void SceneQPainter::paintBackground(const QRegion &region)
{
m_painter->setBrush(Qt::black);
for (const QRect &rect : region) {
......@@ -256,8 +257,9 @@ static bool isXwaylandClient(Toplevel *toplevel)
return false;
}
void SceneQPainter::Window::performPaint(int mask, QRegion region, WindowPaintData data)
void SceneQPainter::Window::performPaint(int mask, const QRegion &_region, const WindowPaintData &data)
{
QRegion region = _region;
if (!(mask & (PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED)))
region &= toplevel->visibleRect();
......@@ -489,7 +491,7 @@ QPainterEffectFrame::~QPainterEffectFrame()
{
}
void QPainterEffectFrame::render(QRegion region, double opacity, double frameOpacity)
void QPainterEffectFrame::render(const QRegion &region, double opacity, double frameOpacity)
{
Q_UNUSED(region)
Q_UNUSED(opacity)
......
......@@ -36,8 +36,8 @@ public:
~SceneQPainter() override;
bool usesOverlayWindow() const override;
OverlayWindow* overlayWindow() const override;
qint64 paint(QRegion damage, QList<Toplevel *> windows) override;
void paintGenericScreen(int mask, ScreenPaintData data) override;
qint64 paint(const QRegion &damage, const QList<Toplevel *> &windows) override;
void paintGenericScreen(int mask, const ScreenPaintData &data) override;
CompositingType compositingType() const override;
bool initFailed() const override;
EffectFrame *createEffectFrame(EffectFrameImpl *frame) override;
......@@ -59,7 +59,7 @@ public:
static SceneQPainter *createScene(QObject *parent);
protected:
void paintBackground(QRegion region) override;
void paintBackground(const QRegion &region) override;
Scene::Window *createWindow(Toplevel *toplevel) override;
void paintCursor() override;
void paintEffectQuickView(EffectQuickView *w) override;
......@@ -76,7 +76,7 @@ class SceneQPainter::Window : public Scene::Window
public:
Window(SceneQPainter *scene, Toplevel *c);
~Window() override;
void performPaint(int mask, QRegion region, WindowPaintData data) override;
void performPaint(int mask, const QRegion &region, const WindowPaintData &data) override;
protected:
WindowPixmap *createWindowPixmap() override;
private:
......@@ -114,7 +114,7 @@ public:
void freeIconFrame() override {}
void freeTextFrame() override {}
void freeSelection() override {}
void render(QRegion region, double opacity, double frameOpacity) override;
void render(const QRegion &region, double opacity, double frameOpacity) override;
private:
SceneQPainter *m_scene;
};
......
......@@ -249,7 +249,7 @@ bool SceneXrender::initFailed() const
}
// the entry point for painting
qint64 SceneXrender::paint(QRegion damage, QList<Toplevel *> toplevels)
qint64 SceneXrender::paint(const QRegion &damage, const QList<Toplevel *> &toplevels)
{
QElapsedTimer renderTimer;
renderTimer.start();
......@@ -269,7 +269,7 @@ qint64 SceneXrender::paint(QRegion damage, QList<Toplevel *> toplevels)
return renderTimer.nsecsElapsed();
}
void SceneXrender::paintGenericScreen(int mask, ScreenPaintData data)
void SceneXrender::paintGenericScreen(int mask, const ScreenPaintData &data)
{
screen_paint = data; // save, transformations will be done when painting windows
Scene::paintGenericScreen(mask, data);
......@@ -283,7 +283,7 @@ void SceneXrender::paintDesktop(int desktop, int mask, const QRegion &region, Sc
}
// fill the screen background
void SceneXrender::paintBackground(QRegion region)
void SceneXrender::paintBackground(const QRegion &region)
{
xcb_render_color_t col = { 0, 0, 0, 0xffff }; // black
const QVector<xcb_rectangle_t> &rects = Xcb::regionToRects(region);
......@@ -418,8 +418,9 @@ void SceneXrender::Window::prepareTempPixmap()
}
// paint the window
void SceneXrender::Window::performPaint(int mask, QRegion region, WindowPaintData data)
void SceneXrender::Window::performPaint(int mask, const QRegion &_region, const WindowPaintData &data)
{
QRegion region = _region;
setTransformedShape(QRegion()); // maybe nothing will be painted
// check if there is something to paint
bool opaque = isOpaque() && qFuzzyCompare(data.opacity(), 1.0);
......@@ -894,7 +895,7 @@ void SceneXrender::EffectFrame::crossFadeText()
// TODO: implement me
}
void SceneXrender::EffectFrame::render(QRegion region, double opacity, double frameOpacity)
void SceneXrender::EffectFrame::render(const QRegion &region, double opacity, double frameOpacity)
{
Q_UNUSED(region)
if (m_effectFrame->geometry().isEmpty()) {
......
......@@ -154,7 +154,7 @@ public:
CompositingType compositingType() const override {
return XRenderCompositing;
}
qint64 paint(QRegion damage, QList<Toplevel *> windows) override;
qint64 paint(const QRegion &damage, const QList<Toplevel *> &windows) override;
Scene::EffectFrame *createEffectFrame(EffectFrameImpl *frame) override;
Shadow *createShadow(Toplevel *toplevel) override;
void screenGeometryChanged(const QSize &size) override;
......@@ -174,8 +174,8 @@ public:
static SceneXrender *createScene(QObject *parent);
protected:
Scene::Window *createWindow(Toplevel *toplevel) override;
void paintBackground(QRegion region) override;
void paintGenericScreen(int mask, ScreenPaintData data) override;
void paintBackground(const QRegion &region) override;
void paintGenericScreen(int mask, const ScreenPaintData &data) override;
void paintDesktop(int desktop, int mask, const QRegion &region, ScreenPaintData &data) override;
void paintCursor() override;
void paintEffectQuickView(EffectQuickView *w) override;
......@@ -192,7 +192,7 @@ class SceneXrender::Window
public:
Window(Toplevel* c, SceneXrender *scene);
~Window() override;
void performPaint(int mask, QRegion region, WindowPaintData data) override;
void performPaint(int mask, const QRegion &region, const WindowPaintData &data) override;
QRegion transformedShape() const;
void setTransformedShape(const QRegion& shape);
static void cleanup();
......@@ -238,7 +238,7 @@ public:
void freeSelection() override;
void crossFadeIcon() override;
void crossFadeText() override;
void render(QRegion region, double opacity, double frameOpacity) override;
void render(const QRegion &region, double opacity, double frameOpacity) override;
static void cleanup();
private:
......
......@@ -191,7 +191,7 @@ void Scene::idle()
}
// the function that'll be eventually called by paintScreen() above
void Scene::finalPaintScreen(int mask, QRegion region, ScreenPaintData& data)
void Scene::finalPaintScreen(int mask, const QRegion &region, ScreenPaintData& data)
{
if (mask & (PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS))
paintGenericScreen(mask, data);
......@@ -201,7 +201,7 @@ void Scene::finalPaintScreen(int mask, QRegion region, ScreenPaintData& data)
// The generic painting code that can handle even transformations.
// It simply paints bottom-to-top.
void Scene::paintGenericScreen(int orig_mask, ScreenPaintData)
void Scene::paintGenericScreen(int orig_mask, const ScreenPaintData &)
{
if (!(orig_mask & PAINT_SCREEN_BACKGROUND_FIRST)) {
paintBackground(infiniteRegion());
......@@ -246,7 +246,7 @@ void Scene::paintGenericScreen(int orig_mask, ScreenPaintData)
// The optimized case without any transformations at all.
// It can paint only the requested region and can use clipping
// to reduce painting and improve performance.
void Scene::paintSimpleScreen(int orig_mask, QRegion region)
void Scene::paintSimpleScreen(int orig_mask, const QRegion &region)
{
Q_ASSERT((orig_mask & (PAINT_SCREEN_TRANSFORMED
| PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS)) == 0);
......@@ -441,7 +441,7 @@ void Scene::windowGeometryShapeChanged(Toplevel *c)
w->discardShape();
}
void Scene::createStackingOrder(QList<Toplevel *> toplevels)
void Scene::createStackingOrder(const QList<Toplevel *> &toplevels)
{
// TODO: cache the stacking_order in case it has not changed
foreach (Toplevel *c, toplevels) {
......@@ -457,11 +457,10 @@ void Scene::clearStackingOrder()
static Scene::Window *s_recursionCheck = nullptr;
void Scene::paintWindow(Window* w, int mask, QRegion region, WindowQuadList quads)
void Scene::paintWindow(Window* w, int mask, const QRegion &_region, const WindowQuadList &quads)
{
// no painting outside visible screen (and no transformations)
const QSize &screenSize = screens()->size();
region &= QRect(0, 0, screenSize.width(), screenSize.height());
const QRegion region = _region & QRect({0, 0}, screens()->size());
if (region.isEmpty()) // completely clipped
return;
if (w->window()->isDeleted() && w->window()->skipsCloseAnimation()) {
......@@ -504,7 +503,7 @@ static void adjustClipRegion(AbstractThumbnailItem *item, QRegion &clippingRegio
}
}
void Scene::paintWindowThumbnails(Scene::Window *w, QRegion region, qreal opacity, qreal brightness, qreal saturation)
void Scene::paintWindowThumbnails(Scene::Window *w, const QRegion &region, qreal opacity, qreal brightness, qreal saturation)
{
EffectWindowImpl *wImpl = static_cast<EffectWindowImpl*>(effectWindow(w));
for (QHash<WindowThumbnailItem*, QPointer<EffectWindowImpl> >::const_iterator it = wImpl->thumbnails().constBegin();
......@@ -601,13 +600,13 @@ void Scene::paintDesktop(int desktop, int mask, const QRegion &region, ScreenPai
}
// the function that'll be eventually called by paintWindow() above
void Scene::finalPaintWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data)
void Scene::finalPaintWindow(EffectWindowImpl* w, int mask, const QRegion &region, WindowPaintData& data)
{
effects->drawWindow(w, mask, region, data);
}
// will be eventually called from drawWindow()
void Scene::finalDrawWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data)
void Scene::finalDrawWindow(EffectWindowImpl* w, int mask, const QRegion &region, WindowPaintData& data)
{
if (waylandServer() && waylandServer()->isScreenLocked() && !w->window()->isLockScreen() && !w->window()->isInputMethod()) {
return;
......
......@@ -76,7 +76,7 @@ public:
// The entry point for the main part of the painting pass.
// returns the time since the last vblank signal - if there's one
// ie. "what of this frame is lost to painting"
virtual qint64 paint(QRegion damage, QList<Toplevel *> windows) = 0;
virtual qint64 paint(const QRegion &damage, const QList<Toplevel *> &windows) = 0;
/**
* Adds the Toplevel to the Scene.
......@@ -209,7 +209,7 @@ public Q_SLOTS:
void windowClosed(KWin::Toplevel* c, KWin::Deleted* deleted);
protected:
virtual Window *createWindow(Toplevel *toplevel) = 0;
void createStackingOrder(QList<Toplevel *> toplevels);
void createStackingOrder(const QList<Toplevel *> &toplevels);
void clearStackingOrder();
// shared implementation, starts painting the screen
void paintScreen(int *mask, const QRegion &damage, const QRegion &repaint,
......@@ -218,20 +218,20 @@ protected:
virtual void paintCursor() = 0;
friend class EffectsHandlerImpl;
// called after all effects had their paintScreen() called
void finalPaintScreen(int mask, QRegion region, ScreenPaintData& data);
void finalPaintScreen(int mask, const QRegion &region, ScreenPaintData& data);
// shared implementation of painting the screen in the generic
// (unoptimized) way
virtual void paintGenericScreen(int mask, ScreenPaintData data);
virtual void paintGenericScreen(int mask, const ScreenPaintData &data);
// shared implementation of painting the screen in an optimized way
virtual void paintSimpleScreen(int mask, QRegion region);
virtual void paintSimpleScreen(int mask, const QRegion &region);
// paint the background (not the desktop background - the whole background)
virtual void paintBackground(QRegion region) = 0;
virtual void paintBackground(const QRegion &region) = 0;
// called after all effects had their paintWindow() called
void finalPaintWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data);
void finalPaintWindow(EffectWindowImpl* w, int mask, const QRegion &region, WindowPaintData& data);
// shared implementation, starts painting the window
virtual void paintWindow(Window* w, int mask, QRegion region, WindowQuadList quads);
virtual void paintWindow(Window* w, int mask, const QRegion &region, const WindowQuadList &quads);
// called after all effects had their drawWindow() called
virtual void finalDrawWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data);
virtual void finalDrawWindow(EffectWindowImpl* w, int mask, const QRegion &region, WindowPaintData& data);
// let the scene decide whether it's better to paint more of the screen, eg. in order to allow a buffer swap
// the default is NOOP
virtual void extendPaintRegion(QRegion &region, bool opaqueFullscreen);
......@@ -263,7 +263,7 @@ protected:
int time_diff;
QElapsedTimer last_time;
private:
void paintWindowThumbnails(Scene::Window *w, QRegion region, qreal opacity, qreal brightness, qreal saturation);
void paintWindowThumbnails(Scene::Window *w, const QRegion &region, qreal opacity, qreal brightness, qreal saturation);
void paintDesktopThumbnails(Scene::Window *w);
QHash< Toplevel*, Window* > m_windows;
// windows in their stacking order
......@@ -295,7 +295,7 @@ public:
Window(Toplevel* c);
virtual ~Window();
// perform the actual painting of the window
virtual void performPaint(int mask, QRegion region, WindowPaintData data) = 0;
virtual void performPaint(int mask, const QRegion &region, const WindowPaintData &data) = 0;
// do any cleanup needed when the window's composite pixmap is discarded
void discardPixmap();
void updatePixmap();
......@@ -530,7 +530,7 @@ class Scene::EffectFrame
public:
EffectFrame(EffectFrameImpl* frame);
virtual ~EffectFrame();
virtual void render(QRegion region, double opacity, double frameOpacity) = 0;
virtual void render(const QRegion &region, double opacity, double frameOpacity) = 0;
virtual void free() = 0;
virtual void freeIconFrame() = 0;
virtual void freeTextFrame() = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment