Port preMultiply of color to xcb_render

Method returns a xcb_render_color_t instead of an XRenderColor.

With this change kwinxrenderutils is XLib free!
This commit is contained in:
Martin Gräßlin 2013-02-12 10:57:27 +01:00
parent 881664b42e
commit f45ade7785
7 changed files with 46 additions and 38 deletions

View file

@ -225,10 +225,8 @@ void MagnifierEffect::paintScreen(int mask, QRegion region, ScreenPaintData& dat
{ int16_t(area.x()), int16_t(area.bottom()-FRAME_WIDTH), uint16_t(area.width()-FRAME_WIDTH), uint16_t(FRAME_WIDTH)},
{ int16_t(area.x()), int16_t(area.y()), uint16_t(FRAME_WIDTH), uint16_t(area.height()-FRAME_WIDTH)}
};
// TODO: remove XRenderColor
const XRenderColor xc = preMultiply(QColor(0,0,0,255));
const xcb_render_color_t c = {xc.red, xc.green, xc.blue, xc.alpha};
xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, effects->xrenderBufferPicture(), c, 4, rects);
xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, effects->xrenderBufferPicture(),
preMultiply(QColor(0,0,0,255)), 4, rects);
#endif
}
}

View file

@ -148,8 +148,7 @@ void MouseMarkEffect::paintScreen(int mask, QRegion region, ScreenPaintData& dat
}
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
if ( effects->compositingType() == XRenderCompositing) {
XRenderColor xc = preMultiply(color);
xcb_render_color_t c = {xc.red, xc.green, xc.blue, xc.alpha};
xcb_render_color_t c = preMultiply(color);
for (int i = 0; i < marks.count(); ++i) {
const int n = marks[i].count() - 1;
if (n > 0) {

View file

@ -155,9 +155,8 @@ void SnapHelperEffect::postPaintScreen()
rects[5].width = 4;
rects[5].height = 2*halfHeight - 4;
XRenderColor xc = preMultiply(QColor(128, 128, 128, m_timeline.currentValue()*128));
xcb_render_color_t c = {xc.red, xc.green, xc.blue, xc.alpha};
xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_OVER, effects->xrenderBufferPicture(), c, 6, rects);
xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_OVER, effects->xrenderBufferPicture(),
preMultiply(QColor(128, 128, 128, m_timeline.currentValue()*128)), 6, rects);
}
#endif
}

View file

@ -12,10 +12,8 @@ set(kwin_EFFECTSLIB_SRCS
kde4_add_library(kwineffects SHARED ${kwin_EFFECTSLIB_SRCS})
target_link_libraries(kwineffects ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY}
${X11_LIBRARIES}
${X11_Xrender_LIB}
${X11_Xrandr_LIB}
${X11_Xdamage_LIB}
${X11_Xfixes_LIB}
${XCB_XCB_LIBRARIES}
${X11_XCB_LIBRARIES}
${XCB_XFIXES_LIBRARIES}

View file

@ -29,9 +29,9 @@ namespace KWin
{
// adapted from Qt, because this really sucks ;)
XRenderColor preMultiply(const QColor &c, float opacity)
xcb_render_color_t preMultiply(const QColor &c, float opacity)
{
XRenderColor color;
xcb_render_color_t color;
const uint A = c.alpha() * opacity,
R = c.red(),
G = c.green(),
@ -43,33 +43,38 @@ XRenderColor preMultiply(const QColor &c, float opacity)
return color;
}
XRenderPicture xRenderFill(const XRenderColor *xc)
XRenderPicture xRenderFill(const xcb_render_color_t &c)
{
Pixmap pixmap = XCreatePixmap(display(), rootWindow(), 1, 1, 32);
XRenderPictureAttributes pa; pa.repeat = True;
xcb_pixmap_t pixmap = xcb_generate_id(connection());
xcb_create_pixmap(connection(), 32, pixmap, rootWindow(), 1, 1);
XRenderPicture fill(pixmap, 32);
XFreePixmap(display(), pixmap);
XRenderChangePicture(display(), fill, CPRepeat, &pa);
XRenderFillRectangle(display(), PictOpSrc, fill, xc, 0, 0, 1, 1);
xcb_free_pixmap(connection(), pixmap);
uint32_t values[] = {true};
xcb_render_change_picture(connection(), fill, XCB_RENDER_CP_REPEAT, values);
xcb_rectangle_t rect = {0, 0, 1, 1};
xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, fill, c, 1, &rect);
return fill;
}
XRenderPicture xRenderFill(const QColor &c)
{
XRenderColor xc = preMultiply(c);
return xRenderFill(&xc);
return xRenderFill(preMultiply(c));
}
static XRenderPicture _blendPicture(X::None);
static XRenderColor _blendColor;
XRenderPicture xRenderBlendPicture(double opacity)
{
_blendColor.alpha = ushort(opacity * 0xffff);
if (_blendPicture == X::None)
_blendPicture = xRenderFill(&_blendColor);
else
XRenderFillRectangle(display(), PictOpSrc, _blendPicture, &_blendColor, 0, 0, 1, 1);
return _blendPicture;
static XRenderPicture s_blendPicture(XCB_RENDER_PICTURE_NONE);
static xcb_render_color_t s_blendColor = {0, 0, 0, 0};
s_blendColor.alpha = uint16_t(opacity * 0xffff);
if (s_blendPicture == XCB_RENDER_PICTURE_NONE) {
s_blendPicture = xRenderFill(s_blendColor);
} else {
xcb_rectangle_t rect = {0, 0, 1, 1};
xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, s_blendPicture, s_blendColor, 1, &rect);
}
return s_blendPicture;
}
static xcb_render_picture_t createPicture(xcb_pixmap_t pix, int depth)

View file

@ -24,25 +24,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kwinconfig.h>
#include <QtCore/QSharedData>
#include <QtGui/QColor>
#include <QVector>
#include <ksharedptr.h>
#include <kwinglobals.h>
#include <X11/extensions/Xfixes.h>
// TODO: remove, currently only included to not break builds of effects
#include <X11/extensions/Xrender.h>
#include <xcb/xfixes.h>
class QColor;
/** @addtogroup kwineffects */
/** @{ */
namespace KWin
{
/**
* dumps a QColor into a XRenderColor
* dumps a QColor into a xcb_render_color_t
*/
KWIN_EXPORT XRenderColor preMultiply(const QColor &c, float opacity = 1.0);
KWIN_EXPORT xcb_render_color_t preMultiply(const QColor &c, float opacity = 1.0);
/** @internal */
class KWIN_EXPORT XRenderPictureData
@ -158,7 +159,7 @@ KWIN_EXPORT XRenderPicture xRenderBlendPicture(double opacity);
/**
* Creates a 1x1 Picture filled with c
*/
KWIN_EXPORT XRenderPicture xRenderFill(const XRenderColor *c);
KWIN_EXPORT XRenderPicture xRenderFill(const xcb_render_color_t &c);
KWIN_EXPORT XRenderPicture xRenderFill(const QColor &c);
/**

View file

@ -697,13 +697,21 @@ XRenderComposite(display(), PictOpOver, _PART_->x11PictureHandle(), decorationAl
if (data.brightness() != 1.0) {
// fake brightness change by overlaying black
const float alpha = (1 - data.brightness()) * data.opacity();
XRenderColor col = preMultiply(data.brightness() < 1.0 ? QColor(0,0,0,255*alpha) : QColor(255,255,255,-alpha*255));
xcb_rectangle_t rect;
if (blitInTempPixmap) {
XRenderFillRectangle(display(), PictOpOver, renderTarget, &col,
-temp_visibleRect.left(), -temp_visibleRect.top(), width(), height());
rect.x = -temp_visibleRect.left();
rect.y = -temp_visibleRect.top();
rect.width = width();
rect.height = height();
} else {
XRenderFillRectangle(display(), PictOpOver, renderTarget, &col, wr.x(), wr.y(), wr.width(), wr.height());
rect.x = wr.x();
rect.y = wr.y();
rect.width = wr.width();
rect.height = wr.height();
}
xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_OVER, renderTarget,
preMultiply(data.brightness() < 1.0 ? QColor(0,0,0,255*alpha) : QColor(255,255,255,-alpha*255)),
1, &rect);
}
if (blitInTempPixmap) {
const QRect r = mapToScreen(mask, data, temp_visibleRect);