kwin/scene.h

688 lines
22 KiB
C
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_SCENE_H
#define KWIN_SCENE_H
#include "toplevel.h"
#include "utils.h"
#include "kwineffects.h"
#include <QElapsedTimer>
#include <QMatrix4x4>
class QOpenGLFramebufferObject;
namespace KWayland
{
namespace Server
{
class BufferInterface;
class SubSurfaceInterface;
}
}
namespace KWin
{
namespace Decoration
{
class DecoratedClientImpl;
class Renderer;
}
class AbstractThumbnailItem;
class Deleted;
class EffectFrameImpl;
class EffectWindowImpl;
class OverlayWindow;
class Shadow;
class WindowPixmap;
// The base class for compositing backends.
class KWIN_EXPORT Scene : public QObject
2011-01-30 14:34:42 +00:00
{
Q_OBJECT
2011-01-30 14:34:42 +00:00
public:
explicit Scene(QObject *parent = nullptr);
Run clang-tidy with modernize-use-override check Summary: Currently code base of kwin can be viewed as two pieces. One is very ancient, and the other one is more modern, which uses new C++ features. The main problem with the ancient code is that it was written before C++11 era. So, no override or final keywords, lambdas, etc. Quite recently, KDE compiler settings were changed to show a warning if a virtual method has missing override keyword. As you might have already guessed, this fired back at us because of that ancient code. We had about 500 new compiler warnings. A "solution" was proposed to that problem - disable -Wno-suggest-override and the other similar warning for clang. It's hard to call a solution because those warnings are disabled not only for the old code, but also for new. This is not what we want! The main argument for not actually fixing the problem was that git history will be screwed as well because of human factor. While good git history is a very important thing, we should not go crazy about it and block every change that somehow alters git history. git blame allows to specify starting revision for a reason. The other argument (human factor) can be easily solved by using tools such as clang-tidy. clang-tidy is a clang-based linter for C++. It can be used for various things, e.g. fixing coding style(e.g. add missing braces to if statements, readability-braces-around-statements check), or in our case add missing override keywords. Test Plan: Compiles. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: davidedmundson, apol, romangg, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
~Scene() override = 0;
2011-01-30 14:34:42 +00:00
class EffectFrame;
class Window;
// Returns true if the ctor failed to properly initialize.
virtual bool initFailed() const = 0;
virtual CompositingType compositingType() const = 0;
virtual bool hasPendingFlush() const { return false; }
2011-01-30 14:34:42 +00:00
// Repaints the given screen areas, windows provides the stacking order.
// 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, ToplevelList windows) = 0;
2011-01-30 14:34:42 +00:00
/**
* Adds the Toplevel to the Scene.
*
* If the toplevel gets deleted, then the scene will try automatically
* to re-bind an underlying scene window to the corresponding Deleted.
*
* @param toplevel The window to be added.
* @note You can add a toplevel to scene only once.
*/
void addToplevel(Toplevel *toplevel);
/**
* Removes the Toplevel from the Scene.
*
* @param toplevel The window to be removed.
* @note You can remove a toplevel from the scene only once.
*/
void removeToplevel(Toplevel *toplevel);
2011-01-30 14:34:42 +00:00
/**
* @brief Creates the Scene backend of an EffectFrame.
*
* @param frame The EffectFrame this Scene::EffectFrame belongs to.
*/
virtual Scene::EffectFrame *createEffectFrame(EffectFrameImpl *frame) = 0;
/**
* @brief Creates the Scene specific Shadow subclass.
*
* An implementing class has to create a proper instance. It is not allowed to
* return @c null.
*
* @param toplevel The Toplevel for which the Shadow needs to be created.
*/
virtual Shadow *createShadow(Toplevel *toplevel) = 0;
/**
* Method invoked when the screen geometry is changed.
* Reimplementing classes should also invoke the parent method
* as it takes care of resizing the overlay window.
* @param size The new screen geometry size
*/
virtual void screenGeometryChanged(const QSize &size);
2011-01-30 14:34:42 +00:00
// Flags controlling how painting is done.
enum {
// Window (or at least part of it) will be painted opaque.
PAINT_WINDOW_OPAQUE = 1 << 0,
// Window (or at least part of it) will be painted translucent.
PAINT_WINDOW_TRANSLUCENT = 1 << 1,
// Window will be painted with transformed geometry.
PAINT_WINDOW_TRANSFORMED = 1 << 2,
// Paint only a region of the screen (can be optimized, cannot
// be used together with TRANSFORMED flags).
PAINT_SCREEN_REGION = 1 << 3,
// Whole screen will be painted with transformed geometry.
PAINT_SCREEN_TRANSFORMED = 1 << 4,
// At least one window will be painted with transformed geometry.
PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5,
// Clear whole background as the very first step, without optimizing it
PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6,
// PAINT_DECORATION_ONLY = 1 << 7 has been removed
2011-01-30 14:34:42 +00:00
// Window will be painted with a lanczos filter.
2012-03-02 13:03:05 +00:00
PAINT_WINDOW_LANCZOS = 1 << 8
// PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS = 1 << 9 has been removed
};
2011-01-30 14:34:42 +00:00
// types of filtering available
enum ImageFilterType { ImageFilterFast, ImageFilterGood };
// there's nothing to paint (adjust time_diff later)
virtual void idle();
virtual bool blocksForRetrace() const;
virtual bool syncsToVBlank() const;
virtual OverlayWindow* overlayWindow() const = 0;
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
virtual bool makeOpenGLContextCurrent();
virtual void doneOpenGLContextCurrent();
virtual QMatrix4x4 screenProjectionMatrix() const;
/**
* Whether the Scene uses an X11 overlay window to perform compositing.
*/
virtual bool usesOverlayWindow() const = 0;
virtual void triggerFence();
virtual Decoration::Renderer *createDecorationRenderer(Decoration::DecoratedClientImpl *) = 0;
/**
* Whether the Scene is able to drive animations.
* This is used as a hint to the effects system which effects can be supported.
* If the Scene performs software rendering it is supposed to return @c false,
* if rendering is hardware accelerated it should return @c true.
*/
virtual bool animationsSupported() const = 0;
/**
* The render buffer used by an XRender based compositor scene.
* Default implementation returns XCB_RENDER_PICTURE_NONE
*/
virtual xcb_render_picture_t xrenderBufferPicture() const;
/**
* The QPainter used by a QPainter based compositor scene.
* Default implementation returns @c nullptr;
*/
virtual QPainter *scenePainter() const;
/**
* The render buffer used by a QPainter based compositor.
* Default implementation returns @c nullptr.
*/
virtual QImage *qpainterRenderBuffer() const;
/**
* The backend specific extensions (e.g. EGL/GLX extensions).
*
* Not the OpenGL (ES) extension!
*
* Default implementation returns empty list
*/
virtual QVector<QByteArray> openGLPlatformInterfaceExtensions() const;
Q_SIGNALS:
void frameRendered();
void resetCompositing();
public Q_SLOTS:
// shape/size of a window changed
void windowGeometryShapeChanged(KWin::Toplevel* c);
// a window has been closed
void windowClosed(KWin::Toplevel* c, KWin::Deleted* deleted);
2011-01-30 14:34:42 +00:00
protected:
virtual Window *createWindow(Toplevel *toplevel) = 0;
void createStackingOrder(ToplevelList toplevels);
void clearStackingOrder();
2011-01-30 14:34:42 +00:00
// shared implementation, starts painting the screen
void paintScreen(int *mask, const QRegion &damage, const QRegion &repaint,
QRegion *updateRegion, QRegion *validRegion, const QMatrix4x4 &projection = QMatrix4x4(), const QRect &outputGeometry = QRect());
// Render cursor texture in case hardware cursor is disabled/non-applicable
virtual void paintCursor() = 0;
2011-01-30 14:34:42 +00:00
friend class EffectsHandlerImpl;
// called after all effects had their paintScreen() called
void finalPaintScreen(int mask, QRegion region, ScreenPaintData& data);
// shared implementation of painting the screen in the generic
// (unoptimized) way
virtual void paintGenericScreen(int mask, ScreenPaintData data);
// shared implementation of painting the screen in an optimized way
virtual void paintSimpleScreen(int mask, QRegion region);
// paint the background (not the desktop background - the whole background)
virtual void paintBackground(QRegion region) = 0;
// called after all effects had their paintWindow() called
void finalPaintWindow(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data);
// shared implementation, starts painting the window
virtual void paintWindow(Window* w, int mask, QRegion region, WindowQuadList quads);
// called after all effects had their drawWindow() called
virtual void finalDrawWindow(EffectWindowImpl* w, int mask, 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);
virtual void paintDesktop(int desktop, int mask, const QRegion &region, ScreenPaintData &data);
2011-01-30 14:34:42 +00:00
// compute time since the last repaint
void updateTimeDiff();
// saved data for 2nd pass of optimized screen painting
struct Phase2Data {
Window *window = nullptr;
2011-01-30 14:34:42 +00:00
QRegion region;
QRegion clip;
int mask = 0;
2011-01-30 14:34:42 +00:00
WindowQuadList quads;
};
// The region which actually has been painted by paintScreen() and should be
// copied from the buffer to the screen. I.e. the region returned from Scene::paintScreen().
// Since prePaintWindow() can extend areas to paint, these changes would have to propagate
// up all the way from paintSimpleScreen() up to paintScreen(), so save them here rather
// than propagate them up in arguments.
QRegion painted_region;
// Additional damage that needs to be repaired to bring a reused back buffer up to date
QRegion repaint_region;
// The dirty region before it was unioned with repaint_region
QRegion damaged_region;
2011-01-30 14:34:42 +00:00
// time since last repaint
int time_diff;
QElapsedTimer last_time;
private:
void paintWindowThumbnails(Scene::Window *w, QRegion region, qreal opacity, qreal brightness, qreal saturation);
void paintDesktopThumbnails(Scene::Window *w);
QHash< Toplevel*, Window* > m_windows;
// windows in their stacking order
QVector< Window* > stacking_order;
2011-01-30 14:34:42 +00:00
};
Move SceneXRender into a plugin Summary: First step for loading the compositor Scenes through plugins. The general idea is that we currently needlessly pull in all the Scenes although only one will be used. E.g. on X11 we pull in QPainter, although they are not compatible. On Wayland we pull in XRender although they are not compatible. Furthermore our current Scene creation strategy is not really fault tolerant and can create situations where we don't get a compositor. E.g on fbdev backend the default settings won't work as it does not support OpenGL. Long term I want to tackle those conceptional problems together: we try to load all plugins supported by the current platform till we have a scene which works. Thus on Wayland we don't end up in a situation where we don't have a working compositor because the configuration is bad. To make this possible the switch statement in the Scene needs to go and needs to be replaced by a for loop iterating over all the available scenes on the platform. If we go there it makes sense to replace it directly with a plugin based approach. So this is a change which tackles the problem by first introducing the plugin loading. The xrender based scene (as it's the most simple one) is moved into a plugin. It is first tried to find a scene plugin and only if there is none the existing code is used. Test Plan: Tested all scenes Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D7232
2017-08-10 16:13:42 +00:00
/**
* Factory class to create a Scene. Needs to be implemented by the plugins.
*/
Move SceneXRender into a plugin Summary: First step for loading the compositor Scenes through plugins. The general idea is that we currently needlessly pull in all the Scenes although only one will be used. E.g. on X11 we pull in QPainter, although they are not compatible. On Wayland we pull in XRender although they are not compatible. Furthermore our current Scene creation strategy is not really fault tolerant and can create situations where we don't get a compositor. E.g on fbdev backend the default settings won't work as it does not support OpenGL. Long term I want to tackle those conceptional problems together: we try to load all plugins supported by the current platform till we have a scene which works. Thus on Wayland we don't end up in a situation where we don't have a working compositor because the configuration is bad. To make this possible the switch statement in the Scene needs to go and needs to be replaced by a for loop iterating over all the available scenes on the platform. If we go there it makes sense to replace it directly with a plugin based approach. So this is a change which tackles the problem by first introducing the plugin loading. The xrender based scene (as it's the most simple one) is moved into a plugin. It is first tried to find a scene plugin and only if there is none the existing code is used. Test Plan: Tested all scenes Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D7232
2017-08-10 16:13:42 +00:00
class KWIN_EXPORT SceneFactory : public QObject
{
Q_OBJECT
public:
Run clang-tidy with modernize-use-override check Summary: Currently code base of kwin can be viewed as two pieces. One is very ancient, and the other one is more modern, which uses new C++ features. The main problem with the ancient code is that it was written before C++11 era. So, no override or final keywords, lambdas, etc. Quite recently, KDE compiler settings were changed to show a warning if a virtual method has missing override keyword. As you might have already guessed, this fired back at us because of that ancient code. We had about 500 new compiler warnings. A "solution" was proposed to that problem - disable -Wno-suggest-override and the other similar warning for clang. It's hard to call a solution because those warnings are disabled not only for the old code, but also for new. This is not what we want! The main argument for not actually fixing the problem was that git history will be screwed as well because of human factor. While good git history is a very important thing, we should not go crazy about it and block every change that somehow alters git history. git blame allows to specify starting revision for a reason. The other argument (human factor) can be easily solved by using tools such as clang-tidy. clang-tidy is a clang-based linter for C++. It can be used for various things, e.g. fixing coding style(e.g. add missing braces to if statements, readability-braces-around-statements check), or in our case add missing override keywords. Test Plan: Compiles. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: davidedmundson, apol, romangg, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
~SceneFactory() override;
Move SceneXRender into a plugin Summary: First step for loading the compositor Scenes through plugins. The general idea is that we currently needlessly pull in all the Scenes although only one will be used. E.g. on X11 we pull in QPainter, although they are not compatible. On Wayland we pull in XRender although they are not compatible. Furthermore our current Scene creation strategy is not really fault tolerant and can create situations where we don't get a compositor. E.g on fbdev backend the default settings won't work as it does not support OpenGL. Long term I want to tackle those conceptional problems together: we try to load all plugins supported by the current platform till we have a scene which works. Thus on Wayland we don't end up in a situation where we don't have a working compositor because the configuration is bad. To make this possible the switch statement in the Scene needs to go and needs to be replaced by a for loop iterating over all the available scenes on the platform. If we go there it makes sense to replace it directly with a plugin based approach. So this is a change which tackles the problem by first introducing the plugin loading. The xrender based scene (as it's the most simple one) is moved into a plugin. It is first tried to find a scene plugin and only if there is none the existing code is used. Test Plan: Tested all scenes Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D7232
2017-08-10 16:13:42 +00:00
/**
* @returns The created Scene, may be @c nullptr.
*/
Move SceneXRender into a plugin Summary: First step for loading the compositor Scenes through plugins. The general idea is that we currently needlessly pull in all the Scenes although only one will be used. E.g. on X11 we pull in QPainter, although they are not compatible. On Wayland we pull in XRender although they are not compatible. Furthermore our current Scene creation strategy is not really fault tolerant and can create situations where we don't get a compositor. E.g on fbdev backend the default settings won't work as it does not support OpenGL. Long term I want to tackle those conceptional problems together: we try to load all plugins supported by the current platform till we have a scene which works. Thus on Wayland we don't end up in a situation where we don't have a working compositor because the configuration is bad. To make this possible the switch statement in the Scene needs to go and needs to be replaced by a for loop iterating over all the available scenes on the platform. If we go there it makes sense to replace it directly with a plugin based approach. So this is a change which tackles the problem by first introducing the plugin loading. The xrender based scene (as it's the most simple one) is moved into a plugin. It is first tried to find a scene plugin and only if there is none the existing code is used. Test Plan: Tested all scenes Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D7232
2017-08-10 16:13:42 +00:00
virtual Scene *create(QObject *parent = nullptr) const = 0;
protected:
explicit SceneFactory(QObject *parent);
};
// The base class for windows representations in composite backends
class Scene::Window
2011-01-30 14:34:42 +00:00
{
public:
Window(Toplevel* c);
virtual ~Window();
// perform the actual painting of the window
virtual void performPaint(int mask, QRegion region, WindowPaintData data) = 0;
// do any cleanup needed when the window's composite pixmap is discarded
void pixmapDiscarded();
2011-01-30 14:34:42 +00:00
int x() const;
int y() const;
int width() const;
int height() const;
QRect geometry() const;
QPoint pos() const;
QSize size() const;
QRect rect() const;
// access to the internal window class
// TODO eventually get rid of this
Toplevel* window() const;
2011-01-30 14:34:42 +00:00
// should the window be painted
bool isPaintingEnabled() const;
void resetPaintingEnabled();
// Flags explaining why painting should be disabled
enum {
// Window will not be painted
PAINT_DISABLED = 1 << 0,
// Window will not be painted because it is deleted
PAINT_DISABLED_BY_DELETE = 1 << 1,
// Window will not be painted because of which desktop it's on
PAINT_DISABLED_BY_DESKTOP = 1 << 2,
// Window will not be painted because it is minimized
PAINT_DISABLED_BY_MINIMIZE = 1 << 3,
// Window will not be painted because it's not on the current activity
PAINT_DISABLED_BY_ACTIVITY = 1 << 5
};
2011-01-30 14:34:42 +00:00
void enablePainting(int reason);
void disablePainting(int reason);
// is the window visible at all
bool isVisible() const;
// is the window fully opaque
bool isOpaque() const;
// shape of the window
const QRegion &shape() const;
2011-01-30 14:34:42 +00:00
QRegion clientShape() const;
void discardShape();
void updateToplevel(Toplevel* c);
// creates initial quad list for the window
virtual WindowQuadList buildQuads(bool force = false) const;
void updateShadow(Shadow* shadow);
const Shadow* shadow() const;
Shadow* shadow();
void referencePreviousPixmap();
void unreferencePreviousPixmap();
void invalidateQuadsCache();
2011-01-30 14:34:42 +00:00
protected:
WindowQuadList makeQuads(WindowQuadType type, const QRegion& reg, const QPoint &textureOffset = QPoint(0, 0), qreal textureScale = 1.0) const;
WindowQuadList makeDecorationQuads(const QRect *rects, const QRegion &region, qreal textureScale = 1.0) const;
/**
* @brief Returns the WindowPixmap for this Window.
*
2019-01-11 13:36:17 +00:00
* If the WindowPixmap does not yet exist, this method will invoke createWindowPixmap.
* If the WindowPixmap is not valid it tries to create it, in case this succeeds the WindowPixmap is
* returned. In case it fails, the previous (and still valid) WindowPixmap is returned.
*
2019-01-11 13:36:17 +00:00
* @note This method can return @c NULL as there might neither be a valid previous nor current WindowPixmap
* around.
*
* The WindowPixmap gets casted to the type passed in as a template parameter. That way this class does not
* need to know the actual WindowPixmap subclass used by the concrete Scene implementations.
*
* @return The WindowPixmap casted to T* or @c NULL if there is no valid window pixmap.
*/
template<typename T> T *windowPixmap();
template<typename T> T *previousWindowPixmap();
/**
* @brief Factory method to create a WindowPixmap.
*
* The inheriting classes need to implement this method to create a new instance of their WindowPixmap subclass.
2019-01-11 13:36:17 +00:00
* @note Do not use WindowPixmap::create on the created instance. The Scene will take care of that.
*/
virtual WindowPixmap *createWindowPixmap() = 0;
2011-01-30 14:34:42 +00:00
Toplevel* toplevel;
ImageFilterType filter;
Shadow *m_shadow;
2011-01-30 14:34:42 +00:00
private:
QScopedPointer<WindowPixmap> m_currentPixmap;
QScopedPointer<WindowPixmap> m_previousPixmap;
int m_referencePixmapCounter;
2011-01-30 14:34:42 +00:00
int disable_painting;
mutable QRegion shape_region;
mutable bool shape_valid;
Scene: Fix memory leak Detected by ASAN ``` Indirect leak of 2080 byte(s) in 10 object(s) allocated from: #0 0x4dc922 in operator new(unsigned long) (/home/kfunk/devel/install/kf5/bin/kwin_x11+0x4dc922) #1 0x7f43db47efd6 in QList<KWin::WindowQuad>::node_construct(QList<KWin::WindowQuad>::Node*, KWin::WindowQuad const&) /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:404:65 #2 0x7f43db47e51c in QList<KWin::WindowQuad>::append(KWin::WindowQuad const&) /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:553:13 #3 0x7f43db72787d in KWin::Scene::Window::makeQuads(KWin::WindowQuadType, QRegion const&, QPoint const&) const /home/kfunk/devel/src/kf5/kwin/scene.cpp:927:9 #4 0x7f43db725817 in KWin::Scene::Window::buildQuads(bool) const /home/kfunk/devel/src/kf5/kwin/scene.cpp:834:15 #5 0x7f43db899c79 in KWin::EffectWindowImpl::buildQuads(bool) const /home/kfunk/devel/src/kf5/kwin/effects.cpp:1700:12 #6 0x7f43db4666d6 in KWin::Shadow::createShadow(KWin::Toplevel*) /home/kfunk/devel/src/kf5/kwin/shadow.cpp:69:17 #7 0x7f43db6fb825 in KWin::Toplevel::getShadow() /home/kfunk/devel/src/kf5/kwin/toplevel.cpp:318:9 #8 0x7f43db7197dc in KWin::Scene::windowAdded(KWin::Toplevel*) /home/kfunk/devel/src/kf5/kwin/scene.cpp:408:5 #9 0x7f43db6d6b71 in KWin::Toplevel::setupCompositing() /home/kfunk/devel/src/kf5/kwin/composite.cpp:981:5 #10 0x7f43db6db215 in KWin::Client::setupCompositing() /home/kfunk/devel/src/kf5/kwin/composite.cpp:1248:10 #11 0x7f43db6c4517 in KWin::Compositor::startupWithWorkspace() /home/kfunk/devel/src/kf5/kwin/composite.cpp:329:9 #12 0x7f43db6c28db in KWin::Compositor::slotCompositingOptionsInitialized() /home/kfunk/devel/src/kf5/kwin/composite.cpp:283:9 #13 0x7f43db6beda4 in KWin::Compositor::setup() /home/kfunk/devel/src/kf5/kwin/composite.cpp:184:9 #14 0x7f43dbef60af in KWin::Compositor::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) /home/kfunk/devel/build/kf5/kwin/moc_composite.cpp:263:18 #15 0x7f43d54de7b0 in QObject::event(QEvent*) (/usr/lib/x86_64-linux-gnu/libQt5Core.so.5+0x2b67b0) #16 0x7f43d5da39db in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x15b9db) ```
2016-02-01 20:41:48 +00:00
mutable QScopedPointer<WindowQuadList> cached_quad_list;
2011-01-30 14:34:42 +00:00
Q_DISABLE_COPY(Window)
};
/**
2019-01-12 10:31:32 +00:00
* @brief Wrapper for a pixmap of the Scene::Window.
*
* This class encapsulates the functionality to get the pixmap for a window. When initialized the pixmap is not yet
2019-01-12 10:31:32 +00:00
* mapped to the window and isValid will return @c false. The pixmap mapping to the window can be established
* through @ref create. If it succeeds isValid will return @c true, otherwise it will keep in the non valid
* state and it can be tried to create the pixmap mapping again (e.g. in the next frame).
*
* This class is not intended to be updated when the pixmap is no longer valid due to e.g. resizing the window.
* Instead a new instance of this class should be instantiated. The idea behind this is that a valid pixmap does not
* get destroyed, but can continue to be used. To indicate that a newer pixmap should in generally be around, one can
2019-01-12 10:31:32 +00:00
* use markAsDiscarded.
*
* This class is intended to be inherited for the needs of the compositor backends which need further mapping from
* the native pixmap to the respective rendering format.
*/
Move SceneXRender into a plugin Summary: First step for loading the compositor Scenes through plugins. The general idea is that we currently needlessly pull in all the Scenes although only one will be used. E.g. on X11 we pull in QPainter, although they are not compatible. On Wayland we pull in XRender although they are not compatible. Furthermore our current Scene creation strategy is not really fault tolerant and can create situations where we don't get a compositor. E.g on fbdev backend the default settings won't work as it does not support OpenGL. Long term I want to tackle those conceptional problems together: we try to load all plugins supported by the current platform till we have a scene which works. Thus on Wayland we don't end up in a situation where we don't have a working compositor because the configuration is bad. To make this possible the switch statement in the Scene needs to go and needs to be replaced by a for loop iterating over all the available scenes on the platform. If we go there it makes sense to replace it directly with a plugin based approach. So this is a change which tackles the problem by first introducing the plugin loading. The xrender based scene (as it's the most simple one) is moved into a plugin. It is first tried to find a scene plugin and only if there is none the existing code is used. Test Plan: Tested all scenes Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D7232
2017-08-10 16:13:42 +00:00
class KWIN_EXPORT WindowPixmap
{
public:
virtual ~WindowPixmap();
/**
* @brief Tries to create the mapping between the Window and the pixmap.
*
2019-01-12 10:31:32 +00:00
* In case this method succeeds in creating the pixmap for the window, isValid will return @c true otherwise
* @c false.
*
* Inheriting classes should re-implement this method in case they need to add further functionality for mapping the
* native pixmap to the rendering format.
*/
virtual void create();
/**
* @return @c true if the pixmap has been created and is valid, @c false otherwise
*/
virtual bool isValid() const;
/**
* @return The native X11 pixmap handle
*/
xcb_pixmap_t pixmap() const;
/**
* @return The Wayland BufferInterface for this WindowPixmap.
*/
QPointer<KWayland::Server::BufferInterface> buffer() const;
const QSharedPointer<QOpenGLFramebufferObject> &fbo() const;
/**
* @brief Whether this WindowPixmap is considered as discarded. This means the window has changed in a way that a new
* WindowPixmap should have been created already.
*
* @return @c true if this WindowPixmap is considered as discarded, @c false otherwise.
* @see markAsDiscarded
*/
bool isDiscarded() const;
/**
2019-01-12 10:31:32 +00:00
* @brief Marks this WindowPixmap as discarded. From now on isDiscarded will return @c true. This method should
* only be used by the Window when it changes in a way that a new pixmap is required.
*
* @see isDiscarded
*/
void markAsDiscarded();
/**
* The size of the pixmap.
*/
const QSize &size() const;
/**
* The geometry of the Client's content inside the pixmap. In case of a decorated Client the
* pixmap also contains the decoration which is not rendered into this pixmap, though. This
* contentsRect tells where inside the complete pixmap the real content is.
*/
const QRect &contentsRect() const;
/**
* @brief Returns the Toplevel this WindowPixmap belongs to.
* Note: the Toplevel can change over the lifetime of the WindowPixmap in case the Toplevel is copied to Deleted.
*/
Toplevel *toplevel() const;
/**
* @returns the parent WindowPixmap in the sub-surface tree
*/
WindowPixmap *parent() const {
return m_parent;
}
/**
* @returns the current sub-surface tree
*/
QVector<WindowPixmap*> children() const {
return m_children;
}
/**
* @returns the subsurface this WindowPixmap is for if it is not for a root window
*/
QPointer<KWayland::Server::SubSurfaceInterface> subSurface() const {
return m_subSurface;
}
/**
* @returns the surface this WindowPixmap references, might be @c null.
*/
KWayland::Server::SurfaceInterface *surface() const;
protected:
explicit WindowPixmap(Scene::Window *window);
explicit WindowPixmap(const QPointer<KWayland::Server::SubSurfaceInterface> &subSurface, WindowPixmap *parent);
virtual WindowPixmap *createChild(const QPointer<KWayland::Server::SubSurfaceInterface> &subSurface);
/**
* @return The Window this WindowPixmap belongs to
*/
Scene::Window *window();
/**
* Should be called by the implementing subclasses when the Wayland Buffer changed and needs
* updating.
*/
virtual void updateBuffer();
/**
* Sets the sub-surface tree to @p children.
*/
void setChildren(const QVector<WindowPixmap*> &children) {
m_children = children;
}
private:
Scene::Window *m_window;
xcb_pixmap_t m_pixmap;
QSize m_pixmapSize;
bool m_discarded;
QRect m_contentsRect;
QPointer<KWayland::Server::BufferInterface> m_buffer;
QSharedPointer<QOpenGLFramebufferObject> m_fbo;
WindowPixmap *m_parent = nullptr;
QVector<WindowPixmap*> m_children;
QPointer<KWayland::Server::SubSurfaceInterface> m_subSurface;
};
class Scene::EffectFrame
2011-01-30 14:34:42 +00:00
{
public:
EffectFrame(EffectFrameImpl* frame);
virtual ~EffectFrame();
virtual void render(QRegion region, double opacity, double frameOpacity) = 0;
virtual void free() = 0;
virtual void freeIconFrame() = 0;
virtual void freeTextFrame() = 0;
virtual void freeSelection() = 0;
virtual void crossFadeIcon() = 0;
virtual void crossFadeText() = 0;
protected:
EffectFrameImpl* m_effectFrame;
};
inline
int Scene::Window::x() const
2011-01-30 14:34:42 +00:00
{
return toplevel->x();
2011-01-30 14:34:42 +00:00
}
inline
int Scene::Window::y() const
2011-01-30 14:34:42 +00:00
{
return toplevel->y();
2011-01-30 14:34:42 +00:00
}
inline
int Scene::Window::width() const
2011-01-30 14:34:42 +00:00
{
return toplevel->width();
2011-01-30 14:34:42 +00:00
}
inline
int Scene::Window::height() const
2011-01-30 14:34:42 +00:00
{
return toplevel->height();
2011-01-30 14:34:42 +00:00
}
inline
QRect Scene::Window::geometry() const
2011-01-30 14:34:42 +00:00
{
return toplevel->geometry();
2011-01-30 14:34:42 +00:00
}
inline
QSize Scene::Window::size() const
2011-01-30 14:34:42 +00:00
{
return toplevel->size();
2011-01-30 14:34:42 +00:00
}
inline
QPoint Scene::Window::pos() const
2011-01-30 14:34:42 +00:00
{
return toplevel->pos();
2011-01-30 14:34:42 +00:00
}
inline
QRect Scene::Window::rect() const
2011-01-30 14:34:42 +00:00
{
return toplevel->rect();
2011-01-30 14:34:42 +00:00
}
inline
Toplevel* Scene::Window::window() const
2011-01-30 14:34:42 +00:00
{
return toplevel;
2011-01-30 14:34:42 +00:00
}
inline
2011-01-30 14:34:42 +00:00
void Scene::Window::updateToplevel(Toplevel* c)
{
toplevel = c;
2011-01-30 14:34:42 +00:00
}
inline
const Shadow* Scene::Window::shadow() const
{
return m_shadow;
}
inline
Shadow* Scene::Window::shadow()
{
return m_shadow;
}
inline
QPointer<KWayland::Server::BufferInterface> WindowPixmap::buffer() const
{
return m_buffer;
}
inline
const QSharedPointer<QOpenGLFramebufferObject> &WindowPixmap::fbo() const
{
return m_fbo;
}
template <typename T>
inline
T* Scene::Window::windowPixmap()
{
if (m_currentPixmap.isNull()) {
m_currentPixmap.reset(createWindowPixmap());
}
if (m_currentPixmap->isValid()) {
return static_cast<T*>(m_currentPixmap.data());
}
m_currentPixmap->create();
if (m_currentPixmap->isValid()) {
return static_cast<T*>(m_currentPixmap.data());
} else {
return static_cast<T*>(m_previousPixmap.data());
}
}
template <typename T>
inline
T* Scene::Window::previousWindowPixmap()
{
return static_cast<T*>(m_previousPixmap.data());
}
inline
Toplevel* WindowPixmap::toplevel() const
{
return m_window->window();
}
inline
xcb_pixmap_t WindowPixmap::pixmap() const
{
return m_pixmap;
}
inline
bool WindowPixmap::isDiscarded() const
{
return m_discarded;
}
inline
void WindowPixmap::markAsDiscarded()
{
m_discarded = true;
m_window->referencePreviousPixmap();
}
inline
const QRect &WindowPixmap::contentsRect() const
{
return m_contentsRect;
}
inline
const QSize &WindowPixmap::size() const
{
return m_pixmapSize;
}
} // namespace
Move SceneXRender into a plugin Summary: First step for loading the compositor Scenes through plugins. The general idea is that we currently needlessly pull in all the Scenes although only one will be used. E.g. on X11 we pull in QPainter, although they are not compatible. On Wayland we pull in XRender although they are not compatible. Furthermore our current Scene creation strategy is not really fault tolerant and can create situations where we don't get a compositor. E.g on fbdev backend the default settings won't work as it does not support OpenGL. Long term I want to tackle those conceptional problems together: we try to load all plugins supported by the current platform till we have a scene which works. Thus on Wayland we don't end up in a situation where we don't have a working compositor because the configuration is bad. To make this possible the switch statement in the Scene needs to go and needs to be replaced by a for loop iterating over all the available scenes on the platform. If we go there it makes sense to replace it directly with a plugin based approach. So this is a change which tackles the problem by first introducing the plugin loading. The xrender based scene (as it's the most simple one) is moved into a plugin. It is first tried to find a scene plugin and only if there is none the existing code is used. Test Plan: Tested all scenes Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D7232
2017-08-10 16:13:42 +00:00
Q_DECLARE_INTERFACE(KWin::SceneFactory, "org.kde.kwin.Scene")
#endif