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>
48#include "qohosplatformvulkaninstance.h"
57 auto devSources = QNapi::getArrayElements<std::vector<std::string>, QNapi::String>(
58 jsState.eval<QNapi::Array>(
59 "@ohos.multimodalInput.inputDevice.getDeviceInfoSync(*).sources",
61 return std::find(devSources.begin(), devSources.end(), type) != devSources.end();
66 return isInputDeviceOfType(jsState, deviceId,
"touchscreen");
71 return isInputDeviceOfType(jsState, deviceId,
"touchpad");
76 return isInputDeviceOfType(jsState, deviceId,
"mouse");
80 QtOhos::
JsState &jsState,
const std::vector<std::uint32_t> &deviceIds,
84 deviceIds.begin(), deviceIds.end(),
85 [&](
std::uint32_t deviceId) {
86 return isDeviceTypeFunc(jsState, deviceId);
92 return QtOhos::evalInJsThreadWithPromise<std::set<QInputDevice::DeviceType>>(
93 [](QtOhos::JsState &jsState, QOhosTaskPromise<std::set<QInputDevice::DeviceType>> evalPromise) {
94 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
95 jsState.evalToPromiseOrRejectOnThrow(
"@ohos.multimodalInput.inputDevice.getDeviceList()")
97 [thenPromise = std::move(thenCatchPromises.first)](
const QtOhos::CallbackInfo &cbInfo) {
98 auto deviceIdsJsArray = cbInfo.getFirstArg<QNapi::Array>(Q_FUNC_INFO);
99 auto deviceIds = QNapi::getArrayElements<std::vector<std::uint32_t>, QNapi::Number>(deviceIdsJsArray);
100 std::set<QInputDevice::DeviceType> deviceTypes;
101 if (isDeviceTypeInDeviceIds(cbInfo.jsState(), deviceIds, isInputDeviceWithTouchscreen))
102 deviceTypes.insert(QInputDevice::DeviceType::TouchScreen);
103 if (isDeviceTypeInDeviceIds(cbInfo.jsState(), deviceIds, isInputDeviceWithTouchpad))
104 deviceTypes.insert(QInputDevice::DeviceType::TouchPad);
105 if (isDeviceTypeInDeviceIds(cbInfo.jsState(), deviceIds, isInputDeviceWithMouse))
106 deviceTypes.insert(QInputDevice::DeviceType::Mouse);
107 thenPromise(deviceTypes);
110 [catchPromise = std::move(thenCatchPromises.second)](
const QtOhos::CallbackInfo &) {
112 "Error while obtaining device list (@ohos.multimodalInput.inputDevice.getDeviceList()). "
113 "No pointing devices will be pre-registered; every device will instead be lazily "
114 "created and registered on first use.");
129 return static_cast<QOhosPlatformIntegration *>(QGuiApplicationPrivate::platformIntegration());
135 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::QOhosPlatformIntegration");
136 m_settingsCacheHandle = QOhosSettings::instance().installSettingsCache();
137 m_ohosPlatformNativeInterface.reset(
new QOhosPlatformNativeInterface());
140 auto rawDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
141 if (Q_UNLIKELY(rawDisplay == EGL_NO_DISPLAY))
142 qOhosReportFatalErrorAndAbort(
"Could not open egl display");
146 if (Q_UNLIKELY(!eglInitialize(rawDisplay, &major, &minor)))
147 qOhosReportFatalErrorAndAbort(
"Could not initialize egl display");
149 m_eglDisplay = std::shared_ptr<EGLDisplay>(
150 new EGLDisplay(rawDisplay),
156 if (Q_UNLIKELY(!eglBindAPI(EGL_OPENGL_ES_API)))
157 qOhosReportFatalErrorAndAbort(
"Could not bind GL_ES API");
160 if (!QtOhos::isOhosNoUiChildMode())
161 m_screenManager = std::make_unique<QOhosScreenManager>();
163 m_mainThread = QThread::currentThread();
165 m_ohosFDB = std::make_unique<QOhosPlatformFontDatabase>();
166 m_ohosPlatformServices = std::make_unique<QOhosPlatformServices>();
167 if (!QtOhos::isOhosNoUiChildMode())
168 m_ohosInputMethodEventHandler = std::make_unique<QOhosInputMethodEventHandler>(getAvailableDeviceTypes());
170#ifndef QT_NO_CLIPBOARD
171 if (!QtOhos::isOhosNoUiChildMode())
172 m_platformClipboard = std::make_unique<QOhosPlatformClipboard>();
175#if QT_CONFIG(draganddrop)
176 if (!QtOhos::isOhosNoUiChildMode())
177 m_drag = makeQOhosPlatformDrag();
180 QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(
false);
183 QCoreApplication::postEvent(m_ohosPlatformNativeInterface.data(),
new QEvent(QEvent::User));
188 return m_ohosInputMethodEventHandler.get();
198 if (hint == ShowIsMaximized)
200 return QPlatformIntegration::styleHint(hint);
206 if ((flags & Qt::Dialog & ~Qt::Window) != 0)
207 return Qt::WindowNoState;
209 return QPlatformIntegration::defaultWindowState(flags);
214 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::createPlatformWindow");
216 static const QSet<QString> nativeDialogClass = {
217 QString::fromUtf8(
"QFileDialogClassWindow"),
221 if (window !=
nullptr && !nativeDialogClass.contains(window->objectName()))
228 return new QOhosForeignWindow(window, windowId);
233 return m_ohosFDB.get();
236#ifndef QT_NO_CLIPBOARD
239 return m_platformClipboard.get();
243#if QT_CONFIG(draganddrop)
244QPlatformDrag *QOhosPlatformIntegration::drag()
const
252 std::unique_ptr<QPlatformBackingStore> result;
253 switch (window->surfaceType()) {
254 case QSurface::RasterSurface:
258 result = QtOhos::isGlBackingStoreDefaultEnabled()
259 ? makeGlOhosPlatformBackingStore(window)
260 : std::make_unique<QOhosPlatformBackingStore>(
262 QOhosPlatformBackingStore::CreateInfo{
263 .debugDrawFlushedRegion = QtOhos::isDebugDrawQtRasterBackingStoreFlushedRegionEnabled(),
264 .enableVsync = QtOhos::isVsyncOnSoftwareBackingStoreEnabled(),
267 case QSurface::OpenGLSurface:
268 case QSurface::VulkanSurface:
269 result = std::make_unique<QRhiBackingStore>(window);
271 case QSurface::OpenVGSurface:
272 case QSurface::MetalSurface:
273 case QSurface::Direct3DSurface:
274 qOhosReportFatalErrorAndAbort(
"Unsupported window surface type for backing store: %d", window->surfaceType());
278 return result.release();
283 QSurfaceFormat format = context->format();
284 format.setRedBufferSize(8);
285 format.setGreenBufferSize(8);
286 format.setBlueBufferSize(8);
287 format.setAlphaBufferSize(8);
288 auto *eglCtx =
new QOhosEGLPlatformContext(format, context->shareHandle(), *m_eglDisplay);
294 return QEGLPlatformContext::createFrom<QOhosEGLPlatformContext>(context, display, *m_eglDisplay, shareContext);
298QPlatformOffscreenSurface *
301 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::createPlatformOffscreenSurface");
302 return new QEGLPbuffer(*m_eglDisplay, surface->requestedFormat(), surface);
307 qOhosDebug(QtForOhos) <<
"QOhosPlatformIntegration::hasCapability:" << cap;
310 case ApplicationState:
return true;
311 case ThreadedPixmaps:
return true;
316 case OffscreenSurface:
return true;
319 case OpenGLOnRasterSurface: {
320 return (QOhosDeviceInfo::getProperty(QOhosDeviceInfo::Type::productModel).toString() == QString::fromUtf8(
"emulator"));
322 case MultipleWindows:
return true;
323 case WindowManagement:
324 case NonFullScreenWindows:
326 case TopStackedNativeChildWindows:
return false;
328 return QPlatformIntegration::hasCapability(cap);
334 return m_platformInputContext.data();
339 auto d = make_QCScopedDebug(
"QOhosPlatformIntegration::initialize");
340 const auto requestedInputContext = QPlatformInputContextFactory::requested();
341 if (requestedInputContext.isEmpty()) {
343 m_platformInputContext.reset(context);
345 m_platformInputContext.reset(QPlatformInputContextFactory::create(requestedInputContext));
348 if (QWindowSystemInterfacePrivate::eventHandler !=
nullptr)
349 qOhosReportFatalErrorAndAbort(
"QWindowSystemInterfacePrivate::eventHandler was already registered.");
351 auto tracker = makeApplicationStateTracker();
352 QWindowSystemInterfacePrivate::installWindowSystemEventHandler(tracker.get());
353 m_applicationStateTracker = QtOhos::makeDestroyNotifier(
354 [tracker = std::move(tracker)]() {
355 QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(tracker.get());
361 if (QtOhos::isDebugUseBasicStyleAndThemeEnabled())
362 return std::make_unique<QPlatformTheme>().release();
364 if (name == QString::fromUtf8(ohosThemeName))
371 return {QString::fromUtf8(ohosThemeName)};
381 return m_systemLocale.data();
386 m_systemLocale.reset(systemLocale);
392 m_mainWindowPersistencePolicy = policy;
397 const auto policy = !enabled.has_value()
407 return m_mainWindowPersistencePolicy;
412 return m_ohosPlatformServices.get();
417 return m_ohosPlatformNativeInterface.get();
422 return m_screenManager.get();
427QPlatformVulkanInstance *QOhosPlatformIntegration::createPlatformVulkanInstance(
428 QVulkanInstance *instance)
const
430 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()