Now that all of the CPU blend modes work, we can allow back-to-back
fullscreen solid color draws to get blended together regardless of their
blend mode/color opacity.
Part of https://github.com/flutter/flutter/issues/127232.
Adds an explicit ColorFilter concept to Aiks which wraps the GPU and CPU
implementations. We're not using the CPU implementations yet, but I'll
be getting it wired up in a follow-up patch.
For devices that don't support memoryless textures, the fullscreen MSAA texture adds a substantial amount of memory thrashing when it is allocated and deallocated. For these devices, lets cache the MSAA texture in the swapchain image.
https://github.com/flutter/flutter/issues/129737
Reverts flutter/engine#42584. (Thanks to @jonahwilliams for bisecting)
With this change, layers are getting clipped incorrectly when rendering
platform views in Wondrous.
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
The linter is failing on this in my unrelated PR for some reason: https://github.com/flutter/engine/pull/43348
```
â Failures for clang-tidy on /Volumes/Work/s/w/ir/cache/builder/src/flutter/impeller/renderer/backend/metal/vertex_descriptor_mtl.mm:
/Volumes/Work/s/w/ir/cache/builder/src/flutter/impeller/renderer/backend/metal/vertex_descriptor_mtl.mm:177:3: error: missing username/bug in TODO [google-readability-todo,-warnings-as-errors]
// TODO: its odd that we offset buffers from the max index on metal
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// TODO(chrome-bot): its odd that we offset buffers from the max index on metal
Suppressed 1476 warnings (1475 in non-user code, 1 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
1 warning treated as error
```
Some Android devices do not support the memory type eLazilyAllocated, which we use for MSAA and stencil textures. These textures were falling back to device local in dedicated allocations, which are expensive to both allocate and free. The dedicated allocation is implied by asking for eLazilyAllocated
Instead, perform a check for support for this memory type. Never request dedicated allocations (at least not until we have a compelling use case)
This should fix https://github.com/flutter/flutter/issues/129737https://github.com/flutter/flutter/issues/129784
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
Investigated as part of
https://github.com/flutter/flutter/issues/127232.
This took some time to work out, but:
* The amount of blending applied to the source color needs to be
weighted by the destination alpha, which is pretty sensible behavior.
This is in addition to applying source-over behavior with the resulting
blended color.
* All of the blend functions assume that the color is already
premultiplied, so remove the unpremultiply/premultiply surrounding the
blend call.
All of the blend modes now visually match up with the [Flutter
docs](https://api.flutter.dev/flutter/dart-ui/BlendMode.html), except
for ColorBurn and Saturation, which appear to have a slight
miscalculation going on with the red channel.
Update flutter engine includes to be more specific about use of Skia includes.
These changes are required to unblock the Skia roller that has new streamlined include files.
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.
Piping the feedback to logs is disabled by default but can be enabled by patching the source for now. If reading from logs gets to be useful, we can move it behind a flag. In traces, enabled by default, pipeline cache hits and misses will be shown via counters. The time taken to create a pipeline variant is already covered by existing traces.
This patch also sets up infrastructure in the impeller::CapabilitiesVK to quickly enable optional device extensions.
Pipeline feedback will only be reported if the device supports `VK_EXT_pipeline_creation_feedback`.
Example of logs:
```
E/flutter ( 2011): >>>>>>
E/flutter ( 2011): Pipeline 'GaussianBlurAlphaDecal Pipeline' Time: 48.60ms Cache Hit: 0 Base Accel: 0 Thread: 481449901232
E/flutter ( 2011): Stage 1: Time: 12.91ms Cache Hit: 0 Base Accel: 0 Thread: 481449901232
E/flutter ( 2011): Stage 2: Time: 15.10ms Cache Hit: 0 Base Accel: 0 Thread: 481449901232
E/flutter ( 2011): <<<<<<
```
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