HostDisplay: Move most backend logic to FrontendCommon

This commit is contained in:
Connor McLaughlin
2020-06-30 02:46:57 +10:00
parent 84a52a3911
commit 2a38090e7a
43 changed files with 870 additions and 1909 deletions

View File

@ -13,12 +13,6 @@ HostDisplayTexture::~HostDisplayTexture() = default;
HostDisplay::~HostDisplay() = default;
void HostDisplay::WindowResized(s32 new_window_width, s32 new_window_height)
{
m_window_width = new_window_width;
m_window_height = new_window_height;
}
void HostDisplay::SetSoftwareCursor(std::unique_ptr<HostDisplayTexture> texture, float scale /*= 1.0f*/)
{
m_cursor_texture = std::move(texture);
@ -68,7 +62,7 @@ void HostDisplay::CalculateDrawRect(s32 window_width, s32 window_height, s32* ou
float* out_y_scale) const
{
const float y_scale =
(static_cast<float>(m_display_width) / static_cast<float>(m_display_height)) / m_display_pixel_aspect_ratio;
(static_cast<float>(m_display_width) / static_cast<float>(m_display_height)) / m_display_aspect_ratio;
const float display_width = static_cast<float>(m_display_width);
const float display_height = static_cast<float>(m_display_height) * y_scale;
const float active_left = static_cast<float>(m_display_active_left);
@ -266,26 +260,28 @@ bool HostDisplay::WriteDisplayTextureToFile(const char* filename, bool full_reso
s32 resize_height = 0;
if (apply_aspect_ratio && full_resolution)
{
if (m_display_pixel_aspect_ratio > 1.0f)
if (m_display_aspect_ratio > 1.0f)
{
resize_width = m_display_texture_view_width;
resize_height = static_cast<s32>(static_cast<float>(resize_width) / m_display_pixel_aspect_ratio);
resize_height = static_cast<s32>(static_cast<float>(resize_width) / m_display_aspect_ratio);
}
else
{
resize_height = std::abs(m_display_texture_view_height);
resize_width = static_cast<s32>(static_cast<float>(resize_height) * m_display_pixel_aspect_ratio);
resize_width = static_cast<s32>(static_cast<float>(resize_height) * m_display_aspect_ratio);
}
}
else if (apply_aspect_ratio)
{
const auto [left, top, right, bottom] = CalculateDrawRect(m_window_width, m_window_height, m_display_top_margin);
const auto [left, top, right, bottom] =
CalculateDrawRect(GetWindowWidth(), GetWindowHeight(), m_display_top_margin);
resize_width = right - left;
resize_height = bottom - top;
}
else if (!full_resolution)
{
const auto [left, top, right, bottom] = CalculateDrawRect(m_window_width, m_window_height, m_display_top_margin);
const auto [left, top, right, bottom] =
CalculateDrawRect(GetWindowWidth(), GetWindowHeight(), m_display_top_margin);
const float ratio =
static_cast<float>(m_display_texture_view_width) / static_cast<float>(std::abs(m_display_texture_view_height));
if (ratio > 1.0f)

View File

@ -1,7 +1,9 @@
#pragma once
#include "common/rectangle.h"
#include "common/window_info.h"
#include "types.h"
#include <memory>
#include <string_view>
#include <tuple>
#include <vector>
@ -31,8 +33,8 @@ public:
virtual ~HostDisplay();
ALWAYS_INLINE s32 GetWindowWidth() const { return m_window_width; }
ALWAYS_INLINE s32 GetWindowHeight() const { return m_window_height; }
ALWAYS_INLINE s32 GetWindowWidth() const { return static_cast<s32>(m_window_info.surface_width); }
ALWAYS_INLINE s32 GetWindowHeight() const { return static_cast<s32>(m_window_info.surface_height); }
// Position is relative to the top-left corner of the window.
ALWAYS_INLINE s32 GetMousePositionX() const { return m_mouse_position_x; }
@ -47,8 +49,19 @@ public:
virtual void* GetRenderDevice() const = 0;
virtual void* GetRenderContext() const = 0;
virtual bool HasRenderDevice() const = 0;
virtual bool HasRenderSurface() const = 0;
virtual bool CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device) = 0;
virtual bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device) = 0;
virtual bool MakeRenderContextCurrent() = 0;
virtual bool DoneRenderContextCurrent() = 0;
virtual void DestroyRenderDevice() = 0;
virtual void DestroyRenderSurface() = 0;
virtual bool ChangeRenderWindow(const WindowInfo& wi) = 0;
/// Call when the window size changes externally to recreate any resources.
virtual void WindowResized(s32 new_window_width, s32 new_window_height);
virtual void ResizeRenderWindow(s32 new_window_width, s32 new_window_height) = 0;
/// Creates an abstracted RGBA8 texture. If dynamic, the texture can be updated with UpdateTexture() below.
virtual std::unique_ptr<HostDisplayTexture> CreateTexture(u32 width, u32 height, const void* data, u32 data_stride,
@ -59,7 +72,8 @@ public:
virtual bool DownloadTexture(const void* texture_handle, u32 x, u32 y, u32 width, u32 height, void* out_data,
u32 out_data_stride) = 0;
virtual void Render() = 0;
/// Returns false if the window was completely occluded.
virtual bool Render() = 0;
virtual void SetVSync(bool enabled) = 0;
@ -91,7 +105,7 @@ public:
}
void SetDisplayParameters(s32 display_width, s32 display_height, s32 active_left, s32 active_top, s32 active_width,
s32 active_height, float pixel_aspect_ratio)
s32 active_height, float display_aspect_ratio)
{
m_display_width = display_width;
m_display_height = display_height;
@ -99,7 +113,7 @@ public:
m_display_active_top = active_top;
m_display_active_width = active_width;
m_display_active_height = active_height;
m_display_pixel_aspect_ratio = pixel_aspect_ratio;
m_display_aspect_ratio = display_aspect_ratio;
m_display_changed = true;
}
@ -147,8 +161,7 @@ protected:
std::tuple<s32, s32, s32, s32> CalculateSoftwareCursorDrawRect() const;
s32 m_window_width = 0;
s32 m_window_height = 0;
WindowInfo m_window_info;
s32 m_mouse_position_x = 0;
s32 m_mouse_position_y = 0;
@ -159,7 +172,7 @@ protected:
s32 m_display_active_top = 0;
s32 m_display_active_width = 0;
s32 m_display_active_height = 0;
float m_display_pixel_aspect_ratio = 1.0f;
float m_display_aspect_ratio = 1.0f;
void* m_display_texture_handle = nullptr;
s32 m_display_texture_width = 0;

View File

@ -39,7 +39,7 @@ public:
virtual ~HostInterface();
/// Access to host display.
ALWAYS_INLINE HostDisplay* GetDisplay() const { return m_display; }
ALWAYS_INLINE HostDisplay* GetDisplay() const { return m_display.get(); }
/// Access to host audio stream.
ALWAYS_INLINE AudioStream* GetAudioStream() const { return m_audio_stream.get(); }
@ -96,6 +96,12 @@ public:
/// Retrieves information about specified game from game list.
virtual void GetGameInfo(const char* path, CDImage* image, std::string* code, std::string* title);
/// Returns the default path to a memory card.
virtual std::string GetSharedMemoryCardPath(u32 slot) const;
/// Returns the default path to a memory card for a specific game.
virtual std::string GetGameMemoryCardPath(const char* game_code, u32 slot) const;
/// Enables the software cursor. Can be called multiple times, but must be matched by a call to DisableSoftwareCursor().
void EnableSoftwareCursor();
@ -135,12 +141,6 @@ protected:
/// Sets the user directory to the program directory, i.e. "portable mode".
void SetUserDirectoryToProgramDirectory();
/// Returns the default path to a memory card.
std::string GetSharedMemoryCardPath(u32 slot) const;
/// Returns the default path to a memory card for a specific game.
std::string GetGameMemoryCardPath(const char* game_code, u32 slot) const;
/// Loads the BIOS image for the specified region.
std::optional<std::vector<u8>> GetBIOSImage(ConsoleRegion region);
@ -153,7 +153,7 @@ protected:
bool SaveState(const char* filename);
void CreateAudioStream();
HostDisplay* m_display = nullptr;
std::unique_ptr<HostDisplay> m_display;
std::unique_ptr<AudioStream> m_audio_stream;
std::unique_ptr<System> m_system;
Settings m_settings;

View File

@ -463,7 +463,7 @@ const char* Settings::GetControllerTypeDisplayName(ControllerType type)
static std::array<const char*, 4> s_memory_card_type_names = {{"None", "Shared", "PerGame", "PerGameTitle"}};
static std::array<const char*, 4> s_memory_card_type_display_names = {{"No Memory Card", "Shared Between All Games",
"Separate Card Per Game (Game Code)",
"Seperate Card Per Game (Game Title)"}};
"Separate Card Per Game (Game Title)"}};
std::optional<MemoryCardType> Settings::ParseMemoryCardTypeName(const char* str)
{

View File

@ -45,6 +45,12 @@ struct SystemBootParameters
class System
{
public:
enum : u32
{
// 5 megabytes is sufficient for now, at the moment they're around 4.2MB.
MAX_SAVE_STATE_SIZE = 5 * 1024 * 1024
};
friend TimingEvent;
~System();