diff options
Diffstat (limited to 'src/gui/painting/qpainter_p.h')
-rw-r--r-- | src/gui/painting/qpainter_p.h | 110 |
1 files changed, 42 insertions, 68 deletions
diff --git a/src/gui/painting/qpainter_p.h b/src/gui/painting/qpainter_p.h index 870381d48a..0ddd78fb2a 100644 --- a/src/gui/painting/qpainter_p.h +++ b/src/gui/painting/qpainter_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QPAINTER_P_H #define QPAINTER_P_H @@ -65,6 +29,9 @@ #include <private/qpen_p.h> +#include <memory> +#include <stack> + QT_BEGIN_NAMESPACE class QPaintEngine; @@ -100,7 +67,7 @@ inline bool qbrush_has_transform(const QBrush &b) { return data_ptr(b)->transfor class QPainterClipInfo { public: - QPainterClipInfo() {} // for QVector, don't use + QPainterClipInfo() { } // for QList, don't use enum ClipType { RegionClip, PathClip, RectClip, RectFClip }; QPainterClipInfo(const QPainterPath &p, Qt::ClipOperation op, const QTransform &m) : @@ -138,7 +105,7 @@ public: }; -Q_DECLARE_TYPEINFO(QPainterClipInfo, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(QPainterClipInfo, Q_RELOCATABLE_TYPE); class Q_GUI_EXPORT QPainterState : public QPaintEngineState { @@ -158,7 +125,7 @@ public: QPainterPath clipPath; Qt::ClipOperation clipOperation = Qt::NoClip; QPainter::RenderHints renderHints; - QVector<QPainterClipInfo> clipInfo; // ### Make me smaller and faster to copy around... + QList<QPainterClipInfo> clipInfo; // ### Make me smaller and faster to copy around... QTransform worldMatrix; // World transformation matrix, not window and viewport QTransform matrix; // Complete transformation matrix, QTransform redirectionMatrix; @@ -191,28 +158,29 @@ class QPainterPrivate { Q_DECLARE_PUBLIC(QPainter) public: - QPainterPrivate(QPainter *painter) - : q_ptr(painter), d_ptrs(nullptr), state(nullptr), dummyState(nullptr), txinv(0), inDestructor(false), d_ptrs_size(0), - refcount(1), device(nullptr), original_device(nullptr), helper_device(nullptr), engine(nullptr), emulationEngine(nullptr), - extended(nullptr) - { - } - + explicit QPainterPrivate(QPainter *painter); ~QPainterPrivate(); QPainter *q_ptr; - QPainterPrivate **d_ptrs; - - QPainterState *state; - QVarLengthArray<QPainterState *, 8> states; + // Allocate space for 4 d-pointers (enough for up to 4 sub-sequent + // redirections within the same paintEvent(), which should be enough + // in 99% of all cases). E.g: A renders B which renders C which renders D. + static constexpr qsizetype NDPtrs = 4; + QVarLengthArray<QPainterPrivate*, NDPtrs> d_ptrs; + + std::unique_ptr<QPainterState> state; + template <typename T, std::size_t N = 8> + struct SmallStack : std::stack<T, QVarLengthArray<T, N>> { + void clear() { this->c.clear(); } + }; + SmallStack<std::unique_ptr<QPainterState>> savedStates; - mutable QPainterDummyState *dummyState; + mutable std::unique_ptr<QPainterDummyState> dummyState; QTransform invMatrix; uint txinv:1; uint inDestructor : 1; - uint d_ptrs_size; - uint refcount; + uint refcount = 1; enum DrawOperation { StrokeDraw = 0x1, FillDraw = 0x2, @@ -221,13 +189,14 @@ public: QPainterDummyState *fakeState() const { if (!dummyState) - dummyState = new QPainterDummyState(); - return dummyState; + dummyState = std::make_unique<QPainterDummyState>(); + return dummyState.get(); } void updateEmulationSpecifier(QPainterState *s); void updateStateImpl(QPainterState *state); void updateState(QPainterState *state); + void updateState(std::unique_ptr<QPainterState> &state) { updateState(state.get()); } void draw_helper(const QPainterPath &path, DrawOperation operation = StrokeAndFillDraw); void drawStretchedGradient(const QPainterPath &path, DrawOperation operation); @@ -247,7 +216,7 @@ public: static QPainterPrivate *get(QPainter *painter) { - return painter->d_ptr.data(); + return painter->d_ptr.get(); } QTransform viewTransform() const; @@ -257,12 +226,21 @@ public: void detachPainterPrivate(QPainter *q); void initFrom(const QPaintDevice *device); - QPaintDevice *device; - QPaintDevice *original_device; - QPaintDevice *helper_device; - QPaintEngine *engine; - QEmulationPaintEngine *emulationEngine; - QPaintEngineEx *extended; + QPaintDevice *device = nullptr; + QPaintDevice *original_device = nullptr; + QPaintDevice *helper_device = nullptr; + + struct QPaintEngineDestructor { + void operator()(QPaintEngine *pe) const noexcept + { + if (pe && pe->autoDestruct()) + delete pe; + } + }; + std::unique_ptr<QPaintEngine, QPaintEngineDestructor> engine; + + std::unique_ptr<QEmulationPaintEngine> emulationEngine; + QPaintEngineEx *extended = nullptr; QBrush colorBrush; // for fill with solid color }; @@ -270,10 +248,6 @@ Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, Q QString qt_generate_brush_key(const QBrush &brush); -inline bool qt_pen_is_cosmetic(const QPen &pen, QPainter::RenderHints hints) -{ - return pen.isCosmetic() || (const_cast<QPen &>(pen).data_ptr()->defaultWidth && (hints & QPainter::Qt4CompatiblePainting)); -} QT_END_NAMESPACE |