Skip to content

Commit f402bce

Browse files
xiaowei-guanswift-kim
authored andcommitted
Fix vsync issue (#204)
* Fix vsync issue After the engine is shutdown, OnVsync no longer be called. * Add lock when call OnVsync 1.Remove lock when create TdmClient. 2.Add lock when call OnVsync. 3.Change tdmClient to tdm_client.
1 parent e4528b7 commit f402bce

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

shell/platform/tizen/flutter_tizen_engine.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ bool FlutterTizenEngine::StopEngine() {
286286
if (plugin_registrar_destruction_callback_) {
287287
plugin_registrar_destruction_callback_(plugin_registrar_.get());
288288
}
289+
#ifndef TIZEN_RENDERER_EVAS_GL
290+
tizen_vsync_waiter_.reset();
291+
#endif
289292
FlutterEngineResult result = embedder_api_.Shutdown(engine_);
290293
engine_ = nullptr;
291294
return (result == kSuccess);

shell/platform/tizen/tizen_vsync_waiter.cc

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@ TizenVsyncWaiter::TizenVsyncWaiter(FlutterTizenEngine* engine)
2727
}
2828

2929
TizenVsyncWaiter::~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+
3744
void 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+
109122
void 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

shell/platform/tizen/tizen_vsync_waiter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <Ecore.h>
99
#include <tdm_client.h>
10+
#include <mutex>
1011

1112
#include "flutter/shell/platform/embedder/embedder.h"
1213

@@ -22,6 +23,7 @@ class TdmClient {
2223
void DestroyTdm();
2324
bool IsValid();
2425
void WaitVblank(intptr_t baton);
26+
void OnEngineStop();
2527
static void VblankCallback(tdm_client_vblank* vblank,
2628
tdm_error error,
2729
unsigned int sequence,
@@ -30,6 +32,7 @@ class TdmClient {
3032
void* user_data);
3133

3234
private:
35+
std::mutex engine_mutex_;
3336
tdm_client* client_{nullptr};
3437
tdm_client_output* output_{nullptr};
3538
tdm_client_vblank* vblank_{nullptr};
@@ -42,13 +45,15 @@ class TizenVsyncWaiter {
4245
TizenVsyncWaiter(FlutterTizenEngine* engine);
4346
virtual ~TizenVsyncWaiter();
4447
void AsyncWaitForVsync(intptr_t baton);
48+
void SetTdmClient(TdmClient* tdm_client);
4549

4650
private:
4751
void Send(int event, intptr_t baton);
4852
static void RequestVblankLoop(void* data, Ecore_Thread* thread);
4953
Ecore_Thread* vblank_thread_{nullptr};
5054
Eina_Thread_Queue* vblank_thread_queue_{nullptr};
5155
FlutterTizenEngine* engine_{nullptr};
56+
TdmClient* tdm_client_{nullptr};
5257
};
5358

5459
} // namespace flutter

0 commit comments

Comments
 (0)