emu_window_sdl2_vk.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. // Include these late to avoid polluting everything with Xlib macros
  15. // Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307
  16. #ifdef __clang__
  17. #pragma clang diagnostic push
  18. #pragma clang diagnostic ignored "-Wimplicit-fallthrough"
  19. #endif
  20. #include <SDL.h>
  21. #ifdef __clang__
  22. #pragma clang diagnostic pop
  23. #endif
  24. #include <SDL_syswm.h>
  25. EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem)
  26. : EmuWindow_SDL2{input_subsystem} {
  27. const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name,
  28. Common::g_scm_branch, Common::g_scm_desc);
  29. render_window =
  30. SDL_CreateWindow(window_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
  31. Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height,
  32. SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
  33. SDL_SysWMinfo wm;
  34. SDL_VERSION(&wm.version);
  35. if (SDL_GetWindowWMInfo(render_window, &wm) == SDL_FALSE) {
  36. LOG_CRITICAL(Frontend, "Failed to get information from the window manager");
  37. std::exit(EXIT_FAILURE);
  38. }
  39. SetWindowIcon();
  40. switch (wm.subsystem) {
  41. #ifdef SDL_VIDEO_DRIVER_WINDOWS
  42. case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS:
  43. window_info.type = Core::Frontend::WindowSystemType::Windows;
  44. window_info.render_surface = reinterpret_cast<void*>(wm.info.win.window);
  45. break;
  46. #endif
  47. #ifdef SDL_VIDEO_DRIVER_X11
  48. case SDL_SYSWM_TYPE::SDL_SYSWM_X11:
  49. window_info.type = Core::Frontend::WindowSystemType::X11;
  50. window_info.display_connection = wm.info.x11.display;
  51. window_info.render_surface = reinterpret_cast<void*>(wm.info.x11.window);
  52. break;
  53. #endif
  54. #ifdef SDL_VIDEO_DRIVER_WAYLAND
  55. case SDL_SYSWM_TYPE::SDL_SYSWM_WAYLAND:
  56. window_info.type = Core::Frontend::WindowSystemType::Wayland;
  57. window_info.display_connection = wm.info.wl.display;
  58. window_info.render_surface = wm.info.wl.surface;
  59. break;
  60. #endif
  61. default:
  62. LOG_CRITICAL(Frontend, "Window manager subsystem not implemented");
  63. std::exit(EXIT_FAILURE);
  64. }
  65. OnResize();
  66. OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
  67. SDL_PumpEvents();
  68. LOG_INFO(Frontend, "yuzu Version: {} | {}-{} (Vulkan)", Common::g_build_name,
  69. Common::g_scm_branch, Common::g_scm_desc);
  70. }
  71. EmuWindow_SDL2_VK::~EmuWindow_SDL2_VK() = default;
  72. std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_VK::CreateSharedContext() const {
  73. return std::make_unique<DummyContext>();
  74. }