diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 6df05a1cc4085..cb1e2777b1bd4 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -170,6 +170,8 @@ FILE: ../../../flutter/fml/platform/darwin/scoped_nsobject.mm FILE: ../../../flutter/fml/platform/darwin/string_range_sanitization.h FILE: ../../../flutter/fml/platform/darwin/string_range_sanitization.mm FILE: ../../../flutter/fml/platform/darwin/string_range_sanitization_unittests.mm +FILE: ../../../flutter/fml/platform/fuchsia/message_loop_fuchsia.cc +FILE: ../../../flutter/fml/platform/fuchsia/message_loop_fuchsia.h FILE: ../../../flutter/fml/platform/fuchsia/paths_fuchsia.cc FILE: ../../../flutter/fml/platform/linux/message_loop_linux.cc FILE: ../../../flutter/fml/platform/linux/message_loop_linux.h diff --git a/fml/BUILD.gn b/fml/BUILD.gn index f6eca0f933166..32f58eddf6056 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -164,12 +164,28 @@ source_set("fml") { } if (is_fuchsia) { - sources += [ "platform/fuchsia/paths_fuchsia.cc" ] + sources += [ + "platform/fuchsia/message_loop_fuchsia.cc", + "platform/fuchsia/message_loop_fuchsia.h", + "platform/fuchsia/paths_fuchsia.cc", + ] if (using_fuchsia_sdk) { - public_deps += [ "$fuchsia_sdk_root/pkg:trace" ] + public_deps += [ + "$fuchsia_sdk_root/pkg:async-cpp", + "$fuchsia_sdk_root/pkg:async-loop-cpp", + "$fuchsia_sdk_root/pkg:async-loop-default", + "$fuchsia_sdk_root/pkg:trace", + "$fuchsia_sdk_root/pkg:zx", + ] } else { - public_deps += [ "//zircon/public/lib/trace" ] + public_deps += [ + "//zircon/public/lib/async-cpp", + "//zircon/public/lib/async-loop-cpp", + "//zircon/public/lib/async-loop-default", + "//zircon/public/lib/trace", + "//zircon/public/lib/zx", + ] } } @@ -205,16 +221,21 @@ executable("fml_unittests") { sources = [ "base32_unittest.cc", "command_line_unittest.cc", + "gpu_thread_merger_unittests.cc", "memory/ref_counted_unittest.cc", "memory/weak_ptr_unittest.cc", "message_loop_task_queues_merge_unmerge_unittests.cc", + "message_loop_task_queues_unittests.cc", + "message_loop_unittests.cc", "message_unittests.cc", "paths_unittests.cc", "platform/darwin/string_range_sanitization_unittests.mm", + "synchronization/count_down_latch_unittests.cc", "synchronization/semaphore_unittest.cc", "synchronization/sync_switch_unittest.cc", "synchronization/waitable_event_unittest.cc", "thread_local_unittests.cc", + "thread_unittests.cc", "time/time_delta_unittest.cc", "time/time_point_unittest.cc", "time/time_unittest.cc", @@ -222,14 +243,7 @@ executable("fml_unittests") { # TODO(gw280): Figure out why these tests don't work currently on Fuchsia if (!is_fuchsia) { - sources += [ - "file_unittest.cc", - "gpu_thread_merger_unittests.cc", - "message_loop_task_queues_unittests.cc", - "message_loop_unittests.cc", - "synchronization/count_down_latch_unittests.cc", - "thread_unittests.cc", - ] + sources += [ "file_unittest.cc" ] } deps = [ diff --git a/fml/message_loop_impl.cc b/fml/message_loop_impl.cc index 9e07e11278810..d4c9331e35990 100644 --- a/fml/message_loop_impl.cc +++ b/fml/message_loop_impl.cc @@ -17,6 +17,8 @@ #include "flutter/fml/platform/darwin/message_loop_darwin.h" #elif OS_ANDROID #include "flutter/fml/platform/android/message_loop_android.h" +#elif OS_FUCHSIA +#include "flutter/fml/platform/fuchsia/message_loop_fuchsia.h" #elif OS_LINUX #include "flutter/fml/platform/linux/message_loop_linux.h" #elif OS_WIN @@ -30,6 +32,8 @@ fml::RefPtr MessageLoopImpl::Create() { return fml::MakeRefCounted(); #elif OS_ANDROID return fml::MakeRefCounted(); +#elif OS_FUCHSIA + return fml::MakeRefCounted(); #elif OS_LINUX return fml::MakeRefCounted(); #elif OS_WIN diff --git a/fml/platform/fuchsia/message_loop_fuchsia.cc b/fml/platform/fuchsia/message_loop_fuchsia.cc new file mode 100644 index 0000000000000..506de40ef8974 --- /dev/null +++ b/fml/platform/fuchsia/message_loop_fuchsia.cc @@ -0,0 +1,38 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/fml/platform/fuchsia/message_loop_fuchsia.h" + +#include +#include +#include + +namespace fml { + +MessageLoopFuchsia::MessageLoopFuchsia() + : loop_(&kAsyncLoopConfigAttachToCurrentThread) {} + +MessageLoopFuchsia::~MessageLoopFuchsia() = default; + +void MessageLoopFuchsia::Run() { + loop_.Run(); +} + +void MessageLoopFuchsia::Terminate() { + loop_.Quit(); +} + +void MessageLoopFuchsia::WakeUp(fml::TimePoint time_point) { + fml::TimePoint now = fml::TimePoint::Now(); + zx::duration due_time{0}; + if (time_point > now) { + due_time = zx::nsec((time_point - now).ToNanoseconds()); + } + + FML_DCHECK(async::PostDelayedTask( + loop_.dispatcher(), [this]() { RunExpiredTasksNow(); }, + due_time) == ZX_OK); +} + +} // namespace fml diff --git a/fml/platform/fuchsia/message_loop_fuchsia.h b/fml/platform/fuchsia/message_loop_fuchsia.h new file mode 100644 index 0000000000000..f54c587c4a2b3 --- /dev/null +++ b/fml/platform/fuchsia/message_loop_fuchsia.h @@ -0,0 +1,36 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_FML_PLATFORM_FUCHSIA_MESSAGE_LOOP_FUCHSIA_H_ +#define FLUTTER_FML_PLATFORM_FUCHSIA_MESSAGE_LOOP_FUCHSIA_H_ + +#include + +#include "flutter/fml/macros.h" +#include "flutter/fml/message_loop_impl.h" + +namespace fml { + +class MessageLoopFuchsia : public MessageLoopImpl { + private: + MessageLoopFuchsia(); + + ~MessageLoopFuchsia() override; + + void Run() override; + + void Terminate() override; + + void WakeUp(fml::TimePoint time_point) override; + + async::Loop loop_; + + FML_FRIEND_MAKE_REF_COUNTED(MessageLoopFuchsia); + FML_FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopFuchsia); + FML_DISALLOW_COPY_AND_ASSIGN(MessageLoopFuchsia); +}; + +} // namespace fml + +#endif // FLUTTER_FML_PLATFORM_FUCHSIA_MESSAGE_LOOP_FUCHSIA_H_ diff --git a/shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx b/shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx index 015acc94b4e47..ea275dd650b1b 100644 --- a/shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx +++ b/shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx @@ -10,7 +10,7 @@ "services": [ "fuchsia.accessibility.semantics.SemanticsManager", "fuchsia.intl.PropertyProvider", - "fuchsia.sys.Launcher" + "fuchsia.process.Launcher" ] } } diff --git a/testing/fuchsia/meta/fuchsia_test.cmx b/testing/fuchsia/meta/fuchsia_test.cmx index fedcb77867acb..1eb7a22e5ef28 100644 --- a/testing/fuchsia/meta/fuchsia_test.cmx +++ b/testing/fuchsia/meta/fuchsia_test.cmx @@ -9,7 +9,7 @@ ], "services": [ "fuchsia.accessibility.semantics.SemanticsManager", - "fuchsia.sys.Launcher" + "fuchsia.process.Launcher" ] } }