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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,21 @@
CancelFrame();
return PostPrerollResult::kSkipAndRetryFrame;
}
// If the post preroll action is successful, we will display platform views in the current frame.
// In order to sync the rendering of the platform views (quartz) with skia's rendering,
// We need to begin an explicit CATransaction. This transaction needs to be submitted
// after the current frame is submitted.
BeginCATransaction();
raster_thread_merger->ExtendLeaseTo(kDefaultMergedLeaseDuration);
return PostPrerollResult::kSuccess;
}

void FlutterPlatformViewsController::PrerollCompositeEmbeddedView(
int view_id,
std::unique_ptr<EmbeddedViewParams> params) {
// All the CATransactions should be committed by the end of the last frame,
// so catransaction_added_ must be false.
FML_DCHECK(!catransaction_added_);
picture_recorders_[view_id] = std::make_unique<SkPictureRecorder>();

auto rtree_factory = RTreeFactory();
Expand Down Expand Up @@ -548,6 +556,10 @@

did_submit &= frame->Submit();

// If the frame is submitted with embedded platform views,
// there should be a |[CATransaction begin]| call in this frame prior to all the drawing.
// If that case, we need to commit the transaction.
CommitCATransactionIfNeeded();
return did_submit;
}

Expand Down Expand Up @@ -662,6 +674,21 @@
views_to_dispose_.clear();
}

void FlutterPlatformViewsController::BeginCATransaction() {
FML_DCHECK([[NSThread currentThread] isMainThread]);
FML_DCHECK(!catransaction_added_);
[CATransaction begin];
catransaction_added_ = true;
}

void FlutterPlatformViewsController::CommitCATransactionIfNeeded() {
if (catransaction_added_) {
FML_DCHECK([[NSThread currentThread] isMainThread]);
[CATransaction commit];
catransaction_added_ = false;
}
}

} // namespace flutter

// This recognizers delays touch events from being dispatched to the responder chain until it failed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ class FlutterPlatformViewsController {

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 @@ -294,6 +296,13 @@ class FlutterPlatformViewsController {
// order.
void BringLayersIntoView(LayersMap layer_map);

// Begin a CATransaction.
// This transaction needs to be balanced with |CommitCATransactionIfNeeded|.
void BeginCATransaction();

// Commit a CATransaction if |BeginCATransaction| has been called during the frame.
void CommitCATransactionIfNeeded();

FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewsController);
};

Expand Down
17 changes: 2 additions & 15 deletions shell/platform/darwin/ios/ios_surface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@
TRACE_EVENT0("flutter", "IOSSurface::CancelFrame");
FML_CHECK(platform_views_controller_ != nullptr);
platform_views_controller_->CancelFrame();
// Committing the current transaction as |BeginFrame| will create a nested
// CATransaction otherwise.
[CATransaction commit];
}

// |ExternalViewEmbedder|
Expand All @@ -84,7 +81,6 @@
TRACE_EVENT0("flutter", "IOSSurface::BeginFrame");
FML_CHECK(platform_views_controller_ != nullptr);
platform_views_controller_->SetFrameSize(frame_size);
[CATransaction begin];
}

// |ExternalViewEmbedder|
Expand All @@ -102,10 +98,6 @@
TRACE_EVENT0("flutter", "IOSSurface::PostPrerollAction");
FML_CHECK(platform_views_controller_ != nullptr);
PostPrerollResult result = platform_views_controller_->PostPrerollAction(raster_thread_merger);
if (result == PostPrerollResult::kSkipAndRetryFrame) {
// Commit the current transaction if the frame is dropped.
[CATransaction commit];
}
return result;
}

Expand All @@ -126,13 +118,8 @@
void IOSSurface::SubmitFrame(GrDirectContext* context, std::unique_ptr<SurfaceFrame> frame) {
TRACE_EVENT0("flutter", "IOSSurface::SubmitFrame");
FML_CHECK(platform_views_controller_ != nullptr);
bool submitted =
platform_views_controller_->SubmitFrame(std::move(context), ios_context_, std::move(frame));

if (submitted) {
TRACE_EVENT0("flutter", "IOSSurface::DidSubmitFrame");
[CATransaction commit];
}
platform_views_controller_->SubmitFrame(std::move(context), ios_context_, std::move(frame));
TRACE_EVENT0("flutter", "IOSSurface::DidSubmitFrame");
}

// |ExternalViewEmbedder|
Expand Down