2011-08-21 19:50:23 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
|
2012-08-23 11:42:59 +00:00
|
|
|
Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org>
|
2011-08-21 19:50:23 +00:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
2019-07-02 18:28:45 +00:00
|
|
|
#pragma once
|
2011-08-21 19:50:23 +00:00
|
|
|
|
2013-04-05 07:41:25 +00:00
|
|
|
#include <kwinglobals.h>
|
2019-07-02 18:28:45 +00:00
|
|
|
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QElapsedTimer>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QBasicTimer>
|
2011-08-21 19:50:23 +00:00
|
|
|
#include <QRegion>
|
2012-08-17 06:19:38 +00:00
|
|
|
|
2019-07-02 18:28:45 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
2012-08-23 11:42:59 +00:00
|
|
|
class Client;
|
2019-06-22 10:40:12 +00:00
|
|
|
class CompositorSelectionOwner;
|
2012-08-16 19:19:54 +00:00
|
|
|
class Scene;
|
2011-08-21 19:50:23 +00:00
|
|
|
|
2019-07-02 18:28:45 +00:00
|
|
|
class KWIN_EXPORT Compositor : public QObject
|
|
|
|
{
|
2011-08-21 19:50:23 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-07-04 01:19:18 +00:00
|
|
|
enum class State {
|
|
|
|
On = 0,
|
|
|
|
Off,
|
|
|
|
Starting,
|
|
|
|
Stopping
|
|
|
|
};
|
|
|
|
|
2019-07-02 18:28:45 +00:00
|
|
|
~Compositor() override;
|
2019-08-07 17:33:20 +00:00
|
|
|
static Compositor *self();
|
2019-07-02 18:28:45 +00:00
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
// when adding repaints caused by a window, you probably want to use
|
|
|
|
// either Toplevel::addRepaint() or Toplevel::addWorkspaceRepaint()
|
|
|
|
void addRepaint(const QRect& r);
|
|
|
|
void addRepaint(const QRegion& r);
|
|
|
|
void addRepaint(int x, int y, int w, int h);
|
2019-07-02 18:28:45 +00:00
|
|
|
void addRepaintFull();
|
2012-08-16 19:19:54 +00:00
|
|
|
|
|
|
|
/**
|
2019-07-02 18:28:45 +00:00
|
|
|
* Schedules a new repaint if no repaint is currently scheduled.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-07-02 18:28:45 +00:00
|
|
|
void scheduleRepaint();
|
2011-08-21 19:50:23 +00:00
|
|
|
|
2012-08-28 17:31:17 +00:00
|
|
|
/**
|
2019-07-02 18:28:45 +00:00
|
|
|
* Notifies the compositor that SwapBuffers() is about to be called.
|
|
|
|
* Rendering of the next frame will be deferred until bufferSwapComplete()
|
|
|
|
* is called.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-07-02 18:28:45 +00:00
|
|
|
void aboutToSwapBuffers();
|
|
|
|
|
2012-08-28 17:31:17 +00:00
|
|
|
/**
|
2019-07-02 18:28:45 +00:00
|
|
|
* Notifies the compositor that a pending buffer swap has completed.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-07-02 18:28:45 +00:00
|
|
|
void bufferSwapComplete();
|
2013-04-26 22:00:23 +00:00
|
|
|
|
2012-08-17 06:18:36 +00:00
|
|
|
/**
|
2019-07-02 18:28:45 +00:00
|
|
|
* Toggles compositing, that is if the Compositor is suspended it will be resumed
|
|
|
|
* and if the Compositor is active it will be suspended.
|
|
|
|
* Invoked by keybinding (shortcut default: Shift + Alt + F12).
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-08-07 17:33:20 +00:00
|
|
|
virtual void toggleCompositing() = 0;
|
2019-07-02 18:28:45 +00:00
|
|
|
|
2012-08-17 08:15:33 +00:00
|
|
|
/**
|
|
|
|
* Re-initializes the Compositor completely.
|
|
|
|
* Connected to the D-Bus signal org.kde.KWin /KWin reinitCompositing
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-08-07 17:33:20 +00:00
|
|
|
virtual void reinitialize();
|
2019-07-02 18:28:45 +00:00
|
|
|
|
2012-08-23 11:42:59 +00:00
|
|
|
/**
|
2019-07-02 18:28:45 +00:00
|
|
|
* Whether the Compositor is active. That is a Scene is present and the Compositor is
|
|
|
|
* not shutting down itself.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-07-02 18:28:45 +00:00
|
|
|
bool isActive();
|
2019-08-07 17:33:20 +00:00
|
|
|
virtual int refreshRate() const = 0;
|
2019-07-02 18:28:45 +00:00
|
|
|
|
|
|
|
bool hasScene() const {
|
|
|
|
return m_scene != NULL;
|
|
|
|
}
|
2019-08-07 17:33:20 +00:00
|
|
|
Scene *scene() const {
|
|
|
|
return m_scene;
|
|
|
|
}
|
2011-08-21 19:50:23 +00:00
|
|
|
|
2014-08-27 16:24:43 +00:00
|
|
|
/**
|
2019-07-02 18:28:45 +00:00
|
|
|
* Checks whether @p w is the Scene's overlay window.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-08-07 17:33:20 +00:00
|
|
|
virtual bool checkForOverlayWindow(WId w) const = 0;
|
2014-08-27 16:24:43 +00:00
|
|
|
|
2019-07-02 18:28:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Static check to test whether the Compositor is available and active.
|
|
|
|
*
|
|
|
|
* @return bool @c true if there is a Compositor and it is active, @c false otherwise
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-07-02 18:28:45 +00:00
|
|
|
static bool compositing() {
|
|
|
|
return s_compositor != NULL && s_compositor->isActive();
|
|
|
|
}
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
|
|
|
|
virtual void updateCompositeBlocking() = 0;
|
|
|
|
virtual void updateClientCompositeBlocking(KWin::Client *c) = 0;
|
2019-07-02 18:28:45 +00:00
|
|
|
|
|
|
|
// for delayed supportproperty management of effects
|
|
|
|
void keepSupportProperty(xcb_atom_t atom);
|
|
|
|
void removeSupportProperty(xcb_atom_t atom);
|
2014-08-27 16:24:43 +00:00
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
Q_SIGNALS:
|
2014-06-02 06:51:28 +00:00
|
|
|
void compositingToggled(bool active);
|
2014-12-03 12:10:35 +00:00
|
|
|
void aboutToDestroy();
|
2019-02-20 13:09:37 +00:00
|
|
|
void aboutToToggleCompositing();
|
2016-04-14 06:51:16 +00:00
|
|
|
void sceneCreated();
|
2019-02-21 22:25:19 +00:00
|
|
|
void bufferSwapCompleted();
|
2011-08-21 19:50:23 +00:00
|
|
|
|
|
|
|
protected:
|
2019-08-07 17:33:20 +00:00
|
|
|
explicit Compositor(QObject *parent = nullptr);
|
2019-07-02 18:28:45 +00:00
|
|
|
void timerEvent(QTimerEvent *te) override;
|
2011-08-21 19:50:23 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
virtual void start() = 0;
|
2019-07-04 01:19:18 +00:00
|
|
|
void stop();
|
2011-08-21 19:50:23 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
/**
|
|
|
|
* @brief Prepares start.
|
|
|
|
* @return bool @c true if start should be continued and @c if not.
|
|
|
|
*/
|
|
|
|
bool setupStart();
|
2015-02-23 14:57:00 +00:00
|
|
|
/**
|
|
|
|
* Continues the startup after Scene And Workspace are created
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-02-23 14:57:00 +00:00
|
|
|
void startupWithWorkspace();
|
2019-08-07 17:33:20 +00:00
|
|
|
virtual void performCompositing();
|
|
|
|
|
|
|
|
virtual void configChanged();
|
|
|
|
|
|
|
|
void destroyCompositorSelection();
|
|
|
|
|
|
|
|
static Compositor *s_compositor;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void claimCompositorSelection();
|
|
|
|
|
2017-08-24 08:43:38 +00:00
|
|
|
void setupX11Support();
|
2011-08-21 19:50:23 +00:00
|
|
|
|
2019-07-02 18:28:45 +00:00
|
|
|
void setCompositeTimer();
|
|
|
|
bool windowRepaintsPending() const;
|
|
|
|
|
|
|
|
void releaseCompositorSelection();
|
|
|
|
void deleteUnusedSupportProperties();
|
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
State m_state;
|
2013-01-09 15:03:54 +00:00
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
QBasicTimer compositeTimer;
|
2019-06-22 10:40:12 +00:00
|
|
|
CompositorSelectionOwner *m_selectionOwner;
|
2012-10-14 10:18:35 +00:00
|
|
|
QTimer m_releaseSelectionTimer;
|
2013-04-26 22:00:23 +00:00
|
|
|
QList<xcb_atom_t> m_unusedSupportProperties;
|
|
|
|
QTimer m_unusedSupportPropertyTimer;
|
2013-03-28 20:53:25 +00:00
|
|
|
qint64 vBlankInterval, fpsInterval;
|
2011-08-21 19:50:23 +00:00
|
|
|
QRegion repaints_region;
|
|
|
|
|
2013-03-28 20:53:25 +00:00
|
|
|
qint64 m_timeSinceLastVBlank;
|
2019-07-02 18:28:45 +00:00
|
|
|
|
2012-08-16 19:19:54 +00:00
|
|
|
Scene *m_scene;
|
2019-07-02 18:28:45 +00:00
|
|
|
|
2014-08-27 16:24:43 +00:00
|
|
|
bool m_bufferSwapPending;
|
|
|
|
bool m_composeAtSwapCompletion;
|
2019-07-02 18:28:45 +00:00
|
|
|
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
int m_framesToTestForSafety = 3;
|
[wayland] Send correct current time in the frame callback
Summary:
Currently, each frame callback sent by KWin has the current time in
nanoseconds, but the protocol spec states that we have to send the time
in milliseconds. This is the reason why animations that are driven by
frame callbacks are too fast.
In addition to that, m_timeSinceStart isn't actually "time since start,"
it's rather accumulated duration of all painting cycles. If there is
something to draw and it takes quite a while to compose the scene, maybe
m_timeSinceStart will be close enough to the current time. So, it has
been replaced with QElapsedTimer, this makes the current time correct
and also simplifies code a little bit.
Test Plan: The triangle in weston-subsurfaces no longer spins very fast.
Reviewers: #kwin, romangg
Reviewed By: #kwin, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18656
2019-02-01 21:39:22 +00:00
|
|
|
QElapsedTimer m_monotonicClock;
|
2019-08-07 17:33:20 +00:00
|
|
|
};
|
2012-08-28 17:31:17 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
class KWIN_EXPORT WaylandCompositor : public Compositor
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static WaylandCompositor *create(QObject *parent = nullptr);
|
|
|
|
~WaylandCompositor() override = default;
|
|
|
|
|
|
|
|
int refreshRate() const override;
|
|
|
|
|
|
|
|
void toggleCompositing() override;
|
|
|
|
|
|
|
|
bool checkForOverlayWindow(WId w) const override;
|
|
|
|
|
|
|
|
void updateCompositeBlocking() override;
|
|
|
|
void updateClientCompositeBlocking(KWin::Client* c) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void start() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit WaylandCompositor(QObject *parent);
|
|
|
|
};
|
|
|
|
|
|
|
|
class KWIN_EXPORT X11Compositor : public Compositor
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum SuspendReason {
|
|
|
|
NoReasonSuspend = 0,
|
|
|
|
UserSuspend = 1 << 0,
|
|
|
|
BlockRuleSuspend = 1 << 1,
|
|
|
|
ScriptSuspend = 1 << 2,
|
|
|
|
AllReasonSuspend = 0xff
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(SuspendReasons, SuspendReason)
|
|
|
|
|
|
|
|
static X11Compositor *create(QObject *parent = nullptr);
|
|
|
|
~X11Compositor() override = default;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Suspends the Compositor if it is currently active.
|
|
|
|
*
|
|
|
|
* Note: it is possible that the Compositor is not able to suspend. Use isActive to check
|
|
|
|
* whether the Compositor has been suspended.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @see resume
|
|
|
|
* @see isActive
|
|
|
|
**/
|
|
|
|
Q_INVOKABLE void suspend(SuspendReason reason);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Resumes the Compositor if it is currently suspended.
|
|
|
|
*
|
|
|
|
* Note: it is possible that the Compositor cannot be resumed, that is there might be Clients
|
|
|
|
* blocking the usage of Compositing or the Scene might be broken. Use isActive to check
|
|
|
|
* whether the Compositor has been resumed. Also check isCompositingPossible and
|
|
|
|
* isOpenGLBroken.
|
|
|
|
*
|
|
|
|
* Note: The starting of the Compositor can require some time and is partially done threaded.
|
|
|
|
* After this method returns the setup may not have been completed.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @see suspend
|
|
|
|
* @see isActive
|
|
|
|
* @see isCompositingPossible
|
|
|
|
* @see isOpenGLBroken
|
|
|
|
**/
|
|
|
|
Q_INVOKABLE void resume(SuspendReason reason);
|
|
|
|
|
|
|
|
void toggleCompositing() override;
|
|
|
|
void reinitialize() override;
|
|
|
|
|
|
|
|
void configChanged() override;
|
|
|
|
|
|
|
|
bool checkForOverlayWindow(WId w) const override;
|
|
|
|
/**
|
|
|
|
* @returns Whether the Scene's Overlay X Window is visible.
|
|
|
|
**/
|
|
|
|
bool isOverlayWindowVisible() const;
|
|
|
|
|
|
|
|
int refreshRate() const override;
|
|
|
|
|
|
|
|
void updateCompositeBlocking() override;
|
|
|
|
void updateClientCompositeBlocking(KWin::Client* c) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void start() override;
|
|
|
|
void performCompositing() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit X11Compositor(QObject *parent);
|
|
|
|
/**
|
|
|
|
* Whether the Compositor is currently suspended, 8 bits encoding the reason
|
|
|
|
**/
|
|
|
|
SuspendReasons m_suspended;
|
|
|
|
|
|
|
|
int m_xrrRefreshRate;
|
2011-08-21 19:50:23 +00:00
|
|
|
};
|
|
|
|
|
2019-07-02 18:28:45 +00:00
|
|
|
}
|