/src/qtbase/src/gui/kernel/qrasterwindow.cpp
Line | Count | Source |
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 | | // Qt-Security score:significant reason:default |
4 | | |
5 | | #include "qrasterwindow.h" |
6 | | |
7 | | #include <QtGui/private/qpaintdevicewindow_p.h> |
8 | | |
9 | | #include <QtGui/QBackingStore> |
10 | | #include <QtGui/QPainter> |
11 | | |
12 | | QT_BEGIN_NAMESPACE |
13 | | |
14 | | /*! |
15 | | \class QRasterWindow |
16 | | \inmodule QtGui |
17 | | \since 5.4 |
18 | | \brief QRasterWindow is a convenience class for using QPainter on a QWindow. |
19 | | |
20 | | QRasterWindow is a QWindow with a raster-based, non-OpenGL surface. On top of |
21 | | the functionality offered by QWindow, QRasterWindow adds a virtual |
22 | | paintEvent() function and the possibility to open a QPainter on itself. The |
23 | | underlying paint engine will be the raster one, meaning that all drawing will |
24 | | happen on the CPU. For performing accelerated, OpenGL-based drawing, use |
25 | | QOpenGLWindow instead. |
26 | | |
27 | | Internally the class is thin wrapper for QWindow and QBackingStore |
28 | | and is very similar to the \l{Raster Window Example}{Raster Window |
29 | | Example} that uses these classes directly. |
30 | | |
31 | | \sa QPaintDeviceWindow::paintEvent(), QPaintDeviceWindow::update() |
32 | | */ |
33 | | |
34 | | class QRasterWindowPrivate : public QPaintDeviceWindowPrivate |
35 | | { |
36 | 0 | Q_DECLARE_PUBLIC(QRasterWindow) |
37 | 0 | public: |
38 | 0 | void handleResizeEvent() override |
39 | 0 | { |
40 | 0 | Q_Q(QRasterWindow); |
41 | 0 | if (backingstore->size() != q->size()) |
42 | 0 | markWindowAsDirty(); |
43 | 0 | } |
44 | | |
45 | | void beginPaint(const QRegion ®ion) override |
46 | 0 | { |
47 | 0 | Q_Q(QRasterWindow); |
48 | 0 | const QSize size = q->size(); |
49 | 0 | if (backingstore->size() != size) |
50 | 0 | backingstore->resize(size); |
51 | |
|
52 | 0 | backingstore->beginPaint(region); |
53 | 0 | } |
54 | | |
55 | | void endPaint() override |
56 | 0 | { |
57 | 0 | backingstore->endPaint(); |
58 | 0 | } |
59 | | |
60 | | void flush(const QRegion ®ion) override |
61 | 0 | { |
62 | 0 | Q_Q(QRasterWindow); |
63 | 0 | backingstore->flush(region, q); |
64 | 0 | } |
65 | | |
66 | | QScopedPointer<QBackingStore> backingstore; |
67 | | }; |
68 | | |
69 | | /*! |
70 | | Constructs a new QRasterWindow with \a parent. |
71 | | */ |
72 | | QRasterWindow::QRasterWindow(QWindow *parent) |
73 | 0 | : QPaintDeviceWindow(*(new QRasterWindowPrivate), parent) |
74 | 0 | { |
75 | 0 | setSurfaceType(QSurface::RasterSurface); |
76 | 0 | d_func()->backingstore.reset(new QBackingStore(this)); |
77 | 0 | } |
78 | | |
79 | | QRasterWindow::~QRasterWindow() |
80 | 0 | { |
81 | 0 | Q_D(QRasterWindow); |
82 | | // Delete backingstore while window is still alive, as it |
83 | | // might need to reference the window in the process |
84 | 0 | d->backingstore.reset(nullptr); |
85 | 0 | } |
86 | | |
87 | | /*! |
88 | | \internal |
89 | | */ |
90 | | int QRasterWindow::metric(PaintDeviceMetric metric) const |
91 | 0 | { |
92 | 0 | Q_D(const QRasterWindow); |
93 | |
|
94 | 0 | switch (metric) { |
95 | 0 | case PdmDepth: |
96 | 0 | return d->backingstore->paintDevice()->depth(); |
97 | 0 | default: |
98 | 0 | break; |
99 | 0 | } |
100 | 0 | return QPaintDeviceWindow::metric(metric); |
101 | 0 | } |
102 | | |
103 | | /*! |
104 | | \internal |
105 | | */ |
106 | | QPaintDevice *QRasterWindow::redirected(QPoint *) const |
107 | 0 | { |
108 | 0 | Q_D(const QRasterWindow); |
109 | 0 | return d->backingstore->paintDevice(); |
110 | 0 | } |
111 | | |
112 | | void QRasterWindow::resizeEvent(QResizeEvent *) |
113 | 0 | { |
114 | 0 | } |
115 | | |
116 | | QT_END_NAMESPACE |
117 | | |
118 | | #include "moc_qrasterwindow.cpp" |