Debian Codegraph @

tests/manual/rhi/multiwindow_threaded/window.cpp

raw
1 // Copyright (C) 2018 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include "window.h"
5 #include <QPlatformSurfaceEvent>
6
7 #if QT_CONFIG(vulkan)
8 extern QVulkanInstance *instance;
9 #endif
10
11 Window::Window(const QString &title, GraphicsApi api)
12 {
13 switch (api) {
14 case OpenGL:
15 setSurfaceType(OpenGLSurface);
16 break;
17 case Vulkan:
18 setSurfaceType(VulkanSurface);
19 #if QT_CONFIG(vulkan)
20 setVulkanInstance(instance);
21 #endif
22 break;
23 case D3D11:
24 case D3D12:
25 setSurfaceType(Direct3DSurface);
26 break;
27 case Metal:
28 setSurfaceType(MetalSurface);
29 break;
30 default:
31 break;
32 }
33
34 resize(800, 600);
35 setTitle(title);
36 }
37
38 Window::~Window()
39 {
40 }
41
42 void Window::exposeEvent(QExposeEvent *)
43 {
44 if (isExposed()) {
45 if (!m_running) {
46 // initialize and start rendering when the window becomes usable for graphics purposes
47 m_running = true;
48 m_notExposed = false;
49 emit initRequested();
50 emit renderRequested(true);
51 } else {
52 // continue when exposed again
53 if (m_notExposed) {
54 m_notExposed = false;
55 emit renderRequested(true);
56 } else {
57 // resize generates exposes - this is very important here (unlike in a single-threaded renderer)
58 emit syncSurfaceSizeRequested();
59 }
60 }
61 } else {
62 // stop pushing frames when not exposed (on some platforms this is essential, optional on others)
63 if (m_running)
64 m_notExposed = true;
65 }
66 }
67
68 bool Window::event(QEvent *e)
69 {
70 switch (e->type()) {
71 case QEvent::UpdateRequest:
72 if (!m_notExposed)
73 emit renderRequested(false);
74 break;
75
76 case QEvent::PlatformSurface:
77 // this is the proper time to tear down the swapchain (while the native window and surface are still around)
78 if (static_cast<QPlatformSurfaceEvent *>(e)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed)
79 emit surfaceGoingAway();
80 break;
81
82 default:
83 break;
84 }
85
86 return QWindow::event(e);
87 }