|
|
|
|
|
|
|
|
|
|
FML_DCHECK(fbo_ == 0); |
|
|
|
surface_manager_->MakeCurrent(EGL_NO_DISPLAY); |
|
|
|
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr, width, height); |
|
|
|
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr); |
|
|
|
// fml::AutoResetWaitableEvent latch;
|
|
|
|
// std::thread::id gfx_worker_thread_id;
|
|
|
|
// UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker(
|
|
|
|
// [&latch, &gfx_worker_thread_id]() -> void {
|
|
|
|
// gfx_worker_thread_id = std::this_thread::get_id();
|
|
|
|
// latch.Signal();
|
|
|
|
// });
|
|
|
|
// latch.Wait();
|
|
|
|
fml::AutoResetWaitableEvent latch; |
|
|
|
std::thread::id gfx_worker_thread_id; |
|
|
|
UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker( |
|
|
|
[&latch, &gfx_worker_thread_id]() -> void { |
|
|
|
gfx_worker_thread_id = std::this_thread::get_id(); |
|
|
|
latch.Signal(); |
|
|
|
}); |
|
|
|
latch.Wait(); |
|
|
|
// gfx_worker_task_runner_ = std::make_unique<GfxWorkerTaskRunner>(
|
|
|
|
// gfx_worker_thread_id, [this](const auto* task) {
|
|
|
|
// if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {
|
|
|
|
// std::cerr << "Could not post an gfx worker task." << std::endl;
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
gfx_worker_task_runner_ = std::make_unique<GfxWorkerTaskRunner>( |
|
|
|
gfx_worker_thread_id, [this](const auto* task) { |
|
|
|
if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) { |
|
|
|
std::cerr << "Could not post an gfx worker task." << std::endl; |
|
|
|
} |
|
|
|
}); |
|
|
|
// UIWidgetsTaskRunnerDescription render_task_runner = {};
|
|
|
|
// render_task_runner.struct_size = sizeof(UIWidgetsTaskRunnerDescription);
|
|
|
|
// render_task_runner.identifier = 1;
|
|
|
|
// render_task_runner.user_data = gfx_worker_task_runner_.get();
|
|
|
|
// render_task_runner.runs_task_on_current_thread_callback =
|
|
|
|
// [](void* user_data) -> bool {
|
|
|
|
// return static_cast<GfxWorkerTaskRunner*>(user_data)
|
|
|
|
// ->RunsTasksOnCurrentThread();
|
|
|
|
// };
|
|
|
|
// render_task_runner.post_task_callback = [](UIWidgetsTask task,
|
|
|
|
// uint64_t target_time_nanos,
|
|
|
|
// void* user_data) -> void {
|
|
|
|
// static_cast<GfxWorkerTaskRunner*>(user_data)->PostTask(task,
|
|
|
|
// target_time_nanos);
|
|
|
|
// };
|
|
|
|
UIWidgetsTaskRunnerDescription render_task_runner = {}; |
|
|
|
render_task_runner.struct_size = sizeof(UIWidgetsTaskRunnerDescription); |
|
|
|
render_task_runner.identifier = 1; |
|
|
|
render_task_runner.user_data = gfx_worker_task_runner_.get(); |
|
|
|
render_task_runner.runs_task_on_current_thread_callback = |
|
|
|
[](void* user_data) -> bool { |
|
|
|
return static_cast<GfxWorkerTaskRunner*>(user_data) |
|
|
|
->RunsTasksOnCurrentThread(); |
|
|
|
}; |
|
|
|
render_task_runner.post_task_callback = [](UIWidgetsTask task, |
|
|
|
uint64_t target_time_nanos, |
|
|
|
void* user_data) -> void { |
|
|
|
static_cast<GfxWorkerTaskRunner*>(user_data)->PostTask(task, |
|
|
|
target_time_nanos); |
|
|
|
}; |
|
|
|
// UIWidgetsRendererConfig config = {};
|
|
|
|
// config.type = kOpenGL;
|
|
|
|
// config.open_gl.struct_size = sizeof(config.open_gl);
|
|
|
|
// config.open_gl.clear_current = [](void* user_data) -> bool {
|
|
|
|
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
|
|
|
|
// return panel->surface_manager_->ClearCurrent();
|
|
|
|
// };
|
|
|
|
// config.open_gl.make_current = [](void* user_data) -> bool {
|
|
|
|
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
|
|
|
|
// return panel->surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
|
|
|
|
// };
|
|
|
|
// config.open_gl.make_resource_current = [](void* user_data) -> bool {
|
|
|
|
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
|
|
|
|
// return panel->surface_manager_->MakeResourceCurrent();
|
|
|
|
// };
|
|
|
|
// config.open_gl.fbo_callback = [](void* user_data) -> uint32_t {
|
|
|
|
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
|
|
|
|
// return panel->fbo_;
|
|
|
|
// };
|
|
|
|
// config.open_gl.present = [](void* user_data) -> bool { return true; };
|
|
|
|
// config.open_gl.gl_proc_resolver = [](void* user_data,
|
|
|
|
// const char* what) -> void* {
|
|
|
|
// return reinterpret_cast<void*>(eglGetProcAddress(what));
|
|
|
|
// };
|
|
|
|
// config.open_gl.fbo_reset_after_present = true;
|
|
|
|
UIWidgetsRendererConfig config = {}; |
|
|
|
config.type = kOpenGL; |
|
|
|
config.open_gl.struct_size = sizeof(config.open_gl); |
|
|
|
config.open_gl.clear_current = [](void* user_data) -> bool { |
|
|
|
auto* panel = static_cast<UIWidgetsPanel*>(user_data); |
|
|
|
return panel->surface_manager_->ClearCurrent(); |
|
|
|
}; |
|
|
|
config.open_gl.make_current = [](void* user_data) -> bool { |
|
|
|
auto* panel = static_cast<UIWidgetsPanel*>(user_data); |
|
|
|
return panel->surface_manager_->MakeCurrent(EGL_NO_DISPLAY); |
|
|
|
}; |
|
|
|
config.open_gl.make_resource_current = [](void* user_data) -> bool { |
|
|
|
auto* panel = static_cast<UIWidgetsPanel*>(user_data); |
|
|
|
return panel->surface_manager_->MakeResourceCurrent(); |
|
|
|
}; |
|
|
|
config.open_gl.fbo_callback = [](void* user_data) -> uint32_t { |
|
|
|
auto* panel = static_cast<UIWidgetsPanel*>(user_data); |
|
|
|
return panel->fbo_; |
|
|
|
}; |
|
|
|
config.open_gl.present = [](void* user_data) -> bool { return true; }; |
|
|
|
config.open_gl.gl_proc_resolver = [](void* user_data, |
|
|
|
const char* what) -> void* { |
|
|
|
return reinterpret_cast<void*>(eglGetProcAddress(what)); |
|
|
|
}; |
|
|
|
config.open_gl.fbo_reset_after_present = true; |
|
|
|
// task_runner_ = std::make_unique<Win32TaskRunner>(
|
|
|
|
// GetCurrentThreadId(), [this](const auto* task) {
|
|
|
|
// if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {
|
|
|
|
// std::cerr << "Could not post an engine task." << std::endl;
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
task_runner_ = std::make_unique<CocoaTaskRunner>( |
|
|
|
gettid(), [this](const auto* task) { |
|
|
|
if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) { |
|
|
|
std::cerr << "Could not post an engine task." << std::endl; |
|
|
|
} |
|
|
|
}); |
|
|
|
// UIWidgetsTaskRunnerDescription ui_task_runner = {};
|
|
|
|
// ui_task_runner.struct_size = sizeof(UIWidgetsTaskRunnerDescription);
|
|
|
|
// ui_task_runner.identifier = 2;
|
|
|
|
// ui_task_runner.user_data = task_runner_.get();
|
|
|
|
// ui_task_runner.runs_task_on_current_thread_callback =
|
|
|
|
// [](void* user_data) -> bool {
|
|
|
|
// return static_cast<Win32TaskRunner*>(user_data)->RunsTasksOnCurrentThread();
|
|
|
|
// };
|
|
|
|
// ui_task_runner.post_task_callback = [](UIWidgetsTask task,
|
|
|
|
// uint64_t target_time_nanos,
|
|
|
|
// void* user_data) -> void {
|
|
|
|
// static_cast<Win32TaskRunner*>(user_data)->PostTask(task, target_time_nanos);
|
|
|
|
// };
|
|
|
|
UIWidgetsTaskRunnerDescription ui_task_runner = {}; |
|
|
|
ui_task_runner.struct_size = sizeof(UIWidgetsTaskRunnerDescription); |
|
|
|
ui_task_runner.identifier = 2; |
|
|
|
ui_task_runner.user_data = task_runner_.get(); |
|
|
|
// UIWidgetsCustomTaskRunners custom_task_runners = {};
|
|
|
|
// custom_task_runners.struct_size = sizeof(UIWidgetsCustomTaskRunners);
|
|
|
|
// custom_task_runners.platform_task_runner = &ui_task_runner;
|
|
|
|
// custom_task_runners.ui_task_runner = &ui_task_runner;
|
|
|
|
// custom_task_runners.render_task_runner = &render_task_runner;
|
|
|
|
// TODO: waht is this
|
|
|
|
ui_task_runner.runs_task_on_current_thread_callback = |
|
|
|
[](void* user_data) -> bool { |
|
|
|
return static_cast<CocoaTaskRunner*>(user_data)->RunsTasksOnCurrentThread(); |
|
|
|
}; |
|
|
|
ui_task_runner.post_task_callback = [](UIWidgetsTask task, |
|
|
|
uint64_t target_time_nanos, |
|
|
|
void* user_data) -> void { |
|
|
|
static_cast<CocoaTaskRunner*>(user_data)->PostTask(task, target_time_nanos); |
|
|
|
}; |
|
|
|
// UIWidgetsProjectArgs args = {};
|
|
|
|
// args.struct_size = sizeof(UIWidgetsProjectArgs);
|
|
|
|
UIWidgetsCustomTaskRunners custom_task_runners = {}; |
|
|
|
custom_task_runners.struct_size = sizeof(UIWidgetsCustomTaskRunners); |
|
|
|
custom_task_runners.platform_task_runner = &ui_task_runner; |
|
|
|
custom_task_runners.ui_task_runner = &ui_task_runner; |
|
|
|
custom_task_runners.render_task_runner = &render_task_runner; |
|
|
|
|
|
|
|
UIWidgetsProjectArgs args = {}; |
|
|
|
args.struct_size = sizeof(UIWidgetsProjectArgs); |
|
|
|
// args.assets_path = streaming_assets_path;
|
|
|
|
// args.font_asset = settings;
|
|
|
|
args.assets_path = streaming_assets_path; |
|
|
|
args.font_asset = settings; |
|
|
|
// args.icu_mapper = GetICUStaticMapping;
|
|
|
|
args.icu_mapper = GetICUStaticMapping; |
|
|
|
|
|
|
|
// // Used for IOS build
|
|
|
|
// // std::string icu_symbol_prefix = "_binary_icudtl_dat_start";
|
|
|
|
|
|
|
// // return GetSymbolMapping(icu_symbol_prefix, native_lib_path);
|
|
|
|
// // };
|
|
|
|
// args.command_line_argc = 0;
|
|
|
|
// args.command_line_argv = nullptr;
|
|
|
|
args.command_line_argc = 0; |
|
|
|
args.command_line_argv = nullptr; |
|
|
|
// args.platform_message_callback =
|
|
|
|
// [](const UIWidgetsPlatformMessage* engine_message,
|
|
|
|
// void* user_data) -> void {};
|
|
|
|
args.platform_message_callback = |
|
|
|
[](const UIWidgetsPlatformMessage* engine_message, |
|
|
|
void* user_data) -> void {}; |
|
|
|
// args.custom_task_runners = &custom_task_runners;
|
|
|
|
// args.task_observer_add = [](intptr_t key, void* callback,
|
|
|
|
// void* user_data) -> void {
|
|
|
|
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
|
|
|
|
// panel->task_runner_->AddTaskObserver(key,
|
|
|
|
// *static_cast<fml::closure*>(callback));
|
|
|
|
// };
|
|
|
|
// args.task_observer_remove = [](intptr_t key, void* user_data) -> void {
|
|
|
|
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
|
|
|
|
// panel->task_runner_->RemoveTaskObserver(key);
|
|
|
|
// };
|
|
|
|
args.custom_task_runners = &custom_task_runners; |
|
|
|
args.task_observer_add = [](intptr_t key, void* callback, |
|
|
|
void* user_data) -> void { |
|
|
|
auto* panel = static_cast<UIWidgetsPanel*>(user_data); |
|
|
|
panel->task_runner_->AddTaskObserver(key, |
|
|
|
*static_cast<fml::closure*>(callback)); |
|
|
|
}; |
|
|
|
args.task_observer_remove = [](intptr_t key, void* user_data) -> void { |
|
|
|
auto* panel = static_cast<UIWidgetsPanel*>(user_data); |
|
|
|
panel->task_runner_->RemoveTaskObserver(key); |
|
|
|
}; |
|
|
|
// args.custom_mono_entrypoint = [](void* user_data) -> void {
|
|
|
|
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
|
|
|
|
// panel->MonoEntrypoint();
|
|
|
|
// };
|
|
|
|
args.custom_mono_entrypoint = [](void* user_data) -> void { |
|
|
|
auto* panel = static_cast<UIWidgetsPanel*>(user_data); |
|
|
|
panel->MonoEntrypoint(); |
|
|
|
}; |
|
|
|
// args.vsync_callback = [](void* user_data, intptr_t baton) -> void {
|
|
|
|
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
|
|
|
|
// panel->VSyncCallback(baton);
|
|
|
|
// };
|
|
|
|
args.vsync_callback = [](void* user_data, intptr_t baton) -> void { |
|
|
|
auto* panel = static_cast<UIWidgetsPanel*>(user_data); |
|
|
|
panel->VSyncCallback(baton); |
|
|
|
}; |
|
|
|
// args.initial_window_metrics.width = width;
|
|
|
|
// args.initial_window_metrics.height = height;
|
|
|
|
// args.initial_window_metrics.pixel_ratio = device_pixel_ratio;
|
|
|
|
args.initial_window_metrics.width = width; |
|
|
|
args.initial_window_metrics.height = height; |
|
|
|
args.initial_window_metrics.pixel_ratio = device_pixel_ratio; |
|
|
|
// UIWidgetsEngine engine = nullptr;
|
|
|
|
// auto result = UIWidgetsEngineInitialize(&config, &args, this, &engine);
|
|
|
|
UIWidgetsEngine engine = nullptr; |
|
|
|
auto result = UIWidgetsEngineInitialize(&config, &args, this, &engine); |
|
|
|
// if (result != kSuccess || engine == nullptr) {
|
|
|
|
// std::cerr << "Failed to start UIWidgets engine: error " << result
|
|
|
|
// << std::endl;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
if (result != kSuccess || engine == nullptr) { |
|
|
|
std::cerr << "Failed to start UIWidgets engine: error " << result |
|
|
|
<< std::endl; |
|
|
|
return; |
|
|
|
} |
|
|
|
// engine_ = engine;
|
|
|
|
// UIWidgetsEngineRunInitialized(engine);
|
|
|
|
engine_ = engine; |
|
|
|
UIWidgetsEngineRunInitialized(engine); |
|
|
|
// UIWidgetsSystem::GetInstancePtr()->RegisterPanel(this);
|
|
|
|
UIWidgetsSystem::GetInstancePtr()->RegisterPanel(this); |
|
|
|
// process_events_ = true;
|
|
|
|
process_events_ = true; |
|
|
|
} |
|
|
|
|
|
|
|
void UIWidgetsPanel::MonoEntrypoint() { entrypoint_callback_(handle_); } |
|
|
|
|
|
|
gfx_worker_task_runner_ = nullptr; |
|
|
|
task_runner_ = nullptr; |
|
|
|
|
|
|
|
// if (fbo_) {
|
|
|
|
// surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
|
|
|
|
if (fbo_) { |
|
|
|
surface_manager_->MakeCurrent(EGL_NO_DISPLAY); |
|
|
|
// surface_manager_->DestroyRenderSurface();
|
|
|
|
// fbo_ = 0;
|
|
|
|
surface_manager_->DestroyRenderSurface(); |
|
|
|
fbo_ = 0; |
|
|
|
// surface_manager_->ClearCurrent();
|
|
|
|
// }
|
|
|
|
surface_manager_->ClearCurrent(); |
|
|
|
} |
|
|
|
// surface_manager_ = nullptr;
|
|
|
|
surface_manager_ = nullptr; |
|
|
|
// reinterpret_cast<EmbedderEngine*>(engine_)->PostRenderThreadTask(
|
|
|
|
// [this, native_texture_ptr]() -> void {
|
|
|
|
// surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
|
|
|
|
reinterpret_cast<EmbedderEngine*>(engine_)->PostRenderThreadTask( |
|
|
|
[this, native_texture_ptr]() -> void { |
|
|
|
surface_manager_->MakeCurrent(EGL_NO_DISPLAY); |
|
|
|
// if (fbo_) {
|
|
|
|
// surface_manager_->DestroyRenderSurface();
|
|
|
|
// fbo_ = 0;
|
|
|
|
// }
|
|
|
|
// fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
|
|
|
|
if (fbo_) { |
|
|
|
surface_manager_->DestroyRenderSurface(); |
|
|
|
fbo_ = 0; |
|
|
|
} |
|
|
|
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr); |
|
|
|
// surface_manager_->ClearCurrent();
|
|
|
|
// });
|
|
|
|
surface_manager_->ClearCurrent(); |
|
|
|
}); |
|
|
|
// ViewportMetrics metrics;
|
|
|
|
// metrics.physical_width = static_cast<float>(width);
|
|
|
|
// metrics.physical_height = static_cast<float>(height);
|
|
|
|
// metrics.device_pixel_ratio = device_pixel_ratio;
|
|
|
|
// reinterpret_cast<EmbedderEngine*>(engine_)->SetViewportMetrics(metrics);
|
|
|
|
ViewportMetrics metrics; |
|
|
|
metrics.physical_width = static_cast<float>(width); |
|
|
|
metrics.physical_height = static_cast<float>(height); |
|
|
|
metrics.device_pixel_ratio = device_pixel_ratio; |
|
|
|
reinterpret_cast<EmbedderEngine*>(engine_)->SetViewportMetrics(metrics); |
|
|
|
} |
|
|
|
|
|
|
|
int UIWidgetsPanel::RegisterTexture(void* native_texture_ptr) { |
|
|
|
|
|
|
|
|
|
|
UIWIDGETS_API(void*) |
|
|
|
SetTextureFromUnity2(void* tex, int w, int h) { return UnitySurfaceManager::SetTextureFromUnity(tex, w, h); } |
|
|
|
|
|
|
|
static void UNITY_INTERFACE_API OnGetUnityContextEvent(int eventID) |
|
|
|
{ |
|
|
|
UnitySurfaceManager::GetUnityContext(); |
|
|
|
} |
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// GetRenderEventFunc, an example function we export which is used to get a rendering event callback function.
|
|
|
|
|
|
|
|
UIWIDGETS_API(UnityRenderingEvent) GetUnityContextEventFunc() |
|
|
|
{ |
|
|
|
return OnGetUnityContextEvent; |
|
|
|
} |
|
|
|
|
|
|
|
static void UNITY_INTERFACE_API OnRenderEvent(int eventID) |
|
|
|
{ |
|
|
|