now do all painting through cached pixmaps and only paint things that are

in the PaintEvent region. makes it a bit easier to modify the look and saves
another ~15% for 100000 repaint resp. 10000 caption changes... :)

svn path=/trunk/kdebase/kwin/; revision=399339
icc-effect-5.14.5
Sandro Giessl 2005-03-20 21:07:11 +00:00
parent a80216662a
commit cd66337cff
3 changed files with 235 additions and 192 deletions

View File

@ -204,15 +204,13 @@ QColor PlastikHandler::getColor(KWinPlastik::ColorType type, const bool active)
case TitleGradient3:
return KDecoration::options()->color(ColorTitleBar, active);
break;
case TitleHighlightTop:
case SideHighlightLeft:
case ShadeTitleLight:
return alphaBlendColors(KDecoration::options()->color(ColorTitleBar, active),
Qt::white, active?150:160);
Qt::white, active?150:160);
break;
case SideHighlightRight:
case SideHighlightBottom:
case ShadeTitleDark:
return alphaBlendColors(KDecoration::options()->color(ColorTitleBar, active),
Qt::black, active?150:160);
Qt::black, active?150:160);
break;
case Border:
return KDecoration::options()->color(ColorFrame, active);
@ -228,55 +226,215 @@ const QPixmap &PlastikHandler::pixmap(Pixmaps type, bool active, bool toolWindow
if (m_pixmaps[toolWindow][active][type])
return *m_pixmaps[toolWindow][active][type];
QPixmap *pm = 0;
switch (type) {
case TitleBarTileTop:
case TitleBarTile:
{
const int topHeight = 2;
const int topGradientHeight = 4;
int h = (toolWindow ? m_titleHeightTool : m_titleHeight) + topHeight;
QPixmap gradient(1, h); // TODO: test width of 5 or so for performance
const int titleBarTileHeight = (toolWindow ? m_titleHeightTool : m_titleHeight) + 2;
// gradient used as well in TitleBarTileTop as TitleBarTile
const int gradientHeight = 2 + titleBarTileHeight-1;
QPixmap gradient(1, gradientHeight);
QPainter painter(&gradient);
KPixmap tempPixmap;
tempPixmap.resize(1, topGradientHeight);
tempPixmap.resize(1, 4);
KPixmapEffect::gradient(tempPixmap,
getColor(TitleGradient1, active),
getColor(TitleGradient2, active),
KPixmapEffect::VerticalGradient);
painter.drawPixmap(0,0, tempPixmap);
tempPixmap.resize(1, h-topGradientHeight);
tempPixmap.resize(1, gradientHeight-4);
KPixmapEffect::gradient(tempPixmap,
getColor(TitleGradient2, active),
getColor(TitleGradient3, active),
KPixmapEffect::VerticalGradient);
painter.drawPixmap(0,topGradientHeight, tempPixmap);
painter.drawPixmap(0,4, tempPixmap);
painter.end();
QPixmap *pixmap;
// actual titlebar tiles
if (type == TitleBarTileTop) {
pixmap = new QPixmap(1, topHeight);
painter.begin(pixmap);
painter.drawPixmap(0, 0, gradient);
pm = new QPixmap(1, 4);
painter.begin(pm);
// contour
painter.setPen(getColor(WindowContour, active) );
painter.drawPoint(0,0);
// top highlight
painter.setPen(getColor(ShadeTitleLight, active) );
painter.drawPoint(0,1);
// gradient
painter.drawPixmap(0, 2, gradient);
painter.end();
} else {
pixmap = new QPixmap(1, h-topHeight);
painter.begin(pixmap);
painter.drawPixmap(0, 0, gradient, 0,topHeight);
pm = new QPixmap(1, titleBarTileHeight);
painter.begin(pm);
painter.drawPixmap(0, 0, gradient, 0,2);
painter.setPen(getColor(TitleGradient3, active) );
painter.drawPoint(0,titleBarTileHeight-1);
painter.end();
}
m_pixmaps[toolWindow][active][type] = pixmap;
return *pixmap;
break;
}
case TitleBarLeft:
{
const int w = m_borderSize;
const int h = 4 + (toolWindow ? m_titleHeightTool : m_titleHeight) + 2;
pm = new QPixmap(w, h);
QPainter painter(pm);
painter.drawTiledPixmap(0,0, w, 4, pixmap(TitleBarTileTop, active, toolWindow) );
painter.drawTiledPixmap(0,4, w, h-4, pixmap(TitleBarTile, active, toolWindow) );
painter.setPen(getColor(WindowContour, active) );
painter.drawLine(0,0, 0,h);
painter.drawPoint(1,1);
const QColor highlightTitleLeft = alphaBlendColors(getColor(TitleGradient3, active),
getColor(ShadeTitleLight, active), 150);
painter.setPen(highlightTitleLeft);
painter.drawLine(1,2, 1,h);
// outside the region normally masked by doShape
painter.setPen(QColor(0,0,0) );
painter.drawLine(0, 0, 1, 0 );
painter.drawPoint(0, 1);
break;
}
case TitleBarRight:
{
const int w = m_borderSize;
const int h = 4 + (toolWindow ? m_titleHeightTool : m_titleHeight) + 2;
pm = new QPixmap(w, h);
QPainter painter(pm);
painter.drawTiledPixmap(0,0, w, 4, pixmap(TitleBarTileTop, active, toolWindow) );
painter.drawTiledPixmap(0,4, w, h-4, pixmap(TitleBarTile, active, toolWindow) );
painter.setPen(getColor(WindowContour, active) );
painter.drawLine(w-1,0, w-1,h);
painter.drawPoint(w-2,1);
const QColor highlightTitleRight = alphaBlendColors(getColor(TitleGradient3, active),
getColor(ShadeTitleDark, active), 150);
painter.setPen(highlightTitleRight);
painter.drawLine(w-2,2, w-2,h);
// outside the region normally masked by doShape
painter.setPen(QColor(0,0,0) );
painter.drawLine(w-2, 0, w-1, 0 );
painter.drawPoint(w-1, 1);
break;
}
case BorderLeftTile:
{
const int w = m_borderSize;
pm = new QPixmap(w, 1);
QPainter painter(pm);
painter.setPen(getColor(WindowContour, active) );
painter.drawPoint(0, 0);
painter.setPen(
alphaBlendColors(getColor(Border, active),
getColor(ShadeTitleLight, active), 150) );
painter.drawPoint(1, 0);
painter.setPen(getColor(Border, active) );
painter.drawLine(2,0, w-1,0);
painter.end();
break;
}
case BorderRightTile:
{
const int w = m_borderSize;
pm = new QPixmap(w, 1);
QPainter painter(pm);
painter.setPen(getColor(Border, active) );
painter.drawLine(0,0, w-3,0);
painter.setPen(
alphaBlendColors(getColor(Border, active),
getColor(ShadeTitleDark, active), 150) );
painter.drawPoint(w-2, 0);
painter.setPen(getColor(WindowContour, active) );
painter.drawPoint(w-1, 0);
painter.end();
break;
}
case BorderBottomLeft:
{
const int w = m_borderSize;
const int h = m_borderSize;
pm = new QPixmap(w, h);
QPainter painter(pm);
painter.drawTiledPixmap(0,0,w,h, pixmap(BorderBottomTile, active, toolWindow) );
painter.setPen(getColor(WindowContour, active) );
painter.drawLine(0,0, 0,h);
painter.setPen(
alphaBlendColors(getColor(Border, active),
getColor(ShadeTitleLight, active), 150) );
painter.drawLine(1,0, 1,h-2);
painter.end();
break;
}
case BorderBottomRight:
{
const int w = m_borderSize;
const int h = m_borderSize;
pm = new QPixmap(w, h);
QPainter painter(pm);
painter.drawTiledPixmap(0,0,w,h, pixmap(BorderBottomTile, active, toolWindow) );
painter.setPen(getColor(WindowContour, active) );
painter.drawLine(w-1,0, w-1,h);
painter.setPen(
alphaBlendColors(getColor(Border, active),
getColor(ShadeTitleDark, active), 150) );
painter.drawLine(w-2,0, w-2,h-2);
painter.end();
break;
}
case BorderBottomTile:
default:
{
const int h = m_borderSize;
pm = new QPixmap(1, m_borderSize);
QPainter painter(pm);
painter.setPen(getColor(Border, active) );
painter.drawLine(0,0, 0,h-3);
painter.setPen(
alphaBlendColors(getColor(Border, active),
getColor(ShadeTitleDark, active), 150) );
painter.drawPoint(0, h-2);
painter.setPen(getColor(WindowContour, active) );
painter.drawPoint(0, h-1);
painter.end();
break;
}
}
m_pixmaps[toolWindow][active][type] = pm;
return *pm;
}
const QBitmap &PlastikHandler::buttonBitmap(ButtonIcon type, const QSize &size, bool toolWindow)

View File

@ -35,10 +35,8 @@ enum ColorType {
TitleGradient1, // top
TitleGradient2,
TitleGradient3, // bottom
TitleHighlightTop,
SideHighlightLeft,
SideHighlightRight,
SideHighlightBottom,
ShadeTitleLight,
ShadeTitleDark,
Border,
TitleFont
};
@ -46,6 +44,13 @@ enum ColorType {
enum Pixmaps {
TitleBarTileTop=0,
TitleBarTile,
TitleBarLeft,
TitleBarRight,
BorderLeftTile,
BorderRightTile,
BorderBottomTile,
BorderBottomLeft,
BorderBottomRight,
NumPixmaps
};
@ -97,7 +102,6 @@ private:
void readConfig();
bool m_titleShadow;
bool m_shrinkBorders;
bool m_animateButtons;
bool m_menuClose;
bool m_reverse;

View File

@ -110,11 +110,11 @@ int PlastikClient::layoutMetric(LayoutMetric lm, bool respectWindowState, const
case LM_TitleEdgeBottom:
{
if (respectWindowState && maximized) {
return 1;
} else {
// if (respectWindowState && maximized) {
// return 1;
// } else {
return 2;
}
// }
}
case LM_TitleEdgeLeft:
@ -247,27 +247,6 @@ void PlastikClient::paintEvent(QPaintEvent *e)
QPainter painter(widget() );
QRegion mask;
// colors...
const QColor windowContour = Handler()->getColor(WindowContour, active);
const QColor deco = Handler()->getColor(TitleGradient3, active);
const QColor border = Handler()->getColor(Border, active);
const QColor highlightTop = Handler()->getColor(TitleHighlightTop, active);
const QColor highlightTitleLeft = alphaBlendColors(deco,
Handler()->getColor(SideHighlightLeft, active), 150);
const QColor highlightTitleRight = alphaBlendColors(deco,
Handler()->getColor(SideHighlightRight, active), 150);
const QColor highlightLeft = alphaBlendColors(border,
Handler()->getColor(SideHighlightLeft, active), 150);
const QColor highlightRight = alphaBlendColors(border,
Handler()->getColor(SideHighlightRight, active), 150);
const QColor highlightBottom = alphaBlendColors(border,
Handler()->getColor(SideHighlightBottom, active), 150);
const QColor filledCorner = QColor(0,0,0);
// often needed coordinates
QRect r = widget()->rect();
@ -287,10 +266,6 @@ void PlastikClient::paintEvent(QPaintEvent *e)
const int borderBottomTop = r_y2-borderBottom+1;
const int borderLeftRight = r_x+borderLeft-1;
const int borderRightLeft = r_x2-borderRight+1;
const int titleEdgeLeftRight = r_x+titleEdgeLeft-1;
const int titleEdgeRightLeft = r_x2-titleEdgeRight+1;
const int titleEdgeTopBottom = r_y+titleEdgeTop;
const int titleEdgeBottomTop = r_y+titleEdgeTop+titleHeight+1;
const int titleEdgeBottomBottom = r_y+titleEdgeTop+titleHeight+titleEdgeBottom-1;
const int sideHeight = borderBottomTop-titleEdgeBottomBottom-1;
@ -301,50 +276,13 @@ void PlastikClient::paintEvent(QPaintEvent *e)
QRect tempRect;
// Draw the window contour
painter.setPen(windowContour );
if (titleEdgeTop > 0) {
painter.drawLine(r_x+2, r_y, r_x2-2, r_y );
painter.drawPoint(r_x+1, r_y+1 );
painter.drawPoint(r_x2-1, r_y+1 );
painter.drawLine(r_x, r_y+2, r_x, titleEdgeTopBottom );
painter.drawLine(r_x2, r_y+2, r_x2, titleEdgeTopBottom );
}
if(borderLeft > 0 && sideHeight > 0) {
painter.drawLine(r_x, Rtitle.top()/*titleEdgeBottomBottom+1*/,
r_x, r_y2-1 );
}
if(borderRight > 0 && sideHeight > 0) {
painter.drawLine(r_x2, Rtitle.top()/*titleEdgeBottomBottom+1*/,
r_x2, r_y2-1 );
}
if(borderBottom > 0) {
painter.drawLine(r_x+1, r_y2,
r_x2-1, r_y2 );
}
// topSpacer
if(titleEdgeTop > 0)
{
painter.setPen(highlightTop );
painter.drawLine(r_x+2, r_y+1, r_x2-2, r_y+1 );
// highlight...
painter.setPen(highlightTitleLeft);
painter.drawLine(r_x+1, r_y+2, r_x+1, titleEdgeTopBottom );
painter.setPen(highlightTitleRight);
painter.drawLine(r_x2-1, r_y+2, r_x2-1, titleEdgeTopBottom );
tempRect.setRect(r_x+2, r_y+2, r_w-2*2, titleEdgeTop-2 );
tempRect.setRect(r_x+2, r_y, r_w-2*2, titleEdgeTop );
if (tempRect.isValid() && region.contains(tempRect) ) {
painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarTileTop, active, toolWindow) );
}
// outside the region normally masked by doShape
painter.setPen(filledCorner);
painter.drawLine(r_x, r_y, r_x+1, r_y );
painter.drawPoint(r_x, r_y+1);
painter.drawLine(r_x2, r_y, r_x2-1, r_y );
painter.drawPoint(r_x2, r_y+1);
}
// leftTitleSpacer
@ -352,26 +290,25 @@ void PlastikClient::paintEvent(QPaintEvent *e)
int titleMarginRight = 0;
if(titleEdgeLeft > 0)
{
painter.setPen(highlightTitleLeft);
painter.drawLine(r_x+1, Rtitle.top(),
r_x+1, Rtitle.bottom() );
titleMarginLeft = 2;
tempRect.setRect(r_x, r_y, borderLeft, titleEdgeTop+titleHeight+titleEdgeBottom);
if (tempRect.isValid() && region.contains(tempRect) ) {
painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarLeft, active, toolWindow) );
titleMarginLeft = borderLeft;
}
}
// rightTitleSpacer
if(titleEdgeRight > 0)
{
painter.setPen(highlightTitleRight);
painter.drawLine(r_x2-1, Rtitle.top(),
r_x2-1, Rtitle.bottom() );
titleMarginRight = 2;
tempRect.setRect(borderRightLeft, r_y, borderRight, titleEdgeTop+titleHeight+titleEdgeBottom);
if (tempRect.isValid() && region.contains(tempRect) ) {
painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarRight, active, toolWindow) );
titleMarginRight = borderRight;
}
}
// titleSpacer
const QPixmap &caption = captionPixmap();
// QPixmap *titleBfrPtr = active ? aCaptionBuffer : iCaptionBuffer;
if(Rtitle.width() > 0)
{
m_captionRect = captionRect(); // also update m_captionRect!
@ -395,104 +332,47 @@ void PlastikClient::paintEvent(QPaintEvent *e)
}
}
// titleBfrPtr = 0;
// decoSpacer
if(titleEdgeBottom > 0)
{
int l;
if(borderLeft != 0)
l = r_x+2;
else
l = r_x;
int r;
if(borderRight != 0)
r = r_x2-2;
else
r = r_x2;
painter.setPen(deco );
painter.drawLine(l, titleEdgeBottomBottom-1, r, titleEdgeBottomBottom-1 );
painter.drawLine(l, titleEdgeBottomBottom, r, titleEdgeBottomBottom );
if(borderLeft != 0) {
painter.setPen(highlightTitleLeft);
painter.drawLine(r_x+1, titleEdgeBottomTop,
r_x+1, titleEdgeBottomBottom );
}
if(borderRight != 0) {
painter.setPen(highlightTitleRight);
painter.drawLine(r_x2-1, titleEdgeBottomTop,
r_x2-1, titleEdgeBottomBottom );
}
}
// leftSpacer
if(borderLeft > 0 && sideHeight > 0)
{
painter.setPen(highlightLeft );
painter.drawLine(r_x+1, titleEdgeBottomBottom+1,
r_x+1, borderBottomTop-1 );
if(borderLeft > 2) {
tempRect.setCoords(r_x+2, titleEdgeBottomBottom+1,
borderLeftRight, borderBottomTop-1 );
painter.fillRect(tempRect, border );
tempRect.setCoords(r_x, titleEdgeBottomBottom+1, borderLeftRight, borderBottomTop);
if (tempRect.isValid() && region.contains(tempRect) ) {
painter.drawTiledPixmap(tempRect, handler->pixmap(BorderLeftTile, active, toolWindow) );
}
}
// rightSpacer
if(borderRight > 0 && sideHeight > 0)
{
painter.setPen(highlightRight );
painter.drawLine(r_x2-1, titleEdgeBottomBottom+1,
r_x2-1, borderBottomTop-1 );
if(borderRight > 2) {
tempRect.setCoords(borderRightLeft, titleEdgeBottomBottom+1,
r_x2-2, borderBottomTop-1 );
painter.fillRect(tempRect, border );
tempRect.setCoords(borderRightLeft, titleEdgeBottomBottom+1, r_x2, borderBottomTop);
if (tempRect.isValid() && region.contains(tempRect) ) {
painter.drawTiledPixmap(tempRect, handler->pixmap(BorderRightTile, active, toolWindow) );
}
}
// bottomSpacer
if(borderBottom > 0)
{
if(borderLeft != 0) {
painter.setPen(highlightLeft );
painter.drawLine(r_x+1, borderBottomTop,
r_x+1, r_y2-2 );
// anti-alias for the window contour...
painter.setPen(alphaBlendColors(border, windowContour, 110) );
painter.drawPoint(r_x+1, r_y2-1);
int l = r_x;
int r = r_x2;
tempRect.setRect(r_x, borderBottomTop, borderLeft, borderBottom);
if (tempRect.isValid() && region.contains(tempRect) ) {
painter.drawTiledPixmap(tempRect, handler->pixmap(BorderBottomLeft, active, toolWindow) );
l = tempRect.right()+1;
}
if(borderRight != 0) {
painter.setPen(highlightRight );
painter.drawLine(r_x2-1, borderBottomTop,
r_x2-1, r_y2-2 );
// anti-alias for the window contour...
painter.setPen(alphaBlendColors(border, windowContour, 110) );
painter.drawPoint(r_x2-1, r_y2-1);
tempRect.setRect(borderRightLeft, borderBottomTop, borderLeft, borderBottom);
if (tempRect.isValid() && region.contains(tempRect) ) {
painter.drawTiledPixmap(tempRect, handler->pixmap(BorderBottomRight, active, toolWindow) );
r = tempRect.left()-1;
}
// outside the region normally masked by doShape
painter.setPen(filledCorner);
painter.drawPoint(r_x, r_y2);
painter.drawPoint(r_x2, r_y2);
int l;
if(borderLeft != 0)
l = r_x+2;
else
l = r_x;
int r;
if(borderRight != 0)
r = r_x2-2;
else
r = r_x2;
painter.setPen(highlightBottom );
painter.drawLine(l, r_y2-1,
r, r_y2-1 );
tempRect.setCoords(l, borderBottomTop, r, r_y2-2);
painter.fillRect(tempRect, border );
tempRect.setCoords(l, borderBottomTop, r, r_y2);
if (tempRect.isValid() && region.contains(tempRect) ) {
painter.drawTiledPixmap(tempRect, handler->pixmap(BorderBottomTile, active, toolWindow) );
}
}
}
@ -502,6 +382,7 @@ QRect PlastikClient::captionRect() const
QRect r = widget()->rect();
const int titleHeight = layoutMetric(LM_TitleHeight);
const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
const int marginLeft = layoutMetric(LM_TitleBorderLeft);
@ -532,7 +413,7 @@ QRect PlastikClient::captionRect() const
tX = titleLeft+titleWidth-caption.width();
}
return QRect(tX, r.top()+titleEdgeTop, tW, titleHeight);
return QRect(tX, r.top()+titleEdgeTop, tW, titleHeight+titleEdgeBottom);
}
void PlastikClient::updateCaption()
@ -598,7 +479,7 @@ const QPixmap &PlastikClient::captionPixmap() const
int captionWidth = fm.width(c);
int captionHeight = fm.height();
const int th = layoutMetric(LM_TitleHeight, false);
const int th = layoutMetric(LM_TitleHeight, false) + layoutMetric(LM_TitleEdgeBottom, false);
QPainter painter;