widgets: Fix painting to a fully transparent top level widget

QWS used to have a line to change the composite mode from SourceOver
to Source for the top level widget. This wasn't used with QPA and I
removed the internal DontSetCompositionMode in qtbase. It turns out that
the QWS way is the most efficient one to initialize the background of
the widget.

The alternative is to have the QPlatformBackingStore::beginPaint
always clear the entire to be painted area and then paint the background
of the widget. The difference of painting each pixel once or twice is
noticable on embedded platforms and in the range of one to two fps.

Reproduce the issue with:
echo "QWidget {background: transparent}" > style.css
./examples/widgets/wiggly/wiggly -stylesheet style.css

Task-number: QTBUG-24526
Change-Id: Ica4c980bb3bf6eb87ddb5b510ac7493292d01543
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
This commit is contained in:
Holger Hans Peter Freyther 2012-04-02 11:59:04 +02:00 committed by Qt by Nokia
parent 5cb2fbe088
commit 83fc52e3b4
3 changed files with 13 additions and 5 deletions

View File

@ -114,9 +114,6 @@ QWindow* QPlatformBackingStore::window() const
This function is called before painting onto the surface begins,
with the \a region in which the painting will occur.
\note A platform providing a backing store with an alpha channel
needs to properly initialize the region to be painted.
\sa endPaint(), paintDevice()
*/

View File

@ -2137,7 +2137,15 @@ void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int
if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) {
const QBrush bg = q->palette().brush(QPalette::Window);
fillRegion(painter, rgn, bg);
if (!(flags & DontSetCompositionMode)) {
//copy alpha straight in
QPainter::CompositionMode oldMode = painter->compositionMode();
painter->setCompositionMode(QPainter::CompositionMode_Source);
fillRegion(painter, rgn, bg);
painter->setCompositionMode(oldMode);
} else {
fillRegion(painter, rgn, bg);
}
}
if (q->autoFillBackground())
@ -5229,6 +5237,8 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset,
else
flags |= DontSubtractOpaqueChildren;
flags |= DontSetCompositionMode;
if (target->devType() == QInternal::Printer) {
QPainter p(target);
render_helper(&p, targetOffset, paintRegion, renderFlags);

View File

@ -284,7 +284,8 @@ public:
DrawInvisible = 0x08,
DontSubtractOpaqueChildren = 0x10,
DontDrawOpaqueChildren = 0x20,
DontDrawNativeChildren = 0x40
DontDrawNativeChildren = 0x40,
DontSetCompositionMode = 0x80
};
enum CloseMode {