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
qohosplatformbackingstore.h
Go to the documentation of this file.
1// Copyright (C) 2025 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#ifndef QOHOSPLATFORMBACKINGSTORE_H
5#define QOHOSPLATFORMBACKINGSTORE_H
6
7#include <qohosplatformwindow.h>
8#include <qohosplugincore.h>
9#include <QtCore/private/qohoscommon_p.h>
10#include <QtCore/qspan.h>
11#include <QtGui/qimage.h>
12#include <qpa/qplatformbackingstore.h>
13#include <qpa/qwindowsysteminterface.h>
14#include <QtGui/private/qrasterbackingstore_p.h>
15#include <QtOpenGL/QOpenGLPaintDevice>
16#include <QOpenGLContext>
17#include <QScopedPointer>
18#include <cstddef>
19#include <deque>
20#include <functional>
21#include <memory>
22#include <native_window/buffer_handle.h>
23#include <native_window/external_window.h>
24#include <unordered_map>
25#include <utility>
26
27
28QT_BEGIN_NAMESPACE
29
30class QOhosPlatformBackingStore final : public QRasterBackingStore
31{
32public:
33 class QImageView
34 {
35 public:
36 explicit QImageView(const QImage &srcImage, const QRect &subRect);
37
38 QSize size() const;
39 std::size_t bytesPerPixel() const;
40 std::size_t bytesPerLine() const;
41 QSpan<const uchar> constScanLine(int i) const;
42 private:
43 const QImage m_srcImage;
44 QRect m_subRect;
45 };
46
47 class BufferRegionHandler
48 {
49 public:
50 BufferRegionHandler(::OHNativeWindow *nativeWindow);
51
52 QOhosOptional<QRegion> mergeRegionForBufferHandle(::BufferHandle *bufferHandle, QRegion region) const;
53 void storeRegionForBufferHandle(::BufferHandle *bufferHandle, const QRegion &region);
54
55 private:
56 std::uint64_t m_bufferQueueSize {0};
57 std::uint64_t m_flushSequenceId {0};
58 std::unordered_map<::BufferHandle *, std::uint64_t> m_buffersToFlushSequenceIds;
59 std::deque<QRegion> m_lastFlushedRegions;
60 };
61
62 class FlushData
63 {
64 public:
65 explicit FlushData(std::function<void()> flushRequestFunc);
66
67 void updateDirtyRegionAndScheduleFlush(const QRegion &region, const QPoint &rootWindowOffset);
68 std::pair<QRegion, QPoint> fetchAndReset();
69
70 private:
71 std::function<void()> m_flushRequestFunc;
72 QRegion m_mergedRegionForFlush;
73 QPoint m_lastWindowOffset;
74 };
75
76 class WindowContext
77 {
78 public:
79 explicit WindowContext(
80 ::OHNativeWindow *nativeWindow, std::function<void()> flushRequestFunc);
81
82 BufferRegionHandler &bufferRegionHandler();
83 FlushData &flushData();
84
85 private:
86 std::unique_ptr<BufferRegionHandler> m_bufferRegionHandler;
87 FlushData m_flushData;
88 };
89
90 class WindowContextManager
91 {
92 public:
93 WindowContextManager(bool vsyncEnabled, std::function<void(QWindow *)> flushImmediateFunc);
94
95 WindowContext &getOrCreateWindowContext(QWindow *window, ::OHNativeWindow *nativeWindow);
96
97 private:
98 std::unordered_map<QWindow *, std::unique_ptr<WindowContext>> m_windowContexts;
99 std::shared_ptr<std::function<void(QWindow *)>> m_flushFunc;
100 bool m_vsyncEnabled;
101 };
102
103 struct CreateInfo
104 {
105 bool debugDrawFlushedRegion = false;
106 bool enableVsync = false;
107 };
108
109 explicit QOhosPlatformBackingStore(QWindow *window, const CreateInfo &createInfo);
110 void resize(const QSize &size, const QRegion &staticContents) override;
111 void flush(QWindow *window, const QRegion &region, const QPoint &offset) final;
112 QImage::Format format() const override;
113 bool scroll(const QRegion &area, int dx, int dy) override;
114
115private:
116 void flushImmediate(QWindow *window);
117
118 std::function<void()> m_windowBufferFlushedCallback;
119 bool m_debugDrawFlushedRegion {false};
120 bool m_vsyncEnabled {false};
121 WindowContextManager m_windowContextManager;
122 bool m_reinitializeContextManager{false};
123};
124
125QT_END_NAMESPACE
126
127#endif // QOHOSPLATFORMBACKINGSTORE_H
QOhosFloatingWindow(QWindow *window)
~QOhosFloatingWindow() override
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
bool startSystemMove() override
Reimplement this method to start a system move operation if the system supports it and return true to...
QOhosView * ownedViewOrNull() const override
void onWindowStateChanged(Qt::WindowStates oldWindowState, Qt::WindowStates currentWindowState) override
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void onWindowFlagsChanged(Qt::WindowFlags previousWindowFlags, Qt::WindowFlags currentWindowFlags) override
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
QOhosSurface * ownedSurfaceOrNull() const override
void setMask(const QRegion &region) override
Reimplement to be able to let Qt set the mask of a window.
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
void update(Qt::InputMethodQueries queries) override
Notification on editor updates.
QRectF keyboardRect() const override
This function can be reimplemented to return virtual keyboard rectangle in currently active window co...
void setSoftwareKeyboardVisibilityStatus(bool visible)
void showInputPanel() override
Request to show input panel.
void invokeAction(QInputMethod::Action action, int cursorPosition) override
Called when the word currently being composed in the input item is tapped by the user.
void setLastInputTypeToTriggerSoftKeyboard(RequestKeyboardReason inputType)
void reset() override
Method to be called when input method needs to be reset.
void hideInputPanel() override
Request to hide input panel.
bool isValid() const override
Returns input context validity.
bool eventFilter(QObject *obj, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
bool isInputPanelVisible() const override
Returns input panel visibility status.
QObject * focusObjectOrNull() const
void setFocusObject(QObject *object) override
This virtual method gets called to notify updated focus to object.
bool isAnimating() const override
This function can be reimplemented to return true whenever input method is animating shown or hidden.
void onMouseWheelEvent(const QOhosWheelEvent &event, QWindow *window)
void onNonClientAreaTouchEvents(QWindow *targetWindow, std::vector< QOhosWindowProxy::NonClientAreaTouchEvent > eventBatch)
void onGestureEventFromNativeNode(QWindow *targetWindow, std::int64_t timestamp, qreal value, QPointF localPosition, QPointF screenPosition, Qt::NativeGestureType gestureType, QInputDevice::DeviceType deviceType)
void onMouseEvent(const QOhosMouseEvent &mouseEvent)
void onTouchEventFromJsWindow(QWindow *optTargetWindow, const QList< QWindowSystemInterface::TouchPoint > &touchPoints)
void onTouchEventFromXComponent(QWindow *targetWindow, std::chrono::nanoseconds timeStamp, const std::vector< QOhosTouchEventTouchPointData > &touchPoints, QInputDevice::DeviceType deviceType)
void onHoverEvent(bool isHover, const QPointF &local, const QPointF &global, QWindow *window)
void onNonClientAreaMouseEvents(QWindow *targetWindow, std::vector< QOhosWindowProxy::NonClientAreaMouseEvent > eventBatch)
void onKeyEvent(const QOhosKeyEvent &keyEvent, QWindow *targetWindow)
virtual bool equals(const QOhosKeyEvent &other) const =0
virtual QOhosOptional< QOhosQtKeyEvent > tryConvertToQOhosQtKeyEvent() const =0
virtual ~QOhosKeyEvent()
std::enable_if_t< qohosplugincore_h_detail::isQOhosOptional< QOhosInvokeResult< Func, T > >, QOhosInvokeResult< Func, T > > andThen(Func &&func) const
bool ownsMode(QClipboard::Mode mode) const override
virtual ~QOhosPlatformClipboard()
std::shared_ptr< QMimeData > getPasteboardDataWithLazyFetchOrLocalIfOwner() const
QMimeData * mimeData(QClipboard::Mode mode=QClipboard::Clipboard) override
static void setInAppOnlyPasteboardShareOption(bool shareInAppOnly)
void setMimeData(QMimeData *mimeData, QClipboard::Mode mode=QClipboard::Clipboard) override
bool supportsMode(QClipboard::Mode mode) const override
static void setMainWindowGeometryPersistencePolicy(WindowGeometryPersistencePolicy policy)
QOhosScreenManager * screenManager() const
QPlatformOpenGLContext * createPlatformOpenGLContext(QOpenGLContext *context) const override
Factory function for QPlatformOpenGLContext.
QOhosPlatformClipboard * clipboard() const override
Accessor for the platform integration's clipboard.
QPlatformOffscreenSurface * createPlatformOffscreenSurface(QOffscreenSurface *surface) const override
Factory function for QOffscreenSurface.
static void setDefaultDisplayMetrics(const QOhosDisplayInfo &m_displayInfo)
bool hasCapability(Capability cap) const override
QPlatformInputContext * inputContext() const override
Returns the platforms input context.
QPlatformFontDatabase * fontDatabase() const override
Accessor for the platform integration's fontdatabase.
QPlatformServices * services() const override
QPlatformNativeInterface * nativeInterface() const override
QOpenGLContext * createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const override
QPlatformWindow * createPlatformWindow(QWindow *window) const override
Factory function for QPlatformWindow.
static QOhosPlatformIntegration * instance()
QPlatformTheme * createPlatformTheme(const QString &name) const override
QVariant styleHint(StyleHint hint) const override
QStringList themeNames() const override
static WindowGeometryPersistencePolicy getMainWindowGeometryPersistencePolicy()
Qt::WindowState defaultWindowState(Qt::WindowFlags flags) const override
QPlatformWindow * createForeignWindow(QWindow *, WId) const override
QOhosInputMethodEventHandler * inputMethodEventHandler() const
QPlatformBackingStore * createPlatformBackingStore(QWindow *window) const override
Factory function for QPlatformBackingStore.
QOhosPlatformIntegration(const QStringList &paramList)
QAbstractEventDispatcher * createEventDispatcher() const override
Factory function for the GUI event dispatcher.
void initialize() override
Performs initialization steps that depend on having an event dispatcher available.
static QOhosSystemLocale * systemLocale()
static void setSystemLocale(QOhosSystemLocale *systemLocale)
void setDisplayIdFromOhos(QOhosOptional< QOhosDisplayInfo::JsDisplayId > displayId)
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void notifyInputSystemsWindowActiveStatusChanged(bool active)
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
QOhosPlatformScreen * platformScreenForDisplayIdOrNull(QOhosDisplayInfo::JsDisplayId displayId) const
QOhosPlatformScreen * platformScreenForDisplayIdOrFail(QOhosDisplayInfo::JsDisplayId displayId) const
QOhosSurface * surfaceOrNull() const
void setWindowMask(const QOhosWindowProxy::WindowMask &windowMask)
void lower()
ViewGeometry viewGeometry() const
bool startMoving()
bool isSubWindowCoveringFullScreen() const
void raise()
static QWindowProxyRegistry & instance()
bool isWindowPcModeEnabled()
Combined button and popup list for selecting options.
bool isWindowRotatedByTabletScreenRotation(QWindow *window, QOhosWindowProxy::RectChangeOptions rectChangeOptions)
Qt::KeyboardModifiers convertOhosToQtKeyboardModifiers(QFlags< OhosKeyboardModifier > ohosKeysModifiers)
QFlags< OhosKeyboardModifier > readKeyModifiersFromKeyState(QSpan< const OhosKeyToModifier > keysToModifiers)
QFlags< OhosKeyboardModifier > readKeyModifiersFromOhosUiInputEvent(::ArkUI_UIInputEvent *uiInputEvent)
OhosKeyboardModifier
QOhosRuntimeDeviceTypeAndMode queryQOhosRuntimeDeviceAndMode()
::Input_KeyStateAction keyStateActionKeyActive
std::vector<::Input_KeyCode > keysToCheck
std::int32_t(* getKeyStateActionFunc)(const ::Input_KeyState *)
OhosKeyboardModifier modifier
QFlags< OhosKeyboardModifier > modifiers
QPointer< QWindow > targetWindow
std::chrono::milliseconds timestampMs
Qt::KeyboardModifiers modifiers
QEvent::Type keyAction
Qt::KeyboardModifiers guiApplicationKeyboardModifiers
quint32 nativeKeyCode
QOhosConsumer< QtOhos::JsState &, JsDisplayId > displayAddedCb
QOhosConsumer< QtOhos::JsState &, JsDisplayId, QRectF > displayAvailableAreaChangedCb
QOhosConsumer< QtOhos::JsState &, JsDisplayId > displayRemovedCb
std::vector< QOhosDisplayInfo > displayInfos
QOhosConsumer< QtOhos::JsState &, JsDisplayId > displayChangedCb
::OH_NativeXComponent_TouchPoint touchPoint
QFlags< OhosKeyboardModifier > modifiers