Commit 739ad768 authored by Jan Arve Saether's avatar Jan Arve Saether Committed by The Qt Project
Browse files

Do not always fallback to bitmap printing when printing alpha.



The previous code resulted in that all regions that had some alpha
blending content had to be rasterized as bitmaps.

With this patch, we only need to fallback to proper alpha blending
if there is a background content to blend against.
If there is no background content we simly assume that the background
is white (which happen to be the most common paper color). It will
then be treated as a solid background.

Task-number: QTBUG-33548
Change-Id: I9d2c9be95a701704cdb3724480421db49b4cdd98
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: default avatarGunnar Sletta <gunnar.sletta@jollamobile.com>
parent 9ce8a6b9
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
......@@ -166,11 +166,14 @@ void QAlphaPaintEngine::drawPath(const QPainterPath &path)
if (d->m_pass == 0) {
d->m_continueCall = false;
if (d->m_hasalpha || d->m_advancedPen || d->m_advancedBrush
if (d->canSeeTroughBackground(d->m_hasalpha, tr) || d->m_advancedPen || d->m_advancedBrush
|| d->m_emulateProjectiveTransforms)
{
d->addAlphaRect(tr);
}
d->addDirtyRect(tr);
if (d->m_picengine)
d->m_picengine->drawPath(path);
} else {
......@@ -192,12 +195,14 @@ void QAlphaPaintEngine::drawPolygon(const QPointF *points, int pointCount, Polyg
if (d->m_pass == 0) {
d->m_continueCall = false;
if (d->m_hasalpha || d->m_advancedPen || d->m_advancedBrush
if (d->canSeeTroughBackground(d->m_hasalpha, tr) || d->m_advancedPen || d->m_advancedBrush
|| d->m_emulateProjectiveTransforms)
{
d->addAlphaRect(tr);
}
d->addDirtyRect(tr);
if (d->m_picengine)
d->m_picengine->drawPolygon(points, pointCount, mode);
} else {
......@@ -212,10 +217,12 @@ void QAlphaPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRe
QRectF tr = d->m_transform.mapRect(r);
if (d->m_pass == 0) {
d->m_continueCall = false;
if (pm.hasAlpha() || d->m_alphaOpacity || d->m_complexTransform || pm.isQBitmap()) {
if (d->canSeeTroughBackground(pm.hasAlpha() || d->m_alphaOpacity, tr) || d->m_complexTransform || pm.isQBitmap()) {
d->addAlphaRect(tr);
}
d->addDirtyRect(tr);
if (d->m_picengine)
d->m_picengine->drawPixmap(r, pm, sr);
......@@ -233,9 +240,12 @@ void QAlphaPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem
if (d->m_pass == 0) {
d->m_continueCall = false;
if (d->m_alphaPen || d->m_alphaOpacity || d->m_advancedPen) {
if (d->canSeeTroughBackground(d->m_alphaPen || d->m_alphaOpacity, tr) || d->m_advancedPen) {
d->addAlphaRect(tr);
}
d->addDirtyRect(tr);
if (d->m_picengine) {
d->m_picengine->drawTextItem(p, textItem);
}
......@@ -252,9 +262,12 @@ void QAlphaPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap,
if (d->m_pass == 0) {
d->m_continueCall = false;
if (pixmap.hasAlpha() || d->m_alphaOpacity || d->m_complexTransform || pixmap.isQBitmap()) {
if (d->canSeeTroughBackground(pixmap.hasAlpha() || d->m_alphaOpacity, brect) || d->m_complexTransform || pixmap.isQBitmap()) {
d->addAlphaRect(brect);
}
d->addDirtyRect(brect);
if (d->m_picengine)
d->m_picengine->drawTiledPixmap(r, pixmap, s);
} else {
......@@ -410,19 +423,14 @@ QRectF QAlphaPaintEnginePrivate::addPenWidth(const QPainterPath &path)
return (tmp.controlPointRect() * m_transform).boundingRect();
}
QRect QAlphaPaintEnginePrivate::toRect(const QRectF &rect) const
void QAlphaPaintEnginePrivate::addAlphaRect(const QRectF &rect)
{
QRect r;
r.setLeft(int(rect.left()));
r.setTop(int(rect.top()));
r.setRight(int(rect.right() + 1));
r.setBottom(int(rect.bottom() + 1));
return r;
m_alphargn |= rect.toAlignedRect();
}
void QAlphaPaintEnginePrivate::addAlphaRect(const QRectF &rect)
bool QAlphaPaintEnginePrivate::canSeeTroughBackground(bool somethingInRectHasAlpha, const QRectF &rect) const
{
m_alphargn |= toRect(rect);
return somethingInRectHasAlpha && m_dirtyrgn.intersects(rect.toAlignedRect());
}
void QAlphaPaintEnginePrivate::drawAlphaImage(const QRectF &rect)
......@@ -474,7 +482,7 @@ void QAlphaPaintEnginePrivate::drawAlphaImage(const QRectF &rect)
bool QAlphaPaintEnginePrivate::fullyContained(const QRectF &rect) const
{
QRegion r(toRect(rect));
QRegion r(rect.toAlignedRect());
return (m_cliprgn.intersected(r) == r);
}
......
......@@ -107,6 +107,7 @@ public:
QRegion m_alphargn;
QRegion m_cliprgn;
QRegion m_dirtyrgn;
bool m_hasalpha;
bool m_alphaPen;
......@@ -122,6 +123,9 @@ public:
QPen m_pen;
void addAlphaRect(const QRectF &rect);
void addDirtyRect(const QRectF &rect) { m_dirtyrgn |= rect.toAlignedRect(); }
bool canSeeTroughBackground(bool somethingInRectHasAlpha, const QRectF &rect) const;
QRectF addPenWidth(const QPainterPath &path);
void drawAlphaImage(const QRectF &rect);
QRect toRect(const QRectF &rect) const;
......
......@@ -573,7 +573,13 @@ void QWin32PrintEngine::drawPixmap(const QRectF &targetRect,
width = (tw - (x * txinc));
}
QPixmap p = pixmap.copy(tileSize * x, tileSize * y, imgw, imgh);
QImage img(QSize(imgw, imgh), QImage::Format_RGB32);
img.fill(Qt::white);
QPainter painter(&img);
painter.drawPixmap(0,0, pixmap, tileSize * x, tileSize * y, imgw, imgh);
QPixmap p = QPixmap::fromImage(img);
HBITMAP hbitmap = qt_pixmapToWinHBITMAP(p, HBitmapNoAlpha);
HDC display_dc = GetDC(0);
HDC hbitmap_hdc = CreateCompatibleDC(display_dc);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment