Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/ui/painting/image_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class ImageDecoder {
std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner_;
fml::WeakPtr<IOManager> io_manager_;
fml::WeakPtrFactory<ImageDecoder> weak_factory_;

FML_DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
};

Expand Down
45 changes: 22 additions & 23 deletions shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,29 +910,6 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
}

private:
Engine::Delegate& delegate_;
const Settings settings_;
std::unique_ptr<Animator> animator_;
std::unique_ptr<RuntimeController> runtime_controller_;

// The pointer_data_dispatcher_ depends on animator_ and runtime_controller_.
// So it should be defined after them to ensure that pointer_data_dispatcher_
// is destructed first.
std::unique_ptr<PointerDataDispatcher> pointer_data_dispatcher_;

std::string last_entry_point_;
std::string last_entry_point_library_;
std::string initial_route_;
ViewportMetrics viewport_metrics_;
std::shared_ptr<AssetManager> asset_manager_;
bool activity_running_;
bool have_surface_;
std::shared_ptr<FontCollection> font_collection_;
ImageDecoder image_decoder_;
ImageGeneratorRegistry image_generator_registry_;
TaskRunners task_runners_;
fml::WeakPtrFactory<Engine> weak_factory_;

// |RuntimeDelegate|
std::string DefaultRouteName() override;

Expand Down Expand Up @@ -981,6 +958,28 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {

friend class testing::ShellTest;

Engine::Delegate& delegate_;
const Settings settings_;
std::unique_ptr<Animator> animator_;
std::unique_ptr<RuntimeController> runtime_controller_;

// The pointer_data_dispatcher_ depends on animator_ and runtime_controller_.
// So it should be defined after them to ensure that pointer_data_dispatcher_
// is destructed first.
std::unique_ptr<PointerDataDispatcher> pointer_data_dispatcher_;

std::string last_entry_point_;
std::string last_entry_point_library_;
std::string initial_route_;
ViewportMetrics viewport_metrics_;
std::shared_ptr<AssetManager> asset_manager_;
bool activity_running_;
bool have_surface_;
std::shared_ptr<FontCollection> font_collection_;
ImageDecoder image_decoder_;
ImageGeneratorRegistry image_generator_registry_;
TaskRunners task_runners_;
fml::WeakPtrFactory<Engine> weak_factory_; // Must be the last member.
FML_DISALLOW_COPY_AND_ASSIGN(Engine);
};

Expand Down
9 changes: 4 additions & 5 deletions shell/common/platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,14 @@ class PlatformView {
CreateSnapshotSurfaceProducer();

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

PlatformView::Delegate& delegate_;
const TaskRunners task_runners_;

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
10 changes: 4 additions & 6 deletions shell/common/pointer_data_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,18 @@ class SmoothPointerDataDispatcher : public DefaultPointerDataDispatcher {
virtual ~SmoothPointerDataDispatcher();

private:
void DispatchPendingPacket();
void ScheduleSecondaryVsyncCallback();

// If non-null, this will be a pending pointer data packet for the next frame
// to consume. This is used to smooth out the irregular drag events delivery.
// See also `DispatchPointerDataPacket` and input_events_unittests.cc.
std::unique_ptr<PointerDataPacket> pending_packet_;
int pending_trace_flow_id_ = -1;

bool is_pointer_data_in_progress_ = false;

// WeakPtrFactory must be the last member.
fml::WeakPtrFactory<SmoothPointerDataDispatcher> weak_factory_;

void DispatchPendingPacket();

void ScheduleSecondaryVsyncCallback();

FML_DISALLOW_COPY_AND_ASSIGN(SmoothPointerDataDispatcher);
};

Expand Down
34 changes: 18 additions & 16 deletions shell/common/rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,22 +448,6 @@ class Rasterizer final : public SnapshotDelegate {
void DisableThreadMergerIfNeeded();

private:
Delegate& delegate_;
std::unique_ptr<Surface> surface_;
std::unique_ptr<SnapshotSurfaceProducer> snapshot_surface_producer_;
std::unique_ptr<flutter::CompositorContext> compositor_context_;
// This is the last successfully rasterized layer tree.
std::unique_ptr<flutter::LayerTree> last_layer_tree_;
// Set when we need attempt to rasterize the layer tree again. This layer_tree
// has not successfully rasterized. This can happen due to the change in the
// thread configuration. This will be inserted to the front of the pipeline.
std::unique_ptr<flutter::LayerTree> resubmitted_layer_tree_;
fml::closure next_frame_callback_;
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 +484,24 @@ class Rasterizer final : public SnapshotDelegate {

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

Delegate& delegate_;
std::unique_ptr<Surface> surface_;
std::unique_ptr<SnapshotSurfaceProducer> snapshot_surface_producer_;
std::unique_ptr<flutter::CompositorContext> compositor_context_;
// This is the last successfully rasterized layer tree.
std::unique_ptr<flutter::LayerTree> last_layer_tree_;
// Set when we need attempt to rasterize the layer tree again. This layer_tree
// has not successfully rasterized. This can happen due to the change in the
// thread configuration. This will be inserted to the front of the pipeline.
std::unique_ptr<flutter::LayerTree> resubmitted_layer_tree_;
fml::closure next_frame_callback_;
bool user_override_resource_cache_bytes_;
std::optional<size_t> max_cache_bytes_;
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger_;
std::shared_ptr<ExternalViewEmbedder> external_view_embedder_;

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

Expand Down
19 changes: 10 additions & 9 deletions shell/gpu/gpu_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class GPUSurfaceGL : public Surface {
bool AllowsDrawingWhenGpuDisabled() const override;

private:
bool CreateOrUpdateSurfaces(const SkISize& size);

sk_sp<SkSurface> AcquireRenderSurface(
const SkISize& untransformed_size,
const SkMatrix& root_surface_transformation);

bool PresentSurface(SkCanvas* canvas);

GPUSurfaceGLDelegate* delegate_;
sk_sp<GrDirectContext> context_;
sk_sp<SkSurface> onscreen_surface_;
Expand All @@ -66,16 +74,9 @@ 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);

sk_sp<SkSurface> AcquireRenderSurface(
const SkISize& untransformed_size,
const SkMatrix& root_surface_transformation);

bool PresentSurface(SkCanvas* canvas);

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

Expand Down
1 change: 0 additions & 1 deletion shell/gpu/gpu_surface_software.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class GPUSurfaceSoftware : public Surface {
// external view embedder is present.
const bool render_to_surface_;
fml::TaskRunnerAffineWeakPtrFactory<GPUSurfaceSoftware> weak_factory_;

FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceSoftware);
};

Expand Down
1 change: 0 additions & 1 deletion shell/gpu/gpu_surface_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class GPUSurfaceVulkan : public Surface {
const bool render_to_surface_;

fml::WeakPtrFactory<GPUSurfaceVulkan> weak_factory_;

FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceVulkan);
};

Expand Down
4 changes: 4 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ - (void)dealloc {
object:self
userInfo:nil];

// It will be destroyed and invalidate its weak pointers
// before any other members are destroyed.
_weakFactory.reset();

/// nil out weak references.
[_registrars
enumerateKeysAndObjectsUsingBlock:^(id key, FlutterEngineRegistrar* registrar, BOOL* stop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ - (void)addSecondaryResponder:(nonnull id<FlutterKeySecondaryResponder>)responde
}

- (void)dealloc {
// It will be destroyed and invalidate its weak pointers
// before any other members are destroyed.
_weakFactory.reset();

[_primaryResponders removeAllObjects];
[_secondaryResponders removeAllObjects];
[_primaryResponders release];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ + (NSData*)createTxtData:(NSURL*)url {
}

- (void)dealloc {
// It will be destroyed and invalidate its weak pointers
// before any other members are destroyed.
_weakFactory.reset();

[_delegate stopService];
[_url release];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,67 +182,6 @@ class FlutterPlatformViewsController {

using LayersMap = std::map<int64_t, std::vector<std::shared_ptr<FlutterPlatformViewLayer>>>;

// The pool of reusable view layers. The pool allows to recycle layer in each frame.
std::unique_ptr<FlutterPlatformViewLayerPool> layer_pool_;

// The platform view's R-tree keyed off the view id, which contains any subsequent
// draw operation until the next platform view or the last leaf node in the layer tree.
//
// The R-trees are deleted by the FlutterPlatformViewsController.reset().
std::map<int64_t, sk_sp<RTree>> platform_view_rtrees_;

// The platform view's picture recorder keyed off the view id, which contains any subsequent
// operation until the next platform view or the end of the last leaf node in the layer tree.
std::map<int64_t, std::unique_ptr<SkPictureRecorder>> picture_recorders_;

fml::scoped_nsobject<FlutterMethodChannel> channel_;
fml::scoped_nsobject<UIView> flutter_view_;
fml::scoped_nsobject<UIViewController> flutter_view_controller_;
std::map<std::string, fml::scoped_nsobject<NSObject<FlutterPlatformViewFactory>>> factories_;
std::map<int64_t, fml::scoped_nsobject<NSObject<FlutterPlatformView>>> views_;
std::map<int64_t, fml::scoped_nsobject<FlutterTouchInterceptingView>> touch_interceptors_;
// Mapping a platform view ID to the top most parent view (root_view) of a platform view. In
// |SubmitFrame|, root_views_ are added to flutter_view_ as child views.
//
// The platform view with the view ID is a child of the root view; If the platform view is not
// clipped, and no clipping view is added, the root view will be the intercepting view.
std::map<int64_t, fml::scoped_nsobject<UIView>> root_views_;
// Mapping a platform view ID to its latest composition params.
std::map<int64_t, EmbeddedViewParams> current_composition_params_;
// Mapping a platform view ID to the count of the clipping operations that were applied to the
// platform view last time it was composited.
std::map<int64_t, int64_t> clip_count_;
SkISize frame_size_;

// The number of frames the rasterizer task runner will continue
// to run on the platform thread after no platform view is rendered.
//
// Note: this is an arbitrary number that attempts to account for cases
// where the platform view might be momentarily off the screen.
static const int kDefaultMergedLeaseDuration = 10;

// Method channel `OnDispose` calls adds the views to be disposed to this set to be disposed on
// the next frame.
std::unordered_set<int64_t> views_to_dispose_;

// A vector of embedded view IDs according to their composition order.
// The last ID in this vector belond to the that is composited on top of all others.
std::vector<int64_t> composition_order_;

// The latest composition order that was presented in Present().
std::vector<int64_t> active_composition_order_;

// Only compoiste platform views in this set.
std::unordered_set<int64_t> views_to_recomposite_;

// The FlutterPlatformViewGestureRecognizersBlockingPolicy for each type of platform view.
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);
void OnDispose(FlutterMethodCall* call, FlutterResult& result);
void OnAcceptGesture(FlutterMethodCall* call, FlutterResult& result);
Expand Down Expand Up @@ -302,6 +241,67 @@ class FlutterPlatformViewsController {
// Resets the state of the frame.
void ResetFrameState();

// The pool of reusable view layers. The pool allows to recycle layer in each frame.
std::unique_ptr<FlutterPlatformViewLayerPool> layer_pool_;

// The platform view's R-tree keyed off the view id, which contains any subsequent
// draw operation until the next platform view or the last leaf node in the layer tree.
//
// The R-trees are deleted by the FlutterPlatformViewsController.reset().
std::map<int64_t, sk_sp<RTree>> platform_view_rtrees_;

// The platform view's picture recorder keyed off the view id, which contains any subsequent
// operation until the next platform view or the end of the last leaf node in the layer tree.
std::map<int64_t, std::unique_ptr<SkPictureRecorder>> picture_recorders_;

fml::scoped_nsobject<FlutterMethodChannel> channel_;
fml::scoped_nsobject<UIView> flutter_view_;
fml::scoped_nsobject<UIViewController> flutter_view_controller_;
std::map<std::string, fml::scoped_nsobject<NSObject<FlutterPlatformViewFactory>>> factories_;
std::map<int64_t, fml::scoped_nsobject<NSObject<FlutterPlatformView>>> views_;
std::map<int64_t, fml::scoped_nsobject<FlutterTouchInterceptingView>> touch_interceptors_;
// Mapping a platform view ID to the top most parent view (root_view) of a platform view. In
// |SubmitFrame|, root_views_ are added to flutter_view_ as child views.
//
// The platform view with the view ID is a child of the root view; If the platform view is not
// clipped, and no clipping view is added, the root view will be the intercepting view.
std::map<int64_t, fml::scoped_nsobject<UIView>> root_views_;
// Mapping a platform view ID to its latest composition params.
std::map<int64_t, EmbeddedViewParams> current_composition_params_;
// Mapping a platform view ID to the count of the clipping operations that were applied to the
// platform view last time it was composited.
std::map<int64_t, int64_t> clip_count_;
SkISize frame_size_;

// The number of frames the rasterizer task runner will continue
// to run on the platform thread after no platform view is rendered.
//
// Note: this is an arbitrary number that attempts to account for cases
// where the platform view might be momentarily off the screen.
static const int kDefaultMergedLeaseDuration = 10;

// Method channel `OnDispose` calls adds the views to be disposed to this set to be disposed on
// the next frame.
std::unordered_set<int64_t> views_to_dispose_;

// A vector of embedded view IDs according to their composition order.
// The last ID in this vector belond to the that is composited on top of all others.
std::vector<int64_t> composition_order_;

// The latest composition order that was presented in Present().
std::vector<int64_t> active_composition_order_;

// Only compoiste platform views in this set.
std::unordered_set<int64_t> views_to_recomposite_;

// The FlutterPlatformViewGestureRecognizersBlockingPolicy for each type of platform view.
std::map<std::string, FlutterPlatformViewGestureRecognizersBlockingPolicy>
gesture_recognizers_blocking_policies;

bool catransaction_added_ = false;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,10 @@ - (void)deregisterNotifications {
}

- (void)dealloc {
// It will be destroyed and invalidate its weak pointers
// before any other members are destroyed.
_weakFactory.reset();

[self removeInternalPlugins];
[self deregisterNotifications];
[super dealloc];
Expand Down
Loading