Merge QPainterPathPrivate and QPainterPathData

As per ### Qt 6 comment, and the code that never allocated QPainterPathPrivate.

Change-Id: I553e3559fdb2a675f37cdd9855462a2f22ef84c6
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
bb10
Volker Hilsheimer 2020-09-02 13:22:55 +02:00
parent 00a5629d8d
commit c87b626d70
3 changed files with 70 additions and 93 deletions

View File

@ -92,10 +92,8 @@ struct QPainterPathPrivateDeleter
{
static inline void cleanup(QPainterPathPrivate *d)
{
// note - we must downcast to QPainterPathData since QPainterPathPrivate
// has a non-virtual destructor!
if (d && !d->ref.deref())
delete static_cast<QPainterPathData *>(d);
delete d;
}
};
@ -569,7 +567,7 @@ QPainterPath::QPainterPath(const QPainterPath &other)
*/
QPainterPath::QPainterPath(const QPointF &startPoint)
: d_ptr(new QPainterPathData)
: d_ptr(new QPainterPathPrivate)
{
Element e = { startPoint.x(), startPoint.y(), MoveToElement };
d_func()->elements << e;
@ -587,7 +585,7 @@ void QPainterPath::detach()
*/
void QPainterPath::detach_helper()
{
QPainterPathPrivate *data = new QPainterPathData(*d_func());
QPainterPathPrivate *data = new QPainterPathPrivate(*d_func());
d_ptr.reset(data);
}
@ -596,7 +594,7 @@ void QPainterPath::detach_helper()
*/
void QPainterPath::ensureData_helper()
{
QPainterPathPrivate *data = new QPainterPathData;
QPainterPathPrivate *data = new QPainterPathPrivate;
data->elements.reserve(16);
QPainterPath::Element e = { 0, 0, QPainterPath::MoveToElement };
data->elements << e;
@ -753,7 +751,7 @@ void QPainterPath::moveTo(const QPointF &p)
ensureData();
detach();
QPainterPathData *d = d_func();
QPainterPathPrivate *d = d_func();
Q_ASSERT(!d->elements.isEmpty());
d->require_moveTo = false;
@ -803,7 +801,7 @@ void QPainterPath::lineTo(const QPointF &p)
ensureData();
detach();
QPainterPathData *d = d_func();
QPainterPathPrivate *d = d_func();
Q_ASSERT(!d->elements.isEmpty());
d->maybeMoveTo();
if (p == QPointF(d->elements.constLast()))
@ -862,7 +860,7 @@ void QPainterPath::cubicTo(const QPointF &c1, const QPointF &c2, const QPointF &
ensureData();
detach();
QPainterPathData *d = d_func();
QPainterPathPrivate *d = d_func();
Q_ASSERT(!d->elements.isEmpty());
@ -1288,7 +1286,7 @@ void QPainterPath::addPath(const QPainterPath &other)
ensureData();
detach();
QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func());
QPainterPathPrivate *d = d_func();
// Remove last moveto so we don't get multiple moveto's
if (d->elements.constLast().type == MoveToElement)
d->elements.remove(d->elements.size()-1);
@ -1319,7 +1317,7 @@ void QPainterPath::connectPath(const QPainterPath &other)
ensureData();
detach();
QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func());
QPainterPathPrivate *d = d_func();
// Remove last moveto so we don't get multiple moveto's
if (d->elements.constLast().type == MoveToElement)
d->elements.remove(d->elements.size()-1);
@ -1509,7 +1507,7 @@ QRectF QPainterPath::boundingRect() const
{
if (!d_ptr)
return QRectF();
QPainterPathData *d = d_func();
QPainterPathPrivate *d = d_func();
if (d->dirtyBounds)
computeBoundingRect();
@ -1530,7 +1528,7 @@ QRectF QPainterPath::controlPointRect() const
{
if (!d_ptr)
return QRectF();
QPainterPathData *d = d_func();
QPainterPathPrivate *d = d_func();
if (d->dirtyControlBounds)
computeControlPointRect();
@ -1857,7 +1855,7 @@ bool QPainterPath::contains(const QPointF &pt) const
if (isEmpty() || !controlPointRect().contains(pt))
return false;
QPainterPathData *d = d_func();
QPainterPathPrivate *d = d_func();
int winding_number = 0;
@ -2316,8 +2314,8 @@ static inline bool epsilonCompare(const QPointF &a, const QPointF &b, const QSiz
bool QPainterPath::operator==(const QPainterPath &path) const
{
QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func());
QPainterPathData *other_d = path.d_func();
QPainterPathPrivate *d = d_func();
QPainterPathPrivate *other_d = path.d_func();
if (other_d == d) {
return true;
} else if (!d || !other_d) {
@ -3356,7 +3354,7 @@ void QPainterPath::setDirty(bool dirty)
void QPainterPath::computeBoundingRect() const
{
QPainterPathData *d = d_func();
QPainterPathPrivate *d = d_func();
d->dirtyBounds = false;
if (!d_ptr) {
d->bounds = QRect();
@ -3403,7 +3401,7 @@ void QPainterPath::computeBoundingRect() const
void QPainterPath::computeControlPointRect() const
{
QPainterPathData *d = d_func();
QPainterPathPrivate *d = d_func();
d->dirtyControlBounds = false;
if (!d_ptr) {
d->controlBounds = QRect();

View File

@ -54,7 +54,6 @@ QT_BEGIN_NAMESPACE
class QFont;
class QPainterPathPrivate;
struct QPainterPathPrivateDeleter;
class QPainterPathData;
class QPainterPathStrokerPrivate;
class QPen;
class QPolygonF;
@ -209,9 +208,8 @@ private:
void computeBoundingRect() const;
void computeControlPointRect() const;
QPainterPathData *d_func() const { return reinterpret_cast<QPainterPathData *>(d_ptr.data()); }
QPainterPathPrivate *d_func() const { return d_ptr.data(); }
friend class QPainterPathData;
friend class QPainterPathStroker;
friend class QPainterPathStrokerPrivate;
friend class QTransform;

View File

@ -66,51 +66,6 @@
QT_BEGIN_NAMESPACE
// ### Qt 6: merge with QPainterPathData
class QPainterPathPrivate
{
public:
friend class QPainterPath;
friend class QPainterPathData;
friend class QPainterPathStroker;
friend class QPainterPathStrokerPrivate;
friend class QTransform;
friend class QVectorPath;
friend struct QPainterPathPrivateDeleter;
#ifndef QT_NO_DATASTREAM
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
#endif
QPainterPathPrivate() noexcept
: ref(1)
{
}
QPainterPathPrivate(const QPainterPathPrivate &other) noexcept
: ref(1),
elements(other.elements)
{
}
QPainterPathPrivate &operator=(const QPainterPathPrivate &) = delete;
~QPainterPathPrivate() = default;
private:
QAtomicInt ref;
QList<QPainterPath::Element> elements;
};
class QPainterPathStrokerPrivate
{
public:
QPainterPathStrokerPrivate();
QStroker stroker;
QList<qfixed> dashPattern;
qreal dashOffset;
};
class QPolygonF;
class QVectorPathConverter;
@ -173,36 +128,49 @@ private:
Q_DISABLE_COPY_MOVE(QVectorPathConverter)
};
class QPainterPathData : public QPainterPathPrivate
class QPainterPathPrivate
{
public:
QPainterPathData() :
cStart(0),
fillRule(Qt::OddEvenFill),
require_moveTo(false),
dirtyBounds(false),
dirtyControlBounds(false),
convex(false),
pathConverter(nullptr)
friend class QPainterPath;
friend class QPainterPathStroker;
friend class QPainterPathStrokerPrivate;
friend class QTransform;
friend class QVectorPath;
friend struct QPainterPathPrivateDeleter;
#ifndef QT_NO_DATASTREAM
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
#endif
QPainterPathPrivate() noexcept
: ref(1),
cStart(0),
fillRule(Qt::OddEvenFill),
require_moveTo(false),
dirtyBounds(false),
dirtyControlBounds(false),
convex(false),
pathConverter(nullptr)
{
}
QPainterPathData(const QPainterPathData &other) :
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)
QPainterPathPrivate(const QPainterPathPrivate &other) noexcept
: ref(1),
elements(other.elements),
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)
{
}
QPainterPathData &operator=(const QPainterPathData &) = delete;
~QPainterPathData() = default;
QPainterPathPrivate &operator=(const QPainterPathPrivate &) = delete;
~QPainterPathPrivate() = default;
inline bool isClosed() const;
inline void close();
@ -215,6 +183,10 @@ public:
return pathConverter->path;
}
private:
QAtomicInt ref;
QList<QPainterPath::Element> elements;
int cStart;
Qt::FillRule fillRule;
@ -229,12 +201,21 @@ public:
std::unique_ptr<QVectorPathConverter> pathConverter;
};
class QPainterPathStrokerPrivate
{
public:
QPainterPathStrokerPrivate();
QStroker stroker;
QList<qfixed> dashPattern;
qreal dashOffset;
};
inline const QPainterPath QVectorPath::convertToPainterPath() const
{
QPainterPath path;
path.ensureData();
QPainterPathData *data = path.d_func();
QPainterPathPrivate *data = path.d_func();
data->elements.reserve(m_count);
int index = 0;
data->elements[0].x = m_points[index++];
@ -270,14 +251,14 @@ inline const QPainterPath QVectorPath::convertToPainterPath() const
void Q_GUI_EXPORT qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length,
QPointF* startPoint, QPointF *endPoint);
inline bool QPainterPathData::isClosed() const
inline bool QPainterPathPrivate::isClosed() const
{
const QPainterPath::Element &first = elements.at(cStart);
const QPainterPath::Element &last = elements.last();
return first.x == last.x && first.y == last.y;
}
inline void QPainterPathData::close()
inline void QPainterPathPrivate::close()
{
Q_ASSERT(ref.loadRelaxed() == 1);
require_moveTo = true;
@ -294,7 +275,7 @@ inline void QPainterPathData::close()
}
}
inline void QPainterPathData::maybeMoveTo()
inline void QPainterPathPrivate::maybeMoveTo()
{
if (require_moveTo) {
QPainterPath::Element e = elements.last();
@ -304,7 +285,7 @@ inline void QPainterPathData::maybeMoveTo()
}
}
inline void QPainterPathData::clear()
inline void QPainterPathPrivate::clear()
{
Q_ASSERT(ref.loadRelaxed() == 1);