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
|
2013-04-05 07:41:25 +00:00
|
|
|
// KWin
|
|
|
|
#include <kwinglobals.h>
|
2013-04-26 15:11:37 +00:00
|
|
|
// KDE
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KSelectionOwner>
|
2013-04-05 07:41:25 +00:00
|
|
|
// Qt
|
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
|
|
|
|
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
|
|
|
|
2013-04-26 15:11:37 +00:00
|
|
|
class CompositorSelectionOwner : public KSelectionOwner
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
CompositorSelectionOwner(const char *selection);
|
|
|
|
private:
|
|
|
|
friend class Compositor;
|
|
|
|
bool owning;
|
2013-07-22 14:07:39 +00:00
|
|
|
private Q_SLOTS:
|
2013-04-26 15:11:37 +00:00
|
|
|
void looseOwnership();
|
|
|
|
};
|
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
class Compositor : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-01-09 15:03:54 +00:00
|
|
|
enum SuspendReason { NoReasonSuspend = 0, UserSuspend = 1<<0, BlockRuleSuspend = 1<<1, ScriptSuspend = 1<<2, AllReasonSuspend = 0xff };
|
|
|
|
Q_DECLARE_FLAGS(SuspendReasons, SuspendReason)
|
2011-08-21 19:50:23 +00:00
|
|
|
~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);
|
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);
|
2013-04-10 20:14:17 +00:00
|
|
|
|
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 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();
|
|
|
|
}
|
|
|
|
|
2013-04-26 22:00:23 +00:00
|
|
|
// for delayed supportproperty management of effects
|
|
|
|
void keepSupportProperty(xcb_atom_t atom);
|
|
|
|
void removeSupportProperty(xcb_atom_t atom);
|
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
public Q_SLOTS:
|
|
|
|
void addRepaintFull();
|
2012-09-01 07:10:56 +00:00
|
|
|
/**
|
|
|
|
* @brief Suspends the Compositor if it is currently active.
|
|
|
|
*
|
|
|
|
* Note: it is possible that the Compositor is not able to suspend. Use @link isActive to check
|
|
|
|
* whether the Compositor has been suspended.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @see resume
|
|
|
|
* @see isActive
|
|
|
|
**/
|
2013-01-09 15:03:54 +00:00
|
|
|
void suspend(Compositor::SuspendReason reason);
|
2012-09-01 07:10:56 +00:00
|
|
|
/**
|
|
|
|
* @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 @link isActive to check
|
|
|
|
* whether the Compositor has been resumed. Also check @link isCompositingPossible and
|
|
|
|
* @link 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
|
|
|
|
**/
|
2013-01-09 15:03:54 +00:00
|
|
|
void resume(Compositor::SuspendReason reason);
|
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
|
|
|
|
2014-08-27 16:24:43 +00:00
|
|
|
/**
|
|
|
|
* Notifies the compositor that SwapBuffers() is about to be called.
|
|
|
|
* Rendering of the next frame will be deferred until bufferSwapComplete()
|
|
|
|
* is called.
|
|
|
|
*/
|
|
|
|
void aboutToSwapBuffers();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies the compositor that a pending buffer swap has completed.
|
|
|
|
*/
|
|
|
|
void bufferSwapComplete();
|
|
|
|
|
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();
|
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 delayedCheckUnredirect();
|
|
|
|
void slotConfigChanged();
|
2012-10-14 10:18:35 +00:00
|
|
|
void releaseCompositorSelection();
|
2013-04-26 22:00:23 +00:00
|
|
|
void deleteUnusedSupportProperties();
|
2011-08-21 19:50:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setCompositeTimer();
|
|
|
|
bool windowRepaintsPending() const;
|
|
|
|
|
2012-08-17 06:18:36 +00:00
|
|
|
/**
|
2013-01-09 15:03:54 +00:00
|
|
|
* Whether the Compositor is currently suspended, 8 bits encoding the reason
|
2012-08-17 06:18:36 +00:00
|
|
|
**/
|
2013-01-09 15:03:54 +00:00
|
|
|
SuspendReasons m_suspended;
|
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
QBasicTimer compositeTimer;
|
2013-04-26 15:11:37 +00:00
|
|
|
CompositorSelectionOwner* cm_selection;
|
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
|
|
|
int m_xrrRefreshRate;
|
|
|
|
QElapsedTimer nextPaintReference;
|
|
|
|
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
|
2012-10-14 10:18:35 +00:00
|
|
|
bool m_starting; // start() sets this variable while starting
|
2013-03-28 20:53:25 +00:00
|
|
|
qint64 m_timeSinceLastVBlank;
|
2012-08-16 19:19:54 +00:00
|
|
|
Scene *m_scene;
|
2014-08-27 16:24:43 +00:00
|
|
|
bool m_bufferSwapPending;
|
|
|
|
bool m_composeAtSwapCompletion;
|
2012-08-28 17:31:17 +00:00
|
|
|
|
2013-04-05 07:41:25 +00:00
|
|
|
KWIN_SINGLETON_VARIABLE(Compositor, s_compositor)
|
2011-08-21 19:50:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
# endif // KWIN_COMPOSITE_H
|