diff --git a/fml/BUILD.gn b/fml/BUILD.gn index ab34374913705e332a605a85b8f0fac0cfad5990..e81ed4f1683a34b908e4ccf4598fc98dbe169e3e 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -8,6 +8,9 @@ source_set("fml") { "icu_util.h", "mapping.cc", "mapping.h", + "memory/weak_ptr.h", + "memory/weak_ptr_internal.cc", + "memory/weak_ptr_internal.h", "message_loop.cc", "message_loop.h", "message_loop_impl.cc", @@ -24,8 +27,8 @@ source_set("fml") { ] deps = [ - "//third_party/dart/runtime:dart_api", "//garnet/public/lib/fxl", + "//third_party/dart/runtime:dart_api", # These need to be in sync with the Fuchsia buildroot. "//third_party/icu", @@ -33,9 +36,7 @@ source_set("fml") { configs += [ "//third_party/icu:icu_config" ] - public_configs = [ - "$flutter_root:config", - ] + public_configs = [ "$flutter_root:config" ] libs = [] @@ -108,15 +109,16 @@ executable("fml_unittests") { testonly = true sources = [ + "memory/weak_ptr_unittest.cc", "message_loop_unittests.cc", "thread_local_unittests.cc", "thread_unittests.cc", ] deps = [ - "//third_party/dart/runtime:libdart_jit", "$flutter_root/fml", "$flutter_root/testing", "//garnet/public/lib/fxl", + "//third_party/dart/runtime:libdart_jit", ] } diff --git a/fml/memory/weak_ptr.h b/fml/memory/weak_ptr.h new file mode 100644 index 0000000000000000000000000000000000000000..5b85c531966b20bb02adc99acea1d5e54e521788 --- /dev/null +++ b/fml/memory/weak_ptr.h @@ -0,0 +1,178 @@ +// Copyright 2016 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file provides weak pointers and weak pointer factories that work like +// Chromium's |base::WeakPtr| and |base::WeakPtrFactory|. + +#ifndef FLUTTER_FML_MEMORY_WEAK_PTR_H_ +#define FLUTTER_FML_MEMORY_WEAK_PTR_H_ + +#include + +#include "flutter/fml/memory/weak_ptr_internal.h" +#include "lib/fxl/logging.h" +#include "lib/fxl/memory/ref_counted.h" + +namespace fml { + +// Forward declaration, so |WeakPtr| can friend it. +template +class WeakPtrFactory; + +// Class for "weak pointers" that can be invalidated. Valid weak pointers can +// only originate from a |WeakPtrFactory| (see below), though weak pointers are +// copyable and movable. +// +// Weak pointers are not in general thread-safe. They may only be *used* on a +// single thread, namely the same thread as the "originating" |WeakPtrFactory| +// (which can invalidate the weak pointers that it generates). +// +// However, weak pointers may be passed to other threads, reset on other +// threads, or destroyed on other threads. They may also be reassigned on other +// threads (in which case they should then only be used on the thread +// corresponding to the new "originating" |WeakPtrFactory|). +template +class WeakPtr { + public: + WeakPtr() : ptr_(nullptr) {} + + // Copy constructor. + WeakPtr(const WeakPtr& r) = default; + + template + WeakPtr(const WeakPtr& r) : ptr_(r.ptr_), flag_(r.flag_) {} + + // Move constructor. + WeakPtr(WeakPtr&& r) = default; + + template + WeakPtr(WeakPtr&& r) : ptr_(r.ptr_), flag_(std::move(r.flag_)) {} + + ~WeakPtr() = default; + + // The following methods are thread-friendly, in the sense that they may be + // called subject to additional synchronization. + + // Copy assignment. + WeakPtr& operator=(const WeakPtr& r) = default; + + // Move assignment. + WeakPtr& operator=(WeakPtr&& r) = default; + + void reset() { flag_ = nullptr; } + + // The following methods should only be called on the same thread as the + // "originating" |WeakPtrFactory|. + + explicit operator bool() const { return flag_ && flag_->is_valid(); } + + T* get() const { return *this ? ptr_ : nullptr; } + + T& operator*() const { + FXL_DCHECK(*this); + return *get(); + } + + T* operator->() const { + FXL_DCHECK(*this); + return get(); + } + + private: + template + friend class WeakPtr; + + friend class WeakPtrFactory; + + explicit WeakPtr(T* ptr, fxl::RefPtr&& flag) + : ptr_(ptr), flag_(std::move(flag)) {} + + T* ptr_; + fxl::RefPtr flag_; + + // Copy/move construction/assignment supported. +}; + +// Class that produces (valid) |WeakPtr|s. Typically, this is used as a +// member variable of |T| (preferably the last one -- see below), and |T|'s +// methods control how weak pointers to it are vended. This class is not +// thread-safe, and should only be created, destroyed and used on a single +// thread. +// +// Example: +// +// class Controller { +// public: +// Controller() : ..., weak_factory_(this) {} +// ... +// +// void SpawnWorker() { Worker::StartNew(weak_factory_.GetWeakPtr()); } +// void WorkComplete(const Result& result) { ... } +// +// private: +// ... +// +// // Member variables should appear before the |WeakPtrFactory|, to ensure +// // that any |WeakPtr|s to |Controller| are invalidated before its member +// // variables' destructors are executed. +// WeakPtrFactory weak_factory_; +// }; +// +// class Worker { +// public: +// static void StartNew(const WeakPtr& controller) { +// Worker* worker = new Worker(controller); +// // Kick off asynchronous processing.... +// } +// +// private: +// Worker(const WeakPtr& controller) : controller_(controller) {} +// +// void DidCompleteAsynchronousProcessing(const Result& result) { +// if (controller_) +// controller_->WorkComplete(result); +// } +// +// WeakPtr controller_; +// }; +template +class WeakPtrFactory { + public: + explicit WeakPtrFactory(T* ptr) : ptr_(ptr) { FXL_DCHECK(ptr_); } + ~WeakPtrFactory() { InvalidateWeakPtrs(); } + + // Gets a new weak pointer, which will be valid until either + // |InvalidateWeakPtrs()| is called or this object is destroyed. + WeakPtr GetWeakPtr() { + if (!flag_) + flag_ = fxl::MakeRefCounted(); + return WeakPtr(ptr_, flag_.Clone()); + } + + // Call this method to invalidate all existing weak pointers. (Note that + // additional weak pointers can be produced even after this is called.) + void InvalidateWeakPtrs() { + if (!flag_) + return; + flag_->Invalidate(); + flag_ = nullptr; + } + + // Call this method to determine if any weak pointers exist. (Note that a + // "false" result is definitive, but a "true" result may not be if weak + // pointers are held/reset/destroyed/reassigned on other threads.) + bool HasWeakPtrs() const { return flag_ && !flag_->HasOneRef(); } + + private: + // Note: See weak_ptr_internal.h for an explanation of why we store the + // pointer here, instead of in the "flag". + T* const ptr_; + fxl::RefPtr flag_; + + FXL_DISALLOW_COPY_AND_ASSIGN(WeakPtrFactory); +}; + +} // namespace fml + +#endif // FLUTTER_FML_MEMORY_WEAK_PTR_H_ diff --git a/fml/memory/weak_ptr_internal.cc b/fml/memory/weak_ptr_internal.cc new file mode 100644 index 0000000000000000000000000000000000000000..e5379cbd3d0fd631fe2d1f71e0820056b3a510a4 --- /dev/null +++ b/fml/memory/weak_ptr_internal.cc @@ -0,0 +1,26 @@ +// Copyright 2016 The Fuchsia 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/memory/weak_ptr_internal.h" + +#include "lib/fxl/logging.h" + +namespace fml { +namespace internal { + +WeakPtrFlag::WeakPtrFlag() : is_valid_(true) {} + +WeakPtrFlag::~WeakPtrFlag() { + // Should be invalidated before destruction. + FXL_DCHECK(!is_valid_); +} + +void WeakPtrFlag::Invalidate() { + // Invalidation should happen exactly once. + FXL_DCHECK(is_valid_); + is_valid_ = false; +} + +} // namespace internal +} // namespace fml diff --git a/fml/memory/weak_ptr_internal.h b/fml/memory/weak_ptr_internal.h new file mode 100644 index 0000000000000000000000000000000000000000..570bd90ddf20e5fa67e4fbe8c37672291ef4b150 --- /dev/null +++ b/fml/memory/weak_ptr_internal.h @@ -0,0 +1,41 @@ +// Copyright 2016 The Fuchsia 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_MEMORY_WEAK_PTR_INTERNAL_H_ +#define FLUTTER_FML_MEMORY_WEAK_PTR_INTERNAL_H_ + +#include "lib/fxl/macros.h" +#include "lib/fxl/memory/ref_counted.h" + +namespace fml { +namespace internal { + +// |WeakPtr|s have a reference to a |WeakPtrFlag| to determine whether they +// are valid (non-null) or not. We do not store a |T*| in this object since +// there may also be |WeakPtr|s to the same object, where |U| is a superclass +// of |T|. +// +// This class in not thread-safe, though references may be released on any +// thread (allowing weak pointers to be destroyed/reset/reassigned on any +// thread). +class FXL_EXPORT WeakPtrFlag : public fxl::RefCountedThreadSafe { + public: + WeakPtrFlag(); + + ~WeakPtrFlag(); + + bool is_valid() const { return is_valid_; } + + void Invalidate(); + + private: + bool is_valid_; + + FXL_DISALLOW_COPY_AND_ASSIGN(WeakPtrFlag); +}; + +} // namespace internal +} // namespace fml + +#endif // FLUTTER_FML_MEMORY_WEAK_PTR_INTERNAL_H_ diff --git a/fml/memory/weak_ptr_unittest.cc b/fml/memory/weak_ptr_unittest.cc new file mode 100644 index 0000000000000000000000000000000000000000..2b6dbd035e78cae349f20096393cac0fa759ff45 --- /dev/null +++ b/fml/memory/weak_ptr_unittest.cc @@ -0,0 +1,197 @@ +// Copyright 2016 The Fuchsia 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/memory/weak_ptr.h" + +#include + +#include "gtest/gtest.h" + +namespace fml { +namespace { + +TEST(WeakPtrTest, Basic) { + int data = 0; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + EXPECT_EQ(&data, ptr.get()); +} + +TEST(WeakPtrTest, CopyConstruction) { + int data = 0; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + WeakPtr ptr2(ptr); + EXPECT_EQ(&data, ptr.get()); + EXPECT_EQ(&data, ptr2.get()); +} + +TEST(WeakPtrTest, MoveConstruction) { + int data = 0; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + WeakPtr ptr2(std::move(ptr)); + EXPECT_EQ(nullptr, ptr.get()); + EXPECT_EQ(&data, ptr2.get()); +} + +TEST(WeakPtrTest, CopyAssignment) { + int data = 0; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + WeakPtr ptr2; + EXPECT_EQ(nullptr, ptr2.get()); + ptr2 = ptr; + EXPECT_EQ(&data, ptr.get()); + EXPECT_EQ(&data, ptr2.get()); +} + +TEST(WeakPtrTest, MoveAssignment) { + int data = 0; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + WeakPtr ptr2; + EXPECT_EQ(nullptr, ptr2.get()); + ptr2 = std::move(ptr); + EXPECT_EQ(nullptr, ptr.get()); + EXPECT_EQ(&data, ptr2.get()); +} + +TEST(WeakPtrTest, Testable) { + int data = 0; + WeakPtrFactory factory(&data); + WeakPtr ptr; + EXPECT_EQ(nullptr, ptr.get()); + EXPECT_FALSE(ptr); + ptr = factory.GetWeakPtr(); + EXPECT_EQ(&data, ptr.get()); + EXPECT_TRUE(ptr); +} + +TEST(WeakPtrTest, OutOfScope) { + WeakPtr ptr; + EXPECT_EQ(nullptr, ptr.get()); + { + int data = 0; + WeakPtrFactory factory(&data); + ptr = factory.GetWeakPtr(); + } + EXPECT_EQ(nullptr, ptr.get()); +} + +TEST(WeakPtrTest, Multiple) { + WeakPtr a; + WeakPtr b; + { + int data = 0; + WeakPtrFactory factory(&data); + a = factory.GetWeakPtr(); + b = factory.GetWeakPtr(); + EXPECT_EQ(&data, a.get()); + EXPECT_EQ(&data, b.get()); + } + EXPECT_EQ(nullptr, a.get()); + EXPECT_EQ(nullptr, b.get()); +} + +TEST(WeakPtrTest, MultipleStaged) { + WeakPtr a; + { + int data = 0; + WeakPtrFactory factory(&data); + a = factory.GetWeakPtr(); + { WeakPtr b = factory.GetWeakPtr(); } + EXPECT_NE(a.get(), nullptr); + } + EXPECT_EQ(nullptr, a.get()); +} + +struct Base { + double member = 0.; +}; +struct Derived : public Base {}; + +TEST(WeakPtrTest, Dereference) { + Base data; + data.member = 123456.; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + EXPECT_EQ(&data, ptr.get()); + EXPECT_EQ(data.member, (*ptr).member); + EXPECT_EQ(data.member, ptr->member); +} + +TEST(WeakPtrTest, UpcastCopyConstruction) { + Derived data; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + WeakPtr ptr2(ptr); + EXPECT_EQ(&data, ptr.get()); + EXPECT_EQ(&data, ptr2.get()); +} + +TEST(WeakPtrTest, UpcastMoveConstruction) { + Derived data; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + WeakPtr ptr2(std::move(ptr)); + EXPECT_EQ(nullptr, ptr.get()); + EXPECT_EQ(&data, ptr2.get()); +} + +TEST(WeakPtrTest, UpcastCopyAssignment) { + Derived data; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + WeakPtr ptr2; + EXPECT_EQ(nullptr, ptr2.get()); + ptr2 = ptr; + EXPECT_EQ(&data, ptr.get()); + EXPECT_EQ(&data, ptr2.get()); +} + +TEST(WeakPtrTest, UpcastMoveAssignment) { + Derived data; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + WeakPtr ptr2; + EXPECT_EQ(nullptr, ptr2.get()); + ptr2 = std::move(ptr); + EXPECT_EQ(nullptr, ptr.get()); + EXPECT_EQ(&data, ptr2.get()); +} + +TEST(WeakPtrTest, InvalidateWeakPtrs) { + int data = 0; + WeakPtrFactory factory(&data); + WeakPtr ptr = factory.GetWeakPtr(); + EXPECT_EQ(&data, ptr.get()); + EXPECT_TRUE(factory.HasWeakPtrs()); + factory.InvalidateWeakPtrs(); + EXPECT_EQ(nullptr, ptr.get()); + EXPECT_FALSE(factory.HasWeakPtrs()); + + // Test that the factory can create new weak pointers after a + // |InvalidateWeakPtrs()| call, and that they remain valid until the next + // |InvalidateWeakPtrs()| call. + WeakPtr ptr2 = factory.GetWeakPtr(); + EXPECT_EQ(&data, ptr2.get()); + EXPECT_TRUE(factory.HasWeakPtrs()); + factory.InvalidateWeakPtrs(); + EXPECT_EQ(nullptr, ptr2.get()); + EXPECT_FALSE(factory.HasWeakPtrs()); +} + +TEST(WeakPtrTest, HasWeakPtrs) { + int data = 0; + WeakPtrFactory factory(&data); + { + WeakPtr ptr = factory.GetWeakPtr(); + EXPECT_TRUE(factory.HasWeakPtrs()); + } + EXPECT_FALSE(factory.HasWeakPtrs()); +} + +} // namespace +} // namespace fml diff --git a/shell/common/animator.cc b/shell/common/animator.cc index 2602ae7b848fbe4e65dc0fa83a617164a3003a7c..ce6988f65df826ea8f265991186a1bdad9781daa 100644 --- a/shell/common/animator.cc +++ b/shell/common/animator.cc @@ -11,7 +11,7 @@ namespace shell { -Animator::Animator(fxl::WeakPtr rasterizer, +Animator::Animator(fml::WeakPtr rasterizer, VsyncWaiter* waiter, Engine* engine) : rasterizer_(rasterizer), diff --git a/shell/common/animator.h b/shell/common/animator.h index 42d53299e2dcac6dfeee3a33e223b15d30ec3316..7074864d64aa62a0136a8083a6cf01f271ea05d4 100644 --- a/shell/common/animator.h +++ b/shell/common/animator.h @@ -18,13 +18,13 @@ namespace shell { class Animator { public: - Animator(fxl::WeakPtr rasterizer, + Animator(fml::WeakPtr rasterizer, VsyncWaiter* waiter, Engine* engine); ~Animator(); - void set_rasterizer(fxl::WeakPtr rasterizer) { + void set_rasterizer(fml::WeakPtr rasterizer) { rasterizer_ = rasterizer; } @@ -46,7 +46,7 @@ class Animator { const char* FrameParity(); - fxl::WeakPtr rasterizer_; + fml::WeakPtr rasterizer_; VsyncWaiter* waiter_; Engine* engine_; @@ -59,7 +59,7 @@ class Animator { bool paused_; bool frame_scheduled_; - fxl::WeakPtrFactory weak_factory_; + fml::WeakPtrFactory weak_factory_; FXL_DISALLOW_COPY_AND_ASSIGN(Animator); }; diff --git a/shell/common/engine.cc b/shell/common/engine.cc index ee3941ba22367ce505ef983ac042f8c563d34ed1..91a9009729112414d784927d1ac42495636fe771 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -82,11 +82,11 @@ Engine::Engine(PlatformView* platform_view) Engine::~Engine() {} -void Engine::set_rasterizer(fxl::WeakPtr rasterizer) { +void Engine::set_rasterizer(fml::WeakPtr rasterizer) { animator_->set_rasterizer(rasterizer); } -fxl::WeakPtr Engine::GetWeakPtr() { +fml::WeakPtr Engine::GetWeakPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/shell/common/engine.h b/shell/common/engine.h index 5ce57e8f371c669be43d25319bb8c7f007ebffd2..8568a22a475d657d353c7ebc40f5864aad829558 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -31,7 +31,7 @@ class Engine : public blink::RuntimeDelegate { ~Engine() override; - fxl::WeakPtr GetWeakPtr(); + fml::WeakPtr GetWeakPtr(); static void Init(const std::string& bundle_path); @@ -75,7 +75,7 @@ class Engine : public blink::RuntimeDelegate { void DispatchSemanticsAction(int id, blink::SemanticsAction action); void SetSemanticsEnabled(bool enabled); - void set_rasterizer(fxl::WeakPtr rasterizer); + void set_rasterizer(fml::WeakPtr rasterizer); private: // RuntimeDelegate methods: @@ -122,7 +122,7 @@ class Engine : public blink::RuntimeDelegate { // TODO(eseidel): This should move into an AnimatorStateMachine. bool activity_running_; bool have_surface_; - fxl::WeakPtrFactory weak_factory_; + fml::WeakPtrFactory weak_factory_; FXL_DISALLOW_COPY_AND_ASSIGN(Engine); }; diff --git a/shell/common/null_rasterizer.cc b/shell/common/null_rasterizer.cc index 80c60638fc0f03e91726ad7295a0867dd733cfab..f774208ff2a9bad25c274487623dcbcf046a2017 100644 --- a/shell/common/null_rasterizer.cc +++ b/shell/common/null_rasterizer.cc @@ -25,7 +25,7 @@ void NullRasterizer::Teardown( teardown_completion_event->Signal(); } -fxl::WeakPtr NullRasterizer::GetWeakRasterizerPtr() { +fml::WeakPtr NullRasterizer::GetWeakRasterizerPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/shell/common/null_rasterizer.h b/shell/common/null_rasterizer.h index 43e4edb6f2297e8df88f4e89d09ab6a475f4b5bf..a5fee836c27d92cb3bb53e2b36b206ae9228d017 100644 --- a/shell/common/null_rasterizer.h +++ b/shell/common/null_rasterizer.h @@ -24,7 +24,7 @@ class NullRasterizer : public Rasterizer { void Clear(SkColor color, const SkISize& size) override; - fxl::WeakPtr GetWeakRasterizerPtr() override; + fml::WeakPtr GetWeakRasterizerPtr() override; flow::LayerTree* GetLastLayerTree() override; @@ -34,7 +34,7 @@ class NullRasterizer : public Rasterizer { private: std::unique_ptr surface_; - fxl::WeakPtrFactory weak_factory_; + fml::WeakPtrFactory weak_factory_; FXL_DISALLOW_COPY_AND_ASSIGN(NullRasterizer); }; diff --git a/shell/common/platform_view_service_protocol.cc b/shell/common/platform_view_service_protocol.cc index 8a076bbf3fe001bb2125b6b39837365b52bc7617..9f04656573ad4529a8ac24bfd66868f752fbd3c4 100644 --- a/shell/common/platform_view_service_protocol.cc +++ b/shell/common/platform_view_service_protocol.cc @@ -250,8 +250,8 @@ static sk_sp EncodeBitmapAsPNG(const SkBitmap& bitmap) { return data; } -static fxl::WeakPtr GetRandomRasterizer() { - fxl::WeakPtr rasterizer; +static fml::WeakPtr GetRandomRasterizer() { + fml::WeakPtr rasterizer; Shell::Shared().IteratePlatformViews( [&rasterizer](PlatformView* view) -> bool { rasterizer = view->rasterizer().GetWeakRasterizerPtr(); diff --git a/shell/common/rasterizer.h b/shell/common/rasterizer.h index 6739df7098ebba5d91ceb324495f43f56339db37..0a588710469881707f8effd9c9848a0efba6165a 100644 --- a/shell/common/rasterizer.h +++ b/shell/common/rasterizer.h @@ -8,10 +8,10 @@ #include #include "flutter/flow/layers/layer_tree.h" +#include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/surface.h" #include "flutter/synchronization/pipeline.h" #include "lib/fxl/functional/closure.h" -#include "lib/fxl/memory/weak_ptr.h" #include "lib/fxl/synchronization/waitable_event.h" namespace shell { @@ -29,7 +29,7 @@ class Rasterizer { virtual void Clear(SkColor color, const SkISize& size) = 0; - virtual fxl::WeakPtr GetWeakRasterizerPtr() = 0; + virtual fml::WeakPtr GetWeakRasterizerPtr() = 0; virtual flow::LayerTree* GetLastLayerTree() = 0; diff --git a/shell/common/vsync_waiter_fallback.h b/shell/common/vsync_waiter_fallback.h index 345c328553b656da8c43556bbda4bd5eaa3e7580..bfb7e118b1330875bff2bd4967c38b3464abb6cd 100644 --- a/shell/common/vsync_waiter_fallback.h +++ b/shell/common/vsync_waiter_fallback.h @@ -5,9 +5,9 @@ #ifndef FLUTTER_SHELL_COMMON_VSYNC_WAITER_FALLBACK_H_ #define FLUTTER_SHELL_COMMON_VSYNC_WAITER_FALLBACK_H_ +#include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/vsync_waiter.h" #include "lib/fxl/macros.h" -#include "lib/fxl/memory/weak_ptr.h" #include "lib/fxl/time/time_point.h" namespace shell { @@ -23,7 +23,7 @@ class VsyncWaiterFallback : public VsyncWaiter { fxl::TimePoint phase_; Callback callback_; - fxl::WeakPtrFactory weak_factory_; + fml::WeakPtrFactory weak_factory_; FXL_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterFallback); }; diff --git a/shell/gpu/BUILD.gn b/shell/gpu/BUILD.gn index 6cb36faac8b46072a264fae190c14955d9559fcb..4547965e18e00e681931012226013fde5f9d6b26 100644 --- a/shell/gpu/BUILD.gn +++ b/shell/gpu/BUILD.gn @@ -27,14 +27,13 @@ source_set("gpu") { "$flutter_root/glue", "$flutter_root/shell/common", "$flutter_root/synchronization", + "//flutter/fml", "//garnet/public/lib/fxl", "//third_party/skia", "//third_party/skia:gpu", ] - public_configs = [ - "$flutter_root:config", - ] + public_configs = [ "$flutter_root:config" ] if (shell_enable_vulkan) { deps += [ "$flutter_root/vulkan" ] diff --git a/shell/gpu/gpu_rasterizer.cc b/shell/gpu/gpu_rasterizer.cc index 49083c1ff01ca17f9fe55ca62b1377d7d60cd131..4abe1e63f74d8bac520edd1afa82e085c2553e09 100644 --- a/shell/gpu/gpu_rasterizer.cc +++ b/shell/gpu/gpu_rasterizer.cc @@ -21,7 +21,7 @@ GPURasterizer::GPURasterizer(std::unique_ptr info) GPURasterizer::~GPURasterizer() = default; -fxl::WeakPtr GPURasterizer::GetWeakRasterizerPtr() { +fml::WeakPtr GPURasterizer::GetWeakRasterizerPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/shell/gpu/gpu_rasterizer.h b/shell/gpu/gpu_rasterizer.h index 61942e003c59ecad605123dc9ad56c1e03a3c4f8..b2a3e43ca3d2dfe0d869a9de6d3325af330c1fd1 100644 --- a/shell/gpu/gpu_rasterizer.h +++ b/shell/gpu/gpu_rasterizer.h @@ -29,7 +29,7 @@ class GPURasterizer : public Rasterizer { void Teardown( fxl::AutoResetWaitableEvent* teardown_completion_event) override; - fxl::WeakPtr GetWeakRasterizerPtr() override; + fml::WeakPtr GetWeakRasterizerPtr() override; flow::LayerTree* GetLastLayerTree() override; @@ -46,7 +46,7 @@ class GPURasterizer : public Rasterizer { // next time. NULL if there is no callback or the callback was set back to // NULL after being called. fxl::Closure nextFrameCallback_; - fxl::WeakPtrFactory weak_factory_; + fml::WeakPtrFactory weak_factory_; void DoDraw(std::unique_ptr layer_tree); diff --git a/shell/gpu/gpu_surface_gl.h b/shell/gpu/gpu_surface_gl.h index d3b6a9bf5f2f6fe5116608594391828f8aca78ee..3938a0845ab48a0c7a1bdb241ce55e87dfd5c14e 100644 --- a/shell/gpu/gpu_surface_gl.h +++ b/shell/gpu/gpu_surface_gl.h @@ -5,10 +5,10 @@ #ifndef SHELL_GPU_GPU_SURFACE_GL_H_ #define SHELL_GPU_GPU_SURFACE_GL_H_ +#include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/surface.h" #include "flutter/synchronization/debug_thread_checker.h" #include "lib/fxl/macros.h" -#include "lib/fxl/memory/weak_ptr.h" #include "third_party/skia/include/gpu/GrContext.h" namespace shell { @@ -44,7 +44,7 @@ class GPUSurfaceGL : public Surface { sk_sp onscreen_surface_; sk_sp offscreen_surface_; bool valid_ = false; - fxl::WeakPtrFactory weak_factory_; + fml::WeakPtrFactory weak_factory_; bool CreateOrUpdateSurfaces(const SkISize& size); diff --git a/shell/gpu/gpu_surface_software.h b/shell/gpu/gpu_surface_software.h index 557742558efb10fe637f169cd1e7c2e3bc1aac03..f7312153db8bcaf7b9fe36f66727c05b1fc1d85e 100644 --- a/shell/gpu/gpu_surface_software.h +++ b/shell/gpu/gpu_surface_software.h @@ -5,9 +5,9 @@ #ifndef FLUTTER_SHELL_GPU_GPU_SURFACE_SOFTWARE_H_ #define FLUTTER_SHELL_GPU_GPU_SURFACE_SOFTWARE_H_ +#include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/surface.h" #include "lib/fxl/macros.h" -#include "lib/fxl/memory/weak_ptr.h" #include "third_party/skia/include/core/SkSurface.h" namespace shell { @@ -35,7 +35,7 @@ class GPUSurfaceSoftware : public Surface { private: GPUSurfaceSoftwareDelegate* delegate_; - fxl::WeakPtrFactory weak_factory_; + fml::WeakPtrFactory weak_factory_; FXL_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceSoftware); }; diff --git a/shell/gpu/gpu_surface_vulkan.h b/shell/gpu/gpu_surface_vulkan.h index d88dbdee34d0700abc1d0ee43cd679fdca9b59f2..eafed43a6296d91fe7a640cae61cfd319caad64c 100644 --- a/shell/gpu/gpu_surface_vulkan.h +++ b/shell/gpu/gpu_surface_vulkan.h @@ -6,11 +6,11 @@ #define SHELL_GPU_GPU_SURFACE_VULKAN_H_ #include +#include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/surface.h" #include "flutter/vulkan/vulkan_native_surface.h" #include "flutter/vulkan/vulkan_window.h" #include "lib/fxl/macros.h" -#include "lib/fxl/memory/weak_ptr.h" namespace shell { @@ -29,7 +29,7 @@ class GPUSurfaceVulkan : public Surface { private: vulkan::VulkanWindow window_; - fxl::WeakPtrFactory weak_factory_; + fml::WeakPtrFactory weak_factory_; FXL_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceVulkan); }; diff --git a/shell/platform/android/vsync_waiter_android.cc b/shell/platform/android/vsync_waiter_android.cc index 2b316cd556233f5c8c9ba51560eb29437edb51dd..29e1958dcc011d7e2496d9642436a4dcfe1c8565 100644 --- a/shell/platform/android/vsync_waiter_android.cc +++ b/shell/platform/android/vsync_waiter_android.cc @@ -26,8 +26,8 @@ VsyncWaiterAndroid::~VsyncWaiterAndroid() = default; void VsyncWaiterAndroid::AsyncWaitForVsync(Callback callback) { FXL_DCHECK(!callback_); callback_ = std::move(callback); - fxl::WeakPtr* weak = - new fxl::WeakPtr(); + fml::WeakPtr* weak = + new fml::WeakPtr(); *weak = weak_factory_.GetWeakPtr(); blink::Threads::Platform()->PostTask([weak] { @@ -70,8 +70,8 @@ static void OnNativeVsync(JNIEnv* env, TRACE_EVENT2("flutter", "VSYNC", "mode", "basic", "deadline", deadline); } #endif - fxl::WeakPtr* weak = - reinterpret_cast*>(cookie); + fml::WeakPtr* weak = + reinterpret_cast*>(cookie); VsyncWaiterAndroid* waiter = weak->get(); delete weak; if (waiter) { diff --git a/shell/platform/android/vsync_waiter_android.h b/shell/platform/android/vsync_waiter_android.h index 8b272c6b18778b488ea3973095ca5385fe3fbdae..c73af4bfca6f0764ee2d0d5169fadc9c67cf2ff3 100644 --- a/shell/platform/android/vsync_waiter_android.h +++ b/shell/platform/android/vsync_waiter_android.h @@ -6,9 +6,9 @@ #define SHELL_PLATFORM_ANDROID_VSYNC_WAITER_ANDROID_H_ #include +#include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/vsync_waiter.h" #include "lib/fxl/macros.h" -#include "lib/fxl/memory/weak_ptr.h" namespace shell { @@ -26,9 +26,8 @@ class VsyncWaiterAndroid : public VsyncWaiter { private: Callback callback_; - fxl::WeakPtr self_; - - fxl::WeakPtrFactory weak_factory_; + fml::WeakPtr self_; + fml::WeakPtrFactory weak_factory_; FXL_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterAndroid); }; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index db6812f5f04e34d5e627d36740fc868b895022e0..7c382838c6f5ce77c0ef0125830d1f7c5872ad07 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -44,7 +44,7 @@ return YES; } -void SnapshotRasterizer(fxl::WeakPtr rasterizer, +void SnapshotRasterizer(fml::WeakPtr rasterizer, CGContextRef context, bool is_opaque) { if (!rasterizer) { @@ -89,8 +89,8 @@ void SnapshotRasterizer(fxl::WeakPtr rasterizer, SkCGDrawBitmap(context, bitmap, 0, 0); } -static fxl::WeakPtr GetRandomRasterizer() { - fxl::WeakPtr rasterizer; +static fml::WeakPtr GetRandomRasterizer() { + fml::WeakPtr rasterizer; shell::Shell::Shared().IteratePlatformViews([&rasterizer](shell::PlatformView* view) -> bool { rasterizer = view->rasterizer().GetWeakRasterizerPtr(); // We just grab the first rasterizer so there is no need to iterate diff --git a/shell/platform/darwin/ios/platform_view_ios.h b/shell/platform/darwin/ios/platform_view_ios.h index 0b4bc9d9ecad71d85cd26bb1b6b7c84322f2cb99..f9c6cafacc9e793842b8b3f3515abb7b0afd219b 100644 --- a/shell/platform/darwin/ios/platform_view_ios.h +++ b/shell/platform/darwin/ios/platform_view_ios.h @@ -7,13 +7,13 @@ #include +#include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/platform_view.h" #include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h" #include "flutter/shell/platform/darwin/ios/framework/Source/platform_message_router.h" #include "flutter/shell/platform/darwin/ios/ios_surface.h" #include "lib/fxl/functional/closure.h" #include "lib/fxl/macros.h" -#include "lib/fxl/memory/weak_ptr.h" @class CALayer; @class UIView; @@ -39,7 +39,7 @@ class PlatformViewIOS : public PlatformView { return platform_message_router_; } - fxl::WeakPtr GetWeakPtr(); + fml::WeakPtr GetWeakPtr(); void UpdateSurfaceSize(); @@ -65,7 +65,7 @@ class PlatformViewIOS : public PlatformView { PlatformMessageRouter platform_message_router_; std::unique_ptr accessibility_bridge_; fxl::Closure firstFrameCallback_; - fxl::WeakPtrFactory weak_factory_; + fml::WeakPtrFactory weak_factory_; NSObject* binary_messenger_; void SetupAndLoadFromSource(const std::string& assets_directory, diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index ba0e87577f82061926554ec434e07e8871cd5d9d..fa1871816cdc15f428761f4cc5df5d67c9b14230 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/shell/platform/darwin/ios/platform_view_ios.mm @@ -68,7 +68,7 @@ void PlatformViewIOS::SetupAndLoadFromSource(const std::string& assets_directory }); } -fxl::WeakPtr PlatformViewIOS::GetWeakPtr() { +fml::WeakPtr PlatformViewIOS::GetWeakPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/travis/licenses_golden/licenses_flutter b/travis/licenses_golden/licenses_flutter index 102155aa310d0e033092ce584895b6b8bb1631e4..0b327993678fce083a1acb9d41661562cae0c849 100644 --- a/travis/licenses_golden/licenses_flutter +++ b/travis/licenses_golden/licenses_flutter @@ -9497,6 +9497,44 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ==================================================================================================== +==================================================================================================== +LIBRARY: engine +ORIGIN: ../../../topaz/lib/tonic/LICENSE +TYPE: LicenseType.bsd +FILE: ../../../flutter/fml/memory/weak_ptr.h +FILE: ../../../flutter/fml/memory/weak_ptr_internal.cc +FILE: ../../../flutter/fml/memory/weak_ptr_internal.h +FILE: ../../../flutter/fml/memory/weak_ptr_unittest.cc +---------------------------------------------------------------------------------------------------- +Copyright 2016 The Fuchsia Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +==================================================================================================== + ==================================================================================================== LIBRARY: txt ORIGIN: ../../../flutter/third_party/txt/LICENSE @@ -9780,4 +9818,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================================================== -Total license count: 211 +Total license count: 212