emu_window_sdl2_vk.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <cstdlib>
  4. #include <memory>
  5. #include <string>
  6. #include <fmt/format.h>
  7. #include "common/logging/log.h"
  8. #include "common/scm_rev.h"
  9. #include "video_core/renderer_vulkan/renderer_vulkan.h"
  10. #include "yuzu_cmd/emu_window/emu_window_sdl2_vk.h"
  11. #include <SDL.h>
  12. #include <SDL_syswm.h>
  13. EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem_,
  14. Core::System& system_, bool fullscreen)
  15. : EmuWindow_SDL2{input_subsystem_, system_} {
  16. const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name,
  17. Common::g_scm_branch, Common::g_scm_desc);
  18. render_window =
  19. SDL_CreateWindow(window_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
  20. Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height,
  21. SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
  22. SDL_SysWMinfo wm;
  23. SDL_VERSION(&wm.version);
  24. if (SDL_GetWindowWMInfo(render_window, &wm) == SDL_FALSE) {
  25. LOG_CRITICAL(Frontend, "Failed to get information from the window manager");
  26. std::exit(EXIT_FAILURE);
  27. }
  28. SetWindowIcon();
  29. if (fullscreen) {
  30. Fullscreen();
  31. ShowCursor(false);
  32. }
  33. switch (wm.subsystem) {
  34. #ifdef SDL_VIDEO_DRIVER_WINDOWS
  35. case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS:
  36. window_info.type = Core::Frontend::WindowSystemType::Windows;
  37. window_info.render_surface = reinterpret_cast<void*>(wm.info.win.window);
  38. break;
  39. #endif
  40. #ifdef SDL_VIDEO_DRIVER_X11
  41. case SDL_SYSWM_TYPE::SDL_SYSWM_X11:
  42. window_info.type = Core::Frontend::WindowSystemType::X11;
  43. window_info.display_connection = wm.info.x11.display;
  44. window_info.render_surface = reinterpret_cast<void*>(wm.info.x11.window);
  45. break;
  46. #endif
  47. #ifdef SDL_VIDEO_DRIVER_WAYLAND
  48. case SDL_SYSWM_TYPE::SDL_SYSWM_WAYLAND:
  49. window_info.type = Core::Frontend::WindowSystemType::Wayland;
  50. window_info.display_connection = wm.info.wl.display;
  51. window_info.render_surface = wm.info.wl.surface;
  52. break;
  53. #endif
  54. #ifdef SDL_VIDEO_DRIVER_COCOA
  55. case SDL_SYSWM_TYPE::SDL_SYSWM_COCOA:
  56. window_info.type = Core::Frontend::WindowSystemType::Cocoa;
  57. window_info.render_surface = SDL_Metal_CreateView(render_window);
  58. break;
  59. #endif
  60. #ifdef SDL_VIDEO_DRIVER_ANDROID
  61. case SDL_SYSWM_TYPE::SDL_SYSWM_ANDROID:
  62. window_info.type = Core::Frontend::WindowSystemType::Android;
  63. window_info.render_surface = reinterpret_cast<void*>(wm.info.android.window);
  64. break;
  65. #endif
  66. default:
  67. LOG_CRITICAL(Frontend, "Window manager subsystem {} not implemented", wm.subsystem);
  68. std::exit(EXIT_FAILURE);
  69. break;
  70. }
  71. OnResize();
  72. OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
  73. SDL_PumpEvents();
  74. LOG_INFO(Frontend, "yuzu Version: {} | {}-{} (Vulkan)", Common::g_build_name,
  75. Common::g_scm_branch, Common::g_scm_desc);
  76. }
  77. EmuWindow_SDL2_VK::~EmuWindow_SDL2_VK() = default;
  78. std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_VK::CreateSharedContext() const {
  79. return std::make_unique<DummyContext>();
  80. }