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>
38#include <qpa/qwindowsysteminterface.h>
39#include <qpa/qplatforminputcontextfactory_p.h>
40#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");
74 QtOhos::
JsState &jsState,
const std::vector<std::uint32_t> &deviceIds,
78 deviceIds.begin(), deviceIds.end(),
79 [&](
std::uint32_t deviceId) {
80 return isDeviceTypeFunc(jsState, deviceId);
86 return QtOhos::evalInJsThreadWithConsumer<std::set<QInputDevice::DeviceType>>(
87 [](QtOhos::JsState &jsState, QOhosConsumer<std::set<QInputDevice::DeviceType>> resultConsumer) {
88 jsState.eval<QNapi::Promise>(
"@ohos.multimodalInput.inputDevice.getDeviceList()")
89 .withContext(std::move(resultConsumer))
91 [](
const QtOhos::CallbackInfo &cbInfo,
auto &resultConsumer) {
92 auto deviceIdsJsArray = cbInfo.getFirstArg<QNapi::Array>(Q_FUNC_INFO);
93 auto deviceIds = QNapi::getArrayElements<std::vector<std::uint32_t>, QNapi::Number>(deviceIdsJsArray);
94 std::set<QInputDevice::DeviceType> deviceTypes;
95 if (isDeviceTypeInDeviceIds(cbInfo.jsState(), deviceIds, isInputDeviceWithTouchscreen))
96 deviceTypes.insert(QInputDevice::DeviceType::TouchScreen);
97 if (isDeviceTypeInDeviceIds(cbInfo.jsState(), deviceIds, isInputDeviceWithTouchpad))
98 deviceTypes.insert(QInputDevice::DeviceType::TouchPad);
99 resultConsumer(deviceTypes);
102 [](
const QtOhos::CallbackInfo &,
auto &resultConsumer) {
103 qOhosPrintfError(
"Error while obtaining device list (@ohos.multimodalInput.inputDevice.getDeviceList())");
117 return static_cast<QOhosPlatformIntegration *>(QGuiApplicationPrivate::platformIntegration());
123 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::QOhosPlatformIntegration");
124 m_ohosPlatformNativeInterface.reset(
new QOhosPlatformNativeInterface());
127 m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
128 if (Q_UNLIKELY(m_eglDisplay == EGL_NO_DISPLAY))
129 qOhosReportFatalErrorAndAbort(
"Could not open egl display");
133 if (Q_UNLIKELY(!eglInitialize(m_eglDisplay, &major, &minor)))
134 qOhosReportFatalErrorAndAbort(
"Could not initialize egl display");
136 if (Q_UNLIKELY(!eglBindAPI(EGL_OPENGL_ES_API)))
137 qOhosReportFatalErrorAndAbort(
"Could not bind GL_ES API");
140 if (!QtOhos::isOhosNoUiChildMode())
141 m_screenManager = std::make_unique<QOhosScreenManager>();
143 m_mainThread = QThread::currentThread();
145 m_ohosFDB = std::make_unique<QOhosPlatformFontDatabase>();
146 m_ohosPlatformServices = std::make_unique<QOhosPlatformServices>();
147 if (!QtOhos::isOhosNoUiChildMode())
148 m_ohosInputMethodEventHandler = std::make_unique<QOhosInputMethodEventHandler>(getAvailableDeviceTypes());
150#ifndef QT_NO_CLIPBOARD
151 if (!QtOhos::isOhosNoUiChildMode())
152 m_platformClipboard = std::make_unique<QOhosPlatformClipboard>();
155#if QT_CONFIG(draganddrop)
156 if (!QtOhos::isOhosNoUiChildMode())
157 m_drag = makeQOhosPlatformDrag();
161 QCoreApplication::postEvent(m_ohosPlatformNativeInterface.data(),
new QEvent(QEvent::User));
166 return m_ohosInputMethodEventHandler.get();
176 if (hint == ShowIsMaximized)
178 return QPlatformIntegration::styleHint(hint);
184 if ((flags & Qt::Dialog & ~Qt::Window) != 0)
185 return Qt::WindowNoState;
187 return QPlatformIntegration::defaultWindowState(flags);
192 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::createPlatformWindow");
194 static const QSet<QString> nativeDialogClass = {
195 QString::fromUtf8(
"QFileDialogClassWindow"),
199 if (window !=
nullptr && !nativeDialogClass.contains(window->objectName()))
206 return new QOhosForeignWindow(window, windowId);
211 return m_ohosFDB.get();
214#ifndef QT_NO_CLIPBOARD
217 return m_platformClipboard.get();
221#if QT_CONFIG(draganddrop)
222QPlatformDrag *QOhosPlatformIntegration::drag()
const
230 std::unique_ptr<QPlatformBackingStore> result;
231 switch (window->surfaceType()) {
232 case QSurface::RasterSurface:
236 result = QtOhos::isGlBackingStoreDefaultEnabled()
237 ? makeGlOhosPlatformBackingStore(window)
238 : std::make_unique<QOhosPlatformBackingStore>(
240 QOhosPlatformBackingStore::CreateInfo{
241 .debugDrawFlushedRegion = QtOhos::isDebugDrawQtRasterBackingStoreFlushedRegionEnabled(),
242 .enableVsync = QtOhos::isVsyncOnSoftwareBackingStoreEnabled(),
245 case QSurface::OpenGLSurface:
246 case QSurface::VulkanSurface:
247 result = std::make_unique<QRhiBackingStore>(window);
249 case QSurface::OpenVGSurface:
250 case QSurface::MetalSurface:
251 case QSurface::Direct3DSurface:
252 qOhosReportFatalErrorAndAbort(
"Unsupported window surface type for backing store: %d", window->surfaceType());
256 return result.release();
261 QSurfaceFormat format = context->format();
262 format.setRedBufferSize(8);
263 format.setGreenBufferSize(8);
264 format.setBlueBufferSize(8);
265 format.setAlphaBufferSize(8);
266 auto *eglCtx =
new QOhosEGLPlatformContext(format, context->shareHandle(), m_eglDisplay);
272 return QEGLPlatformContext::createFrom<QOhosEGLPlatformContext>(context, display, m_eglDisplay, shareContext);
276QPlatformOffscreenSurface *
279 auto __dbg = make_QCScopedDebug(
"QOhosPlatformIntegration::createPlatformOffscreenSurface");
280 return new QEGLPbuffer(m_eglDisplay, surface->requestedFormat(), surface);
285 qOhosDebug(QtForOhos) <<
"QOhosPlatformIntegration::hasCapability:" << cap;
288 case ApplicationState:
return true;
289 case ThreadedPixmaps:
return true;
294 case OffscreenSurface:
return true;
297 case OpenGLOnRasterSurface: {
298 return (QOhosDeviceInfo::getProperty(QOhosDeviceInfo::Type::productModel).toString() == QString::fromUtf8(
"emulator"));
300 case MultipleWindows:
return true;
301 case WindowManagement:
return true;
302 case TopStackedNativeChildWindows:
return false;
304 return QPlatformIntegration::hasCapability(cap);
310 return m_platformInputContext.data();
315 auto d = make_QCScopedDebug(
"QOhosPlatformIntegration::initialize");
316 const auto requestedInputContext = QPlatformInputContextFactory::requested();
317 if (requestedInputContext.isEmpty()) {
319 m_platformInputContext.reset(context);
321 m_platformInputContext.reset(QPlatformInputContextFactory::create(requestedInputContext));
324 if (QWindowSystemInterfacePrivate::eventHandler !=
nullptr)
325 qOhosReportFatalErrorAndAbort(
"QWindowSystemInterfacePrivate::eventHandler was already registered.");
327 auto tracker = makeApplicationStateTracker();
328 QWindowSystemInterfacePrivate::installWindowSystemEventHandler(tracker.get());
329 m_applicationStateTracker = QtOhos::makeDestroyNotifier(
330 [tracker = std::move(tracker)]() {
331 QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(tracker.get());
337 if (QtOhos::isDebugUseBasicStyleAndThemeEnabled())
338 return std::make_unique<QPlatformTheme>().release();
340 if (name == QString::fromUtf8(ohosThemeName))
347 return {QString::fromUtf8(ohosThemeName)};
352 return m_systemLocale.data();
357 m_systemLocale.reset(systemLocale);
363 m_mainWindowPersistencePolicy = policy;
368 return m_mainWindowPersistencePolicy;
373 return m_ohosPlatformServices.get();
378 return m_ohosPlatformNativeInterface.get();
383 return m_screenManager.get();
388QPlatformVulkanInstance *QOhosPlatformIntegration::createPlatformVulkanInstance(
389 QVulkanInstance *instance)
const
391 return new QOhosPlatformVulkanInstance(instance);
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()