From 0ce86291c596cc0ed220b4cf11a071299925a0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Fri, 6 Jun 2008 09:11:52 +0000 Subject: [PATCH] =?UTF-8?q?Some=20missing=20XRender=20counterparts=20for?= =?UTF-8?q?=20utility=20functions,=20from=20Thomas=20L=C3=BCbking.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit svn path=/trunk/KDE/kdebase/workspace/; revision=817548 --- lib/kwineffects.cpp | 8 +++- lib/kwinxrenderutils.cpp | 92 ++++++++++++++++++++++++++++++++++++++++ lib/kwinxrenderutils.h | 15 +++++++ 3 files changed, 114 insertions(+), 1 deletion(-) diff --git a/lib/kwineffects.cpp b/lib/kwineffects.cpp index 15d1bcf0de..3b7ae0af3f 100644 --- a/lib/kwineffects.cpp +++ b/lib/kwineffects.cpp @@ -405,7 +405,13 @@ bool EffectsHandler::paintTextWithBackground( const QString& text, const QPoint& return paintText( text, center, maxwidth, color, font ); } #endif - // TODO: render at least a simple background rect in XRender mode +#ifdef KWIN_HAVE_XRENDER_COMPOSITING + if( effects->compositingType() == XRenderCompositing ) + { + xRenderRoundBox( effects->xrenderBufferPicture(), area.adjusted( -8, -3, 8, 3 ), 5, bgcolor ); + return paintText( text, center, maxwidth, color, font ); + } +#endif return false; } diff --git a/lib/kwinxrenderutils.cpp b/lib/kwinxrenderutils.cpp index 817a30d1ea..efb7037a8f 100644 --- a/lib/kwinxrenderutils.cpp +++ b/lib/kwinxrenderutils.cpp @@ -24,6 +24,7 @@ along with this program. If not, see . #include #include +#include #include namespace KWin @@ -50,6 +51,97 @@ XserverRegion toXserverRegion( QRegion region ) return ret; } +// adapted from Qt, because this really sucks ;) +XRenderColor preMultiply(const QColor &c, float opacity) +{ + XRenderColor color; + const uint A = c.alpha() * opacity, + R = c.red(), + G = c.green(), + B = c.blue(); + color.alpha = (A | A << 8); + color.red = (R | R << 8) * color.alpha / 0x10000; + color.green = (G | G << 8) * color.alpha / 0x10000; + color.blue = (B | B << 8) * color.alpha / 0x10000; + return color; +} + +XRenderPicture xRenderFill( const XRenderColor *xc ) + { + Pixmap pixmap = XCreatePixmap( display(), rootWindow(), 1, 1, 32 ); + XRenderPictureAttributes pa; pa.repeat = True; + XRenderPicture fill( pixmap, 32 ); + XFreePixmap( display(), pixmap ); + XRenderChangePicture (display(), fill, CPRepeat, &pa); + XRenderFillRectangle( display(), PictOpSrc, fill, xc, 0, 0, 1, 1 ); + return fill; + } + +XRenderPicture xRenderFill( const QColor &c ) + { + XRenderColor xc = preMultiply(c); + return xRenderFill( &xc ); + } + + +static XRenderPicture *_circle[4] = {NULL, NULL, NULL, NULL}; + +#define DUMP_CNR(_SECT_, _W_, _H_, _XOFF_, _YOFF_)\ + dump = QPixmap(_W_, _H_);\ + dump.fill(Qt::transparent);\ + p.begin(&dump);\ + p.drawPixmap( 0, 0, tmp, _XOFF_, _YOFF_, _W_, _H_ );\ + p.end();\ + _circle[_SECT_] = new XRenderPicture(dump); + +#define CS 8 + +static XRenderPicture *circle(int i) + { + if (!_circle[0]) + { + QPixmap tmp(2*CS, 2*CS); + tmp.fill(Qt::transparent); + QPainter p(&tmp); + p.setRenderHint(QPainter::Antialiasing); + p.setPen(Qt::NoPen); p.setBrush(Qt::black); + p.drawEllipse(tmp.rect()); + p.end(); + QPixmap dump; + DUMP_CNR(0, CS, CS, 0, 0); + DUMP_CNR(1, CS, CS, CS, 0); + DUMP_CNR(2, CS, CS, CS, CS); + DUMP_CNR(3, CS, CS, 0, CS); + } + return _circle[i]; + } + +void xRenderRoundBox( Picture pict, const QRect &rect, int , const QColor &c ) + { + XRenderPicture fill = xRenderFill(c); + int op = c.alpha() == 255 ? PictOpSrc : PictOpOver; + // TODO: implement second paramenter "roundness" + // so rather use ?? XRenderCompositeTriFan (dpy, op, src, dst, maskFormat, xSrc, ySrc, + //XPointFixed *points, npoint); + // this will require "points on a circle" calculation, however... + + int s = qMin(CS, qMin(rect.height()/2, rect.width()/2)); + int x,y,b,r; + rect.getCoords(&x,&y,&r,&b); + r -= (s - 1); + b -= (s - 1); + XRenderComposite( display(), PictOpOver, fill, *circle(0), pict, 0, 0, 0, 0, x, y, CS, CS ); + XRenderComposite( display(), PictOpOver, fill, *circle(1), pict, 0, 0, CS-s, 0, r, y, s, s ); + XRenderComposite( display(), PictOpOver, fill, *circle(2), pict, 0, 0, CS-s, CS-s, r, b, s, s ); + XRenderComposite( display(), PictOpOver, fill, *circle(3), pict, 0, 0, 0, CS-s, x, b, s, s ); + XRenderComposite( display(), op, fill, 0, pict, 0, 0, 0, 0, x+s, y, rect.width()-2*s, s); + XRenderComposite( display(), op, fill, 0, pict, 0, 0, 0, 0, x, y+s, rect.width(), rect.height()-2*s); + XRenderComposite( display(), op, fill, 0, pict, 0, 0, 0, 0, x+s, b, rect.width()-2*s, s); + } + +#undef CS +#undef DUMP_CNR + // XRenderFind(Standard)Format() is a roundtrip, so cache the results static XRenderPictFormat* renderformats[ 33 ]; diff --git a/lib/kwinxrenderutils.h b/lib/kwinxrenderutils.h index 336b7c3e72..5caafa78d4 100644 --- a/lib/kwinxrenderutils.h +++ b/lib/kwinxrenderutils.h @@ -26,6 +26,7 @@ along with this program. If not, see . #ifdef KWIN_HAVE_XRENDER_COMPOSITING #include +#include #include #include @@ -43,6 +44,14 @@ namespace KWin * Convert QRegion to XserverRegion. */ KWIN_EXPORT XserverRegion toXserverRegion( QRegion region ); +/** + * draws a round box on the renderscene + */ +KWIN_EXPORT void xRenderRoundBox( Picture pict, const QRect &rect, int round, const QColor &c ); +/** + * dumps a QColor into a XRenderColor + */ +KWIN_EXPORT XRenderColor preMultiply(const QColor &c, float opacity = 1.0); /** @internal */ class KWIN_EXPORT XRenderPictureData @@ -106,6 +115,12 @@ XRenderPicture::operator Picture() return d->value(); } +/** + * Creates a 1x1 Picture filled with c + */ +KWIN_EXPORT XRenderPicture xRenderFill( const XRenderColor *c ); +KWIN_EXPORT XRenderPicture xRenderFill( const QColor &c ); + } // namespace #endif