de-duplicate code in QPainter

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-12-10 23:07:10 +02:00
parent a480bbbdd2
commit ba61b62af0

View file

@ -4481,65 +4481,10 @@ void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm)
p.x(), p.y(), pm.width(), pm.height());
#endif
Q_D(QPainter);
const int w = pm.width();
const int h = pm.height();
if (!d->engine || pm.isNull())
return;
#ifndef QT_NO_DEBUG
qt_painter_thread_test(d->device->devType(), "drawPixmap()", true);
#endif
if (d->extended) {
d->extended->drawPixmap(p, pm);
return;
}
qreal x = p.x();
qreal y = p.y();
int w = pm.width();
int h = pm.height();
if (w <= 0)
return;
// Emulate opaque background for bitmaps
if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap()) {
fillRect(QRectF(x, y, w, h), d->state->bgBrush.color());
}
d->updateState(d->state);
if ((d->state->matrix.type() > QTransform::TxTranslate
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform))
|| (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)))
{
save();
// If there is no rotation involved we have to make sure we use the
// antialiased and not the aliased coordinate system by rounding the coordinates.
if (d->state->matrix.type() <= QTransform::TxScale) {
const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix);
x = p.x();
y = p.y();
}
translate(x, y);
setBackgroundMode(Qt::TransparentMode);
QBrush brush(d->state->pen.color(), pm);
setBrush(brush);
setPen(Qt::NoPen);
setBrushOrigin(QPointF(0, 0));
drawRect(pm.rect());
restore();
} else {
if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
x += d->state->matrix.dx();
y += d->state->matrix.dy();
}
d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(0, 0, w, h));
}
drawPixmap(QRectF(p.x(), p.y(), w, h), pm, QRectF(0, 0, w, h));
}
void QPainter::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
@ -4774,56 +4719,15 @@ void QPainter::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
void QPainter::drawImage(const QPointF &p, const QImage &image)
{
Q_D(QPainter);
#if defined QT_DEBUG_DRAW
printf("QPainter::drawImage(), p=[%.2f,%.2f], img=[%d,%d]\n",
p.x(), p.y(), image.width(), image.height());
#endif
if (!d->engine || image.isNull())
return;
const int w = image.width();
const int h = image.height();
if (d->extended) {
d->extended->drawImage(p, image);
return;
}
qreal x = p.x();
qreal y = p.y();
int w = image.width();
int h = image.height();
d->updateState(d->state);
if (((d->state->matrix.type() > QTransform::TxTranslate)
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform))
|| (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)))
{
save();
// If there is no rotation involved we have to make sure we use the
// antialiased and not the aliased coordinate system by rounding the coordinates.
if (d->state->matrix.type() <= QTransform::TxScale) {
const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix);
x = p.x();
y = p.y();
}
translate(x, y);
setBackgroundMode(Qt::TransparentMode);
QBrush brush(image);
setBrush(brush);
setPen(Qt::NoPen);
setBrushOrigin(QPointF(0, 0));
drawRect(image.rect());
restore();
return;
}
if (d->state->matrix.type() == QTransform::TxTranslate
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
x += d->state->matrix.dx();
y += d->state->matrix.dy();
}
d->engine->drawImage(QRectF(x, y, w, h), image, QRectF(0, 0, w, h), Qt::AutoColor);
drawImage(QRectF(p.x(), p.y(), w, h), image, QRectF(0, 0, w, h), Qt::AutoColor);
}
void QPainter::drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect,