emu_window_sdl2_vk.cpp 3.6 KB

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