Some missing XRender counterparts for utility functions, from Thomas Lübking.

svn path=/trunk/KDE/kdebase/workspace/; revision=817548
icc-effect-5.14.5
Luboš Luňák 2008-06-06 09:11:52 +00:00
parent 82cf0edda7
commit 0ce86291c5
3 changed files with 114 additions and 1 deletions

View File

@ -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;
}

View File

@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <qvector.h>
#include <qpixmap.h>
#include <qpainter.h>
#include <kdebug.h>
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 ];

View File

@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
#include <QtCore/QSharedData>
#include <QtGui/QColor>
#include <ksharedptr.h>
#include <kwinglobals.h>
@ -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