| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include "Common/Flag.h" |
| 7 |
#include "Common/MathUtil.h" |
| 8 |
|
| 9 |
#include "VideoCommon/OnScreenUIKeyMap.h" |
| 10 |
#include "VideoCommon/TextureCacheBase.h" |
| 11 |
#include "VideoCommon/TextureConfig.h" |
| 12 |
#include "VideoCommon/VideoCommon.h" |
| 13 |
|
| 14 |
#include <array> |
| 15 |
#include <memory> |
| 16 |
#include <mutex> |
| 17 |
#include <tuple> |
| 18 |
|
| 19 |
class AbstractTexture; |
| 20 |
struct SurfaceInfo; |
| 21 |
enum class DolphinKey; |
| 22 |
|
| 23 |
namespace VideoCommon |
| 24 |
{ |
| 25 |
class OnScreenUI; |
| 26 |
class PostProcessing; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
class Presenter |
| 31 |
{ |
| 32 |
public: |
| 33 |
using ClearColor = std::array<float, 4>; |
| 34 |
|
| 35 |
Presenter(); |
| 36 |
virtual ~Presenter(); |
| 37 |
|
| 38 |
void ViSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u64 ticks, |
| 39 |
TimePoint presentation_time); |
| 40 |
void ImmediateSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height); |
| 41 |
|
| 42 |
void SetNextSwapEstimatedTime(u64 ticks, TimePoint host_time); |
| 43 |
|
| 44 |
void Present(PresentInfo* present_info = nullptr); |
| 45 |
void ClearLastXfbId() { m_last_xfb_id = std::numeric_limits<u64>::max(); } |
| 46 |
|
| 47 |
bool Initialize(); |
| 48 |
|
| 49 |
void ConfigChanged(u32 changed_bits); |
| 50 |
|
| 51 |
|
| 52 |
int GetBackbufferWidth() const { return m_backbuffer_width; } |
| 53 |
int GetBackbufferHeight() const { return m_backbuffer_height; } |
| 54 |
float GetBackbufferScale() const { return m_backbuffer_scale; } |
| 55 |
u32 AutoIntegralScale() const; |
| 56 |
AbstractTextureFormat GetBackbufferFormat() const { return m_backbuffer_format; } |
| 57 |
void SetSuggestedWindowSize(int width, int height); |
| 58 |
void SetBackbuffer(int backbuffer_width, int backbuffer_height); |
| 59 |
void SetBackbuffer(SurfaceInfo info); |
| 60 |
void OnBackbufferSet(bool size_changed, bool is_first_set); |
| 61 |
|
| 62 |
void UpdateDrawRectangle(); |
| 63 |
|
| 64 |
|
| 65 |
MathUtil::Rectangle<int> GetCustomCrop(const MathUtil::Rectangle<int>& rect) const; |
| 66 |
|
| 67 |
|
| 68 |
MathUtil::Rectangle<int> AdjustForCustomCrop(const MathUtil::Rectangle<int>& rect) const; |
| 69 |
|
| 70 |
|
| 71 |
float AdjustAspectRatioForCustomCrop(float input_aspect_ratio) const; |
| 72 |
|
| 73 |
|
| 74 |
float CalculateDrawAspectRatio(bool allow_stretch = true) const; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
void AdjustRectanglesToFitBounds(MathUtil::Rectangle<int>* target_rect, |
| 80 |
MathUtil::Rectangle<int>* source_rect, int fb_width, |
| 81 |
int fb_height); |
| 82 |
|
| 83 |
void ReleaseXFBContentLock(); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
virtual void RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc, |
| 88 |
const AbstractTexture* source_texture, |
| 89 |
const MathUtil::Rectangle<int>& source_rc); |
| 90 |
|
| 91 |
VideoCommon::PostProcessing* GetPostProcessor() const { return m_post_processor.get(); } |
| 92 |
|
| 93 |
|
| 94 |
void ChangeSurface(void* new_surface_handle); |
| 95 |
void ResizeSurface(); |
| 96 |
bool SurfaceResizedTestAndClear() { return m_surface_resized.TestAndClear(); } |
| 97 |
bool SurfaceChangedTestAndClear() { return m_surface_changed.TestAndClear(); } |
| 98 |
void* GetNewSurfaceHandle(); |
| 99 |
|
| 100 |
void SetKeyMap(const DolphinKeyMap& key_map); |
| 101 |
|
| 102 |
void SetKey(u32 key, bool is_down, const char* chars); |
| 103 |
void SetMousePos(float x, float y); |
| 104 |
void SetMousePress(u32 button_mask); |
| 105 |
|
| 106 |
int FrameCount() const { return m_frame_count; } |
| 107 |
|
| 108 |
void DoState(PointerWrap& p); |
| 109 |
|
| 110 |
const MathUtil::Rectangle<int>& GetTargetRectangle() const { return m_target_rectangle; } |
| 111 |
|
| 112 |
private: |
| 113 |
|
| 114 |
|
| 115 |
bool FetchXFB(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u64 ticks); |
| 116 |
|
| 117 |
void ProcessFrameDumping(u64 ticks) const; |
| 118 |
|
| 119 |
void OnBackBufferSizeChanged(); |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
std::tuple<int, int> CalculateOutputDimensions(int width, int height, |
| 124 |
bool allow_stretch = true) const; |
| 125 |
std::tuple<float, float> ApplyStandardAspectCrop(float width, float height, |
| 126 |
bool allow_stretch = true) const; |
| 127 |
|
| 128 |
std::tuple<float, float> ScaleToDisplayAspectRatio(int width, int height, |
| 129 |
bool allow_stretch = true) const; |
| 130 |
|
| 131 |
|
| 132 |
std::tuple<MathUtil::Rectangle<int>, MathUtil::Rectangle<int>> |
| 133 |
ConvertStereoRectangle(const MathUtil::Rectangle<int>& rc) const; |
| 134 |
|
| 135 |
std::mutex m_swap_mutex; |
| 136 |
|
| 137 |
|
| 138 |
int m_backbuffer_width = 0; |
| 139 |
int m_backbuffer_height = 0; |
| 140 |
float m_backbuffer_scale = 1.0f; |
| 141 |
AbstractTextureFormat m_backbuffer_format = AbstractTextureFormat::Undefined; |
| 142 |
|
| 143 |
void* m_new_surface_handle = nullptr; |
| 144 |
Common::Flag m_surface_changed; |
| 145 |
Common::Flag m_surface_resized; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
MathUtil::Rectangle<int> m_target_rectangle = {}; |
| 151 |
|
| 152 |
u32 m_auto_resolution_scale = 1; |
| 153 |
|
| 154 |
RcTcacheEntry m_xfb_entry; |
| 155 |
|
| 156 |
MathUtil::Rectangle<int> m_xfb_rect{0, 0, MAX_XFB_WIDTH, MAX_XFB_HEIGHT}; |
| 157 |
|
| 158 |
|
| 159 |
u64 m_last_xfb_id = std::numeric_limits<u64>::max(); |
| 160 |
|
| 161 |
|
| 162 |
int m_last_window_request_width = 0; |
| 163 |
int m_last_window_request_height = 0; |
| 164 |
|
| 165 |
std::unique_ptr<VideoCommon::PostProcessing> m_post_processor; |
| 166 |
std::unique_ptr<VideoCommon::OnScreenUI> m_onscreen_ui; |
| 167 |
|
| 168 |
u64 m_frame_count = 0; |
| 169 |
u64 m_present_count = 0; |
| 170 |
|
| 171 |
|
| 172 |
u64 m_last_xfb_ticks = 0; |
| 173 |
u32 m_last_xfb_addr = 0; |
| 174 |
|
| 175 |
u32 m_last_xfb_width = MAX_XFB_WIDTH; |
| 176 |
u32 m_last_xfb_stride = 0; |
| 177 |
|
| 178 |
u32 m_last_xfb_height = MAX_XFB_HEIGHT; |
| 179 |
|
| 180 |
Common::EventHook m_config_changed; |
| 181 |
Common::EventHook m_end_field_hook; |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
TimePoint GetUpdatedPresentationTime(TimePoint intended_presentation_time); |
| 186 |
|
| 187 |
|
| 188 |
DT m_presentation_time_offset{}; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
u64 m_next_swap_estimated_ticks = 0; |
| 193 |
TimePoint m_next_swap_estimated_time{Clock::now()}; |
| 194 |
|
| 195 |
std::atomic_bool m_immediate_swap_happened_this_field{}; |
| 196 |
}; |
| 197 |
|
| 198 |
} |
| 199 |
|
| 200 |
extern std::unique_ptr<VideoCommon::Presenter> g_presenter; |