Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qwasmbackingstore.cpp
Go to the documentation of this file.
1
// Copyright (C) 2018 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qwasmbackingstore.h"
6
#
include
"qwasmwindow.h"
7
#
include
"qwasmcompositor.h"
8
#
include
"qwasmdom.h"
9
10
#
include
<
QtGui
/
qpainter
.
h
>
11
#
include
<
QtGui
/
qbackingstore
.
h
>
12
13
#
include
<
emscripten
.
h
>
14
#
include
<
emscripten
/
wire
.
h
>
15
16
QT_BEGIN_NAMESPACE
17
18
QWasmBackingStore
::
QWasmBackingStore
(QWasmCompositor *compositor, QWindow *window)
19
: QPlatformBackingStore(window), m_compositor(compositor)
20
{
21
QWasmWindow *wasmWindow =
static_cast
<QWasmWindow *>(window->handle());
22
if
(wasmWindow)
23
wasmWindow->setBackingStore(
this
);
24
}
25
26
QWasmBackingStore
::~
QWasmBackingStore
()
27
{
28
auto
window =
this
->window();
29
QWasmIntegration
::
get
(
)
->removeBackingStore(window);
30
QWasmWindow
*wasmWindow =
static_cast
<
QWasmWindow
*>(window->handle());
31
if
(wasmWindow)
32
wasmWindow
->
setBackingStore
(
nullptr
)
;
33
}
34
35
QPaintDevice
*
QWasmBackingStore
::
paintDevice
()
36
{
37
return
&m_image;
38
}
39
40
void
QWasmBackingStore
::flush(QWindow *window,
const
QRegion ®ion,
const
QPoint
&offset)
41
{
42
Q_UNUSED(window);
43
m_dirty |= region;
44
45
QRect updateRect = region.boundingRect();
46
updateRect.translate(offset);
47
48
m_compositor->handleBackingStoreFlush(
this
->window(), updateRect);
49
}
50
51
void
QWasmBackingStore
::
updateTexture
(
QWasmWindow
*window)
52
{
53
if
(m_dirty.isNull())
54
return
;
55
56
if
(m_image.size().isEmpty())
57
return
;
58
59
if
(m_webImageDataArray.isUndefined()) {
60
m_webImageDataArray = window->context2d().call<emscripten::val>(
61
"createImageData"
, emscripten::val(m_image.width()),
62
emscripten::val(m_image.height()));
63
}
64
65
QRegion clippedDpiScaledRegion;
66
QRect imageRect = m_image.rect();
67
68
for
(
const
QRect &rect : m_dirty) {
69
// Convert device-independent dirty region to device region
70
qreal dpr = m_image.devicePixelRatio();
71
QRect deviceRect = QRect(rect.topLeft() * dpr, rect.size() * dpr);
72
73
// intersect with image rect to be sure
74
QRect r = imageRect & deviceRect;
75
// if the rect is wide enough it is cheaper to just extend it instead of doing an image copy
76
if
(r.width() >= imageRect.width() / 2) {
77
r.setX(0);
78
r.setWidth(imageRect.width());
79
}
80
81
clippedDpiScaledRegion |= r;
82
}
83
84
for
(
const
QRect &dirtyRect : clippedDpiScaledRegion)
85
dom::drawImageToWebImageDataArray(m_image, m_webImageDataArray, dirtyRect);
86
87
m_dirty = QRegion();
88
}
89
90
void
QWasmBackingStore
::
beginPaint
(
const
QRegion ®ion)
91
{
92
m_dirty |= region;
93
// Keep backing store device pixel ratio in sync with window
94
if
(m_image.devicePixelRatio() != window()->handle()->devicePixelRatio())
95
resize(backingStore()->size(), backingStore()->staticContents());
96
97
QPainter painter(&m_image);
98
99
if
(m_image.hasAlphaChannel()) {
100
painter.setCompositionMode(QPainter::CompositionMode_Source);
101
const
QColor blank = Qt::transparent;
102
for
(
const
QRect &rect : region)
103
painter.fillRect(rect, blank);
104
}
105
}
106
107
void
QWasmBackingStore
::
resize
(
const
QSize &size,
const
QRegion &staticContents)
108
{
109
Q_UNUSED(staticContents);
110
111
QImage::Format format = QImage::Format_RGBA8888;
112
const
auto
platformScreenDPR = window()->handle()->devicePixelRatio();
113
m_image = QImage(size * platformScreenDPR, format);
114
m_image.setDevicePixelRatio(platformScreenDPR);
115
m_webImageDataArray = emscripten::val::undefined();
116
}
117
118
QImage
QWasmBackingStore
::
toImage
()
const
119
{
120
// used by QPlatformBackingStore::rhiFlush
121
return
m_image;
122
}
123
124
const
QImage
&
QWasmBackingStore
::
getImageRef
()
const
125
{
126
return
m_image;
127
}
128
129
emscripten
::val
QWasmBackingStore
::
getUpdatedWebImage
(
QWasmWindow
*window)
130
{
131
updateTexture
(
window
)
;
132
return
m_webImageDataArray;
133
}
134
135
QT_END_NAMESPACE
QPoint
\inmodule QtCore\reentrant
Definition
qpoint.h:30
QWasmBackingStore
Definition
qwasmbackingstore.h:21
QWasmBackingStore::getUpdatedWebImage
emscripten::val getUpdatedWebImage(QWasmWindow *window)
Definition
qwasmbackingstore.cpp:129
QWasmBackingStore::beginPaint
void beginPaint(const QRegion &) override
This function is called before painting onto the surface begins, with the region in which the paintin...
Definition
qwasmbackingstore.cpp:90
QWasmBackingStore::resize
void resize(const QSize &size, const QRegion &staticContents) override
Definition
qwasmbackingstore.cpp:107
QWasmBackingStore::~QWasmBackingStore
~QWasmBackingStore()
Definition
qwasmbackingstore.cpp:26
QWasmBackingStore::updateTexture
void updateTexture(QWasmWindow *window)
Definition
qwasmbackingstore.cpp:51
QWasmBackingStore::paintDevice
QPaintDevice * paintDevice() override
Implement this function to return the appropriate paint device.
Definition
qwasmbackingstore.cpp:35
QWasmBackingStore::getImageRef
const QImage & getImageRef() const
Definition
qwasmbackingstore.cpp:124
QWasmBackingStore::toImage
QImage toImage() const override
Implemented in subclasses to return the content of the backingstore as a QImage.
Definition
qwasmbackingstore.cpp:118
QWasmIntegration
Definition
qwasmintegration.h:41
QWasmIntegration::get
static QWasmIntegration * get()
Definition
qwasmintegration.h:77
QWasmWindow::QWasmCompositor
friend class QWasmCompositor
Definition
qwasmwindow.h:237
QWasmWindow::setBackingStore
void setBackingStore(QWasmBackingStore *store)
Definition
qwasmwindow.h:98
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
emscripten
Definition
qwasmwindowtreenode.h:12
qtbase
src
plugins
platforms
wasm
qwasmbackingstore.cpp
Generated on
for Qt by
1.18.0