Commit 169099b5e9c77c6633deb3c7bb949800a5f80ec2

  • avatar
  • Samuel Rødal <sroedal @trol…ech.com>
  • Fri Sep 18 15:02:25 CEST 2009
Fixed broken scrolling of cached graphics items on X11.

The scrolling was broken in other graphics systems than the native,
since _q_scrollPixmap assumed that all QPixmaps were using the X11
backend. We can just use QPixmap::scroll instead, which should also make
it faster with the raster paint engine than creating a temporary painter
and doing a blit. Also, _q_scrollPixmap would do blending instead of
blitting for non-opaque pixmaps.

Reviewed-by: Olivier Goffart
  
50755075}
50765076
50775077/*!
5078 \internal
5079
5080 Scrolls \a rect in \a pix by \a dx, \a dy.
5081
5082 ### This can be done much more efficiently by using XCopyArea on X11 with
5083 the same dst and src, and through moving pixels in the raster engine. It
5084 can probably also be done much better on the other paint engines.
5085*/
5086void _q_scrollPixmap(QPixmap *pix, const QRect &rect, int dx, int dy)
5087{
5088#if 0
5089 QPainter painter(pix);
5090 painter.setClipRect(rect);
5091 painter.drawPixmap(rect.translated(dx, dy), *pix, rect);
5092 painter.end();
5093#elif defined Q_WS_X11
5094 GC gc = XCreateGC(X11->display, pix->handle(), 0, 0);
5095
5096 XRectangle xrect;
5097 xrect.x = rect.x();
5098 xrect.y = rect.y();
5099 xrect.width = rect.width();
5100 xrect.height = rect.height();
5101 XSetClipRectangles(X11->display, gc, 0, 0, &xrect, 1, YXBanded);
5102
5103 XCopyArea(X11->display, pix->handle(), pix->handle(), gc,
5104 rect.x(), rect.y(), rect.width(), rect.height(),
5105 rect.x()+dx, rect.y()+dy);
5106 XFreeGC(X11->display, gc);
5107#else
5108 QPixmap newPix = *pix;
5109 QPainter painter(&newPix);
5110 painter.setClipRect(rect);
5111 painter.drawPixmap(rect.translated(dx, dy), *pix, rect);
5112 painter.end();
5113 *pix = newPix;
5114#endif
5115}
5116
5117/*!
51185078 \since 4.4
51195079 Scrolls the contents of \a rect by \a dx, \a dy. If \a rect is a null rect
51205080 (the default), the item's bounding rect is scrolled.
51145114 QRectF br = boundingRect().adjusted(-adjust, -adjust, adjust, adjust);
51155115 QRect irect = rect.toRect().translated(-br.x(), -br.y());
51165116
5117 _q_scrollPixmap(&pix, irect, dx, dy);
5117 pix.scroll(dx, dy, irect);
51185118
51195119 QPixmapCache::replace(c->key, pix);
51205120