Skip to content

Commit 14319f6

Browse files
authored
Switch TizenEventLoop to use CurrentTimeProc (flutter-tizen#137)
* Switch TizenEventLoop to use CurrentTimeProc * Additional clean-ups
1 parent 39fd66f commit 14319f6

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

shell/platform/tizen/BUILD.gn

+5-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ template("embedder_for_profile") {
154154
}
155155

156156
defines = invoker.defines
157+
defines += [ "FLUTTER_ENGINE_NO_PROTOTYPES" ]
157158

158159
if (use_evas_gl_renderer || enable_desktop_embeddings) {
159160
sources += [ "tizen_renderer_evas_gl.cc" ]
@@ -260,7 +261,10 @@ template("embedder_executable") {
260261
"evas",
261262
]
262263

263-
defines = [ "TIZEN_RENDERER_EVAS_GL" ]
264+
defines = [
265+
"FLUTTER_ENGINE_NO_PROTOTYPES",
266+
"TIZEN_RENDERER_EVAS_GL",
267+
]
264268

265269
cflags_cc = [
266270
"-Wno-newline-eof",

shell/platform/tizen/flutter_tizen_engine.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ FlutterTizenEngine::FlutterTizenEngine(const FlutterProjectBundle& project)
4444
// thread). UI threads need to send flutter task to platform thread.
4545
event_loop_ = std::make_unique<TizenPlatformEventLoop>(
4646
std::this_thread::get_id(), // main thread
47-
[this](const auto* task) {
47+
embedder_api_.GetCurrentTime, [this](const auto* task) {
4848
if (embedder_api_.RunTask(this->engine_, task) != kSuccess) {
4949
FT_LOGE("Could not post an engine task.");
5050
}
@@ -74,6 +74,7 @@ void FlutterTizenEngine::InitializeRenderer(int32_t x,
7474

7575
render_loop_ = std::make_unique<TizenRenderEventLoop>(
7676
std::this_thread::get_id(), // main thread
77+
embedder_api_.GetCurrentTime,
7778
[this](const auto* task) {
7879
if (embedder_api_.RunTask(this->engine_, task) != kSuccess) {
7980
FT_LOGE("Could not post an engine task.");

shell/platform/tizen/tizen_event_loop.cc

+10-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
namespace flutter {
1616

1717
TizenEventLoop::TizenEventLoop(std::thread::id main_thread_id,
18+
CurrentTimeProc get_current_time,
1819
TaskExpiredCallback on_task_expired)
1920
: main_thread_id_(main_thread_id),
21+
get_current_time_(get_current_time),
2022
on_task_expired_(std::move(on_task_expired)) {
2123
ecore_pipe_ = ecore_pipe_add(ExcuteTaskEvents, this);
2224
}
@@ -54,7 +56,7 @@ TizenEventLoop::TaskTimePoint TizenEventLoop::TimePointFromFlutterTime(
5456
uint64_t flutter_target_time_nanos) {
5557
const auto now = TaskTimePoint::clock::now();
5658
const int64_t flutter_duration =
57-
flutter_target_time_nanos - FlutterEngineGetCurrentTime();
59+
flutter_target_time_nanos - get_current_time_();
5860
return now + std::chrono::nanoseconds(flutter_duration);
5961
}
6062

@@ -83,7 +85,7 @@ void TizenEventLoop::ExcuteTaskEvents(void* data,
8385

8486
const double flutter_duration =
8587
(static_cast<double>(p_task->fire_time.time_since_epoch().count()) -
86-
FlutterEngineGetCurrentTime()) /
88+
self->get_current_time_()) /
8789
1000000000.0;
8890
if (flutter_duration > 0) {
8991
{
@@ -102,8 +104,9 @@ void TizenEventLoop::ExcuteTaskEvents(void* data,
102104

103105
TizenPlatformEventLoop::TizenPlatformEventLoop(
104106
std::thread::id main_thread_id,
107+
CurrentTimeProc get_current_time,
105108
TaskExpiredCallback on_task_expired)
106-
: TizenEventLoop(main_thread_id, on_task_expired) {}
109+
: TizenEventLoop(main_thread_id, get_current_time, on_task_expired) {}
107110

108111
TizenPlatformEventLoop::~TizenPlatformEventLoop() {}
109112

@@ -116,9 +119,11 @@ void TizenPlatformEventLoop::OnTaskExpired() {
116119

117120
#ifdef TIZEN_RENDERER_EVAS_GL
118121
TizenRenderEventLoop::TizenRenderEventLoop(std::thread::id main_thread_id,
122+
CurrentTimeProc get_current_time,
119123
TaskExpiredCallback on_task_expired,
120124
TizenRenderer* renderer)
121-
: TizenEventLoop(main_thread_id, on_task_expired), renderer_(renderer) {
125+
: TizenEventLoop(main_thread_id, get_current_time, on_task_expired),
126+
renderer_(renderer) {
122127
evas_object_image_pixels_get_callback_set(
123128
static_cast<TizenRendererEvasGL*>(renderer_)->GetImageHandle(),
124129
[](void* data, Evas_Object* o) { // Render callback
@@ -150,6 +155,6 @@ void TizenRenderEventLoop::OnTaskExpired() {
150155
// Do nothing
151156
}
152157
}
153-
#endif
158+
#endif // TIZEN_RENDERER_EVAS_GL
154159

155160
} // namespace flutter

shell/platform/tizen/tizen_event_loop.h

+19-7
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,23 @@
2121

2222
namespace flutter {
2323

24+
typedef uint64_t (*CurrentTimeProc)();
25+
2426
class TizenRenderer;
2527

2628
class TizenEventLoop {
2729
public:
2830
using TaskExpiredCallback = std::function<void(const FlutterTask*)>;
31+
2932
TizenEventLoop(std::thread::id main_thread_id,
33+
CurrentTimeProc get_current_time,
3034
TaskExpiredCallback on_task_expired);
3135
virtual ~TizenEventLoop();
36+
37+
// Prevent copying.
38+
TizenEventLoop(const TizenEventLoop&) = delete;
39+
TizenEventLoop& operator=(const TizenEventLoop&) = delete;
40+
3241
bool RunsTasksOnCurrentThread() const;
3342

3443
void ExcuteTaskEvents(
@@ -41,6 +50,7 @@ class TizenEventLoop {
4150

4251
protected:
4352
using TaskTimePoint = std::chrono::steady_clock::time_point;
53+
4454
struct Task {
4555
uint64_t order;
4656
TaskTimePoint fire_time;
@@ -55,7 +65,9 @@ class TizenEventLoop {
5565
}
5666
};
5767
};
68+
5869
std::thread::id main_thread_id_;
70+
CurrentTimeProc get_current_time_;
5971
TaskExpiredCallback on_task_expired_;
6072
std::mutex task_queue_mutex_;
6173
std::priority_queue<Task, std::deque<Task>, Task::Comparer> task_queue_;
@@ -67,40 +79,40 @@ class TizenEventLoop {
6779
private:
6880
Ecore_Pipe* ecore_pipe_;
6981

70-
TizenEventLoop(const TizenEventLoop&) = delete;
71-
72-
TizenEventLoop& operator=(const TizenEventLoop&) = delete;
82+
// Returns a TaskTimePoint computed from the given target time from Flutter.
83+
TaskTimePoint TimePointFromFlutterTime(uint64_t flutter_target_time_nanos);
7384

7485
static void ExcuteTaskEvents(void* data, void* buffer, unsigned int nbyte);
7586

7687
static Eina_Bool TaskTimerCallback(void* data);
77-
78-
static TaskTimePoint TimePointFromFlutterTime(
79-
uint64_t flutter_target_time_nanos);
8088
};
8189

8290
class TizenPlatformEventLoop : public TizenEventLoop {
8391
public:
8492
TizenPlatformEventLoop(std::thread::id main_thread_id,
93+
CurrentTimeProc get_current_time,
8594
TaskExpiredCallback on_task_expired);
8695
virtual ~TizenPlatformEventLoop();
96+
8797
virtual void OnTaskExpired() override;
8898
};
8999

90100
#ifdef TIZEN_RENDERER_EVAS_GL
91101
class TizenRenderEventLoop : public TizenEventLoop {
92102
public:
93103
TizenRenderEventLoop(std::thread::id main_thread_id,
104+
CurrentTimeProc get_current_time,
94105
TaskExpiredCallback on_task_expired,
95106
TizenRenderer* renderer);
96107
virtual ~TizenRenderEventLoop();
108+
97109
virtual void OnTaskExpired() override;
98110

99111
private:
100112
TizenRenderer* renderer_{nullptr};
101113
std::atomic_bool has_pending_renderer_callback_{false};
102114
};
103-
#endif
115+
#endif // TIZEN_RENDERER_EVAS_GL
104116

105117
} // namespace flutter
106118

0 commit comments

Comments
 (0)