Inject GLFW shell and move Win32 key map
This commit is contained in:
@@ -48,6 +48,11 @@ namespace {
|
||||
// DEBT-0017: fallback for platforms that do not inject PlatformServices yet.
|
||||
class LegacyPlatformServices final : public pp::platform::PlatformServices {
|
||||
public:
|
||||
explicit LegacyPlatformServices(pp::platform::legacy::LegacyGlfwPlatformShell glfw_shell = {})
|
||||
: glfw_shell_(std::move(glfw_shell))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_storage_paths() override
|
||||
{
|
||||
#if defined(__IOS__)
|
||||
@@ -181,7 +186,7 @@ public:
|
||||
#elif __ANDROID__
|
||||
android_async_lock();
|
||||
#elif __LINUX__ || __WEB__
|
||||
pp::platform::legacy::acquire_legacy_glfw_render_context();
|
||||
invoke_legacy_glfw_shell_callback(glfw_shell_.acquire_render_context);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -201,7 +206,7 @@ public:
|
||||
#elif __ANDROID__
|
||||
android_async_swap();
|
||||
#elif __LINUX__ || __WEB__
|
||||
pp::platform::legacy::present_legacy_glfw_render_context();
|
||||
invoke_legacy_glfw_shell_callback(glfw_shell_.present_render_context);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -507,7 +512,7 @@ public:
|
||||
#ifdef __OSX__
|
||||
pp::platform::apple::active_legacy_apple_document_platform_services().request_app_close();
|
||||
#elif __LINUX__
|
||||
pp::platform::legacy::request_legacy_glfw_app_close();
|
||||
invoke_legacy_glfw_shell_callback(glfw_shell_.request_app_close);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -545,6 +550,15 @@ public:
|
||||
callback(value, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
static void invoke_legacy_glfw_shell_callback(const std::function<void()>& callback)
|
||||
{
|
||||
if (callback)
|
||||
callback();
|
||||
}
|
||||
|
||||
pp::platform::legacy::LegacyGlfwPlatformShell glfw_shell_;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -557,8 +571,9 @@ PlatformServices& platform_services()
|
||||
return services;
|
||||
}
|
||||
|
||||
std::unique_ptr<PlatformServices> create_platform_services()
|
||||
std::unique_ptr<PlatformServices> create_platform_services(
|
||||
LegacyGlfwPlatformShell glfw_shell)
|
||||
{
|
||||
return std::make_unique<LegacyPlatformServices>();
|
||||
return std::make_unique<LegacyPlatformServices>(std::move(glfw_shell));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
#include "platform_api/platform_services.h"
|
||||
|
||||
namespace pp::platform::legacy {
|
||||
|
||||
struct LegacyGlfwPlatformShell {
|
||||
std::function<void()> acquire_render_context;
|
||||
std::function<void()> present_render_context;
|
||||
std::function<void()> request_app_close;
|
||||
};
|
||||
|
||||
[[nodiscard]] PlatformServices& platform_services();
|
||||
[[nodiscard]] std::unique_ptr<PlatformServices> create_platform_services();
|
||||
[[nodiscard]] std::unique_ptr<PlatformServices> create_platform_services(
|
||||
LegacyGlfwPlatformShell glfw_shell = {});
|
||||
|
||||
}
|
||||
|
||||
@@ -107,21 +107,6 @@ void set_legacy_glfw_window_title(std::string_view title)
|
||||
const std::string title_value(title);
|
||||
glfwSetWindowTitle(window, title_value.c_str());
|
||||
}
|
||||
|
||||
void acquire_legacy_glfw_render_context()
|
||||
{
|
||||
glfwMakeContextCurrent(retained_legacy_glfw_platform_state().window);
|
||||
}
|
||||
|
||||
void present_legacy_glfw_render_context()
|
||||
{
|
||||
glfwSwapBuffers(retained_legacy_glfw_platform_state().window);
|
||||
}
|
||||
|
||||
void request_legacy_glfw_app_close()
|
||||
{
|
||||
glfwSetWindowShouldClose(retained_legacy_glfw_platform_state().window, GLFW_TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services()
|
||||
|
||||
@@ -14,9 +14,6 @@ namespace pp::platform::legacy {
|
||||
#if defined(__LINUX__) || defined(__WEB__)
|
||||
void set_legacy_glfw_window(GLFWwindow* window);
|
||||
void set_legacy_glfw_window_title(std::string_view title);
|
||||
void acquire_legacy_glfw_render_context();
|
||||
void present_legacy_glfw_render_context();
|
||||
void request_legacy_glfw_app_close();
|
||||
#endif
|
||||
|
||||
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services();
|
||||
|
||||
Reference in New Issue
Block a user