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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#ifndef KWIN_COMPOSITE_H
|
|
|
|
#define KWIN_COMPOSITE_H
|
|
|
|
|
|
|
|
#include <QtCore/QObject>
|
2012-08-28 17:31:17 +00:00
|
|
|
#include <QtCore/QElapsedTimer>
|
2011-08-21 19:50:23 +00:00
|
|
|
#include <QtCore/QTimer>
|
2012-09-03 01:33:17 +00:00
|
|
|
#include <QtCore/QBasicTimer>
|
2011-08-21 19:50:23 +00:00
|
|
|
#include <QRegion>
|
2012-08-17 06:19:38 +00:00
|
|
|
|
|
|
|
class KSelectionOwner;
|
2011-08-21 19:50:23 +00:00
|
|
|
|
|
|
|
namespace KWin {
|
|
|
|
|
2012-08-23 11:42:59 +00:00
|
|
|
class Client;
|
2012-08-16 19:19:54 +00:00
|
|
|
class Scene;
|
2011-08-21 19:50:23 +00:00
|
|
|
|
|
|
|
class Compositor : public QObject {
|
|
|
|
Q_OBJECT
|
2012-08-30 06:20:26 +00:00
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Compositing")
|
|
|
|
/**
|
|
|
|
* @brief Whether the Compositor is active. That is a Scene is present and the Compositor is
|
|
|
|
* not shutting down itself.
|
|
|
|
**/
|
|
|
|
Q_PROPERTY(bool active READ isActive)
|
|
|
|
/**
|
|
|
|
* @brief Whether compositing is possible. Mostly means whether the required X extensions
|
|
|
|
* are available.
|
|
|
|
**/
|
|
|
|
Q_PROPERTY(bool compositingPossible READ isCompositingPossible)
|
|
|
|
/**
|
|
|
|
* @brief The reason why compositing is not possible. Empty String if compositing is possible.
|
|
|
|
**/
|
|
|
|
Q_PROPERTY(QString compositingNotPossibleReason READ compositingNotPossibleReason)
|
|
|
|
/**
|
|
|
|
* @brief Whether OpenGL has failed badly in the past (crash) and is considered as broken.
|
|
|
|
**/
|
|
|
|
Q_PROPERTY(bool openGLIsBroken READ isOpenGLBroken)
|
|
|
|
/**
|
|
|
|
* The type of the currently used Scene:
|
|
|
|
* @li @c none No Compositing
|
|
|
|
* @li @c xrender XRender
|
|
|
|
* @li @c gl1 OpenGL 1
|
|
|
|
* @li @c gl2 OpenGL 2
|
|
|
|
* @li @c gles OpenGL ES 2
|
|
|
|
**/
|
|
|
|
Q_PROPERTY(QString compositingType READ compositingType)
|
2011-08-21 19:50:23 +00:00
|
|
|
public:
|
|
|
|
~Compositor();
|
|
|
|
// 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);
|
|
|
|
// Mouse polling
|
|
|
|
void startMousePolling();
|
|
|
|
void stopMousePolling();
|
2012-08-17 06:18:36 +00:00
|
|
|
/**
|
|
|
|
* Whether the Compositor is active. That is a Scene is present and the Compositor is
|
|
|
|
* not shutting down itself.
|
|
|
|
**/
|
|
|
|
bool isActive();
|
|
|
|
int xrrRefreshRate() const {
|
2011-08-21 19:50:23 +00:00
|
|
|
return m_xrrRefreshRate;
|
|
|
|
}
|
|
|
|
void setCompositeResetTimer(int msecs);
|
|
|
|
// returns the _estimated_ delay to the next screen update
|
|
|
|
// good for having a rough idea to calculate transformations, bad to rely on.
|
|
|
|
// might happen few ms earlier, might be an entire frame to short. This is NOT deterministic.
|
2012-08-17 06:18:36 +00:00
|
|
|
int nextFrameDelay() const {
|
2011-08-21 19:50:23 +00:00
|
|
|
return m_nextFrameDelay;
|
|
|
|
}
|
2012-08-16 19:19:54 +00:00
|
|
|
bool hasScene() const {
|
|
|
|
return m_scene != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether @p w is the Scene's overlay window.
|
|
|
|
**/
|
|
|
|
bool checkForOverlayWindow(WId w) const;
|
|
|
|
/**
|
|
|
|
* @returns The Scene's Overlay X Window.
|
|
|
|
**/
|
|
|
|
WId overlayWindow() const;
|
|
|
|
/**
|
|
|
|
* @returns Whether the Scene's Overlay X Window is visible.
|
|
|
|
**/
|
|
|
|
bool isOverlayWindowVisible() const;
|
|
|
|
/**
|
|
|
|
* Set's the Scene's Overlay X Window visibility to @p visible.
|
|
|
|
**/
|
|
|
|
void setOverlayWindowVisibility(bool visible);
|
|
|
|
|
|
|
|
Scene *scene() {
|
|
|
|
return m_scene;
|
|
|
|
}
|
2011-08-21 19:50:23 +00:00
|
|
|
|
2012-08-28 17:31:17 +00:00
|
|
|
/**
|
|
|
|
* @brief Factory Method to create the Compositor singleton.
|
|
|
|
*
|
|
|
|
* This method is mainly used by Workspace to create the Compositor Singleton as a child
|
|
|
|
* of the Workspace.
|
|
|
|
*
|
|
|
|
* To actually access the Compositor instance use @link self.
|
|
|
|
*
|
|
|
|
* @param parent The parent object
|
|
|
|
* @return :Compositor* Created Compositor if not already created
|
|
|
|
* @warning This method is not Thread safe.
|
|
|
|
* @see self
|
|
|
|
**/
|
|
|
|
static Compositor *createCompositor(QObject *parent);
|
|
|
|
/**
|
|
|
|
* @brief Singleton getter for the Compositor object.
|
|
|
|
*
|
|
|
|
* Ensure that the Compositor has been created through createCompositor prior to access
|
|
|
|
* this method.
|
|
|
|
*
|
|
|
|
* @return :Compositor* The Compositor instance
|
|
|
|
* @see createCompositor
|
|
|
|
**/
|
|
|
|
static Compositor *self() {
|
|
|
|
Q_ASSERT(s_compositor);
|
|
|
|
return s_compositor;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @brief Checks whether the Compositor has already been created by the Workspace.
|
|
|
|
*
|
|
|
|
* This method can be used to check whether self will return the Compositor instance or @c null.
|
|
|
|
*
|
|
|
|
* @return bool @c true if the Compositor has been created, @c false otherwise
|
|
|
|
**/
|
|
|
|
static bool isCreated() {
|
|
|
|
return s_compositor != NULL;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
**/
|
|
|
|
static bool compositing() {
|
|
|
|
return s_compositor != NULL && s_compositor->isActive();
|
|
|
|
}
|
|
|
|
|
2012-08-30 06:20:26 +00:00
|
|
|
// D-Bus: getters for Properties, see documentation on the property
|
|
|
|
bool isCompositingPossible() const;
|
|
|
|
QString compositingNotPossibleReason() const;
|
|
|
|
bool isOpenGLBroken() const;
|
|
|
|
QString compositingType() const;
|
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
public Q_SLOTS:
|
|
|
|
void addRepaintFull();
|
2012-08-30 06:20:26 +00:00
|
|
|
/**
|
|
|
|
* Called from the D-Bus interface. Does the same as slotToggleCompositing with the
|
|
|
|
* addition to show a notification on how to revert the compositing state.
|
|
|
|
**/
|
|
|
|
Q_SCRIPTABLE void toggleCompositing();
|
2012-08-17 06:18:36 +00:00
|
|
|
/**
|
|
|
|
* Actual slot to perform the toggling compositing.
|
|
|
|
* That is if the Compositor is suspended it will be resumed and if the Compositor is active
|
|
|
|
* it will be suspended.
|
|
|
|
* Invoked primarily by the keybinding.
|
|
|
|
* TODO: make private slot
|
|
|
|
**/
|
2011-08-21 19:50:23 +00:00
|
|
|
void slotToggleCompositing();
|
2012-08-17 08:15:33 +00:00
|
|
|
/**
|
|
|
|
* Re-initializes the Compositor completely.
|
|
|
|
* Connected to the D-Bus signal org.kde.KWin /KWin reinitCompositing
|
|
|
|
**/
|
|
|
|
void slotReinitialize();
|
2012-08-23 11:42:59 +00:00
|
|
|
/**
|
|
|
|
* Schedules a new repaint if no repaint is currently scheduled.
|
|
|
|
**/
|
|
|
|
void scheduleRepaint();
|
|
|
|
void checkUnredirect();
|
|
|
|
void checkUnredirect(bool force);
|
|
|
|
void updateCompositeBlocking();
|
|
|
|
void updateCompositeBlocking(KWin::Client* c);
|
2011-08-21 19:50:23 +00:00
|
|
|
|
2012-08-30 06:20:26 +00:00
|
|
|
// For the D-Bus interface
|
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
Q_SIGNALS:
|
2012-08-30 06:20:26 +00:00
|
|
|
Q_SCRIPTABLE void compositingToggled(bool active);
|
2011-08-21 19:50:23 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void timerEvent(QTimerEvent *te);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2012-08-17 06:18:36 +00:00
|
|
|
void setup();
|
2011-08-21 19:50:23 +00:00
|
|
|
/**
|
|
|
|
* Called from setupCompositing() when the CompositingPrefs are ready.
|
|
|
|
**/
|
|
|
|
void slotCompositingOptionsInitialized();
|
2012-08-17 06:18:36 +00:00
|
|
|
void finish();
|
|
|
|
/**
|
|
|
|
* Restarts the Compositor if running.
|
|
|
|
* That is the Compositor will be stopped and started again.
|
|
|
|
**/
|
|
|
|
void restart();
|
2011-08-21 19:50:23 +00:00
|
|
|
void fallbackToXRenderCompositing();
|
|
|
|
void performCompositing();
|
|
|
|
void performMousePoll();
|
|
|
|
void delayedCheckUnredirect();
|
|
|
|
void slotConfigChanged();
|
|
|
|
|
|
|
|
private:
|
2012-08-28 17:31:17 +00:00
|
|
|
Compositor(QObject *workspace);
|
2012-08-17 06:18:36 +00:00
|
|
|
/**
|
|
|
|
* Suspends or Resumes the Compositor.
|
|
|
|
* That is stops the Scene in case of @p suspend and restores otherwise.
|
|
|
|
* @param suspend If @c true suspends the Compositor, if @c false starts the Compositor.
|
|
|
|
* TODO: split in two methods: suspend and resume
|
|
|
|
**/
|
|
|
|
void suspendResume(bool suspend = true);
|
2011-08-21 19:50:23 +00:00
|
|
|
void setCompositeTimer();
|
|
|
|
bool windowRepaintsPending() const;
|
|
|
|
|
2012-08-17 08:15:33 +00:00
|
|
|
/**
|
|
|
|
* Restarts the Window Manager in case that the Qt's GraphicsSystem need to be changed
|
|
|
|
* for the chosen Compositing backend.
|
|
|
|
* @param reason The reason why the Window Manager is being restarted, this is logged
|
|
|
|
**/
|
|
|
|
void restartKWin(const QString &reason);
|
|
|
|
|
2012-08-17 06:18:36 +00:00
|
|
|
/**
|
|
|
|
* Whether the Compositor is currently suspended.
|
|
|
|
**/
|
|
|
|
bool m_suspended;
|
|
|
|
/**
|
|
|
|
* Whether the Compositor is currently blocked by at least one Client requesting full resources.
|
|
|
|
**/
|
|
|
|
bool m_blocked;
|
2011-08-21 19:50:23 +00:00
|
|
|
QBasicTimer compositeTimer;
|
|
|
|
KSelectionOwner* cm_selection;
|
|
|
|
uint vBlankInterval, fpsInterval;
|
|
|
|
int m_xrrRefreshRate;
|
|
|
|
QElapsedTimer nextPaintReference;
|
|
|
|
QTimer mousePollingTimer;
|
|
|
|
QRegion repaints_region;
|
|
|
|
|
|
|
|
QTimer unredirectTimer;
|
|
|
|
bool forceUnredirectCheck;
|
|
|
|
QTimer compositeResetTimer; // for compressing composite resets
|
2012-08-17 06:18:36 +00:00
|
|
|
bool m_finishing; // finish() sets this variable while shutting down
|
2011-08-21 19:50:23 +00:00
|
|
|
int m_timeSinceLastVBlank, m_nextFrameDelay;
|
2012-08-16 19:19:54 +00:00
|
|
|
Scene *m_scene;
|
2012-08-28 17:31:17 +00:00
|
|
|
|
|
|
|
static Compositor *s_compositor;
|
2011-08-21 19:50:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
# endif // KWIN_COMPOSITE_H
|