[UI] Image post-processing and full presentation/window rework

[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
This commit is contained in:
Triang3l
2022-01-29 13:22:03 +03:00
parent 372bdd3ec9
commit fe3f0f26e4
428 changed files with 75942 additions and 18360 deletions

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2020 Ben Vanik. All rights reserved. *
* Copyright 2022 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -13,10 +13,15 @@
#include <memory>
#include <string>
#include "xenia/base/platform_win.h"
#include "xenia/ui/menu_item.h"
#include "xenia/ui/window.h"
// Must be included before Windows headers for things like NOMINMAX.
#include "xenia/base/platform_win.h"
#include <ShellScalingApi.h>
#include <dxgi.h>
namespace xe {
namespace ui {
@@ -24,73 +29,127 @@ class Win32Window : public Window {
using super = Window;
public:
Win32Window(WindowedAppContext& app_context, const std::string& title);
Win32Window(WindowedAppContext& app_context, const std::string_view title,
uint32_t desired_logical_width, uint32_t desired_logical_height);
~Win32Window() override;
NativePlatformHandle native_platform_handle() const override;
NativeWindowHandle native_handle() const override { return hwnd_; }
// Will be null if the window hasn't been successfully opened yet, or has been
// closed.
HWND hwnd() const { return hwnd_; }
void EnableMainMenu() override;
void DisableMainMenu() override;
bool set_title(const std::string_view title) override;
bool SetIcon(const void* buffer, size_t size) override;
bool CaptureMouse() override;
bool ReleaseMouse() override;
bool is_fullscreen() const override;
void ToggleFullscreen(bool fullscreen) override;
bool is_bordered() const override;
void set_bordered(bool enabled) override;
int get_dpi() const override;
void set_cursor_visible(bool value) override;
void set_focus(bool value) override;
void Resize(int32_t width, int32_t height) override;
void Resize(int32_t left, int32_t top, int32_t right,
int32_t bottom) override;
// (raw) Resize the window, no DPI scaling applied.
void RawReposition(const RECT& rc);
bool Initialize() override;
void Invalidate() override;
void Close() override;
uint32_t GetMediumDpi() const override;
protected:
bool OnCreate() override;
void OnMainMenuChange() override;
void OnDestroy() override;
void OnClose() override;
bool OpenImpl() override;
void RequestCloseImpl() override;
void OnResize(UIEvent* e) override;
uint32_t GetLatestDpiImpl() const override;
void ApplyNewFullscreen() override;
void ApplyNewTitle() override;
void LoadAndApplyIcon(const void* buffer, size_t size,
bool can_apply_state_in_current_phase) override;
void ApplyNewMainMenu(MenuItem* old_main_menu) override;
void CompleteMainMenuItemsUpdateImpl() override;
void ApplyNewMouseCapture() override;
void ApplyNewMouseRelease() override;
void ApplyNewCursorVisibility(
CursorVisibility old_cursor_visibility) override;
void FocusImpl() override;
std::unique_ptr<Surface> CreateSurfaceImpl(
Surface::TypeFlags allowed_types) override;
void RequestPaintImpl() override;
private:
enum : UINT {
kUserMessageAutoHideCursor = WM_USER,
};
BOOL AdjustWindowRectangle(RECT& rect, DWORD style, BOOL menu, DWORD ex_style,
UINT dpi) const;
BOOL AdjustWindowRectangle(RECT& rect) const;
uint32_t GetCurrentSystemDpi() const;
uint32_t GetCurrentDpi() const;
void ApplyFullscreenEntry(WindowDestructionReceiver& destruction_receiver);
void HandleSizeUpdate(WindowDestructionReceiver& destruction_receiver);
// For updating multiple factors that may influence the window size at once,
// without handling WM_SIZE multiple times (that may not only result in wasted
// handling, but also in the state potentially changed to an inconsistent one
// in the middle of a size update by the listeners).
void BeginBatchedSizeUpdate();
void EndBatchedSizeUpdate(WindowDestructionReceiver& destruction_receiver);
bool HandleMouse(UINT message, WPARAM wParam, LPARAM lParam,
WindowDestructionReceiver& destruction_receiver);
bool HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam,
WindowDestructionReceiver& destruction_receiver);
void SetCursorIfFocusedOnClientArea(HCURSOR cursor) const;
void SetCursorAutoHideTimer();
static void NTAPI AutoHideCursorTimerCallback(void* parameter,
BOOLEAN timer_or_wait_fired);
static LRESULT CALLBACK WndProcThunk(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam);
// This can't handle messages sent during CreateWindow (hwnd_ still not
// assigned to) or after nulling hwnd_ in closing / deleting.
virtual LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam);
private:
void EnableMMCSS();
bool HandleMouse(UINT message, WPARAM wParam, LPARAM lParam);
bool HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam);
HWND hwnd_ = nullptr;
HICON icon_ = nullptr;
bool closing_ = false;
bool fullscreen_ = false;
HCURSOR arrow_cursor_ = nullptr;
WINDOWPLACEMENT windowed_pos_ = {0};
POINT last_mouse_pos_ = {0};
HICON icon_ = nullptr;
void* GetDpiForMonitor_ = nullptr;
uint32_t dpi_ = USER_DEFAULT_SCREEN_DPI;
// hwnd_ may be accessed by the cursor hiding timer callback from a separate
// thread, but the timer can be active only with a valid window anyway.
HWND hwnd_ = nullptr;
uint32_t batched_size_update_depth_ = 0;
bool batched_size_update_contained_wm_size_ = false;
bool batched_size_update_contained_wm_paint_ = false;
uint32_t pre_fullscreen_dpi_;
WINDOWPLACEMENT pre_fullscreen_placement_;
// The client area part of pre_fullscreen_placement_.rcNormalPosition, saved
// in case something effecting the behavior of AdjustWindowRectEx for the
// non-fullscreen state is changed mid-fullscreen (for instance, the menu is
// toggled), so a new AdjustWindowRectExForDpi call for the old DPI, but with
// the other state different than the old one, while exiting fullscreen, won't
// cause anomalies like negative size.
uint32_t pre_fullscreen_normal_client_width_;
uint32_t pre_fullscreen_normal_client_height_;
// Must be the screen position, not the client position, so it's possible to
// immediately hide the cursor, for instance, when switching to fullscreen
// (and thus changing the client area top-left corner, resulting in
// WM_MOUSEMOVE being sent, which would instantly reveal the cursor because of
// that relative position change).
POINT cursor_auto_hide_last_screen_pos_ = {LONG_MAX, LONG_MAX};
// Using a timer queue timer for hiding the cursor rather than WM_TIMER
// because the latter is a very low-priority message which is never received
// if WM_PAINT messages are sent continuously (invalidating the window right
// after painting).
HANDLE cursor_auto_hide_timer_ = nullptr;
// Last hiding case numbers for skipping of obsolete cursor hiding messages
// (both WM_MOUSEMOVE and the hiding message have been sent, for instance, and
// WM_MOUSEMOVE hasn't been handled yet, or the cursor visibility state has
// been changed). The queued index is read, and the signaled index is written,
// by the timer callback, which is executed outside the message thread, so
// before modifying the queued number, or reading the signaled number, in the
// message thread, delete the timer (deleting the timer awaits cancels the
// callback if it hasn't been invoked yet, or awaits it if it has). Use
// equality comparison for safe rollover handling.
WPARAM last_cursor_auto_hide_queued = 0;
WPARAM last_cursor_auto_hide_signaled = 0;
// Whether the cursor has been hidden after the expiration of the timer, and
// hasn't been revealed yet.
bool cursor_currently_auto_hidden_ = false;
};
class Win32MenuItem : public MenuItem {
@@ -99,10 +158,9 @@ class Win32MenuItem : public MenuItem {
std::function<void()> callback);
~Win32MenuItem() override;
HMENU handle() { return handle_; }
HMENU handle() const { return handle_; }
void EnableMenuItem(Window& window) override;
void DisableMenuItem(Window& window) override;
void SetEnabled(bool enabled) override;
using MenuItem::OnSelected;