add general async swap

This commit is contained in:
2019-07-10 23:33:46 +02:00
parent f5d885a3f4
commit 80b9a4d281
3 changed files with 22 additions and 8 deletions

View File

@@ -17,7 +17,7 @@ void android_async_unlock(struct engine* engine);
#elif _WIN32
bool async_lock_try();
void async_lock();
void async_swap();
void win32_async_swap();
void async_unlock();
void destroy_window();
#endif
@@ -521,6 +521,19 @@ void App::async_end()
#endif
}
void App::async_swap()
{
#if __OSX__
[osx_view async_swap];
#elif __IOS__
[ios_view async_swap];
#elif __ANDROID__
android_async_swap(and_engine);
#elif _WIN32
win32_async_swap();
#endif
}
bool App::update_ui_observer(Node *n)
{
if (n && n->m_display)
@@ -1039,7 +1052,7 @@ void App::render_thread_main()
// execute the tasks
if (!working_list.empty())
{
async_lock();
async_start();
while (!working_list.empty())
{
//LOG("render task %d", count);
@@ -1047,7 +1060,7 @@ void App::render_thread_main()
working_list.front()();
working_list.pop_front();
}
async_unlock();
async_end();
}
}
}

View File

@@ -178,6 +178,7 @@ public:
void async_start();
void async_update();
void async_redraw();
void async_swap();
void async_end();
void resize(float w, float h);
void show_cursor();
@@ -272,7 +273,7 @@ public:
// don't capture a reference to this ptr as the object may be destroyed
// by the time the task is executed
template<typename T, typename R = std::result_of<T()>::type>
template<typename T, typename R = void>
std::future<R> render_task_async(T task)
{
#ifdef _WIN32
@@ -294,7 +295,7 @@ public:
#endif // _WIN32
}
template<typename T, typename R = std::result_of<T()>::type>
template<typename T, typename R = void>
R render_task(T task)
{
#ifdef _WIN32
@@ -342,7 +343,7 @@ public:
// don't capture a reference to this ptr as the object may be destroyed
// by the time the task is executed
template<typename T, typename R = std::result_of<T()>::type>
template<typename T, typename R = void>
std::future<R> ui_task_async(T task)
{
std::packaged_task<R()> pt(task);
@@ -362,7 +363,7 @@ public:
return f;
}
template<typename T, typename R = std::result_of<T()>::type>
template<typename T, typename R = void>
R ui_task(T task)
{
std::packaged_task<R()> pt(task);

View File

@@ -146,7 +146,7 @@ bool async_lock_try()
return true;
}
void async_swap()
void win32_async_swap()
{
SwapBuffers(hDC);
//LOG("swap");