4
4
5
5
#include " tizen_vsync_waiter.h"
6
6
7
+ #include < Ecore.h>
8
+
7
9
#include " flutter/shell/platform/tizen/logger.h"
8
10
9
- TizenVsyncWaiter::TizenVsyncWaiter ()
10
- : client_(NULL ),
11
- output_(NULL ),
12
- vblank_(NULL ),
13
- flutter_engine_(nullptr ),
14
- baton_(0 ),
15
- vblank_ecore_pipe_(NULL ) {
16
- if (CreateTDMVblank ()) {
17
- std::thread t (CreateVblankEventLoop, this );
18
- t.join ();
19
- } else {
20
- LoggerE (" CreateVsyncVaiter fail" );
11
+ static std::atomic<Ecore_Pipe*> g_vblank_ecore_pipe = nullptr ;
12
+
13
+ static const int VBLANK_LOOP_REQUEST = 1 ;
14
+ static const int VBLANK_LOOP_DEL_PIPE = 2 ;
15
+
16
+ static void SendVblankLoopRequest (int event_type) {
17
+ if (ecore_pipe_write (g_vblank_ecore_pipe.load (), &event_type,
18
+ sizeof (event_type)) == EINA_FALSE) {
19
+ LoggerE (" Failed to Send Reqeust [%s]" , event_type == VBLANK_LOOP_REQUEST
20
+ ? " VBLANK_LOOP_REQUEST"
21
+ : " VBLANK_LOOP_DEL_PIPE" );
21
22
}
22
23
}
23
24
24
- void TizenVsyncWaiter::CreateVblankEventLoop (void * data) {
25
- TizenVsyncWaiter* tizen_vsync_waiter =
26
- reinterpret_cast <TizenVsyncWaiter*>(data);
27
- if (!ecore_init ()) {
28
- LoggerE (" ERROR: Cannot init Ecore!" );
25
+ TizenVsyncWaiter::TizenVsyncWaiter () {
26
+ if (!CreateTDMVblank ()) {
27
+ LoggerE (" Failed to create TDM vblank" );
29
28
return ;
30
29
}
31
- tizen_vsync_waiter->vblank_ecore_pipe_ =
32
- ecore_pipe_add (VblankEventLoopCallback, tizen_vsync_waiter);
33
- LoggerD (" ecore_init successful" );
34
- ecore_main_loop_begin ();
35
- ecore_shutdown ();
36
- }
37
30
38
- void TizenVsyncWaiter::VblankEventLoopCallback (void * data, void * buffer,
39
- unsigned int nbyte) {
40
- TizenVsyncWaiter* tizen_vsync_waiter =
41
- reinterpret_cast <TizenVsyncWaiter*>(data);
42
- int * event_type = reinterpret_cast <int *>(buffer);
43
- if ((*event_type) == VBLANK_LOOP_REQUEST) {
44
- tizen_vsync_waiter->AsyncWaitForVsyncCallback ();
45
- } else if ((*event_type) == VBLANK_LOOP_DEL_PIPE) {
46
- tizen_vsync_waiter->DeleteVblankEventPipe ();
31
+ std::thread t (
32
+ [this ](void * data) {
33
+ if (!ecore_init ()) {
34
+ LoggerE (" Failed to init Ecore" );
35
+ return ;
36
+ }
37
+ Ecore_Pipe* vblank_ecore_pipe = ecore_pipe_add (
38
+ [](void * data, void * buffer, unsigned int nbyte) {
39
+ TizenVsyncWaiter* tizen_vsync_waiter =
40
+ reinterpret_cast <TizenVsyncWaiter*>(data);
41
+ int event_type = *(reinterpret_cast <int *>(buffer));
42
+ if (event_type == VBLANK_LOOP_REQUEST) {
43
+ tizen_vsync_waiter->HandleVblankLoopRequest ();
44
+ } else if (event_type == VBLANK_LOOP_DEL_PIPE) {
45
+ if (g_vblank_ecore_pipe.load ()) {
46
+ ecore_pipe_del (g_vblank_ecore_pipe);
47
+ g_vblank_ecore_pipe = NULL ;
48
+ }
49
+ ecore_main_loop_quit ();
50
+ }
51
+ },
52
+ this );
53
+
54
+ g_vblank_ecore_pipe.store (vblank_ecore_pipe);
55
+ ecore_main_loop_begin ();
56
+ ecore_shutdown ();
57
+ },
58
+ nullptr );
59
+ t.join ();
60
+
61
+ if (g_vblank_ecore_pipe.load () == nullptr ) {
62
+ LoggerE (" Failed to create Ecore Pipe" );
47
63
}
48
64
}
49
65
50
- void TizenVsyncWaiter::AsyncWaitForVsyncCallback () {
51
- tdm_error ret;
52
- ret = tdm_client_vblank_wait (vblank_, 1 , TdmClientVblankCallback, this );
53
- if (ret != TDM_ERROR_NONE) {
54
- LoggerE (" ERROR, ret = %d" , ret);
55
- return ;
66
+ TizenVsyncWaiter::~TizenVsyncWaiter () {
67
+ if (g_vblank_ecore_pipe.load ()) {
68
+ SendVblankLoopRequest (VBLANK_LOOP_DEL_PIPE);
69
+ }
70
+ if (vblank_) {
71
+ tdm_client_vblank_destroy (vblank_);
72
+ }
73
+ if (client_) {
74
+ tdm_client_destroy (client_);
56
75
}
57
- tdm_client_handle_events (client_);
58
76
}
59
77
60
- void TizenVsyncWaiter::DeleteVblankEventPipe () {
61
- if (vblank_ecore_pipe_) {
62
- ecore_pipe_del (vblank_ecore_pipe_);
63
- vblank_ecore_pipe_ = NULL ;
64
- }
65
- ecore_main_loop_quit ();
78
+ void TizenVsyncWaiter::AsyncWaitForVsync (intptr_t baton) {
79
+ baton_ = baton;
80
+ SendVblankLoopRequest (VBLANK_LOOP_REQUEST);
81
+ }
82
+
83
+ bool TizenVsyncWaiter::IsValid () {
84
+ return g_vblank_ecore_pipe.load () && client_ && output_ && vblank_ &&
85
+ flutter_engine_;
66
86
}
67
87
68
88
bool TizenVsyncWaiter::CreateTDMVblank () {
@@ -94,57 +114,20 @@ void TizenVsyncWaiter::TdmClientVblankCallback(
94
114
unsigned int tv_sec, unsigned int tv_usec, void * user_data) {
95
115
TizenVsyncWaiter* tizen_vsync_waiter =
96
116
reinterpret_cast <TizenVsyncWaiter*>(user_data);
97
- if (tizen_vsync_waiter == nullptr ) {
98
- LoggerE (" tizen_vsync_waiter is null" );
99
- return ;
100
- }
101
- if (tizen_vsync_waiter->flutter_engine_ == nullptr ) {
102
- LoggerI (" flutter engine creation is not completed" );
103
- return ;
104
- }
117
+
105
118
uint64_t frame_start_time_nanos = tv_sec * 1e9 + tv_usec * 1e3 ;
106
119
uint64_t frame_target_time_nanos = 16.6 * 1e6 + frame_start_time_nanos;
107
120
FlutterEngineOnVsync (tizen_vsync_waiter->flutter_engine_ ,
108
121
tizen_vsync_waiter->baton_ , frame_start_time_nanos,
109
122
frame_target_time_nanos);
110
123
}
111
124
112
- bool TizenVsyncWaiter::AsyncWaitForVsync () {
113
- if (nullptr == flutter_engine_) {
114
- LoggerD (" flutter_engine_ is null" );
115
- return false ;
116
- }
117
- if (vblank_ecore_pipe_) {
118
- int event_type = VBLANK_LOOP_REQUEST;
119
- ecore_pipe_write (vblank_ecore_pipe_, &event_type, sizeof (event_type));
120
- }
121
- return true ;
122
- }
123
-
124
- TizenVsyncWaiter::~TizenVsyncWaiter () {
125
- if (vblank_ecore_pipe_) {
126
- int event_type = VBLANK_LOOP_DEL_PIPE;
127
- ecore_pipe_write (vblank_ecore_pipe_, &event_type, sizeof (event_type));
128
- }
129
- if (vblank_) {
130
- tdm_client_vblank_destroy (vblank_);
131
- }
132
- if (client_) {
133
- tdm_client_destroy (client_);
134
- }
135
- }
136
-
137
- void TizenVsyncWaiter::AsyncWaitForVsync (intptr_t baton) {
138
- baton_ = baton;
139
- AsyncWaitForVsync ();
140
- }
141
-
142
- void TizenVsyncWaiter::AsyncWaitForRunEngineSuccess (
143
- FLUTTER_API_SYMBOL (FlutterEngine) flutter_engine) {
144
- flutter_engine_ = flutter_engine;
145
- if (baton_ == 0 ) {
146
- LoggerD (" baton_ == 0" );
125
+ void TizenVsyncWaiter::HandleVblankLoopRequest () {
126
+ tdm_error ret;
127
+ ret = tdm_client_vblank_wait (vblank_, 1 , TdmClientVblankCallback, this );
128
+ if (ret != TDM_ERROR_NONE) {
129
+ LoggerE (" ERROR, ret = %d" , ret);
147
130
return ;
148
131
}
149
- AsyncWaitForVsync ( );
150
- }
132
+ tdm_client_handle_events (client_ );
133
+ }
0 commit comments