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