Retain Apple bridge services and bind Win32 runtime
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "app.h"
|
||||
#include "legacy_preference_storage.h"
|
||||
#include "platform_windows/windows_runtime_shell.h"
|
||||
#include "platform_windows/windows_stylus_input.h"
|
||||
|
||||
namespace pp::platform::windows {
|
||||
@@ -50,6 +51,7 @@ void handle_window_close_message(VrShellState& vr)
|
||||
App::I->runtime().ui_thread_stop();
|
||||
App::I->runtime().render_thread_stop();
|
||||
App::I->terminate();
|
||||
bind_runtime(nullptr);
|
||||
delete App::I;
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
#include "platform_windows/windows_bootstrap_helpers.h"
|
||||
#include "platform_windows/windows_lifecycle_shell.h"
|
||||
#include "platform_windows/windows_platform_services.h"
|
||||
#include "platform_windows/windows_runtime_shell.h"
|
||||
#include "platform_windows/windows_stylus_input.h"
|
||||
#include "platform_windows/windows_window_shell.h"
|
||||
|
||||
#include "app_runtime.h"
|
||||
#include "log.h"
|
||||
#include "legacy_gl_runtime_dispatch.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
@@ -171,18 +173,25 @@ void swap_async_render_context()
|
||||
|
||||
void enqueue_main_thread_task(std::packaged_task<void()> task)
|
||||
{
|
||||
if (!App::I)
|
||||
if (auto* runtime = bound_runtime())
|
||||
{
|
||||
task();
|
||||
runtime->main_thread_task(std::move(task));
|
||||
return;
|
||||
}
|
||||
App::I->runtime().main_thread_task(std::move(task));
|
||||
|
||||
if (!task.valid())
|
||||
return;
|
||||
|
||||
task();
|
||||
}
|
||||
|
||||
void drain_main_thread_tasks()
|
||||
{
|
||||
if (App::I)
|
||||
App::I->runtime().drain_main_thread_tasks();
|
||||
if (auto* runtime = bound_runtime())
|
||||
{
|
||||
runtime->drain_main_thread_tasks();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace pp::platform::windows
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "platform_windows/windows_runtime_shell.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "app_runtime.h"
|
||||
#include "log.h"
|
||||
#include "platform_windows/windows_bootstrap_helpers.h"
|
||||
#include "platform_windows/windows_lifecycle_shell.h"
|
||||
@@ -16,6 +17,16 @@ namespace pp::platform::windows {
|
||||
|
||||
namespace {
|
||||
|
||||
struct RetainedWindowsRuntimeState final {
|
||||
AppRuntime* runtime = nullptr;
|
||||
};
|
||||
|
||||
[[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state()
|
||||
{
|
||||
static RetainedWindowsRuntimeState state;
|
||||
return state;
|
||||
}
|
||||
|
||||
void register_touch_window(HWND hWnd)
|
||||
{
|
||||
// link: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-registertouchwindow
|
||||
@@ -102,12 +113,23 @@ void shutdown_main_window_runtime(const MainWindowStartupState& startup, HINSTAN
|
||||
|
||||
}
|
||||
|
||||
void bind_runtime(AppRuntime* runtime) noexcept
|
||||
{
|
||||
retained_runtime_state().runtime = runtime;
|
||||
}
|
||||
|
||||
AppRuntime* bound_runtime() noexcept
|
||||
{
|
||||
return retained_runtime_state().runtime;
|
||||
}
|
||||
|
||||
int run_main_application(int argc, char** argv)
|
||||
{
|
||||
auto& state = retained_state();
|
||||
state.hInst = GetModuleHandle(NULL);
|
||||
|
||||
App::I = new App();
|
||||
bind_runtime(&App::I->runtime());
|
||||
App::I->set_platform_services(&pp::platform::windows::platform_services());
|
||||
App::I->initLog();
|
||||
|
||||
@@ -136,8 +158,10 @@ int run_main_application(int argc, char** argv)
|
||||
case pp::platform::windows::MainStartupResult::Ok:
|
||||
break;
|
||||
case pp::platform::windows::MainStartupResult::GladLoadFailure:
|
||||
bind_runtime(nullptr);
|
||||
return 0;
|
||||
case pp::platform::windows::MainStartupResult::MissingCoreContextSupport:
|
||||
bind_runtime(nullptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -151,6 +175,7 @@ int run_main_application(int argc, char** argv)
|
||||
case const_hash("convert"):
|
||||
App::I->initShaders();
|
||||
App::I->cmd_convert(argv[2], argv[3]);
|
||||
bind_runtime(nullptr);
|
||||
return 0;
|
||||
case const_hash("-vrmode"):
|
||||
start_in_vr = true;
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
#include "platform_windows/windows_bootstrap_helpers.h"
|
||||
#include "platform_windows/windows_splash.h"
|
||||
|
||||
class AppRuntime;
|
||||
|
||||
namespace pp::platform::windows {
|
||||
|
||||
int run_main_application(int argc, char** argv);
|
||||
void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, SplashScreen& splash);
|
||||
void bind_runtime(AppRuntime* runtime) noexcept;
|
||||
[[nodiscard]] AppRuntime* bound_runtime() noexcept;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user