Route render context lifecycle through platform services

This commit is contained in:
2026-06-03 04:50:42 +02:00
parent f3925f8423
commit 7a9b14a86f
10 changed files with 134 additions and 49 deletions

View File

@@ -16,15 +16,7 @@
#endif
#include "settings.h"
#ifdef __ANDROID__
void android_async_lock();
void android_async_swap();
void android_async_unlock();
#elif _WIN32
bool async_lock_try();
void async_lock();
void win32_async_swap();
void async_unlock();
#ifdef _WIN32
void win32_renderdoc_frame_start();
void win32_renderdoc_frame_end();
#elif __LINUX__
@@ -609,18 +601,7 @@ void App::init()
void App::async_start()
{
#if __OSX__
[osx_view async_lock];
#elif __IOS__
[ios_view async_lock];
#elif __ANDROID__
android_async_lock();
#elif _WIN32
async_lock();
glBindFramebuffer(framebuffer_target(), default_framebuffer_id());
#elif __LINUX__ || __WEB__
glfwMakeContextCurrent(glfw_window);
#endif
acquire_render_context();
}
void App::async_redraw()
@@ -631,30 +612,12 @@ void App::async_redraw()
void App::async_end()
{
#if __OSX__
[osx_view async_unlock];
#elif __IOS__
[ios_view async_unlock];
#elif __ANDROID__
android_async_unlock();
#elif _WIN32
async_unlock();
#endif
release_render_context();
}
void App::async_swap()
{
#if __OSX__
[osx_view async_swap];
#elif __IOS__
[ios_view async_swap];
#elif __ANDROID__
android_async_swap();
#elif _WIN32
win32_async_swap();
#elif __LINUX__ || __WEB__
glfwSwapBuffers(glfw_window);
#endif
present_render_context();
}
bool App::update_ui_observer(Node *n)

View File

@@ -192,6 +192,9 @@ public:
void request_app_close();
void attach_ui_thread();
void detach_ui_thread();
void acquire_render_context();
void release_render_context();
void present_render_context();
void update_platform_frame(float delta_time_seconds);
void report_rendered_frames(int frames);
void save_prepared_file(

View File

@@ -229,6 +229,21 @@ void App::detach_ui_thread()
active_platform_services().detach_ui_thread();
}
void App::acquire_render_context()
{
active_platform_services().acquire_render_context();
}
void App::release_render_context()
{
active_platform_services().release_render_context();
}
void App::present_render_context()
{
active_platform_services().present_render_context();
}
void App::update_platform_frame(float delta_time_seconds)
{
active_platform_services().update_platform_frame(delta_time_seconds);

View File

@@ -20,6 +20,9 @@ public:
virtual void set_virtual_keyboard_visible(bool visible) = 0;
virtual void attach_ui_thread() = 0;
virtual void detach_ui_thread() = 0;
virtual void acquire_render_context() = 0;
virtual void release_render_context() = 0;
virtual void present_render_context() = 0;
virtual void update_platform_frame(float delta_time_seconds) = 0;
virtual void report_rendered_frames(int frames) = 0;
virtual void display_file(std::string_view path) = 0;

View File

@@ -6,6 +6,9 @@
#ifdef __ANDROID__
void displayKeyboard(bool pShow);
void android_async_lock();
void android_async_swap();
void android_async_unlock();
void android_attach_jni();
void android_detach_jni();
void android_pick_file(std::function<void(std::string)> callback);
@@ -104,6 +107,43 @@ public:
#endif
}
void acquire_render_context() override
{
#if __OSX__
[App::I->osx_view async_lock];
#elif __IOS__
[App::I->ios_view async_lock];
#elif __ANDROID__
android_async_lock();
#elif __LINUX__ || __WEB__
glfwMakeContextCurrent(App::I->glfw_window);
#endif
}
void release_render_context() override
{
#if __OSX__
[App::I->osx_view async_unlock];
#elif __IOS__
[App::I->ios_view async_unlock];
#elif __ANDROID__
android_async_unlock();
#endif
}
void present_render_context() override
{
#if __OSX__
[App::I->osx_view async_swap];
#elif __IOS__
[App::I->ios_view async_swap];
#elif __ANDROID__
android_async_swap();
#elif __LINUX__ || __WEB__
glfwSwapBuffers(App::I->glfw_window);
#endif
}
void update_platform_frame(float delta_time_seconds) override
{
(void)delta_time_seconds;

View File

@@ -1,6 +1,8 @@
#include "pch.h"
#include "platform_windows/windows_platform_services.h"
#include "renderer_gl/opengl_capabilities.h"
#include <deque>
extern HWND hWnd;
@@ -8,6 +10,9 @@ extern std::deque<std::packaged_task<void()>> main_tasklist;
extern std::mutex main_task_mutex;
void destroy_window();
void async_lock();
void async_unlock();
void win32_async_swap();
void win32_update_fps(int frames);
void win32_update_stylus(float dt);
@@ -178,6 +183,24 @@ public:
{
}
void acquire_render_context() override
{
async_lock();
glBindFramebuffer(
static_cast<GLenum>(pp::renderer::gl::framebuffer_target()),
static_cast<GLuint>(pp::renderer::gl::default_framebuffer_id()));
}
void release_render_context() override
{
async_unlock();
}
void present_render_context() override
{
win32_async_swap();
}
void update_platform_frame(float delta_time_seconds) override
{
win32_update_stylus(delta_time_seconds);