Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qrasterbackingstore.cpp
Go to the documentation of this file.
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
6
7#include <QtGui/qbackingstore.h>
8#include <QtGui/qpainter.h>
9
10#include <private/qhighdpiscaling_p.h>
11#include <qpa/qplatformwindow.h>
12
14
15QRasterBackingStore::QRasterBackingStore(QWindow *window)
16 : QPlatformBackingStore(window)
17{
18}
19
20QRasterBackingStore::~QRasterBackingStore()
21{
22}
23
24void QRasterBackingStore::resize(const QSize &size, const QRegion &staticContents)
25{
26 Q_UNUSED(staticContents);
27 m_requestedSize = size;
28}
29
30QImage::Format QRasterBackingStore::format() const
31{
32 if (window()->format().hasAlpha())
33 return QImage::Format_ARGB32_Premultiplied;
34 else
35 return QImage::Format_RGB32;
36}
37
38QPaintDevice *QRasterBackingStore::paintDevice()
39{
40 return &m_image;
41}
42
43QImage QRasterBackingStore::toImage() const
44{
45 return m_image;
46}
47
48bool QRasterBackingStore::scroll(const QRegion &region, int dx, int dy)
49{
50 if (window()->surfaceType() != QSurface::RasterSurface)
51 return false;
52
53 extern void qt_scrollRectInImage(QImage &, const QRect &, const QPoint &);
54
55 const qreal devicePixelRatio = m_image.devicePixelRatio();
56 const QPoint delta(dx * devicePixelRatio, dy * devicePixelRatio);
57
58 const QRect rect = region.boundingRect();
59 qt_scrollRectInImage(m_image, QRect(rect.topLeft() * devicePixelRatio, rect.size() * devicePixelRatio), delta);
60
61 return true;
62}
63
64void QRasterBackingStore::beginPaint(const QRegion &region)
65{
66 qreal nativeWindowDevicePixelRatio = window()->handle()->devicePixelRatio();
67 QSize effectiveBufferSize = m_requestedSize * nativeWindowDevicePixelRatio;
68 if (m_image.devicePixelRatio() != nativeWindowDevicePixelRatio || m_image.size() != effectiveBufferSize) {
69 m_image = QImage(effectiveBufferSize, format());
70 m_image.setDevicePixelRatio(nativeWindowDevicePixelRatio);
71 if (m_image.hasAlphaChannel())
72 m_image.fill(Qt::transparent);
73 }
74
75 if (!m_image.hasAlphaChannel())
76 return;
77
78 QPainter painter(&m_image);
79 painter.setCompositionMode(QPainter::CompositionMode_Source);
80 for (const QRect &rect : region)
81 painter.fillRect(rect, Qt::transparent);
82}
83
84QT_END_NAMESPACE
Combined button and popup list for selecting options.