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