diff options
Diffstat (limited to 'src/gui/painting')
29 files changed, 448 insertions, 219 deletions
diff --git a/src/gui/painting/qbezier.cpp b/src/gui/painting/qbezier.cpp index ddd1d997f2..8cda4b4072 100644 --- a/src/gui/painting/qbezier.cpp +++ b/src/gui/painting/qbezier.cpp @@ -261,9 +261,9 @@ static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offse static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold) { int map[4]; - bool p1_p2_equal = (orig->x1 == orig->x2 && orig->y1 == orig->y2); - bool p2_p3_equal = (orig->x2 == orig->x3 && orig->y2 == orig->y3); - bool p3_p4_equal = (orig->x3 == orig->x4 && orig->y3 == orig->y4); + bool p1_p2_equal = qFuzzyCompare(orig->x1, orig->x2) && qFuzzyCompare(orig->y1, orig->y2); + bool p2_p3_equal = qFuzzyCompare(orig->x2, orig->x3) && qFuzzyCompare(orig->y2, orig->y3); + bool p3_p4_equal = qFuzzyCompare(orig->x3, orig->x4) && qFuzzyCompare(orig->y3, orig->y4); QPointF points[4]; int np = 0; diff --git a/src/gui/painting/qblendfunctions_p.h b/src/gui/painting/qblendfunctions_p.h index 5ea78cdde2..080da98ec4 100644 --- a/src/gui/painting/qblendfunctions_p.h +++ b/src/gui/painting/qblendfunctions_p.h @@ -71,10 +71,10 @@ void qt_scale_image_16bit(uchar *destPixels, int dbpl, const int ix = 0x00010000 * sx; const int iy = 0x00010000 * sy; -// qDebug() << "scale:" << endl -// << " - target" << targetRect << endl -// << " - source" << srcRect << endl -// << " - clip" << clip << endl +// qDebug() << "scale:" << Qt::endl +// << " - target" << targetRect << Qt::endl +// << " - source" << srcRect << Qt::endl +// << " - clip" << clip << Qt::endl // << " - sx=" << sx << " sy=" << sy << " ix=" << ix << " iy=" << iy; QRect tr = targetRect.normalized().toRect(); @@ -162,10 +162,10 @@ template <typename T> void qt_scale_image_32bit(uchar *destPixels, int dbpl, const int ix = 0x00010000 * sx; const int iy = 0x00010000 * sy; -// qDebug() << "scale:" << endl -// << " - target" << targetRect << endl -// << " - source" << srcRect << endl -// << " - clip" << clip << endl +// qDebug() << "scale:" << Qt::endl +// << " - target" << targetRect << Qt::endl +// << " - source" << srcRect << Qt::endl +// << " - clip" << clip << Qt::endl // << " - sx=" << sx << " sy=" << sy << " ix=" << ix << " iy=" << iy; QRect tr = targetRect.normalized().toRect(); diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 49b40aa756..13d986073e 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -1401,6 +1401,13 @@ QGradient::QGradient(Preset preset) } } +/*! + \internal +*/ +QGradient::~QGradient() +{ +} + QT_END_NAMESPACE static void initGradientPresets() { Q_INIT_RESOURCE(qmake_webgradients); } Q_CONSTRUCTOR_FUNCTION(initGradientPresets); @@ -1785,6 +1792,12 @@ QLinearGradient::QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, q { } +/*! + \internal +*/ +QLinearGradient::~QLinearGradient() +{ +} /*! Returns the start point of this linear gradient in logical coordinates. @@ -2056,6 +2069,13 @@ QRadialGradient::QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal f } /*! + \internal +*/ +QRadialGradient::~QRadialGradient() +{ +} + +/*! Returns the center of this radial gradient in logical coordinates. \sa QGradient::stops() @@ -2301,6 +2321,13 @@ QConicalGradient::QConicalGradient(qreal cx, qreal cy, qreal angle) { } +/*! + \internal +*/ +QConicalGradient::~QConicalGradient() +{ +} + /*! Constructs a conical with center at (0, 0) starting the diff --git a/src/gui/painting/qbrush.h b/src/gui/painting/qbrush.h index 27d710eca6..ca51430cf4 100644 --- a/src/gui/painting/qbrush.h +++ b/src/gui/painting/qbrush.h @@ -79,10 +79,8 @@ public: ~QBrush(); QBrush &operator=(const QBrush &brush); -#ifdef Q_COMPILER_RVALUE_REFS inline QBrush &operator=(QBrush &&other) noexcept { qSwap(d, other.d); return *this; } -#endif inline void swap(QBrush &other) noexcept { qSwap(d, other.d); } @@ -378,6 +376,7 @@ public: QGradient(); QGradient(Preset); + ~QGradient(); Type type() const { return m_type; } @@ -431,6 +430,7 @@ public: QLinearGradient(); QLinearGradient(const QPointF &start, const QPointF &finalStop); QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop); + ~QLinearGradient(); QPointF start() const; void setStart(const QPointF &start); @@ -455,6 +455,8 @@ public: QRadialGradient(const QPointF ¢er, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius); QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius); + ~QRadialGradient(); + QPointF center() const; void setCenter(const QPointF ¢er); inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); } @@ -480,6 +482,7 @@ public: QConicalGradient(); QConicalGradient(const QPointF ¢er, qreal startAngle); QConicalGradient(qreal cx, qreal cy, qreal startAngle); + ~QConicalGradient(); QPointF center() const; void setCenter(const QPointF ¢er); diff --git a/src/gui/painting/qcolor.h b/src/gui/painting/qcolor.h index 77b2d43c40..e3c267f97d 100644 --- a/src/gui/painting/qcolor.h +++ b/src/gui/painting/qcolor.h @@ -82,11 +82,9 @@ public: #if QT_VERSION < QT_VERSION_CHECK(6,0,0) inline QColor(const QColor &color) noexcept; // ### Qt 6: remove all of these, the trivial ones are fine. -# ifdef Q_COMPILER_RVALUE_REFS QColor(QColor &&other) noexcept : cspec(other.cspec), ct(other.ct) {} QColor &operator=(QColor &&other) noexcept { cspec = other.cspec; ct = other.ct; return *this; } -# endif QColor &operator=(const QColor &) noexcept; #endif // Qt < 6 diff --git a/src/gui/painting/qcolormatrix_p.h b/src/gui/painting/qcolormatrix_p.h index 3d1dca6222..66db95df7e 100644 --- a/src/gui/painting/qcolormatrix_p.h +++ b/src/gui/painting/qcolormatrix_p.h @@ -52,6 +52,7 @@ // #include <QtGui/qtguiglobal.h> +#include <QtCore/qpoint.h> #include <cmath> QT_BEGIN_NAMESPACE @@ -61,7 +62,13 @@ class QColorVector { public: QColorVector() = default; - constexpr QColorVector(float x, float y, float z) : x(x), y(y), z(z), _unused(0.0f) { } + Q_DECL_CONSTEXPR QColorVector(float x, float y, float z) : x(x), y(y), z(z), _unused(0.0f) { } + explicit Q_DECL_CONSTEXPR QColorVector(const QPointF &chr) // from XY chromaticity + : x(chr.x() / chr.y()) + , y(1.0f) + , z((1.0 - chr.x() - chr.y()) / chr.y()) + , _unused(0.0f) + { } float x; // X, x or red float y; // Y, y or green float z; // Z, Y or blue @@ -69,11 +76,28 @@ public: friend inline bool operator==(const QColorVector &v1, const QColorVector &v2); friend inline bool operator!=(const QColorVector &v1, const QColorVector &v2); + bool isNull() const + { + return !x && !y && !z; + } + + static Q_DECL_CONSTEXPR QColorVector null() { return QColorVector(0.0f, 0.0f, 0.0f); } + static bool isValidChromaticity(const QPointF &chr) + { + if (chr.x() < qreal(0.0) || chr.x() > qreal(1.0)) + return false; + if (chr.y() <= qreal(0.0) || chr.y() > qreal(1.0)) + return false; + if (chr.x() + chr.y() > qreal(1.0)) + return false; + return true; + } - static constexpr QColorVector null() { return QColorVector(0.0f, 0.0f, 0.0f); } - // Common whitepoints on normalized XYZ form: - static constexpr QColorVector D50() { return QColorVector(0.96421f, 1.0f, 0.82519f); } - static constexpr QColorVector D65() { return QColorVector(0.95043f, 1.0f, 1.08890f); } + // Common whitepoints: + static Q_DECL_CONSTEXPR QPointF D50Chromaticity() { return QPointF(0.34567, 0.35850); } + static Q_DECL_CONSTEXPR QPointF D65Chromaticity() { return QPointF(0.31271, 0.32902); } + static Q_DECL_CONSTEXPR QColorVector D50() { return QColorVector(D50Chromaticity()); } + static Q_DECL_CONSTEXPR QColorVector D65() { return QColorVector(D65Chromaticity()); } }; inline bool operator==(const QColorVector &v1, const QColorVector &v2) @@ -102,6 +126,10 @@ public: friend inline bool operator==(const QColorMatrix &m1, const QColorMatrix &m2); friend inline bool operator!=(const QColorMatrix &m1, const QColorMatrix &m2); + bool isNull() const + { + return r.isNull() && g.isNull() && b.isNull(); + } bool isValid() const { // A color matrix must be invertible @@ -167,6 +195,13 @@ public: { return { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }; } + static QColorMatrix fromScale(QColorVector v) + { + return QColorMatrix { { v.x, 0.0f, 0.0f }, + { 0.0f, v.y, 0.0f }, + { 0.0f, 0.0f, v.z } }; + } + // These are used to recognize matrices from ICC profiles: static QColorMatrix toXyzFromSRgb() { return QColorMatrix { { 0.4360217452f, 0.2224751115f, 0.0139281144f }, diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp index 24785f7b61..8d3bbbe412 100644 --- a/src/gui/painting/qcolorspace.cpp +++ b/src/gui/painting/qcolorspace.cpp @@ -53,6 +53,104 @@ QT_BEGIN_NAMESPACE +QBasicMutex QColorSpacePrivate::s_lutWriteLock; + +QColorSpacePrimaries::QColorSpacePrimaries(QColorSpace::Gamut gamut) +{ + switch (gamut) { + case QColorSpace::Gamut::SRgb: + redPoint = QPointF(0.640, 0.330); + greenPoint = QPointF(0.300, 0.600); + bluePoint = QPointF(0.150, 0.060); + whitePoint = QColorVector::D65Chromaticity(); + break; + case QColorSpace::Gamut::DciP3D65: + redPoint = QPointF(0.680, 0.320); + greenPoint = QPointF(0.265, 0.690); + bluePoint = QPointF(0.150, 0.060); + whitePoint = QColorVector::D65Chromaticity(); + break; + case QColorSpace::Gamut::Bt2020: + redPoint = QPointF(0.708, 0.292); + greenPoint = QPointF(0.190, 0.797); + bluePoint = QPointF(0.131, 0.046); + whitePoint = QColorVector::D65Chromaticity(); + break; + case QColorSpace::Gamut::AdobeRgb: + redPoint = QPointF(0.640, 0.330); + greenPoint = QPointF(0.210, 0.710); + bluePoint = QPointF(0.150, 0.060); + whitePoint = QColorVector::D65Chromaticity(); + break; + case QColorSpace::Gamut::ProPhotoRgb: + redPoint = QPointF(0.7347, 0.2653); + greenPoint = QPointF(0.1596, 0.8404); + bluePoint = QPointF(0.0366, 0.0001); + whitePoint = QColorVector::D50Chromaticity(); + break; + default: + Q_UNREACHABLE(); + } +} + +bool QColorSpacePrimaries::areValid() const +{ + if (!QColorVector::isValidChromaticity(redPoint)) + return false; + if (!QColorVector::isValidChromaticity(greenPoint)) + return false; + if (!QColorVector::isValidChromaticity(bluePoint)) + return false; + if (!QColorVector::isValidChromaticity(whitePoint)) + return false; + return true; +} + +QColorMatrix QColorSpacePrimaries::toXyzMatrix() const +{ + // This converts to XYZ in some undefined scale. + QColorMatrix toXyz = { QColorVector(redPoint), + QColorVector(greenPoint), + QColorVector(bluePoint) }; + + // Since the white point should be (1.0, 1.0, 1.0) in the + // input, we can figure out the scale by using the + // inverse conversion on the white point. + QColorVector wXyz(whitePoint); + QColorVector whiteScale = toXyz.inverted().map(wXyz); + + // Now we have scaled conversion to XYZ relative to the given whitepoint + toXyz = toXyz * QColorMatrix::fromScale(whiteScale); + + // But we want a conversion to XYZ relative to D50 + QColorVector wXyzD50 = QColorVector::D50(); + + if (wXyz != wXyzD50) { + // Do chromatic adaptation to map our white point to XYZ D50. + + // The Bradford method chromatic adaptation matrix: + QColorMatrix abrad = { { 0.8951f, -0.7502f, 0.0389f }, + { 0.2664f, 1.7135f, -0.0685f }, + { -0.1614f, 0.0367f, 1.0296f } }; + QColorMatrix abradinv = { { 0.9869929f, 0.4323053f, -0.0085287f }, + { -0.1470543f, 0.5183603f, 0.0400428f }, + { 0.1599627f, 0.0492912f, 0.9684867f } }; + + QColorVector srcCone = abrad.map(wXyz); + QColorVector dstCone = abrad.map(wXyzD50); + + QColorMatrix wToD50 = { { dstCone.x / srcCone.x, 0, 0 }, + { 0, dstCone.y / srcCone.y, 0 }, + { 0, 0, dstCone.z / srcCone.z } }; + + + QColorMatrix chromaticAdaptation = abradinv * (wToD50 * abrad); + toXyz = chromaticAdaptation * toXyz; + } + + return toXyz; +} + QColorSpacePrivate::QColorSpacePrivate() : id(QColorSpace::Unknown) , gamut(QColorSpace::Gamut::Custom) @@ -128,6 +226,21 @@ QColorSpacePrivate::QColorSpacePrivate(QColorSpace::Gamut gamut, QColorSpace::Tr initialize(); } +QColorSpacePrivate::QColorSpacePrivate(const QColorSpacePrimaries &primaries, + QColorSpace::TransferFunction fun, + float gamma) + : gamut(QColorSpace::Gamut::Custom) + , transferFunction(fun) + , gamma(gamma) +{ + Q_ASSERT(primaries.areValid()); + toXyz = primaries.toXyzMatrix(); + whitePoint = QColorVector(primaries.whitePoint); + if (!identifyColorSpace()) + id = QColorSpace::Unknown; + setTransferFunction(); +} + bool QColorSpacePrivate::identifyColorSpace() { switch (gamut) { @@ -195,33 +308,14 @@ void QColorSpacePrivate::initialize() void QColorSpacePrivate::setToXyzMatrix() { - switch (gamut) { - case QColorSpace::Gamut::SRgb: - toXyz = QColorMatrix::toXyzFromSRgb(); - whitePoint = QColorVector::D65(); - return; - case QColorSpace::Gamut::AdobeRgb: - toXyz = QColorMatrix::toXyzFromAdobeRgb(); - whitePoint = QColorVector::D65(); - return; - case QColorSpace::Gamut::DciP3D65: - toXyz = QColorMatrix::toXyzFromDciP3D65(); - whitePoint = QColorVector::D65(); - return; - case QColorSpace::Gamut::ProPhotoRgb: - toXyz = QColorMatrix::toXyzFromProPhotoRgb(); - whitePoint = QColorVector::D50(); - return; - case QColorSpace::Gamut::Bt2020: - toXyz = QColorMatrix::toXyzFromBt2020(); - whitePoint = QColorVector::D65(); - return; - case QColorSpace::Gamut::Custom: + if (gamut == QColorSpace::Gamut::Custom) { toXyz = QColorMatrix::null(); whitePoint = QColorVector::D50(); return; } - Q_UNREACHABLE(); + QColorSpacePrimaries primaries(gamut); + toXyz = primaries.toXyzMatrix(); + whitePoint = QColorVector(primaries.whitePoint); } void QColorSpacePrivate::setTransferFunction() @@ -386,6 +480,23 @@ QColorSpace::QColorSpace(QColorSpace::Gamut gamut, float gamma) { } +/*! + Creates a custom colorspace with a gamut based on the chromaticities of the primary colors \a whitePoint, + \a redPoint, \a greenPoint and \a bluePoint, and using the transfer function \a fun and optionally \a gamma. + */ +QColorSpace::QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, + const QPointF &greenPoint, const QPointF &bluePoint, + QColorSpace::TransferFunction fun, float gamma) +{ + QColorSpacePrimaries primaries(whitePoint, redPoint, greenPoint, bluePoint); + if (!primaries.areValid()) { + qWarning() << "QColorSpace attempted constructed from invalid primaries:" << whitePoint << redPoint << greenPoint << bluePoint; + d_ptr = QColorSpace(QColorSpace::Undefined).d_ptr; + return; + } + d_ptr = new QColorSpacePrivate(primaries, fun, gamma); +} + QColorSpace::~QColorSpace() { } @@ -549,7 +660,7 @@ bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) \fn bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) \relates QColorSpace - Returns \c true if colorspace \a colorspace1 is not equal to colorspace \a colorspace2; + Returns \c true if colorspace \a colorSpace1 is not equal to colorspace \a colorSpace2; otherwise returns \c false */ diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h index 923546ec6f..56676826a9 100644 --- a/src/gui/painting/qcolorspace.h +++ b/src/gui/painting/qcolorspace.h @@ -85,6 +85,9 @@ public: QColorSpace(ColorSpaceId colorSpaceId = Undefined); QColorSpace(Gamut gamut, TransferFunction fun, float gamma = 0.0f); QColorSpace(Gamut gamut, float gamma); + QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, + const QPointF &greenPoint, const QPointF &bluePoint, + TransferFunction fun, float gamma = 0.0f); ~QColorSpace(); QColorSpace(QColorSpace &&colorSpace); diff --git a/src/gui/painting/qcolorspace_p.h b/src/gui/painting/qcolorspace_p.h index 91107a9a89..a49c46f195 100644 --- a/src/gui/painting/qcolorspace_p.h +++ b/src/gui/painting/qcolorspace_p.h @@ -56,18 +56,44 @@ #include "qcolortrc_p.h" #include "qcolortrclut_p.h" +#include <QtCore/qmutex.h> +#include <QtCore/qpoint.h> #include <QtCore/qshareddata.h> QT_BEGIN_NAMESPACE +class Q_GUI_EXPORT QColorSpacePrimaries +{ +public: + QColorSpacePrimaries() = default; + QColorSpacePrimaries(QColorSpace::Gamut gamut); + QColorSpacePrimaries(QPointF whitePoint, + QPointF redPoint, + QPointF greenPoint, + QPointF bluePoint) + : whitePoint(whitePoint) + , redPoint(redPoint) + , greenPoint(greenPoint) + , bluePoint(bluePoint) + { } + + QColorMatrix toXyzMatrix() const; + bool areValid() const; + + QPointF whitePoint; + QPointF redPoint; + QPointF greenPoint; + QPointF bluePoint; +}; + class QColorSpacePrivate : public QSharedData { public: QColorSpacePrivate(); QColorSpacePrivate(QColorSpace::ColorSpaceId colorSpaceId); QColorSpacePrivate(QColorSpace::Gamut gamut, QColorSpace::TransferFunction fun, float gamma); + QColorSpacePrivate(const QColorSpacePrimaries &primaries, QColorSpace::TransferFunction fun, float gamma); QColorSpacePrivate(const QColorSpacePrivate &other) = default; - QColorSpacePrivate &operator=(const QColorSpacePrivate &other) = default; void initialize(); void setToXyzMatrix(); @@ -87,8 +113,24 @@ public: QString description; QByteArray iccProfile; - mutable QSharedPointer<QColorTrcLut> lut[3]; - mutable QAtomicInt lutsGenerated; + static QBasicMutex s_lutWriteLock; + struct LUT { + LUT() = default; + ~LUT() = default; + LUT(const LUT &other) + { + if (other.generated.loadAcquire()) { + table[0] = other.table[0]; + table[1] = other.table[1]; + table[2] = other.table[2]; + generated.store(1); + } + } + QSharedPointer<QColorTrcLut> &operator[](int i) { return table[i]; } + const QSharedPointer<QColorTrcLut> &operator[](int i) const { return table[i]; } + QSharedPointer<QColorTrcLut> table[3]; + QAtomicInt generated; + } mutable lut; }; QT_END_NAMESPACE diff --git a/src/gui/painting/qcolortransform.cpp b/src/gui/painting/qcolortransform.cpp index c723e12f8a..2f81449693 100644 --- a/src/gui/painting/qcolortransform.cpp +++ b/src/gui/painting/qcolortransform.cpp @@ -68,8 +68,12 @@ QColorTrcLut *lutFromTrc(const QColorTrc &trc) void QColorTransformPrivate::updateLutsIn() const { - if (colorSpaceIn->lutsGenerated.loadAcquire()) + if (colorSpaceIn->lut.generated.loadAcquire()) return; + QMutexLocker lock(&QColorSpacePrivate::s_lutWriteLock); + if (colorSpaceIn->lut.generated.load()) + return; + for (int i = 0; i < 3; ++i) { if (!colorSpaceIn->trc[i].isValid()) return; @@ -84,12 +88,15 @@ void QColorTransformPrivate::updateLutsIn() const colorSpaceIn->lut[i].reset(lutFromTrc(colorSpaceIn->trc[i])); } - colorSpaceIn->lutsGenerated.storeRelease(1); + colorSpaceIn->lut.generated.storeRelease(1); } void QColorTransformPrivate::updateLutsOut() const { - if (colorSpaceOut->lutsGenerated.loadAcquire()) + if (colorSpaceOut->lut.generated.loadAcquire()) + return; + QMutexLocker lock(&QColorSpacePrivate::s_lutWriteLock); + if (colorSpaceOut->lut.generated.load()) return; for (int i = 0; i < 3; ++i) { if (!colorSpaceOut->trc[i].isValid()) @@ -105,7 +112,7 @@ void QColorTransformPrivate::updateLutsOut() const colorSpaceOut->lut[i].reset(lutFromTrc(colorSpaceOut->trc[i])); } - colorSpaceOut->lutsGenerated.storeRelease(1); + colorSpaceOut->lut.generated.storeRelease(1); } /*! @@ -150,7 +157,7 @@ QRgb QColorTransform::map(const QRgb &argb) const c.x = std::max(0.0f, std::min(1.0f, c.x)); c.y = std::max(0.0f, std::min(1.0f, c.y)); c.z = std::max(0.0f, std::min(1.0f, c.z)); - if (d->colorSpaceOut->lutsGenerated.loadAcquire()) { + if (d->colorSpaceOut->lut.generated.loadAcquire()) { c.x = d->colorSpaceOut->lut[0]->fromLinear(c.x); c.y = d->colorSpaceOut->lut[1]->fromLinear(c.y); c.z = d->colorSpaceOut->lut[2]->fromLinear(c.z); @@ -182,7 +189,7 @@ QRgba64 QColorTransform::map(const QRgba64 &rgba64) const c.x = std::max(0.0f, std::min(1.0f, c.x)); c.y = std::max(0.0f, std::min(1.0f, c.y)); c.z = std::max(0.0f, std::min(1.0f, c.z)); - if (d->colorSpaceOut->lutsGenerated.loadAcquire()) { + if (d->colorSpaceOut->lut.generated.loadAcquire()) { c.x = d->colorSpaceOut->lut[0]->fromLinear(c.x); c.y = d->colorSpaceOut->lut[1]->fromLinear(c.y); c.z = d->colorSpaceOut->lut[2]->fromLinear(c.z); @@ -221,7 +228,7 @@ QColor QColorTransform::map(const QColor &color) const c = d->colorMatrix.map(c); bool inGamut = c.x >= 0.0f && c.x <= 1.0f && c.y >= 0.0f && c.y <= 1.0f && c.z >= 0.0f && c.z <= 1.0f; if (inGamut) { - if (d_ptr->colorSpaceOut->lutsGenerated.loadAcquire()) { + if (d_ptr->colorSpaceOut->lut.generated.loadAcquire()) { c.x = d->colorSpaceOut->lut[0]->fromLinear(c.x); c.y = d->colorSpaceOut->lut[1]->fromLinear(c.y); c.z = d->colorSpaceOut->lut[2]->fromLinear(c.z); diff --git a/src/gui/painting/qcoregraphics.mm b/src/gui/painting/qcoregraphics.mm index 53066687d3..e2497eaadb 100644 --- a/src/gui/painting/qcoregraphics.mm +++ b/src/gui/painting/qcoregraphics.mm @@ -366,40 +366,35 @@ void qt_mac_scale_region(QRegion *region, qreal scaleFactor) // ---------------------- QMacCGContext ---------------------- -QMacCGContext::QMacCGContext(QPaintDevice *paintDevice) : context(0) +QMacCGContext::QMacCGContext(QPaintDevice *paintDevice) { - // In Qt 5, QWidget and QPixmap (and QImage) paint devices are all QImages under the hood. - QImage *image = 0; - if (paintDevice->devType() == QInternal::Image) { - image = static_cast<QImage *>(paintDevice); - } else if (paintDevice->devType() == QInternal::Pixmap) { - - const QPixmap *pm = static_cast<const QPixmap*>(paintDevice); - QPlatformPixmap *data = const_cast<QPixmap *>(pm)->data_ptr().data(); - if (data && data->classId() == QPlatformPixmap::RasterClass) { - image = data->buffer(); - } else { - qDebug("QMacCGContext: Unsupported pixmap class"); - } - } else if (paintDevice->devType() == QInternal::Widget) { - // TODO test: image = static_cast<QImage *>(static_cast<const QWidget *>(paintDevice)->backingStore()->paintDevice()); - qDebug("QMacCGContext: not implemented: Widget class"); - } - - if (!image) - return; // Context type not supported. - - QCFType<CGColorSpaceRef> colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); - context = CGBitmapContextCreate(image->bits(), image->width(), image->height(), 8, - image->bytesPerLine(), colorSpace, qt_mac_bitmapInfoForImage(*image)); + initialize(paintDevice); +} - CGContextTranslateCTM(context, 0, image->height()); - const qreal devicePixelRatio = paintDevice->devicePixelRatioF(); - CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); - CGContextScaleCTM(context, 1, -1); +void QMacCGContext::initialize(QPaintDevice *paintDevice) +{ + // Find the underlying QImage of the paint device + switch (int deviceType = paintDevice->devType()) { + case QInternal::Pixmap: { + auto *platformPixmap = static_cast<QPixmap*>(paintDevice)->handle(); + if (platformPixmap && platformPixmap->classId() == QPlatformPixmap::RasterClass) + initialize(platformPixmap->buffer()); + else + qWarning() << "QMacCGContext: Unsupported pixmap class" << platformPixmap->classId(); + break; + } + case QInternal::Image: + initialize(static_cast<const QImage *>(paintDevice)); + break; + case QInternal::Widget: + qWarning() << "QMacCGContext: not implemented: Widget class"; + break; + default: + qWarning() << "QMacCGContext:: Unsupported paint device type" << deviceType; + } } -QMacCGContext::QMacCGContext(QPainter *painter) : context(0) +QMacCGContext::QMacCGContext(QPainter *painter) { QPaintEngine *paintEngine = painter->paintEngine(); @@ -414,51 +409,68 @@ QMacCGContext::QMacCGContext(QPainter *painter) : context(0) return; } - int devType = painter->device()->devType(); - if (paintEngine->type() == QPaintEngine::Raster - && (devType == QInternal::Widget || - devType == QInternal::Pixmap || - devType == QInternal::Image)) { - - const QImage *image = static_cast<const QImage *>(paintEngine->paintDevice()); - QCFType<CGColorSpaceRef> colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); - context = CGBitmapContextCreate((void *)image->bits(), image->width(), image->height(), 8, - image->bytesPerLine(), colorSpace, qt_mac_bitmapInfoForImage(*image)); - - // Invert y axis - CGContextTranslateCTM(context, 0, image->height()); - CGContextScaleCTM(context, 1, -1); - - const qreal devicePixelRatio = image->devicePixelRatio(); - - if (devType == QInternal::Widget) { - // Set the clip rect which is an intersection of the system clip - // and the painter clip. To make matters more interesting these - // are in device pixels and device-independent pixels, respectively. - QRegion clip = painter->paintEngine()->systemClip(); // get system clip in device pixels - QTransform native = painter->deviceTransform(); // get device transform. dx/dy is in device pixels - - if (painter->hasClipping()) { - QRegion r = painter->clipRegion(); // get painter clip, which is in device-independent pixels - qt_mac_scale_region(&r, devicePixelRatio); // scale painter clip to device pixels - r.translate(native.dx(), native.dy()); - if (clip.isEmpty()) - clip = r; - else - clip &= r; - } - qt_mac_clip_cg(context, clip, 0); // clip in device pixels - - // Scale the context so that painting happens in device-independent pixels - CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); - CGContextTranslateCTM(context, native.dx() / devicePixelRatio, native.dy() / devicePixelRatio); - } else { - // Scale to paint in device-independent pixels - CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); + if (paintEngine->type() != QPaintEngine::Raster) { + qWarning() << "QMacCGContext:: Unsupported paint engine type" << paintEngine->type(); + return; + } + + // The raster paint engine always operates on a QImage + Q_ASSERT(paintEngine->paintDevice()->devType() == QInternal::Image); + + // On behalf of one of these supported painter devices + switch (int painterDeviceType = painter->device()->devType()) { + case QInternal::Pixmap: + case QInternal::Image: + case QInternal::Widget: + break; + default: + qWarning() << "QMacCGContext:: Unsupported paint device type" << painterDeviceType; + return; + } + + // Applying the clip is so entangled with the rest of the context setup + // that for simplicity we just pass in the painter. + initialize(static_cast<const QImage *>(paintEngine->paintDevice()), painter); +} + +void QMacCGContext::initialize(const QImage *image, QPainter *painter) +{ + QCFType<CGColorSpaceRef> colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); + context = CGBitmapContextCreate((void *)image->bits(), image->width(), image->height(), 8, + image->bytesPerLine(), colorSpace, qt_mac_bitmapInfoForImage(*image)); + + // Invert y axis + CGContextTranslateCTM(context, 0, image->height()); + CGContextScaleCTM(context, 1, -1); + + const qreal devicePixelRatio = image->devicePixelRatio(); + + if (painter && painter->device()->devType() == QInternal::Widget) { + // Set the clip rect which is an intersection of the system clip and the painter clip + QRegion clip = painter->paintEngine()->systemClip(); + QTransform deviceTransform = painter->deviceTransform(); + + if (painter->hasClipping()) { + // To make matters more interesting the painter clip is in device-independent pixels, + // so we need to scale it to match the device-pixels of the system clip. + QRegion painterClip = painter->clipRegion(); + qt_mac_scale_region(&painterClip, devicePixelRatio); + + painterClip.translate(deviceTransform.dx(), deviceTransform.dy()); + + if (clip.isEmpty()) + clip = painterClip; + else + clip &= painterClip; } - } else { - qDebug() << "QMacCGContext:: Unsupported painter devtype type" << devType; + + qt_mac_clip_cg(context, clip, 0); + + CGContextTranslateCTM(context, deviceTransform.dx(), deviceTransform.dy()); } + + // Scale the context so that painting happens in device-independent pixels + CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); } QT_END_NAMESPACE diff --git a/src/gui/painting/qcoregraphics_p.h b/src/gui/painting/qcoregraphics_p.h index 868c2b08b5..ba2cde8325 100644 --- a/src/gui/painting/qcoregraphics_p.h +++ b/src/gui/painting/qcoregraphics_p.h @@ -51,6 +51,8 @@ // We mean it. // +#include <QtCore/private/qcore_mac_p.h> + #include <QtGui/private/qtguiglobal_p.h> #include <QtGui/qregion.h> #include <QtGui/qpalette.h> @@ -89,38 +91,16 @@ Q_GUI_EXPORT QBrush qt_mac_toQBrush(CGColorRef color); class Q_GUI_EXPORT QMacCGContext { public: - inline QMacCGContext() { context = 0; } + QMacCGContext() = default; QMacCGContext(QPaintDevice *pdev); QMacCGContext(QPainter *p); - inline QMacCGContext(CGContextRef cg, bool takeOwnership = false) { - context = cg; - if (!takeOwnership) - CGContextRetain(context); - } - inline QMacCGContext(const QMacCGContext ©) : context(0) { *this = copy; } - inline ~QMacCGContext() { - if (context) - CGContextRelease(context); - } - inline bool isNull() const { return context; } - inline operator CGContextRef() { return context; } - inline QMacCGContext &operator=(const QMacCGContext ©) { - if (context) - CGContextRelease(context); - context = copy.context; - CGContextRetain(context); - return *this; - } - inline QMacCGContext &operator=(CGContextRef cg) { - if (context) - CGContextRelease(context); - context = cg; - CGContextRetain(context); //we do not take ownership - return *this; - } + + operator CGContextRef() { return context; } private: - CGContextRef context; + void initialize(QPaintDevice *paintDevice); + void initialize(const QImage *, QPainter *painter = nullptr); + QCFType<CGContextRef> context; }; QT_END_NAMESPACE diff --git a/src/gui/painting/qdrawhelper_sse4.cpp b/src/gui/painting/qdrawhelper_sse4.cpp index 5e8acc332d..68d887ae6d 100644 --- a/src/gui/painting/qdrawhelper_sse4.cpp +++ b/src/gui/painting/qdrawhelper_sse4.cpp @@ -156,6 +156,17 @@ template<bool RGBA, bool RGBx> static inline void convertARGBFromARGB32PM_sse4(uint *buffer, const uint *src, int count) { int i = 0; + if ((_MM_GET_EXCEPTION_MASK() & _MM_MASK_INVALID) == 0) { + for (; i < count; ++i) { + uint v = qUnpremultiply(src[i]); + if (RGBx) + v = 0xff000000 | v; + if (RGBA) + v = ARGB2RGBA(v); + buffer[i] = v; + } + return; + } const __m128i alphaMask = _mm_set1_epi32(0xff000000); const __m128i rgbaMask = _mm_setr_epi8(2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15); const __m128i zero = _mm_setzero_si128(); @@ -223,6 +234,13 @@ template<bool RGBA> static inline void convertARGBFromRGBA64PM_sse4(uint *buffer, const QRgba64 *src, int count) { int i = 0; + if ((_MM_GET_EXCEPTION_MASK() & _MM_MASK_INVALID) == 0) { + for (; i < count; ++i) { + const QRgba64 v = src[i].unpremultiplied(); + buffer[i] = RGBA ? toRgba8888(v) : toArgb32(v); + } + return; + } const __m128i alphaMask = _mm_set1_epi64x(qint64(Q_UINT64_C(0xffff) << 48)); const __m128i alphaMask32 = _mm_set1_epi32(0xff000000); const __m128i rgbaMask = _mm_setr_epi8(2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15); diff --git a/src/gui/painting/qpagelayout.h b/src/gui/painting/qpagelayout.h index faf0827c1a..7ee0ce7a76 100644 --- a/src/gui/painting/qpagelayout.h +++ b/src/gui/painting/qpagelayout.h @@ -82,9 +82,7 @@ public: const QMarginsF &margins, Unit units = Point, const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0)); QPageLayout(const QPageLayout &other); -#ifdef Q_COMPILER_RVALUE_REFS QPageLayout &operator=(QPageLayout &&other) noexcept { swap(other); return *this; } -#endif QPageLayout &operator=(const QPageLayout &other); ~QPageLayout(); diff --git a/src/gui/painting/qpagesize.h b/src/gui/painting/qpagesize.h index a2ea691677..133274760f 100644 --- a/src/gui/painting/qpagesize.h +++ b/src/gui/painting/qpagesize.h @@ -236,9 +236,7 @@ public: const QString &name = QString(), SizeMatchPolicy matchPolicy = FuzzyMatch); QPageSize(const QPageSize &other); -#ifdef Q_COMPILER_RVALUE_REFS QPageSize &operator=(QPageSize &&other) noexcept { swap(other); return *this; } -#endif QPageSize &operator=(const QPageSize &other); ~QPageSize(); diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index b0dec5cf78..85ddff53db 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -767,7 +767,7 @@ void QRasterPaintEngine::updatePen(const QPen &pen) s->flags.fast_pen = pen_style > Qt::NoPen && s->penData.blend && ((cosmetic && penWidth <= 1) - || (!cosmetic && s->flags.tx_noshear && penWidth * s->txscale <= 1)); + || (!cosmetic && (s->flags.tx_noshear || !s->flags.antialiased) && penWidth * s->txscale <= 1)); s->flags.non_complex_pen = qpen_capStyle(s->lastPen) <= Qt::SquareCap && s->flags.tx_noshear; @@ -898,7 +898,7 @@ void QRasterPaintEngine::renderHintsChanged() QRasterPaintEngineState *s = state(); #ifdef QT_DEBUG_DRAW - qDebug() << "QRasterPaintEngine::renderHintsChanged()" << hex << s->renderHints; + qDebug() << "QRasterPaintEngine::renderHintsChanged()" << Qt::hex << s->renderHints; #endif bool was_aa = s->flags.antialiased; @@ -1745,7 +1745,7 @@ void QRasterPaintEngine::fill(const QVectorPath &path, const QBrush &brush) QRectF rf = path.controlPointRect(); qDebug() << "QRasterPaintEngine::fill(): " << "size=" << path.elementCount() - << ", hints=" << hex << path.hints() + << ", hints=" << Qt::hex << path.hints() << rf << brush; #endif diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h index 500e0fae54..ec4a35087a 100644 --- a/src/gui/painting/qpaintengine_raster_p.h +++ b/src/gui/painting/qpaintengine_raster_p.h @@ -434,7 +434,7 @@ public: QImage::Format prepare(QImage *image); - uchar *scanLine(int y) { Q_ASSERT(y>=0); Q_ASSERT(y<m_height); return m_buffer + y * bytes_per_line; } + uchar *scanLine(int y) { Q_ASSERT(y>=0); Q_ASSERT(y<m_height); return m_buffer + y * qsizetype(bytes_per_line); } int width() const { return m_width; } int height() const { return m_height; } diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp index 22d3fb3001..8314e8bc8a 100644 --- a/src/gui/painting/qpaintengineex.cpp +++ b/src/gui/painting/qpaintengineex.cpp @@ -140,7 +140,7 @@ QDebug Q_GUI_EXPORT &operator<<(QDebug &s, const QVectorPath &path) QDebugStateSaver saver(s); QRectF rf = path.controlPointRect(); s << "QVectorPath(size:" << path.elementCount() - << " hints:" << hex << path.hints() + << " hints:" << Qt::hex << path.hints() << rf << ')'; return s; } diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index 649cfd554b..42872359d7 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -75,7 +75,7 @@ struct QPainterPathPrivateDeleter { static inline void cleanup(QPainterPathPrivate *d) { - // note - we must up-cast to QPainterPathData since QPainterPathPrivate + // note - we must downcast to QPainterPathData since QPainterPathPrivate // has a non-virtual destructor! if (d && !d->ref.deref()) delete static_cast<QPainterPathData *>(d); @@ -3499,8 +3499,7 @@ void QPainterPath::setDirty(bool dirty) { d_func()->dirtyBounds = dirty; d_func()->dirtyControlBounds = dirty; - delete d_func()->pathConverter; - d_func()->pathConverter = 0; + d_func()->pathConverter.reset(); d_func()->convex = false; } @@ -3576,10 +3575,10 @@ void QPainterPath::computeControlPointRect() const #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug s, const QPainterPath &p) { - s.nospace() << "QPainterPath: Element count=" << p.elementCount() << endl; + s.nospace() << "QPainterPath: Element count=" << p.elementCount() << Qt::endl; const char *types[] = {"MoveTo", "LineTo", "CurveTo", "CurveToData"}; for (int i=0; i<p.elementCount(); ++i) { - s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ')' << endl; + s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ')' << Qt::endl; } return s; diff --git a/src/gui/painting/qpainterpath.h b/src/gui/painting/qpainterpath.h index 2785669260..ed5be667b7 100644 --- a/src/gui/painting/qpainterpath.h +++ b/src/gui/painting/qpainterpath.h @@ -92,10 +92,8 @@ public: explicit QPainterPath(const QPointF &startPoint); QPainterPath(const QPainterPath &other); QPainterPath &operator=(const QPainterPath &other); -#ifdef Q_COMPILER_RVALUE_REFS inline QPainterPath &operator=(QPainterPath &&other) noexcept { qSwap(d_ptr, other.d_ptr); return *this; } -#endif ~QPainterPath(); inline void swap(QPainterPath &other) noexcept { d_ptr.swap(other.d_ptr); } diff --git a/src/gui/painting/qpainterpath_p.h b/src/gui/painting/qpainterpath_p.h index 98056483bc..4eb541ec65 100644 --- a/src/gui/painting/qpainterpath_p.h +++ b/src/gui/painting/qpainterpath_p.h @@ -62,8 +62,11 @@ #include <private/qvectorpath_p.h> #include <private/qstroker_p.h> +#include <memory> + QT_BEGIN_NAMESPACE +// ### Qt 6: merge with QPainterPathData class QPainterPathPrivate { public: @@ -80,7 +83,19 @@ public: friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); #endif - QPainterPathPrivate() : ref(1) {} + QPainterPathPrivate() noexcept + : ref(1) + { + } + + QPainterPathPrivate(const QPainterPathPrivate &other) noexcept + : ref(1), + elements(other.elements) + { + } + + QPainterPathPrivate &operator=(const QPainterPathPrivate &) = delete; + ~QPainterPathPrivate() = default; private: QAtomicInt ref; @@ -166,30 +181,30 @@ public: QPainterPathData() : cStart(0), fillRule(Qt::OddEvenFill), + require_moveTo(false), dirtyBounds(false), dirtyControlBounds(false), + convex(false), pathConverter(nullptr) { - require_moveTo = false; - convex = false; } QPainterPathData(const QPainterPathData &other) : - QPainterPathPrivate(), cStart(other.cStart), fillRule(other.fillRule), + QPainterPathPrivate(other), + cStart(other.cStart), + fillRule(other.fillRule), bounds(other.bounds), controlBounds(other.controlBounds), + require_moveTo(false), dirtyBounds(other.dirtyBounds), dirtyControlBounds(other.dirtyControlBounds), convex(other.convex), pathConverter(nullptr) { - require_moveTo = false; - elements = other.elements; } - ~QPainterPathData() { - delete pathConverter; - } + QPainterPathData &operator=(const QPainterPathData &) = delete; + ~QPainterPathData() = default; inline bool isClosed() const; inline void close(); @@ -198,7 +213,7 @@ public: const QVectorPath &vectorPath() { if (!pathConverter) - pathConverter = new QVectorPathConverter(elements, fillRule, convex); + pathConverter.reset(new QVectorPathConverter(elements, fillRule, convex)); return pathConverter->path; } @@ -213,7 +228,7 @@ public: uint dirtyControlBounds : 1; uint convex : 1; - QVectorPathConverter *pathConverter; + std::unique_ptr<QVectorPathConverter> pathConverter; }; @@ -307,8 +322,7 @@ inline void QPainterPathData::clear() dirtyControlBounds = false; convex = false; - delete pathConverter; - pathConverter = nullptr; + pathConverter.reset(); } #define KAPPA qreal(0.5522847498) diff --git a/src/gui/painting/qpen.h b/src/gui/painting/qpen.h index 884ec8cdfa..10b11d1d85 100644 --- a/src/gui/painting/qpen.h +++ b/src/gui/painting/qpen.h @@ -70,12 +70,10 @@ public: ~QPen(); QPen &operator=(const QPen &pen) noexcept; -#ifdef Q_COMPILER_RVALUE_REFS QPen(QPen &&other) noexcept : d(other.d) { other.d = nullptr; } QPen &operator=(QPen &&other) noexcept { qSwap(d, other.d); return *this; } -#endif void swap(QPen &other) noexcept { qSwap(d, other.d); } Qt::PenStyle style() const; diff --git a/src/gui/painting/qpolygon.h b/src/gui/painting/qpolygon.h index 118861c0f2..93fab55aa1 100644 --- a/src/gui/painting/qpolygon.h +++ b/src/gui/painting/qpolygon.h @@ -60,16 +60,12 @@ public: inline ~QPolygon() {} inline explicit QPolygon(int size); inline /*implicit*/ QPolygon(const QVector<QPoint> &v) : QVector<QPoint>(v) {} -#ifdef Q_COMPILER_RVALUE_REFS /*implicit*/ QPolygon(QVector<QPoint> &&v) noexcept : QVector<QPoint>(std::move(v)) {} -#endif QPolygon(const QRect &r, bool closed=false); QPolygon(int nPoints, const int *points); QPolygon(const QPolygon &other) : QVector<QPoint>(other) {} -#ifdef Q_COMPILER_RVALUE_REFS QPolygon(QPolygon &&other) noexcept : QVector<QPoint>(std::move(other)) {} QPolygon &operator=(QPolygon &&other) noexcept { swap(other); return *this; } -#endif QPolygon &operator=(const QPolygon &other) { QVector<QPoint>::operator=(other); return *this; } void swap(QPolygon &other) noexcept { QVector<QPoint>::swap(other); } // prevent QVector<QPoint><->QPolygon swaps @@ -145,16 +141,12 @@ public: inline ~QPolygonF() {} inline explicit QPolygonF(int size); inline /*implicit*/ QPolygonF(const QVector<QPointF> &v) : QVector<QPointF>(v) {} -#ifdef Q_COMPILER_RVALUE_REFS /* implicit */ QPolygonF(QVector<QPointF> &&v) noexcept : QVector<QPointF>(std::move(v)) {} -#endif QPolygonF(const QRectF &r); /*implicit*/ QPolygonF(const QPolygon &a); inline QPolygonF(const QPolygonF &a) : QVector<QPointF>(a) {} -#ifdef Q_COMPILER_RVALUE_REFS QPolygonF(QPolygonF &&other) noexcept : QVector<QPointF>(std::move(other)) {} QPolygonF &operator=(QPolygonF &&other) noexcept { swap(other); return *this; } -#endif QPolygonF &operator=(const QPolygonF &other) { QVector<QPointF>::operator=(other); return *this; } inline void swap(QPolygonF &other) { QVector<QPointF>::swap(other); } // prevent QVector<QPointF><->QPolygonF swaps diff --git a/src/gui/painting/qregion.h b/src/gui/painting/qregion.h index 9b6b25d743..54de916198 100644 --- a/src/gui/painting/qregion.h +++ b/src/gui/painting/qregion.h @@ -74,10 +74,8 @@ public: QRegion(const QBitmap &bitmap); ~QRegion(); QRegion &operator=(const QRegion &); -#ifdef Q_COMPILER_RVALUE_REFS inline QRegion &operator=(QRegion &&other) noexcept { qSwap(d, other.d); return *this; } -#endif inline void swap(QRegion &other) noexcept { qSwap(d, other.d); } bool isEmpty() const; bool isNull() const; diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp index f8f8d72d14..5b6990e667 100644 --- a/src/gui/painting/qstroker.cpp +++ b/src/gui/painting/qstroker.cpp @@ -456,7 +456,7 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine QLineF prevLine(qt_fixed_to_real(m_back2X), qt_fixed_to_real(m_back2Y), qt_fixed_to_real(m_back1X), qt_fixed_to_real(m_back1Y)); QPointF isect; - QLineF::IntersectType type = prevLine.intersect(nextLine, &isect); + QLineF::IntersectionType type = prevLine.intersects(nextLine, &isect); if (join == FlatJoin) { QLineF shortCut(prevLine.p2(), nextLine.p1()); @@ -1148,6 +1148,8 @@ void QDashStroker::processCurrentSubpath() QSubpathFlatIterator it(&m_elements, m_dashThreshold); qfixed2d prev = it.next(); + if (!prev.isFinite()) + return; bool clipping = !m_clip_rect.isEmpty(); qfixed2d move_to_pos = prev; @@ -1163,6 +1165,8 @@ void QDashStroker::processCurrentSubpath() bool hasMoveTo = false; while (it.hasNext()) { QStrokerOps::Element e = it.next(); + if (!qfixed2d(e).isFinite()) + continue; Q_ASSERT(e.isLineTo()); cline = QLineF(qt_fixed_to_real(prev.x), diff --git a/src/gui/painting/qstroker_p.h b/src/gui/painting/qstroker_p.h index 722a0904f3..f107b6eb20 100644 --- a/src/gui/painting/qstroker_p.h +++ b/src/gui/painting/qstroker_p.h @@ -104,6 +104,7 @@ struct qfixed2d qfixed x; qfixed y; + bool isFinite() { return qIsFinite(x) && qIsFinite(y); } bool operator==(const qfixed2d &other) const { return qFuzzyCompare(x, other.x) && qFuzzyCompare(y, other.y); } }; diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 6110a548fd..7696da7d45 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -265,7 +265,9 @@ QTransform::QTransform() , m_13(0), m_23(0), m_33(1) , m_type(TxNone) , m_dirty(TxNone) +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) , d(nullptr) +#endif { } @@ -284,7 +286,9 @@ QTransform::QTransform(qreal h11, qreal h12, qreal h13, , m_13(h13), m_23(h23), m_33(h33) , m_type(TxNone) , m_dirty(TxProject) +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) , d(nullptr) +#endif { } @@ -301,7 +305,9 @@ QTransform::QTransform(qreal h11, qreal h12, qreal h21, , m_13(0), m_23(0), m_33(1) , m_type(TxNone) , m_dirty(TxShear) +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) , d(nullptr) +#endif { } @@ -317,7 +323,9 @@ QTransform::QTransform(const QMatrix &mtx) m_13(0), m_23(0), m_33(1) , m_type(TxNone) , m_dirty(TxShear) +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) , d(nullptr) +#endif { } diff --git a/src/gui/painting/qtransform.h b/src/gui/painting/qtransform.h index 18c53f4a6f..b220770144 100644 --- a/src/gui/painting/qtransform.h +++ b/src/gui/painting/qtransform.h @@ -176,7 +176,9 @@ private: , m_13(h13), m_23(h23), m_33(h33) , m_type(TxNone) , m_dirty(TxProject) +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) , d(nullptr) +#endif { } inline QTransform(bool) @@ -184,7 +186,9 @@ private: , m_13(0), m_23(0), m_33(1) , m_type(TxNone) , m_dirty(TxNone) +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) , d(nullptr) +#endif { } inline TransformationType inline_type() const; diff --git a/src/gui/painting/qtriangulator_p.h b/src/gui/painting/qtriangulator_p.h index 8f043fc925..177e5e66ed 100644 --- a/src/gui/painting/qtriangulator_p.h +++ b/src/gui/painting/qtriangulator_p.h @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE -class Q_GUI_EXPORT QVertexIndexVector +class QVertexIndexVector { public: enum Type { @@ -93,17 +93,6 @@ public: return indices16.size(); } - inline QVertexIndexVector &operator = (const QVertexIndexVector &other) - { - if (t == UnsignedInt) - indices32 = other.indices32; - else - indices16 = other.indices16; - - t = other.t; - return *this; - } - private: Type t; @@ -111,23 +100,15 @@ private: QVector<quint16> indices16; }; -struct Q_GUI_EXPORT QTriangleSet +struct QTriangleSet { - inline QTriangleSet() { } - inline QTriangleSet(const QTriangleSet &other) : vertices(other.vertices), indices(other.indices) { } - QTriangleSet &operator = (const QTriangleSet &other) {vertices = other.vertices; indices = other.indices; return *this;} - // The vertices of a triangle are given by: (x[i[n]], y[i[n]]), (x[j[n]], y[j[n]]), (x[k[n]], y[k[n]]), n = 0, 1, ... QVector<qreal> vertices; // [x[0], y[0], x[1], y[1], x[2], ...] QVertexIndexVector indices; // [i[0], j[0], k[0], i[1], j[1], k[1], i[2], ...] }; -struct Q_GUI_EXPORT QPolylineSet +struct QPolylineSet { - inline QPolylineSet() { } - inline QPolylineSet(const QPolylineSet &other) : vertices(other.vertices), indices(other.indices) { } - QPolylineSet &operator = (const QPolylineSet &other) {vertices = other.vertices; indices = other.indices; return *this;} - QVector<qreal> vertices; // [x[0], y[0], x[1], y[1], x[2], ...] QVertexIndexVector indices; // End of polyline is marked with -1. }; |