From f6318c00bade814b6f49f0038b14bdb899070e4d Mon Sep 17 00:00:00 2001 From: Swift Kim Date: Thu, 8 Jul 2021 17:37:15 +0900 Subject: [PATCH 1/2] Switch TizenEventLoop to use CurrentTimeProc --- shell/platform/tizen/BUILD.gn | 6 +++++- shell/platform/tizen/flutter_tizen_engine.cc | 3 ++- shell/platform/tizen/tizen_event_loop.cc | 13 +++++++++---- shell/platform/tizen/tizen_event_loop.h | 10 ++++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index 5c67ed8e217b8..ea2fbf946f90e 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -154,6 +154,7 @@ template("embedder_for_profile") { } defines = invoker.defines + defines += [ "FLUTTER_ENGINE_NO_PROTOTYPES" ] if (use_evas_gl_renderer || enable_desktop_embeddings) { sources += [ "tizen_renderer_evas_gl.cc" ] @@ -260,7 +261,10 @@ template("embedder_executable") { "evas", ] - defines = [ "TIZEN_RENDERER_EVAS_GL" ] + defines = [ + "FLUTTER_ENGINE_NO_PROTOTYPES", + "TIZEN_RENDERER_EVAS_GL", + ] cflags_cc = [ "-Wno-newline-eof", diff --git a/shell/platform/tizen/flutter_tizen_engine.cc b/shell/platform/tizen/flutter_tizen_engine.cc index d9ec11022c1f3..7feb78b6a3614 100644 --- a/shell/platform/tizen/flutter_tizen_engine.cc +++ b/shell/platform/tizen/flutter_tizen_engine.cc @@ -44,7 +44,7 @@ FlutterTizenEngine::FlutterTizenEngine(const FlutterProjectBundle& project) // thread). UI threads need to send flutter task to platform thread. event_loop_ = std::make_unique( std::this_thread::get_id(), // main thread - [this](const auto* task) { + embedder_api_.GetCurrentTime, [this](const auto* task) { if (embedder_api_.RunTask(this->engine_, task) != kSuccess) { FT_LOGE("Could not post an engine task."); } @@ -74,6 +74,7 @@ void FlutterTizenEngine::InitializeRenderer(int32_t x, render_loop_ = std::make_unique( std::this_thread::get_id(), // main thread + embedder_api_.GetCurrentTime, [this](const auto* task) { if (embedder_api_.RunTask(this->engine_, task) != kSuccess) { FT_LOGE("Could not post an engine task."); diff --git a/shell/platform/tizen/tizen_event_loop.cc b/shell/platform/tizen/tizen_event_loop.cc index 33c150b135ae2..a0584174d2168 100644 --- a/shell/platform/tizen/tizen_event_loop.cc +++ b/shell/platform/tizen/tizen_event_loop.cc @@ -15,8 +15,10 @@ namespace flutter { TizenEventLoop::TizenEventLoop(std::thread::id main_thread_id, + CurrentTimeProc get_current_time, TaskExpiredCallback on_task_expired) : main_thread_id_(main_thread_id), + get_current_time_(get_current_time), on_task_expired_(std::move(on_task_expired)) { ecore_pipe_ = ecore_pipe_add(ExcuteTaskEvents, this); } @@ -54,7 +56,7 @@ TizenEventLoop::TaskTimePoint TizenEventLoop::TimePointFromFlutterTime( uint64_t flutter_target_time_nanos) { const auto now = TaskTimePoint::clock::now(); const int64_t flutter_duration = - flutter_target_time_nanos - FlutterEngineGetCurrentTime(); + flutter_target_time_nanos - get_current_time_(); return now + std::chrono::nanoseconds(flutter_duration); } @@ -83,7 +85,7 @@ void TizenEventLoop::ExcuteTaskEvents(void* data, const double flutter_duration = (static_cast(p_task->fire_time.time_since_epoch().count()) - - FlutterEngineGetCurrentTime()) / + self->get_current_time_()) / 1000000000.0; if (flutter_duration > 0) { { @@ -102,8 +104,9 @@ void TizenEventLoop::ExcuteTaskEvents(void* data, TizenPlatformEventLoop::TizenPlatformEventLoop( std::thread::id main_thread_id, + CurrentTimeProc get_current_time, TaskExpiredCallback on_task_expired) - : TizenEventLoop(main_thread_id, on_task_expired) {} + : TizenEventLoop(main_thread_id, get_current_time, on_task_expired) {} TizenPlatformEventLoop::~TizenPlatformEventLoop() {} @@ -116,9 +119,11 @@ void TizenPlatformEventLoop::OnTaskExpired() { #ifdef TIZEN_RENDERER_EVAS_GL TizenRenderEventLoop::TizenRenderEventLoop(std::thread::id main_thread_id, + CurrentTimeProc get_current_time, TaskExpiredCallback on_task_expired, TizenRenderer* renderer) - : TizenEventLoop(main_thread_id, on_task_expired), renderer_(renderer) { + : TizenEventLoop(main_thread_id, get_current_time, on_task_expired), + renderer_(renderer) { evas_object_image_pixels_get_callback_set( static_cast(renderer_)->GetImageHandle(), [](void* data, Evas_Object* o) { // Render callback diff --git a/shell/platform/tizen/tizen_event_loop.h b/shell/platform/tizen/tizen_event_loop.h index 013f926d92df1..f51bc4cac65e5 100644 --- a/shell/platform/tizen/tizen_event_loop.h +++ b/shell/platform/tizen/tizen_event_loop.h @@ -21,12 +21,15 @@ namespace flutter { +typedef uint64_t (*CurrentTimeProc)(); + class TizenRenderer; class TizenEventLoop { public: using TaskExpiredCallback = std::function; TizenEventLoop(std::thread::id main_thread_id, + CurrentTimeProc get_current_time, TaskExpiredCallback on_task_expired); virtual ~TizenEventLoop(); bool RunsTasksOnCurrentThread() const; @@ -56,6 +59,7 @@ class TizenEventLoop { }; }; std::thread::id main_thread_id_; + CurrentTimeProc get_current_time_; TaskExpiredCallback on_task_expired_; std::mutex task_queue_mutex_; std::priority_queue, Task::Comparer> task_queue_; @@ -75,13 +79,14 @@ class TizenEventLoop { static Eina_Bool TaskTimerCallback(void* data); - static TaskTimePoint TimePointFromFlutterTime( - uint64_t flutter_target_time_nanos); + // Returns a TaskTimePoint computed from the given target time from Flutter. + TaskTimePoint TimePointFromFlutterTime(uint64_t flutter_target_time_nanos); }; class TizenPlatformEventLoop : public TizenEventLoop { public: TizenPlatformEventLoop(std::thread::id main_thread_id, + CurrentTimeProc get_current_time, TaskExpiredCallback on_task_expired); virtual ~TizenPlatformEventLoop(); virtual void OnTaskExpired() override; @@ -91,6 +96,7 @@ class TizenPlatformEventLoop : public TizenEventLoop { class TizenRenderEventLoop : public TizenEventLoop { public: TizenRenderEventLoop(std::thread::id main_thread_id, + CurrentTimeProc get_current_time, TaskExpiredCallback on_task_expired, TizenRenderer* renderer); virtual ~TizenRenderEventLoop(); From 3b1c6a7e28eec25e2e964f0764c49b3a4b5a1ec8 Mon Sep 17 00:00:00 2001 From: Swift Kim Date: Thu, 8 Jul 2021 18:03:43 +0900 Subject: [PATCH 2/2] Additional clean-ups --- shell/platform/tizen/tizen_event_loop.cc | 2 +- shell/platform/tizen/tizen_event_loop.h | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/shell/platform/tizen/tizen_event_loop.cc b/shell/platform/tizen/tizen_event_loop.cc index a0584174d2168..72c7fa7b37724 100644 --- a/shell/platform/tizen/tizen_event_loop.cc +++ b/shell/platform/tizen/tizen_event_loop.cc @@ -155,6 +155,6 @@ void TizenRenderEventLoop::OnTaskExpired() { // Do nothing } } -#endif +#endif // TIZEN_RENDERER_EVAS_GL } // namespace flutter diff --git a/shell/platform/tizen/tizen_event_loop.h b/shell/platform/tizen/tizen_event_loop.h index f51bc4cac65e5..db2612b7cce41 100644 --- a/shell/platform/tizen/tizen_event_loop.h +++ b/shell/platform/tizen/tizen_event_loop.h @@ -28,10 +28,16 @@ class TizenRenderer; class TizenEventLoop { public: using TaskExpiredCallback = std::function; + TizenEventLoop(std::thread::id main_thread_id, CurrentTimeProc get_current_time, TaskExpiredCallback on_task_expired); virtual ~TizenEventLoop(); + + // Prevent copying. + TizenEventLoop(const TizenEventLoop&) = delete; + TizenEventLoop& operator=(const TizenEventLoop&) = delete; + bool RunsTasksOnCurrentThread() const; void ExcuteTaskEvents( @@ -44,6 +50,7 @@ class TizenEventLoop { protected: using TaskTimePoint = std::chrono::steady_clock::time_point; + struct Task { uint64_t order; TaskTimePoint fire_time; @@ -58,6 +65,7 @@ class TizenEventLoop { } }; }; + std::thread::id main_thread_id_; CurrentTimeProc get_current_time_; TaskExpiredCallback on_task_expired_; @@ -71,16 +79,12 @@ class TizenEventLoop { private: Ecore_Pipe* ecore_pipe_; - TizenEventLoop(const TizenEventLoop&) = delete; - - TizenEventLoop& operator=(const TizenEventLoop&) = delete; + // Returns a TaskTimePoint computed from the given target time from Flutter. + TaskTimePoint TimePointFromFlutterTime(uint64_t flutter_target_time_nanos); static void ExcuteTaskEvents(void* data, void* buffer, unsigned int nbyte); static Eina_Bool TaskTimerCallback(void* data); - - // Returns a TaskTimePoint computed from the given target time from Flutter. - TaskTimePoint TimePointFromFlutterTime(uint64_t flutter_target_time_nanos); }; class TizenPlatformEventLoop : public TizenEventLoop { @@ -89,6 +93,7 @@ class TizenPlatformEventLoop : public TizenEventLoop { CurrentTimeProc get_current_time, TaskExpiredCallback on_task_expired); virtual ~TizenPlatformEventLoop(); + virtual void OnTaskExpired() override; }; @@ -100,13 +105,14 @@ class TizenRenderEventLoop : public TizenEventLoop { TaskExpiredCallback on_task_expired, TizenRenderer* renderer); virtual ~TizenRenderEventLoop(); + virtual void OnTaskExpired() override; private: TizenRenderer* renderer_{nullptr}; std::atomic_bool has_pending_renderer_callback_{false}; }; -#endif +#endif // TIZEN_RENDERER_EVAS_GL } // namespace flutter