diff --git a/sky/shell/dart/dart_library_provider_files.h b/sky/shell/dart/dart_library_provider_files.h index fa4775c3103b0b561c5051616ba316c91a74e2fd..24cade6da46e6288f58894cbd4ac664ccb52bf47 100644 --- a/sky/shell/dart/dart_library_provider_files.h +++ b/sky/shell/dart/dart_library_provider_files.h @@ -7,6 +7,7 @@ #include "base/files/file_path.h" #include "flutter/tonic/dart_library_provider.h" +#include "lib/ftl/macros.h" #include "lib/tonic/parsers/packages_map.h" namespace sky { @@ -32,7 +33,7 @@ class DartLibraryProviderFiles : public blink::DartLibraryProvider { base::FilePath packages_; tonic::PackagesMap packages_map_; - DISALLOW_COPY_AND_ASSIGN(DartLibraryProviderFiles); + FTL_DISALLOW_COPY_AND_ASSIGN(DartLibraryProviderFiles); }; } // namespace shell diff --git a/sky/shell/diagnostic/diagnostic_server.cc b/sky/shell/diagnostic/diagnostic_server.cc index 80e852d65b63d8250a53e77cdfc6e09886535c66..67a913cb94986508b921e43d6592a440cf6bf859 100644 --- a/sky/shell/diagnostic/diagnostic_server.cc +++ b/sky/shell/diagnostic/diagnostic_server.cc @@ -103,7 +103,7 @@ void DiagnosticServer::HandleSkiaPictureRequest(Dart_Handle send_port) { } void DiagnosticServer::SkiaPictureTask(Dart_Port port_id) { - std::vector> rasterizers; + std::vector> rasterizers; Shell::Shared().GetRasterizers(&rasterizers); if (rasterizers.size() != 1) { SendNull(port_id); diff --git a/sky/shell/gpu/direct/rasterizer_direct.cc b/sky/shell/gpu/direct/rasterizer_direct.cc index 864a7691452f85de93780abf33551edfe65df528..e8499100ec870883f86dfe3224b3be66218a68de 100644 --- a/sky/shell/gpu/direct/rasterizer_direct.cc +++ b/sky/shell/gpu/direct/rasterizer_direct.cc @@ -31,7 +31,7 @@ std::unique_ptr Rasterizer::Create() { } // sky::shell::Rasterizer override. -base::WeakPtr RasterizerDirect::GetWeakRasterizerPtr() { +ftl::WeakPtr RasterizerDirect::GetWeakRasterizerPtr() { return weak_factory_.GetWeakPtr(); } @@ -44,9 +44,10 @@ void RasterizerDirect::ConnectToRasterizer( } // sky::shell::Rasterizer override. -void RasterizerDirect::Setup(PlatformView* platform_view, - base::Closure continuation, - base::WaitableEvent* setup_completion_event) { +void RasterizerDirect::Setup( + PlatformView* platform_view, + ftl::Closure continuation, + ftl::AutoResetWaitableEvent* setup_completion_event) { CHECK(platform_view) << "Must be able to acquire the view."; // The context needs to be made current before the GrGL interface can be @@ -66,14 +67,14 @@ void RasterizerDirect::Setup(PlatformView* platform_view, LOG(ERROR) << "WARNING: Flutter will be unable to render to the display"; } - continuation.Run(); + continuation(); setup_completion_event->Signal(); } // sky::shell::Rasterizer override. void RasterizerDirect::Teardown( - base::WaitableEvent* teardown_completion_event) { + ftl::AutoResetWaitableEvent* teardown_completion_event) { platform_view_ = nullptr; last_layer_tree_.reset(); compositor_context_.OnGrContextDestroyed(); diff --git a/sky/shell/gpu/direct/rasterizer_direct.h b/sky/shell/gpu/direct/rasterizer_direct.h index b6f6431e721405d98835e3d350616116ac2355ef..81c7e2865862a0e5efd48b6dcfdcbb4d8f36531f 100644 --- a/sky/shell/gpu/direct/rasterizer_direct.h +++ b/sky/shell/gpu/direct/rasterizer_direct.h @@ -5,9 +5,9 @@ #ifndef SKY_SHELL_GPU_DIRECT_RASTERIZER_DIRECT_H_ #define SKY_SHELL_GPU_DIRECT_RASTERIZER_DIRECT_H_ -#include "base/memory/weak_ptr.h" -#include "base/synchronization/waitable_event.h" #include "flow/compositor_context.h" +#include "lib/ftl/memory/weak_ptr.h" +#include "lib/ftl/synchronization/waitable_event.h" #include "sky/shell/gpu/direct/ganesh_canvas.h" #include "sky/shell/rasterizer.h" @@ -26,14 +26,15 @@ class RasterizerDirect : public Rasterizer { // sky::shell::Rasterizer override. void Setup(PlatformView* platform_view, - base::Closure continuation, - base::WaitableEvent* setup_completion_event) override; + ftl::Closure continuation, + ftl::AutoResetWaitableEvent* setup_completion_event) override; // sky::shell::Rasterizer override. - void Teardown(base::WaitableEvent* teardown_completion_event) override; + void Teardown( + ftl::AutoResetWaitableEvent* teardown_completion_event) override; // sky::shell::Rasterizer override. - base::WeakPtr GetWeakRasterizerPtr() override; + ftl::WeakPtr GetWeakRasterizerPtr() override; // sky::shell::Rasterizer override. flow::LayerTree* GetLastLayerTree() override; @@ -44,12 +45,12 @@ class RasterizerDirect : public Rasterizer { mojo::Binding binding_; std::unique_ptr last_layer_tree_; PlatformView* platform_view_; - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; // sky::services::rasterizer::Rasterizer (from rasterizer.mojom) override. void Draw(uint64_t layer_tree_ptr, const DrawCallback& callback) override; - DISALLOW_COPY_AND_ASSIGN(RasterizerDirect); + FTL_DISALLOW_COPY_AND_ASSIGN(RasterizerDirect); }; } // namespace shell diff --git a/sky/shell/gpu/mojo/gl_texture_recycler.cc b/sky/shell/gpu/mojo/gl_texture_recycler.cc index 1a5f19c3932c7c5708c8dece9b3465988d13a514..bb6933861c98324b87f39bdbc97f496c12ebd85c 100644 --- a/sky/shell/gpu/mojo/gl_texture_recycler.cc +++ b/sky/shell/gpu/mojo/gl_texture_recycler.cc @@ -82,7 +82,7 @@ mojo::gfx::composition::ResourcePtr GLTextureRecycler::BindTextureResource( } void GLTextureRecycler::ReleaseTexture(GLRecycledTextureInfo texture_info, - bool recyclable) { + bool recyclable) { DCHECK(bound_textures_); bound_textures_--; if (recyclable && recycled_textures_.size() < max_recycled_textures_) { @@ -93,7 +93,7 @@ void GLTextureRecycler::ReleaseTexture(GLRecycledTextureInfo texture_info, } GLTextureRecycler::GLTextureReleaser::GLTextureReleaser( - const base::WeakPtr& provider, + const ftl::WeakPtr& provider, GLRecycledTextureInfo info) : provider_(provider), texture_info_(std::move(info)), binding_(this) {} diff --git a/sky/shell/gpu/mojo/gl_texture_recycler.h b/sky/shell/gpu/mojo/gl_texture_recycler.h index b5d91286eb432a282806ae7f4c184604c6207cf7..99c5b671b9f2a630f2e4de9fa55863b182f4c594 100644 --- a/sky/shell/gpu/mojo/gl_texture_recycler.h +++ b/sky/shell/gpu/mojo/gl_texture_recycler.h @@ -8,9 +8,10 @@ #include #include -#include "base/callback.h" -#include "base/macros.h" -#include "base/memory/weak_ptr.h" +#include "base/memory/ref_counted.h" +#include "lib/ftl/functional/closure.h" +#include "lib/ftl/macros.h" +#include "lib/ftl/memory/weak_ptr.h" #include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/services/gfx/composition/interfaces/resources.mojom.h" @@ -29,7 +30,7 @@ namespace shell { class GLTextureRecycler { public: GLTextureRecycler(scoped_refptr gl_context, - uint32_t max_recycled_textures = 3u); + uint32_t max_recycled_textures = 3u); ~GLTextureRecycler(); // Obtains a texture of the specified size. @@ -51,7 +52,7 @@ class GLTextureRecycler { // migrating to image pipes. class GLTextureReleaser : mojo::gfx::composition::MailboxTextureCallback { public: - GLTextureReleaser(const base::WeakPtr& provider, + GLTextureReleaser(const ftl::WeakPtr& provider, GLRecycledTextureInfo info); ~GLTextureReleaser() override; @@ -61,7 +62,7 @@ class GLTextureRecycler { void OnMailboxTextureReleased() override; void Release(bool recyclable); - base::WeakPtr provider_; + ftl::WeakPtr provider_; GLRecycledTextureInfo texture_info_; mojo::StrongBinding binding_; @@ -75,9 +76,9 @@ class GLTextureRecycler { std::deque recycled_textures_; uint32_t bound_textures_ = 0u; - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; - DISALLOW_COPY_AND_ASSIGN(GLTextureRecycler); + FTL_DISALLOW_COPY_AND_ASSIGN(GLTextureRecycler); }; } // namespace shell diff --git a/sky/shell/gpu/mojo/rasterizer_mojo.cc b/sky/shell/gpu/mojo/rasterizer_mojo.cc index 2fbce666e13546f475369fa72d915487974a0445..c75e1541c204c78b50159d573584e53984eaedc6 100644 --- a/sky/shell/gpu/mojo/rasterizer_mojo.cc +++ b/sky/shell/gpu/mojo/rasterizer_mojo.cc @@ -40,7 +40,7 @@ RasterizerMojo::~RasterizerMojo() { Shell::Shared().PurgeRasterizers(); } -base::WeakPtr RasterizerMojo::GetWeakRasterizerPtr() { +ftl::WeakPtr RasterizerMojo::GetWeakRasterizerPtr() { return weak_factory_.GetWeakPtr(); } @@ -57,14 +57,16 @@ void RasterizerMojo::Init(mojo::ApplicationConnectorPtr connector, scene_ = scene.Pass(); } -void RasterizerMojo::Setup(PlatformView* platform_view, - base::Closure rasterizer_continuation, - base::WaitableEvent* setup_completion_event) { +void RasterizerMojo::Setup( + PlatformView* platform_view, + ftl::Closure rasterizer_continuation, + ftl::AutoResetWaitableEvent* setup_completion_event) { setup_completion_event->Signal(); - rasterizer_continuation.Run(); + rasterizer_continuation(); } -void RasterizerMojo::Teardown(base::WaitableEvent* teardown_completion_event) { +void RasterizerMojo::Teardown( + ftl::AutoResetWaitableEvent* teardown_completion_event) { teardown_completion_event->Signal(); } diff --git a/sky/shell/gpu/mojo/rasterizer_mojo.h b/sky/shell/gpu/mojo/rasterizer_mojo.h index 7107eac4adf5d869537367dd0c6fef04555e2e2e..27e4414467fb42107a6f713102d34ad51e83390d 100644 --- a/sky/shell/gpu/mojo/rasterizer_mojo.h +++ b/sky/shell/gpu/mojo/rasterizer_mojo.h @@ -5,8 +5,8 @@ #ifndef SKY_SHELL_GPU_MOJO_RASTERIZER_MOJO_H_ #define SKY_SHELL_GPU_MOJO_RASTERIZER_MOJO_H_ -#include "base/memory/weak_ptr.h" #include "flow/compositor_context.h" +#include "lib/ftl/memory/weak_ptr.h" #include "mojo/gpu/gl_context.h" #include "mojo/public/interfaces/application/application_connector.mojom.h" #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" @@ -32,14 +32,15 @@ class RasterizerMojo : public Rasterizer { // sky::shell::rasterizer::Rasterizer override void Setup(PlatformView* platform_view, - base::Closure rasterizer_continuation, - base::WaitableEvent* setup_completion_event) override; + ftl::Closure rasterizer_continuation, + ftl::AutoResetWaitableEvent* setup_completion_event) override; // sky::shell::rasterizer::Rasterizer override - void Teardown(base::WaitableEvent* teardown_completion_event) override; + void Teardown( + ftl::AutoResetWaitableEvent* teardown_completion_event) override; // sky::shell::rasterizer::Rasterizer override - base::WeakPtr GetWeakRasterizerPtr() override; + ftl::WeakPtr GetWeakRasterizerPtr() override; // sky::shell::rasterizer::Rasterizer override flow::LayerTree* GetLastLayerTree() override; @@ -60,11 +61,11 @@ class RasterizerMojo : public Rasterizer { std::unique_ptr gl_state_; flow::CompositorContext compositor_context_; std::unique_ptr last_layer_tree_; - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; void Draw(uint64_t layer_tree_ptr, const DrawCallback& callback) override; - DISALLOW_COPY_AND_ASSIGN(RasterizerMojo); + FTL_DISALLOW_COPY_AND_ASSIGN(RasterizerMojo); }; } // namespace shell diff --git a/sky/shell/platform/android/flutter_main.cc b/sky/shell/platform/android/flutter_main.cc index 7ad5ea69ae100a9153f2a84f0dd6f5570c00930b..ed24c547b436378b2dde707028245ea0da5927f4 100644 --- a/sky/shell/platform/android/flutter_main.cc +++ b/sky/shell/platform/android/flutter_main.cc @@ -13,7 +13,7 @@ #include "base/files/file_path.h" #include "base/lazy_instance.h" #include "base/logging.h" -#include "base/macros.h" +#include "lib/ftl/macros.h" #include "base/message_loop/message_loop.h" #include "base/path_service.h" #include "base/run_loop.h" diff --git a/sky/shell/platform/android/platform_view_android.cc b/sky/shell/platform/android/platform_view_android.cc index d6665c8731319bfce00b851ffd6cf8d6e452c8c0..6e0756c4f79715732854e0bf13dc5ec492f9c288 100644 --- a/sky/shell/platform/android/platform_view_android.cc +++ b/sky/shell/platform/android/platform_view_android.cc @@ -86,10 +86,9 @@ EGLResult CreatePBufferSurface(EGLDisplay display, return {surface != EGL_NO_SURFACE, surface}; } -EGLResult CreateContext( - EGLDisplay display, - EGLConfig config, - EGLContext share = EGL_NO_CONTEXT) { +EGLResult CreateContext(EGLDisplay display, + EGLConfig config, + EGLContext share = EGL_NO_CONTEXT) { EGLint attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; EGLContext context = eglCreateContext(display, config, share, attributes); @@ -156,8 +155,7 @@ void InitGlobal() { std::tie(success, g_resource_surface) = CreatePBufferSurface(g_display, resource_egl_config); if (!success) { - DLOG(INFO) - << "Could not create the pbuffer surface for resource loading."; + DLOG(INFO) << "Could not create the pbuffer surface for resource loading."; LogLastEGLError(); return; } @@ -199,7 +197,7 @@ class AndroidNativeWindow { private: Handle window_; - DISALLOW_COPY_AND_ASSIGN(AndroidNativeWindow); + FTL_DISALLOW_COPY_AND_ASSIGN(AndroidNativeWindow); }; class AndroidGLContext { @@ -242,8 +240,8 @@ class AndroidGLContext { // Create a context for the configuration. - std::tie(success, context_) = CreateContext(g_display, config_, - g_resource_context); + std::tie(success, context_) = + CreateContext(g_display, config_, g_resource_context); if (!success) { DLOG(INFO) << "Could not create the main rendering context"; @@ -343,7 +341,7 @@ class AndroidGLContext { return {surface != EGL_NO_SURFACE, surface}; } - DISALLOW_COPY_AND_ASSIGN(AndroidGLContext); + FTL_DISALLOW_COPY_AND_ASSIGN(AndroidGLContext); }; static jlong Attach(JNIEnv* env, jclass clazz, jint skyEngineHandle) { @@ -402,7 +400,7 @@ void PlatformViewAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) { context_ = nullptr; } -base::WeakPtr PlatformViewAndroid::GetWeakViewPtr() { +ftl::WeakPtr PlatformViewAndroid::GetWeakViewPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/sky/shell/platform/android/platform_view_android.h b/sky/shell/platform/android/platform_view_android.h index 10490fa54c801944d90e131b5ac005284c66cbc8..07e7b736da7c8556f9eb2e38548a435b49377fc7 100644 --- a/sky/shell/platform/android/platform_view_android.h +++ b/sky/shell/platform/android/platform_view_android.h @@ -5,9 +5,8 @@ #ifndef SKY_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_H_ #define SKY_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_H_ -#include "base/macros.h" #include "base/android/jni_android.h" -#include "base/synchronization/waitable_event.h" +#include "lib/ftl/memory/weak_ptr.h" #include "sky/shell/platform_view.h" namespace sky { @@ -33,7 +32,7 @@ class PlatformViewAndroid : public PlatformView { void SurfaceDestroyed(JNIEnv* env, jobject obj); // sky::shell::PlatformView override - base::WeakPtr GetWeakViewPtr() override; + ftl::WeakPtr GetWeakViewPtr() override; // sky::shell::PlatformView override uint64_t DefaultFramebuffer() const override; @@ -55,9 +54,9 @@ class PlatformViewAndroid : public PlatformView { private: std::unique_ptr context_; - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; - DISALLOW_COPY_AND_ASSIGN(PlatformViewAndroid); + FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewAndroid); }; } // namespace shell diff --git a/sky/shell/platform/glfw/message_pump_glfw.h b/sky/shell/platform/glfw/message_pump_glfw.h index 71c52d3cb603f06e4637575be78c6dc1d9a290e4..66dcca5fae18622ded476dac55d78721dd2d2e35 100644 --- a/sky/shell/platform/glfw/message_pump_glfw.h +++ b/sky/shell/platform/glfw/message_pump_glfw.h @@ -30,7 +30,7 @@ class MessagePumpGLFW : public base::MessagePump { bool should_quit_; base::TimeTicks delayed_work_time_; - DISALLOW_COPY_AND_ASSIGN(MessagePumpGLFW); + FTL_DISALLOW_COPY_AND_ASSIGN(MessagePumpGLFW); }; } // namespace shell diff --git a/sky/shell/platform/glfw/platform_view_glfw.h b/sky/shell/platform/glfw/platform_view_glfw.h index 031a1fc93c45687c00f5ac4741433e18c80c6963..1a375734b63d8c5510e1d9034d6ef46a9ad341b3 100644 --- a/sky/shell/platform/glfw/platform_view_glfw.h +++ b/sky/shell/platform/glfw/platform_view_glfw.h @@ -21,7 +21,7 @@ class PlatformViewGLFW : public PlatformView { private: gfx::AcceleratedWidget window_; - DISALLOW_COPY_AND_ASSIGN(PlatformViewGLFW); + FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewGLFW); }; } // namespace shell diff --git a/sky/shell/platform/glfw/window_impl.h b/sky/shell/platform/glfw/window_impl.h index d4de690c169f36fbc89c2efeee8c02fc90f8e6ee..cf214f2f5e77bb0d012680c2f9137c2e350886bc 100644 --- a/sky/shell/platform/glfw/window_impl.h +++ b/sky/shell/platform/glfw/window_impl.h @@ -52,7 +52,7 @@ class WindowImpl : public mojo::ServiceProvider, mojo::BindingSet raw_keyboard_bindings_; std::vector raw_keyboard_listeners_; - DISALLOW_COPY_AND_ASSIGN(WindowImpl); + FTL_DISALLOW_COPY_AND_ASSIGN(WindowImpl); }; } // namespace shell diff --git a/sky/shell/platform/ios/framework/Source/FlutterViewController.mm b/sky/shell/platform/ios/framework/Source/FlutterViewController.mm index a4ee0ed110bc7d9ca3ddc17e831020bd37b5b515..1179c35b6cd69ee2718d90f59c2f178438bd3607 100644 --- a/sky/shell/platform/ios/framework/Source/FlutterViewController.mm +++ b/sky/shell/platform/ios/framework/Source/FlutterViewController.mm @@ -216,10 +216,14 @@ static void DynamicServiceResolve(void* baton, new sky::shell::PlatformServiceProvider(serviceProviderProxy.Pass(), serviceResolutionCallback); + ftl::WeakPtr appplication_messages_impl + = _appMessageReceiver.GetWeakPtr(); mojo::ServiceProviderPtr viewServiceProvider; - new sky::shell::ViewServiceProvider( - base::Bind(&sky::shell::ApplicationMessagesImpl::AddBinding, - _appMessageReceiver.GetWeakPtr()), + new sky::shell::ViewServiceProvider([appplication_messages_impl]( + mojo::InterfaceRequest request) { + if (appplication_messages_impl) + appplication_messages_impl->AddBinding(std::move(request)); + }, mojo::GetProxy(&viewServiceProvider)); DCHECK(!_dartServices.is_bound()); diff --git a/sky/shell/platform/ios/framework/Source/accessibility_bridge.h b/sky/shell/platform/ios/framework/Source/accessibility_bridge.h index 34d8ef36005435a2124e702c8be550485a94b7e6..bec8c1e9a0fb9a9cbf9adad31d262daeab3b6752 100644 --- a/sky/shell/platform/ios/framework/Source/accessibility_bridge.h +++ b/sky/shell/platform/ios/framework/Source/accessibility_bridge.h @@ -9,7 +9,7 @@ #include #include -#include "base/macros.h" +#include "lib/ftl/macros.h" #include "mojo/public/cpp/bindings/array.h" #include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/interfaces/application/service_provider.mojom.h" @@ -71,7 +71,7 @@ class AccessibilityBridge final : public semantics::SemanticsListener { mojo::Binding binding_; - DISALLOW_COPY_AND_ASSIGN(AccessibilityBridge); + FTL_DISALLOW_COPY_AND_ASSIGN(AccessibilityBridge); }; } // namespace shell diff --git a/sky/shell/platform/ios/framework/Source/application_messages_impl.h b/sky/shell/platform/ios/framework/Source/application_messages_impl.h index c45d66a73c1a76831d38b058cc6c91c8fe4a5872..b3eaa8f8b028ea4231201bbf1817aba967b83251 100644 --- a/sky/shell/platform/ios/framework/Source/application_messages_impl.h +++ b/sky/shell/platform/ios/framework/Source/application_messages_impl.h @@ -7,7 +7,7 @@ #include -#include "base/memory/weak_ptr.h" +#include "lib/ftl/memory/weak_ptr.h" #include "mojo/public/cpp/bindings/binding_set.h" #include "sky/services/platform/app_messages.mojom.h" #include "sky/shell/platform/ios/framework/Headers/FlutterAsyncMessageListener.h" @@ -21,16 +21,15 @@ class ApplicationMessagesImpl : public flutter::platform::ApplicationMessages { ApplicationMessagesImpl(); ~ApplicationMessagesImpl() override; - base::WeakPtr GetWeakPtr(); - void AddBinding(mojo::InterfaceRequest request); + ftl::WeakPtr GetWeakPtr(); + void AddBinding( + mojo::InterfaceRequest request); - void SetMessageListener( - const std::string& message_name, - NSObject* listener); + void SetMessageListener(const std::string& message_name, + NSObject* listener); - void SetAsyncMessageListener( - const std::string& message_name, - NSObject* listener); + void SetAsyncMessageListener(const std::string& message_name, + NSObject* listener); private: void SendString(const mojo::String& message_name, @@ -38,12 +37,11 @@ class ApplicationMessagesImpl : public flutter::platform::ApplicationMessages { const SendStringCallback& callback) override; mojo::BindingSet binding_; - std::unordered_map< - std::string, NSObject*> listeners_; - std::unordered_map< - std::string, NSObject*> async_listeners_; + std::unordered_map*> listeners_; + std::unordered_map*> + async_listeners_; - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; }; } // namespace shell diff --git a/sky/shell/platform/ios/framework/Source/application_messages_impl.mm b/sky/shell/platform/ios/framework/Source/application_messages_impl.mm index 066f232b7a2d725e99fec81ef9b6b01e4f1341c6..bbf383d36b984e7fc4805fd9dc6470ee1e299007 100644 --- a/sky/shell/platform/ios/framework/Source/application_messages_impl.mm +++ b/sky/shell/platform/ios/framework/Source/application_messages_impl.mm @@ -15,7 +15,7 @@ ApplicationMessagesImpl::ApplicationMessagesImpl() : weak_factory_(this) { ApplicationMessagesImpl::~ApplicationMessagesImpl() { } -base::WeakPtr ApplicationMessagesImpl::GetWeakPtr() { +ftl::WeakPtr ApplicationMessagesImpl::GetWeakPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/sky/shell/platform/ios/framework/Source/flutter_touch_mapper.h b/sky/shell/platform/ios/framework/Source/flutter_touch_mapper.h index c08f15dd590142054ac146f4f77079137ee956a6..31e1ae75b05b23771ab9069d593bb6d16d82e879 100644 --- a/sky/shell/platform/ios/framework/Source/flutter_touch_mapper.h +++ b/sky/shell/platform/ios/framework/Source/flutter_touch_mapper.h @@ -7,7 +7,7 @@ #include -#include "base/macros.h" +#include "lib/ftl/macros.h" #include @@ -33,7 +33,7 @@ class TouchMapper { BitSet free_spots_; std::map touch_map_; - DISALLOW_COPY_AND_ASSIGN(TouchMapper); + FTL_DISALLOW_COPY_AND_ASSIGN(TouchMapper); }; } // namespace shell diff --git a/sky/shell/platform/ios/platform_view_ios.h b/sky/shell/platform/ios/platform_view_ios.h index 8ff4d997b91c1cb830d5d742b797de34200ceb67..9c63e24b7147a31fac58babf0e41896740b2914c 100644 --- a/sky/shell/platform/ios/platform_view_ios.h +++ b/sky/shell/platform/ios/platform_view_ios.h @@ -7,9 +7,9 @@ #include -#include "base/macros.h" #include "base/mac/scoped_nsobject.h" -#include "base/memory/weak_ptr.h" +#include "lib/ftl/macros.h" +#include "lib/ftl/memory/weak_ptr.h" #include "sky/shell/platform_view.h" @class CAEAGLLayer; @@ -25,7 +25,7 @@ class PlatformViewIOS : public PlatformView { ~PlatformViewIOS() override; - base::WeakPtr GetWeakViewPtr() override; + ftl::WeakPtr GetWeakViewPtr() override; uint64_t DefaultFramebuffer() const override; @@ -37,9 +37,9 @@ class PlatformViewIOS : public PlatformView { private: std::unique_ptr context_; - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; - DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS); + FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS); }; } // namespace shell diff --git a/sky/shell/platform/ios/platform_view_ios.mm b/sky/shell/platform/ios/platform_view_ios.mm index 837b80579996f3a0c36fd2c2f87147b6fdeb63aa..9acd6f36e85788107789ea363ec8d9da509d9c3d 100644 --- a/sky/shell/platform/ios/platform_view_ios.mm +++ b/sky/shell/platform/ios/platform_view_ios.mm @@ -266,7 +266,7 @@ class IOSGLContext { return true; } - DISALLOW_COPY_AND_ASSIGN(IOSGLContext); + FTL_DISALLOW_COPY_AND_ASSIGN(IOSGLContext); }; PlatformViewIOS::PlatformViewIOS(CAEAGLLayer* layer) @@ -275,7 +275,7 @@ PlatformViewIOS::PlatformViewIOS(CAEAGLLayer* layer) PlatformViewIOS::~PlatformViewIOS() = default; -base::WeakPtr PlatformViewIOS::GetWeakViewPtr() { +ftl::WeakPtr PlatformViewIOS::GetWeakViewPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/sky/shell/platform/linux/platform_view_linux.cc b/sky/shell/platform/linux/platform_view_linux.cc index bb258dcae870dbce2a133495e5dec34c993d28a0..2c20ce876a1e507f71943d733c002cad7ebd3b5c 100644 --- a/sky/shell/platform/linux/platform_view_linux.cc +++ b/sky/shell/platform/linux/platform_view_linux.cc @@ -13,7 +13,7 @@ PlatformViewLinux::PlatformViewLinux(const Config& config, PlatformViewLinux::~PlatformViewLinux() {} -base::WeakPtr PlatformViewLinux::GetWeakViewPtr() { +ftl::WeakPtr PlatformViewLinux::GetWeakViewPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/sky/shell/platform/linux/platform_view_linux.h b/sky/shell/platform/linux/platform_view_linux.h index 1afa3bae58183827c172a0cecee48405436c8304..0b2f4e0fb5b1e76906d451efa0dcbfcb92179c3c 100644 --- a/sky/shell/platform/linux/platform_view_linux.h +++ b/sky/shell/platform/linux/platform_view_linux.h @@ -12,12 +12,13 @@ namespace shell { class PlatformViewLinux : public PlatformView { public: - explicit PlatformViewLinux(const Config& config, SurfaceConfig surface_config); + explicit PlatformViewLinux(const Config& config, + SurfaceConfig surface_config); ~PlatformViewLinux() override; // sky::shell::PlatformView override - base::WeakPtr GetWeakViewPtr() override; + ftl::WeakPtr GetWeakViewPtr() override; // sky::shell::PlatformView override uint64_t DefaultFramebuffer() const override; @@ -29,9 +30,9 @@ class PlatformViewLinux : public PlatformView { bool SwapBuffers() override; private: - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; - DISALLOW_COPY_AND_ASSIGN(PlatformViewLinux); + FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewLinux); }; } // namespace shell diff --git a/sky/shell/platform/mac/platform_mac.mm b/sky/shell/platform/mac/platform_mac.mm index 31f99982c378cb335a6f80ee0102f5a3303518b4..7c2d592bfd39a6d7cf0154cc389c13f8bbc2595e 100644 --- a/sky/shell/platform/mac/platform_mac.mm +++ b/sky/shell/platform/mac/platform_mac.mm @@ -107,7 +107,7 @@ class EmbedderState { base::AtExitManager exit_manager_; std::unique_ptr embedder_message_loop_; - DISALLOW_COPY_AND_ASSIGN(EmbedderState); + FTL_DISALLOW_COPY_AND_ASSIGN(EmbedderState); }; void PlatformMacMain(int argc, const char* argv[], std::string icu_data_path) { diff --git a/sky/shell/platform/mac/platform_service_provider.h b/sky/shell/platform/mac/platform_service_provider.h index 6836cfff396641544e404ee763ca5703c574e438..4a76c8d4f3d4d2d91419af89c4cb8b81d17bae6f 100644 --- a/sky/shell/platform/mac/platform_service_provider.h +++ b/sky/shell/platform/mac/platform_service_provider.h @@ -5,7 +5,7 @@ #ifndef SKY_SHELL_PLATFORM_MAC_PLATFORM_SERVICE_PROVIDER_H_ #define SKY_SHELL_PLATFORM_MAC_PLATFORM_SERVICE_PROVIDER_H_ -#include "base/macros.h" +#include "lib/ftl/macros.h" #include "base/callback.h" #include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/interfaces/application/service_provider.mojom.h" @@ -30,7 +30,7 @@ class PlatformServiceProvider : public mojo::ServiceProvider { DynamicServiceProviderCallback dynamic_service_provider_; mojo::StrongBinding binding_; - DISALLOW_COPY_AND_ASSIGN(PlatformServiceProvider); + FTL_DISALLOW_COPY_AND_ASSIGN(PlatformServiceProvider); }; } // namespace shell diff --git a/sky/shell/platform/mac/platform_view_mac.h b/sky/shell/platform/mac/platform_view_mac.h index d7f845b4dc24f789d7079d66cd235b3da96316d0..f3ebe603e421749da0c37ab5e7e3c1697b0a9c04 100644 --- a/sky/shell/platform/mac/platform_view_mac.h +++ b/sky/shell/platform/mac/platform_view_mac.h @@ -5,9 +5,9 @@ #ifndef SKY_SHELL_PLATFORM_MAC_PLATFORM_VIEW_MAC_H_ #define SKY_SHELL_PLATFORM_MAC_PLATFORM_VIEW_MAC_H_ -#include "base/memory/weak_ptr.h" -#include "sky/shell/platform_view.h" #include "base/mac/scoped_nsobject.h" +#include "lib/ftl/memory/weak_ptr.h" +#include "sky/shell/platform_view.h" @class NSOpenGLView; @class NSOpenGLContext; @@ -21,7 +21,7 @@ class PlatformViewMac : public PlatformView { ~PlatformViewMac() override; - base::WeakPtr GetWeakViewPtr() override; + ftl::WeakPtr GetWeakViewPtr() override; uint64_t DefaultFramebuffer() const override; @@ -34,11 +34,11 @@ class PlatformViewMac : public PlatformView { private: base::scoped_nsobject opengl_view_; base::scoped_nsobject resource_loading_context_; - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; bool IsValid() const; - DISALLOW_COPY_AND_ASSIGN(PlatformViewMac); + FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewMac); }; } // namespace shell diff --git a/sky/shell/platform/mac/platform_view_mac.mm b/sky/shell/platform/mac/platform_view_mac.mm index 21498bfa054f981931b5948412e0606484fdf9f8..3222e9101ad8ce0397dbf4e684e19034c5b4987a 100644 --- a/sky/shell/platform/mac/platform_view_mac.mm +++ b/sky/shell/platform/mac/platform_view_mac.mm @@ -20,7 +20,7 @@ PlatformViewMac::PlatformViewMac(NSOpenGLView* gl_view) PlatformViewMac::~PlatformViewMac() = default; -base::WeakPtr PlatformViewMac::GetWeakViewPtr() { +ftl::WeakPtr PlatformViewMac::GetWeakViewPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/sky/shell/platform/mac/sky_window.mm b/sky/shell/platform/mac/sky_window.mm index 282c831cbc39d1a762168f674fa88a42f97f688e..fa507e978badabc00e64d1c9e290b2919f374f81 100644 --- a/sky/shell/platform/mac/sky_window.mm +++ b/sky/shell/platform/mac/sky_window.mm @@ -16,6 +16,10 @@ #include "sky/shell/switches.h" #include "sky/shell/ui_delegate.h" +static void IgnoreRequest( + mojo::InterfaceRequest) { +} + static void DynamicServiceResolve(const mojo::String& service_name, mojo::ScopedMessagePipeHandle handle) {} @@ -83,7 +87,7 @@ static inline pointer::PointerType EventTypeFromNSEventPhase( base::Bind(DynamicServiceResolve)); mojo::ServiceProviderPtr view_service_provider; - new sky::shell::ViewServiceProvider(sky::shell::AppMesssagesConnector(), + new sky::shell::ViewServiceProvider(IgnoreRequest, mojo::GetProxy(&view_service_provider)); sky::ServicesDataPtr services = sky::ServicesData::New(); diff --git a/sky/shell/platform/mac/view_service_provider.cc b/sky/shell/platform/mac/view_service_provider.cc index f0b3217d386b14ddfde6131ad99fdaf3e87108e2..8359240692a03dc1776163c5129fcd4b9a1c2cc2 100644 --- a/sky/shell/platform/mac/view_service_provider.cc +++ b/sky/shell/platform/mac/view_service_provider.cc @@ -2,36 +2,34 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/logging.h" #include "sky/shell/platform/mac/view_service_provider.h" +#include + namespace sky { namespace shell { ViewServiceProvider::ViewServiceProvider( AppMesssagesConnector connect_to_app_messages, mojo::InterfaceRequest request) - : binding_(this, request.Pass()), - connect_to_app_messages_(connect_to_app_messages) { -} + : binding_(this, request.Pass()), + connect_to_app_messages_(connect_to_app_messages) {} -ViewServiceProvider::~ViewServiceProvider() { -} +ViewServiceProvider::~ViewServiceProvider() {} void ViewServiceProvider::ConnectToService( const mojo::String& service_name, mojo::ScopedMessagePipeHandle client_handle) { - if (service_name == ::flutter::platform::ApplicationMessages::Name_ && - !connect_to_app_messages_.is_null()) { - connect_to_app_messages_.Run( + if (service_name == ::flutter::platform::ApplicationMessages::Name_) { + connect_to_app_messages_( mojo::InterfaceRequest<::flutter::platform::ApplicationMessages>( - client_handle.Pass())); + std::move(client_handle))); return; } #if TARGET_OS_IPHONE if (service_name == ::editing::Keyboard::Name_) { new sky::services::editing::KeyboardImpl( - mojo::InterfaceRequest<::editing::Keyboard>(client_handle.Pass())); + mojo::InterfaceRequest<::editing::Keyboard>(std::move(client_handle))); return; } #endif diff --git a/sky/shell/platform/mac/view_service_provider.h b/sky/shell/platform/mac/view_service_provider.h index 441746b168c0517fd98126e8f1cda7461178732e..3f968e9db188f52e468ed8fee4626058cd795057 100644 --- a/sky/shell/platform/mac/view_service_provider.h +++ b/sky/shell/platform/mac/view_service_provider.h @@ -5,7 +5,9 @@ #ifndef SKY_SHELL_PLATFORM_MAC_VIEW_SERVICE_PROVIDER_H_ #define SKY_SHELL_PLATFORM_MAC_VIEW_SERVICE_PROVIDER_H_ -#include "base/bind.h" +#include + +#include "lib/ftl/macros.h" #include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/interfaces/application/service_provider.mojom.h" #include "sky/engine/wtf/Assertions.h" @@ -18,9 +20,9 @@ namespace sky { namespace shell { -typedef base::Callback< - void(mojo::InterfaceRequest) - > AppMesssagesConnector; +typedef std::function)> + AppMesssagesConnector; class ViewServiceProvider : public mojo::ServiceProvider { public: @@ -35,7 +37,7 @@ class ViewServiceProvider : public mojo::ServiceProvider { mojo::StrongBinding binding_; AppMesssagesConnector connect_to_app_messages_; - DISALLOW_COPY_AND_ASSIGN(ViewServiceProvider); + FTL_DISALLOW_COPY_AND_ASSIGN(ViewServiceProvider); }; } // namespace shell diff --git a/sky/shell/platform/mojo/content_handler_impl.h b/sky/shell/platform/mojo/content_handler_impl.h index 1bf19a0d645f2b5210e254f012028b3e2d3052e6..e60b40108dab3660d8acc384563aca752c392285 100644 --- a/sky/shell/platform/mojo/content_handler_impl.h +++ b/sky/shell/platform/mojo/content_handler_impl.h @@ -5,7 +5,7 @@ #ifndef SKY_SHELL_PLATFORM_MOJO_CONTENT_HANDLER_IMPL_H_ #define SKY_SHELL_PLATFORM_MOJO_CONTENT_HANDLER_IMPL_H_ -#include "base/macros.h" +#include "lib/ftl/macros.h" #include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" @@ -24,7 +24,7 @@ class ContentHandlerImpl : public mojo::ContentHandler { mojo::URLResponsePtr response) override; mojo::StrongBinding binding_; - DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); + FTL_DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); }; } // namespace shell diff --git a/sky/shell/platform/mojo/main_mojo.cc b/sky/shell/platform/mojo/main_mojo.cc index 503ab1377cce2b6eeb4d93787b8a46b4e63860a2..aa28be157cf7c58cb26b10ce05e7cc19c62e33b6 100644 --- a/sky/shell/platform/mojo/main_mojo.cc +++ b/sky/shell/platform/mojo/main_mojo.cc @@ -62,7 +62,7 @@ class MojoApp : public mojo::ApplicationImplBase { mojo::TracingImpl tracing_; - DISALLOW_COPY_AND_ASSIGN(MojoApp); + FTL_DISALLOW_COPY_AND_ASSIGN(MojoApp); }; } // namespace shell diff --git a/sky/shell/platform/mojo/platform_view_mojo.cc b/sky/shell/platform/mojo/platform_view_mojo.cc index f06fe0ac0d1d9d55f3e1d96aad37168d435448f8..fc6ed5f89c95111ec19459312759f0f6b9e4dd73 100644 --- a/sky/shell/platform/mojo/platform_view_mojo.cc +++ b/sky/shell/platform/mojo/platform_view_mojo.cc @@ -4,9 +4,7 @@ #include "sky/shell/platform/mojo/platform_view_mojo.h" -#include "base/bind.h" -#include "base/location.h" -#include "base/single_thread_task_runner.h" +#include "glue/movable_wrapper.h" #include "sky/shell/gpu/mojo/rasterizer_mojo.h" namespace sky { @@ -18,15 +16,17 @@ PlatformViewMojo::~PlatformViewMojo() = default; void PlatformViewMojo::InitRasterizer(mojo::ApplicationConnectorPtr connector, mojo::gfx::composition::ScenePtr scene) { - auto rasterizer_mojo = reinterpret_cast(config_.rasterizer); - auto continuation = - base::Bind(&RasterizerMojo::Init, // method - base::Unretained(rasterizer_mojo), // target - base::Passed(&connector), base::Passed(&scene)); - NotifyCreated(continuation); + auto rasterizer = reinterpret_cast(config_.rasterizer); + auto wrapped_connector = glue::WrapMovable(std::move(connector)); + auto wrapped_scene = glue::WrapMovable(std::move(scene)); + + NotifyCreated([rasterizer, wrapped_connector, wrapped_scene]() mutable { + if (rasterizer) + rasterizer->Init(wrapped_connector.Unwrap(), wrapped_scene.Unwrap()); + }); } -base::WeakPtr PlatformViewMojo::GetWeakViewPtr() { +ftl::WeakPtr PlatformViewMojo::GetWeakViewPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/sky/shell/platform/mojo/platform_view_mojo.h b/sky/shell/platform/mojo/platform_view_mojo.h index 2180603d474b434efc25885804d4d0db24e2cf71..51c2ef55f098b961f4c95ecd76fc0428a629cf30 100644 --- a/sky/shell/platform/mojo/platform_view_mojo.h +++ b/sky/shell/platform/mojo/platform_view_mojo.h @@ -5,13 +5,14 @@ #ifndef SKY_SHELL_PLATFORM_MOJO_PLATFORM_VIEW_MOJO_H_ #define SKY_SHELL_PLATFORM_MOJO_PLATFORM_VIEW_MOJO_H_ -#include "base/macros.h" +#include + +#include "lib/ftl/macros.h" +#include "lib/ftl/memory/weak_ptr.h" #include "mojo/public/interfaces/application/application_connector.mojom.h" #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" #include "sky/shell/platform_view.h" -#include - namespace sky { namespace shell { @@ -25,7 +26,7 @@ class PlatformViewMojo : public PlatformView { mojo::gfx::composition::ScenePtr scene); // sky::shell::PlatformView override - base::WeakPtr GetWeakViewPtr() override; + ftl::WeakPtr GetWeakViewPtr() override; // sky::shell::PlatformView override uint64_t DefaultFramebuffer() const override; @@ -40,9 +41,9 @@ class PlatformViewMojo : public PlatformView { bool SwapBuffers() override; private: - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; - DISALLOW_COPY_AND_ASSIGN(PlatformViewMojo); + FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewMojo); }; } // namespace shell diff --git a/sky/shell/platform/mojo/pointer_converter_mojo.h b/sky/shell/platform/mojo/pointer_converter_mojo.h index 5775f7cc15f7d516c7e61c8a1b3da2f90d65e306..f2f2545bbb8bfeb10409dbdb7bd5f8c9e685060b 100644 --- a/sky/shell/platform/mojo/pointer_converter_mojo.h +++ b/sky/shell/platform/mojo/pointer_converter_mojo.h @@ -7,7 +7,7 @@ #include -#include "base/macros.h" +#include "lib/ftl/macros.h" #include "mojo/services/input_events/interfaces/input_events.mojom.h" #include "sky/services/pointer/pointer.mojom.h" @@ -28,7 +28,7 @@ class PointerConverterMojo { std::map> pointer_positions_; - DISALLOW_COPY_AND_ASSIGN(PointerConverterMojo); + FTL_DISALLOW_COPY_AND_ASSIGN(PointerConverterMojo); }; } // namespace shell diff --git a/sky/shell/platform/mojo/view_impl.h b/sky/shell/platform/mojo/view_impl.h index 0863e55d51d25715fd44f8d0a68803608ae90faa..01192c503e725c8c0c87e65f65f260debe3aad94 100644 --- a/sky/shell/platform/mojo/view_impl.h +++ b/sky/shell/platform/mojo/view_impl.h @@ -7,7 +7,7 @@ #include -#include "base/macros.h" +#include "lib/ftl/macros.h" #include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/interfaces/application/application_connector.mojom.h" @@ -69,7 +69,7 @@ class ViewImpl : public mojo::ui::ViewListener, PointerConverterMojo pointer_converter_; - DISALLOW_COPY_AND_ASSIGN(ViewImpl); + FTL_DISALLOW_COPY_AND_ASSIGN(ViewImpl); }; } // namespace shell diff --git a/sky/shell/platform_view.cc b/sky/shell/platform_view.cc index 1b9896c0cd5bf40cf297d6f016ad87e0fcc8b042..2b8ab53c30b5b3f8165aed8539c37824aa6d36df 100644 --- a/sky/shell/platform_view.cc +++ b/sky/shell/platform_view.cc @@ -4,11 +4,10 @@ #include "sky/shell/platform_view.h" -#include "base/bind_helpers.h" -#include "base/bind.h" -#include "base/location.h" -#include "base/single_thread_task_runner.h" +#include + #include "flutter/lib/ui/painting/resource_context.h" +#include "glue/movable_wrapper.h" #include "sky/shell/rasterizer.h" #include "third_party/skia/include/gpu/gl/GrGLInterface.h" @@ -25,84 +24,99 @@ PlatformView::PlatformView() // Create the engine for this platform view. Engine::Config engine_config; - engine_config.gpu_task_runner = shell.gpu_task_runner(); + engine_config.gpu_task_runner = + ftl::RefPtr(shell.gpu_ftl_task_runner()); + ftl::WeakPtr rasterizer_impl = + rasterizer_->GetWeakRasterizerPtr(); rasterizer::RasterizerPtr rasterizer; - mojo::InterfaceRequest request = - mojo::GetProxy(&rasterizer); + auto request = glue::WrapMovable(mojo::GetProxy(&rasterizer)); - shell.gpu_task_runner()->PostTask( - FROM_HERE, - base::Bind(&Rasterizer::ConnectToRasterizer, - rasterizer_->GetWeakRasterizerPtr(), base::Passed(&request))); + shell.gpu_ftl_task_runner()->PostTask([rasterizer_impl, request]() mutable { + if (rasterizer_impl) + rasterizer_impl->ConnectToRasterizer(request.Unwrap()); + }); engine_.reset(new Engine(engine_config, rasterizer.Pass())); // Setup the platform config. - config_.ui_task_runner = shell.ui_task_runner(); + config_.ui_task_runner = + ftl::RefPtr(shell.ui_ftl_task_runner()); config_.ui_delegate = engine_->GetWeakPtr(); config_.rasterizer = rasterizer_.get(); } PlatformView::~PlatformView() { Shell& shell = Shell::Shared(); - // Purge dead PlatformViews. - shell.ui_task_runner()->PostTask( - FROM_HERE, - base::Bind(&Shell::PurgePlatformViews, base::Unretained(&shell))); - shell.gpu_task_runner()->DeleteSoon(FROM_HERE, rasterizer_.release()); - shell.ui_task_runner()->DeleteSoon(FROM_HERE, engine_.release()); + + shell.ui_ftl_task_runner()->PostTask( + []() { Shell::Shared().PurgePlatformViews(); }); + + Rasterizer* rasterizer = rasterizer_.release(); + shell.gpu_ftl_task_runner()->PostTask([rasterizer]() { delete rasterizer; }); + + Engine* engine = engine_.release(); + shell.ui_ftl_task_runner()->PostTask([engine]() { delete engine; }); } void PlatformView::ConnectToEngine(mojo::InterfaceRequest request) { + ftl::WeakPtr ui_delegate = config_.ui_delegate; + auto wrapped_request = glue::WrapMovable(std::move(request)); + config_.ui_task_runner->PostTask([ui_delegate, wrapped_request]() mutable { + if (ui_delegate) + ui_delegate->ConnectToEngine(wrapped_request.Unwrap()); + }); + ftl::WeakPtr view = GetWeakViewPtr(); config_.ui_task_runner->PostTask( - FROM_HERE, base::Bind(&UIDelegate::ConnectToEngine, config_.ui_delegate, - base::Passed(&request))); - Shell& shell = Shell::Shared(); - shell.ui_task_runner()->PostTask( - FROM_HERE, base::Bind(&Shell::AddPlatformView, base::Unretained(&shell), - GetWeakViewPtr())); + [view]() { Shell::Shared().AddPlatformView(view); }); } void PlatformView::NotifyCreated() { - PlatformView::NotifyCreated(base::Bind(&base::DoNothing)); + PlatformView::NotifyCreated([]() {}); } -void PlatformView::NotifyCreated(base::Closure rasterizer_continuation) { +void PlatformView::NotifyCreated(ftl::Closure rasterizer_continuation) { CHECK(config_.rasterizer != nullptr); - auto delegate = config_.ui_delegate; auto rasterizer = config_.rasterizer->GetWeakRasterizerPtr(); - base::WaitableEvent latch(false, false); + ftl::AutoResetWaitableEvent latch; + auto delegate_continuation = [rasterizer, this, rasterizer_continuation, + &latch]() { + if (rasterizer) + rasterizer->Setup(this, rasterizer_continuation, &latch); + // TODO(abarth): We should signal the latch if the rasterizer is gone. + }; - auto delegate_continuation = - base::Bind(&Rasterizer::Setup, // method - rasterizer, // target - base::Unretained(this), rasterizer_continuation, - base::Unretained(&latch)); - - config_.ui_task_runner->PostTask( - FROM_HERE, base::Bind(&UIDelegate::OnOutputSurfaceCreated, delegate, - delegate_continuation)); + auto delegate = config_.ui_delegate; + config_.ui_task_runner->PostTask([delegate, delegate_continuation]() { + if (delegate) + delegate->OnOutputSurfaceCreated(delegate_continuation); + // TODO(abarth): We should signal the latch if the delegate is gone. + }); latch.Wait(); } void PlatformView::NotifyDestroyed() { - CHECK(config_.rasterizer != nullptr); + FTL_CHECK(config_.rasterizer != nullptr); auto delegate = config_.ui_delegate; auto rasterizer = config_.rasterizer->GetWeakRasterizerPtr(); - base::WaitableEvent latch(false, false); + ftl::AutoResetWaitableEvent latch; - auto delegate_continuation = - base::Bind(&Rasterizer::Teardown, rasterizer, base::Unretained(&latch)); + auto delegate_continuation = [rasterizer, &latch]() { + if (rasterizer) + rasterizer->Teardown(&latch); + // TODO(abarth): We should signal the latch if the rasterizer is gone. + }; - config_.ui_task_runner->PostTask( - FROM_HERE, base::Bind(&UIDelegate::OnOutputSurfaceDestroyed, delegate, - delegate_continuation)); + config_.ui_task_runner->PostTask([delegate, delegate_continuation]() { + if (delegate) + delegate->OnOutputSurfaceDestroyed(delegate_continuation); + // TODO(abarth): We should signal the latch if the delegate is gone. + }); latch.Wait(); } @@ -116,17 +130,16 @@ void PlatformView::Resize(const SkISize& size) { } void PlatformView::SetupResourceContextOnIOThread() { - base::WaitableEvent latch(false, false); + ftl::AutoResetWaitableEvent latch; + + Shell::Shared().io_ftl_task_runner()->PostTask( + [this, &latch]() { SetupResourceContextOnIOThreadPerform(&latch); }); - Shell::Shared().io_task_runner()->PostTask( - FROM_HERE, - base::Bind(&PlatformView::SetupResourceContextOnIOThreadPerform, - base::Unretained(this), base::Unretained(&latch))); latch.Wait(); } void PlatformView::SetupResourceContextOnIOThreadPerform( - base::WaitableEvent* latch) { + ftl::AutoResetWaitableEvent* latch) { if (blink::ResourceContext::Get() != nullptr) { // The resource context was already setup. This could happen if platforms // try to setup a context multiple times, or, if there are multiple platform diff --git a/sky/shell/platform_view.h b/sky/shell/platform_view.h index 63741f21d6fead4b39e62584c1632204fe6ec318..759549ea1b4862d36be7dda2453dc5d90f44ede5 100644 --- a/sky/shell/platform_view.h +++ b/sky/shell/platform_view.h @@ -7,13 +7,12 @@ #include -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "base/synchronization/waitable_event.h" -#include "base/threading/thread_local_storage.h" +#include "lib/ftl/macros.h" +#include "lib/ftl/memory/weak_ptr.h" +#include "lib/ftl/synchronization/waitable_event.h" #include "sky/shell/shell.h" -#include "sky/shell/ui/engine.h" #include "sky/shell/ui_delegate.h" +#include "sky/shell/ui/engine.h" #include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/gpu/GrContext.h" @@ -29,9 +28,9 @@ class PlatformView { ~Config(); - base::WeakPtr ui_delegate; + ftl::WeakPtr ui_delegate; Rasterizer* rasterizer; - scoped_refptr ui_task_runner; + ftl::RefPtr ui_task_runner; }; struct SurfaceConfig { @@ -51,11 +50,11 @@ class PlatformView { void NotifyCreated(); - void NotifyCreated(base::Closure continuation); + void NotifyCreated(ftl::Closure continuation); void NotifyDestroyed(); - virtual base::WeakPtr GetWeakViewPtr() = 0; + virtual ftl::WeakPtr GetWeakViewPtr() = 0; virtual uint64_t DefaultFramebuffer() const = 0; @@ -82,10 +81,11 @@ class PlatformView { explicit PlatformView(); - void SetupResourceContextOnIOThreadPerform(base::WaitableEvent* event); + void SetupResourceContextOnIOThreadPerform( + ftl::AutoResetWaitableEvent* event); private: - DISALLOW_COPY_AND_ASSIGN(PlatformView); + FTL_DISALLOW_COPY_AND_ASSIGN(PlatformView); }; } // namespace shell diff --git a/sky/shell/rasterizer.h b/sky/shell/rasterizer.h index d97d65d7aca48fcf397fd8afa2cd446e882c0aea..dfb24dabdaae4ab9406d64e4cab795c0055634d2 100644 --- a/sky/shell/rasterizer.h +++ b/sky/shell/rasterizer.h @@ -7,10 +7,10 @@ #include -#include "base/callback.h" -#include "base/memory/weak_ptr.h" -#include "base/synchronization/waitable_event.h" #include "flow/layers/layer_tree.h" +#include "lib/ftl/memory/weak_ptr.h" +#include "lib/ftl/synchronization/waitable_event.h" +#include "lib/ftl/functional/closure.h" #include "mojo/public/cpp/bindings/binding.h" #include "sky/services/rasterizer/rasterizer.mojom.h" @@ -27,12 +27,13 @@ class Rasterizer : public rasterizer::Rasterizer { mojo::InterfaceRequest request) = 0; virtual void Setup(PlatformView* platform_view, - base::Closure rasterizer_continuation, - base::WaitableEvent* setup_completion_event) = 0; + ftl::Closure rasterizer_continuation, + ftl::AutoResetWaitableEvent* setup_completion_event) = 0; - virtual void Teardown(base::WaitableEvent* teardown_completion_event) = 0; + virtual void Teardown( + ftl::AutoResetWaitableEvent* teardown_completion_event) = 0; - virtual base::WeakPtr GetWeakRasterizerPtr() = 0; + virtual ftl::WeakPtr GetWeakRasterizerPtr() = 0; virtual flow::LayerTree* GetLastLayerTree() = 0; diff --git a/sky/shell/shell.cc b/sky/shell/shell.cc index b0583098259457bdadae7d21822da7ac720d90d6..52af493131df8580ce1baa077d46decd9c3be68a 100644 --- a/sky/shell/shell.cc +++ b/sky/shell/shell.cc @@ -19,6 +19,7 @@ #include "base/trace_event/trace_event.h" #include "dart/runtime/include/dart_tools_api.h" #include "glue/task_runner_adaptor.h" +#include "lib/ftl/files/unique_fd.h" #include "mojo/message_pump/message_pump_mojo.h" #include "skia/ext/event_tracer_impl.h" #include "sky/engine/core/script/dart_init.h" @@ -38,11 +39,11 @@ scoped_ptr CreateMessagePumpMojo() { return make_scoped_ptr(new mojo::common::MessagePumpMojo); } -bool IsInvalid(const base::WeakPtr& rasterizer) { +bool IsInvalid(const ftl::WeakPtr& rasterizer) { return !rasterizer; } -bool IsViewInvalid(const base::WeakPtr& platform_view) { +bool IsViewInvalid(const ftl::WeakPtr& platform_view) { return !platform_view; } @@ -85,25 +86,20 @@ Shell::Shell() { gpu_thread_.reset(new base::Thread("gpu_thread")); gpu_thread_->StartWithOptions(options); - gpu_task_runner_ = gpu_thread_->message_loop()->task_runner(); - gpu_ftl_task_runner_ = - ftl::MakeRefCounted(gpu_task_runner_); - gpu_task_runner_->PostTask( - FROM_HERE, base::Bind(&Shell::InitGpuThread, base::Unretained(this))); + gpu_ftl_task_runner_ = ftl::MakeRefCounted( + gpu_thread_->message_loop()->task_runner()); + gpu_ftl_task_runner_->PostTask([this]() { InitGpuThread(); }); ui_thread_.reset(new base::Thread("ui_thread")); ui_thread_->StartWithOptions(options); - ui_task_runner_ = ui_thread_->message_loop()->task_runner(); - ui_ftl_task_runner_ = - ftl::MakeRefCounted(ui_task_runner_); - ui_task_runner_->PostTask( - FROM_HERE, base::Bind(&Shell::InitUIThread, base::Unretained(this))); + ui_ftl_task_runner_ = ftl::MakeRefCounted( + ui_thread_->message_loop()->task_runner()); + ui_ftl_task_runner_->PostTask([this]() { InitUIThread(); }); io_thread_.reset(new base::Thread("io_thread")); io_thread_->StartWithOptions(options); - io_task_runner_ = io_thread_->message_loop()->task_runner(); - io_ftl_task_runner_ = - ftl::MakeRefCounted(io_task_runner_); + io_ftl_task_runner_ = ftl::MakeRefCounted( + io_thread_->message_loop()->task_runner()); blink::SetServiceIsolateHook(ServiceIsolateHook); blink::SetRegisterNativeServiceProtocolExtensionHook( @@ -115,19 +111,17 @@ Shell::~Shell() {} void Shell::InitStandalone(std::string icu_data_path) { TRACE_EVENT0("flutter", "Shell::InitStandalone"); - int file_descriptor = - icu_data_path.size() != 0 - ? HANDLE_EINTR(::open(icu_data_path.data(), O_RDONLY)) - : -1; - - if (file_descriptor == -1) { + ftl::UniqueFD icu_fd( + icu_data_path.empty() ? -1 : HANDLE_EINTR(::open(icu_data_path.c_str(), + O_RDONLY))); + if (icu_fd.get() == -1) { // If the embedder did not specify a valid file, fallback to looking through // internal search paths. - CHECK(base::i18n::InitializeICU()); + FTL_CHECK(base::i18n::InitializeICU()); } else { - auto region = base::MemoryMappedFile::Region::kWholeFile; - CHECK(base::i18n::InitializeICUWithFileDescriptor(file_descriptor, region)); - IGNORE_EINTR(::close(file_descriptor)); + FTL_CHECK(base::i18n::InitializeICUWithFileDescriptor( + icu_fd.get(), base::MemoryMappedFile::Region::kWholeFile)); + icu_fd.reset(); } base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); @@ -145,8 +139,9 @@ void Shell::InitStandalone(std::string icu_data_path) { if (stream >> port) { settings.observatory_port = port; } else { - LOG(INFO) << "Observatory port specified was malformed. Will default to " - << settings.observatory_port; + FTL_LOG(INFO) + << "Observatory port specified was malformed. Will default to " + << settings.observatory_port; } } settings.start_paused = command_line.HasSwitch(switches::kStartPaused); @@ -180,13 +175,13 @@ void Shell::Init() { InitSkiaEventTracer(); #endif - DCHECK(!g_shell); + FTL_DCHECK(!g_shell); g_shell = new Shell(); - g_shell->ui_task_runner()->PostTask(FROM_HERE, base::Bind(&Engine::Init)); + g_shell->ui_ftl_task_runner()->PostTask(Engine::Init); } Shell& Shell::Shared() { - DCHECK(g_shell); + FTL_DCHECK(g_shell); return *g_shell; } @@ -202,61 +197,58 @@ void Shell::InitUIThread() { ui_thread_checker_.reset(new base::ThreadChecker()); } -void Shell::AddRasterizer(const base::WeakPtr& rasterizer) { - DCHECK(gpu_thread_checker_ && gpu_thread_checker_->CalledOnValidThread()); +void Shell::AddRasterizer(const ftl::WeakPtr& rasterizer) { + FTL_DCHECK(gpu_thread_checker_ && gpu_thread_checker_->CalledOnValidThread()); rasterizers_.push_back(rasterizer); } void Shell::PurgeRasterizers() { - DCHECK(gpu_thread_checker_ && gpu_thread_checker_->CalledOnValidThread()); + FTL_DCHECK(gpu_thread_checker_ && gpu_thread_checker_->CalledOnValidThread()); rasterizers_.erase( std::remove_if(rasterizers_.begin(), rasterizers_.end(), IsInvalid), rasterizers_.end()); } -void Shell::GetRasterizers( - std::vector>* rasterizers) { - DCHECK(gpu_thread_checker_ && gpu_thread_checker_->CalledOnValidThread()); +void Shell::GetRasterizers(std::vector>* rasterizers) { + FTL_DCHECK(gpu_thread_checker_ && gpu_thread_checker_->CalledOnValidThread()); *rasterizers = rasterizers_; } -void Shell::AddPlatformView(const base::WeakPtr& platform_view) { - DCHECK(ui_thread_checker_ && ui_thread_checker_->CalledOnValidThread()); +void Shell::AddPlatformView(const ftl::WeakPtr& platform_view) { + FTL_DCHECK(ui_thread_checker_ && ui_thread_checker_->CalledOnValidThread()); if (platform_view) { platform_views_.push_back(platform_view); } } void Shell::PurgePlatformViews() { - DCHECK(ui_thread_checker_ && ui_thread_checker_->CalledOnValidThread()); + FTL_DCHECK(ui_thread_checker_ && ui_thread_checker_->CalledOnValidThread()); platform_views_.erase(std::remove_if(platform_views_.begin(), platform_views_.end(), IsViewInvalid), platform_views_.end()); } void Shell::GetPlatformViews( - std::vector>* platform_views) { - DCHECK(ui_thread_checker_ && ui_thread_checker_->CalledOnValidThread()); + std::vector>* platform_views) { + FTL_DCHECK(ui_thread_checker_ && ui_thread_checker_->CalledOnValidThread()); *platform_views = platform_views_; } void Shell::WaitForPlatformViewIds( std::vector* platform_view_ids) { - base::WaitableEvent latch(false, false); + ftl::AutoResetWaitableEvent latch; - ui_task_runner()->PostTask( - FROM_HERE, - base::Bind(&Shell::WaitForPlatformViewsIdsUIThread, - base::Unretained(this), base::Unretained(platform_view_ids), - base::Unretained(&latch))); + ui_ftl_task_runner()->PostTask([this, platform_view_ids, &latch]() { + WaitForPlatformViewsIdsUIThread(platform_view_ids, &latch); + }); latch.Wait(); } void Shell::WaitForPlatformViewsIdsUIThread( std::vector* platform_view_ids, - base::WaitableEvent* latch) { - std::vector> platform_views; + ftl::AutoResetWaitableEvent* latch) { + std::vector> platform_views; GetPlatformViews(&platform_views); for (auto it = platform_views.begin(); it != platform_views.end(); it++) { PlatformView* view = it->get(); @@ -278,25 +270,20 @@ void Shell::RunInPlatformView(uintptr_t view_id, const char* asset_directory, bool* view_existed, int64_t* dart_isolate_id) { - base::WaitableEvent latch(false, false); - DCHECK(view_id != 0); - DCHECK(main_script); - DCHECK(packages_file); - DCHECK(asset_directory); - DCHECK(view_existed); - - ui_task_runner()->PostTask( - FROM_HERE, - base::Bind(&Shell::RunInPlatformViewUIThread, - base::Unretained(this), - view_id, - std::string(main_script), - std::string(packages_file), - std::string(asset_directory), - base::Unretained(view_existed), - base::Unretained(dart_isolate_id), - base::Unretained(&latch))); - + ftl::AutoResetWaitableEvent latch; + FTL_DCHECK(view_id != 0); + FTL_DCHECK(main_script); + FTL_DCHECK(packages_file); + FTL_DCHECK(asset_directory); + FTL_DCHECK(view_existed); + + ui_ftl_task_runner()->PostTask([this, view_id, main_script, packages_file, + asset_directory, view_existed, + dart_isolate_id, &latch]() { + RunInPlatformViewUIThread(view_id, main_script, packages_file, + asset_directory, view_existed, dart_isolate_id, + &latch); + }); latch.Wait(); } @@ -306,8 +293,8 @@ void Shell::RunInPlatformViewUIThread(uintptr_t view_id, const std::string& assets_directory, bool* view_existed, int64_t* dart_isolate_id, - base::WaitableEvent* latch) { - DCHECK(ui_thread_checker_ && ui_thread_checker_->CalledOnValidThread()); + ftl::AutoResetWaitableEvent* latch) { + FTL_DCHECK(ui_thread_checker_ && ui_thread_checker_->CalledOnValidThread()); *view_existed = false; diff --git a/sky/shell/shell.h b/sky/shell/shell.h index 112b5dddabfcfaa5316eb741195bd889bf253c9b..6c8509e2f54245f9031040e51df0345ac313583b 100644 --- a/sky/shell/shell.h +++ b/sky/shell/shell.h @@ -5,13 +5,11 @@ #ifndef SKY_SHELL_SHELL_H_ #define SKY_SHELL_SHELL_H_ -#include "base/macros.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "base/message_loop/message_loop.h" -#include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" +#include "lib/ftl/macros.h" #include "lib/ftl/memory/ref_ptr.h" +#include "lib/ftl/memory/weak_ptr.h" +#include "lib/ftl/synchronization/waitable_event.h" #include "lib/ftl/tasks/task_runner.h" #include "sky/shell/tracing_controller.h" @@ -33,18 +31,6 @@ class Shell { static Shell& Shared(); - base::SingleThreadTaskRunner* gpu_task_runner() const { - return gpu_task_runner_.get(); - } - - base::SingleThreadTaskRunner* ui_task_runner() const { - return ui_task_runner_.get(); - } - - base::SingleThreadTaskRunner* io_task_runner() const { - return io_task_runner_.get(); - } - ftl::TaskRunner* gpu_ftl_task_runner() const { return gpu_ftl_task_runner_.get(); } @@ -61,17 +47,17 @@ class Shell { // Maintain a list of rasterizers. // These APIs must only be accessed on the GPU thread. - void AddRasterizer(const base::WeakPtr& rasterizer); + void AddRasterizer(const ftl::WeakPtr& rasterizer); void PurgeRasterizers(); - void GetRasterizers(std::vector>* rasterizer); + void GetRasterizers(std::vector>* rasterizer); // List of PlatformViews. // These APIs must only be accessed on UI thread. - void AddPlatformView(const base::WeakPtr& platform_view); + void AddPlatformView(const ftl::WeakPtr& platform_view); void PurgePlatformViews(); void GetPlatformViews( - std::vector>* platform_views); + std::vector>* platform_views); struct PlatformViewInfo { uintptr_t view_id; @@ -99,7 +85,7 @@ class Shell { void WaitForPlatformViewsIdsUIThread( std::vector* platform_views, - base::WaitableEvent* latch); + ftl::AutoResetWaitableEvent* latch); void RunInPlatformViewUIThread(uintptr_t view_id, const std::string& main, @@ -107,16 +93,12 @@ class Shell { const std::string& assets_directory, bool* view_existed, int64_t* dart_isolate_id, - base::WaitableEvent* latch); + ftl::AutoResetWaitableEvent* latch); std::unique_ptr gpu_thread_; std::unique_ptr ui_thread_; std::unique_ptr io_thread_; - scoped_refptr gpu_task_runner_; - scoped_refptr ui_task_runner_; - scoped_refptr io_task_runner_; - ftl::RefPtr gpu_ftl_task_runner_; ftl::RefPtr ui_ftl_task_runner_; ftl::RefPtr io_ftl_task_runner_; @@ -126,10 +108,10 @@ class Shell { TracingController tracing_controller_; - std::vector> rasterizers_; - std::vector> platform_views_; + std::vector> rasterizers_; + std::vector> platform_views_; - DISALLOW_COPY_AND_ASSIGN(Shell); + FTL_DISALLOW_COPY_AND_ASSIGN(Shell); }; } // namespace shell diff --git a/sky/shell/testing/platform_view_test.cc b/sky/shell/testing/platform_view_test.cc index e9239537e66dc1f3f0263de134be493892c2aef4..ef3d3a16ec94685f87088df690365ca3519da6cc 100644 --- a/sky/shell/testing/platform_view_test.cc +++ b/sky/shell/testing/platform_view_test.cc @@ -13,7 +13,7 @@ PlatformViewTest::PlatformViewTest() : weak_factory_(this) {} PlatformViewTest::~PlatformViewTest() = default; -base::WeakPtr PlatformViewTest::GetWeakViewPtr() { +ftl::WeakPtr PlatformViewTest::GetWeakViewPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/sky/shell/testing/platform_view_test.h b/sky/shell/testing/platform_view_test.h index b9fb13ab21b6d47f5d7bd0fb7f8cd0f4363f56ee..3dd5e019a1965cc6ff18887e1cf5fbefc880aba8 100644 --- a/sky/shell/testing/platform_view_test.h +++ b/sky/shell/testing/platform_view_test.h @@ -6,6 +6,7 @@ #define SKY_SHELL_TESTING_PLATFORM_VIEW_TEST_H_ #include "lib/ftl/macros.h" +#include "lib/ftl/memory/weak_ptr.h" #include "sky/shell/platform_view.h" namespace sky { @@ -19,7 +20,7 @@ class PlatformViewTest : public PlatformView { ~PlatformViewTest(); - base::WeakPtr GetWeakViewPtr() override; + ftl::WeakPtr GetWeakViewPtr() override; uint64_t DefaultFramebuffer() const override; @@ -30,7 +31,7 @@ class PlatformViewTest : public PlatformView { bool SwapBuffers() override; private: - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewTest); }; diff --git a/sky/shell/testing/test_runner.h b/sky/shell/testing/test_runner.h index 00d50df02e141703693ad99dd65e046baf9321ef..9258e90176adf1d28faf3a8de887c1e63404003a 100644 --- a/sky/shell/testing/test_runner.h +++ b/sky/shell/testing/test_runner.h @@ -8,8 +8,8 @@ #include #include -#include "base/macros.h" -#include "base/memory/weak_ptr.h" +#include "lib/ftl/macros.h" +#include "lib/ftl/memory/weak_ptr.h" #include "mojo/public/cpp/bindings/binding_set.h" #include "sky/services/engine/sky_engine.mojom.h" @@ -35,9 +35,9 @@ class TestRunner { std::unique_ptr platform_view_; SkyEnginePtr sky_engine_; - base::WeakPtrFactory weak_ptr_factory_; + ftl::WeakPtrFactory weak_ptr_factory_; - DISALLOW_COPY_AND_ASSIGN(TestRunner); + FTL_DISALLOW_COPY_AND_ASSIGN(TestRunner); }; } // namespace shell diff --git a/sky/shell/ui/animator.h b/sky/shell/ui/animator.h index 242b8b318a76e27c1ba58be3b783d6f9559caaf2..80e2576236372cbfc782dbeea42af259f82c9d9a 100644 --- a/sky/shell/ui/animator.h +++ b/sky/shell/ui/animator.h @@ -59,7 +59,7 @@ class Animator { base::WeakPtrFactory weak_factory_; - DISALLOW_COPY_AND_ASSIGN(Animator); + FTL_DISALLOW_COPY_AND_ASSIGN(Animator); }; } // namespace shell diff --git a/sky/shell/ui/engine.cc b/sky/shell/ui/engine.cc index c9fc7c844ba402937ae4f1b4da892055f719f252..65687326602ed4539ff71415781281263dc25dde 100644 --- a/sky/shell/ui/engine.cc +++ b/sky/shell/ui/engine.cc @@ -4,13 +4,13 @@ #include "sky/shell/ui/engine.h" -#include "base/bind.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/time/time.h" #include "base/trace_event/trace_event.h" #include "flutter/assets/directory_asset_bundle.h" #include "flutter/assets/zip_asset_bundle.h" +#include "glue/movable_wrapper.h" #include "mojo/public/cpp/application/connect.h" #include "sky/engine/bindings/mojo_services.h" #include "sky/engine/core/script/dart_init.h" @@ -47,7 +47,7 @@ Engine::Engine(const Config& config, rasterizer::RasterizerPtr rasterizer) Engine::~Engine() {} -base::WeakPtr Engine::GetWeakPtr() { +ftl::WeakPtr Engine::GetWeakPtr() { return weak_factory_.GetWeakPtr(); } @@ -101,18 +101,18 @@ void Engine::ConnectToEngine(mojo::InterfaceRequest request) { binding_.Bind(request.Pass()); } -void Engine::OnOutputSurfaceCreated(const base::Closure& gpu_continuation) { - config_.gpu_task_runner->PostTask(FROM_HERE, gpu_continuation); +void Engine::OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation) { + config_.gpu_task_runner->PostTask(gpu_continuation); have_surface_ = true; StartAnimatorIfPossible(); if (sky_view_) ScheduleFrame(); } -void Engine::OnOutputSurfaceDestroyed(const base::Closure& gpu_continuation) { +void Engine::OnOutputSurfaceDestroyed(const ftl::Closure& gpu_continuation) { have_surface_ = false; StopAnimator(); - config_.gpu_task_runner->PostTask(FROM_HERE, gpu_continuation); + config_.gpu_task_runner->PostTask(gpu_continuation); } void Engine::SetServices(ServicesDataPtr services) { @@ -259,10 +259,10 @@ void Engine::RunFromBundle(const mojo::String& script_uri, TRACE_EVENT0("flutter", "Engine::RunFromBundle"); ConfigureZipAssetBundle(path); - - root_bundle_->GetAsStream(blink::kSnapshotAssetKey, - base::Bind(&Engine::RunFromSnapshotStream, - weak_factory_.GetWeakPtr(), script_uri)); + mojo::DataPipe pipe; + asset_store_->GetAsStream(blink::kSnapshotAssetKey, + std::move(pipe.producer_handle)); + RunFromSnapshotStream(script_uri, std::move(pipe.consumer_handle)); } void Engine::RunFromBundleAndSnapshot(const mojo::String& script_uri, @@ -273,9 +273,10 @@ void Engine::RunFromBundleAndSnapshot(const mojo::String& script_uri, ConfigureZipAssetBundle(bundle_path); asset_store_->AddOverlayFile(blink::kSnapshotAssetKey, snapshot_path); - root_bundle_->GetAsStream(blink::kSnapshotAssetKey, - base::Bind(&Engine::RunFromSnapshotStream, - weak_factory_.GetWeakPtr(), script_uri)); + mojo::DataPipe pipe; + asset_store_->GetAsStream(blink::kSnapshotAssetKey, + std::move(pipe.producer_handle)); + RunFromSnapshotStream(script_uri, std::move(pipe.consumer_handle)); } void Engine::PushRoute(const mojo::String& route) { @@ -322,15 +323,15 @@ void Engine::DidCreateMainIsolate(Dart_Isolate isolate) { void Engine::DidCreateSecondaryIsolate(Dart_Isolate isolate) { mojo::ServiceProviderPtr services_from_embedder; - mojo::InterfaceRequest request = - mojo::GetProxy(&services_from_embedder); - base::Closure closure = - base::Bind(&Engine::BindToServiceProvider, weak_factory_.GetWeakPtr(), - base::Passed(&request)); + auto request = glue::WrapMovable(mojo::GetProxy(&services_from_embedder)); + ftl::WeakPtr engine = weak_factory_.GetWeakPtr(); blink::Platform::current()->GetUITaskRunner()->PostTask( - [closure]() { closure.Run(); }); - blink::MojoServices::Create(isolate, nullptr, services_from_embedder.Pass(), - nullptr); + [engine, request]() mutable { + if (engine) + engine->BindToServiceProvider(request.Unwrap()); + }); + blink::MojoServices::Create(isolate, nullptr, + std::move(services_from_embedder), nullptr); } void Engine::BindToServiceProvider( diff --git a/sky/shell/ui/engine.h b/sky/shell/ui/engine.h index b7878ea7606821d38a0366634d473369eb2dd209..6cb56e813a103f526f2c8c20e13c7977c3d04acc 100644 --- a/sky/shell/ui/engine.h +++ b/sky/shell/ui/engine.h @@ -6,13 +6,13 @@ #define SKY_SHELL_UI_ENGINE_H_ #include "base/files/file_path.h" -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "base/single_thread_task_runner.h" #include "flutter/assets/zip_asset_store.h" +#include "lib/ftl/macros.h" +#include "lib/ftl/memory/weak_ptr.h" +#include "lib/ftl/tasks/task_runner.h" #include "mojo/public/cpp/application/service_provider_impl.h" -#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding_set.h" +#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/handle.h" #include "mojo/public/interfaces/application/service_provider.mojom.h" @@ -38,13 +38,13 @@ class Engine : public UIDelegate, Config(); ~Config(); - scoped_refptr gpu_task_runner; + ftl::RefPtr gpu_task_runner; }; explicit Engine(const Config& config, rasterizer::RasterizerPtr rasterizer); ~Engine() override; - base::WeakPtr GetWeakPtr(); + ftl::WeakPtr GetWeakPtr(); static void Init(); @@ -59,8 +59,8 @@ class Engine : public UIDelegate, private: // UIDelegate implementation: void ConnectToEngine(mojo::InterfaceRequest request) override; - void OnOutputSurfaceCreated(const base::Closure& gpu_continuation) override; - void OnOutputSurfaceDestroyed(const base::Closure& gpu_continuation) override; + void OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation) override; + void OnOutputSurfaceDestroyed(const ftl::Closure& gpu_continuation) override; // SkyEngine implementation: void SetServices(ServicesDataPtr services) override; @@ -127,9 +127,9 @@ class Engine : public UIDelegate, bool activity_running_; bool have_surface_; - base::WeakPtrFactory weak_factory_; + ftl::WeakPtrFactory weak_factory_; - DISALLOW_COPY_AND_ASSIGN(Engine); + FTL_DISALLOW_COPY_AND_ASSIGN(Engine); }; } // namespace shell diff --git a/sky/shell/ui_delegate.h b/sky/shell/ui_delegate.h index 5ee3c99dab77e3597ab62fea3e4f8015ae64270f..7d14b5f59214b3dd035493ca16b74b9ade6c2f44 100644 --- a/sky/shell/ui_delegate.h +++ b/sky/shell/ui_delegate.h @@ -5,9 +5,9 @@ #ifndef SKY_SHELL_UI_DELEGATE_H_ #define SKY_SHELL_UI_DELEGATE_H_ +#include "lib/ftl/functional/closure.h" #include "mojo/public/cpp/bindings/interface_request.h" #include "sky/services/engine/sky_engine.mojom.h" -#include "base/callback.h" namespace sky { namespace shell { @@ -16,11 +16,10 @@ class UIDelegate { public: virtual void ConnectToEngine(mojo::InterfaceRequest request) = 0; - virtual void OnOutputSurfaceCreated( - const base::Closure& gpu_continuation) = 0; + virtual void OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation) = 0; virtual void OnOutputSurfaceDestroyed( - const base::Closure& gpu_continuation) = 0; + const ftl::Closure& gpu_continuation) = 0; protected: virtual ~UIDelegate();