This commit is contained in:
xingweizhu 2022-02-25 15:42:24 +08:00
Родитель 724cefe344
Коммит 68dc46a662
6 изменённых файлов: 43 добавлений и 59 удалений

Просмотреть файл

@ -43,14 +43,6 @@ namespace uiwidgets
const char *streaming_assets_path,
const char *settings)
{
surface_manager_ = std::make_unique<UnitySurfaceManager>(
UIWidgetsSystem::GetInstancePtr()->GetUnityInterfaces());
FML_DCHECK(fbo_ == 0);
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
surface_manager_->ClearCurrent();
fml::AutoResetWaitableEvent latch;
std::thread::id gfx_worker_thread_id;
UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker(
@ -59,6 +51,14 @@ namespace uiwidgets
latch.Signal();
});
latch.Wait();
surface_manager_ = std::make_unique<UnitySurfaceManager>(
UIWidgetsSystem::GetInstancePtr()->GetUnityInterfaces());
FML_DCHECK(fbo_ == 0);
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
surface_manager_->ClearCurrent();
gfx_worker_task_runner_ = std::make_unique<GfxWorkerTaskRunner>(
gfx_worker_thread_id, [this](const auto *task) {

Просмотреть файл

@ -80,7 +80,7 @@ class UIWidgetsPanel : public fml::RefCountedThreadSafe<UIWidgetsPanel> {
private:
UIWidgetsPanel(Mono_Handle handle, UIWidgetsWindowType window_type, EntrypointCallback entrypoint_callback);
void CreateInternalUIWidgetsEngine(size_t width, size_t height, float device_pixel_ratio, const char* streaming_assets_path, const char* settings);
void CreateInternalUIWidgetsEngine(size_t width, size_t height, float device_pixel_ratio, const char* streaming_assets_path, const char* settings, std::thread::id gfx_worker_thread_id);
void dispatchTouches(float x, float y, int button, UIWidgetsTouchPhase evtType);

Просмотреть файл

@ -35,18 +35,6 @@ bool UIWidgetsPanel::NeedUpdateByEditorLoop() {
void* UIWidgetsPanel::OnEnable(size_t width, size_t height, float device_pixel_ratio,
const char* streaming_assets_path, const char* settings)
{
surface_manager_ = std::make_unique<UnitySurfaceManager>(
UIWidgetsSystem::GetInstancePtr()->GetUnityInterfaces());
void* metal_tex = surface_manager_->CreateRenderTexture(width, height);
CreateInternalUIWidgetsEngine(width, height, device_pixel_ratio, streaming_assets_path, settings);
return metal_tex;
}
void UIWidgetsPanel::CreateInternalUIWidgetsEngine(size_t width, size_t height, float device_pixel_ratio,
const char* streaming_assets_path, const char* settings)
{
fml::AutoResetWaitableEvent latch;
std::thread::id gfx_worker_thread_id;
@ -57,6 +45,18 @@ void UIWidgetsPanel::CreateInternalUIWidgetsEngine(size_t width, size_t height,
});
latch.Wait();
surface_manager_ = std::make_unique<UnitySurfaceManager>(
UIWidgetsSystem::GetInstancePtr()->GetUnityInterfaces());
void* metal_tex = surface_manager_->CreateRenderTexture(width, height);
CreateInternalUIWidgetsEngine(width, height, device_pixel_ratio, streaming_assets_path, settings, gfx_worker_thread_id);
return metal_tex;
}
void UIWidgetsPanel::CreateInternalUIWidgetsEngine(size_t width, size_t height, float device_pixel_ratio,
const char* streaming_assets_path, const char* settings, std::thread::id gfx_worker_thread_id)
{
gfx_worker_task_runner_ = std::make_unique<GfxWorkerTaskRunner>(
gfx_worker_thread_id, [this](const auto* task) {
if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {

Просмотреть файл

@ -81,7 +81,7 @@ class UIWidgetsPanel : public fml::RefCountedThreadSafe<UIWidgetsPanel> {
private:
UIWidgetsPanel(Mono_Handle handle, UIWidgetsWindowType window_type, EntrypointCallback entrypoint_callback);
void CreateInternalUIWidgetsEngine(size_t width, size_t height, float device_pixel_ratio, const char* streaming_assets_path, const char* settings);
void CreateInternalUIWidgetsEngine(size_t width, size_t height, float device_pixel_ratio, const char* streaming_assets_path, const char* settings, std::thread::id gfx_worker_thread_id);
MouseState GetMouseState() { return mouse_state_; }

Просмотреть файл

@ -35,18 +35,6 @@ bool UIWidgetsPanel::NeedUpdateByEditorLoop() {
void* UIWidgetsPanel::OnEnable(size_t width, size_t height, float device_pixel_ratio,
const char* streaming_assets_path, const char* settings)
{
surface_manager_ = std::make_unique<UnitySurfaceManager>(
UIWidgetsSystem::GetInstancePtr()->GetUnityInterfaces());
void* metal_tex = surface_manager_->CreateRenderTexture(width, height);
CreateInternalUIWidgetsEngine(width, height, device_pixel_ratio, streaming_assets_path, settings);
return metal_tex;
}
void UIWidgetsPanel::CreateInternalUIWidgetsEngine(size_t width, size_t height, float device_pixel_ratio,
const char* streaming_assets_path, const char* settings)
{
fml::AutoResetWaitableEvent latch;
std::thread::id gfx_worker_thread_id;
@ -57,6 +45,18 @@ void UIWidgetsPanel::CreateInternalUIWidgetsEngine(size_t width, size_t height,
});
latch.Wait();
surface_manager_ = std::make_unique<UnitySurfaceManager>(
UIWidgetsSystem::GetInstancePtr()->GetUnityInterfaces());
void* metal_tex = surface_manager_->CreateRenderTexture(width, height);
CreateInternalUIWidgetsEngine(width, height, device_pixel_ratio, streaming_assets_path, settings, gfx_worker_thread_id);
return metal_tex;
}
void UIWidgetsPanel::CreateInternalUIWidgetsEngine(size_t width, size_t height, float device_pixel_ratio,
const char* streaming_assets_path, const char* settings, std::thread::id gfx_worker_thread_id)
{
gfx_worker_task_runner_ = std::make_unique<GfxWorkerTaskRunner>(
gfx_worker_thread_id, [this](const auto* task) {
if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {

Просмотреть файл

@ -16,10 +16,6 @@
namespace uiwidgets {
std::thread::id gfx_worker_thread_id;
int worker_set = 0;
fml::RefPtr<UIWidgetsPanel> UIWidgetsPanel::Create(
Mono_Handle handle, UIWidgetsWindowType window_type, EntrypointCallback entrypoint_callback) {
return fml::MakeRefCounted<UIWidgetsPanel>(handle, window_type, entrypoint_callback);
@ -45,12 +41,14 @@ void* UIWidgetsPanel::OnEnable(size_t width,
const char* streaming_assets_path,
const char* settings) {
fml::AutoResetWaitableEvent latch2;
// std::thread::id gfx_worker_thread_id;
UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker([&latch2]() -> void {
latch2.Signal();
});
latch2.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();
surface_manager_ = std::make_unique<UnitySurfaceManager>(
UIWidgetsSystem::GetInstancePtr()->GetUnityInterfaces());
@ -61,21 +59,7 @@ void* UIWidgetsPanel::OnEnable(size_t width,
void* d3dtexture = surface_manager_->GetD3DInnerTexture();
surface_manager_->ClearCurrent();
if (worker_set == 0)
{
fml::AutoResetWaitableEvent latch;
//std::thread::id gfx_worker_thread_id;
UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker(
[&latch]() -> void {
gfx_worker_thread_id = std::this_thread::get_id();
latch.Signal();
});
latch.Wait();
worker_set = 1;
}
gfx_worker_task_runner_ = std::make_unique<GfxWorkerTaskRunner>(
gfx_worker_thread_id, [this](const auto* task) {
if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {