-
Notifications
You must be signed in to change notification settings - Fork 6k
Improve iOS PlatformViews to better handle thread merging. #16935
Conversation
flow/embedded_views.h
Outdated
@@ -250,6 +250,14 @@ class ExternalViewEmbedder { | |||
|
|||
virtual bool SubmitFrame(GrContext* context); | |||
|
|||
// Caller should make sure to call this after |SubmitFrame|. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only be called after |SubmitFrame|
reads better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
flow/embedded_views.h
Outdated
@@ -250,6 +250,14 @@ class ExternalViewEmbedder { | |||
|
|||
virtual bool SubmitFrame(GrContext* context); | |||
|
|||
// Caller should make sure to call this after |SubmitFrame|. | |||
// Embedder that implements this method to do additional tasks after |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method provides the embedder a way to do additional tasks after |SubmitFrame|
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
flow/embedded_views.h
Outdated
@@ -250,6 +250,14 @@ class ExternalViewEmbedder { | |||
|
|||
virtual bool SubmitFrame(GrContext* context); | |||
|
|||
// Caller should make sure to call this after |SubmitFrame|. | |||
// Embedder that implements this method to do additional tasks after | |||
// |SubmitFrame|. One of such examples is threading merging on iOS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example on the iOS embedder, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
flow/embedded_views.h
Outdated
// Embedder that implements this method to do additional tasks after | ||
// |SubmitFrame|. One of such examples is threading merging on iOS. | ||
// | ||
// After invoking this method, the current task on the TaskRunner should end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be useful to document why this is the case as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed the whole paragraph a little bit, could you take a look again?
@@ -184,8 +184,9 @@ | |||
if (gpu_thread_merger->IsMerged()) { | |||
gpu_thread_merger->ExtendLeaseTo(kDefaultMergedLeaseDuration); | |||
} else { | |||
// Wait until |EndFrame| to perform thread merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to perform thread merging
-> to merge the threads
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -184,8 +184,9 @@ | |||
if (gpu_thread_merger->IsMerged()) { | |||
gpu_thread_merger->ExtendLeaseTo(kDefaultMergedLeaseDuration); | |||
} else { | |||
// Wait until |EndFrame| to perform thread merging. | |||
will_merge_threads_ = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: merge_threads_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -368,6 +369,12 @@ | |||
|
|||
bool FlutterPlatformViewsController::SubmitFrame(GrContext* gr_context, | |||
std::shared_ptr<IOSContext> ios_context) { | |||
if (will_merge_threads_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment explaining why these are cleared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -91,6 +91,8 @@ class FlutterPlatformViewsController { | |||
|
|||
void SetFrameSize(SkISize frame_size); | |||
|
|||
// Indicates that we don't compisite any platform views or overlays during this frame. | |||
// Also reverts the composite_order_ to its original state at the begining of the frame. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
composition_order_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -170,6 +177,8 @@ class FlutterPlatformViewsController { | |||
void OnAcceptGesture(FlutterMethodCall* call, FlutterResult& result); | |||
void OnRejectGesture(FlutterMethodCall* call, FlutterResult& result); | |||
|
|||
// Remove PlatformViews and Overlays that is in `active_composition_order_` but not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that are in
, must run on platform thread
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iskakaushik Updated based on your comments.
flow/embedded_views.h
Outdated
@@ -250,6 +250,14 @@ class ExternalViewEmbedder { | |||
|
|||
virtual bool SubmitFrame(GrContext* context); | |||
|
|||
// Caller should make sure to call this after |SubmitFrame|. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
flow/embedded_views.h
Outdated
@@ -250,6 +250,14 @@ class ExternalViewEmbedder { | |||
|
|||
virtual bool SubmitFrame(GrContext* context); | |||
|
|||
// Caller should make sure to call this after |SubmitFrame|. | |||
// Embedder that implements this method to do additional tasks after | |||
// |SubmitFrame|. One of such examples is threading merging on iOS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
flow/embedded_views.h
Outdated
@@ -250,6 +250,14 @@ class ExternalViewEmbedder { | |||
|
|||
virtual bool SubmitFrame(GrContext* context); | |||
|
|||
// Caller should make sure to call this after |SubmitFrame|. | |||
// Embedder that implements this method to do additional tasks after |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
flow/embedded_views.h
Outdated
// Embedder that implements this method to do additional tasks after | ||
// |SubmitFrame|. One of such examples is threading merging on iOS. | ||
// | ||
// After invoking this method, the current task on the TaskRunner should end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed the whole paragraph a little bit, could you take a look again?
@@ -184,8 +184,9 @@ | |||
if (gpu_thread_merger->IsMerged()) { | |||
gpu_thread_merger->ExtendLeaseTo(kDefaultMergedLeaseDuration); | |||
} else { | |||
// Wait until |EndFrame| to perform thread merging. | |||
will_merge_threads_ = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -184,8 +184,9 @@ | |||
if (gpu_thread_merger->IsMerged()) { | |||
gpu_thread_merger->ExtendLeaseTo(kDefaultMergedLeaseDuration); | |||
} else { | |||
// Wait until |EndFrame| to perform thread merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -368,6 +369,12 @@ | |||
|
|||
bool FlutterPlatformViewsController::SubmitFrame(GrContext* gr_context, | |||
std::shared_ptr<IOSContext> ios_context) { | |||
if (will_merge_threads_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -91,6 +91,8 @@ class FlutterPlatformViewsController { | |||
|
|||
void SetFrameSize(SkISize frame_size); | |||
|
|||
// Indicates that we don't compisite any platform views or overlays during this frame. | |||
// Also reverts the composite_order_ to its original state at the begining of the frame. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@iskakaushik is there anything left in this PR that you'd like to address? |
flow/embedded_views.h
Outdated
// A new frame on the platform thread starts immediately. If the GPU thread | ||
// still has some task running, there could be two frames being rendered | ||
// concurrently, which causes undefined behaviors. | ||
virtual void EndFrame(fml::RefPtr<fml::GpuThreadMerger> gpu_thread_merger) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: The description of this method seems similar to FinishFrame
. Is it possible to have a single method for both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we currently only call EndFrame during thread merging process. It doesn't seem to be doing the same thing with we are doing in FinishFrame
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used particularly in the thread merging scenario. FinishFrame
is actually not the very end of the frame. But the EndFrame
marks the very end of the frame.
@blasten Sorry, this got off my radar. I will take a look at this on Monday. |
can we write a test for this change? |
…ging. (flutter#16935)" (flutter#17600)" This reverts commit caebc93.
…lutter#16935)" (flutter#17600) This reverts commit f6b8eda.
This PR is a partial effort of enabling dynamic thread merging on iOS. flutter/flutter#23975
This PR mainly focuses on potential crashes after enabling thread merge. This PR DOES NOT enable thread merging and the behavior of iOS platform view and rasterizer should be the same as it is today after this. PR lands.
This PR includes:
EndFrame
method in theExternalViewEmbedder
; updated the code inFlutterPlatformViewsController
to handle that change.FlutterPlatformViewsController
to help reproduce crashes related to running UIKit operations in background threads.FlutterPlatformViewsController
.[CATransaction commit]
only runs on the main thread.Edit:
ExternalViewEmbedder
impls inios_surface_gl
andios_surface_software
are combined intoios_surface
after this PR was put up. This PR has updated to reflect this change.