1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPAINTENGINE_H
5#define QPAINTENGINE_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qnamespace.h>
9#include <QtCore/qobjectdefs.h>
10#include <QtCore/qscopedpointer.h>
11#include <QtGui/qpainter.h>
12
13QT_BEGIN_NAMESPACE
14
15
16class QFontEngine;
17class QLineF;
18class QPaintDevice;
19class QPaintEnginePrivate;
20class QPainterPath;
21class QPointF;
22class QPolygonF;
23class QRectF;
24struct QGlyphLayout;
25class QTextItemInt;
26class QPaintEngineState;
27
28class Q_GUI_EXPORT QTextItem {
29public:
30 enum RenderFlag {
31 RightToLeft = 0x1,
32 Overline = 0x10,
33 Underline = 0x20,
34 StrikeOut = 0x40,
35
36 Dummy = 0xffffffff
37 };
38 Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
39 qreal descent() const;
40 qreal ascent() const;
41 qreal width() const;
42
43 RenderFlags renderFlags() const;
44 QString text() const;
45 QFont font() const;
46};
47Q_DECLARE_TYPEINFO(QTextItem, Q_PRIMITIVE_TYPE);
48
49
50class Q_GUI_EXPORT QPaintEngine
51{
52 Q_DECLARE_PRIVATE(QPaintEngine)
53public:
54 enum PaintEngineFeature {
55 PrimitiveTransform = 0x00000001, // Can transform primitives brushes
56 PatternTransform = 0x00000002, // Can transform pattern brushes
57 PixmapTransform = 0x00000004, // Can transform pixmaps
58 PatternBrush = 0x00000008, // Can fill with pixmaps and standard patterns
59 LinearGradientFill = 0x00000010, // Can fill gradient areas
60 RadialGradientFill = 0x00000020, // Can render radial gradients
61 ConicalGradientFill = 0x00000040, // Can render conical gradients
62 AlphaBlend = 0x00000080, // Can do source over alpha blend
63 PorterDuff = 0x00000100, // Can do general porter duff compositions
64 PainterPaths = 0x00000200, // Can fill, outline and clip paths
65 Antialiasing = 0x00000400, // Can antialias lines
66 BrushStroke = 0x00000800, // Can render brush based pens
67 ConstantOpacity = 0x00001000, // Can render at constant opacity
68 MaskedBrush = 0x00002000, // Can fill with textures that has an alpha channel or mask
69 PerspectiveTransform = 0x00004000, // Can do perspective transformations
70 BlendModes = 0x00008000, // Can do extended Porter&Duff composition
71 ObjectBoundingModeGradients = 0x00010000, // Can do object bounding mode gradients
72 RasterOpModes = 0x00020000, // Can do logical raster operations
73 PaintOutsidePaintEvent = 0x20000000, // Engine is capable of painting outside paint events
74 /* 0x10000000, // Used for emulating
75 QGradient::StretchToDevice,
76 defined in qpainter.cpp
77
78 0x40000000, // Used internally for emulating opaque backgrounds
79 */
80
81 AllFeatures = 0xffffffff // For convenience
82 };
83 Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)
84
85 enum DirtyFlag {
86 DirtyPen = 0x0001,
87 DirtyBrush = 0x0002,
88 DirtyBrushOrigin = 0x0004,
89 DirtyFont = 0x0008,
90 DirtyBackground = 0x0010,
91 DirtyBackgroundMode = 0x0020,
92 DirtyTransform = 0x0040,
93 DirtyClipRegion = 0x0080,
94 DirtyClipPath = 0x0100,
95 DirtyHints = 0x0200,
96 DirtyCompositionMode = 0x0400,
97 DirtyClipEnabled = 0x0800,
98 DirtyOpacity = 0x1000,
99
100 AllDirty = 0xffff
101 };
102 Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
103
104 enum PolygonDrawMode {
105 OddEvenMode,
106 WindingMode,
107 ConvexMode,
108 PolylineMode
109 };
110
111 explicit QPaintEngine(PaintEngineFeatures features=PaintEngineFeatures());
112 virtual ~QPaintEngine();
113
114 bool isActive() const { return active; }
115 void setActive(bool newState) { active = newState; }
116
117 virtual bool begin(QPaintDevice *pdev) = 0;
118 virtual bool end() = 0;
119
120 virtual void updateState(const QPaintEngineState &state) = 0;
121
122 virtual void drawRects(const QRect *rects, int rectCount);
123 virtual void drawRects(const QRectF *rects, int rectCount);
124
125 virtual void drawLines(const QLine *lines, int lineCount);
126 virtual void drawLines(const QLineF *lines, int lineCount);
127
128 virtual void drawEllipse(const QRectF &r);
129 virtual void drawEllipse(const QRect &r);
130
131 virtual void drawPath(const QPainterPath &path);
132
133 virtual void drawPoints(const QPointF *points, int pointCount);
134 virtual void drawPoints(const QPoint *points, int pointCount);
135
136 virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
137 virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
138
139 virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) = 0;
140 virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
141 virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
142 virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
143 Qt::ImageConversionFlags flags = Qt::AutoColor);
144
145 void setPaintDevice(QPaintDevice *device);
146 QPaintDevice *paintDevice() const;
147
148 void setSystemClip(const QRegion &baseClip);
149 QRegion systemClip() const;
150
151 void setSystemRect(const QRect &rect);
152 QRect systemRect() const;
153
154
155 virtual QPoint coordinateOffset() const;
156
157 enum Type {
158 X11,
159 Windows,
160 QuickDraw, CoreGraphics, MacPrinter,
161 QWindowSystem,
162 OpenGL,
163 Picture,
164 SVG,
165 Raster,
166 Direct3D,
167 Pdf,
168 OpenVG,
169 OpenGL2,
170 PaintBuffer,
171 Blitter,
172 Direct2D,
173
174 User = 50, // first user type id
175 MaxUser = 100 // last user type id
176 };
177 virtual Type type() const = 0;
178
179 inline void fix_neg_rect(int *x, int *y, int *w, int *h);
180
181 inline bool testDirty(DirtyFlags df);
182 inline void setDirty(DirtyFlags df);
183 inline void clearDirty(DirtyFlags df);
184
185 bool hasFeature(PaintEngineFeatures feature) const { return bool(gccaps & feature); }
186
187 QPainter *painter() const;
188
189 void syncState();
190 inline bool isExtended() const { return extended; }
191
192 virtual QPixmap createPixmap(QSize size);
193 virtual QPixmap createPixmapFromImage(QImage image, Qt::ImageConversionFlags flags = Qt::AutoColor);
194
195protected:
196 QPaintEngine(QPaintEnginePrivate &data, PaintEngineFeatures devcaps=PaintEngineFeatures());
197
198 QPaintEngineState *state;
199 PaintEngineFeatures gccaps;
200
201 uint active : 1;
202 uint selfDestruct : 1;
203 uint extended : 1;
204
205 QScopedPointer<QPaintEnginePrivate> d_ptr;
206
207private:
208 void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
209 bool autoDestruct() const { return selfDestruct; }
210 Q_DISABLE_COPY(QPaintEngine)
211
212 friend class QPainterReplayer;
213 friend class QFontEngineBox;
214 friend class QFontEngineMac;
215 friend class QFontEngineWin;
216 friend class QMacPrintEngine;
217 friend class QMacPrintEnginePrivate;
218 friend class QFontEngineQPF2;
219 friend class QPainter;
220 friend class QPainterPrivate;
221 friend class QWidget;
222 friend class QWidgetPrivate;
223 friend class QWin32PaintEngine;
224 friend class QWin32PaintEnginePrivate;
225 friend class QMacCGContext;
226 friend class QPreviewPaintEngine;
227 friend class QX11GLPlatformPixmap;
228};
229
230
231class Q_GUI_EXPORT QPaintEngineState
232{
233public:
234 QPaintEngine::DirtyFlags state() const { return dirtyFlags; }
235
236 QPen pen() const;
237 QBrush brush() const;
238 QPointF brushOrigin() const;
239 QBrush backgroundBrush() const;
240 Qt::BGMode backgroundMode() const;
241 QFont font() const;
242 QTransform transform() const;
243
244 Qt::ClipOperation clipOperation() const;
245 QRegion clipRegion() const;
246 QPainterPath clipPath() const;
247 bool isClipEnabled() const;
248
249 QPainter::RenderHints renderHints() const;
250 QPainter::CompositionMode compositionMode() const;
251 qreal opacity() const;
252
253 QPainter *painter() const;
254
255 bool brushNeedsResolving() const;
256 bool penNeedsResolving() const;
257
258protected:
259 friend class QPaintEngine;
260 friend class QRasterPaintEngine;
261 friend class QWidget;
262 friend class QPainter;
263 friend class QPainterPrivate;
264 friend class QMacPrintEnginePrivate;
265
266 QPaintEngine::DirtyFlags dirtyFlags;
267};
268
269//
270// inline functions
271//
272
273inline void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h)
274{
275 if (*w < 0) {
276 *w = -*w;
277 *x -= *w - 1;
278 }
279 if (*h < 0) {
280 *h = -*h;
281 *y -= *h - 1;
282 }
283}
284
285inline bool QPaintEngine::testDirty(DirtyFlags df) {
286 Q_ASSERT(state);
287 return bool(state->dirtyFlags & df);
288}
289
290inline void QPaintEngine::setDirty(DirtyFlags df) {
291 Q_ASSERT(state);
292 state->dirtyFlags |= df;
293}
294
295inline void QPaintEngine::clearDirty(DirtyFlags df)
296{
297 Q_ASSERT(state);
298 state->dirtyFlags &= ~df;
299}
300
301Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags)
302Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures)
303Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags)
304
305QT_END_NAMESPACE
306
307#endif // QPAINTENGINE_H
308

source code of qtbase/src/gui/painting/qpaintengine.h