4#ifndef QOHOSJSSCOPEDATAOWNER_H
5#define QOHOSJSSCOPEDATAOWNER_H
7#include <QtCore/private/qcore_ohos_p.h>
8#include <QtCore/private/qohoscommon_p.h>
9#include <QtCore/private/qohoslogger_p.h>
13#include <qohosplugincore.h>
22template<
typename JsScopeData>
41 void addAsyncCleanup(std::function<
void(QOhosJsState &, JsScopeData &, QOhosTaskPromise<>)> cleanupFunc);
46 std::shared_ptr<JsScopeData> data;
47 std::vector<std::function<
void(QOhosJsState &, JsScopeData &, QOhosTaskPromise<>)>> asyncCleanupFuncs;
50 static void checkJsThreadOrAbort();
51 void runAsyncCleanupsAndDestroyData(QOhosJsState &jsState, std::shared_ptr<QOhosTaskPromise<>> donePromise);
52 void createDataIfMissing()
const;
54 std::shared_ptr<State> m_state;
57template<
typename JsScopeData>
59 : m_state(
std::make_shared<State>())
63template<
typename JsScopeData>
67 qOhosReportFatalErrorAndAbort(
"%s: JS scope data owner destroyed on the JS thread", Q_FUNC_INFO);
72 QOhosJsThreadGateway::invokeAndWaitForContinue(
73 [&](QOhosJsState &jsState, QOhosTaskPromise<> donePromise) {
74 runAsyncCleanupsAndDestroyData(jsState, std::make_shared<QOhosTaskPromise<>>(std::move(donePromise)));
79template<
typename JsScopeData>
82 checkJsThreadOrAbort();
83 createDataIfMissing();
84 return m_state->data.get();
87template<
typename JsScopeData>
90 checkJsThreadOrAbort();
91 createDataIfMissing();
92 return *m_state->data;
95template<
typename JsScopeData>
97 std::function<
void(QOhosJsState &, JsScopeData &, QOhosTaskPromise<>)> cleanupFunc)
99 checkJsThreadOrAbort();
100 createDataIfMissing();
101 m_state->asyncCleanupFuncs.push_back(
std::move(cleanupFunc));
104template<
typename JsScopeData>
108 qOhosReportFatalErrorAndAbort(
"%s: JS scope data accessed outside the JS thread", Q_FUNC_INFO);
111template<
typename JsScopeData>
115 qOhosReportFatalErrorAndAbort(
"%s: JS scope data accessed after its release", Q_FUNC_INFO);
118 m_state->data =
std::make_shared<JsScopeData>();
121template<
typename JsScopeData>
123 QOhosJsState &jsState, std::shared_ptr<QOhosTaskPromise<>> donePromise)
125 if (m_state->asyncCleanupFuncs.empty()) {
126 const auto state =
std::move(m_state);
132 auto nextCleanupFunc =
std::move(m_state->asyncCleanupFuncs.back());
133 m_state->asyncCleanupFuncs.pop_back();
135 auto runNextCleanup = [
this, &jsState, donePromise]() {
136 runAsyncCleanupsAndDestroyData(jsState, donePromise);
140 nextCleanupFunc(jsState, *m_state->data, QOhosTaskPromise<>(runNextCleanup, runNextCleanup, Q_FUNC_INFO));
141 }
catch (
const std::exception &e) {
142 qOhosPrintfError(
"%s: asynchronous cleanup threw, continuing with the remaining ones: %s", Q_FUNC_INFO, e.what());
QArkUi::QEmbeddedWindowNode & embeddedWindowNodeInJsThread()
QOhosForeignWindow(QWindow *qWindow, WId windowId)
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
void setGeometry(const QRect &unscaledGeometry) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
void setParent(const QPlatformWindow *window) override
This function is called to enable native child window in QPA.
bool isForeignWindow() const override
QMargins frameMargins() const override
QOhosPropertiesProvider(QOhosPropertiesStore &store)
std::optional< T > tryGetProperty() const
std::shared_ptr< void > addPropertyWriteCallback(QOhosConsumer< T > propertyWriteCallback)
QOhosPropertiesStore(QObject *qObject)
std::shared_ptr< void > addPropertyWriteCallback(QOhosConsumer< T > propertyWriteCallback)
std::optional< T > tryGetProperty() const
void notifyPropertyWrite(const QByteArray &propertyName)
void setExtraUsageBitsForNativeWindowBuffer(std::uint64_t usageSetBits)
::OHNativeWindow * nativeWindow() const
static constexpr ::OH_NativeBuffer_Format bufferFormat
void paintOnNativeWindowSurface(std::function< std::vector<::Region::Rect >(QImage &, ::BufferHandle *)> paintFunc, std::function< void(::BufferHandle *)> onFlushSuccessFunc)
static std::optional< QSize > tryGetBufferGeometryForWindow(::OHNativeWindow *nativeWindow)
void setNativeWindowSurface(::OHNativeWindow *nativeWindow, const std::optional< QSize > &optSurfaceSize)
static QImage::Format mapNativeBufferFormatToQImageFormatOrFail(std::int32_t format)
std::optional< QSize > surfaceResolution() const
QOhosSurface(::OHNativeWindow *nativeWindow)
EGLSurface tryGetOrCreateEGLWindowSurface(EGLDisplay display, EGLConfig config, bool swappingBuffers)
void clearNativeWindowSurface()
void windowStatusChange(QOhosWindowProxy::WindowStatus windowStatus)
void setParentOrReparent(QOhosView &parentView)
bool consumePendingSelfMinimizeEcho()
void setCursor(const QCursor &cursor)
void handleWindowFlagsChange(Qt::WindowFlags previousWindowFlags, Qt::WindowFlags currentWindowFlags)
void addForeignWindowChild(QOhosForeignWindow *foreignWindow)
void handleWindowStateChange(Qt::WindowStates previousWindowState, Qt::WindowStates currentWindowState)
void setFocusable(bool focusable)
QArkUi::QQtEmbeddedWindowNode::NodeAreaInfo nodeAreaInfo() const
QOhosSurface * surfaceOrNull() const
void windowVisibilityChange(bool visibility)
QList< QRect > displayCutoutRects() const
void setTransparentBackground(bool transparent)
void setModality(Qt::WindowModality modality)
bool isFullscreenImmersiveModeEnabled()
void setFramelessWindow(bool frameless)
QPixmap makeSnapshot() const
void setWindowTransparentForInput(bool transparentForInput)
void tryDetachFromEmbeddedParent()
ViewType viewType() const
QMargins avoidAreaMargins(QOhosWindowProxy::AvoidAreaType type) const
QWindow * ownerWindow() const
void handleSurfaceContentsUpdated()
void windowRectChanged(QOhosWindowProxy::RectChangeOptions rectChangeOptions)
void windowRectChangedInGlobalDisplay(QOhosWindowProxy::RectChangeOptions rectChangeOptions)
void forceGeometryUpdate()
void externalContentInteractionDetected()
void setWindowMinMaxCloseButtonState(const WindowMinMaxCloseButtonsState &state)
void setWindowMask(const QOhosWindowProxy::WindowMask &windowMask)
void setSizeLimits(const QSize &minSize, const QSize &maxSize)
std::optional< QSize > surfaceResolution() const
QHarmonyJsObjectRef abilityObjectRef() const
QOhosView(QWindow *ownerWindow, QSharedPointer< QNativeNode > nativeNode, QOhosPropertiesProvider propertiesProvider, QWindow *optLogicalParent)
void windowTouchOutside()
void nodeAreaChanged(QArkUi::QQtEmbeddedWindowNode::NodeAreaInfo areaChangeEvt)
void handlePaletteChange()
void windowResizeRejected(QSize rejectedSize)
void windowDisplayIdChanged(QOhosDisplayInfo::JsDisplayId)
static std::unique_ptr< QOhosView > createForWindow(QOhosPlatformWindow *window, QOhosPropertiesProvider windowPropertiesProvider)
void setOpacity(qreal opacity)
QHarmonyJsObjectRef jsWindowObjectRef() const
void windowMoveRejected(QPoint rejectedPosition)
void setWindowStaysOnTop(bool staysOnTop)
ViewGeometry viewGeometry() const
void avoidAreaChanged(QOhosWindowProxy::AvoidAreaType avoidAreaType, const QOhosWindowProxy::AvoidArea &avoidArea)
void setSize(const QSize &size)
void setPosition(const QPoint &position)
bool isSubWindowCoveringFullScreen() const
void surfaceStatusChanged(const std::optional< QSize > &optSurfaceSize)
QRect nodeParentRelativeGeometryPixels() const
void setTitle(const QString &title)
void startDrag(const std::vector< QImage > &images, const QPointF &hotspot, const QMimeData &mimeData, QOhosConsumer< Qt::DropAction > dropActionConsumer)
const QOhosView * viewParentOrNull() const
QRect nodeScreenGeometryPixels() const
QtOhosQpa::enums::ohos::window::AvoidAreaType AvoidAreaType
bool sendEvent(WindowSystemEvent *event) override
static JsCallBatch & immediate()
JsScopeDataOwner(const JsScopeDataOwner &)=delete
JsScopeData & operator*() const
JsScopeData * operator->() const
JsScopeDataOwner & operator=(const JsScopeDataOwner &)=delete
void addAsyncCleanup(std::function< void(QOhosJsState &, JsScopeData &, QOhosTaskPromise<>)> cleanupFunc)
JsScopeDataOwner & operator=(JsScopeDataOwner &&)=delete
JsScopeDataOwner(JsScopeDataOwner &&)=delete
Combined button and popup list for selecting options.
@ ForwardToGuiApplication
QOhosView * mapQWindowToViewOrNull(QWindow *window)
std::optional< T > tryMapFromQVariant(QVariant variant)
const char * qObjectOhosPropertyName()
std::shared_ptr< QWindowSystemEventHandler > makeApplicationStateTracker()
QOhosRuntimeDeviceTypeAndMode
@ HandheldDeviceFullScreen
@ HandheldDeviceWindowPcMode
void setQOhosPropertyOnQObject(QObject *qObject, T propertyValue)
std::optional< T > tryGetQOhosPropertyFromQObject(QObject *qObject)
bool disableWindowFocusableBeforeLoadContent
std::optional< QOhosDisplayInfo::JsDisplayId > displayId