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 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
02556ae
++
Jul 11, 2024
b3f6670
move all state updates to end of compositing.
Jul 11, 2024
b31aae6
working but unsynchronized.
Jul 11, 2024
75f931a
hey it almost works.
Jul 12, 2024
4525bd8
disable partial repaint.
Jul 12, 2024
6ce3aa0
cleanups.
Jul 12, 2024
be03cf8
set presentsWithTransaction.
Jul 12, 2024
6770376
sanity refactor.
Jul 12, 2024
912cd40
linting.
Jul 12, 2024
1f65cc3
skip post message if there are no platform views.
Jul 12, 2024
53adc81
linting.
Jul 12, 2024
870b950
dispose views in callback.
Jul 15, 2024
f8267bd
++
Jul 15, 2024
80565d5
Merge branch 'main' of github.com:flutter/engine into three_phase_render
Jul 16, 2024
2b9a825
tear down.
Jul 16, 2024
0a7dc5a
reserve.
Jul 17, 2024
2745e88
++
Jul 17, 2024
6002aa0
++
Jul 17, 2024
e7a832f
++
Jul 17, 2024
f099d74
come on big money no whammies.
Jul 17, 2024
e2e6a2a
okay one more.
Jul 17, 2024
44d5b5b
debug printf
Jul 17, 2024
b53063a
++
Jul 19, 2024
9a84539
make test work.
Jul 23, 2024
65a5210
++
Jul 23, 2024
735ce22
testing fixes.
Jul 24, 2024
a4f523b
Merge branch 'main' of github.com:flutter/engine into three_phase_render
Jul 24, 2024
b6c3345
merge in view slicer.
Jul 24, 2024
a4b771e
Merge branch 'main' of github.com:flutter/engine into three_phase_render
Jul 24, 2024
cd8e1de
++
Jul 25, 2024
6603d18
minor cleanups.
Jul 25, 2024
27c0daa
formatting.
Jul 25, 2024
d794211
add back clear
Jul 26, 2024
2f4314b
++
Jul 26, 2024
25a4e06
++
Jul 26, 2024
ea2e66d
merge threads on SIM.
Jul 26, 2024
d220885
++
Jul 26, 2024
9b534cd
Update shell/platform/darwin/ios/ios_external_view_embedder.mm
Jul 26, 2024
970e13a
++
Jul 26, 2024
63ebe66
Merge branch 'three_phase_render' of github.com:jonahwilliams/engine …
Jul 26, 2024
ff4802a
Merge branch 'main' of github.com:flutter/engine into three_phase_render
Jul 26, 2024
e3fc731
does it blend?
Jul 26, 2024
c0fab3b
++
Jul 26, 2024
d73671e
test fixes and clang tidy.
Jul 27, 2024
7285907
simplify and clean up thread access for UIViews.
Jul 27, 2024
bcd8519
reset before clearning composition order.
Jul 27, 2024
b25a742
Merge branch 'main' of github.com:flutter/engine into three_phase_render
Jul 30, 2024
5f6a8d4
switch to SurfaceFrame API.
Jul 30, 2024
be7853d
++
Jul 30, 2024
b19b4d8
Remove extra include.
Jul 30, 2024
ab08739
clang tidy
Jul 30, 2024
6e6e5a2
bracken feedback
Jul 30, 2024
355ab30
more bracken review.
Aug 1, 2024
8cd1c74
++
Aug 1, 2024
30e7b97
review comments and remove dead code.
Aug 1, 2024
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
Prev Previous commit
Next Next commit
simplify and clean up thread access for UIViews.
  • Loading branch information
jonahwilliams committed Jul 27, 2024
commit 72859079d326ec3d87b0c522c3dc021cd2555324
123 changes: 59 additions & 64 deletions shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
NSString* viewTypeString = args[@"viewType"];
std::string viewType(viewTypeString.UTF8String);

if (views_.count(viewId) != 0) {
if (platform_views_.count(viewId) != 0) {
result([FlutterError errorWithCode:@"recreating_view"
message:@"trying to create an already created view"
details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
return;
}

NSObject<FlutterPlatformViewFactory>* factory = factories_[viewType].get();
Expand Down Expand Up @@ -248,19 +249,21 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
// Set a unique view identifier, so the platform view can be identified in unit tests.
platform_view.accessibilityIdentifier =
[NSString stringWithFormat:@"platform_view[%lld]", viewId];
views_[viewId] = fml::scoped_nsobject<NSObject<FlutterPlatformView>>(embedded_view);

FlutterTouchInterceptingView* touch_interceptor = [[FlutterTouchInterceptingView alloc]
initWithEmbeddedView:platform_view
platformViewsController:GetWeakPtr()
gestureRecognizersBlockingPolicy:gesture_recognizers_blocking_policies_[viewType]];

touch_interceptors_[viewId] =
fml::scoped_nsobject<FlutterTouchInterceptingView>(touch_interceptor);

ChildClippingView* clipping_view = [[ChildClippingView alloc] initWithFrame:CGRectZero];
[clipping_view addSubview:touch_interceptor];
root_views_[viewId] = fml::scoped_nsobject<UIView>(clipping_view);

platform_views_[viewId] = PlatformViewData{
.view = fml::scoped_nsobject<NSObject<FlutterPlatformView>>(embedded_view), //
.touch_interceptor =
fml::scoped_nsobject<FlutterTouchInterceptingView>(touch_interceptor), //
.root_view = fml::scoped_nsobject<UIView>(clipping_view) //
};

result(nil);
}
Expand All @@ -269,7 +272,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
NSNumber* arg = [call arguments];
int64_t viewId = [arg longLongValue];

if (views_.count(viewId) == 0) {
if (platform_views_.count(viewId) == 0) {
result([FlutterError errorWithCode:@"unknown_view"
message:@"trying to dispose an unknown"
details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
Expand All @@ -285,14 +288,14 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
NSDictionary<NSString*, id>* args = [call arguments];
int64_t viewId = [args[@"id"] longLongValue];

if (views_.count(viewId) == 0) {
if (platform_views_.count(viewId) == 0) {
result([FlutterError errorWithCode:@"unknown_view"
message:@"trying to set gesture state for an unknown view"
details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
return;
}

FlutterTouchInterceptingView* view = touch_interceptors_[viewId].get();
FlutterTouchInterceptingView* view = platform_views_[viewId].touch_interceptor.get();
[view releaseGesture];

result(nil);
Expand All @@ -303,14 +306,14 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
NSDictionary<NSString*, id>* args = [call arguments];
int64_t viewId = [args[@"id"] longLongValue];

if (views_.count(viewId) == 0) {
if (platform_views_.count(viewId) == 0) {
result([FlutterError errorWithCode:@"unknown_view"
message:@"trying to set gesture state for an unknown view"
details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
return;
}

FlutterTouchInterceptingView* view = touch_interceptors_[viewId].get();
FlutterTouchInterceptingView* view = platform_views_[viewId].touch_interceptor.get();
[view blockGesture];

result(nil);
Expand Down Expand Up @@ -418,15 +421,16 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,

FlutterTouchInterceptingView* FlutterPlatformViewsController::GetFlutterTouchInterceptingViewByID(
int64_t view_id) {
if (views_.empty()) {
if (platform_views_.empty()) {
return nil;
}
return touch_interceptors_[view_id].get();
return platform_views_[view_id].touch_interceptor.get();
}

long FlutterPlatformViewsController::FindFirstResponderPlatformViewId() {
for (auto const& [id, root_view] : root_views_) {
if (((UIView*)root_view.get()).flt_hasFirstResponderInViewHierarchySubtree) {
for (auto const& [id, platform_view_data] : platform_views_) {
UIView* root_view = (UIView*)platform_view_data.root_view.get();
if (root_view.flt_hasFirstResponderInViewHierarchySubtree) {
return id;
}
}
Expand Down Expand Up @@ -590,7 +594,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
void FlutterPlatformViewsController::CompositeWithParams(int64_t view_id,
const EmbeddedViewParams& params) {
CGRect frame = CGRectMake(0, 0, params.sizePoints().width(), params.sizePoints().height());
FlutterTouchInterceptingView* touchInterceptor = touch_interceptors_[view_id].get();
FlutterTouchInterceptingView* touchInterceptor = platform_views_[view_id].touch_interceptor.get();
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
FML_DCHECK(CGPointEqualToPoint([touchInterceptor embeddedView].frame.origin, CGPointZero));
if (non_zero_origin_views_.find(view_id) == non_zero_origin_views_.end() &&
Expand All @@ -614,7 +618,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
touchInterceptor.alpha = 1;

const MutatorsStack& mutatorStack = params.mutatorsStack();
UIView* clippingView = root_views_[view_id].get();
UIView* clippingView = platform_views_[view_id].root_view.get();
// The frame of the clipping view should be the final bounding rect.
// Because the translate matrix in the Mutator Stack also includes the offset,
// when we apply the transforms matrix in |ApplyMutators|, we need
Expand All @@ -631,28 +635,20 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
}

void FlutterPlatformViewsController::Reset() {
std::vector<UIView*> views;
views.reserve(composition_order_.size());
for (int64_t view_id : composition_order_) {
views.push_back(root_views_[view_id].get());
}

fml::TaskRunner::RunNowOrPostTask(platform_task_runner_, [views = views]() {
for (auto* sub_view : views) {
[sub_view removeFromSuperview];
}
});

root_views_.clear();
touch_interceptors_.clear();
views_.clear();
composition_order_.clear();
slices_.clear();
current_composition_params_.clear();
clip_count_.clear();
views_to_recomposite_.clear();
layer_pool_->RecycleLayers();
visited_platform_views_.clear();

fml::TaskRunner::RunNowOrPostTask(
platform_task_runner_, [&, composition_order = composition_order_]() {
for (int64_t view_id : composition_order_) {
[platform_views_[view_id].root_view.get() removeFromSuperview];
}
platform_views_.clear();
});
}

bool FlutterPlatformViewsController::SubmitFrame(GrDirectContext* gr_context,
Expand All @@ -668,7 +664,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,

LayersMap platform_view_layers;
std::vector<SurfaceFrame::DeferredSubmit> callbacks;
auto did_submit = true;
bool did_submit = true;
std::unordered_map<int64_t, SkRect> view_rects;

for (int64_t view_id : composition_order_) {
Expand Down Expand Up @@ -730,8 +726,12 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
layer->did_submit_last_frame = frame->Submit();

did_submit &= layer->did_submit_last_frame;
platform_view_layers[view_id].push_back(
{.rect = overlay->second, .view_id = view_id, .overlay_id = overlay_id, .layer = layer});
platform_view_layers[view_id] = LayerData{
.rect = overlay->second, //
.view_id = view_id, //
.overlay_id = overlay_id, //
.layer = layer //
};
overlay_id++;
}

Expand All @@ -752,16 +752,14 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
views_to_recomposite = views_to_recomposite_, //
callbacks = std::move(callbacks), //
composition_order = composition_order_, //
unused_layers = std::move(unused_layers),
views_to_dispose = GetViewsToDispose() //
unused_layers = std::move(unused_layers) //
]() mutable {
PerformSubmit(platform_view_layers, //
callbacks, //
current_composition_params, //
views_to_recomposite, //
composition_order, //
unused_layers, //
views_to_dispose //
unused_layers //
);
};

Expand All @@ -778,7 +776,8 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,

auto missing_layer_count = required_overlay_layers - layer_pool_->size();

// Workaround for FLutterPlatformViewsTest
// If raster thread is merged because we're in a unit test or running on simulator, then
// we don't need to post a task to create an overlay layer.
if ([[NSThread currentThread] isMainThread]) {
// Create Missing Layers
for (auto i = 0u; i < missing_layer_count; i++) {
Expand Down Expand Up @@ -811,25 +810,23 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
std::map<int64_t, EmbeddedViewParams>& current_composition_params,
const std::unordered_set<int64_t>& views_to_recomposite,
const std::vector<int64_t>& composition_order,
const std::vector<std::shared_ptr<FlutterPlatformViewLayer>>& unused_layers,
const std::vector<UIView*>& views_to_dispose) {
TRACE_EVENT0("flutter", "FlutterPlatformViewsController::SubmitFrame::CATransaction");
const std::vector<std::shared_ptr<FlutterPlatformViewLayer>>& unused_layers) {
TRACE_EVENT0("flutter", "FlutterPlatformViewsController::PerformSubmit");
FML_DCHECK([[NSThread currentThread] isMainThread]);

[CATransaction begin];

// Configure Flutter overlay views.
for (const auto& [key, layers] : platform_view_layers) {
for (const auto& layer_data : layers) {
layer_data.layer->UpdateViewState(flutter_view_, //
layer_data.rect, //
layer_data.view_id, //
layer_data.overlay_id //
);
}
for (const auto& [key, layer_data] : platform_view_layers) {
layer_data.layer->UpdateViewState(flutter_view_, //
layer_data.rect, //
layer_data.view_id, //
layer_data.overlay_id //
);
}

// Dispose unused Flutter Views.
for (auto& view : views_to_dispose) {
for (auto& view : GetViewsToDispose()) {
[view removeFromSuperview];
}

Expand Down Expand Up @@ -857,7 +854,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
}

void FlutterPlatformViewsController::BringLayersIntoView(
LayersMap layer_map,
const LayersMap& layer_map,
const std::vector<int64_t>& composition_order) {
FML_DCHECK(flutter_view_);
UIView* flutter_view = flutter_view_.get();
Expand All @@ -866,11 +863,12 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
NSMutableArray* desired_platform_subviews = [NSMutableArray array];
for (size_t i = 0; i < composition_order.size(); i++) {
int64_t platform_view_id = composition_order[i];
std::vector<LayerData> layers = layer_map[platform_view_id];
UIView* platform_view_root = root_views_[platform_view_id].get();
UIView* platform_view_root = platform_views_[platform_view_id].root_view.get();
[desired_platform_subviews addObject:platform_view_root];
for (const auto& layer_data : layers) {
[desired_platform_subviews addObject:layer_data.layer->overlay_view_wrapper];

auto maybe_layer_data = layer_map.find(platform_view_id);
if (maybe_layer_data != layer_map.end()) {
[desired_platform_subviews addObject:maybe_layer_data->second.layer->overlay_view_wrapper];
}
previous_composition_order_.push_back(platform_view_id);
}
Expand Down Expand Up @@ -941,7 +939,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
// Remove unused platform views.
for (int64_t view_id : previous_composition_order_) {
if (composition_order_set.find(view_id) == composition_order_set.end()) {
UIView* platform_view_root = root_views_[view_id].get();
UIView* platform_view_root = platform_views_[view_id].root_view.get();
[platform_view_root removeFromSuperview];
}
}
Expand All @@ -961,14 +959,11 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
views_to_delay_dispose.insert(viewId);
continue;
}
UIView* root_view = root_views_[viewId].get();
UIView* root_view = platform_views_[viewId].root_view.get();
views.push_back(root_view);
views_.erase(viewId);
touch_interceptors_.erase(viewId);
root_views_.erase(viewId);
current_composition_params_.erase(viewId);
clip_count_.erase(viewId);
views_to_recomposite_.erase(viewId);
platform_views_.erase(viewId);
}
views_to_dispose_ = std::move(views_to_delay_dispose);
return views;
Expand Down
Loading