4
4
5
5
#include " tizen_vsync_waiter.h"
6
6
7
+ #include < eina_thread_queue.h>
8
+
7
9
#include " flutter/shell/platform/tizen/tizen_embedder_engine.h"
8
10
#include " flutter/shell/platform/tizen/tizen_log.h"
9
11
10
- void TizenVsyncWaiter::RequestVblank (void * data, Ecore_Thread* thread) {
11
- TizenVsyncWaiter* tizen_vsync_waiter =
12
- reinterpret_cast <TizenVsyncWaiter*>(data);
13
- if (!ecore_thread_check (thread)) {
14
- tdm_error error = tdm_client_vblank_wait (tizen_vsync_waiter->vblank_ , 1 ,
15
- TdmClientVblankCallback, data);
16
- if (error != TDM_ERROR_NONE) {
17
- FT_LOGE (" tdm_client_vblank_wait error %d" , error);
18
- return ;
19
- }
20
- tdm_client_handle_events (tizen_vsync_waiter->client_ );
21
- }
22
- }
12
+ static const int QUEUE_QUIT = -1 ;
13
+ static const int QUEUE_REQUEST_VBLANK = 0 ;
14
+
15
+ typedef struct {
16
+ Eina_Thread_Queue_Msg head;
17
+ int value;
18
+ } Msg;
19
+
20
+ static Eina_Thread_Queue* vblank_thread_queue{nullptr };
23
21
24
22
TizenVsyncWaiter::TizenVsyncWaiter (TizenEmbedderEngine* engine)
25
23
: engine_(engine) {
26
24
if (!CreateTDMVblank ()) {
27
25
FT_LOGE (" Failed to create TDM vblank" );
28
26
DestoryTDMVblank ();
27
+ } else {
28
+ vblank_thread_queue = eina_thread_queue_new ();
29
+ vblank_thread_ =
30
+ ecore_thread_feedback_run (RequestVblankLoop, NULL , VblankLoopFinish,
31
+ VblankLoopFinish, this , EINA_TRUE);
29
32
}
30
33
}
31
34
32
- TizenVsyncWaiter::~TizenVsyncWaiter () { DestoryTDMVblank (); }
35
+ TizenVsyncWaiter::~TizenVsyncWaiter () {
36
+ SendMessage (QUEUE_QUIT);
37
+ if (vblank_thread_) {
38
+ ecore_thread_cancel (vblank_thread_);
39
+ vblank_thread_ = nullptr ;
40
+ }
41
+ DestoryTDMVblank ();
42
+ }
33
43
34
44
void TizenVsyncWaiter::AsyncWaitForVsync (intptr_t baton) {
35
45
baton_ = baton;
36
46
if (TDMValid ()) {
37
- ecore_thread_run (RequestVblank, NULL , NULL , this );
47
+ SendMessage (QUEUE_REQUEST_VBLANK);
48
+ }
49
+ }
50
+
51
+ void TizenVsyncWaiter::SendMessage (int val) {
52
+ if (!vblank_thread_queue || !vblank_thread_) {
53
+ FT_LOGE (" vblank thread or vblank thread queue not valid" );
54
+ return ;
55
+ }
56
+ Msg* msg;
57
+ void * ref;
58
+ msg = (Msg*)eina_thread_queue_send (vblank_thread_queue, sizeof (Msg), &ref);
59
+ msg->value = val;
60
+ eina_thread_queue_send_done (vblank_thread_queue, ref);
61
+ }
62
+
63
+ void TizenVsyncWaiter::RequestVblankLoop (void * data, Ecore_Thread* thread) {
64
+ TizenVsyncWaiter* tizen_vsync_waiter =
65
+ reinterpret_cast <TizenVsyncWaiter*>(data);
66
+ void * ref;
67
+ Msg* msg;
68
+ while (!ecore_thread_check (thread)) {
69
+ if (!vblank_thread_queue) {
70
+ FT_LOGE (" Vblank thread queue is not valid" );
71
+ return ;
72
+ }
73
+ msg = (Msg*)eina_thread_queue_wait (vblank_thread_queue, &ref);
74
+ if (msg) {
75
+ eina_thread_queue_wait_done (vblank_thread_queue, ref);
76
+ } else {
77
+ FT_LOGE (" Message is null" );
78
+ continue ;
79
+ }
80
+ if (msg->value == QUEUE_QUIT) {
81
+ FT_LOGD (" Message queue quit" );
82
+ return ;
83
+ }
84
+ if (!tizen_vsync_waiter->TDMValid ()) {
85
+ FT_LOGE (" TDM not valid" );
86
+ return ;
87
+ }
88
+ tdm_error error = tdm_client_vblank_wait (tizen_vsync_waiter->vblank_ , 1 ,
89
+ TdmClientVblankCallback, data);
90
+ if (error != TDM_ERROR_NONE) {
91
+ FT_LOGE (" tdm_client_vblank_wait error %d" , error);
92
+ continue ;
93
+ }
94
+ tdm_client_handle_events (tizen_vsync_waiter->client_ );
95
+ }
96
+ }
97
+
98
+ void TizenVsyncWaiter::VblankLoopFinish (void * data, Ecore_Thread* thread) {
99
+ FT_LOGD (" VblankLoopFinish." );
100
+ if (vblank_thread_queue) {
101
+ eina_thread_queue_free (vblank_thread_queue);
102
+ vblank_thread_queue = nullptr ;
38
103
}
39
104
}
40
105
@@ -67,6 +132,7 @@ void TizenVsyncWaiter::DestoryTDMVblank() {
67
132
tdm_client_vblank_destroy (vblank_);
68
133
vblank_ = nullptr ;
69
134
}
135
+ output_ = nullptr ;
70
136
if (client_) {
71
137
tdm_client_destroy (client_);
72
138
client_ = nullptr ;
@@ -80,11 +146,9 @@ void TizenVsyncWaiter::TdmClientVblankCallback(
80
146
unsigned int tv_sec, unsigned int tv_usec, void * user_data) {
81
147
TizenVsyncWaiter* tizen_vsync_waiter =
82
148
reinterpret_cast <TizenVsyncWaiter*>(user_data);
83
-
84
149
FT_ASSERT (tizen_vsync_waiter != nullptr );
85
150
FT_ASSERT (tizen_vsync_waiter->engine_ != nullptr );
86
151
FT_ASSERT (tizen_vsync_waiter->engine_ ->flutter_engine != nullptr );
87
-
88
152
uint64_t frame_start_time_nanos = tv_sec * 1e9 + tv_usec * 1e3 ;
89
153
uint64_t frame_target_time_nanos = 16.6 * 1e6 + frame_start_time_nanos;
90
154
FlutterEngineOnVsync (tizen_vsync_waiter->engine_ ->flutter_engine ,
0 commit comments