diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2019-09-04 12:50:37 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2019-09-12 12:39:33 +0200 |
commit | d1486e2982df9373a7e5816609eff066cac6eb52 (patch) | |
tree | dfcd03b04c1f3144c083fe9a64be19988b925f36 /src | |
parent | f567129bb514b5856c7d1320cdc4dd5a84a5b6e3 (diff) |
Simplify QColorSpacePrivate initialization
QColorVector and QColorMatrix are default-constructed following the
Qt philosophy of types always being well-defined. The corner-case where
we need uninitialized versions of these types for performance reasons
is handled explicitly.
Change-Id: I629334d1ffc63563ec9fd1298c623946e0799d1d
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/painting/qcolormatrix_p.h | 16 | ||||
-rw-r--r-- | src/gui/painting/qcolorspace.cpp | 8 | ||||
-rw-r--r-- | src/gui/painting/qcolorspace_p.h | 6 | ||||
-rw-r--r-- | src/gui/painting/qcolortransform.cpp | 12 |
4 files changed, 20 insertions, 22 deletions
diff --git a/src/gui/painting/qcolormatrix_p.h b/src/gui/painting/qcolormatrix_p.h index 70d2137119..edb2d32258 100644 --- a/src/gui/painting/qcolormatrix_p.h +++ b/src/gui/painting/qcolormatrix_p.h @@ -62,17 +62,16 @@ class QColorVector { public: QColorVector() = default; - Q_DECL_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) { } 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 - float _unused; + float x = 0.0f; // X, x or red + float y = 0.0f; // Y, y or green + float z = 0.0f; // Z, Y or blue + float _unused = 0.0f; friend inline bool operator==(const QColorVector &v1, const QColorVector &v2); friend inline bool operator!=(const QColorVector &v1, const QColorVector &v2); @@ -81,7 +80,6 @@ public: 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)) @@ -187,10 +185,6 @@ public: { r.z, g.z, b.z } }; } - static QColorMatrix null() - { - return { QColorVector::null(), QColorVector::null(), QColorVector::null() }; - } static QColorMatrix identity() { return { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }; diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp index 720c531e3f..937bb505c9 100644 --- a/src/gui/painting/qcolorspace.cpp +++ b/src/gui/painting/qcolorspace.cpp @@ -146,17 +146,11 @@ QColorMatrix QColorSpacePrimaries::toXyzMatrix() const } QColorSpacePrivate::QColorSpacePrivate() - : primaries(QColorSpace::Primaries::Custom) - , transferFunction(QColorSpace::TransferFunction::Custom) - , gamma(0.0f) - , whitePoint(QColorVector::null()) - , toXyz(QColorMatrix::null()) { } QColorSpacePrivate::QColorSpacePrivate(QColorSpace::NamedColorSpace namedColorSpace) : namedColorSpace(namedColorSpace) - , gamma(0.0f) { switch (namedColorSpace) { case QColorSpace::SRgb: @@ -282,7 +276,7 @@ void QColorSpacePrivate::initialize() void QColorSpacePrivate::setToXyzMatrix() { if (primaries == QColorSpace::Primaries::Custom) { - toXyz = QColorMatrix::null(); + toXyz = QColorMatrix(); whitePoint = QColorVector::D50(); return; } diff --git a/src/gui/painting/qcolorspace_p.h b/src/gui/painting/qcolorspace_p.h index c06681df6b..e7add19ed3 100644 --- a/src/gui/painting/qcolorspace_p.h +++ b/src/gui/painting/qcolorspace_p.h @@ -124,9 +124,9 @@ public: static constexpr QColorSpace::NamedColorSpace Unknown = QColorSpace::NamedColorSpace(0); QColorSpace::NamedColorSpace namedColorSpace = Unknown; - QColorSpace::Primaries primaries; - QColorSpace::TransferFunction transferFunction; - float gamma; + QColorSpace::Primaries primaries = QColorSpace::Primaries::Custom; + QColorSpace::TransferFunction transferFunction = QColorSpace::TransferFunction::Custom; + float gamma = 0.0f; QColorVector whitePoint; QColorTrc trc[3]; diff --git a/src/gui/painting/qcolortransform.cpp b/src/gui/painting/qcolortransform.cpp index 53fd1dfbaa..10ccefed74 100644 --- a/src/gui/painting/qcolortransform.cpp +++ b/src/gui/painting/qcolortransform.cpp @@ -612,6 +612,15 @@ static void storeOpaque(QRgba64 *dst, const QRgba64 *src, const QColorVector *bu static constexpr qsizetype WorkBlockSize = 256; +template <typename T, int Count = 1> +class QUninitialized +{ +public: + operator T*() { return reinterpret_cast<T *>(this); } +private: + alignas(T) char data[sizeof(T) * Count]; +}; + template<typename T> void QColorTransformPrivate::apply(T *dst, const T *src, qsizetype count, TransformFlags flags) const { @@ -623,7 +632,8 @@ void QColorTransformPrivate::apply(T *dst, const T *src, qsizetype count, Transf bool doApplyMatrix = (colorMatrix != QColorMatrix::identity()); - QColorVector buffer[WorkBlockSize]; + QUninitialized<QColorVector, WorkBlockSize> buffer; + qsizetype i = 0; while (i < count) { const qsizetype len = qMin(count - i, WorkBlockSize); |