3698 Commits

Author SHA1 Message Date
Jackson Gardner
b99e758ee1 Reland [skwasm] Scene builder optimizations for platform view placement (flutter/engine#55468)
This is an attempt to reland the overlay optimization for skwasm and fixing the golden diffs from the framework tests.

Original PR description:

This PR refactors the scene builder's logic in order to more aggressively merge flutter content and platform view content together. This essentially covers the case discussed in this flutter issue: https://github.com/flutter/flutter/issues/149863

This optimization ensures that each picture or platform view is applied to the lowest possible slice in the scene, which avoids the proliferation of redundant slices and overlays in the scene.
2024-09-30 17:42:58 +00:00
Harry Terkelsen
5c96bcbf1e Revert "Reland "[canvaskit] Further improve overlay optimization by splitting pictures"" (flutter/engine#55501)
Reverts flutter/engine#55464

The PR caused a large regression in a web benchmark.
2024-09-28 00:51:18 +00:00
gaaclarke
9e2746c137 updated Color docstring to address equality (flutter/engine#55496)
issue: https://github.com/flutter/flutter/issues/155803

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-09-27 21:41:08 +00:00
Jason Simmons
96d24ff033 Listen for uncaught exceptions during loading of a web test suite in Chrome (flutter/engine#55166)
Without this the test runner will hang if the compiled test is invalid and unable to execute.
2024-09-27 17:18:18 +00:00
Mouad Debbar
f6e580d09a [web] Update builder json generator to reflect recent changes (flutter/engine#55307)
Recent [changes](https://github.com/flutter/engine/pull/54584) affected our builder configs, but the script that generates those builder configs wasn't updated.
2024-09-27 16:05:17 +00:00
Harry Terkelsen
1e086b6311 Reland "[canvaskit] Further improve overlay optimization by splitting pictures" (flutter/engine#55464)
This enhances the overlay optimization by delaying combining pictures to get tighter bounds for the pictures that make up the scene, enabling more sophisticated optimization since we can determine if they intersect with platform views on a per-picture basis.

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

On a Macbook in Chrome in an example app with an infinite scrolling grid of platform views, this brings the ratio of dropped frames from 93% to 55% (roughly 4 fps to 30 fps).

This is a reland of https://github.com/flutter/engine/pull/54878 with a fix for scenes with pictures and shader masks that are eventually entirely clipped out.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-09-26 21:25:59 +00:00
auto-submit[bot]
2d9833b103 Reverts "Reland "[canvaskit] Further improve overlay optimization by splitting pictures" (#55402)" (flutter/engine#55456)
Reverts: flutter/engine#55402
Initiated by: chingjun
Reason for reverting: caused internal tests to fail.

See b/369740500 for more details.
Original PR Author: harryterkelsen

Reviewed By: {yjbanov}

This change reverts the following previous change:
This enhances the overlay optimization by delaying combining pictures to get tighter bounds for the pictures that make up the scene, enabling more sophisticated optimization since we can determine if they intersect with platform views on a per-picture basis.

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

On a Macbook in Chrome in an example app with an infinite scrolling grid of platform views, this brings the ratio of dropped frames from 93% to 55% (roughly 4 fps to 30 fps).

This is a reland of https://github.com/flutter/engine/pull/54878 with a fix for scenes with pictures that are eventually entirely clipped out.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-09-26 06:19:47 +00:00
Harry Terkelsen
d91038befd Reland "[canvaskit] Further improve overlay optimization by splitting pictures" (flutter/engine#55402)
This enhances the overlay optimization by delaying combining pictures to get tighter bounds for the pictures that make up the scene, enabling more sophisticated optimization since we can determine if they intersect with platform views on a per-picture basis.

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

On a Macbook in Chrome in an example app with an infinite scrolling grid of platform views, this brings the ratio of dropped frames from 93% to 55% (roughly 4 fps to 30 fps).

This is a reland of https://github.com/flutter/engine/pull/54878 with a fix for scenes with pictures that are eventually entirely clipped out.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-09-25 23:47:18 +00:00
Brandon DeRosier
31ac0fc004 [Flutter GPU] Use vm.Vector4 for clear color instead of ui.Color. (flutter/engine#55416)
Resolves https://github.com/flutter/flutter/issues/155627.

Allow setting the clear directly as floats without conversion work. vector_math already has convenient `Colors.[color]` factories and such. Also, `ui.Color` has a color space now, which does not apply here.

Adds a simple golden to verify that clear colors work:
![flutter_gpu_test_clear_color](https://github.com/user-attachments/assets/ba7a4e74-aaf2-48d8-ac13-115a86daeb19)
2024-09-25 18:02:05 +00:00
Brandon DeRosier
e496b1ed26 [Flutter GPU] Add CullMode. (flutter/engine#55409)
Part of https://github.com/flutter/flutter/issues/155636.

New golden `flutter_gpu_test_cull_mode` will draw a red triangle if the CullMode isn't working:
![flutter_gpu_test_cull_mode](https://github.com/user-attachments/assets/cbdf804e-1608-4352-9aa1-d5d9223f3c1a)
2024-09-25 00:52:11 +00:00
John McDole
14caa2fe19 Disallow time traveling frame times (flutter/engine#55310)
Address bad developer experience in
https://github.com/flutter/flutter/issues/106277

Leave as an error log and hope for more repro reports


```mermaid
sequenceDiagram
  Animator ->> Animator: AwaitVSync
  Animator ->> VsyncWaiter: AsyncWaitForVsync(callback)
  VsyncWaiter -> VsyncWaiterAndroid: AwaitVSync
  note over VsyncWaiterAndroid: GetUITaskRunner
  VsyncWaiterAndroid -> Choreographer: PostFrameCallback
  Choreographer -> NDK: AChoreographer_postFrameCallback64
  note over Choreographer,NDK: The time that the frame is being<br/>rendered as nanoseconds in the <br/>CLOCK_MONOTONIC time base
  NDK --> Choreographer: callback(nanos)
  Choreographer -> VsyncWaiterAndroid: callback
  note over VsyncWaiterAndroid: // Rollback suspicion<br/>if (frame_time > now) frame_time = now;
  VsyncWaiterAndroid -> VsyncWaiterAndroid: OnVsyncFromNDK(frame_nanos)
  VsyncWaiterAndroid -> VsyncWaiter: FireCallback(\n  frame_start_time,\n  target_time)
  VsyncWaiter -> Animator: callback(frame_timings_recorder)

  Animator -> Animator: BeginFrame(frame_timings_recorder)
  Animator -> Shell: OnAnimatorBeginFrame
  Shell -> Engine: BeginFrame(frame_time, frame_number)
  Engine -> RuntimeController: BeginFrame(frame_time, frame_number)
  RuntimeController -> PlatformConfiguration: BeginFrame(frame_time, frame_number)
  PlatformConfiguration -> hooks.dart: begin_frame_
```
2024-09-24 15:33:45 -07:00
Jason Simmons
d333cf4224 [Impeller] Delete command pools held by the CommandPoolRecyclerVK after decoding an image on the IO thread (flutter/engine#55398)
In the Vulkan backend, the CommandPoolRecyclerVK stores command pools that can be reused while rendering a frame.  For each frame, SurfaceContextVK::AcquireNextSurface calls CommandPoolRecyclerVK::Dispose to clear the cached pools.

However, the CommandPoolRecyclerVK's cache of pools is placed in thread-local storage.  So command pools used on the IO thread will not be cleaned up if frame rendering calls Dispose on the raster thread.

This PR adds a Context API that the IO thread can call after using a command pool in order to ensure that cached resources are disposed.

Fixes https://github.com/flutter/flutter/issues/155519
2024-09-24 22:16:37 +00:00
Brandon DeRosier
c4514370d7 [Flutter GPU] Add pipeline stencil config. (flutter/engine#55272)
Also adds a golden that depends on https://github.com/flutter/engine/pull/55270.
Resolves https://github.com/flutter/flutter/issues/142731.

Allow setting the stencil compare function, pass/fail operations, and read/write masks.

Flutter GPU has light "shader object" style programs, so all of the stencil configuration state can be set on the `RenderPass` at any time.

New simple golden that exercises stencil ops:
![flutter_gpu_test_triangle_stencil](https://github.com/user-attachments/assets/acc98cd9-41fc-4988-97a2-afb898a8fc0c)
2024-09-24 21:26:29 +00:00
Harry Terkelsen
81f281b72d Revert "[canvaskit] Further improve overlay optimization by splitting pictures" (flutter/engine#55401)
Reverts flutter/engine#54878

Crashes on real example app with many platform views
2024-09-24 13:06:08 -07:00
Harry Terkelsen
31cde4f8d3 [canvaskit] Further improve overlay optimization by splitting pictures (flutter/engine#54878)
This enhances the overlay optimization by delaying combining pictures to get tighter bounds for the pictures that make up the scene, enabling more sophisticated optimization since we can determine if they intersect with platform views on a per-picture basis.

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

On a Macbook in Chrome in an example app with an infinite scrolling grid of platform views, this brings the ratio of dropped frames from 93% to 55% (roughly 4 fps to 30 fps).

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-09-24 19:39:10 +00:00
Brandon DeRosier
7242297f80 [Flutter GPU] Add setStencilReference to RenderPass. (flutter/engine#55270) 2024-09-24 11:27:25 -07:00
Mouad Debbar
d99ff74d1a [web] Fix keyboard not showing up when iOS input has decoration text (flutter/engine#55152)
In certain situations, semantics elements get assigned `pointer-events: none` when they aren't supposed to.

One such situation is when a text field has a [decoration error text](https://api.flutter.dev/flutter/material/InputDecoration/errorText.html). The semantics node become a container, and we always set `pointer-events: none` on container nodes.

This PR introduces an `acceptsPointerEvents` getter on `SemanticRole` and `SemanticBehavior` to control when `pointer-events` should be `all` or `none`.

Fixes https://github.com/flutter/flutter/issues/141975
2024-09-24 15:03:00 +00:00
gaaclarke
9f66178386 Reland: Update Color to do all calculations with floating point components (flutter/engine#55231)
Reason for revert: Broke customer tests
Reland depends on https://github.com/flutter/flutter/issues/155113

This transforms the rest of Color to use the floating point parameters.  This will likely break existing tests very subtly.  For example, colors will be slightly different in golden tests if `lerp` was ever used.

issue: https://github.com/flutter/flutter/issues/127855

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-09-23 17:43:52 +00:00
Brandon DeRosier
a2fe41a763 [Flutter GPU] Remove the redundant smoketest. (flutter/engine#55267)
This is placeholder stuff that I added before the rest of the API to prove that we can call the engine symbols.

Today this is totally redundant as Flutter GPU has a bunch of automated tests which exercise every FFI call.
2024-09-17 22:24:07 +00:00
Brandon DeRosier
759d173073 [Flutter GPU] Add DeviceBuffer.flush & GpuContext.getMinimumUniformByteAlignment. (flutter/engine#53620)
Part of https://github.com/flutter/flutter/issues/150953.

Provide a way to get the required minimum uniform byte alignment when referencing uniform blocks in a device buffer. Allow the user to explicitly flush DeviceBuffers (necessary for devices without shared memory).
2024-09-17 20:31:50 +00:00
Brandon DeRosier
ea026548ce [Flutter GPU] Add golden test for rendering a triangle. (flutter/engine#55262)
Resolves https://github.com/flutter/flutter/issues/144640.

New golden:
![flutter_gpu_test_triangle](https://github.com/user-attachments/assets/0b39380e-1aa5-4369-ae5b-a8764d5701cb)
2024-09-17 20:00:33 +00:00
auto-submit[bot]
86d1435a0d Reverts "[skwasm] Scene builder optimizations for platform view placement (#54949)" (flutter/engine#55193)
Reverts: flutter/engine#54949
Initiated by: eyebrowsoffire
Reason for reverting: Incorrect golden diffs on engine roll, see https://github.com/flutter/flutter/pull/155181
Original PR Author: eyebrowsoffire

Reviewed By: {harryterkelsen}

This change reverts the following previous change:
This PR refactors the scene builder's logic in order to more aggressively merge flutter content and platform view content together. This essentially covers the case discussed in this flutter issue: https://github.com/flutter/flutter/issues/149863

This optimization ensures that each picture or platform view is applied to the lowest possible slice in the scene, which avoids the proliferation of redundant slices and overlays in the scene.
2024-09-13 22:21:47 +00:00
Jim Graham
7da9ad1862 Delete VolatilePathTracker in favor of Dispatch tracking (flutter/engine#55125)
ui.Canvas and ui.SceneBuilder now use the DlPath object directly from the ui.Path object. This results in increased sharing of the wrapper objects which then increases the sharing of both the converted Impeller paths and Skia's volatile flag.

The VolatilePathTracker mechanism is deleted and rather than count the number of frames that a path is stable for, instead we count the number of times it is used for rendering. If a path is used 100 times in a single frame, it will become non-volatile and start being cached almost immediately. The cached Impeller paths are now also tracked for all instances of the same path, rather than for each call site that originated from a DisplayList dispatch.
2024-09-13 21:49:09 +00:00
Jackson Gardner
0cc27b4e22 [skwasm] Scene builder optimizations for platform view placement (flutter/engine#54949)
This PR refactors the scene builder's logic in order to more aggressively merge flutter content and platform view content together. This essentially covers the case discussed in this flutter issue: https://github.com/flutter/flutter/issues/149863

This optimization ensures that each picture or platform view is applied to the lowest possible slice in the scene, which avoids the proliferation of redundant slices and overlays in the scene.
2024-09-13 17:55:07 +00:00
Matan Lurey
02d5118165 Remove assert(() {... }) and other unnecessary patterns in dart:ui tests (flutter/engine#55165)
Closes https://github.com/flutter/flutter/issues/155054, where we
decided this was correct to do.

As a bonus I improved an `assert` message :)
2024-09-12 17:40:52 -07:00
Brandon DeRosier
16acb8258a Remove Impeller Scene 👋 (flutter/engine#55118)
Impeller Scene has been fully rewritten as a Dart library for Flutter: https://pub.dev/packages/flutter_scene
2024-09-12 14:56:08 -07:00
gaaclarke
f9093e1b13 Revert "Update Color to do all calculations with floating point components" (flutter/engine#55153)
Reverts flutter/engine#54981

This is causing failures in customer tests that need to be updated:
https://github.com/flutter/flutter/pull/155107/checks?check_run_id=30069840819
2024-09-12 13:01:37 -07:00
gaaclarke
c7d96a38bc Update Color to do all calculations with floating point components (flutter/engine#54981)
This transforms the rest of Color to use the floating point parameters.  This will likely break existing tests very subtly.  For example, colors will be slightly different in golden tests if `lerp` was ever used.

issue: https://github.com/flutter/flutter/issues/127855

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-09-12 16:30:06 +00:00
Martin Kustermann
f469f967d8 [dart2wasm] Move web wasm embedder to new dart2wasm embedder API (flutter/engine#55037)
This removes usages of the deprecated top-level `instantiate` and
`invoke` methods and replaces it by method calls to the embedder
objects.

See [0] for the change that introduce this embedder API.

[0] https://dart-review.googlesource.com/c/sdk/+/383242/6
2024-09-12 14:27:05 +02:00
Yegor
d7e52c7710 [skwasm] use temporary RawPaint objects (attempt #2) (flutter/engine#55035)
Relands https://github.com/flutter/engine/pull/54917. The change is the same as before, except now the native resources for `SkwasmColorFilter` and `SkwasmImageFilter` classes are no longer GC'd. Instead, we use manually managed native handles (vended and scoped by `withRawColorFilter` and `withRawImageFilter`). The bug in the previous PR was that filter objects were disposed with the paint while the framework continued holding onto them. When GC kicked the finalization registry, it attempted to double-free the filters.
2024-09-10 04:10:26 +00:00
Jackson Gardner
4a1b51bdda Revert "Add crossOrigin property to <img> tag used for decoding (#54961)" (flutter/engine#55042)
This reverts commit acf6660982dff1f924f3438f05a41bcdba649105.

Reason for revert: We broke users (including a Google internal customer) that depend on credentialed image requests. See https://github.com/flutter/flutter/issues/154809

Fixes https://github.com/flutter/flutter/issues/154809
2024-09-09 17:22:02 +00:00
auto-submit[bot]
a16be84457 Reverts "[skwasm] use temporary RawPaint objects (#54917)" (flutter/engine#55018)
Reverts: flutter/engine#54917
Initiated by: jonahwilliams
Reason for reverting: failing on framework -> engine roll  https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20web_skwasm_tests_7_last/10571/overview
Original PR Author: yjbanov

Reviewed By: {eyebrowsoffire}

This change reverts the following previous change:
Same as https://github.com/flutter/engine/pull/54818, but for Skwasm.

Addresses the `Paint` issue in https://github.com/flutter/flutter/issues/153678 in Skwasm
2024-09-07 00:19:45 +00:00
Paul Berry
92e2915b51 [multiple] Avoid new unreachable_switch_default warning. (flutter/engine#54996)
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the behavior
of the existing `unreachable_switch_case` warning, which is issued
whenever a `case` clause of a `switch` statement is determined to be
unreachable.

Before adding the new warning to the analyzer, code in the engine needs
to first be updated to eliminate these unreachable `default` clauses, so
that the warning won't cause builds to break.

For more information, see
https://github.com/dart-lang/sdk/issues/54575.
2024-09-06 15:24:36 -07:00
Yegor
adfd4c03de [skwasm] use temporary RawPaint objects (flutter/engine#54917)
Same as https://github.com/flutter/engine/pull/54818, but for Skwasm.

Addresses the `Paint` issue in https://github.com/flutter/flutter/issues/153678 in Skwasm
2024-09-06 22:21:54 +00:00
Jonah Williams
547dbe4c4c [impeller] fake image for fake tests. (flutter/engine#54974)
Simulator only change to allow toImage and toByteData to not fail when there is no metal context w/ impeller.
2024-09-06 18:53:53 +00:00
gaaclarke
bba852ec0c Removes the int storage from Color (flutter/engine#54714)
issue: https://github.com/flutter/flutter/issues/127855
This depends on https://github.com/flutter/flutter/pull/153938 being
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.
- [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/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[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
2024-09-05 19:11:25 -07:00
Harry Terkelsen
7bb35d8a86 [canvaskit] Fix incorrect calculation of ImageFilter paint bounds (flutter/engine#54980)
Fixes calculation of `ImageFilter` bounds by taking into account the
offset.

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

## 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/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[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
2024-09-05 15:23:37 -07:00
Juanjo Tugores
cf40f73057 Fix unexpected ViewFocus events when Text Editing utilities change focus in the middle of a blur call. (flutter/engine#54965)
In [some cases][1], text editing utilities re-focus the `<input />` element during a blur event. This causes an unusual sequence of `focusin` and `focusout` events, leading to the engine sending unintended events.

Consider the following HTML code:

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
  <div id="container">
    <input type="" value="1" id="input1">
    <input type="" value="2" id="input2">
    <input type="" value="3" id="input3">
  </div>

  <script>
    container.addEventListener('focusin', (ev) => {
      console.log('focusin: focus was gained by', ev.target);
    });
    container.addEventListener('focusout', (ev) => {
      console.log('focusout: focus is leaving', ev.target, 'and it will go to', ev.relatedTarget);
    });
  </script>
</body>
</html>
```

Clicking input1, then input2, then input3 produces the following console logs:

```
// Input1 is clicked
focusin: focus was gained by <input type value=​"1" id=​"input1">​

// Input2 is clicked
focusout: focus is leaving <input type value=​"1" id=​"input1">​ and it will go to <input type value=​"2" id=​"input2">​
focusin: focus was gained by <input type value=​"2" id=​"input2">​

// Input3 is clicked
focusout: focus is leaving <input type value=​"2" id=​"input2">​ and it will go to <input type value=​"3" id=​"input3">​
focusin: focus was gained by <input type value=​"3" id=​"input3">​
```

Now, let's add a blur handler that changes focus:

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
  <div id="container">
    <input type="" value="1" id="input1">
    <input type="" value="2" id="input2">
    <input type="" value="3" id="input3">
  </div>

  <script>
    container.addEventListener('focusin', (ev) => {
      console.log('focusin: focus was gained by', ev.target);
    });
    container.addEventListener('focusout', (ev) => {
      console.log('focusout: focus is leaving', ev.target, 'and it will go to', ev.relatedTarget);
    });
    input2.addEventListener('blur', (ev) => {
      input2.focus();
    });
  </script>
</body>
</html>
```

The log sequence changes and gives the wrong impression that no dom element has focus:

```
// Input1 is clicked
focusin: focus was gained by <input type value=​"1" id=​"input1">​

// Input2 is clicked
focusout: focus is leaving <input type value=​"1" id=​"input1">​ and it will go to <input type value=​"2" id=​"input2">​
focusin: focus was gained by <input type value=​"2" id=​"input2">​

// Input3 is clicked, but the handler kicks in and instead of the following line being a focusout, it results in a focusin call first.
focusin: focus was gained by <input type value=​"2" id=​"input2">​
focusout: focus is leaving <input type value=​"2" id=​"input2">​ and it will go to null
```

In addition to that, during `focusout` processing, `activeElement` typically points to `<body />`. However, if an element is focused during a `blur` event, `activeElement` points to that focused element.  Although, undocumented it can be verified with:

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
  <div id="container">
    <input type="" value="1" id="input1">
    <input type="" value="2" id="input2">
    <input type="" value="3" id="input3">
  </div>

  <script>
    container.addEventListener('focusin', (ev) => {
      console.log('focusin: was gained by', ev.target);
    });
    container.addEventListener('focusout', (ev) => {
      console.log('document.hasFocus()', document.hasFocus());     
      console.log('document.activeElement', document.activeElement);
      console.log('focusout: focus is leaving', ev.target, 'and it will go to', ev.relatedTarget);
    });
    input2.addEventListener('blur', (ev) => {
      input2.focus();
    });
  </script>
</body>
</html>
```

We leverage these behaviors to ignore `focusout` events when the document has focus but `activeElement` is not `<body />`.

https://github.com/flutter/flutter/issues/153022

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-09-05 18:23:55 +00:00
Harry Terkelsen
acf6660982 Add crossOrigin property to <img> tag used for decoding (flutter/engine#54961)
Adds the `crossOrigin` property to the `<img>` tag used for decoding. This allows us to use cross-origin images in CanvasKit as if it were loaded from the same origin, as long as the CORS headers are properly set on the server hosting the image.

In the case where the image doesn't have proper CORS headers, this change causes an error to occur while attempting to decode, rather than later on in Skia when the image is converted into a texture. Hitting the cross-origin error later causes Skia to behave in undefined ways.

Progress towards https://github.com/flutter/flutter/issues/149843 

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-09-05 00:29:36 +00:00
gaaclarke
02b8207c9a Framework wide color linear gradients (flutter/engine#54748)
This implements wide gamut color support for gradients in the engine.

issue: https://github.com/flutter/flutter/issues/127855
integration test: https://github.com/flutter/flutter/pull/153976

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-09-04 23:50:19 +00:00
Kaylee Lubick
ef050da2b8 Use moved Skia Ganesh header files (flutter/engine#54833)
In http://review.skia.org/892736 and http://review.skia.org/893856, Skia
moved its Ganesh headers to align with the Graphite ones. This updates
Flutter to use those moved files.

All changes are mechanical and there is no API difference between the
headers (indeed, the old ones simply `#include` the new ones).

## 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].
- [ ] 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.
- [ ] 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
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[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
2024-09-04 07:09:51 -07:00
Yegor
6bddf99dc0 [web:canvaskit] switch to temporary SkPaint objects (flutter/engine#54818)
Do not eagerly create an `SkPaint` object that's strongly referenced by `CkPaint`. Instead, when a `Canvas.draw*` is called, create a temporary `SkPaint` object, pass it to Skia, then immediately delete it. This way there are no persistent `SkPaint` handles lurking in the system that transitively hold onto expensive native resources.

Addresses the `Paint` issue in https://github.com/flutter/flutter/issues/153678 in CanvasKit

Spot checking some benchmarks. Here's the effect of this PR on `draw_rect_variable_paint`. It's a bit of a stress test as it creates 300K distinct `Paint` objects to render 600 pictures (a typical ratio does not normally exceed ten paints to one picture). Even so, the effect of creating an extra `SkPaint` on every `draw*` command does not look significant. However, removing a dependency on the GC for 300K objects looks like a good trade-off.

## Before

Allocation stats:

```
  Paint Created: 300000
  Paint Deleted: 300000
  Paint Leaked: 300000
  Picture Created: 600
  Picture Deleted: 599
  Picture Leaked: 599
```

Performance stats:

```
windowRenderDuration: (samples: 98 clean/2 outliers/100 measured/300 total)
 | average: 4679.551020408163 μs
 | outlier average: 5100 μs
 | outlier/clean ratio: 1.0898481452084188x
 | noise: 3.11%

sceneBuildDuration: (samples: 98 clean/2 outliers/100 measured/300 total)
 | average: 4689.765306122449 μs
 | outlier average: 5100 μs
 | outlier/clean ratio: 1.087474461321549x
 | noise: 3.19%

drawFrameDuration: (samples: 97 clean/3 outliers/100 measured/300 total)
 | average: 8447.474226804125 μs
 | outlier average: 9332.666666666666 μs
 | outlier/clean ratio: 1.1047878236850721x
 | noise: 3.52%
```

## After

Allocation stats:

```
  Picture Created: 600
  Picture Deleted: 599
  Picture Leaked: 599
```

Performance stats:

```
windowRenderDuration: (samples: 97 clean/3 outliers/100 measured/300 total)
 | average: 4780.40206185567 μs
 | outlier average: 5133.666666666667 μs
 | outlier/clean ratio: 1.0738985131877936x
 | noise: 2.70%

sceneBuildDuration: (samples: 97 clean/3 outliers/100 measured/300 total)
 | average: 4787.6082474226805 μs
 | outlier average: 5133.666666666667 μs
 | outlier/clean ratio: 1.0722821085936345x
 | noise: 2.72%

drawFrameDuration: (samples: 97 clean/3 outliers/100 measured/300 total)
 | average: 8243.309278350516 μs
 | outlier average: 9033.333333333334 μs
 | outlier/clean ratio: 1.0958382159768851x
 | noise: 2.60%
```
2024-08-30 22:06:18 +00:00
gaaclarke
6596a35625 Reland: Hooks up framework wide gamut to engine wide gamut (flutter/engine#54906)
relands https://github.com/flutter/engine/pull/54567
depends on https://github.com/flutter/engine/pull/54905

This was reverted because the PR that it depends on was reverted.  There is nothing to be addressed here.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-08-30 18:22:04 +00:00
gaaclarke
df9fc7786b Reland: Framework wide color (#54415) (#54737) (flutter/engine#54905)
[This PR](https://github.com/flutter/engine/pull/54415) was reverted
because it required customer testing updates.

issue: https://github.com/flutter/flutter/issues/127855
integration test: https://github.com/flutter/engine/pull/54415

This does the preliminary work for implementing wide gamut colors in the
Flutter framework. Here are the following changes: 1) colors now specify
a colorspace with which they are to be interpreted 1) colors now store
their components as floats to accommodate bit depths more than 8

The storage of this Color class is weird with float/int storage but that
is a temporary solution to support a smooth transition. Here is the plan
for landing this: 1) Land this PR
1) Wait for it to roll into the Framework
1) Land https://github.com/flutter/flutter/pull/153938 which will make
CupertinoDynamicColor implement Color 1) Land another engine PR that
rips out the int storage: https://github.com/flutter/engine/pull/54714

Here are follow up PRs:
1) https://github.com/flutter/engine/pull/54473 - changes DlColor so the
wide gamut colors are rendered 1)
https://github.com/flutter/engine/pull/54567 - Hooks up these changes to
take advantage of wide DlColor 1)
https://github.com/flutter/flutter/pull/153319 - the integration test
for the framework repo

There are some things that have been left as follow up PRs since they
are technically breaking: 1) The math on `lerp` hasn't been updated to
take advantage of the higher bit depth 1) `operator==` hasn't been
updated to take advantage of the higher bit depth 1) `hashCode` hasn't
been updated to take advantage of the higher bit depth 1) `alphaBlend`
hasn't been updated to take advantage of the higher bit depth 1)
`toString` hasn't been updated to take advantage of the higher bit depth

## Reland 2 notes

This was reverted because it changes the math on `_lerpDouble`. While
those changes were mathematcially equivalent, they had different
behaviors when working with non-numbers which created unexpected
changes. The change has been reverted and a test added.

## 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/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[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
2024-08-30 10:33:07 -07:00
auto-submit[bot]
7b38e8d173 Reverts "Reland: Framework wide color (#54415) (#54737)" (flutter/engine#54885)
Reverts: flutter/engine#54737
Initiated by: chingjun
Reason for reverting: Breaking internal tests. See b/363125155
Original PR Author: gaaclarke

Reviewed By: {matanlurey, jonahwilliams}

This change reverts the following previous change:
[This PR](https://github.com/flutter/engine/pull/54415) was reverted because it requires a manual roll into the framework.

issue: https://github.com/flutter/flutter/issues/127855
integration test: https://github.com/flutter/engine/pull/54415

This does the preliminary work for implementing wide gamut colors in the Flutter framework. Here are the following changes: 1) colors now specify a colorspace with which they are to be interpreted 1) colors now store their components as floats to accommodate bit depths more than 8

The storage of this Color class is weird with float/int storage but that is a temporary solution to support a smooth transition. Here is the plan for landing this:
1) Land this PR
1) Wait for it to roll into the Framework
1) Land https://github.com/flutter/flutter/pull/153938 which will make CupertinoDynamicColor implement Color
1) Land another engine PR that rips out the int storage: https://github.com/flutter/engine/pull/54714

Here are follow up PRs:
1) https://github.com/flutter/engine/pull/54473 - changes DlColor so the wide gamut colors are rendered
1) https://github.com/flutter/engine/pull/54567 - Hooks up these changes to take advantage of wide DlColor
1) https://github.com/flutter/flutter/pull/153319 - the integration test for the framework repo

There are some things that have been left as follow up PRs since they are technically breaking:
1) The math on `lerp` hasn't been updated to take advantage of the higher bit depth
1) `operator==` hasn't been updated to take advantage of the higher bit depth
1) `hashCode` hasn't been updated to take advantage of the higher bit depth
1) `alphaBlend` hasn't been updated to take advantage of the higher bit depth
1) `toString` hasn't been updated to take advantage of the higher bit depth
2024-08-30 04:31:26 +00:00
auto-submit[bot]
677c70aa8a Reverts "Hooks up framework wide gamut to engine wide gamut (#54567)" (flutter/engine#54884)
Reverts: flutter/engine#54567
Initiated by: chingjun
Reason for reverting: Breaking internal tests. See b/363125155
Original PR Author: gaaclarke

Reviewed By: {jonahwilliams, chinmaygarde}

This change reverts the following previous change:
issue: https://github.com/flutter/flutter/issues/127855
integration test: https://github.com/flutter/engine/pull/54415

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-08-30 04:27:48 +00:00
gaaclarke
fdc343efec Hooks up framework wide gamut to engine wide gamut (flutter/engine#54567)
issue: https://github.com/flutter/flutter/issues/127855
integration test: https://github.com/flutter/engine/pull/54415

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-08-29 23:22:07 +00:00
gaaclarke
3b2f540e54 Reland: Framework wide color (#54415) (flutter/engine#54737)
[This PR](https://github.com/flutter/engine/pull/54415) was reverted because it requires a manual roll into the framework.

issue: https://github.com/flutter/flutter/issues/127855
integration test: https://github.com/flutter/engine/pull/54415

This does the preliminary work for implementing wide gamut colors in the Flutter framework. Here are the following changes: 1) colors now specify a colorspace with which they are to be interpreted 1) colors now store their components as floats to accommodate bit depths more than 8

The storage of this Color class is weird with float/int storage but that is a temporary solution to support a smooth transition. Here is the plan for landing this:
1) Land this PR
1) Wait for it to roll into the Framework
1) Land https://github.com/flutter/flutter/pull/153938 which will make CupertinoDynamicColor implement Color
1) Land another engine PR that rips out the int storage: https://github.com/flutter/engine/pull/54714

Here are follow up PRs:
1) https://github.com/flutter/engine/pull/54473 - changes DlColor so the wide gamut colors are rendered
1) https://github.com/flutter/engine/pull/54567 - Hooks up these changes to take advantage of wide DlColor
1) https://github.com/flutter/flutter/pull/153319 - the integration test for the framework repo

There are some things that have been left as follow up PRs since they are technically breaking:
1) The math on `lerp` hasn't been updated to take advantage of the higher bit depth
1) `operator==` hasn't been updated to take advantage of the higher bit depth
1) `hashCode` hasn't been updated to take advantage of the higher bit depth
1) `alphaBlend` hasn't been updated to take advantage of the higher bit depth
1) `toString` hasn't been updated to take advantage of the higher bit depth
2024-08-29 19:02:59 +00:00
Jackson Gardner
c518ebc094 [skwasm] Always do backdrop filter operation even if empty. (flutter/engine#54844)
This is a partial fix for https://github.com/flutter/flutter/issues/152026

We are still blocked on https://g-issues.skia.org/issues/362552959 for things to be completely working.
2024-08-28 21:19:54 +00:00
Ömer Sinan Ağacan
8da579925c Compile dart2wasm modules using the JS runtime exported compileStreaming (flutter/engine#51488)
With [1] dart2wasm started using the new Wasm built-in string import
`wasm:js-string`.

With [2] dart2wasm started exporting `compile` and `compileStreaming`
from the generated JS runtime to compile dart2wasm-generated modules
with the `wasm:js-string` built-in, polyfilling it when not available.

Update Wasm compilation code in Flutter to use `compileStreaming` from
the JS runtime, enabling fast `jwasm:js-string` module when available.

[1]: 44c2e17600
[2]: 4cd6096da4
2024-08-28 20:00:51 +02:00