@@ -27,13 +27,20 @@ TizenVsyncWaiter::TizenVsyncWaiter(FlutterTizenEngine* engine)
2727}
2828
2929TizenVsyncWaiter::~TizenVsyncWaiter () {
30+ if (tdm_client_) {
31+ tdm_client_->OnEngineStop ();
32+ }
3033 Send (kMessageQuit , 0 );
3134 if (vblank_thread_) {
3235 ecore_thread_cancel (vblank_thread_);
3336 vblank_thread_ = nullptr ;
3437 }
3538}
3639
40+ void TizenVsyncWaiter::SetTdmClient (TdmClient* tdm_client) {
41+ tdm_client_ = tdm_client;
42+ }
43+
3744void TizenVsyncWaiter::AsyncWaitForVsync (intptr_t baton) {
3845 Send (kMessageRequestVblank , baton);
3946}
@@ -62,6 +69,7 @@ void TizenVsyncWaiter::RequestVblankLoop(void* data, Ecore_Thread* thread) {
6269 TizenVsyncWaiter* tizen_vsync_waiter =
6370 reinterpret_cast <TizenVsyncWaiter*>(data);
6471 TdmClient tdm_client (tizen_vsync_waiter->engine_ );
72+ tizen_vsync_waiter->SetTdmClient (&tdm_client);
6573 if (!tdm_client.IsValid ()) {
6674 FT_LOG (Error) << " Invalid tdm_client." ;
6775 ecore_thread_cancel (thread);
@@ -106,6 +114,11 @@ TdmClient::~TdmClient() {
106114 DestroyTdm ();
107115}
108116
117+ void TdmClient::OnEngineStop () {
118+ std::lock_guard<std::mutex> lock (engine_mutex_);
119+ engine_ = nullptr ;
120+ }
121+
109122void TdmClient::WaitVblank (intptr_t baton) {
110123 baton_ = baton;
111124 tdm_error error = tdm_client_vblank_wait (vblank_, 1 , VblankCallback, this );
@@ -164,12 +177,13 @@ void TdmClient::VblankCallback(tdm_client_vblank* vblank,
164177 void * user_data) {
165178 TdmClient* client = reinterpret_cast <TdmClient*>(user_data);
166179 FT_ASSERT (client != nullptr );
167- FT_ASSERT (client->engine_ != nullptr );
168-
169- uint64_t frame_start_time_nanos = tv_sec * 1e9 + tv_usec * 1e3 ;
170- uint64_t frame_target_time_nanos = 16.6 * 1e6 + frame_start_time_nanos;
171- client->engine_ ->OnVsync (client->baton_ , frame_start_time_nanos,
172- frame_target_time_nanos);
180+ std::lock_guard<std::mutex> lock (client->engine_mutex_ );
181+ if (client->engine_ ) {
182+ uint64_t frame_start_time_nanos = tv_sec * 1e9 + tv_usec * 1e3 ;
183+ uint64_t frame_target_time_nanos = 16.6 * 1e6 + frame_start_time_nanos;
184+ client->engine_ ->OnVsync (client->baton_ , frame_start_time_nanos,
185+ frame_target_time_nanos);
186+ }
173187}
174188
175189} // namespace flutter
0 commit comments