4#include "private/qohosplatformtheme_p.h"
25#include <QtCore/qdebug.h>
26#include <QtCore/qthread.h>
27#include <QtCore/private/qnapi_p.h>
28#include <QtGui/private/qeglpbuffer_p.h>
29#include <QtGui/private/qrhibackingstore_p.h>
30#include <QtCore/private/qohoslogger_p.h>
31#include <QtGui/private/qguiapplication_p.h>
32#include <QtCore/qcoreapplication.h>
33#include <qohosdeviceinfo_p.h>
34#include <qohosplugincore.h>
35#include <qohossettings.h>
39#include <qpa/qwindowsysteminterface.h>
40#include <qpa/qplatforminputcontextfactory_p.h>
41#include <QtCore/qset.h>
47#include "qohosplatformvulkaninstance.h"
56 auto devSources = QNapi::getArrayElements<std::vector<std::string>, QNapi::String>(
57 jsState.eval<QNapi::Array>(
58 "@ohos.multimodalInput.inputDevice.getDeviceInfoSync(*).sources",
60 return std::find(devSources.begin(), devSources.end(), type) != devSources.end();
65 return isInputDeviceOfType(jsState, deviceId,
"touchscreen");
70 return isInputDeviceOfType(jsState, deviceId,
"touchpad");
75 return isInputDeviceOfType(jsState, deviceId,
"mouse");
79 QtOhos::
JsState &jsState,
const std::vector<std::uint32_t> &deviceIds,
83 deviceIds.begin(), deviceIds.end(),
84 [&](
std::uint32_t deviceId) {
85 return isDeviceTypeFunc(jsState, deviceId);
91 return QtOhos::evalInJsThreadWithPromise<std::set<QInputDevice::DeviceType>>(
92 [](QtOhos::JsState &jsState, QOhosTaskPromise<std::set<QInputDevice::DeviceType>> evalPromise) {
93 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
94 jsState.evalToPromiseOrRejectOnThrow(
"@ohos.multimodalInput.inputDevice.getDeviceList()")
96 [thenPromise = std::move(thenCatchPromises.first)](
const QtOhos::CallbackInfo &cbInfo) {
97 auto deviceIdsJsArray = cbInfo.getFirstArg<QNapi::Array>(Q_FUNC_INFO);
98 auto deviceIds = QNapi::getArrayElements<std::vector<std::uint32_t>, QNapi::Number>(deviceIdsJsArray);
99 std::set<QInputDevice::DeviceType> deviceTypes;
100 if (isDeviceTypeInDeviceIds(cbInfo.jsState(), deviceIds, isInputDeviceWithTouchscreen))
101 deviceTypes.insert(QInputDevice::DeviceType::TouchScreen);
102 if (isDeviceTypeInDeviceIds(cbInfo.jsState(), deviceIds, isInputDeviceWithTouchpad))
103 deviceTypes.insert(QInputDevice::DeviceType::TouchPad);
104 if (isDeviceTypeInDeviceIds(cbInfo.jsState(), deviceIds, isInputDeviceWithMouse))
105 deviceTypes.insert(QInputDevice::DeviceType::Mouse);
106 thenPromise(deviceTypes);
109 [catchPromise = std::move(thenCatchPromises.second)](
const QtOhos::CallbackInfo &) {
111 "Error while obtaining device list (@ohos.multimodalInput.inputDevice.getDeviceList()). "
112 "No pointing devices will be pre-registered; every device will instead be lazily "
113 "created and registered on first use.");
128 return static_cast<QOhosPlatformIntegration *>(QGuiApplicationPrivate::platformIntegration());
134 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::QOhosPlatformIntegration");
135 m_settingsCacheHandle = QOhosSettings::instance().installSettingsCache();
136 m_ohosPlatformNativeInterface.reset(
new QOhosPlatformNativeInterface());
139 auto rawDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
140 if (Q_UNLIKELY(rawDisplay == EGL_NO_DISPLAY))
141 qOhosReportFatalErrorAndAbort(
"Could not open egl display");
145 if (Q_UNLIKELY(!eglInitialize(rawDisplay, &major, &minor)))
146 qOhosReportFatalErrorAndAbort(
"Could not initialize egl display");
148 m_eglDisplay = std::shared_ptr<EGLDisplay>(
149 new EGLDisplay(rawDisplay),
155 if (Q_UNLIKELY(!eglBindAPI(EGL_OPENGL_ES_API)))
156 qOhosReportFatalErrorAndAbort(
"Could not bind GL_ES API");
159 if (!QtOhos::isOhosNoUiChildMode())
160 m_screenManager = std::make_unique<QOhosScreenManager>();
162 m_mainThread = QThread::currentThread();
164 m_ohosFDB = std::make_unique<QOhosPlatformFontDatabase>();
165 m_ohosPlatformServices = std::make_unique<QOhosPlatformServices>();
166 if (!QtOhos::isOhosNoUiChildMode())
167 m_ohosInputMethodEventHandler = std::make_unique<QOhosInputMethodEventHandler>(getAvailableDeviceTypes());
169#ifndef QT_NO_CLIPBOARD
170 if (!QtOhos::isOhosNoUiChildMode())
171 m_platformClipboard = std::make_unique<QOhosPlatformClipboard>();
174#if QT_CONFIG(draganddrop)
175 if (!QtOhos::isOhosNoUiChildMode())
176 m_drag = makeQOhosPlatformDrag();
179 QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(
false);
182 QCoreApplication::postEvent(m_ohosPlatformNativeInterface.data(),
new QEvent(QEvent::User));
187 return m_ohosInputMethodEventHandler.get();
197 if (hint == ShowIsMaximized)
199 return QPlatformIntegration::styleHint(hint);
205 if ((flags & Qt::Dialog & ~Qt::Window) != 0)
206 return Qt::WindowNoState;
208 return QPlatformIntegration::defaultWindowState(flags);
213 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::createPlatformWindow");
215 static const QSet<QString> nativeDialogClass = {
216 QString::fromUtf8(
"QFileDialogClassWindow"),
220 if (window !=
nullptr && !nativeDialogClass.contains(window->objectName()))
227 return new QOhosForeignWindow(window, windowId);
232 return m_ohosFDB.get();
235#ifndef QT_NO_CLIPBOARD
238 return m_platformClipboard.get();
242#if QT_CONFIG(draganddrop)
243QPlatformDrag *QOhosPlatformIntegration::drag()
const
251 std::unique_ptr<QPlatformBackingStore> result;
252 switch (window->surfaceType()) {
253 case QSurface::RasterSurface:
257 result = QtOhos::isGlBackingStoreDefaultEnabled()
258 ? makeGlOhosPlatformBackingStore(window)
259 : std::make_unique<QOhosPlatformBackingStore>(
261 QOhosPlatformBackingStore::CreateInfo{
262 .debugDrawFlushedRegion = QtOhos::isDebugDrawQtRasterBackingStoreFlushedRegionEnabled(),
263 .enableVsync = QtOhos::isVsyncOnSoftwareBackingStoreEnabled(),
266 case QSurface::OpenGLSurface:
267 case QSurface::VulkanSurface:
268 result = std::make_unique<QRhiBackingStore>(window);
270 case QSurface::OpenVGSurface:
271 case QSurface::MetalSurface:
272 case QSurface::Direct3DSurface:
273 qOhosReportFatalErrorAndAbort(
"Unsupported window surface type for backing store: %d", window->surfaceType());
277 return result.release();
282 QSurfaceFormat format = context->format();
283 format.setRedBufferSize(8);
284 format.setGreenBufferSize(8);
285 format.setBlueBufferSize(8);
286 format.setAlphaBufferSize(8);
287 auto *eglCtx =
new QOhosEGLPlatformContext(format, context->shareHandle(), *m_eglDisplay);
293 return QEGLPlatformContext::createFrom<QOhosEGLPlatformContext>(context, display, *m_eglDisplay, shareContext);
297QPlatformOffscreenSurface *
300 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::createPlatformOffscreenSurface");
301 return new QEGLPbuffer(*m_eglDisplay, surface->requestedFormat(), surface);
306 qOhosDebug(QtForOhos) <<
"QOhosPlatformIntegration::hasCapability:" << cap;
309 case ApplicationState:
return true;
310 case ThreadedPixmaps:
return true;
315 case OffscreenSurface:
return true;
318 case OpenGLOnRasterSurface: {
319 return (QOhosDeviceInfo::getProperty(QOhosDeviceInfo::Type::productModel).toString() == QString::fromUtf8(
"emulator"));
321 case MultipleWindows:
return true;
322 case WindowManagement:
323 case NonFullScreenWindows:
325 case TopStackedNativeChildWindows:
return false;
327 return QPlatformIntegration::hasCapability(cap);
333 return m_platformInputContext.data();
338 auto d = make_QCScopedDebug(
"QOhosPlatformIntegration::initialize");
339 const auto requestedInputContext = QPlatformInputContextFactory::requested();
340 if (requestedInputContext.isEmpty()) {
342 m_platformInputContext.reset(context);
344 m_platformInputContext.reset(QPlatformInputContextFactory::create(requestedInputContext));
347 if (QWindowSystemInterfacePrivate::eventHandler !=
nullptr)
348 qOhosReportFatalErrorAndAbort(
"QWindowSystemInterfacePrivate::eventHandler was already registered.");
350 auto tracker = makeApplicationStateTracker();
351 QWindowSystemInterfacePrivate::installWindowSystemEventHandler(tracker.get());
352 m_applicationStateTracker = QtOhos::makeDestroyNotifier(
353 [tracker = std::move(tracker)]() {
354 QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(tracker.get());
360 if (QtOhos::isDebugUseBasicStyleAndThemeEnabled())
361 return std::make_unique<QPlatformTheme>().release();
363 if (name == QString::fromUtf8(ohosThemeName))
370 return {QString::fromUtf8(ohosThemeName)};
380 return m_systemLocale.data();
385 m_systemLocale.reset(systemLocale);
391 m_mainWindowPersistencePolicy = policy;
396 const auto policy = !enabled.has_value()
406 return m_mainWindowPersistencePolicy;
411 return m_ohosPlatformServices.get();
416 return m_ohosPlatformNativeInterface.get();
421 return m_screenManager.get();
426QPlatformVulkanInstance *QOhosPlatformIntegration::createPlatformVulkanInstance(
427 QVulkanInstance *instance)
const
429 return new QOhosPlatformVulkanInstance(instance);
bool isWindowPcModeEnabled() const
static QOhosSettings & instance()
bool isInputDeviceWithMouse(QtOhos::JsState &jsState, std::uint32_t deviceId)
std::set< QInputDevice::DeviceType > getAvailableDeviceTypes()
bool isDeviceTypeInDeviceIds(QtOhos::JsState &jsState, const std::vector< std::uint32_t > &deviceIds, const std::function< bool(QtOhos::JsState &, std::uint32_t)> &isDeviceTypeFunc)
bool isInputDeviceWithTouchscreen(QtOhos::JsState &jsState, std::uint32_t deviceId)
bool isInputDeviceOfType(QtOhos::JsState &jsState, std::uint32_t deviceId, const std::string &type)
bool isInputDeviceWithTouchpad(QtOhos::JsState &jsState, std::uint32_t deviceId)
bool isOhosNoUiChildMode()