diff --git a/shell/platform/tizen/flutter_tizen_engine.cc b/shell/platform/tizen/flutter_tizen_engine.cc index b5abfa2bbef90..1d8d6de7bb92f 100644 --- a/shell/platform/tizen/flutter_tizen_engine.cc +++ b/shell/platform/tizen/flutter_tizen_engine.cc @@ -290,6 +290,9 @@ bool FlutterTizenEngine::StopEngine() { if (plugin_registrar_destruction_callback_) { plugin_registrar_destruction_callback_(plugin_registrar_.get()); } +#ifndef TIZEN_RENDERER_EVAS_GL + tizen_vsync_waiter_.reset(); +#endif FlutterEngineResult result = embedder_api_.Shutdown(engine_); engine_ = nullptr; return (result == kSuccess); diff --git a/shell/platform/tizen/tizen_vsync_waiter.cc b/shell/platform/tizen/tizen_vsync_waiter.cc index c4e2c406f539e..3f196bfb1c742 100644 --- a/shell/platform/tizen/tizen_vsync_waiter.cc +++ b/shell/platform/tizen/tizen_vsync_waiter.cc @@ -27,6 +27,9 @@ TizenVsyncWaiter::TizenVsyncWaiter(FlutterTizenEngine* engine) } TizenVsyncWaiter::~TizenVsyncWaiter() { + if (tdm_client_) { + tdm_client_->OnEngineStop(); + } Send(kMessageQuit, 0); if (vblank_thread_) { ecore_thread_cancel(vblank_thread_); @@ -34,6 +37,10 @@ TizenVsyncWaiter::~TizenVsyncWaiter() { } } +void TizenVsyncWaiter::SetTdmClient(TdmClient* tdm_client) { + tdm_client_ = tdm_client; +} + void TizenVsyncWaiter::AsyncWaitForVsync(intptr_t baton) { Send(kMessageRequestVblank, baton); } @@ -62,6 +69,7 @@ void TizenVsyncWaiter::RequestVblankLoop(void* data, Ecore_Thread* thread) { TizenVsyncWaiter* tizen_vsync_waiter = reinterpret_cast(data); TdmClient tdm_client(tizen_vsync_waiter->engine_); + tizen_vsync_waiter->SetTdmClient(&tdm_client); if (!tdm_client.IsValid()) { FT_LOG(Error) << "Invalid tdm_client."; ecore_thread_cancel(thread); @@ -106,6 +114,11 @@ TdmClient::~TdmClient() { DestroyTdm(); } +void TdmClient::OnEngineStop() { + std::lock_guard lock(engine_mutex_); + engine_ = nullptr; +} + void TdmClient::WaitVblank(intptr_t baton) { baton_ = baton; tdm_error error = tdm_client_vblank_wait(vblank_, 1, VblankCallback, this); @@ -164,12 +177,13 @@ void TdmClient::VblankCallback(tdm_client_vblank* vblank, void* user_data) { TdmClient* client = reinterpret_cast(user_data); FT_ASSERT(client != nullptr); - FT_ASSERT(client->engine_ != nullptr); - - uint64_t frame_start_time_nanos = tv_sec * 1e9 + tv_usec * 1e3; - uint64_t frame_target_time_nanos = 16.6 * 1e6 + frame_start_time_nanos; - client->engine_->OnVsync(client->baton_, frame_start_time_nanos, - frame_target_time_nanos); + std::lock_guard lock(client->engine_mutex_); + if (client->engine_) { + uint64_t frame_start_time_nanos = tv_sec * 1e9 + tv_usec * 1e3; + uint64_t frame_target_time_nanos = 16.6 * 1e6 + frame_start_time_nanos; + client->engine_->OnVsync(client->baton_, frame_start_time_nanos, + frame_target_time_nanos); + } } } // namespace flutter diff --git a/shell/platform/tizen/tizen_vsync_waiter.h b/shell/platform/tizen/tizen_vsync_waiter.h index b48429f18c887..9f5be4bb20f14 100644 --- a/shell/platform/tizen/tizen_vsync_waiter.h +++ b/shell/platform/tizen/tizen_vsync_waiter.h @@ -7,6 +7,7 @@ #include #include +#include #include "flutter/shell/platform/embedder/embedder.h" @@ -22,6 +23,7 @@ class TdmClient { void DestroyTdm(); bool IsValid(); void WaitVblank(intptr_t baton); + void OnEngineStop(); static void VblankCallback(tdm_client_vblank* vblank, tdm_error error, unsigned int sequence, @@ -30,6 +32,7 @@ class TdmClient { void* user_data); private: + std::mutex engine_mutex_; tdm_client* client_{nullptr}; tdm_client_output* output_{nullptr}; tdm_client_vblank* vblank_{nullptr}; @@ -42,6 +45,7 @@ class TizenVsyncWaiter { TizenVsyncWaiter(FlutterTizenEngine* engine); virtual ~TizenVsyncWaiter(); void AsyncWaitForVsync(intptr_t baton); + void SetTdmClient(TdmClient* tdm_client); private: void Send(int event, intptr_t baton); @@ -49,6 +53,7 @@ class TizenVsyncWaiter { Ecore_Thread* vblank_thread_{nullptr}; Eina_Thread_Queue* vblank_thread_queue_{nullptr}; FlutterTizenEngine* engine_{nullptr}; + TdmClient* tdm_client_{nullptr}; }; } // namespace flutter