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..72c7fa7b37724 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 @@ -150,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 013f926d92df1..db2612b7cce41 100644 --- a/shell/platform/tizen/tizen_event_loop.h +++ b/shell/platform/tizen/tizen_event_loop.h @@ -21,14 +21,23 @@ 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(); + + // Prevent copying. + TizenEventLoop(const TizenEventLoop&) = delete; + TizenEventLoop& operator=(const TizenEventLoop&) = delete; + bool RunsTasksOnCurrentThread() const; void ExcuteTaskEvents( @@ -41,6 +50,7 @@ class TizenEventLoop { protected: using TaskTimePoint = std::chrono::steady_clock::time_point; + struct Task { uint64_t order; TaskTimePoint fire_time; @@ -55,7 +65,9 @@ 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_; @@ -67,23 +79,21 @@ 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); - - static 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,16 +101,18 @@ 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(); + virtual void OnTaskExpired() override; private: TizenRenderer* renderer_{nullptr}; std::atomic_bool has_pending_renderer_callback_{false}; }; -#endif +#endif // TIZEN_RENDERER_EVAS_GL } // namespace flutter