QtBase  v6.3.1
qpainter_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QPAINTER_P_H
41 #define QPAINTER_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtCore/qvarlengtharray.h>
55 #include <QtGui/private/qtguiglobal_p.h>
56 #include "QtGui/qbrush.h"
57 #include "QtGui/qcolorspace.h"
58 #include "QtGui/qcolortransform.h"
59 #include "QtGui/qfont.h"
60 #include "QtGui/qpen.h"
61 #include "QtGui/qregion.h"
62 #include "QtGui/qpainter.h"
63 #include "QtGui/qpainterpath.h"
64 #include "QtGui/qpaintengine.h"
65 
66 #include <private/qpen_p.h>
67 
68 #include <memory>
69 #include <stack>
70 
72 
73 class QPaintEngine;
75 class QPaintEngineEx;
76 struct QFixedPoint;
77 
78 struct QTLWExtra;
79 
81  void *ptr;
82 };
83 
84 inline const void *data_ptr(const QTransform &t) { return (const DataPtrContainer *) &t; }
85 inline bool qtransform_fast_equals(const QTransform &a, const QTransform &b) { return data_ptr(a) == data_ptr(b); }
86 
87 // QPen inline functions...
88 inline QPen::DataPtr &data_ptr(const QPen &p) { return const_cast<QPen &>(p).data_ptr(); }
89 inline bool qpen_fast_equals(const QPen &a, const QPen &b) { return data_ptr(a) == data_ptr(b); }
90 inline QBrush qpen_brush(const QPen &p) { return data_ptr(p)->brush; }
91 inline qreal qpen_widthf(const QPen &p) { return data_ptr(p)->width; }
92 inline Qt::PenStyle qpen_style(const QPen &p) { return data_ptr(p)->style; }
93 inline Qt::PenCapStyle qpen_capStyle(const QPen &p) { return data_ptr(p)->capStyle; }
94 inline Qt::PenJoinStyle qpen_joinStyle(const QPen &p) { return data_ptr(p)->joinStyle; }
95 
96 // QBrush inline functions...
97 inline QBrush::DataPtr &data_ptr(const QBrush &p) { return const_cast<QBrush &>(p).data_ptr(); }
98 inline bool qbrush_fast_equals(const QBrush &a, const QBrush &b) { return data_ptr(a) == data_ptr(b); }
99 inline Qt::BrushStyle qbrush_style(const QBrush &b) { return data_ptr(b)->style; }
100 inline const QColor &qbrush_color(const QBrush &b) { return data_ptr(b)->color; }
101 inline bool qbrush_has_transform(const QBrush &b) { return data_ptr(b)->transform.type() > QTransform::TxNone; }
102 
104 {
105 public:
106  QPainterClipInfo() { } // for QList, don't use
108 
111 
114 
117 
120 
128 
129  // ###
130 // union {
131 // QRegionData *d;
132 // QPainterPathPrivate *pathData;
133 
134 // struct {
135 // int x, y, w, h;
136 // } rectData;
137 // struct {
138 // qreal x, y, w, h;
139 // } rectFData;
140 // };
141 
142 };
143 
145 
146 class Q_GUI_EXPORT QPainterState : public QPaintEngineState
147 {
148 public:
149  QPainterState();
150  QPainterState(const QPainterState *s);
151  virtual ~QPainterState();
152  void init(QPainter *p);
153 
159  QBrush bgBrush = Qt::white; // background brush
162  Qt::ClipOperation clipOperation = Qt::NoClip;
163  QPainter::RenderHints renderHints;
164  QList<QPainterClipInfo> clipInfo; // ### Make me smaller and faster to copy around...
165  QTransform worldMatrix; // World transformation matrix, not window and viewport
166  QTransform matrix; // Complete transformation matrix,
168  int wx = 0, wy = 0, ww = 0, wh = 0; // window rectangle
169  int vx = 0, vy = 0, vw = 0, vh = 0; // viewport rectangle
170  qreal opacity = 1;
171 
172  uint WxF:1; // World transformation
173  uint VxF:1; // View transformation
175 
177  QPainter *painter = nullptr;
180  uint emulationSpecifier = 0;
181  uint changeFlags = 0;
182 };
183 
185 {
190 };
191 
192 class QRawFont;
194 {
195  Q_DECLARE_PUBLIC(QPainter)
196 public:
197  explicit QPainterPrivate(QPainter *painter);
199 
201  // Allocate space for 4 d-pointers (enough for up to 4 sub-sequent
202  // redirections within the same paintEvent(), which should be enough
203  // in 99% of all cases). E.g: A renders B which renders C which renders D.
204  static constexpr qsizetype NDPtrs = 4;
206 
207  std::unique_ptr<QPainterState> state;
208  template <typename T, std::size_t N = 8>
209  struct SmallStack : std::stack<T, QVarLengthArray<T, N>> {
210  void clear() { this->c.clear(); }
211  };
213 
214  mutable std::unique_ptr<QPainterDummyState> dummyState;
215 
220 
221  enum DrawOperation { StrokeDraw = 0x1,
222  FillDraw = 0x2,
223  StrokeAndFillDraw = 0x3
224  };
225 
227  if (!dummyState)
228  dummyState = std::make_unique<QPainterDummyState>();
229  return dummyState.get();
230  }
231 
235  void updateState(std::unique_ptr<QPainterState> &state) { updateState(state.get()); }
236 
237  void draw_helper(const QPainterPath &path, DrawOperation operation = StrokeAndFillDraw);
238  void drawStretchedGradient(const QPainterPath &path, DrawOperation operation);
239  void drawOpaqueBackground(const QPainterPath &path, DrawOperation operation);
240  void drawTextItem(const QPointF &p, const QTextItem &_ti, QTextEngine *textEngine);
241 
242 #if !defined(QT_NO_RAWFONT)
243  void drawGlyphs(const QPointF &decorationPosition, const quint32 *glyphArray, QFixedPoint *positionArray, int glyphCount,
244  QFontEngine *fontEngine, bool overline = false, bool underline = false,
245  bool strikeOut = false);
246 #endif
247 
248  void updateMatrix();
249  void updateInvMatrix();
250 
251  void checkEmulation();
252 
254  {
255  return painter->d_ptr.get();
256  }
257 
258  QTransform viewTransform() const;
261  static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev);
263  void initFrom(const QPaintDevice *device);
264 
265  QPaintDevice *device = nullptr;
268 
270  void operator()(QPaintEngine *pe) const noexcept
271  {
272  if (pe && pe->autoDestruct())
273  delete pe;
274  }
275  };
276  std::unique_ptr<QPaintEngine, QPaintEngineDestructor> engine;
277 
278  std::unique_ptr<QEmulationPaintEngine> emulationEngine;
280  QBrush colorBrush; // for fill with solid color
281 };
282 
283 Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation);
284 
286 
287 
289 
290 #endif // QPAINTER_P_H
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:66
std::unique_ptr< QBrushData, QBrushDataPointerDeleter > DataPtr
Definition: qbrush.h:113
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:87
The QPaintEngineState class provides information about the active paint engine's current state....
Definition: qpaintengine.h:268
QPainterClipInfo(const QRectF &r, Qt::ClipOperation op, const QTransform &m)
Definition: qpainter_p.h:118
QTransform matrix
Definition: qpainter_p.h:122
ClipType clipType
Definition: qpainter_p.h:121
QPainterClipInfo(const QRect &r, Qt::ClipOperation op, const QTransform &m)
Definition: qpainter_p.h:115
QPainterClipInfo(const QRegion &r, Qt::ClipOperation op, const QTransform &m)
Definition: qpainter_p.h:112
QPainterPath path
Definition: qpainter_p.h:124
Qt::ClipOperation operation
Definition: qpainter_p.h:123
QPainterClipInfo(const QPainterPath &p, Qt::ClipOperation op, const QTransform &m)
Definition: qpainter_p.h:109
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
CompositionMode
Definition: qpainter.h:132
@ CompositionMode_SourceOver
Definition: qpainter.h:133
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:65
QBrush colorBrush
Definition: qpainter_p.h:280
QPainterDummyState * fakeState() const
Definition: qpainter_p.h:226
void drawOpaqueBackground(const QPainterPath &path, DrawOperation operation)
Definition: qpainter.cpp:506
void updateEmulationSpecifier(QPainterState *s)
Definition: qpainter.cpp:688
QTransform invMatrix
Definition: qpainter_p.h:216
QPaintDevice * original_device
Definition: qpainter_p.h:266
QPaintEngineEx * extended
Definition: qpainter_p.h:279
QPaintDevice * helper_device
Definition: qpainter_p.h:267
void initFrom(const QPaintDevice *device)
Definition: qpainter.cpp:1550
static constexpr qsizetype NDPtrs
Definition: qpainter_p.h:204
void updateMatrix()
Definition: qpainter.cpp:659
void updateInvMatrix()
Definition: qpainter.cpp:679
SmallStack< std::unique_ptr< QPainterState > > savedStates
Definition: qpainter_p.h:212
std::unique_ptr< QPaintEngine, QPaintEngineDestructor > engine
Definition: qpainter_p.h:276
void updateState(QPainterState *state)
Definition: qpainter.cpp:925
std::unique_ptr< QEmulationPaintEngine > emulationEngine
Definition: qpainter_p.h:278
void draw_helper(const QPainterPath &path, DrawOperation operation=StrokeAndFillDraw)
Definition: qpainter.cpp:350
QVarLengthArray< QPainterPrivate *, NDPtrs > d_ptrs
Definition: qpainter_p.h:205
QPainter * q_ptr
Definition: qpainter_p.h:200
QPainterPrivate(QPainter *painter)
Definition: qpainter.cpp:232
void drawTextItem(const QPointF &p, const QTextItem &_ti, QTextEngine *textEngine)
Definition: qpainter.cpp:6121
void drawStretchedGradient(const QPainterPath &path, DrawOperation operation)
Definition: qpainter.cpp:544
void updateState(std::unique_ptr< QPainterState > &state)
Definition: qpainter_p.h:235
QTransform hidpiScaleTransform() const
Definition: qpainter.cpp:260
void detachPainterPrivate(QPainter *q)
Definition: qpainter.cpp:323
QPaintDevice * device
Definition: qpainter_p.h:265
static QPainterPrivate * get(QPainter *painter)
Definition: qpainter_p.h:253
QTransform viewTransform() const
Definition: qpainter.cpp:240
qreal effectiveDevicePixelRatio() const
Definition: qpainter.cpp:251
std::unique_ptr< QPainterDummyState > dummyState
Definition: qpainter_p.h:214
void checkEmulation()
Definition: qpainter.cpp:204
std::unique_ptr< QPainterState > state
Definition: qpainter_p.h:207
void updateStateImpl(QPainterState *state)
Definition: qpainter.cpp:893
static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev)
Definition: qpainter.cpp:270
void drawGlyphs(const QPointF &decorationPosition, const quint32 *glyphArray, QFixedPoint *positionArray, int glyphCount, QFontEngine *fontEngine, bool overline=false, bool underline=false, bool strikeOut=false)
Definition: qpainter.cpp:5345
QBrush brush
Definition: qpainter_p.h:158
uint clipEnabled
Definition: qpainter_p.h:174
QRegion clipRegion
Definition: qpainter_p.h:160
QFont deviceFont
Definition: qpainter_p.h:156
QList< QPainterClipInfo > clipInfo
Definition: qpainter_p.h:164
QTransform worldMatrix
Definition: qpainter_p.h:165
QPainter::RenderHints renderHints
Definition: qpainter_p.h:163
QTransform matrix
Definition: qpainter_p.h:166
QPointF brushOrigin
Definition: qpainter_p.h:154
QPainterPath clipPath
Definition: qpainter_p.h:161
Qt::LayoutDirection layoutDirection
Definition: qpainter_p.h:178
QTransform redirectionMatrix
Definition: qpainter_p.h:167
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:61
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QRawFont class provides access to a single physical instance of a font.
Definition: qrawfont.h:60
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:63
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QTextItem class provides all the information required to draw text in a custom paint engine.
Definition: qpaintengine.h:64
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:56
ClipOperation
Definition: qnamespace.h:1330
@ NoClip
Definition: qnamespace.h:1331
LayoutDirection
Definition: qnamespace.h:1462
BGMode
Definition: qnamespace.h:531
@ TransparentMode
Definition: qnamespace.h:532
@ white
Definition: qnamespace.h:62
PenStyle
Definition: qnamespace.h:1111
PenJoinStyle
Definition: qnamespace.h:1131
BrushStyle
Definition: qnamespace.h:1139
PenCapStyle
Definition: qnamespace.h:1124
Definition: brush.cpp:52
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld init[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
set set set set set set set macro pixldst1 op
unsigned int quint32
Definition: qglobal.h:288
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
ptrdiff_t qsizetype
Definition: qglobal.h:308
unsigned int uint
Definition: qglobal.h:334
GLboolean GLboolean GLboolean b
const GLfloat * m
GLboolean r
[2]
GLboolean GLboolean GLboolean GLboolean a
[7]
const GLubyte * c
Definition: qopenglext.h:12701
GLuint GLenum matrix
Definition: qopenglext.h:11564
GLdouble GLdouble t
[9]
Definition: qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition: qopenglext.h:259
GLsizei const GLchar *const * path
Definition: qopenglext.h:4283
GLdouble s
[6]
Definition: qopenglext.h:235
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
qreal qpen_widthf(const QPen &p)
Definition: qpainter_p.h:91
Qt::BrushStyle qbrush_style(const QBrush &b)
Definition: qpainter_p.h:99
bool qpen_fast_equals(const QPen &a, const QPen &b)
Definition: qpainter_p.h:89
Qt::PenStyle qpen_style(const QPen &p)
Definition: qpainter_p.h:92
const QColor & qbrush_color(const QBrush &b)
Definition: qpainter_p.h:100
const void * data_ptr(const QTransform &t)
Definition: qpainter_p.h:84
QString qt_generate_brush_key(const QBrush &brush)
Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation)
Definition: qpainter.cpp:8165
Q_DECLARE_TYPEINFO(QPainterClipInfo, Q_RELOCATABLE_TYPE)
Qt::PenCapStyle qpen_capStyle(const QPen &p)
Definition: qpainter_p.h:93
Qt::PenJoinStyle qpen_joinStyle(const QPen &p)
Definition: qpainter_p.h:94
QBrush qpen_brush(const QPen &p)
Definition: qpainter_p.h:90
bool qbrush_fast_equals(const QBrush &a, const QBrush &b)
Definition: qpainter_p.h:98
bool qtransform_fast_equals(const QTransform &a, const QTransform &b)
Definition: qpainter_p.h:85
bool qbrush_has_transform(const QBrush &b)
Definition: qpainter_p.h:101
@ Q_RELOCATABLE_TYPE
Definition: qtypeinfo.h:156
QPainter painter(this)
[7]
QTransform transform
Definition: qpainter_p.h:189
void operator()(QPaintEngine *pe) const noexcept
Definition: qpainter_p.h:270