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
JSNumber.toDart will now be two functions: toDartDouble and toDartInt.
Note that some code that looks like `toDart.toInt()` was kept as
`toDartDouble.toInt()` instead of `toDartInt`, since `toDartInt` throws
if the value is not an integer.
Object.toJS is now Object.toJSBox. An actual box is introduced on all
backends now, and is unwrapped in JSBoxedDartObject.toDart. There are
many usages of toJSAnyShallow that we should modify, but that's for a
later CL.
This is to help land this CL:
https://dart-review.googlesource.com/c/sdk/+/309082https://dart-review.googlesource.com/c/sdk/+/309081 is the CL that added
the new methods.
## 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].
- [x] All existing and new tests are passing.
For example, `_encodeParagraphStyle` says:
```dart
if (locale != null) {
result[0] |= 1 << 12;
// Passed separately to native.
}
```
We know `1<<12` is 4096.
On the other hand, the old code uses `0x800`, which is 2048.
And the strutStyle field is missing.
*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.*
*List which issues are fixed by this PR. You must list at least one issue.*
*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
We have an issue where autofill in Safari Desktop is only partially autofilling the form. The only input that gets filled is the currently focused one.
This is happening for a couple of reasons:
- We hide non-focused inputs that are part of the autofill form by sizing them to 0px height and width, among other styles.
- This doesn't cause issues in most browsers. However, Safari does not respect offscreen or 0-sized inputs, and this leads to the partial form autofill issue.
The solution is to make sure we hide the inputs in the rest of the form from the users, without hiding it from Safari.
Fixes https://github.com/flutter/flutter/issues/71275
I was missing the VMA flush.
Because skia is writing directly to the exposed ptr, we don't go through the OnSetContents which makes a flush call. Add a flush API and implement it for Vk DeviceBuffers.
In some languages, when the text contains a new line "\n", the `v8BreakIterator` starts returning different values from `breakType()`. This caused our code to think that those line breaks were hard line breaks when in fact they were soft line breaks. Still unclear if this is a `v8BreakIterator` bug or a wrong expectation on our side regarding how `breakType()` is supposed to work.
Instead of using `v8BreakIterator.breakType()`, let's do the `soft` vs `hard` detection ourselves (we already have all the necessary pieces).
Fixes https://github.com/flutter/flutter/issues/127379
Reverts flutter/engine#42944
This didn't improve any of the benchmarks, which I think at least disproves my theory on overloading. Lets go back to the prior strategy and look for improvements elsewhere.
This reverts commit 2b5c1f8d95c9c54e51787f5ceaeb142c0666aa72.
This is a straight reland without any additional changes. The package that was still using the outdated API causing the original revert has been updated in https://github.com/flutter/packages/pull/4233. **Do not land this until that PR has rolled into the framework.**
Even with separate allocators and queues, I think that using the concurrent runner is just overloading the phone.
On Android force it all onto the I/O thread.
https://github.com/flutter/flutter/issues/128919
Safari web autofill has an issue where the autofill dialog flickers and doesn't completely render and allow users to fill any forms.
This is caused by a collision between default browser behavior on the `pointerdown` event and the programatic focusing of our inputs.
### Problem
When we click into an input, the element is created, placed, and (explicitly) focused. However, all of this is done before the `pointerdown` event can finish. Since all `pointerdown` elements target the `flutter-view` (formerly `flt-glass-pane`), default browser behavior is to trigger a `blur` event since the target doesn't match what's currently focused, which is the input element. This doesn't manifest into most text editing issues because we listen for `blur` events on the `input` and call `focus()`. However, in Safari, this near-instant focus/blur results in the disappearance of the autofill popup.
The current chain of events looks like:
`pointerdown` event starts -> input is created + focused -> `pointerdown` event ends, and triggers a `blur` -> input refocuses on `blur`
### Solution
This change ensures that we don't focus the input until after the `pointerdown` event concludes, thus preventing any rapid-fire `blur` event from being emitted. We do this via wrapping the focus logic within a zero-duration Timer.
The new chain of events looks like:
`pointerdown` event starts -> `pointerdown` event ends -> input is created + focused
### Alternative approach
Note: Another option was to call `preventDefault()` on the `pointerdown` event to prevent the `blur` from occurring that way. There may be unintended side effects from that approach, especially as it relates to platform views. The surface area of the chosen approach is much more contained and should result in no side effects outside of Safari Desktop's text editing strategy.
<img width="699" alt="Screenshot 2023-06-15 at 7 34 02 PM" src="https://github.com/flutter/engine/assets/110993981/3548d1ea-65f7-412f-b3c7-f94db2658127">
Fixes https://github.com/flutter/flutter/issues/127960
Moving `webOnlyAssetManager` to `dart:ui_web` and renaming it to simply `assetManager`. This will make it easier for plugins and apps to get a hold of the asset manager without doing `dart:ui` shims or other shenanigans.
Part of https://github.com/flutter/flutter/issues/126831
I was refactoring this class on the Skia side and saw Flutter #included it, but did not appear to actually use it.
This replaces an unnecessary #include with a necessary one.
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style