The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

comp/main: Windows work - got a window to appear!

authored by

Ryan Pavlik and committed by
Jakob Bornecrantz
0cb64ce5 27437901

+257 -1
+1 -1
CMakeLists.txt
··· 117 117 cmake_dependent_option(XRT_HAVE_OPENGLES "Enable OpenGL-ES Graphics API support" ON "OpenGLES_FOUND" OFF) 118 118 cmake_dependent_option(XRT_HAVE_EGL "Enable OpenGL on EGL Graphics API support" ON "EGL_FOUND; XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES" OFF) 119 119 cmake_dependent_option(XRT_HAVE_DBUS "Enable dbus support (for BLE support)" ON "DBUS_FOUND" OFF) 120 - cmake_dependent_option(XRT_FEATURE_COMPOSITOR_MAIN "Build main compositor host functionality" ON "XRT_HAVE_VULKAN; XRT_HAVE_WAYLAND OR XRT_HAVE_XCB OR ANDROID" OFF) 120 + cmake_dependent_option(XRT_FEATURE_COMPOSITOR_MAIN "Build main compositor host functionality" ON "XRT_HAVE_VULKAN; XRT_HAVE_WAYLAND OR XRT_HAVE_XCB OR ANDROID OR WIN32" OFF) 121 121 cmake_dependent_option(XRT_FEATURE_OPENXR "Build OpenXR runtime target" ON "XRT_FEATURE_COMPOSITOR_MAIN" OFF) 122 122 cmake_dependent_option(XRT_FEATURE_SERVICE "Enable separate service module for OpenXR runtime" ON "NOT WIN32" OFF) 123 123 cmake_dependent_option(XRT_HAVE_SYSTEMD "Enable systemd support (for socket activation of service)" ON "Systemd_FOUND AND XRT_FEATURE_SERVICE" OFF)
+6
src/xrt/compositor/CMakeLists.txt
··· 112 112 main/comp_window_direct_nvidia.c 113 113 ) 114 114 endif() 115 + if(WIN32) 116 + list(APPEND MAIN_SOURCE_FILES 117 + main/comp_window_mswin.c 118 + ) 119 + endif() 120 + 115 121 116 122 # generate wayland protocols 117 123 if(XRT_HAVE_WAYLAND)
+24
src/xrt/compositor/main/comp_compositor.c
··· 694 694 COMP_INSTANCE_EXTENSIONS_COMMON, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME}; 695 695 #endif 696 696 697 + #ifdef VK_USE_PLATFORM_WIN32_KHR 698 + static const char *instance_extensions_windows[] = { 699 + COMP_INSTANCE_EXTENSIONS_COMMON, VK_KHR_WIN32_SURFACE_EXTENSION_NAME}; 700 + #endif 701 + 697 702 // Note: Keep synchronized with comp_vk_glue - we should have everything they 698 703 // do, plus VK_KHR_SWAPCHAIN_EXTENSION_NAME 699 704 static const char *device_extensions[] = { ··· 765 770 case WINDOW_ANDROID: 766 771 *out_exts = instance_extensions_android; 767 772 *out_num = ARRAY_SIZE(instance_extensions_android); 773 + break; 774 + #endif 775 + #ifdef VK_USE_PLATFORM_WIN32_KHR 776 + case WINDOW_MSWIN: 777 + *out_exts = instance_extensions_windows; 778 + *out_num = ARRAY_SIZE(instance_extensions_windows); 768 779 break; 769 780 #endif 770 781 default: return VK_ERROR_INITIALIZATION_FAILED; ··· 1139 1150 return true; 1140 1151 } 1141 1152 #endif 1153 + #ifdef XRT_OS_WINDOWS 1154 + if (compositor_try_window(c, comp_window_mswin_create(c))) { 1155 + c->settings.window_type = WINDOW_MSWIN; 1156 + return true; 1157 + } 1158 + #endif 1142 1159 COMP_ERROR(c, "Failed to auto detect window support!"); 1143 1160 break; 1144 1161 case WINDOW_XCB: ··· 1169 1186 COMP_ERROR(c, "Android support not compiled in!"); 1170 1187 #endif 1171 1188 break; 1189 + 1190 + case WINDOW_MSWIN: 1191 + #ifdef XRT_OS_WINDOWS 1192 + compositor_try_window(c, comp_window_mswin_create(c)); 1193 + #else 1194 + COMP_ERROR(c, "Windows support not compiled in!"); 1195 + #endif 1172 1196 default: COMP_ERROR(c, "Unknown window type!"); break; 1173 1197 } 1174 1198
+1
src/xrt/compositor/main/comp_settings.h
··· 49 49 WINDOW_DIRECT_RANDR, 50 50 WINDOW_DIRECT_NVIDIA, 51 51 WINDOW_ANDROID, 52 + WINDOW_MSWIN, 52 53 }; 53 54 54 55
+13
src/xrt/compositor/main/comp_window.h
··· 82 82 83 83 #endif // XRT_OS_ANDROID 84 84 85 + #ifdef XRT_OS_WINDOWS 86 + 87 + /*! 88 + * Create a rendering window on Windows. 89 + * 90 + * @ingroup comp_main 91 + * @public @memberof comp_window_mswin 92 + */ 93 + struct comp_target * 94 + comp_window_mswin_create(struct comp_compositor *c); 95 + 96 + #endif // XRT_OS_WINDOWS 97 + 85 98 #ifdef __cplusplus 86 99 } 87 100 #endif
+212
src/xrt/compositor/main/comp_window_mswin.c
··· 1 + // Copyright 2019-2020, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Wayland window code. 6 + * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com> 7 + * @author Jakob Bornecrantz <jakob@collabora.com> 8 + * @ingroup comp_main 9 + */ 10 + 11 + #include <stdlib.h> 12 + #include <string.h> 13 + #include "xrt/xrt_compiler.h" 14 + #include "main/comp_window.h" 15 + #include "util/u_misc.h" 16 + 17 + 18 + /* 19 + * 20 + * Private structs. 21 + * 22 + */ 23 + 24 + /*! 25 + * A Microsoft Windows window. 26 + * 27 + * @implements comp_target_swapchain 28 + */ 29 + struct comp_window_mswin 30 + { 31 + struct comp_target_swapchain base; 32 + 33 + HINSTANCE instance; 34 + HWND window; 35 + 36 + 37 + bool fullscreen_requested; 38 + }; 39 + 40 + static WCHAR szWindowClass[] = L"Monado"; 41 + 42 + /* 43 + * 44 + * Functions. 45 + * 46 + */ 47 + 48 + static LRESULT CALLBACK 49 + WndProc(HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) 50 + { 51 + switch (message) { 52 + case WM_PAINT: { 53 + // paint the main window 54 + PAINTSTRUCT ps; 55 + HDC hdc = BeginPaint(hWnd, &ps); 56 + // TODO: Add any drawing code that uses hdc here... 57 + EndPaint(hWnd, &ps); 58 + } break; 59 + case WM_DESTROY: 60 + // Post a quit message and return. 61 + //! @todo set quit flag 62 + PostQuitMessage(0); 63 + break; 64 + default: return DefWindowProc(hWnd, message, wParam, lParam); 65 + } 66 + return 0; 67 + } 68 + 69 + 70 + static inline struct vk_bundle * 71 + get_vk(struct comp_window_mswin *cwm) 72 + { 73 + return &cwm->base.base.c->vk; 74 + } 75 + 76 + static void 77 + comp_window_mswin_destroy(struct comp_target *ct) 78 + { 79 + struct comp_window_mswin *cwm = (struct comp_window_mswin *)ct; 80 + 81 + comp_target_swapchain_cleanup(&cwm->base); 82 + 83 + //! @todo 84 + 85 + free(ct); 86 + } 87 + 88 + static void 89 + comp_window_mswin_update_window_title(struct comp_target *ct, const char *title) 90 + { 91 + struct comp_window_mswin *cwm = (struct comp_window_mswin *)ct; 92 + //! @todo 93 + } 94 + 95 + static void 96 + comp_window_mswin_fullscreen(struct comp_window_mswin *w) 97 + { 98 + //! @todo 99 + } 100 + 101 + static VkResult 102 + comp_window_mswin_create_surface(struct comp_window_mswin *w, 103 + VkSurfaceKHR *vk_surface) 104 + { 105 + struct vk_bundle *vk = get_vk(w); 106 + VkResult ret; 107 + VkWin32SurfaceCreateInfoKHR surface_info = { 108 + .sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, 109 + .hinstance = w->instance, 110 + .hwnd = w->window, 111 + }; 112 + 113 + ret = vk->vkCreateWin32SurfaceKHR(vk->instance, &surface_info, NULL, 114 + vk_surface); 115 + if (ret != VK_SUCCESS) { 116 + COMP_ERROR(w->base.base.c, "vkCreateWin32SurfaceKHR: %s", 117 + vk_result_string(ret)); 118 + return ret; 119 + } 120 + 121 + return VK_SUCCESS; 122 + } 123 + 124 + static bool 125 + comp_window_mswin_init_swapchain(struct comp_target *ct, 126 + uint32_t width, 127 + uint32_t height) 128 + { 129 + struct comp_window_mswin *cwm = (struct comp_window_mswin *)ct; 130 + VkResult ret; 131 + 132 + ret = comp_window_mswin_create_surface(cwm, &cwm->base.surface.handle); 133 + if (ret != VK_SUCCESS) { 134 + COMP_ERROR(ct->c, "Failed to create surface!"); 135 + return false; 136 + } 137 + 138 + //! @todo 139 + 140 + return true; 141 + } 142 + 143 + 144 + static void 145 + comp_window_mswin_flush(struct comp_target *ct) 146 + { 147 + struct comp_window_mswin *cwm = (struct comp_window_mswin *)ct; 148 + } 149 + 150 + 151 + static bool 152 + comp_window_mswin_init(struct comp_target *ct) 153 + { 154 + struct comp_window_mswin *cwm = (struct comp_window_mswin *)ct; 155 + cwm->instance = GetModuleHandle(NULL); 156 + 157 + WNDCLASSEXW wcex; 158 + U_ZERO(&wcex); 159 + wcex.cbSize = sizeof(WNDCLASSEXW); 160 + wcex.style = CS_HREDRAW | CS_VREDRAW; 161 + 162 + wcex.lpfnWndProc = WndProc; 163 + wcex.cbClsExtra = 0; 164 + wcex.cbWndExtra = 0; 165 + wcex.hInstance = cwm->instance; 166 + wcex.lpszClassName = szWindowClass; 167 + //! @todo icon 168 + #if 0 169 + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SAMPLEGUI)); 170 + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 171 + wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_SAMPLEGUI); 172 + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); 173 + #endif 174 + RegisterClassExW(&wcex); 175 + 176 + cwm->window = 177 + CreateWindowW(szWindowClass, L"Monado (Windowed)", 178 + WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 179 + 0, NULL, NULL, cwm->instance, NULL); 180 + 181 + return true; 182 + } 183 + 184 + static void 185 + comp_window_mswin_configure(struct comp_window_mswin *w, 186 + int32_t width, 187 + int32_t height) 188 + { 189 + if (w->base.base.c->settings.fullscreen && !w->fullscreen_requested) { 190 + COMP_DEBUG(w->base.base.c, "Setting full screen"); 191 + comp_window_mswin_fullscreen(w); 192 + w->fullscreen_requested = true; 193 + } 194 + } 195 + 196 + struct comp_target * 197 + comp_window_mswin_create(struct comp_compositor *c) 198 + { 199 + struct comp_window_mswin *w = U_TYPED_CALLOC(struct comp_window_mswin); 200 + 201 + comp_target_swapchain_init_set_fnptrs(&w->base); 202 + 203 + w->base.base.name = "MS Windows"; 204 + w->base.base.destroy = comp_window_mswin_destroy; 205 + w->base.base.flush = comp_window_mswin_flush; 206 + w->base.base.init_pre_vulkan = comp_window_mswin_init; 207 + w->base.base.init_post_vulkan = comp_window_mswin_init_swapchain; 208 + w->base.base.set_title = comp_window_mswin_update_window_title; 209 + w->base.base.c = c; 210 + 211 + return &w->base.base; 212 + }