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