Add `PlatformViewRoleManager`, the primary role manager for platform views. Currently, all it does is manager the `aria-owns` attribute that determines the screen reader traversal order of the platform view w.r.t. surrounding content.
This is a partial fix for https://github.com/flutter/flutter/issues/124765. While it does not address literally using the TAB key as a means for traversing widgets, it does address traversal via screen reader shortcuts.
Any user @staticInterop types should only subtype the dart:js_interop
types JSObject and or JSAny as user @staticInterop types erase to
JSObject.
In the future, the other JS types will be added as extension types,
allowing users to implement them with their own extension types.
Allows https://dart-review.googlesource.com/c/sdk/+/316865/1 to be
landed.
## 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.
- [ ] I added new tests to check the change I am making or feature I am
adding, or Hixie said 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].
- [ ] All existing and new tests are passing.
This PR is to add support for the expanded/collapsed-state semantics flag to the engine. After adding another PR to Flutter, we will be able to support the expanded/collapsed state in semantics for submenu buttons.
Related to [#127617](https://github.com/flutter/flutter/issues/127617) in flutter
A ~~simpler~~ very similar version of https://github.com/flutter/engine/pull/43854
* Makes it harder for users to accidentally remove default configuration values, while still allowing them to do so if needed (configuration is now overridden with a subset of values, rather than passing a full configuration object).
* Moves `merge` from the configuration object and into the override method.
* Removes a test-only configuration option:
* `window._flutter_canvaskit_variant_for_test_only`
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Some parts of the flutter engine are built using the latest version of the Dart SDK, ignoring SDK constraints in `pubspec.yaml` files. Therefore, before the Dart SDK can switch on the "private field promotion" feature (https://github.com/dart-lang/language/issues/2020), these parts of the flutter engine need to be modified so that they won't have any "unnecessary `!`" warnings after field private field promotion is enabled. This PR makes the necessary changes.
This PR doesn't introduce any functional change. In principle it might improve performance slightly (by avoiding redundant memory accesses), but in practice the difference is unlikely to rise out of the measurement noise.
Issue fixed by this PR: https://github.com/flutter/flutter/issues/131198
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
I've been trying to avoid this, but since the context type may vary
through runtime decisions, we just need something like this to select
which shader data to pull from the Dart GPU bundle at runtime. One
alternative would be to add a special omni shader concept to the HAL,
but that seems worse than just letting renderers key with a backend enum
sometimes.
Cautioned against using it for cap checks in the doc string.
At some point, we started setting `useColorEmoji` to true in our tests, but we were doing it in a way that resets all other configurations to their defaults. This caused the `canvasKitVariant` config to be lost and always set to the default `auto`.
This PR fixes the issue and adds tests to:
1. Make sure that the CanvasKit suite always runs with a specific variant (not `auto`).
2. Make sure the given CanvasKit variant makes it all the way through to the tests.
The test harness uses a backdoor (a global JS property on `window`) to communicate which canvaskit variant it's using. The test then compares that with `configuration.canvasKitVariant` to make sure they match. If they don't match, then the configuration was lost somewhere on the way.
Fixes https://github.com/flutter/flutter/issues/130993
Always add secondary role managers irrespective of the initial state of the semantic node, and have role manager decide whether it applies to the node or not.
Fixes https://github.com/flutter/flutter/issues/130546
The change in [0] has propagated now everywhere, so we can use
`utf8.encode()` instead of the longer `const Utf8Encoder.convert()`.
Also it cleans up code like
```
Uint8List bytes;
bytes.buffer.asByteData();
```
as that is not guaranteed to be correct, the correct version would be
```
Uint8List bytes;
bytes.buffer.asByteData(bytes.offsetInBytes, bytes.length);
```
a shorter hand for that is:
```
Uint8List bytes;
ByteData.sublistView(bytes);
```
[0] https://github.com/dart-lang/sdk/issues/52801
Reverts flutter/engine#43118
The incorrect default value (`true` instead of `false`) was used in the PR and that caused internal test failures. I'll add a test before trying to reland.
This reverts commit dce75ab4cf647eec6699f8a30ba2289a3738b307.
This also makes some small changes to make onBenchmark a
JSExportedDartFunction instead of a JSBoxedDartObject. This is for
changes in https://github.com/flutter/flutter/pull/129436 and to account
for the fact that flutter/packages provides an `allowInterop`'d
function. Benchmarks tests pass with this CL.
## 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.
- [ ] I added new tests to check the change I am making or feature I am
adding, or Hixie said 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].
- [ ] All existing and new tests are passing.
The goal is to remove the rounding applied in skparagraph and in the framework: https://github.com/flutter/flutter/issues/31707
The plumbing is done via a new static variable `ParagraphBuilder.shouldDisableRoundingHack` that toggles the rounding behavior in skparagraph and the flag is read by framework code. Application code and test code can either use `ParagraphBuilder.setDisableRoundingHack` or `--dart-define="SKPARAGRAPH_REMOVE_ROUNDING_HACK=1"` to opt-in.
Once the internal migration is finished the default value of the flag will be set to true.
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Most of the #include directives for SkPicture are removed except where they are still functional. Many comments rewritten to no longer be SkPicture-centric.
- DL unit tests still use it for consistency testing
- rasterizer/engine still use it for screen shot support
- Fuchsia still uses it extensively
My observations on the Pixel 6 device are that performing device allocations from multiple threads can dramatically slow down the raster task workload. As a stopgap solution, we can adjust image upload to only touch the device allocator on the IO thread which reduces the parallel access.
This doesn't have any impact on the S10, but locally on the Pixel 6 it is a night and day difference. I am testing using jonahwilliams/forked_gallery and navigating to the Reply demo. This demo has a large number of images, several of which are quite large.
Work towards https://github.com/flutter/flutter/issues/129392
### Before
Page transition is ~4 frames.

### After
Page transition is ~20 frames.

Following some thresholds from ANGLE, lets try allocating fewer of our resources into dedicated memory to see if that improves allocator performance.
https://github.com/flutter/flutter/issues/129737
This PR adds a `nonce` JS configuration attribute so users can pass a nonce value to their flutter engine initialization code.
This `nonce` is used to mark all scripts/styles needed by Flutter web that are considered `unsafe-inline` by CSP. In this change, there are only two tags that benefit from this:
* canvaskit.js
* inline styles for text editing
Before this change, the most strict CSP that allows a Flutter Web app to run would look like:
```
script-src 'self' 'nonce-flutter-init-scripts' 'wasm-unsafe-eval' https://www.gstatic.com/flutter-canvaskit/;
font-src https://fonts.gstatic.com;
style-src 'unsafe-inline';
```
After this change, CSP could be tightened to:
```
script-src 'self' 'nonce-YOUR_NONCE_VALUE' 'wasm-unsafe-eval';
font-src https://fonts.gstatic.com;
style-src 'nonce-YOUR_NONCE_VALUE';
```
By initializing the Flutter web app with something like this:
```html
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'nonce-YOUR_NONCE_VALUE' 'wasm-unsafe-eval'; font-src https://fonts.gstatic.com; style-src 'nonce-YOUR_NONCE_VALUE';">
...
<script nonce="YOUR_NONCE_VALUE">
_flutter.loader.loadEntrypoint({
onEntrypointLoaded: async function(engineInitializer) {
let appRunner = await engineInitializer.initializeEngine({
nonce: 'YOUR_NONCE_VALUE',
});
appRunner.runApp();
}
});
</script>
```
## Issues
Fixes https://github.com/flutter/flutter/issues/126977 (does not address `flutter.js`, that's a [different story](https://github.com/flutter/flutter/issues/128061))
Helps with https://github.com/flutter/flutter/issues/80221
---
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Unwrap optionals that already have an empty state that must be checked, like `std::optional<std::shared_ptr<T>>` and `std::optional<std::function<T>>`.
| Old API in `dart:ui` | New API in `dart:ui_web` |
|-|-|
| ~`webOnlyInitializePlatform`~ | ~`ui_web.initializePlatform`~ |
| `webOnlyWarmupEngine` | `ui_web.bootstrapEngine` |
| `debugEmulateFlutterTesterEnvironment` | `ui_web.debugEmulateFlutterTesterEnvironment` |
| `webOnlySetPluginHandler` | `ui_web.setPluginHandler` |
Part of https://github.com/flutter/flutter/issues/126831
To avoid analyzer warnings when utf8.encode() will return the more
precise Uint8List type, we use const Utf8Encoder().convert() which
already returns Uint8List
See https://github.com/dart-lang/sdk/issues/52801
This PR fixes https://github.com/flutter/flutter/issues/128468 by changing the relationship between semantics nodes and their roles from this:
```
SemanticsNode one-to-many RoleManager
```
To this:
```
SemanticsNode one-to-one PrimaryRoleManager one-to-many RoleManager
```
Previously a node would simply have multiple role managers, some of which would be responsible for setting the `role` attribute. It wasn't clear which role manager should be doing this. It also wasn't clear which role managers were safe to reuse across multiple types of nodes. This led to the unfortunate situation in https://github.com/flutter/flutter/issues/128468 where `LabelAndValue` ended up overriding the role assigned by `Checkable`.
With this PR, a `SemanticsNode` has exactly one `PrimaryRoleManager`. A primary role manager is responsible for setting the `role` attribute, and importantly, it's the _only_ thing responsible for it. It's _not safe_ to share primary role managers across different kinds of nodes. They are meant to provide very specific functionality for the widget's main role. OTOH, a non-primary `RoleManager` provides a piece of functionality that's safe to share.
A `Checkable` is a `PrimaryRoleManager` and is the only thing that decides on the `role` attribute. `LabelAndValue` is now a `RoleManager` that's not responsible for setting the role. It's only responsible for `aria-label`. No more confusion.
This also drastically simplifies the logic for role assignment. There's no more [logical soup](d4889c682d/lib/web_ui/lib/src/engine/semantics/semantics.dart (L1340)) attempting to find a good subset of roles to assign to a node. [Finding](93df91df95/lib/web_ui/lib/src/engine/semantics/semantics.dart (L1477)) and [instantiating](93df91df95/lib/web_ui/lib/src/engine/semantics/semantics.dart (L1498)) primary roles are very linear steps, as is [assigning a set of secondary roles](93df91df95/lib/web_ui/lib/src/engine/semantics/image.dart (L16)).
Benchmarks were failing because the code was reading the `frameCount` and `repetitionCount` before reading any frames out of the codec. The codec gets implicitly initialized when you read a frame, but we should return it to the user initialized so that `frameCount` and `repetitionCount` work even if you haven't read a frame yet. This is consistent with how CanvasKit's codec works.
Also, modified our unit tests so that they exercise the codecs in this way.
We'd like to (or already are) using the concurrent message loop for high priority rendering tasks like PSO construction and render pass encoding. The default priority level for the engine managed concurrent message loop is 2, which is a significantly lower priority than the raster thread at -5. This is almost certainly causing priority inversion.
We must move back to dedicated runners so we can adjust thread priorities.
**This must land _after_ https://github.com/flutter/flutter/pull/129032**
Flutter web uses requireJS in `debug` mode to assemble a DDC-compiled app from a bunch of small files ("modules").
This caused that `canvaskit.js` (then, but probably all other modules that used a browserify-like loading header) didn't work because it attempted to use the `define` function provided by Flutter's instance of `requireJS` (which kept the defined modules private, rather than as globals on the page, as the users of the JS expected).
A [fix](https://github.com/flutter/engine/pull/27342) was added to `flutter/engine` to trick loaders into *not* using the `requireJS` module loader, but a recent change in the fix's js-interop layer *subtly* changed its JS output on the page (objects went from `undefined` to `null`), causing this:
* https://github.com/flutter/flutter/issues/126131 (and others)
After flutter/flutter#129032, the engine fix shouldn't be required anymore, so this PR removes it.
## Issues
* Fixes https://github.com/flutter/flutter/issues/126131 (and possibly others)
## Testing
* Manually tested with some test apps, and miscellanous JS scripts as reported by users.
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style