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
Part of https://github.com/flutter/flutter/issues/128606.
* Fix all of the Porter-Duff blends (virtually all of the blends were
wrong). Still working on getting all of the advanced/color blends fixed
up.
* Fill in missing ops for arithmetic types/remove Vector4 conversions.
* Remove the original GeometryTest in favor of the much clearer goldens.
Once we have all of the CPU blends matching up properly with the GPU
blends, we can think about constructing a more intentional test that
covers a select number of important cases with accompanying explanation.
Top rectangles = GPU blends
Bottom rectangles = CPU blends
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
Instead of adding precision mediump float to all shaders that import types.glsl, let vertex shaders be highp by default. Opt rrect blur into highp and all other fragment shaders into mediump. For reasons I don't understand, the default for fragment shaders is being treated as highp without any specifiers.
Fixes https://github.com/flutter/flutter/issues/128284
Fixes https://github.com/flutter/flutter/issues/128412
Adds
- `DlRegion DlRegion::MakeUnion(const Region &, const DlRegion &)`
- `DlRegion DlRegion::MakeIntersection(const Region &, const DlRegion
&)`
- `bool DlRegion::intersects(const DlRegion &)`
- `bool DlRegion::intersects(const SkIRect &)`
Instead of per span line vector all spans are stored in continuous
buffer.
Complete benchmarks:
```
-----------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
-----------------------------------------------------------------------------------------------
BM_DlRegion_IntersectsSingleRect/Tiny 2688 ns 2687 ns 258580
BM_SkRegion_IntersectsSingleRect/Tiny 85889 ns 85877 ns 8092
BM_DlRegion_IntersectsSingleRect/Small 4814 ns 4813 ns 142874
BM_SkRegion_IntersectsSingleRect/Small 101102 ns 101102 ns 6833
BM_DlRegion_IntersectsSingleRect/Medium 2329 ns 2329 ns 302911
BM_SkRegion_IntersectsSingleRect/Medium 60436 ns 60183 ns 11156
BM_DlRegion_IntersectsSingleRect/Large 1243 ns 1243 ns 565209
BM_SkRegion_IntersectsSingleRect/Large 2813 ns 2813 ns 252187
BM_DlRegion_IntersectsRegion/Tiny 38.9 ns 38.9 ns 17913855
BM_SkRegion_IntersectsRegion/Tiny 203 ns 203 ns 3480855
BM_DlRegion_IntersectsRegion/Small 306 ns 306 ns 2295413
BM_SkRegion_IntersectsRegion/Small 1057 ns 1057 ns 660826
BM_DlRegion_IntersectsRegion/Medium 8.83 ns 8.83 ns 79128233
BM_SkRegion_IntersectsRegion/Medium 43.3 ns 43.3 ns 16076912
BM_DlRegion_IntersectsRegion/Large 6.96 ns 6.96 ns 101646676
BM_SkRegion_IntersectsRegion/Large 31.8 ns 31.8 ns 22121517
BM_DlRegion_IntersectsRegion/TinyAsymmetric 54.2 ns 54.2 ns 12890870
BM_SkRegion_IntersectsRegion/TinyAsymmetric 4575 ns 4574 ns 155368
BM_DlRegion_IntersectsRegion/SmallAsymmetric 190 ns 189 ns 3748547
BM_SkRegion_IntersectsRegion/SmallAsymmetric 6157 ns 6157 ns 114403
BM_DlRegion_IntersectsRegion/MediumAsymmetric 20.9 ns 20.9 ns 33523941
BM_SkRegion_IntersectsRegion/MediumAsymmetric 3247 ns 3247 ns 214694
BM_DlRegion_IntersectsRegion/LargeAsymmetric 8.97 ns 8.97 ns 76827676
BM_SkRegion_IntersectsRegion/LargeAsymmetric 154 ns 154 ns 4757924
BM_DlRegion_Operation/Union_Tiny 26.3 us 26.3 us 24534
BM_SkRegion_Operation/Union_Tiny 37.9 us 37.9 us 17973
BM_DlRegion_Operation/Union_Small 64.4 us 64.4 us 10657
BM_SkRegion_Operation/Union_Small 105 us 105 us 6278
BM_DlRegion_Operation/Union_Medium 22.0 us 22.0 us 31631
BM_SkRegion_Operation/Union_Medium 64.8 us 64.8 us 10744
BM_DlRegion_Operation/Union_Large 1.00 us 1.00 us 697406
BM_SkRegion_Operation/Union_Large 1.29 us 1.29 us 547089
BM_DlRegion_Operation/Union_TinyAsymmetric 10.3 us 10.3 us 68647
BM_SkRegion_Operation/Union_TinyAsymmetric 20.6 us 20.6 us 33282
BM_DlRegion_Operation/Union_SmallAsymmetric 14.0 us 14.0 us 49944
BM_SkRegion_Operation/Union_SmallAsymmetric 34.4 us 34.4 us 19618
BM_DlRegion_Operation/Union_MediumAsymmetric 5.24 us 5.24 us 134097
BM_SkRegion_Operation/Union_MediumAsymmetric 12.7 us 12.7 us 55069
BM_DlRegion_Operation/Union_LargeAsymmetric 0.376 us 0.376 us 1808589
BM_SkRegion_Operation/Union_LargeAsymmetric 0.533 us 0.532 us 1283674
BM_DlRegion_Operation/Intersection_Tiny 8.13 us 8.13 us 87199
BM_SkRegion_Operation/Intersection_Tiny 31.8 us 31.8 us 21864
BM_DlRegion_Operation/Intersection_Small 55.9 us 55.9 us 11888
BM_SkRegion_Operation/Intersection_Small 98.4 us 98.3 us 6963
BM_DlRegion_Operation/Intersection_Medium 40.0 us 40.0 us 17667
BM_SkRegion_Operation/Intersection_Medium 69.8 us 69.8 us 9910
BM_DlRegion_Operation/Intersection_Large 1.06 us 1.06 us 650957
BM_SkRegion_Operation/Intersection_Large 1.26 us 1.26 us 559624
BM_DlRegion_Operation/Intersection_TinyAsymmetric 2.62 us 2.62 us 264565
BM_SkRegion_Operation/Intersection_TinyAsymmetric 15.3 us 15.3 us 45528
BM_DlRegion_Operation/Intersection_SmallAsymmetric 7.15 us 7.15 us 93482
BM_SkRegion_Operation/Intersection_SmallAsymmetric 27.5 us 27.5 us 24450
BM_DlRegion_Operation/Intersection_MediumAsymmetric 2.95 us 2.95 us 235133
BM_SkRegion_Operation/Intersection_MediumAsymmetric 10.5 us 10.5 us 65925
BM_DlRegion_Operation/Intersection_LargeAsymmetric 0.165 us 0.165 us 4016433
BM_SkRegion_Operation/Intersection_LargeAsymmetric 0.409 us 0.409 us 1719716
BM_DlRegion_Operation/Intersection_SingleRect_Tiny 0.105 us 0.105 us 7403099
BM_SkRegion_Operation/Intersection_SingleRect_Tiny 10.8 us 10.8 us 64185
BM_DlRegion_Operation/Intersection_SingleRect_Small 0.410 us 0.410 us 1724524
BM_SkRegion_Operation/Intersection_SingleRect_Small 16.2 us 16.2 us 43707
BM_DlRegion_Operation/Intersection_SingleRect_Medium 0.458 us 0.458 us 1540049
BM_SkRegion_Operation/Intersection_SingleRect_Medium 7.54 us 7.54 us 93407
BM_DlRegion_Operation/Intersection_SingleRect_Large 0.175 us 0.175 us 3984926
BM_SkRegion_Operation/Intersection_SingleRect_Large 0.351 us 0.351 us 1931946
BM_DlRegion_FromRects/Tiny 154 us 154 us 4383
BM_SkRegion_FromRects/Tiny 69429 us 69419 us 10
BM_DlRegion_FromRects/Small 369 us 369 us 1932
BM_SkRegion_FromRects/Small 117584 us 117578 us 6
BM_DlRegion_FromRects/Medium 475 us 475 us 1477
BM_SkRegion_FromRects/Medium 21611 us 21610 us 33
BM_DlRegion_FromRects/Large 1329 us 1329 us 533
BM_SkRegion_FromRects/Large 1409 us 1409 us 501
BM_DlRegion_GetRects/Tiny 39.2 us 39.2 us 18030
BM_SkRegion_GetRects/Tiny 84.2 us 84.2 us 9971
BM_DlRegion_GetRects/Small 88.9 us 88.9 us 7873
BM_SkRegion_GetRects/Small 212 us 212 us 3598
BM_DlRegion_GetRects/Medium 0.845 us 0.813 us 881224
BM_SkRegion_GetRects/Medium 3.10 us 3.09 us 223483
BM_DlRegion_GetRects/Large 0.120 us 0.120 us 5954761
BM_SkRegion_GetRects/Large 0.337 us 0.336 us 2068656
```
## 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 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.
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
[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
https://github.com/flutter/flutter/issues/126209
## 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 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.
All of the backends already respect this property for the first color
attachment in the pipeline. ~~Our Vulkan backend disables blending for a
whole pipeline if the first color attachment has blending turned off.~~
This has been under our nose but I haven't checked it until now.
HSR might not be working on some Vulkan & OpenGLES drivers because of
this.