2008-05-07 18:43:13 +04:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2008 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_XRENDERUTILS_H
|
|
|
|
#define KWIN_XRENDERUTILS_H
|
|
|
|
|
2013-02-26 11:02:27 +04:00
|
|
|
// KWin
|
2008-05-07 18:43:13 +04:00
|
|
|
#include <kwinglobals.h>
|
2013-12-01 23:45:39 +04:00
|
|
|
#include <kwineffects_export.h>
|
2013-02-26 11:02:27 +04:00
|
|
|
// KDE
|
|
|
|
#include <KDE/KSharedPtr>
|
|
|
|
// Qt
|
|
|
|
#include <QRegion>
|
|
|
|
#include <QVector>
|
|
|
|
// XCB
|
2013-02-06 10:58:33 +04:00
|
|
|
#include <xcb/xfixes.h>
|
2008-05-07 18:43:13 +04:00
|
|
|
|
2013-02-12 13:57:27 +04:00
|
|
|
class QColor;
|
2013-02-26 11:02:27 +04:00
|
|
|
class QPixmap;
|
2013-02-12 13:57:27 +04:00
|
|
|
|
2008-05-07 18:43:13 +04:00
|
|
|
/** @addtogroup kwineffects */
|
|
|
|
/** @{ */
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
2008-06-06 13:11:52 +04:00
|
|
|
/**
|
2013-02-12 13:57:27 +04:00
|
|
|
* dumps a QColor into a xcb_render_color_t
|
2008-06-06 13:11:52 +04:00
|
|
|
*/
|
2013-12-01 23:45:39 +04:00
|
|
|
KWINEFFECTS_EXPORT xcb_render_color_t preMultiply(const QColor &c, float opacity = 1.0);
|
2008-05-07 18:43:13 +04:00
|
|
|
|
|
|
|
/** @internal */
|
2013-12-01 23:45:39 +04:00
|
|
|
class KWINEFFECTS_EXPORT XRenderPictureData
|
2008-05-07 18:43:13 +04:00
|
|
|
: public QSharedData
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
public:
|
2013-02-12 12:16:42 +04:00
|
|
|
explicit XRenderPictureData(xcb_render_picture_t pic = XCB_RENDER_PICTURE_NONE);
|
2011-01-30 17:34:42 +03:00
|
|
|
~XRenderPictureData();
|
2013-02-12 12:16:42 +04:00
|
|
|
xcb_render_picture_t value();
|
2011-01-30 17:34:42 +03:00
|
|
|
private:
|
2013-02-12 12:16:42 +04:00
|
|
|
xcb_render_picture_t picture;
|
2011-01-30 17:34:42 +03:00
|
|
|
Q_DISABLE_COPY(XRenderPictureData)
|
|
|
|
};
|
2008-05-07 18:43:13 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @short Wrapper around XRender Picture.
|
|
|
|
*
|
2008-05-08 14:08:10 +04:00
|
|
|
* This class wraps XRender's Picture, providing proper initialization,
|
|
|
|
* convenience constructors and freeing of resources.
|
|
|
|
* It should otherwise act exactly like the Picture type.
|
2008-05-07 18:43:13 +04:00
|
|
|
*/
|
2013-12-01 23:45:39 +04:00
|
|
|
class KWINEFFECTS_EXPORT XRenderPicture
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
public:
|
2013-02-12 12:16:42 +04:00
|
|
|
explicit XRenderPicture(xcb_render_picture_t pic = XCB_RENDER_PICTURE_NONE);
|
2013-08-04 16:50:25 +04:00
|
|
|
explicit XRenderPicture(const QImage &img);
|
2013-02-12 12:16:42 +04:00
|
|
|
XRenderPicture(xcb_pixmap_t pix, int depth);
|
|
|
|
operator xcb_render_picture_t();
|
2011-01-30 17:34:42 +03:00
|
|
|
private:
|
2013-08-25 18:17:20 +04:00
|
|
|
void fromImage(const QImage &img);
|
2011-01-30 17:34:42 +03:00
|
|
|
KSharedPtr< XRenderPictureData > d;
|
|
|
|
};
|
2008-05-07 18:43:13 +04:00
|
|
|
|
2013-12-01 23:45:39 +04:00
|
|
|
class KWINEFFECTS_EXPORT XFixesRegion
|
2013-02-06 10:58:33 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit XFixesRegion(const QRegion ®ion);
|
|
|
|
virtual ~XFixesRegion();
|
|
|
|
|
|
|
|
operator xcb_xfixes_region_t();
|
|
|
|
private:
|
|
|
|
xcb_xfixes_region_t m_region;
|
|
|
|
};
|
|
|
|
|
2008-05-07 18:43:13 +04:00
|
|
|
inline
|
2013-02-12 12:16:42 +04:00
|
|
|
XRenderPictureData::XRenderPictureData(xcb_render_picture_t pic)
|
2011-01-30 17:34:42 +03:00
|
|
|
: picture(pic)
|
|
|
|
{
|
|
|
|
}
|
2008-05-07 18:43:13 +04:00
|
|
|
|
|
|
|
inline
|
|
|
|
XRenderPictureData::~XRenderPictureData()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-02-12 12:16:42 +04:00
|
|
|
if (picture != XCB_RENDER_PICTURE_NONE)
|
|
|
|
xcb_render_free_picture(connection(), picture);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-05-07 18:43:13 +04:00
|
|
|
|
|
|
|
inline
|
2013-02-12 12:16:42 +04:00
|
|
|
xcb_render_picture_t XRenderPictureData::value()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2008-05-07 18:43:13 +04:00
|
|
|
return picture;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-05-07 18:43:13 +04:00
|
|
|
|
|
|
|
inline
|
2013-02-12 12:16:42 +04:00
|
|
|
XRenderPicture::XRenderPicture(xcb_render_picture_t pic)
|
2011-01-30 17:34:42 +03:00
|
|
|
: d(new XRenderPictureData(pic))
|
|
|
|
{
|
|
|
|
}
|
2008-05-07 18:43:13 +04:00
|
|
|
|
|
|
|
inline
|
2013-02-12 12:16:42 +04:00
|
|
|
XRenderPicture::operator xcb_render_picture_t()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2008-05-07 18:43:13 +04:00
|
|
|
return d->value();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2008-05-07 18:43:13 +04:00
|
|
|
|
2013-02-06 10:58:33 +04:00
|
|
|
inline
|
|
|
|
XFixesRegion::XFixesRegion(const QRegion ®ion)
|
|
|
|
{
|
|
|
|
m_region = xcb_generate_id(connection());
|
|
|
|
QVector< QRect > rects = region.rects();
|
|
|
|
QVector< xcb_rectangle_t > xrects(rects.count());
|
|
|
|
for (int i = 0;
|
|
|
|
i < rects.count();
|
|
|
|
++i) {
|
|
|
|
const QRect &rect = rects.at(i);
|
|
|
|
xcb_rectangle_t xrect;
|
|
|
|
xrect.x = rect.x();
|
|
|
|
xrect.y = rect.y();
|
|
|
|
xrect.width = rect.width();
|
|
|
|
xrect.height = rect.height();
|
|
|
|
xrects[i] = xrect;
|
|
|
|
}
|
|
|
|
xcb_xfixes_create_region(connection(), m_region, xrects.count(), xrects.constData());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
XFixesRegion::~XFixesRegion()
|
|
|
|
{
|
|
|
|
xcb_xfixes_destroy_region(connection(), m_region);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
XFixesRegion::operator xcb_xfixes_region_t()
|
|
|
|
{
|
|
|
|
return m_region;
|
|
|
|
}
|
|
|
|
|
2009-05-12 18:12:46 +04:00
|
|
|
/**
|
|
|
|
* Static 1x1 picture used to deliver a black pixel with given opacity (for blending performance)
|
|
|
|
* Call and Use, the PixelPicture will stay, but may change it's opacity meanwhile. It's NOT threadsafe either
|
|
|
|
*/
|
2013-12-01 23:45:39 +04:00
|
|
|
KWINEFFECTS_EXPORT XRenderPicture xRenderBlendPicture(double opacity);
|
2008-06-06 13:11:52 +04:00
|
|
|
/**
|
|
|
|
* Creates a 1x1 Picture filled with c
|
|
|
|
*/
|
2013-12-01 23:45:39 +04:00
|
|
|
KWINEFFECTS_EXPORT XRenderPicture xRenderFill(const xcb_render_color_t &c);
|
|
|
|
KWINEFFECTS_EXPORT XRenderPicture xRenderFill(const QColor &c);
|
2008-06-06 13:11:52 +04:00
|
|
|
|
2012-03-04 12:52:32 +04:00
|
|
|
/**
|
|
|
|
* Allows to render a window into a (transparent) pixmap
|
|
|
|
* NOTICE: the result can be queried as xRenderWindowOffscreenTarget()
|
|
|
|
* NOTICE: it may be 0
|
|
|
|
* NOTICE: when done call setXRenderWindowOffscreen(false) to continue normal render process
|
|
|
|
*/
|
2013-12-01 23:45:39 +04:00
|
|
|
KWINEFFECTS_EXPORT void setXRenderOffscreen(bool b);
|
2012-03-04 12:52:32 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows to define a persistent effect member as render target
|
|
|
|
* The window (including shadows) is rendered into the top left corner
|
|
|
|
* NOTICE: do NOT call setXRenderOffscreen(true) in addition!
|
|
|
|
* NOTICE: do not forget to xRenderPopTarget once you're done to continue the normal render process
|
|
|
|
*/
|
2013-12-01 23:45:39 +04:00
|
|
|
KWINEFFECTS_EXPORT void xRenderPushTarget(XRenderPicture *pic);
|
|
|
|
KWINEFFECTS_EXPORT void xRenderPopTarget();
|
2012-03-04 12:52:32 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether windows are currently rendered into an offscreen target buffer
|
|
|
|
*/
|
2013-12-01 23:45:39 +04:00
|
|
|
KWINEFFECTS_EXPORT bool xRenderOffscreen();
|
2012-03-04 12:52:32 +04:00
|
|
|
/**
|
|
|
|
* The offscreen buffer as set by the renderer because of setXRenderWindowOffscreen(true)
|
|
|
|
*/
|
2013-12-01 23:45:39 +04:00
|
|
|
KWINEFFECTS_EXPORT xcb_render_picture_t xRenderOffscreenTarget();
|
2012-03-04 12:52:32 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* NOTICE: HANDS OFF!!!
|
|
|
|
* scene_setXRenderWindowOffscreenTarget() is ONLY to be used by the renderer - DO NOT TOUCH!
|
|
|
|
*/
|
2013-12-01 23:45:39 +04:00
|
|
|
KWINEFFECTS_EXPORT void scene_setXRenderOffscreenTarget(xcb_render_picture_t pix);
|
2012-03-04 12:52:32 +04:00
|
|
|
/**
|
|
|
|
* scene_xRenderWindowOffscreenTarget() is used by the scene to figure the target set by an effect
|
|
|
|
*/
|
2013-12-01 23:45:39 +04:00
|
|
|
KWINEFFECTS_EXPORT XRenderPicture *scene_xRenderOffscreenTarget();
|
2012-03-04 12:52:32 +04:00
|
|
|
|
2008-05-07 18:43:13 +04:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
#endif
|