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");
75 QtOhos::
JsState &jsState,
const std::vector<std::uint32_t> &deviceIds,
79 deviceIds.begin(), deviceIds.end(),
80 [&](
std::uint32_t deviceId) {
81 return isDeviceTypeFunc(jsState, deviceId);
87 return QtOhos::evalInJsThreadWithPromise<std::set<QInputDevice::DeviceType>>(
88 [](QtOhos::JsState &jsState, QOhosTaskPromise<std::set<QInputDevice::DeviceType>> evalPromise) {
89 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
90 jsState.evalToPromiseOrRejectOnThrow(
"@ohos.multimodalInput.inputDevice.getDeviceList()")
92 [thenPromise = std::move(thenCatchPromises.first)](
const QtOhos::CallbackInfo &cbInfo) {
93 auto deviceIdsJsArray = cbInfo.getFirstArg<QNapi::Array>(Q_FUNC_INFO);
94 auto deviceIds = QNapi::getArrayElements<std::vector<std::uint32_t>, QNapi::Number>(deviceIdsJsArray);
95 std::set<QInputDevice::DeviceType> deviceTypes;
96 if (isDeviceTypeInDeviceIds(cbInfo.jsState(), deviceIds, isInputDeviceWithTouchscreen))
97 deviceTypes.insert(QInputDevice::DeviceType::TouchScreen);
98 if (isDeviceTypeInDeviceIds(cbInfo.jsState(), deviceIds, isInputDeviceWithTouchpad))
99 deviceTypes.insert(QInputDevice::DeviceType::TouchPad);
100 thenPromise(deviceTypes);
103 [catchPromise = std::move(thenCatchPromises.second)](
const QtOhos::CallbackInfo &) {
104 qOhosPrintfError(
"Error while obtaining device list (@ohos.multimodalInput.inputDevice.getDeviceList())");
119 return static_cast<QOhosPlatformIntegration *>(QGuiApplicationPrivate::platformIntegration());
125 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::QOhosPlatformIntegration");
126 m_ohosPlatformNativeInterface.reset(
new QOhosPlatformNativeInterface());
129 auto rawDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
130 if (Q_UNLIKELY(rawDisplay == EGL_NO_DISPLAY))
131 qOhosReportFatalErrorAndAbort(
"Could not open egl display");
135 if (Q_UNLIKELY(!eglInitialize(rawDisplay, &major, &minor)))
136 qOhosReportFatalErrorAndAbort(
"Could not initialize egl display");
138 m_eglDisplay = std::shared_ptr<EGLDisplay>(
139 new EGLDisplay(rawDisplay),
145 if (Q_UNLIKELY(!eglBindAPI(EGL_OPENGL_ES_API)))
146 qOhosReportFatalErrorAndAbort(
"Could not bind GL_ES API");
149 if (!QtOhos::isOhosNoUiChildMode())
150 m_screenManager = std::make_unique<QOhosScreenManager>();
152 m_mainThread = QThread::currentThread();
154 m_ohosFDB = std::make_unique<QOhosPlatformFontDatabase>();
155 m_ohosPlatformServices = std::make_unique<QOhosPlatformServices>();
156 if (!QtOhos::isOhosNoUiChildMode())
157 m_ohosInputMethodEventHandler = std::make_unique<QOhosInputMethodEventHandler>(getAvailableDeviceTypes());
159#ifndef QT_NO_CLIPBOARD
160 if (!QtOhos::isOhosNoUiChildMode())
161 m_platformClipboard = std::make_unique<QOhosPlatformClipboard>();
164#if QT_CONFIG(draganddrop)
165 if (!QtOhos::isOhosNoUiChildMode())
166 m_drag = makeQOhosPlatformDrag();
169 QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(
false);
172 QCoreApplication::postEvent(m_ohosPlatformNativeInterface.data(),
new QEvent(QEvent::User));
177 return m_ohosInputMethodEventHandler.get();
187 if (hint == ShowIsMaximized)
189 return QPlatformIntegration::styleHint(hint);
195 if ((flags & Qt::Dialog & ~Qt::Window) != 0)
196 return Qt::WindowNoState;
198 return QPlatformIntegration::defaultWindowState(flags);
203 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::createPlatformWindow");
205 static const QSet<QString> nativeDialogClass = {
206 QString::fromUtf8(
"QFileDialogClassWindow"),
210 if (window !=
nullptr && !nativeDialogClass.contains(window->objectName()))
217 return new QOhosForeignWindow(window, windowId);
222 return m_ohosFDB.get();
225#ifndef QT_NO_CLIPBOARD
228 return m_platformClipboard.get();
232#if QT_CONFIG(draganddrop)
233QPlatformDrag *QOhosPlatformIntegration::drag()
const
241 std::unique_ptr<QPlatformBackingStore> result;
242 switch (window->surfaceType()) {
243 case QSurface::RasterSurface:
247 result = QtOhos::isGlBackingStoreDefaultEnabled()
248 ? makeGlOhosPlatformBackingStore(window)
249 : std::make_unique<QOhosPlatformBackingStore>(
251 QOhosPlatformBackingStore::CreateInfo{
252 .debugDrawFlushedRegion = QtOhos::isDebugDrawQtRasterBackingStoreFlushedRegionEnabled(),
253 .enableVsync = QtOhos::isVsyncOnSoftwareBackingStoreEnabled(),
256 case QSurface::OpenGLSurface:
257 case QSurface::VulkanSurface:
258 result = std::make_unique<QRhiBackingStore>(window);
260 case QSurface::OpenVGSurface:
261 case QSurface::MetalSurface:
262 case QSurface::Direct3DSurface:
263 qOhosReportFatalErrorAndAbort(
"Unsupported window surface type for backing store: %d", window->surfaceType());
267 return result.release();
272 QSurfaceFormat format = context->format();
273 format.setRedBufferSize(8);
274 format.setGreenBufferSize(8);
275 format.setBlueBufferSize(8);
276 format.setAlphaBufferSize(8);
277 auto *eglCtx =
new QOhosEGLPlatformContext(format, context->shareHandle(), *m_eglDisplay);
283 return QEGLPlatformContext::createFrom<QOhosEGLPlatformContext>(context, display, *m_eglDisplay, shareContext);
287QPlatformOffscreenSurface *
290 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::createPlatformOffscreenSurface");
291 return new QEGLPbuffer(*m_eglDisplay, surface->requestedFormat(), surface);
296 qOhosDebug(QtForOhos) <<
"QOhosPlatformIntegration::hasCapability:" << cap;
299 case ApplicationState:
return true;
300 case ThreadedPixmaps:
return true;
305 case OffscreenSurface:
return true;
308 case OpenGLOnRasterSurface: {
309 return (QOhosDeviceInfo::getProperty(QOhosDeviceInfo::Type::productModel).toString() == QString::fromUtf8(
"emulator"));
311 case MultipleWindows:
return true;
312 case WindowManagement:
313 case NonFullScreenWindows:
315 case TopStackedNativeChildWindows:
return false;
317 return QPlatformIntegration::hasCapability(cap);
323 return m_platformInputContext.data();
328 auto d = make_QCScopedDebug(
"QOhosPlatformIntegration::initialize");
329 const auto requestedInputContext = QPlatformInputContextFactory::requested();
330 if (requestedInputContext.isEmpty()) {
332 m_platformInputContext.reset(context);
334 m_platformInputContext.reset(QPlatformInputContextFactory::create(requestedInputContext));
337 if (QWindowSystemInterfacePrivate::eventHandler !=
nullptr)
338 qOhosReportFatalErrorAndAbort(
"QWindowSystemInterfacePrivate::eventHandler was already registered.");
340 auto tracker = makeApplicationStateTracker();
341 QWindowSystemInterfacePrivate::installWindowSystemEventHandler(tracker.get());
342 m_applicationStateTracker = QtOhos::makeDestroyNotifier(
343 [tracker = std::move(tracker)]() {
344 QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(tracker.get());
347 m_settings = std::make_unique<QOhosSettings>();
352 return m_settings.get();
357 if (QtOhos::isDebugUseBasicStyleAndThemeEnabled())
358 return std::make_unique<QPlatformTheme>().release();
360 if (name == QString::fromUtf8(ohosThemeName))
367 return {QString::fromUtf8(ohosThemeName)};
377 return m_systemLocale.data();
382 m_systemLocale.reset(systemLocale);
388 m_mainWindowPersistencePolicy = policy;
393 return m_mainWindowPersistencePolicy;
398 return m_ohosPlatformServices.get();
403 return m_ohosPlatformNativeInterface.get();
408 return m_screenManager.get();
413QPlatformVulkanInstance *QOhosPlatformIntegration::createPlatformVulkanInstance(
414 QVulkanInstance *instance)
const
416 return new QOhosPlatformVulkanInstance(instance);
bool isWindowPcModeEnabled() const
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()