2009-04-22 17:29:56 +00:00
|
|
|
/*****************************************************************
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2009 Lubos Lunak <l.lunak@kde.org>
|
2012-09-28 09:59:42 +00:00
|
|
|
Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org>
|
2009-04-22 17:29:56 +00:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
copy of this software and associated documentation files (the "Software"),
|
|
|
|
to deal in the Software without restriction, including without limitation
|
|
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
DEALINGS IN THE SOFTWARE.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#ifndef PAINTREDIRECTOR_H
|
|
|
|
#define PAINTREDIRECTOR_H
|
|
|
|
|
|
|
|
#include <qregion.h>
|
|
|
|
#include <qtimer.h>
|
|
|
|
#include <qwidget.h>
|
2010-03-16 16:34:39 +00:00
|
|
|
#include <qbasictimer.h>
|
2013-02-18 08:07:42 +00:00
|
|
|
// xcb
|
|
|
|
#include <xcb/render.h>
|
2009-04-22 17:29:56 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
2013-02-18 08:07:42 +00:00
|
|
|
|
2012-09-28 09:59:42 +00:00
|
|
|
// forward declarations
|
|
|
|
class Client;
|
|
|
|
class Deleted;
|
2013-02-18 08:07:42 +00:00
|
|
|
class XRenderPicture;
|
2013-02-22 09:13:46 +00:00
|
|
|
class GLTexture;
|
2009-04-22 17:29:56 +00:00
|
|
|
|
|
|
|
// This class redirects all painting of a given widget (including its children)
|
|
|
|
// into a paint device (QPixmap).
|
|
|
|
class PaintRedirector
|
|
|
|
: public QObject
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-04-22 17:29:56 +00:00
|
|
|
Q_OBJECT
|
2011-01-30 14:34:42 +00:00
|
|
|
public:
|
2012-09-28 09:59:42 +00:00
|
|
|
enum DecorationPixmap {
|
|
|
|
TopPixmap,
|
|
|
|
RightPixmap,
|
|
|
|
BottomPixmap,
|
|
|
|
LeftPixmap,
|
|
|
|
PixmapCount
|
|
|
|
};
|
|
|
|
virtual ~PaintRedirector();
|
2011-01-30 14:34:42 +00:00
|
|
|
virtual bool eventFilter(QObject* o, QEvent* e);
|
|
|
|
QRegion pendingRegion() const;
|
|
|
|
QRegion scheduledRepaintRegion();
|
2012-09-28 09:59:42 +00:00
|
|
|
|
|
|
|
void markAsRepainted() {
|
|
|
|
m_requiresRepaint = false;
|
|
|
|
}
|
|
|
|
bool requiresRepaint() const {
|
|
|
|
return m_requiresRepaint;
|
|
|
|
}
|
|
|
|
void resizePixmaps();
|
|
|
|
|
2013-02-18 08:07:42 +00:00
|
|
|
template <typename T>
|
|
|
|
T topDecoPixmap() const;
|
|
|
|
template <typename T>
|
|
|
|
T leftDecoPixmap() const;
|
|
|
|
template <typename T>
|
|
|
|
T bottomDecoPixmap() const;
|
|
|
|
template <typename T>
|
|
|
|
T rightDecoPixmap() const;
|
2012-09-28 09:59:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used by Deleted::copyToDeleted() to move the PaintRedirector to the Deleted.
|
|
|
|
* The actual redirecting ends as the decoration gets destroyed after the Deleted
|
|
|
|
* is created.
|
|
|
|
**/
|
|
|
|
void reparent(Deleted *d);
|
2013-02-18 08:07:42 +00:00
|
|
|
static PaintRedirector *create(Client *c, QWidget* widget);
|
2012-09-28 09:59:42 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void ensurePixmapsPainted();
|
2013-02-18 08:07:42 +00:00
|
|
|
protected:
|
|
|
|
PaintRedirector(Client *c, QWidget* widget);
|
|
|
|
virtual xcb_render_picture_t picture(DecorationPixmap border) const;
|
2013-02-22 09:13:46 +00:00
|
|
|
virtual GLTexture *texture(DecorationPixmap border) const;
|
2013-02-18 08:07:42 +00:00
|
|
|
virtual void resize(DecorationPixmap border, const QSize &size) = 0;
|
|
|
|
virtual void preparePaint(const QPixmap &pending);
|
2013-02-25 09:18:02 +00:00
|
|
|
virtual void paint(DecorationPixmap border, const QRect& r, const QRect &b, const QRegion ®) = 0;
|
|
|
|
virtual QPaintDevice *scratch() = 0;
|
|
|
|
virtual QPaintDevice *recreateScratch(const QSize &size) = 0;
|
|
|
|
virtual void fillScratch(Qt::GlobalColor color) = 0;
|
|
|
|
virtual void discardScratch() = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
private:
|
|
|
|
void added(QWidget* widget);
|
|
|
|
void removed(QWidget* widget);
|
|
|
|
bool isToolTip(QWidget* widget) const;
|
|
|
|
void timerEvent(QTimerEvent* event);
|
2012-09-28 09:59:42 +00:00
|
|
|
|
2013-02-25 09:18:02 +00:00
|
|
|
void performPendingPaint();
|
|
|
|
void repaintPixmap(DecorationPixmap border, const QRect& r, QRegion reg);
|
2011-01-30 14:34:42 +00:00
|
|
|
QWidget* widget;
|
|
|
|
QRegion pending;
|
|
|
|
QRegion scheduled;
|
|
|
|
bool recursionCheck;
|
|
|
|
QBasicTimer cleanupTimer;
|
2012-09-28 09:59:42 +00:00
|
|
|
|
|
|
|
Client *m_client;
|
|
|
|
bool m_requiresRepaint;
|
2013-02-18 08:07:42 +00:00
|
|
|
};
|
|
|
|
|
2013-02-25 09:18:02 +00:00
|
|
|
class ImageBasedPaintRedirector : public PaintRedirector
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
virtual ~ImageBasedPaintRedirector();
|
|
|
|
protected:
|
|
|
|
ImageBasedPaintRedirector(Client *c, QWidget *widget);
|
|
|
|
virtual QPaintDevice *recreateScratch(const QSize &size);
|
|
|
|
virtual QPaintDevice *scratch();
|
|
|
|
virtual void fillScratch(Qt::GlobalColor color);
|
|
|
|
virtual void discardScratch();
|
|
|
|
const QImage &scratchImage() const;
|
|
|
|
private:
|
|
|
|
QImage m_scratchImage;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpenGLPaintRedirector : public ImageBasedPaintRedirector
|
2013-02-18 08:07:42 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
OpenGLPaintRedirector(Client *c, QWidget *widget);
|
|
|
|
virtual ~OpenGLPaintRedirector();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void resize(DecorationPixmap border, const QSize &size);
|
2013-02-25 09:18:02 +00:00
|
|
|
virtual void paint(DecorationPixmap border, const QRect &r, const QRect &b, const QRegion ®);
|
2013-02-22 09:13:46 +00:00
|
|
|
virtual GLTexture *texture(DecorationPixmap border) const;
|
|
|
|
virtual void preparePaint(const QPixmap &pending);
|
2013-02-18 08:07:42 +00:00
|
|
|
|
|
|
|
private:
|
2013-02-22 09:13:46 +00:00
|
|
|
QImage m_tempImage;
|
|
|
|
GLTexture* m_textures[PixmapCount];
|
2013-02-18 08:07:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class NativeXRenderPaintRedirector : public PaintRedirector
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
NativeXRenderPaintRedirector(Client *c, QWidget *widget);
|
|
|
|
virtual ~NativeXRenderPaintRedirector();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual xcb_render_picture_t picture(DecorationPixmap border) const;
|
|
|
|
virtual void resize(DecorationPixmap border, const QSize &size);
|
2013-02-25 09:18:02 +00:00
|
|
|
virtual void paint(DecorationPixmap border, const QRect &r, const QRect &b, const QRegion ®);
|
|
|
|
virtual void fillScratch(Qt::GlobalColor color);
|
|
|
|
virtual QPaintDevice *recreateScratch(const QSize &size);
|
|
|
|
virtual QPaintDevice *scratch();
|
|
|
|
virtual void discardScratch();
|
2013-02-18 08:07:42 +00:00
|
|
|
private:
|
2012-09-28 09:59:42 +00:00
|
|
|
QPixmap m_pixmaps[PixmapCount];
|
2013-02-25 09:18:02 +00:00
|
|
|
QPixmap m_scratch;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2009-04-22 17:29:56 +00:00
|
|
|
|
2013-02-25 09:18:02 +00:00
|
|
|
class RasterXRenderPaintRedirector : public ImageBasedPaintRedirector
|
2013-02-18 08:07:42 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
RasterXRenderPaintRedirector(Client *c, QWidget *widget);
|
|
|
|
virtual ~RasterXRenderPaintRedirector();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual xcb_render_picture_t picture(DecorationPixmap border) const;
|
|
|
|
virtual void resize(DecorationPixmap border, const QSize &size);
|
2013-02-25 09:18:02 +00:00
|
|
|
virtual void paint(DecorationPixmap border, const QRect &r, const QRect &b, const QRegion ®);
|
2013-02-18 08:07:42 +00:00
|
|
|
virtual void preparePaint(const QPixmap &pending);
|
|
|
|
private:
|
|
|
|
QSize m_sizes[PixmapCount];
|
|
|
|
xcb_pixmap_t m_pixmaps[PixmapCount];
|
|
|
|
xcb_gcontext_t m_gc;
|
|
|
|
XRenderPicture* m_pictures[PixmapCount];
|
|
|
|
QImage m_tempImage;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline
|
2013-02-22 09:13:46 +00:00
|
|
|
GLTexture *PaintRedirector::bottomDecoPixmap() const
|
2013-02-18 08:07:42 +00:00
|
|
|
{
|
2013-02-22 09:13:46 +00:00
|
|
|
return texture(BottomPixmap);
|
2013-02-18 08:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline
|
2013-02-22 09:13:46 +00:00
|
|
|
GLTexture *PaintRedirector::leftDecoPixmap() const
|
2013-02-18 08:07:42 +00:00
|
|
|
{
|
2013-02-22 09:13:46 +00:00
|
|
|
return texture(LeftPixmap);
|
2013-02-18 08:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline
|
2013-02-22 09:13:46 +00:00
|
|
|
GLTexture *PaintRedirector::rightDecoPixmap() const
|
2013-02-18 08:07:42 +00:00
|
|
|
{
|
2013-02-22 09:13:46 +00:00
|
|
|
return texture(RightPixmap);
|
2013-02-18 08:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline
|
2013-02-22 09:13:46 +00:00
|
|
|
GLTexture *PaintRedirector::topDecoPixmap() const
|
2013-02-18 08:07:42 +00:00
|
|
|
{
|
2013-02-22 09:13:46 +00:00
|
|
|
return texture(TopPixmap);
|
2013-02-18 08:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline
|
|
|
|
xcb_render_picture_t PaintRedirector::bottomDecoPixmap() const
|
|
|
|
{
|
|
|
|
return picture(BottomPixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline
|
|
|
|
xcb_render_picture_t PaintRedirector::leftDecoPixmap() const
|
|
|
|
{
|
|
|
|
return picture(LeftPixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline
|
|
|
|
xcb_render_picture_t PaintRedirector::rightDecoPixmap() const
|
|
|
|
{
|
|
|
|
return picture(RightPixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline
|
|
|
|
xcb_render_picture_t PaintRedirector::topDecoPixmap() const
|
|
|
|
{
|
|
|
|
return picture(TopPixmap);
|
|
|
|
}
|
|
|
|
|
2013-02-25 09:18:02 +00:00
|
|
|
inline
|
|
|
|
const QImage &ImageBasedPaintRedirector::scratchImage() const
|
|
|
|
{
|
|
|
|
return m_scratchImage;
|
|
|
|
}
|
|
|
|
|
2009-04-22 17:29:56 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|