blob: dcfc4433e6f685e920ed305604c7299c6b08499a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "qwasmoffscreensurface.h"
QT_BEGIN_NAMESPACE
QWasmOffscreenSurface::QWasmOffscreenSurface(QOffscreenSurface *offscreenSurface)
: QPlatformOffscreenSurface(offscreenSurface), m_offscreenCanvas(emscripten::val::undefined())
{
const auto offscreenCanvasClass = emscripten::val::global("OffscreenCanvas");
// The OffscreenCanvas is not supported on some browsers, most notably on Safari.
if (!offscreenCanvasClass)
return;
m_offscreenCanvas = offscreenCanvasClass.new_(offscreenSurface->size().width(),
offscreenSurface->size().height());
m_specialTargetId = std::string("!qtoffscreen_") + std::to_string(uintptr_t(this));
emscripten::val::module_property("specialHTMLTargets")
.set(m_specialTargetId, m_offscreenCanvas);
}
QWasmOffscreenSurface::~QWasmOffscreenSurface()
{
emscripten::val::module_property("specialHTMLTargets").delete_(m_specialTargetId);
}
bool QWasmOffscreenSurface::isValid() const
{
return !m_offscreenCanvas.isNull() && !m_offscreenCanvas.isUndefined();
}
QT_END_NAMESPACE
|