Fixes https://github.com/flutter/flutter/issues/156361
cc @lyceel. A bit of miscommunication on the priority of this one. I
thought the default font factories were sufficient for the next release.
But it turns out that was not true on the board which is a custom
platform.
In any case, this should unblock custom font registrations. See the
`CanCreateParagraphsWithCustomFont` case for an example. If you don't
provide the family name alias for the custom font, the name will be read
from the font data. This example uses the custom "WhatTheFlutter" custom
font family in "wtf.otf".
<img width="1136" alt="Screenshot 2024-10-17 at 1 26 36 PM"
src="https://github.com/user-attachments/assets/dbbef2fd-f854-4330-8c82-fc8378489769">
This reverts commit 0a9ed4763365f84be6f92f23abf13c778593715c.
This relands commit 530a9f896c3547fd5e27539e9049fae392d61e73.
That commit was a reland of a2ac734e10115547d8c8ef34610ea6172e3cc98b.
Migrates `FlutterEngine` from manual reference counting to ARC. Migrates properties from `retain` to strong and `assign` to `weak` (where referencing an Obj-C object).
This has the following change from the previous patch:
* startProfiler was updated to eliminate the self-capture in https://github.com/flutter/engine/pull/55957 which prevents the possibility of dealloc on the profiling thread.
No semantic changes, therefore no changes to tests.
Issue: https://github.com/flutter/flutter/issues/137801
Issue: https://github.com/flutter/flutter/issues/156177
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
iOS profiling is implemented in ProfileMetricsIOS, which has a default constructor, no member fields, and no superclass. i.e. it's roughly zero cost to create and holds no state. There's therefore no reason to make it an ivar on FlutterEngine.
Further, making it an ivar on FlutterEngine means that the profiling sampler lambda needs to capture self which, in the case where all other FlutterEngine references go out of scope during sampling, means that the last FlutterEngine reference exists on a profiling thread, and when the sampling lambda block completes, the engine is dealloc'ed.
The engine *must* be deallocated on the platform (main in Apple terminology) thread because FlutterEngine holds a reference to a PlatformViewsController, which owns a WeakPtrFactory. WeakPtrFactory's dtor asserts that it executes on the thread on which it was created, in this case, the platform thread. Further, the engine holds direct and indirect references to other UIKit objects such as `UITextInput` in FlutterTextInputPlugin, which must be dealloc'ed on the main thread.
Since there's no need for ProfileMetricsIOS to be tied to the engine, we now create it on the fly in the sampler.
No test changes because no semantic changes.
Uncovered by ARC migration.
Issue: https://github.com/flutter/flutter/issues/137801
Issue: https://github.com/flutter/flutter/issues/156177
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Reverts: flutter/engine#55939
Initiated by: jonahwilliams
Reason for reverting: failing on scenario test
Original PR Author: jonahwilliams
Reviewed By: {matanlurey}
This change reverts the following previous change:
Creating descriptor pools is expensive, no need to have more than one per frame.
The lifecycle of the descriptor pool is exactly the same as the cmd pool, which indicates that we can probably do some consolidation/refactoring in the future.
Fixes https://github.com/flutter/flutter/issues/157115
There are still a couple closures where on engine shutdown, the last
live reference to FlutterEngine may be on a thread other than the
platform thread.
Specifically, the profiling data capture callback can result in the last
live reference to a FlutterEngine being on a profiling thread, resulting
in an assertion failure in the destructor of the PlatformViewsController
held by FlutterEngine, because PlatformViewsController holds a
WeakPtrFactory whose destructor asserts that it be on the platform
thread.
See:
f0f29ce37f/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm (L511-L515)
Backtrace of such a crash:
```
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIView removeFromSuperview]
PID: 46919, TID: 333147, Thread name: FlutterEngine.166.profiler, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4 libios_test_flutter.dylib 0x000000014b658aed -[FlutterTextInputPlugin dealloc] + 27
5 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204
6 libios_test_flutter.dylib 0x000000014b63df5a -[FlutterEngine .cxx_destruct] + 135
7 libobjc.A.dylib 0x00007ff800035766 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83
8 libobjc.A.dylib 0x00007ff80004ddfc objc_destructInstance + 61
9 CoreFoundation 0x00007ff8004a286b -[NSObject(NSObject) __dealloc_zombie] + 159
10 libios_test_flutter.dylib 0x000000014b635fea -[FlutterEngine dealloc] + 334
11 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204
12 libios_test_flutter.dylib 0x000000014b63eda9 _ZNSt3_fl10__function6__funcIZ30-[FlutterEngine startProfiler]E3$_0NS_9allocatorIS2_EEFN7flutter13ProfileSampleEvEEclEv + 69
13 libios_test_flutter.dylib 0x000000014bcd8eaa _ZNSt3_fl10__function6__funcIZNK7flutter16SamplingProfiler16SampleRepeatedlyEN3fml9TimeDeltaEE3$_0NS_9allocatorIS6_EEFvvEEclEv + 40
14 libios_test_flutter.dylib 0x000000014b868786 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 156
15 libios_test_flutter.dylib 0x000000014b86ecca _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 26
16 CoreFoundation 0x00007ff8003ea4a5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
17 CoreFoundation 0x00007ff8003ea032 __CFRunLoopDoTimer + 801
18 CoreFoundation 0x00007ff8003e97b6 __CFRunLoopDoTimers + 243
19 CoreFoundation 0x00007ff8003e4028 __CFRunLoopRun + 2108
20 CoreFoundation 0x00007ff8003e3409 CFRunLoopRunSpecific + 557
21 libios_test_flutter.dylib 0x000000014b86ee07 _ZN3fml17MessageLoopDarwin3RunEv + 65
22 libios_test_flutter.dylib 0x000000014b8686a4 _ZN3fml15MessageLoopImpl5DoRunEv + 22
23 libios_test_flutter.dylib 0x000000014b86dce5 _ZNSt3_fl10__function6__funcIZN3fml6ThreadC1ERKNS_8functionIFvRKNS3_12ThreadConfigEEEES7_E3$_0NS_9allocatorISC_EEFvvEEclEv + 135
24 libios_test_flutter.dylib 0x000000014b86da87 _ZZN3fml12ThreadHandleC1EONSt3_fl8functionIFvvEEEEN3$_08__invokeEPv + 27
25 libsystem_pthread.dylib 0x000000010d6a818b _pthread_start + 99
26 libsystem_pthread.dylib 0x000000010d6a3ae3 thread_start + 15
2024-10-18 09:31:27.549111-0700 IosUnitTests[46919:333147] [reports] Main Thread Checker: UI API called on a background thread: -[UIView removeFromSuperview]
PID: 46919, TID: 333147, Thread name: FlutterEngine.166.profiler, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4 libios_test_flutter.dylib 0x000000014b658aed -[FlutterTextInputPlugin dealloc] + 27
5 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204
6 libios_test_flutter.dylib 0x000000014b63df5a -[FlutterEngine .cxx_destruct] + 135
7 libobjc.A.dylib 0x00007ff800035766 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83
8 libobjc.A.dylib 0x00007ff80004ddfc objc_destructInstance + 61
9 CoreFoundation 0x00007ff8004a286b -[NSObject(NSObject) __dealloc_zombie] + 159
10 libios_test_flutter.dylib 0x000000014b635fea -[FlutterEngine dealloc] + 334
11 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204
12 libios_test_flutter.dylib 0x000000014b63eda9 _ZNSt3_fl10__function6__funcIZ30-[FlutterEngine startProfiler]E3$_0NS_9allocatorIS2_EEFN7flutter13ProfileSampleEvEEclEv + 69
13 libios_test_flutter.dylib 0x000000014bcd8eaa _ZNSt3_fl10__function6__funcIZNK7flutter16SamplingProfiler16SampleRepeatedlyEN3fml9TimeDeltaEE3$_0NS_9allocatorIS6_EEFvvEEclEv + 40
14 libios_test_flutter.dylib 0x000000014b868786 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 156
15 libios_test_flutter.dylib 0x000000014b86ecca _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 26
16 CoreFoundation 0x00007ff8003ea4a5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
17 CoreFoundation 0x00007ff8003ea032 __CFRunLoopDoTimer + 801
18 CoreFoundation 0x00007ff8003e97b6 __CFRunLoopDoTimers + 243
19 CoreFoundation 0x00007ff8003e4028 __CFRunLoopRun + 2108
20 CoreFoundation 0x00007ff8003e3409 CFRunLoopRunSpecific + 557
21 libios_test_flutter.dylib 0x000000014b86ee07 _ZN3fml17MessageLoopDarwin3RunEv + 65
22 libios_test_flutter.dylib 0x000000014b8686a4 _ZN3fml15MessageLoopImpl5DoRunEv + 22
23 libios_test_flutter.dylib 0x000000014b86dce5 _ZNSt3_fl10__function6__funcIZN3fml6ThreadC1ERKNS_8functionIFvRKNS3_12ThreadConfigEEEES7_E3$_0NS_9allocatorISC_EEFvvEEclEv + 135
24 libios_test_flutter.dylib 0x000000014b86da87 _ZZN3fml12ThreadHandleC1EONSt3_fl8functionIFvvEEEEN3$_08__invokeEPv + 27
25 libsystem_pthread.dylib 0x000000010d6a818b _pthread_start + 99
26 libsystem_pthread.dylib 0x000000010d6a3ae3 thread_start + 15
IosUnitTests(47009,0x10ec76240) malloc: enabling scribbling to detect mods to free blocks
IosUnitTests(47009) MallocStackLogging: could not tag MSL-related memory as no_footprint, so those pages will be included in process footprint - (null)
IosUnitTests(47009) MallocStackLogging: stack logs being written to /private/tmp/stack-logs.47009.1057b6000.IosUnitTests.0o4HgN.index
IosUnitTests(47009) MallocStackLogging: recording malloc and VM allocation stacks to disk using standard recorder
IosUnitTests(47009) MallocStackLogging: process 46919 no longer exists, stack logs deleted from /tmp/stack-logs.46919.10d1fc000.IosUnitTests.kFionm.index
```
This reverts commit 530a9f896c3547fd5e27539e9049fae392d61e73.
## Pre-launch Checklist
- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I signed the [CLA].
- [X] All existing and new tests are passing.
If you need help, consider asking for advice on the #hackers-new channel
on [Discord].
<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
Creating descriptor pools is expensive, no need to have more than one per frame.
The lifecycle of the descriptor pool is exactly the same as the cmd pool, which indicates that we can probably do some consolidation/refactoring in the future.
Fixes https://github.com/flutter/flutter/issues/157115
Introduces a mechanism to allow backdrop filters to 1) share backdrop inputs and 2) fuse filter applications for faster blurs.
This is a proposed solution to https://github.com/flutter/flutter/issues/131568
Implemented:
* Developer can specify a "backdrop id" which indicates that a backdrop layer should share the input texture and potentially cached filter for a layer.
* Removes second save layer for each backdrop filter
* Removes save layer trace event for backdrop filter
* Can fuse backdrop filters if there is more than one identical filter
TBD:
* Adjust heruristic to avoid applying bdf filter to entire screen
Suggestions: applying a bdf should be a distinct operation from a save layer in the DL builder/dispatcher. The saveLayer implmenentation in the impeller dispatcher is super convoluted because it needs to handle both.
### Video
Video starts with normal bdf then I hot reload to specify that the bdfs share inputs/filters. This is running on a pixel 8 pro
Change to the macrobenchmark app is just:
```dart
Widget build(BuildContext context) {
Widget addBlur(Widget child, bool shouldBlur) {
if (shouldBlur) {
return ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
backdropId: 1, // Added ID
child: child,
),
);
} else {
return child;
}
}
```
https://github.com/user-attachments/assets/22707f97-5825-43f1-91b4-1a02a43437f5
Requires framework changes in https://github.com/jonahwilliams/flutter/pull/new/backdrop_id
Shell::OnPlatformViewDispatchPlatformMessage is called on the platform thread and must invoke the message handler on the UI thread. If the platform and UI threads are merged, then the handler can be run immediately. The shell can then post an empty task to the UI thread to make the UI message loop run the task observer that drains the microtask queue.
Fixes https://github.com/flutter/flutter/issues/156595
Avoid Sprintf'ing labels for textures/cmd buffers/render passes. For the render target textures, defer combined label construction until we know the label will be used.
From local testing:
1. This is slightly faster
2. This still renders correctly even on old phones (S10)
3. This is validation error clean.
---------------
The vk RenderPass has a built in mechanism to transition the attachments between layout states. Since we expect the images to be in eGeneral layout, we can configure the render pass to do an eUnderfined -> eGeneral transition. eUnderfined means "we don't care what was here before". This is OK because we're about to clear the texture anyway.
Since the RenderPass is doing the transition, we don't need an explicit barrier. All we have to do is update our own state tracking mechanism that the image attachments should behave as if they were in eGeneral layout - because they are once the render pass is started.
Events can only be redispatched using gdk_event_put which is not
dependent on the view.
Ideally the tests would mock gdk_event_put, but I wasn't able to get it
working so I've added fl_keyboard_manager_set_redispatch_handler for
now.
This reverts commit 773c37ab825da3b2870f1c8e9ccc74b84bcd3899.
This relands commit a2ac734e10115547d8c8ef34610ea6172e3cc98b.
Migrates `FlutterEngine` from manual reference counting to ARC. Migrates properties from `retain` to strong and `assign` to `weak` (where referencing an Obj-C object).
Includes two additional fixes on top of the original:
* In `waitForFirstFrame:callback:` we ensure FlutterEngine isn't released on a background thread, but instead is always freed on the platform thread.
* In `testViewControllerIsReleased` we call loadView prior to calling `viewDidLoad`. `viewDidLoad` calls `[FlutterEngine attachView]` which calls `[PlatformViewIOS::attachView]` which asserts that the view is loaded.
No semantic changes, therefore no changes to tests.
Issue: https://github.com/flutter/flutter/issues/137801
Issue: https://github.com/flutter/flutter/issues/156177
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Many of our labeling APIs accepted a std::string. When provided with a string literal (const char*), this would force the allocation of a new std::string object and a copy of the original char*. std::string_view is a view of either a std::string, or a const char* (or other), which allows an API that doesn not need to store the string to accept both without a copy. Of course, we can't store a std::string_view, as that doesn't provide memory ownership - so many of the GLES implementations will still copy the string_view into a string locally.
Also updates several of the debug labelling functions to no-op in release mode and removes some expensive interpolations that aren't super necessary.
Reverts: flutter/engine#55906
Initiated by: zanderso
Reason for reverting: b/373907578
Original PR Author: devoncarew
Reviewed By: {zanderso}
This change reverts the following previous change:
The SoT repository for `package:file` has changed from google/file.dart to dart-lang/tools; this PR updates the DEPS file and the hard-coded paths in the two pubspec.yaml files.
- https://github.com/dart-lang/tools/issues/674
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Fixes [#146251](https://github.com/flutter/flutter/issues/146251).
On Windows, a "pointer add" event to a new view is sometimes sent before the "pointer remove" event from the old view. When `PointerDataPacketConverter` handles the add event, it asserts that the device's pointer state has been cleared. Since the pointer state is cleared only when the remove event is processed, the assertion fails if the events arrive out of order.
The solution proposed here is to synthesize a remove event if an add event is received while the pointer state hasn't been cleared (i.e., if the pointer is added without being removed from the previous view).
To avoid duplicate remove events, the view ID is now tracked in `PointerState`. If the original "remove" arrives after the synthesized one, the state's view ID will differ from the pointer data's view ID, allowing it to be safely ignored.
When synthesizing the remove event, it's possible that the old view has already been destroyed, meaning no remove event will be received later. For example, this occurs when a window is destroyed while the pointer is inside it. However, the framework expects an "add" event to always follow a "remove" event, and "remove" events with invalid views are ignored. To meet the framework's expectations, the view ID of the "add" event will be used for the "remove" event if the old view has been destroyed.
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style