6374 Commits

Author SHA1 Message Date
Robert Ancell
90c1f8ca69 Migrate FlBinaryMessenger using embedder API instead of mock engine. (flutter/engine#57214)
This allows us to remove most of the remaining mock engine code.
2024-12-16 20:02:45 +00:00
MyriadSoft
475d981108 docs: Fix RGB565 format documentation and bit masks (flutter/engine#57210)
The RGB565 format documentation in embedder.h incorrectly stated that the red component uses the least significant bits. Unit tests in embedder/testdefs/embedder_unittests.cc demonstrate this is incorrect, showing:

- Red test (0xF800): Uses bits [15:11]
- Green test (0x07E0): Uses bits [10:5]
- Blue test (0x001F): Uses bits [4:0]

This commit fixes the documentation to correctly reflect the actual bit layout:
- Red uses 5 MSBs [15:11]
- Green uses 6 middle bits [10:5]
- Blue uses 5 LSBs [4:0]

Also fixes the example bit extraction code to use correct masks, matching the test expectations.

Impact: This change helps prevent potential developer confusion about RGB565 bit ordering and ensures the documentation matches the actual implementation as verified by the test suite.
2024-12-16 18:48:04 +00:00
Robert Ancell
eb4af9071e Migrate FlEventChannel tests to FlMockBinaryMessenger (flutter/engine#57150)
Use FlMockBinaryMessenger instead of mocking the whole engine.
2024-12-16 11:45:17 +13:00
Robert Ancell
dcd093fad7 Migrate FlMethodChannel tests to FlMockBinaryMessenger (flutter/engine#57146)
Use FlMockBinaryMessenger instead of mocking the whole engine.
2024-12-16 10:34:14 +13:00
Michael Goderbauer
a0eb1bc42c Fix include path in fuchsia's analysis_options.yaml files (flutter/engine#57203)
The old path doesn't exist.

`dart format` stumbles over this non-existent include.

`analysis_options.yaml` files that just imported something non-existent were deleted.

I am surprised that this never caused any other issues. Is this all dead code that isn't actually analyzed?
2024-12-14 00:51:47 +00:00
hellohuanlin
e2970df999 [ios]limit web view not tappable workaround to a limited depth (flutter/engine#57193)
This PR limits the search depth, because we don't want to enable this workaround for AdMob banner, which has a WKWebView in the depth of 7. See the previous PR for more context: https://github.com/flutter/engine/pull/57168

I was able to confirm that this returns YES for the 3P plugin, and NO for AdMob. 

*List which issues are fixed by this PR. You must list at least one issue.*
https://github.com/flutter/flutter/issues/158961

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-12-13 19:25:25 +00:00
Jim Graham
c1b3709bdd Migrate DlRTree and DlRegion to DisplayList/Impeller geometry classes (flutter/engine#57175)
Continuing the migration of engine code to the new geometry classes. Only DlRTree and DlRegion are converted in this pass, plus a small amount of associated code.
2024-12-13 04:33:17 +00:00
hellohuanlin
f9125dfd91 [ios]enable the webview non tappable workaround by checking subviews recursively (flutter/engine#57168)
The original workaround ([PR](https://github.com/flutter/engine/pull/56804)) works for the official web view plugin, but it doesn't work for a third party plugin `flutter_inappwebview` ([issue](https://github.com/pichillilorenzo/flutter_inappwebview)). Upon discussion with the author of that plugin, it turns out that their platform view is not a WKWebView, but rather a wrapper of WKWebView. 

This PR performs a DFS search of the view hierarchy, and enable the workaround as long as there's a WKWebView inside. 

TODO: pending sample project:
I am quite positive that it should work, but **I haven't tried it since I don't have a sample project yet**. I have requested a sample project with them so I can verify the solution. 

*List which issues are fixed by this PR. You must list at least one issue.*

 https://github.com/pichillilorenzo/flutter_inappwebview/issues/2415

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-12-13 01:06:45 +00:00
gaaclarke
3d8fc3c652 removed c style casts and enabled the lint (flutter/engine#57162)
test exempt: should have no functional change

## 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/blob/master/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/engine/blob/main/docs/testing/Testing-the-engine.md
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
2024-12-12 15:33:37 -08:00
Robert Ancell
d9cdbeebea Make fl_engine_send_key_event into a standard async function. (flutter/engine#57112)
Add missing tests for this function.

Note this makes FlKeyboardManager a bit more complex, but this is
planned to be simplified in a future refactor.
2024-12-13 09:21:00 +13:00
Robert Ancell
50a40b310e Migrate FlPlatformChannel tests to FlMockBinaryMessenger (flutter/engine#57140)
Use FlMockBinaryMessenger instead of mocking the whole engine.
2024-12-13 08:40:13 +13:00
Robert Ancell
3a54460518 Migrate FlBasicMessageChannel tests to FlMockBinaryMessenger (flutter/engine#57115)
Use FlMockBinaryMessenger instead of mocking the whole engine.
2024-12-13 08:38:53 +13:00
Jim Graham
9af7a2a64d Migrate layers and layer_tree to DisplayList/Impeller geometry classes (flutter/engine#57153)
Migrates Layers and LayerTree and parts of the `flow/` utility classes to use DlGeometry (Impeller) classes.
2024-12-12 19:30:55 +00:00
Chris Bracken
e9965b2d07 iOS: Reduce engine/view controller coupling (flutter/engine#57151)
Eliminates some cases where `FlutterViewController` was relying on `FlutterEngine` internals:
* `[FlutterEngine shell]`
* `[FlutterEngine platformView]`
* `[FlutterEngine iosPlatformView]`

Instead, `FlutterEngine` now exposes:
* `installFirstFrameCallback:`
* `enableSemantics:withFlags:`
* `notifyViewCreated`
* `notifyViewDestroyed`
* `waitForFirstFrameSync:callback:`

Also fixes a couple cases where we were relying on transitive header includes:
* `FlutterAppController` relied on `FlutterViewController_Internal.h` for `sendDeepLinkToFramework:completionHandler:`

This is a refactoring followup to https://github.com/flutter/engine/pull/57099 that introduces no semantic changes.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-12-12 18:38:07 +00:00
Bryan Oltman
4eb0bd7d98 Cast ::GetLastError to int (flutter/engine#57113)
`GetLastError` returns an unsigned 32 bit integer that was being
implicitly cast to an int for the std::variant<..., int>. This was
causing my build to fail with:

```
../../flutter/shell/platform/windows/platform_handler.cc(178,12): error: no viable conversion from returned value of type 'DWORD' (aka 'unsigned long') to function return type 'std::variant<std::wstring, int>' (aka 'variant<basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>>, int>')
  178 |     return ::GetLastError();
      |            ^~~~~~~~~~~~~~~~
../../../../../../../Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.42.34433/include\variant(923,7): note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'DWORD' (aka 'unsigned long') to 'const variant<basic_string<wchar_t>, int> &' for 1st argument
  923 | class variant : private _SMF_control<_Variant_destroy_layer<_Types...>, _Types...> { // discriminated union
      |       ^~~~~~~
```

Commands:

```
 ./flutter/tools/gn --runtime-mode release --no-rbe
ninja -C .\out\host_release windows gen_snapshot flutter/build/archives:windows_flutter
```

Explicitly casting `::GetLastError` to an int fixes this issue.

I'm running on Windows 11 (Version 10.0.26100 Build 26100) with VS 2022
Community Edition.

@loic-sharma

Co-authored-by: Eric Seidel <eric@shorebird.dev>
2024-12-11 17:23:11 -08:00
Balint Rozgonyi
41009bcda1 [Linux] Add Multi-Touch Support for Linux (flutter/engine#54214)
This draft PR aims to address the lack of multi-touch support under Linux, leveraging the existing implementation used for Windows. As I am not an expert in this domain, I would greatly appreciate feedback on the implementation.

https://github.com/flutter/flutter/issues/133239
https://github.com/flutter/flutter/issues/52202

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-12-11 22:05:04 +00:00
Jonah Williams
f8a0105146 [engine] changes to DlVertices::Builder and Stopwatch visualizer. (flutter/engine#57031)
Collection of changes to DlVertices::Builder and the stopwatch visualizer.

At a high level:

* improve performance of the stopwatch visualizer by pre-allocating storage (and sharing it across both visualizers), lookup up font once, and cache the debug frame rate used. Updates to use Dl types instead of SkTypes.

* Change DlVerticesBuilder to allow storing the bounds and use that in the visualizer, since we already know them. Make FML_CHECKS into dchecks, as the dart:ui vertices will already bounds check correctly - so these should only be necessary for debugging engine changes.
2024-12-11 21:03:06 +00:00
Robert Ancell
85b89155d5 Clean up key embedder responder tests (flutter/engine#57054)
Remove global variable.
Rename function so doesn't look like provided by GLib.
Use g_autoptr to remove explicit unref.
Move type definition inline.
2024-12-11 10:58:22 +13:00
Chris Bracken
721eec4d5b iOS: Add null checks on shell dereference (flutter/engine#57099)
`FlutterEngine` at the `_shell` unique_ptr ivar it owns have different lifetimes. `_shell` is initialised transitively from `runWithEntrypoint`, and reset in `[FlutterEngine destroyContext]`, which is called transitively from `[FlutterviewController dealloc]` via `[FlutterEngine notifyViewControllerDeallocated]`.

As such, all uses of `_shell` should be checked either via an assertion, in cases we know the shell should be non-null, or via a runtime null check in cases where it's expected that it may be null.

Specifically, this guards against a crash that can occur if we get a CoreAnimation transaction commit callback for an inflight frame just as we're shutting down the app (or removing the FlutterView in an add-to-app scenario).

Example stack trace:
```
0  Flutter                        0x11b28 -[FlutterEngine platformView] + 53 (weak_ptr.h:53)
1  Flutter                        0x11994 -[FlutterEngine updateViewportMetrics:] + 186 (ref_ptr.h:186)
2  Flutter                        0x1f854 -[FlutterViewController updateViewportMetricsIfNeeded] + 427 (vector:427)
3  Flutter                        0x1f9b8 -[FlutterViewController viewDidLayoutSubviews] + 1411 (FlutterViewController.mm:1411)
4  UIKitCore                      0x8c864 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2376
5  QuartzCore                     0x1fa0c CA::Layer::layout_if_needed(CA::Transaction*) + 516
6  QuartzCore                     0x1ae84c CA::Context::commit_transaction(CA::Transaction*, double, double*) + 516
7  QuartzCore                     0x2888 CA::Transaction::commit() + 648
```

Issue: https://github.com/flutter/flutter/issues/98735
Issue: https://github.com/flutter/flutter/issues/159639

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-12-10 19:06:13 +00:00
Brandon Castellano
9d726bb38e [engine] Migrate fuchsia.io Open functions to Open3 (flutter/engine#56818)
Migrate the use of fuchsia.io open functions to the new open3 replacements (which also requires transitioning from OpenFlags -> Flags). Likewise, we update all uses of the SDK VFS library to use the new set of flags.

This work is being done as part of the ongoing io2 migration in https://fxbug.dev/378924259

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-12-10 19:02:01 +00:00
Robert Ancell
f3c1d7bab8 Make fl_key_channel_responder_handle_event async (flutter/engine#56959)
Replace a callback with a more standard async call
2024-12-10 09:06:22 +13:00
Robert Ancell
8cc75a926e Cleanup refactoring in FlKeyboardManager (flutter/engine#56956)
Remove pending keyboard event ID and use the object directly.

Use references to make sure FlKeyboardManagerData is freed.

Refactor marking events as handled
2024-12-09 09:53:58 +13:00
hellohuanlin
13c0f5ad58 [ios][platform_view] workaround for non-tappable webview (flutter/engine#56804)
This is pretty tricky bug - I suspect that because Apple's internal recognizer caching an outdated state of our delaying recognizer. 

The conflict happens between WebKit and platform view's recognizers. It happens to all plugins that uses a WKWebView, or any view that has a similar (unknown) gesture setup. 

This fix has to be in the engine (rather than the plugin), because the plugin itself knows nothing about the existence of our delaying recognizer. 

Here are the steps of my research for future reference: 

1. The bug only happens when the overlay flutter widgets blocks the gestures for the platform view (e.g. tap on the platform view area when a flutter context menu is displayed). When the bug happens, WKWebView's link doesn't work anymore, however, the link can still be highlighted when tapped. 

2. When I remove the delaying recognizer from platform view, the link became clickable again. This means that the bug is related to some conflict between WKWebView's internal recognizers and our delaying recognizer. This also means that it is not possible to fix this issue at plugin level, which knows nothing about the delaying recognizer. 

3. When we tap on the web view when context menu is displayed, `blockGesture` will be called, which simply toggles delaying recognizer's state from `possible` to `ended` state, meaning it should block all recognizers from the current gesture (and it correctly did so). Then I use `dispatch_async` and check the state again, and confirmed the state is correctly reset to `possible` state. 

4. Subsequent tap on web view triggers `acceptGesture`, which turns the `possible` state into `failed` state. This subsequent tap only highlights the link, but not activate the link. This suggests that some internal web kit recognizer that handles the highlight sees the `failed` state of delaying recognizer (which is correct), but the recognizer that handles the link activation probably sees the stale state of `possible` or `ended` (which is outdated old state). 

5. So the solution is trying to make the recognizer "see" the updated state rather than the cached old state. 

6. I tried recreating a new delaying recognizer when `blockGesture` is called: 
```
- blockGesture {
  delayingRecognizer.state = .ended
  dispatch_async {
    // force re-create the delaying recognizer
  }
}
```
This fixed the link activation bug, however, when opening the context menu again, the gesture is not blocked anymore. This means web kit internal recognizers likely cache the old delaying recognizer for state update, thus the new instance of delaying recognizer won't work anymore. So we can't change the instance. However, it's a good experiment that confirms my hypothesis that some internal webkit recognizer caches the outdated state of delaying recognizer. 

7. For the above code, rather than using `dispatch_async`, I also tried `dispatch_after`, and it turns out that it only works if the dispatch_after delay is `0` - even if the delay is much smaller than 1 frame's time (16.7ms), it doesn't work. This means the state checking happens either at the end of the current run loop, or beginning of the next run loop. (not too important information, but it helps me better understand how UIKit works). 

8. So from 6, we know that we have to keep the original instance of delaying recognizer. I tried toggling `recognizer.enabled`, it didn't work. I also tried inserting a dummy recognizer, it didn't work. Neither approach triggers the state "refresh" for those webkit internal recognizers. 

9. I tried removing and adding back the delaying recognizer, and it just worked! This means that removing and adding back the delaying recognizer probably triggered UIKit to refresh the states for all its related recognizers (i.e. those recognizers either blocking or being blocked by the delaying recognizer), hence getting the updated state. 

*List which issues are fixed by this PR. You must list at least one issue.*

Fixes https://github.com/flutter/flutter/issues/158961

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-12-06 21:43:54 +00:00
Chris Bracken
f5db949a32 iOS: add null check on create impeller context (flutter/engine#56952)
In the case where `CreateImpellerContext` encounters an error while creating an `impeller::ContextMTL`, we logged an error, returned nullptr, then immediately dereferenced the null pointer. Now, rather than crash due to a segfault, we now intentionally abort with an appropriate error message.

This adds checks in the `FlutterDarwinContextMetalImpeller` initialiser that aborts with an appropriate error message if impeller context creation fails, Metal device creation fails, or texture cache creation fails.

Rather than bailing out and returning nil from the initialiser to pass the buck to the caller, we terminate since without a graphics context, the app won't be able to render anything to begin with.

Issue: https://github.com/flutter/flutter/issues/157489
Issue: [b/378790930](http://b/378790930)

No test changes since this just changes an accidental crash to an intentional crash.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-12-06 19:32:25 +00:00
Michael Goderbauer
75f9549553 Bump Dart SDK to 3.7 (flutter/engine#56989) 2024-12-06 01:41:03 +00:00
Jonah Williams
2e80dbea2c [Impeller] create a 300 es variant of all GLES shaders to support UBO binding. (flutter/engine#56960)
Create a GLES3 "backend" by compiling a second set of GLES shaders to 300 es. This allows the usage of UBOs and SSBOs.
2024-12-05 20:56:16 +00:00
Robert Ancell
fd12f3489c Remove LSAN supressions for Linux embedder (flutter/engine#56913)
Fixes https://github.com/flutter/flutter/issues/90155
2024-12-05 11:44:08 +13:00
Robert Ancell
4bcd6a93a1 Remove unused constant (flutter/engine#56929) 2024-12-04 15:21:48 +13:00
Gray Mackall
ec896de5c4 [Android] Save back handling state in Activity/Fragment bundle (flutter/engine#56715)
Fixes https://github.com/flutter/flutter/issues/159158, and fixes b/355556397

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-12-04 01:07:27 +00:00
Robert Ancell
dcc250c8a5 Split keyevent channel into own class (flutter/engine#56911)
Split the channel messaging out of the system channels to make them
simpler to understand and refactor.

The new channel classes could be automatically generated in a second
phase, e.g. using Pigeon to reduce code usage.
    
The new classes don't have tests as they will already be covered by the
existing code.
2024-12-04 11:57:05 +13:00
Robert Ancell
d1777a3abd Add tests for errors encoding message channel request and method calls. (flutter/engine#56914)
Fix error not being copied in this case.

Follow up to https://github.com/flutter/engine/pull/56856
2024-12-04 10:39:46 +13:00
Robert Ancell
14ae687eac Make a mock messenger that can easily mock channels (flutter/engine#56867)
The previous mock required knowing the specific functions used in the
binary messenger, this method instead allows test code to provide
complete platform channel implementation for testing and make simulated
platform channel calls into embedder code.
2024-12-03 13:41:33 +13:00
Robert Ancell
983837c311 Fix GTask reference counting (flutter/engine#56866)
Incorrect reference counting of GTask objects meant platform channel
method calls would leave tasks alive that would leak memory and leave
unclosed references to the binary messenger.
2024-12-03 13:37:31 +13:00
LongCatIsLooong
18cf7ae0a7 Reland "[iOS] Full keyboard access scrolling (#56606)" (flutter/engine#56842)
Reverts flutter/engine#56802

https://github.com/flutter/flutter/pull/159517 should address the engine roll failure.

I'm not planning to land this until the coming Monday.
2024-12-02 21:53:21 +00:00
Robert Ancell
aa01970589 Always check for errors when propagating task values. (flutter/engine#56856)
This could occur if a request is cancelled, without this it might not chain up to the original caller correctly.
2024-12-02 21:47:06 +00:00
richardexfo
c62bbc18ad Fix linux on vivante drivers. (flutter/engine#56862)
The same problem with NVIDIA drivers which causes issue [152099](https://github.com/flutter/flutter/issues/152099) occurs with Vivante Corporation drivers.

Quick fix for issue on Vivante drivers:  
https://github.com/flutter/flutter/issues/152099

- [ 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.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-12-02 21:16:22 +00:00
Chris Bracken
f988f524fe iOS: Apply nullability annotations to FlutterPlatformViewsController (flutter/engine#56839)
Applies non-null by default annotations to
FlutterPlatformViewsController with opt-outs where necessary. Updates unit tests to create graphics contexts where requried.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-28 17:44:23 +00:00
LN Liberda
daed210840 IWYU: add some missing includes failing with libstdc++13/14 (flutter/engine#56822)
Fixes builds of engine with libstdc++13 and libstdc++14.

*List which issues are fixed by this PR. You must list at least one issue.*
closes https://github.com/flutter/flutter/issues/159513

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-27 20:11:17 +00:00
Chris Bracken
fb558d9867 Reland: iOS: Eliminate global in platformviews controller (flutter/engine#56831)
This is a minor refactoring that moves a global bool to a boolean ivar in FlutterPlatformViewsController. The purpose of this variable is simply to avoid the overhead of trying to create backdrop filters if we've ever failed to create one in the past.

Given that this class will only ever have the one instance created and held by per engine with the same duration, and that most apps only ever have one engine, the performance win will be identical for most apps. For the few add-to-app cases with multiple engines either at once or over the course of an app's lifetime, the costs associated with firing up an engine are already a far bigger hit than those being saved by this bool.

Also migrates from C++ style namespace { ... } to Obj-C style static functions. These are entirely equivalent as both restrict symbols to the current translation unit.

This is a reland of https://github.com/flutter/engine/pull/56805, which was reverted as part of https://github.com/flutter/engine/pull/56817.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-27 15:32:16 +00:00
Chris Bracken
263fb587b7 Reland: iOS: Delete FlutterPlatformViewsController.layerPoolSize (flutter/engine#56830)
This field is unused in the codebase/tests.

This is a reland of https://github.com/flutter/engine/pull/56806, which was reverted as part of https://github.com/flutter/engine/pull/56790.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-27 06:29:24 +00:00
Chris Bracken
2afb790cad Reland: iOS: Migrate PlatformViewsController to Objective-C (flutter/engine#56828)
This migrates PlatformViewController from C++ to Objective-C. Generally, we try to keep the embedder interfaces and components written in Objective-C except for the few places where C++ interfaces are requried to interface with engine APIs such as Shell and PlatformView (e.g. the PlatformViewIOS subclass). Now that the implementation is Objective-C, the class and file are renamed to match Objective-C naming conventions.

This allows us to take advantage of ARC and weak references, which eliminates the need for std::shared_ptr, fml::WeakPtr etc. Further, this eliminates some particularly unintuitive behaviour wherein this class was owned via a std::shared_ptr held by FlutterEngine, and injected into many other classes (e.g. AccessibilityBridge) via a std::shared_ptr& reference -- such that only one instance of the std::shared_ptr actually ever existed, presumably to avoid std::shared_ptr refcounting overhead. Given that this overhead was only incurred a single time at engine initialisation, this seems like overkill. One might ask why it wasn't therefore held in a `std::unique_ptr` and a `std::unique_ptr&` reference passed around. Likely, this was because we wanted to take a `fml::WeakPtr` reference on it.

Regardless, none of this is necessary any longer now that we can inject `__weak FlutterPlatformViewsController*` instances to classes that use it.

To be clear, this patch makes no attempt whatsoever to simplify or clean up the interface or implementation of this class. This class ties together far too many concepts and is injected into far too many places, and we should break it up and simplify it. However, the goal of this patch was simply to port to an Objective-C interface that plays nicely with the rest of the iOS embedder. This does include a couple minor cleanups in `#include`/`#import` order and usage to match our style guide.

This is a reland with a one-line fix of a lambda-capture block to ensure `self` and any local variables are captured by value rather than by reference:
* In the case where this method is called on the platform thread (i.e. where the UI and platform thread are merged), we use the latch to pause the calling thread until the lambda completes, in which case all locals could be passed by reference since the locals are guaranteed to hang around until the lambda completes and signals the latch.
* In the case where this method is called from the UI thread (i.e. where UI and platform thread are not merged), locals may have gone out of scope by the time the lambda executes, leading to undefined behaviour if passed by reference; thus we always pass by value to be sure; since `latch` must be shared between threads, it's passed held in a `std::shared_ptr` so the underlying latch/mutex is shared but it's kept live until it goes out of scope in both threads.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-27 04:11:25 +00:00
Jim Graham
0c245ce56b [DisplayList] Delete (publicly) unused DlColorColorSource (flutter/engine#56825)
While recently updating the DlColorSource sources I noticed some questionably implementation choices in the Color variant of the color sources.

I then realized that there was no public use of these classes (other than mostly their own unit tests) and so they should be deleted to focus on implementing the variants that are actually used by Flutter.
2024-11-27 00:13:22 +00:00
Jonah Williams
fb62aa5d47 [engine] reland: more consistently flush message loops tasks (flutter/engine#56815)
Changes the following shell callbacks to flush the dart event loop:

* OnPlatformViewSetViewportMetrics
* OnPlatformViewDispatchPointerDataPacket
* OnPlatformViewDispatchPlatformMessage
* OnPlatformViewSetSemanticsEnabled
* OnPlatformViewSetAccessibilityFeatures
Using a new TaskRunner API RunNowAndFlushMessages. If the task runner can run tasks on the current thread, this will immediately invoke a callback and then post an empty task to the event loop to ensure dart listeners fire.

Unlike https://github.com/flutter/engine/pull/56738, does not touch the vsync API - which looks like it depends on scheduling behavior today, at least for iOS.
2024-11-26 22:34:00 +00:00
Chris Bracken
52661e51c0 Revert "iOS: Migrate PlatformViewsController to Objective-C (#56790)" (flutter/engine#56817)
This is a combination of 3 reverts, required to get back to the revert that caused `ios_platform_view_tests` to start failing in the framework repo. In reverse chronological order, this reverts two trivial commits plus the non-trivial commit that likely caused the breakage:

* Revert "iOS: Eliminate global in platformviews controller (#56805)" This reverts commit cea4600caa7098fa7ec109d18b869db46cda726a.
* Revert "iOS: Delete FlutterPlatformViewsController.layerPoolSize (#56806)" This reverts commit 80fa8a590876e0d29055b9ddbfa8670c1f83759e.
* Revert "iOS: Migrate PlatformViewsController to Objective-C (#56790)" This reverts commit afd05afc406deb79fbe9c16684aeeeb19322b288.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-26 19:52:13 +00:00
Chris Bracken
61d0019469 iOS: Rename FlutterPlatformViews_Internal.mm (flutter/engine#56816)
Objective-C files should be named to match their header, in this case, //flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h.

When private API is required, we often create a header named FlutterFoo_Internal.h, but the implementation file is always just FlutterFoo.mm. This brings FlutterPlatformViews back into line with convention.

No test changes since this is just a file rename.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-26 18:56:24 +00:00
Chris Bracken
cea4600caa iOS: Eliminate global in platformviews controller (flutter/engine#56805)
This is a minor refactoring that moves a global bool to a boolean ivar in FlutterPlatformViewsController. The purpose of this variable is simply to avoid the overhead of trying to create backdrop filters if we've ever failed to create one in the past.

Given that this class will only ever have the one instance created and held by per engine with the same duration, and that most apps only ever have one engine, the performance win will be identical for most apps. For the few add-to-app cases with multiple engines either at once or over the course of an app's lifetime, the costs associated with firing up an engine are already a far bigger hit than those being saved by this bool.

Also migrates from C++ style namespace { ... } to Obj-C style static functions. These are entirely equivalent as both restrict symbols to the current translation unit.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-26 18:28:15 +00:00
Chris Bracken
80fa8a5908 iOS: Delete FlutterPlatformViewsController.layerPoolSize (flutter/engine#56806)
This field is unused in the codebase/tests.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-26 05:23:09 +00:00
Chris Bracken
afd05afc40 iOS: Migrate PlatformViewsController to Objective-C (flutter/engine#56790)
This migrates PlatformViewController from C++ to Objective-C. Generally, we try to keep the embedder interfaces and components written in Objective-C except for the few places where C++ interfaces are requried to interface with engine APIs such as Shell and PlatformView (e.g. the PlatformViewIOS subclass). Now that the implementation is Objective-C, the class and file are renamed to match Objective-C naming conventions.

This allows us to take advantage of ARC and weak references, which eliminates the need for std::shared_ptr, fml::WeakPtr etc. Further, this eliminates some particularly unintuitive behaviour wherein this class was owned via a std::shared_ptr held by FlutterEngine, and injected into many other classes (e.g. AccessibilityBridge) via a std::shared_ptr& reference -- such that only one instance of the std::shared_ptr actually ever existed, presumably to avoid std::shared_ptr refcounting overhead. Given that this overhead was only incurred a single time at engine initialisation, this seems like overkill. One might ask why it wasn't therefore held in a `std::unique_ptr` and a `std::unique_ptr&` reference passed around. Likely, this was because we wanted to take a `fml::WeakPtr` reference on it.

Regardless, none of this is necessary any longer now that we can inject `__weak FlutterPlatformViewsController*` instances to classes that use it.

To be clear, this patch makes no attempt whatsoever to simplify or clean up the interface or implementation of this class. This class ties together far too many concepts and is injected into far too many places, and we should break it up and simplify it. However, the goal of this patch was simply to port to an Objective-C interface that plays nicely with the rest of the iOS embedder. This does include a couple minor cleanups in `#include`/`#import` order and usage to match our style guide.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-26 01:23:21 +00:00
auto-submit[bot]
57b102520b Reverts "[iOS] Full keyboard access scrolling (#56606)" (flutter/engine#56802)
Reverts: flutter/engine#56606
Initiated by: LongCatIsLooong
Reason for reverting: https://github.com/flutter/flutter/issues/159456
Original PR Author: LongCatIsLooong

Reviewed By: {chunhtai, cbracken}

This change reverts the following previous change:
This PR adds basic FKA scrolling support: when the iOS focus (the focus state is maintained separately from the framework focus, see the previous PR) switches to an item in a scrollable container that is too close to the edge of the viewport, the container will scroll to make sure the next item is visible. 

Previous PR for context: https://github.com/flutter/engine/pull/55964

https://github.com/user-attachments/assets/84ae5153-f955-4d23-9901-ce942c0e98ac

### Why the UIScrollView subclass in the focus hierarchy

The iOS focus system does not provide an API that allows apps to notify it of focus highlight changes. So if we were to keep using the transforms sent by the framework as-is and not introducing any UIViews in the focus hierarchy, the focus highlight will be positioned at the wrong location after scrolling (via FKA or via framework). That does not seem to be part of the public API and the focus system seems to only know how to properly highlight focusable UIViews.

### Things that currently may not work

1. Nested scroll views (have not tried to verify) 

The `UIScrollView`s are always subviews of the `FlutterView`. If there are nested scrollables the focus system may not be able to properly determine the focus hierarchy (in theory the iOS focus system should never depend on `UIView.parentView` but I haven't tried to verify that).

2. If the next item is too far below the bottom of the screen and there is a tab bar with focusable items, the focus will be transferred to tab bar instead of the next item in the list

Video demo (as you can see the scrolling is really finicky):

https://github.com/user-attachments/assets/51c2bfe4-d7b3-4614-aa49-4256214f8978

I've tried doing the same thing using a `UITableView` with similar configurations but it seems to have the same problem. I'll try to dig a bit deeper into this and see if there's a workaround.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-26 00:39:15 +00:00
Chris Bracken
a661e86e3f iOS: Eliminate logging of non-zero origin platformviews (flutter/engine#56796)
In flutter/engine#35501, handling was added to log a debug message to the console in the case where a platform view with a non-zero origin was identified.

Unfortunately:
* In unopt builds, the first thing we do in that block is to call FML_DCHECK asserting that the origin is zero, so we never actually emit the log statement.
* In opt builds, FML_DCHECK is a no-op, so users are unlikely to actually ever notice the crash.

The proper fix is to eliminate this restriction, but in the meantime, this eliminates this block entirely and leaves the TODO. We've had only two comments on that bug in the 2.5 years since it was added.

Issue: https://github.com/flutter/flutter/issues/109700

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-25 23:38:59 +00:00