Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeakPtrFactory should be destroyed before any other members. #29402

Merged
merged 5 commits into from Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/ui/painting/image_decoder.h
Expand Up @@ -56,8 +56,7 @@ class ImageDecoder {
TaskRunners runners_;
std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner_;
fml::WeakPtr<IOManager> io_manager_;
fml::WeakPtrFactory<ImageDecoder> weak_factory_;

fml::WeakPtrFactory<ImageDecoder> weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
};

Expand Down
3 changes: 2 additions & 1 deletion lib/ui/painting/image_generator_registry.h
Expand Up @@ -85,7 +85,8 @@ class ImageGeneratorRegistry {
using FactorySet = std::set<PrioritizedFactory, Compare>;
FactorySet image_generator_factories_;
size_t nonce_;
fml::WeakPtrFactory<ImageGeneratorRegistry> weak_factory_;
fml::WeakPtrFactory<ImageGeneratorRegistry>
weak_factory_; // Must be the last member.
};

} // namespace flutter
Expand Down
3 changes: 1 addition & 2 deletions shell/common/animator.h
Expand Up @@ -119,10 +119,9 @@ class Animator final {
std::deque<uint64_t> trace_flow_ids_;
bool has_rendered_ = false;

fml::WeakPtrFactory<Animator> weak_factory_;

friend class testing::ShellTest;

fml::WeakPtrFactory<Animator> weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(Animator);
};

Expand Down
3 changes: 1 addition & 2 deletions shell/common/engine.h
Expand Up @@ -931,7 +931,6 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
ImageDecoder image_decoder_;
ImageGeneratorRegistry image_generator_registry_;
TaskRunners task_runners_;
fml::WeakPtrFactory<Engine> weak_factory_;

// |RuntimeDelegate|
std::string DefaultRouteName() override;
Expand Down Expand Up @@ -980,7 +979,7 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
bool GetAssetAsBuffer(const std::string& name, std::vector<uint8_t>* data);

friend class testing::ShellTest;

fml::WeakPtrFactory<Engine> weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(Engine);
};

Expand Down
2 changes: 1 addition & 1 deletion shell/common/platform_view.h
Expand Up @@ -816,11 +816,11 @@ class PlatformView {

PointerDataPacketConverter pointer_data_packet_converter_;
SkISize size_;
fml::WeakPtrFactory<PlatformView> weak_factory_;

// This is the only method called on the raster task runner.
virtual std::unique_ptr<Surface> CreateRenderingSurface();

fml::WeakPtrFactory<PlatformView> weak_factory_; // Must be the last member.
private:
FML_DISALLOW_COPY_AND_ASSIGN(PlatformView);
};
Expand Down
4 changes: 2 additions & 2 deletions shell/common/pointer_data_dispatcher.h
Expand Up @@ -155,12 +155,12 @@ class SmoothPointerDataDispatcher : public DefaultPointerDataDispatcher {

bool is_pointer_data_in_progress_ = false;

fml::WeakPtrFactory<SmoothPointerDataDispatcher> weak_factory_;

void DispatchPendingPacket();

void ScheduleSecondaryVsyncCallback();

fml::WeakPtrFactory<SmoothPointerDataDispatcher>
weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(SmoothPointerDataDispatcher);
};

Expand Down
4 changes: 3 additions & 1 deletion shell/common/rasterizer.h
Expand Up @@ -462,8 +462,8 @@ class Rasterizer final : public SnapshotDelegate {
bool user_override_resource_cache_bytes_;
std::optional<size_t> max_cache_bytes_;
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger_;
fml::TaskRunnerAffineWeakPtrFactory<Rasterizer> weak_factory_;
std::shared_ptr<ExternalViewEmbedder> external_view_embedder_;

// |SnapshotDelegate|
sk_sp<SkImage> MakeRasterSnapshot(
std::function<void(SkCanvas*)> draw_callback,
Expand Down Expand Up @@ -500,6 +500,8 @@ class Rasterizer final : public SnapshotDelegate {

static bool NoDiscard(const flutter::LayerTree& layer_tree) { return false; }

fml::TaskRunnerAffineWeakPtrFactory<Rasterizer>
weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(Rasterizer);
};

Expand Down
3 changes: 2 additions & 1 deletion shell/common/shell.h
Expand Up @@ -685,9 +685,10 @@ class Shell final : public PlatformView::Delegate,
// rasterizer callbacks.
std::unique_ptr<fml::TaskRunnerAffineWeakPtrFactory<Shell>> weak_factory_gpu_;

fml::WeakPtrFactory<Shell> weak_factory_;
friend class testing::ShellTest;

fml::WeakPtrFactory<Shell> weak_factory_; // Must be the last member.

FML_DISALLOW_COPY_AND_ASSIGN(Shell);
};

Expand Down
4 changes: 2 additions & 2 deletions shell/common/shell_io_manager.h
Expand Up @@ -71,8 +71,8 @@ class ShellIOManager final : public IOManager {

std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;

fml::WeakPtrFactory<ShellIOManager> weak_factory_;

fml::WeakPtrFactory<ShellIOManager>
weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(ShellIOManager);
};

Expand Down
3 changes: 2 additions & 1 deletion shell/gpu/gpu_surface_gl.h
Expand Up @@ -66,7 +66,6 @@ class GPUSurfaceGL : public Surface {
// external view embedder is present.
const bool render_to_surface_ = true;
bool valid_ = false;
fml::TaskRunnerAffineWeakPtrFactory<GPUSurfaceGL> weak_factory_;

bool CreateOrUpdateSurfaces(const SkISize& size);

Expand All @@ -76,6 +75,8 @@ class GPUSurfaceGL : public Surface {

bool PresentSurface(SkCanvas* canvas);

fml::TaskRunnerAffineWeakPtrFactory<GPUSurfaceGL>
weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceGL);
};

Expand Down
3 changes: 2 additions & 1 deletion shell/gpu/gpu_surface_software.h
Expand Up @@ -38,8 +38,9 @@ class GPUSurfaceSoftware : public Surface {
// hack to make avoid allocating resources for the root surface when an
// external view embedder is present.
const bool render_to_surface_;
fml::TaskRunnerAffineWeakPtrFactory<GPUSurfaceSoftware> weak_factory_;

fml::TaskRunnerAffineWeakPtrFactory<GPUSurfaceSoftware>
weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceSoftware);
};

Expand Down
4 changes: 2 additions & 2 deletions shell/gpu/gpu_surface_vulkan.h
Expand Up @@ -54,8 +54,8 @@ class GPUSurfaceVulkan : public Surface {
vulkan::VulkanWindow window_;
const bool render_to_surface_;

fml::WeakPtrFactory<GPUSurfaceVulkan> weak_factory_;

fml::WeakPtrFactory<GPUSurfaceVulkan>
weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceVulkan);
};

Expand Down
Expand Up @@ -239,8 +239,6 @@ class FlutterPlatformViewsController {
std::map<std::string, FlutterPlatformViewGestureRecognizersBlockingPolicy>
gesture_recognizers_blocking_policies;

std::unique_ptr<fml::WeakPtrFactory<FlutterPlatformViewsController>> weak_factory_;

bool catransaction_added_ = false;

void OnCreate(FlutterMethodCall* call, FlutterResult& result);
Expand Down Expand Up @@ -302,6 +300,8 @@ class FlutterPlatformViewsController {
// Resets the state of the frame.
void ResetFrameState();

std::unique_ptr<fml::WeakPtrFactory<FlutterPlatformViewsController>>
weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewsController);
};

Expand Down
Expand Up @@ -99,12 +99,11 @@ class AccessibilityBridge final : public AccessibilityBridgeIos {
int32_t last_focused_semantics_object_id_;
fml::scoped_nsobject<NSMutableDictionary<NSNumber*, SemanticsObject*>> objects_;
fml::scoped_nsprotocol<FlutterBasicMessageChannel*> accessibility_channel_;
fml::WeakPtrFactory<AccessibilityBridge> weak_factory_;
int32_t previous_route_id_;
std::unordered_map<int32_t, flutter::CustomAccessibilityAction> actions_;
std::vector<int32_t> previous_routes_;
std::unique_ptr<IosDelegate> ios_delegate_;

fml::WeakPtrFactory<AccessibilityBridge> weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(AccessibilityBridge);
};

Expand Down
Expand Up @@ -46,11 +46,11 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
platform_views_controller_(platform_views_controller),
last_focused_semantics_object_id_(kSemanticObjectIdInvalid),
objects_([[NSMutableDictionary alloc] init]),
weak_factory_(this),
previous_route_id_(0),
previous_routes_({}),
ios_delegate_(ios_delegate ? std::move(ios_delegate)
: std::make_unique<DefaultIosDelegate>()) {
: std::make_unique<DefaultIosDelegate>()),
weak_factory_(this) {
accessibility_channel_.reset([[FlutterBasicMessageChannel alloc]
initWithName:@"flutter/accessibility"
binaryMessenger:platform_view->GetOwnerViewController().get().engine.binaryMessenger
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/fuchsia/flutter/component_v1.h
Expand Up @@ -101,7 +101,6 @@ class ComponentV1 final : public Engine::Delegate,
fml::RefPtr<flutter::DartSnapshot> isolate_snapshot_;
std::set<std::unique_ptr<Engine>> shell_holders_;
std::pair<bool, uint32_t> last_return_code_;
fml::WeakPtrFactory<ComponentV1> weak_factory_;

ComponentV1(
TerminationCallback termination_callback,
Expand Down Expand Up @@ -133,6 +132,7 @@ class ComponentV1 final : public Engine::Delegate,
// |flutter::Engine::Delegate|
void OnEngineTerminate(const Engine* holder) override;

fml::WeakPtrFactory<ComponentV1> weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(ComponentV1);
};

Expand Down
2 changes: 1 addition & 1 deletion shell/platform/fuchsia/flutter/component_v2.h
Expand Up @@ -108,7 +108,6 @@ class ComponentV2 final
fml::RefPtr<flutter::DartSnapshot> isolate_snapshot_;
std::set<std::unique_ptr<Engine>> shell_holders_;
std::pair<bool, uint32_t> last_return_code_;
fml::WeakPtrFactory<ComponentV2> weak_factory_;

ComponentV2(
TerminationCallback termination_callback,
Expand Down Expand Up @@ -149,6 +148,7 @@ class ComponentV2 final
// |flutter::Engine::Delegate|
void OnEngineTerminate(const Engine* holder) override;

fml::WeakPtrFactory<ComponentV2> weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(ComponentV2);
};

Expand Down
3 changes: 1 addition & 2 deletions shell/platform/fuchsia/flutter/engine.h
Expand Up @@ -170,10 +170,9 @@ class Engine final : public fuchsia::memorypressure::Watcher {

bool intercept_all_input_ = false;

fml::WeakPtrFactory<Engine> weak_factory_;

friend class testing::EngineTest;

fml::WeakPtrFactory<Engine> weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(Engine);
};

Expand Down
1 change: 0 additions & 1 deletion shell/platform/fuchsia/flutter/gfx_platform_view.h
Expand Up @@ -84,7 +84,6 @@ class GfxPlatformView final : public flutter_runner::PlatformView,

fml::WeakPtrFactory<GfxPlatformView>
weak_factory_; // Must be the last member.

FML_DISALLOW_COPY_AND_ASSIGN(GfxPlatformView);
};

Expand Down
1 change: 0 additions & 1 deletion shell/platform/fuchsia/flutter/platform_view.h
Expand Up @@ -224,7 +224,6 @@ class PlatformView : public flutter::PlatformView,
await_vsync_for_secondary_callback_callback_;

fml::WeakPtrFactory<PlatformView> weak_factory_; // Must be the last member.

FML_DISALLOW_COPY_AND_ASSIGN(PlatformView);
};

Expand Down
3 changes: 1 addition & 2 deletions shell/platform/fuchsia/flutter/vsync_waiter.h
Expand Up @@ -48,8 +48,7 @@ class VsyncWaiter final : public flutter::VsyncWaiter {

fml::WeakPtr<VsyncWaiter> weak_ui_;
std::unique_ptr<fml::WeakPtrFactory<VsyncWaiter>> weak_factory_ui_;
fml::WeakPtrFactory<VsyncWaiter> weak_factory_;

fml::WeakPtrFactory<VsyncWaiter> weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiter);
};

Expand Down
4 changes: 3 additions & 1 deletion shell/platform/fuchsia/flutter/vulkan_surface_producer.h
Expand Up @@ -69,11 +69,13 @@ class VulkanSurfaceProducer final : public SurfaceProducer,
// Keep track of the last time we produced a surface. This is used to
// determine whether it is safe to shrink |surface_pool_| or not.
zx::time last_produce_time_ = async::Now(async_get_default_dispatcher());
fml::WeakPtrFactory<VulkanSurfaceProducer> weak_factory_{this};

// Disallow copy and assignment.
VulkanSurfaceProducer(const VulkanSurfaceProducer&) = delete;
VulkanSurfaceProducer& operator=(const VulkanSurfaceProducer&) = delete;

fml::WeakPtrFactory<VulkanSurfaceProducer> weak_factory_{
this}; // Must be the last member.
};

} // namespace flutter_runner