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
qohossurfaceimage.cpp
Go to the documentation of this file.
1
// Copyright (C) 2026 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
4
#
include
"qohossurfaceimage_p.h"
5
6
#
include
"qohosglobal_p.h"
7
8
#
include
<
QtCore
/
qbytearray
.
h
>
9
#
include
<
QtCore
/
qloggingcategory
.
h
>
10
11
#
include
<
native_window
/
external_window
.
h
>
12
13
QT_BEGIN_NAMESPACE
14
15
namespace
{
16
constexpr
uint32_t
kGlTextureExternalOes
= 0x8D65;
// GL_OES_EGL_image_external
17
}
// namespace
18
19
std::atomic<quint64> QOhosSurfaceImage::s_nextIndex{ 1 };
20
21
QOhosSurfaceImage::QOhosSurfaceImage(uint32_t glTextureId, QObject *parent)
22
: QObject(parent), m_textureId(glTextureId)
23
{
24
m_index = s_nextIndex.fetch_add(1);
25
26
m_image = OH_NativeImage_Create(glTextureId, kGlTextureExternalOes);
27
if
(!m_image) {
28
qCWarning(qLcOhosMediaPlugin) <<
"OH_NativeImage_Create failed for texture"
<< glTextureId;
29
return
;
30
}
31
32
m_nativeWindow = OH_NativeImage_AcquireNativeWindow(m_image);
33
if
(!m_nativeWindow) {
34
qCWarning(qLcOhosMediaPlugin) <<
"OH_NativeImage_AcquireNativeWindow returned null"
;
35
OH_NativeImage_Destroy(&m_image);
36
return
;
37
}
38
39
uint64_t surfaceIdRaw = 0;
40
if
(OH_NativeImage_GetSurfaceId(m_image, &surfaceIdRaw) == 0)
41
m_surfaceId = QByteArray::number(qulonglong(surfaceIdRaw));
42
43
OH_OnFrameAvailableListener listener{};
44
listener.context =
this
;
45
listener.onFrameAvailable = &QOhosSurfaceImage::onFrameAvailableTrampoline;
46
OH_NativeImage_SetOnFrameAvailableListener(m_image, listener);
47
}
48
49
QOhosSurfaceImage::~QOhosSurfaceImage()
50
{
51
if
(m_image) {
52
OH_NativeImage_UnsetOnFrameAvailableListener(m_image);
53
OH_NativeImage_Destroy(&m_image);
54
}
55
}
56
57
bool
QOhosSurfaceImage::updateTexImage()
58
{
59
if
(!m_image)
60
return
false
;
61
return
OH_NativeImage_UpdateSurfaceImage(m_image) == 0;
62
}
63
64
QMatrix4x4 QOhosSurfaceImage::transformMatrix()
const
65
{
66
QMatrix4x4 m;
67
if
(!m_image)
68
return
m;
69
// OH_NativeImage returns column-major; populate QMatrix4x4's storage directly.
70
if
(OH_NativeImage_GetTransformMatrixV2(m_image, m.data()) != 0)
71
m.setToIdentity();
72
return
m;
73
}
74
75
void
QOhosSurfaceImage::onFrameAvailableTrampoline(
void
*context)
76
{
77
auto
*self =
reinterpret_cast
<QOhosSurfaceImage *>(context);
78
if
(!self)
79
return
;
80
// Native producer thread — emit the signal so the GL context thread can
81
// pick it up via a queued connection.
82
Q_EMIT self->frameAvailable(self->m_index);
83
}
84
85
QT_END_NAMESPACE
86
87
#
include
"moc_qohossurfaceimage_p.cpp"
QT_BEGIN_NAMESPACE::kGlTextureExternalOes
constexpr uint32_t kGlTextureExternalOes
Definition
qohossurfaceimage.cpp:16
qtmultimedia
src
plugins
multimedia
ohos
common
qohossurfaceimage.cpp
Generated on
for Qt by
1.18.0