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
qwindowsnativeinterface.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
11#include "qwindowstheme.h"
12#include "qwin10helpers.h"
13
14#include <QtGui/qwindow.h>
15#include <QtGui/qopenglcontext.h>
16#include <QtGui/qscreen.h>
17#include <qpa/qplatformscreen.h>
18
20
29
30static int resourceType(const QByteArray &key)
31{
32 static const char *names[] = { // match ResourceType
33 "renderingcontext",
34 "handle",
35 "glhandle",
36 "getdc",
37 "releasedc",
38 "vkSurface"
39 };
40 const char ** const end = names + sizeof(names) / sizeof(names[0]);
41 const char **result = std::find(names, end, key);
42 if (result == end)
43 result = std::find(names, end, key.toLower());
44 return int(result - names);
45}
46
47void *QWindowsNativeInterface::nativeResourceForWindow(const QByteArray &resource, QWindow *window)
48{
49 if (!window || !window->handle()) {
50 qWarning("%s: '%s' requested for null window or window without handle.", __FUNCTION__, resource.constData());
51 return nullptr;
52 }
53 auto *bw = static_cast<QWindowsWindow *>(window->handle());
54 int type = resourceType(resource);
55 if (type == HandleType)
56 return bw->handle();
57 switch (window->surfaceType()) {
58 case QWindow::RasterSurface:
59 if (type == GetDCType)
60 return bw->getDC();
61 if (type == ReleaseDCType) {
62 bw->releaseDC();
63 return nullptr;
64 }
65 break;
66 case QWindow::VulkanSurface:
67#if QT_CONFIG(vulkan)
68 if (type == VkSurface)
69 return bw->surface(nullptr, nullptr); // returns the address of the VkSurfaceKHR, not the value, as expected
70#endif
71 break;
72 default:
73 break;
74 }
75 qWarning("%s: Invalid key '%s' requested.", __FUNCTION__, resource.constData());
76 return nullptr;
77}
78
79void *QWindowsNativeInterface::nativeResourceForScreen(const QByteArray &resource, QScreen *screen)
80{
81 if (!screen || !screen->handle()) {
82 qWarning("%s: '%s' requested for null screen or screen without handle.", __FUNCTION__, resource.constData());
83 return nullptr;
84 }
85 auto *bs = static_cast<QWindowsScreen *>(screen->handle());
86 int type = resourceType(resource);
87 if (type == HandleType)
88 return bs->handle();
89
90 qWarning("%s: Invalid key '%s' requested.", __FUNCTION__, resource.constData());
91 return nullptr;
92}
93
94#ifndef QT_NO_CURSOR
95void *QWindowsNativeInterface::nativeResourceForCursor(const QByteArray &resource, const QCursor &cursor)
96{
97 if (resource == QByteArrayLiteral("hcursor")) {
98 if (const QScreen *primaryScreen = QGuiApplication::primaryScreen()) {
99 if (const QPlatformCursor *pCursor= primaryScreen->handle()->cursor())
100 return static_cast<const QWindowsCursor *>(pCursor)->hCursor(cursor);
101 }
102 }
103 return nullptr;
104}
105#endif // !QT_NO_CURSOR
106
107void *QWindowsNativeInterface::nativeResourceForIntegration(const QByteArray &resource)
108{
109#ifdef QT_NO_OPENGL
110 Q_UNUSED(resource);
111#else
112 if (resourceType(resource) == GlHandleType) {
114 return sc->moduleHandle();
115 }
116#endif
117
118 return nullptr;
119}
120
121#ifndef QT_NO_OPENGL
122void *QWindowsNativeInterface::nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context)
123{
124 if (!context || !context->handle()) {
125 qWarning("%s: '%s' requested for null context or context without handle.", __FUNCTION__, resource.constData());
126 return nullptr;
127 }
128
129 qWarning("%s: Invalid key '%s' requested.", __FUNCTION__, resource.constData());
130 return nullptr;
131}
132#endif // !QT_NO_OPENGL
133
134QT_END_NAMESPACE
Platform cursor implementation.
static QWindowsStaticOpenGLContext * staticOpenGLContext()
Provides access to native handles.
void * nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) override
void * nativeResourceForWindow(const QByteArray &resource, QWindow *window) override
void * nativeResourceForCursor(const QByteArray &resource, const QCursor &cursor) override
void * nativeResourceForScreen(const QByteArray &resource, QScreen *screen) override
Windows screen.
virtual void * moduleHandle() const =0
Raster or OpenGL Window.
static int resourceType(const QByteArray &key)