diff options
author | Zephyron <zephyron@citron-emu.org> | 2024-12-31 16:19:25 +1000 |
---|---|---|
committer | Zephyron <zephyron@citron-emu.org> | 2024-12-31 16:19:25 +1000 |
commit | 9427e27e24a7135880ee2881c3c44988e174b41a (patch) | |
tree | 83f0062a35be144f6b162eaa823c5b3c7620146e /src/citron_cmd/emu_window | |
parent | b35ae725d20960411e8588b11c12a2d55f86c9d0 (diff) |
chore: update project branding to citron
Diffstat (limited to 'src/citron_cmd/emu_window')
-rw-r--r-- | src/citron_cmd/emu_window/emu_window_sdl2.cpp | 254 | ||||
-rw-r--r-- | src/citron_cmd/emu_window/emu_window_sdl2.h | 95 | ||||
-rw-r--r-- | src/citron_cmd/emu_window/emu_window_sdl2_gl.cpp | 153 | ||||
-rw-r--r-- | src/citron_cmd/emu_window/emu_window_sdl2_gl.h | 37 | ||||
-rw-r--r-- | src/citron_cmd/emu_window/emu_window_sdl2_null.cpp | 51 | ||||
-rw-r--r-- | src/citron_cmd/emu_window/emu_window_sdl2_null.h | 26 | ||||
-rw-r--r-- | src/citron_cmd/emu_window/emu_window_sdl2_vk.cpp | 93 | ||||
-rw-r--r-- | src/citron_cmd/emu_window/emu_window_sdl2_vk.h | 26 |
8 files changed, 735 insertions, 0 deletions
diff --git a/src/citron_cmd/emu_window/emu_window_sdl2.cpp b/src/citron_cmd/emu_window/emu_window_sdl2.cpp new file mode 100644 index 000000000..eae614f9d --- /dev/null +++ b/src/citron_cmd/emu_window/emu_window_sdl2.cpp @@ -0,0 +1,254 @@ +// SPDX-FileCopyrightText: 2016 Citra Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <SDL.h> + +#include "common/logging/log.h" +#include "common/scm_rev.h" +#include "common/settings.h" +#include "core/core.h" +#include "core/perf_stats.h" +#include "hid_core/hid_core.h" +#include "input_common/drivers/keyboard.h" +#include "input_common/drivers/mouse.h" +#include "input_common/drivers/touch_screen.h" +#include "input_common/main.h" +#include "yuzu_cmd/emu_window/emu_window_sdl2.h" +#include "yuzu_cmd/yuzu_icon.h" + +EmuWindow_SDL2::EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem_, Core::System& system_) + : input_subsystem{input_subsystem_}, system{system_} { + input_subsystem->Initialize(); + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) { + LOG_CRITICAL(Frontend, "Failed to initialize SDL2: {}, Exiting...", SDL_GetError()); + exit(1); + } + SDL_SetMainReady(); +} + +EmuWindow_SDL2::~EmuWindow_SDL2() { + system.HIDCore().UnloadInputDevices(); + input_subsystem->Shutdown(); + SDL_Quit(); +} + +InputCommon::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const { + switch (button) { + case SDL_BUTTON_LEFT: + return InputCommon::MouseButton::Left; + case SDL_BUTTON_RIGHT: + return InputCommon::MouseButton::Right; + case SDL_BUTTON_MIDDLE: + return InputCommon::MouseButton::Wheel; + case SDL_BUTTON_X1: + return InputCommon::MouseButton::Backward; + case SDL_BUTTON_X2: + return InputCommon::MouseButton::Forward; + default: + return InputCommon::MouseButton::Undefined; + } +} + +std::pair<float, float> EmuWindow_SDL2::MouseToTouchPos(s32 touch_x, s32 touch_y) const { + int w, h; + SDL_GetWindowSize(render_window, &w, &h); + const float fx = static_cast<float>(touch_x) / w; + const float fy = static_cast<float>(touch_y) / h; + + return {std::clamp<float>(fx, 0.0f, 1.0f), std::clamp<float>(fy, 0.0f, 1.0f)}; +} + +void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { + const auto mouse_button = SDLButtonToMouseButton(button); + if (state == SDL_PRESSED) { + const auto [touch_x, touch_y] = MouseToTouchPos(x, y); + input_subsystem->GetMouse()->PressButton(x, y, mouse_button); + input_subsystem->GetMouse()->PressMouseButton(mouse_button); + input_subsystem->GetMouse()->PressTouchButton(touch_x, touch_y, mouse_button); + } else { + input_subsystem->GetMouse()->ReleaseButton(mouse_button); + } +} + +void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { + const auto [touch_x, touch_y] = MouseToTouchPos(x, y); + input_subsystem->GetMouse()->Move(x, y, 0, 0); + input_subsystem->GetMouse()->MouseMove(touch_x, touch_y); + input_subsystem->GetMouse()->TouchMove(touch_x, touch_y); +} + +void EmuWindow_SDL2::OnFingerDown(float x, float y, std::size_t id) { + input_subsystem->GetTouchScreen()->TouchPressed(x, y, id); +} + +void EmuWindow_SDL2::OnFingerMotion(float x, float y, std::size_t id) { + input_subsystem->GetTouchScreen()->TouchMoved(x, y, id); +} + +void EmuWindow_SDL2::OnFingerUp() { + input_subsystem->GetTouchScreen()->ReleaseAllTouch(); +} + +void EmuWindow_SDL2::OnKeyEvent(int key, u8 state) { + if (state == SDL_PRESSED) { + input_subsystem->GetKeyboard()->PressKey(static_cast<std::size_t>(key)); + } else if (state == SDL_RELEASED) { + input_subsystem->GetKeyboard()->ReleaseKey(static_cast<std::size_t>(key)); + } +} + +bool EmuWindow_SDL2::IsOpen() const { + return is_open; +} + +bool EmuWindow_SDL2::IsShown() const { + return is_shown; +} + +void EmuWindow_SDL2::OnResize() { + int width, height; + SDL_GL_GetDrawableSize(render_window, &width, &height); + UpdateCurrentFramebufferLayout(width, height); +} + +void EmuWindow_SDL2::ShowCursor(bool show_cursor) { + SDL_ShowCursor(show_cursor ? SDL_ENABLE : SDL_DISABLE); +} + +void EmuWindow_SDL2::Fullscreen() { + SDL_DisplayMode display_mode; + switch (Settings::values.fullscreen_mode.GetValue()) { + case Settings::FullscreenMode::Exclusive: + // Set window size to render size before entering fullscreen -- SDL2 does not resize window + // to display dimensions automatically in this mode. + if (SDL_GetDesktopDisplayMode(0, &display_mode) == 0) { + SDL_SetWindowSize(render_window, display_mode.w, display_mode.h); + } else { + LOG_ERROR(Frontend, "SDL_GetDesktopDisplayMode failed: {}", SDL_GetError()); + } + + if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN) == 0) { + return; + } + + LOG_ERROR(Frontend, "Fullscreening failed: {}", SDL_GetError()); + LOG_INFO(Frontend, "Attempting to use borderless fullscreen..."); + [[fallthrough]]; + case Settings::FullscreenMode::Borderless: + if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0) { + return; + } + + LOG_ERROR(Frontend, "Borderless fullscreening failed: {}", SDL_GetError()); + [[fallthrough]]; + default: + // Fallback algorithm: Maximise window. + // Works on all systems (unless something is seriously wrong), so no fallback for this one. + LOG_INFO(Frontend, "Falling back on a maximised window..."); + SDL_MaximizeWindow(render_window); + break; + } +} + +void EmuWindow_SDL2::WaitEvent() { + // Called on main thread + SDL_Event event; + + if (!SDL_WaitEvent(&event)) { + const char* error = SDL_GetError(); + if (!error || strcmp(error, "") == 0) { + // https://github.com/libsdl-org/SDL/issues/5780 + // Sometimes SDL will return without actually having hit an error condition; + // just ignore it in this case. + return; + } + + LOG_CRITICAL(Frontend, "SDL_WaitEvent failed: {}", error); + exit(1); + } + + switch (event.type) { + case SDL_WINDOWEVENT: + switch (event.window.event) { + case SDL_WINDOWEVENT_SIZE_CHANGED: + case SDL_WINDOWEVENT_RESIZED: + case SDL_WINDOWEVENT_MAXIMIZED: + case SDL_WINDOWEVENT_RESTORED: + OnResize(); + break; + case SDL_WINDOWEVENT_MINIMIZED: + case SDL_WINDOWEVENT_EXPOSED: + is_shown = event.window.event == SDL_WINDOWEVENT_EXPOSED; + OnResize(); + break; + case SDL_WINDOWEVENT_CLOSE: + is_open = false; + break; + } + break; + case SDL_KEYDOWN: + case SDL_KEYUP: + OnKeyEvent(static_cast<int>(event.key.keysym.scancode), event.key.state); + break; + case SDL_MOUSEMOTION: + // ignore if it came from touch + if (event.button.which != SDL_TOUCH_MOUSEID) + OnMouseMotion(event.motion.x, event.motion.y); + break; + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + // ignore if it came from touch + if (event.button.which != SDL_TOUCH_MOUSEID) { + OnMouseButton(event.button.button, event.button.state, event.button.x, event.button.y); + } + break; + case SDL_FINGERDOWN: + OnFingerDown(event.tfinger.x, event.tfinger.y, + static_cast<std::size_t>(event.tfinger.touchId)); + break; + case SDL_FINGERMOTION: + OnFingerMotion(event.tfinger.x, event.tfinger.y, + static_cast<std::size_t>(event.tfinger.touchId)); + break; + case SDL_FINGERUP: + OnFingerUp(); + break; + case SDL_QUIT: + is_open = false; + break; + default: + break; + } + + const u32 current_time = SDL_GetTicks(); + if (current_time > last_time + 2000) { + const auto results = system.GetAndResetPerfStats(); + const auto title = + fmt::format("yuzu {} | {}-{} | FPS: {:.0f} ({:.0f}%)", Common::g_build_fullname, + Common::g_scm_branch, Common::g_scm_desc, results.average_game_fps, + results.emulation_speed * 100.0); + SDL_SetWindowTitle(render_window, title.c_str()); + last_time = current_time; + } +} + +// Credits to Samantas5855 and others for this function. +void EmuWindow_SDL2::SetWindowIcon() { + SDL_RWops* const yuzu_icon_stream = SDL_RWFromConstMem((void*)yuzu_icon, yuzu_icon_size); + if (yuzu_icon_stream == nullptr) { + LOG_WARNING(Frontend, "Failed to create yuzu icon stream."); + return; + } + SDL_Surface* const window_icon = SDL_LoadBMP_RW(yuzu_icon_stream, 1); + if (window_icon == nullptr) { + LOG_WARNING(Frontend, "Failed to read BMP from stream."); + return; + } + // The icon is attached to the window pointer + SDL_SetWindowIcon(render_window, window_icon); + SDL_FreeSurface(window_icon); +} + +void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) { + SDL_SetWindowMinimumSize(render_window, minimal_size.first, minimal_size.second); +} diff --git a/src/citron_cmd/emu_window/emu_window_sdl2.h b/src/citron_cmd/emu_window/emu_window_sdl2.h new file mode 100644 index 000000000..4ad05e0e1 --- /dev/null +++ b/src/citron_cmd/emu_window/emu_window_sdl2.h @@ -0,0 +1,95 @@ +// SPDX-FileCopyrightText: 2016 Citra Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <utility> + +#include "core/frontend/emu_window.h" +#include "core/frontend/graphics_context.h" + +struct SDL_Window; + +namespace Core { +class System; +} + +namespace InputCommon { +class InputSubsystem; +enum class MouseButton; +} // namespace InputCommon + +class EmuWindow_SDL2 : public Core::Frontend::EmuWindow { +public: + explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem_, Core::System& system_); + ~EmuWindow_SDL2(); + + /// Whether the window is still open, and a close request hasn't yet been sent + bool IsOpen() const; + + /// Returns if window is shown (not minimized) + bool IsShown() const override; + + /// Wait for the next event on the main thread. + void WaitEvent(); + + // Sets the window icon from yuzu.bmp + void SetWindowIcon(); + +protected: + /// Called by WaitEvent when a key is pressed or released. + void OnKeyEvent(int key, u8 state); + + /// Converts a SDL mouse button into MouseInput mouse button + InputCommon::MouseButton SDLButtonToMouseButton(u32 button) const; + + /// Translates pixel position to float position + std::pair<float, float> MouseToTouchPos(s32 touch_x, s32 touch_y) const; + + /// Called by WaitEvent when a mouse button is pressed or released + void OnMouseButton(u32 button, u8 state, s32 x, s32 y); + + /// Called by WaitEvent when the mouse moves. + void OnMouseMotion(s32 x, s32 y); + + /// Called by WaitEvent when a finger starts touching the touchscreen + void OnFingerDown(float x, float y, std::size_t id); + + /// Called by WaitEvent when a finger moves while touching the touchscreen + void OnFingerMotion(float x, float y, std::size_t id); + + /// Called by WaitEvent when a finger stops touching the touchscreen + void OnFingerUp(); + + /// Called by WaitEvent when any event that may cause the window to be resized occurs + void OnResize(); + + /// Called when users want to hide the mouse cursor + void ShowCursor(bool show_cursor); + + /// Called when user passes the fullscreen parameter flag + void Fullscreen(); + + /// Called when a configuration change affects the minimal size of the window + void OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) override; + + /// Is the window still open? + bool is_open = true; + + /// Is the window being shown? + bool is_shown = true; + + /// Internal SDL2 render window + SDL_Window* render_window{}; + + /// Keeps track of how often to update the title bar during gameplay + u32 last_time = 0; + + /// Input subsystem to use with this window. + InputCommon::InputSubsystem* input_subsystem; + + /// yuzu core instance + Core::System& system; +}; + +class DummyContext : public Core::Frontend::GraphicsContext {}; diff --git a/src/citron_cmd/emu_window/emu_window_sdl2_gl.cpp b/src/citron_cmd/emu_window/emu_window_sdl2_gl.cpp new file mode 100644 index 000000000..ddcb048d6 --- /dev/null +++ b/src/citron_cmd/emu_window/emu_window_sdl2_gl.cpp @@ -0,0 +1,153 @@ +// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <algorithm> +#include <cstdlib> +#include <string> + +#define SDL_MAIN_HANDLED +#include <SDL.h> + +#include <fmt/format.h> +#include <glad/glad.h> +#include "common/logging/log.h" +#include "common/scm_rev.h" +#include "common/settings.h" +#include "common/string_util.h" +#include "core/core.h" +#include "input_common/main.h" +#include "video_core/renderer_base.h" +#include "yuzu_cmd/emu_window/emu_window_sdl2_gl.h" + +class SDLGLContext : public Core::Frontend::GraphicsContext { +public: + explicit SDLGLContext(SDL_Window* window_) : window{window_} { + context = SDL_GL_CreateContext(window); + } + + ~SDLGLContext() { + DoneCurrent(); + SDL_GL_DeleteContext(context); + } + + void SwapBuffers() override { + SDL_GL_SwapWindow(window); + } + + void MakeCurrent() override { + if (is_current) { + return; + } + is_current = SDL_GL_MakeCurrent(window, context) == 0; + } + + void DoneCurrent() override { + if (!is_current) { + return; + } + SDL_GL_MakeCurrent(window, nullptr); + is_current = false; + } + +private: + SDL_Window* window; + SDL_GLContext context; + bool is_current = false; +}; + +bool EmuWindow_SDL2_GL::SupportsRequiredGLExtensions() { + std::vector<std::string_view> unsupported_ext; + + // Extensions required to support some texture formats. + if (!GLAD_GL_EXT_texture_compression_s3tc) { + unsupported_ext.push_back("EXT_texture_compression_s3tc"); + } + if (!GLAD_GL_ARB_texture_compression_rgtc) { + unsupported_ext.push_back("ARB_texture_compression_rgtc"); + } + + for (const auto& extension : unsupported_ext) { + LOG_CRITICAL(Frontend, "Unsupported GL extension: {}", extension); + } + + return unsupported_ext.empty(); +} + +EmuWindow_SDL2_GL::EmuWindow_SDL2_GL(InputCommon::InputSubsystem* input_subsystem_, + Core::System& system_, bool fullscreen) + : EmuWindow_SDL2{input_subsystem_, system_} { + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); + SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); + if (Settings::values.renderer_debug) { + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); + } + SDL_GL_SetSwapInterval(0); + + std::string window_title = fmt::format("yuzu {} | {}-{}", Common::g_build_fullname, + Common::g_scm_branch, Common::g_scm_desc); + render_window = + SDL_CreateWindow(window_title.c_str(), + SDL_WINDOWPOS_UNDEFINED, // x position + SDL_WINDOWPOS_UNDEFINED, // y position + Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height, + SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + + if (render_window == nullptr) { + LOG_CRITICAL(Frontend, "Failed to create SDL2 window! {}", SDL_GetError()); + exit(1); + } + + strict_context_required = strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0; + + SetWindowIcon(); + + if (fullscreen) { + Fullscreen(); + ShowCursor(false); + } + + window_context = SDL_GL_CreateContext(render_window); + core_context = CreateSharedContext(); + + if (window_context == nullptr) { + LOG_CRITICAL(Frontend, "Failed to create SDL2 GL context: {}", SDL_GetError()); + exit(1); + } + if (core_context == nullptr) { + LOG_CRITICAL(Frontend, "Failed to create shared SDL2 GL context: {}", SDL_GetError()); + exit(1); + } + + if (!gladLoadGLLoader(static_cast<GLADloadproc>(SDL_GL_GetProcAddress))) { + LOG_CRITICAL(Frontend, "Failed to initialize GL functions! {}", SDL_GetError()); + exit(1); + } + + if (!SupportsRequiredGLExtensions()) { + LOG_CRITICAL(Frontend, "GPU does not support all required OpenGL extensions! Exiting..."); + exit(1); + } + + OnResize(); + OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size); + SDL_PumpEvents(); + LOG_INFO(Frontend, "yuzu Version: {} | {}-{}", Common::g_build_fullname, Common::g_scm_branch, + Common::g_scm_desc); + Settings::LogSettings(); +} + +EmuWindow_SDL2_GL::~EmuWindow_SDL2_GL() { + core_context.reset(); + SDL_GL_DeleteContext(window_context); +} + +std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_GL::CreateSharedContext() const { + return std::make_unique<SDLGLContext>(render_window); +} diff --git a/src/citron_cmd/emu_window/emu_window_sdl2_gl.h b/src/citron_cmd/emu_window/emu_window_sdl2_gl.h new file mode 100644 index 000000000..39346e704 --- /dev/null +++ b/src/citron_cmd/emu_window/emu_window_sdl2_gl.h @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <memory> +#include "core/frontend/emu_window.h" +#include "yuzu_cmd/emu_window/emu_window_sdl2.h" + +namespace Core { +class System; +} + +namespace InputCommon { +class InputSubsystem; +} + +class EmuWindow_SDL2_GL final : public EmuWindow_SDL2 { +public: + explicit EmuWindow_SDL2_GL(InputCommon::InputSubsystem* input_subsystem_, Core::System& system_, + bool fullscreen); + ~EmuWindow_SDL2_GL(); + + std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; + +private: + /// Whether the GPU and driver supports the OpenGL extension required + bool SupportsRequiredGLExtensions(); + + using SDL_GLContext = void*; + + /// The OpenGL context associated with the window + SDL_GLContext window_context; + + /// The OpenGL context associated with the core + std::unique_ptr<Core::Frontend::GraphicsContext> core_context; +}; diff --git a/src/citron_cmd/emu_window/emu_window_sdl2_null.cpp b/src/citron_cmd/emu_window/emu_window_sdl2_null.cpp new file mode 100644 index 000000000..259192f3c --- /dev/null +++ b/src/citron_cmd/emu_window/emu_window_sdl2_null.cpp @@ -0,0 +1,51 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <cstdlib> +#include <memory> +#include <string> + +#include <fmt/format.h> + +#include "common/logging/log.h" +#include "common/scm_rev.h" +#include "video_core/renderer_null/renderer_null.h" +#include "yuzu_cmd/emu_window/emu_window_sdl2_null.h" + +#ifdef YUZU_USE_EXTERNAL_SDL2 +// Include this before SDL.h to prevent the external from including a dummy +#define USING_GENERATED_CONFIG_H +#include <SDL_config.h> +#endif + +#include <SDL.h> + +EmuWindow_SDL2_Null::EmuWindow_SDL2_Null(InputCommon::InputSubsystem* input_subsystem_, + Core::System& system_, bool fullscreen) + : EmuWindow_SDL2{input_subsystem_, system_} { + const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name, + Common::g_scm_branch, Common::g_scm_desc); + render_window = + SDL_CreateWindow(window_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height, + SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + + SetWindowIcon(); + + if (fullscreen) { + Fullscreen(); + ShowCursor(false); + } + + OnResize(); + OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size); + SDL_PumpEvents(); + LOG_INFO(Frontend, "yuzu Version: {} | {}-{} (Null)", Common::g_build_name, + Common::g_scm_branch, Common::g_scm_desc); +} + +EmuWindow_SDL2_Null::~EmuWindow_SDL2_Null() = default; + +std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_Null::CreateSharedContext() const { + return std::make_unique<DummyContext>(); +} diff --git a/src/citron_cmd/emu_window/emu_window_sdl2_null.h b/src/citron_cmd/emu_window/emu_window_sdl2_null.h new file mode 100644 index 000000000..35aee286d --- /dev/null +++ b/src/citron_cmd/emu_window/emu_window_sdl2_null.h @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <memory> + +#include "core/frontend/emu_window.h" +#include "yuzu_cmd/emu_window/emu_window_sdl2.h" + +namespace Core { +class System; +} + +namespace InputCommon { +class InputSubsystem; +} + +class EmuWindow_SDL2_Null final : public EmuWindow_SDL2 { +public: + explicit EmuWindow_SDL2_Null(InputCommon::InputSubsystem* input_subsystem_, + Core::System& system, bool fullscreen); + ~EmuWindow_SDL2_Null() override; + + std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; +}; diff --git a/src/citron_cmd/emu_window/emu_window_sdl2_vk.cpp b/src/citron_cmd/emu_window/emu_window_sdl2_vk.cpp new file mode 100644 index 000000000..8b916f05c --- /dev/null +++ b/src/citron_cmd/emu_window/emu_window_sdl2_vk.cpp @@ -0,0 +1,93 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <cstdlib> +#include <memory> +#include <string> + +#include <fmt/format.h> + +#include "common/logging/log.h" +#include "common/scm_rev.h" +#include "video_core/renderer_vulkan/renderer_vulkan.h" +#include "yuzu_cmd/emu_window/emu_window_sdl2_vk.h" + +#include <SDL.h> +#include <SDL_syswm.h> + +EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem_, + Core::System& system_, bool fullscreen) + : EmuWindow_SDL2{input_subsystem_, system_} { + const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name, + Common::g_scm_branch, Common::g_scm_desc); + render_window = + SDL_CreateWindow(window_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height, + SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + + SDL_SysWMinfo wm; + SDL_VERSION(&wm.version); + if (SDL_GetWindowWMInfo(render_window, &wm) == SDL_FALSE) { + LOG_CRITICAL(Frontend, "Failed to get information from the window manager: {}", + SDL_GetError()); + std::exit(EXIT_FAILURE); + } + + SetWindowIcon(); + + if (fullscreen) { + Fullscreen(); + ShowCursor(false); + } + + switch (wm.subsystem) { +#ifdef SDL_VIDEO_DRIVER_WINDOWS + case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS: + window_info.type = Core::Frontend::WindowSystemType::Windows; + window_info.render_surface = reinterpret_cast<void*>(wm.info.win.window); + break; +#endif +#ifdef SDL_VIDEO_DRIVER_X11 + case SDL_SYSWM_TYPE::SDL_SYSWM_X11: + window_info.type = Core::Frontend::WindowSystemType::X11; + window_info.display_connection = wm.info.x11.display; + window_info.render_surface = reinterpret_cast<void*>(wm.info.x11.window); + break; +#endif +#ifdef SDL_VIDEO_DRIVER_WAYLAND + case SDL_SYSWM_TYPE::SDL_SYSWM_WAYLAND: + window_info.type = Core::Frontend::WindowSystemType::Wayland; + window_info.display_connection = wm.info.wl.display; + window_info.render_surface = wm.info.wl.surface; + break; +#endif +#ifdef SDL_VIDEO_DRIVER_COCOA + case SDL_SYSWM_TYPE::SDL_SYSWM_COCOA: + window_info.type = Core::Frontend::WindowSystemType::Cocoa; + window_info.render_surface = SDL_Metal_CreateView(render_window); + break; +#endif +#ifdef SDL_VIDEO_DRIVER_ANDROID + case SDL_SYSWM_TYPE::SDL_SYSWM_ANDROID: + window_info.type = Core::Frontend::WindowSystemType::Android; + window_info.render_surface = reinterpret_cast<void*>(wm.info.android.window); + break; +#endif + default: + LOG_CRITICAL(Frontend, "Window manager subsystem {} not implemented", wm.subsystem); + std::exit(EXIT_FAILURE); + break; + } + + OnResize(); + OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size); + SDL_PumpEvents(); + LOG_INFO(Frontend, "yuzu Version: {} | {}-{} (Vulkan)", Common::g_build_name, + Common::g_scm_branch, Common::g_scm_desc); +} + +EmuWindow_SDL2_VK::~EmuWindow_SDL2_VK() = default; + +std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_VK::CreateSharedContext() const { + return std::make_unique<DummyContext>(); +} diff --git a/src/citron_cmd/emu_window/emu_window_sdl2_vk.h b/src/citron_cmd/emu_window/emu_window_sdl2_vk.h new file mode 100644 index 000000000..9467d164a --- /dev/null +++ b/src/citron_cmd/emu_window/emu_window_sdl2_vk.h @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <memory> + +#include "core/frontend/emu_window.h" +#include "yuzu_cmd/emu_window/emu_window_sdl2.h" + +namespace Core { +class System; +} + +namespace InputCommon { +class InputSubsystem; +} + +class EmuWindow_SDL2_VK final : public EmuWindow_SDL2 { +public: + explicit EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem_, Core::System& system, + bool fullscreen); + ~EmuWindow_SDL2_VK() override; + + std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; +}; |