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
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
5
7
8#include <QtCore/qbytearray.h>
9#include <QtCore/qloggingcategory.h>
10
11#include <native_window/external_window.h>
12
13QT_BEGIN_NAMESPACE
14
15namespace {
16constexpr uint32_t kGlTextureExternalOes = 0x8D65; // GL_OES_EGL_image_external
17} // namespace
18
19std::atomic<quint64> QOhosSurfaceImage::s_nextIndex{ 1 };
20
21QOhosSurfaceImage::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
49QOhosSurfaceImage::~QOhosSurfaceImage()
50{
51 if (m_image) {
52 OH_NativeImage_UnsetOnFrameAvailableListener(m_image);
53 OH_NativeImage_Destroy(&m_image);
54 }
55}
56
57bool QOhosSurfaceImage::updateTexImage()
58{
59 if (!m_image)
60 return false;
61 return OH_NativeImage_UpdateSurfaceImage(m_image) == 0;
62}
63
64QMatrix4x4 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
75void 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 emit self->frameAvailable(self->m_index);
83}
84
85QT_END_NAMESPACE
86
87#include "moc_qohossurfaceimage_p.cpp"
constexpr uint32_t kGlTextureExternalOes