3378 Commits

Author SHA1 Message Date
David Iglesias
76129ffb8f [web] Fix Scene clip bounds. Trigger resize on DPR Change. (flutter/engine#50161)
The Scene of the HTML renderer is passing incorrect size information to the engine, and when DPR<1, it can result in elements being culled off of the viewport.

In addition to that, when an app is embedded, not all changes in DPR cause a Resize event (only those some of the dimensions fails by a rounding error!), so this PR ensures that all DPR events in embedded trigger a resize event.

### Issues

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

### Testing

Looking good at: https://dit-astral-test.web.app

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-06 01:48:00 +00:00
Juanjo Tugores
358d8b6229 Add the focus state related methods to the platform dispatcher (flutter/engine#50273)
These changes were originally landed on
https://github.com/flutter/engine/pull/49841 but reverted in
64fe7b86c3.
I fixed the offending dart snippets and (think) they now will work
without issues (I think I was able to verify them locally by manually
patching my bin/cache/... copy of these files with these changes).

Relevant Issues are:
* Design doc link:
https://github.com/flutter/website/actions/runs/7560898849/job/20588395967
* Design doc: https://github.com/flutter/flutter/issues/141711
* Focus in web multiview:
https://github.com/flutter/flutter/issues/137443

## 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-02-02 10:13:00 -08:00
auto-submit[bot]
64fe7b86c3 Reverts "Add the focus state related methods to the platform dispatcher" (flutter/engine#50268)
Reverts flutter/engine#49841
Initiated by: zanderso
This change reverts the following previous change:
Original Description:
This change augments the platform dispatcher to allow the engine <===> framework to communicate flutter and platform focus changes.

Relevant Issues are:
* Design doc link: https://github.com/flutter/website/actions/runs/7560898849/job/20588395967
* Design doc: https://github.com/flutter/flutter/issues/141711
* Focus in web multiview: https://github.com/flutter/flutter/issues/137443

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-02 02:59:26 +00:00
Tong Mu
be6209e136 Remove number of arguments from defining Dart FFI (flutter/engine#50153)
The number of arguments are not used. 

And also, even if we need it in the future, they can be derived at compile time:

```cpp
template <typename T>
struct function_traits;

template <typename Ret, typename... Args>
struct function_traits<Ret(Args...)>
{
    using params = std::tuple<Args...>;
};

template <typename T>
constexpr std::size_t get_parameter_count() {
    return std::tuple_size<typename function_traits<T>::params>::value;
}

template <typename T>
struct member_function_traits;

template <typename C, typename Ret, typename... Args>
struct member_function_traits<Ret(C::*)(Args...)>
{
    using params = std::tuple<Args...>;
};

template <typename T>
constexpr std::size_t get_member_function_parameter_count() {
    return std::tuple_size<typename member_function_traits<T>::params>::value;
}

```

(I got the code above with ChatGPT but I verified that they work)

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-01 23:58:31 +00:00
Juanjo Tugores
9858aa35c2 Add the focus state related methods to the platform dispatcher (flutter/engine#49841)
This change augments the platform dispatcher to allow the engine <===>
framework to communicate flutter and platform focus changes.

Relevant Issues are:
* Design doc link:
https://github.com/flutter/website/actions/runs/7560898849/job/20588395967
* Design doc: https://github.com/flutter/flutter/issues/141711
* Focus in web multiview:
https://github.com/flutter/flutter/issues/137443

## 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-02-01 13:20:30 -08:00
auto-submit[bot]
90b6db8915 Reverts "Remove migration flag and unused header files" (flutter/engine#50229)
Reverts flutter/engine#50216
Initiated by: zanderso
This change reverts the following previous change:
Original Description:
The `applyRoundingHack` flag is no longer used by the framework. This also removes the [lib/ui/text/line_metrics.h](https://github.com/flutter/engine/pull/50216/files#diff-9175619f2b114dffef67eba38511b34afe6abefd4f697f4758647133895b34f5) file which doesn't seem to be referenced anywhere.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-01 03:47:16 +00:00
Tong Mu
f1b651bfd0 Multiview: Add view ID to _render and remove render rule skipping (flutter/engine#50220)
This PR adds a view ID parameter to the Dart FFI `_render` function, and
also remove the logic that skips illegal renders that violates the
render rule.

I decided to implement the change to add the view ID as a separate PR
because it's blocking us from performing benchmark testing internally,
which is required to verify before merging the full multiview pipeline.

We're also abolishing the render rule for now to allow presenting the
warmup frame, which affects the startup performance. It is planned to
implement the render rule once we can coordinate the warmup frame into
the pipeline.

### More on removing the render rule enforcement

The project needs to be divided into two phases:
* Phase 1: Dart:ui doesn't kip out-of-vsync frames. And the pipeline
presents these frames in a hacky way.
* Phase 2: Dart:ui skip out-of-vsync frames, but submit warmup frames
using a dedicated method. The pipeline contains no hacks.

The current logic only enforces the render rule in debug mode. It's not
desired to have the debug mode and the release mode behaving
differently. Moreover, I'd like to make only the necessary changes for
phase 1, so that there is as little "to be used in the future" code
between the two phases as possible.

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] 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.
- [ ] 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 `///`).
- [ ] I signed the [CLA].
- [ ] 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-01-31 16:38:07 -08:00
LongCatIsLooong
737437f718 Remove migration flag and unused header files (flutter/engine#50216)
The `applyRoundingHack` flag is no longer used by the framework. This also removes the [lib/ui/text/line_metrics.h](https://github.com/flutter/engine/pull/50216/files#diff-9175619f2b114dffef67eba38511b34afe6abefd4f697f4758647133895b34f5) file which doesn't seem to be referenced anywhere.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-01 00:36:16 +00:00
Ashish Myles
1ee98ba880 Make screen reader announcement append a non-breaking space every other message. (flutter/engine#50151)
This fixes an issue when the same message was sent to the screen reader
again and was not subsequently announced by VoiceOver despite the prior
message having long been removed from the DOM.

Fixes https://github.com/flutter/flutter/issues/142250
2024-01-31 17:30:15 -05:00
Harry Terkelsen
2db9940615 [CanvasKit] Only render one frame at a time. (flutter/engine#50055)
Only have one additional queued frame. If more than one frame is
requested while the current frame is rendering, only the last frame is
queued.

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

## 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-01-31 14:00:08 -08:00
Mouad Debbar
266c32239f [web] Final nail in FlutterViewEmbedder's coffin (flutter/engine#49769)
- Extracted `ResourceManager` out of `FlutterViewEmbedder`.
- Extracted `GlobalHtmlAttributes` out of `FlutterViewEmbedder`.
- Removed usages of:
    - `FlutterViewEmbedder.reset()`.
    - `flutterViewEmbedder`.
    - `ensureFlutterViewEmbedderInitialized`.
- Deleted `FlutterViewEmbedder`.

Fixes https://github.com/flutter/flutter/issues/134443
2024-01-31 17:22:44 +00:00
Jonah Williams
1cd141f1a1 [Impeller] Reland: add interface for submitting multiple command buffers at once. (flutter/engine#50180)
Reland of:  https://github.com/flutter/engine/pull/50139

Metal does not seem to like it when we collect 50+ command buffers at once. Adjust the aiks context logic to regularly flush the cmd buffers.
2024-01-30 21:21:48 +00:00
auto-submit[bot]
f3e4437823 Reverts "[Impeller] Add interface for submitting multiple command buffers at once." (flutter/engine#50174)
Reverts flutter/engine#50139
Initiated by: jonahwilliams
This change reverts the following previous change:
Original Description:
The Impeller Vulkan backend benefits from batching submission to the vk graphics queue. Managing this automatically is non-trivial and adds surprising/fragile thread based behavior, see: https://github.com/flutter/engine/pull/49870

Instead, introduce an impeller::CommandQueue object that command buffers must be submitted to in lieu of CommandBuffer->Submit, which has been made private.

TLDR

old
```c++
buffer->Submit();
```

new
```c++
context.GetQueue()->Submit({buffer});
```

The Metal and GLES implementations internally just call the private CommandBuffer->Submit, though there may be future opportunities to simplify here. The Vulkan implementation is where the meat is.

Aiks takes advantage of this by storing all command buffers on the aiks context while rendering a frame, and then performing one submit in aiks_context render. I don't think this will introduce any thread safety problems, as we don't guarantee much about aiks context - nor do we use it in a multithreaded context as far as I know.

Other tasks such as image upload still just directly submit their command buffers via the queue.

Fixes https://github.com/flutter/flutter/issues/141123
2024-01-30 17:13:17 +00:00
Jonah Williams
6b613131d1 [Impeller] Add interface for submitting multiple command buffers at once. (flutter/engine#50139)
The Impeller Vulkan backend benefits from batching submission to the vk graphics queue. Managing this automatically is non-trivial and adds surprising/fragile thread based behavior, see: https://github.com/flutter/engine/pull/49870

Instead, introduce an impeller::CommandQueue object that command buffers must be submitted to in lieu of CommandBuffer->Submit, which has been made private.

TLDR

old
```c++
buffer->Submit();
```

new
```c++
context.GetQueue()->Submit({buffer});
```

The Metal and GLES implementations internally just call the private CommandBuffer->Submit, though there may be future opportunities to simplify here. The Vulkan implementation is where the meat is.

Aiks takes advantage of this by storing all command buffers on the aiks context while rendering a frame, and then performing one submit in aiks_context render. I don't think this will introduce any thread safety problems, as we don't guarantee much about aiks context - nor do we use it in a multithreaded context as far as I know.

Other tasks such as image upload still just directly submit their command buffers via the queue.

Fixes https://github.com/flutter/flutter/issues/141123
2024-01-30 07:48:35 +00:00
David Iglesias
d9ef3e2551 [web] Do not wipe the PlatformViewManager when disposing of a view. (flutter/engine#49991)
When a view gets disposed of, its rasterizer completely clears up the singleton `PlatformViewManager`. Particularly, it removes all registered platform view factories.

This is wrong because the remaining PlatformViews on the page cannot be re-rendered, and the default Platform View factories (used by `pointer_interceptor`, for example), disappear.

This PR attempts to preserve the `dispose` logic of the canvaskit rasterizer, without using the `debugClear` method of the `PlatformViewManager` (which is supposedly test-only).

## Issues

* Fixes https://github.com/flutter/flutter/issues/142094

## Tests

* Added unit-test
* Deployed demo app: https://dit-maps-tests.web.app

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-26 20:23:26 +00:00
Matan Lurey
e9e5a237f8 Finish landing missing/incorrect header guards across flutter/engine (flutter/engine#50069)
Generated by https://github.com/flutter/engine/pull/48903 (`dart ./tools/header_guard_check/bin/main.dart --fix`).

As discussed with @cbracken and @jmagman, the guards are not technically needed on the Mac/iOS code, but they (a) do not hurt and (b) still provide value if for some reason `#include` is used instead of `#import` (though I suspect we could try to add that to the tool in the future as well).
2024-01-26 19:42:36 +00:00
David Iglesias
9cc9f396b5 [web] Add views proxy and getInitialData. (flutter/engine#49320)
Adds a Dart API so Application/Plugin programmers can retrieve the `initialData` configuration value that may be passed when adding a view from JS in a multiViewEnabled app.

When adding a view to an app like this:

```js
flutterApp.addView({
  hostElement: someElement,
  initialData: {
    randomUUID: globalThis.crypto.randomUUID(),
  }
});
```

`initialData` can be accessed from Dart by defining a JS-interop class like:

```dart
import 'dart:js_interop';

// The JS-interop definition of the `initialData` object passed to the views of this app.
@JS()
@staticInterop
class InitialData {}

/// The attributes of the [InitialData] object.
extension InitialDataExtension on InitialData {
  external String? get randomUUID;
}
```

And then, from the code of the application:

```dart
...
  Widget build(BuildContext context) {
    final int viewId = View.of(context).viewId;
    final InitialData? data = ui_web.views.getInitialData(viewId) as InitialData?;
    return Text('${data?.randomUUID}');
  }
...
```

## Testing

Will add unit tests once naming is sorted out :)

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-26 02:36:37 +00:00
David Iglesias
4292cddf6f [web] Prevent re-rendering disposed views when the engine hot restarts. (flutter/engine#49958)
While debugging a different [issue](https://github.com/flutter/flutter/issues/141588), @elliette identified a problem with the web engine when a flutter web app hot-restarts.

TL;DR: the engine is requesting the framework to re-render a view as it tears them down, causing an assertion failure.

This fix stops listening to changes on view "disposed" events when the engine itself is being disposed, so it doesn't trigger re-renders for views that are never coming back.

## Issues

* Fixes https://github.com/flutter/flutter/issues/142030

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-26 02:26:21 +00:00
Bruno Leroux
282cb244ad Fix a typo in ChannelBuffers documentation (flutter/engine#49928)
Fix one typo in ChannelBuffers documentation
2024-01-25 21:17:17 +00:00
maRci002
e0a9cc7ce0 [web] add support for AppLifecycleState changes (flutter/engine#44720)
closes flutter/flutter#53107

This PR introduces support for `AppLifecycleState` on Web, aligning the web's lifecycle events with those of the mobile platforms. This ensures a more consistent developer experience and better lifecycle management across all platforms.

**PR includes:**

- Page Visibility Handling: Integrated the `visibilitychange` DOM event to determine if the app is in a `resumed` or `paused` state based on the visibility state of the document.
- Page Transition Handling: Used `beforeunload` events to better manage the `detached` state.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-25 16:31:12 +00:00
Jonah Williams
31a5d5d5c9 [Impeller] use const std::unique_ptr ref for Sampler type. (flutter/engine#49974)
The backend specific sampler libraries hold a strong reference to the native sampler objects and never clear this cache. As a result of this, we don't theoretically need rendering commands to increment a shared_ptr ref count - instead the sampler library can provide the Sampler object as a const ref and guarantee that it continues to be valid.

This allows us to reduce the amount of refcount ops for commands that use samplers.

Additionally, the sampler library uses nullptr as a sentinel for failing to construct a sampler object. Since sampler already has an isValid member that is checked - we can replace this with a specific invalid object subtype.
2024-01-24 18:14:42 +00:00
Jonah Williams
6f0249a062 [ui] hold a strong reference to fragment program objects. (flutter/engine#49868)
The native engine needs to hold a strong reference to fragment programs. So the dart side holding a weak ref is more or less pointless
2024-01-24 00:08:24 +00:00
Bruno Leroux
2538fd2edb [Web] Fix an assertion error due to synthesized keyboard events (flutter/engine#49087)
## Description

On Web, browsers can emit key events with a logical key sets to `Process` during compostion.
It is usually not a problem, but in some edge cases (for instance when the browser window lost focus and some keys events were missed), the Flutter web engine might synthesize an up event with a logical key value different that the one used for the down event and this will lead to an assertion message on the framework side.

## Related Issue

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

## Tests

Adds 1 test.
2024-01-23 20:26:12 +00:00
Mouad Debbar
22a1d5c7d7 [web] Bootstrap tests without implicit view by default (flutter/engine#48629)
- Follow up tests for https://github.com/flutter/engine/pull/48505
    - Tests for navigation without an implicit view should work.
- Package [this workaround](6efee0e79b/lib/web_ui/test/engine/semantics/semantics_multi_view_test.dart (L29-L30)) behind a nice, future-proof API.
- Tests by default start with no implicit view.
    - Tests that need an implicit view have to explicitly indicate so (by using the `withImplicitView` param).

Fixes https://github.com/flutter/flutter/issues/138906
2024-01-22 20:43:50 +00:00
Jonah Williams
e7be989feb Reland: Encode directly to command buffer. (flutter/engine#49821)
The original change was reverted as it broke the GPU tracer reset logic. The previous logic assumed that the first started command buffer would also be the first submitted command buffer. With the direct encoding, this is no longer the case - so we shift the logic so that we reset query pools once at startup and then after the queries are finished being recorded.

This might actually be better in general since we should be doing less work in the frame workload.
2024-01-19 19:21:47 +00:00
Harry Terkelsen
de6ec5b77e [canvaskit] Fall back to multi-context rendering on Firefox and Safari (flutter/engine#49572)
This PR refactors rasterization to support two different modes, single
GL context mode backed by a single OffscreenCanvas (Chrome), and
multi-context mode which uses many GL contexts and canvases.

## 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-01-18 11:22:09 -08:00
Yegor
eb33bab677 [web] fix ==/hashCode/toString for several classes across renderers (flutter/engine#49786)
Fix equality and hash code in `ParagraphStyle` and `StrutStyle` across renderers. Since those classes transitively rely on `Paint` and other classes, also fix those at least to a point that they pass the `test/painting/text_style_test.dart` test on the framework side.
2024-01-18 04:01:28 +00:00
Brandon DeRosier
d3951b683b Flutter GPU: Add GpuContext.createHostBuffer (flutter/engine#49822)
Just a quick fix to use the same pattern as other GpuContext derivative things.
2024-01-17 05:25:12 +00:00
auto-submit[bot]
a501e644c2 Reverts "[Impeller] Encode directly to command buffer for Vulkan." (flutter/engine#49818)
Reverts flutter/engine#49780
Initiated by: jonahwilliams
This change reverts the following previous change:
Original Description:
Part of https://github.com/flutter/flutter/issues/140804

Rather than using impeller::Command, the impeller::RenderPass records most state directly into the Vulkan command buffer. This should remove allocation/free overhead of the intermediary structures and make further improvements to the backend even easier. This required a number of other changes to the renderer:

1. The render pass holds a strong ptr to the context. This helps avoid locking continually while encoding, which is quite slow.
2. barriers need to be encoded on the _producing_ side, and not the consuming side. This is because we'll actually run the consuming code before the producing code. i.e. we transition to shader read at the end of a render pass instead of when binding.
3. I've updated the binding code to also provide the descriptor type so that we don't need to look it up from the desc. set.
4. I added a test render pass class that records commands.
2024-01-17 01:18:17 +00:00
David Iglesias
c2b2e4b2b2 [web] Leave blob URLs untouched in TT policy. (flutter/engine#49782)
Very simple tweak to flutter.js that allows blob URLs to be used as entrypointUrls when loading flutter (this is needed by dartpad)

## Testing

I had to test this locally by spinning up a flutter app with something like:

```html
<script>
  let initSrc = `let actualMain = document.createElement("script");
document.head.appendChild(actualMain);
actualMain.id = "injected_from_a_blob";
actualMain.src = "main.dart.js";`;
  let blobInit = new Blob([...initSrc]);
  let blobUrl = URL.createObjectURL(blobInit);
</script>
<script>
  window.addEventListener('load', function(ev) {
    // Download main.dart.js
    _flutter.loader.loadEntrypoint({
      entrypointUrl: blobUrl,
      onEntrypointLoaded: function(engineInitializer) {
        engineInitializer.autoStart();
      }
    });
  });
</script>
```

## Issues

* Fixes https://github.com/flutter/flutter/issues/141329

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-16 22:53:08 +00:00
Jonah Williams
97e3fdb511 [Impeller] Encode directly to command buffer for Vulkan. (flutter/engine#49780)
Part of https://github.com/flutter/flutter/issues/140804

Rather than using impeller::Command, the impeller::RenderPass records most state directly into the Vulkan command buffer. This should remove allocation/free overhead of the intermediary structures and make further improvements to the backend even easier. This required a number of other changes to the renderer:

1. The render pass holds a strong ptr to the context. This helps avoid locking continually while encoding, which is quite slow.
2. barriers need to be encoded on the _producing_ side, and not the consuming side. This is because we'll actually run the consuming code before the producing code. i.e. we transition to shader read at the end of a render pass instead of when binding.
3. I've updated the binding code to also provide the descriptor type so that we don't need to look it up from the desc. set.
4. I added a test render pass class that records commands.
2024-01-16 21:52:54 +00:00
Brandon DeRosier
c38b3676d9 [Flutter GPU] Run unittests on CI and fix HostBuffer. (flutter/engine#49789)
The Flutter GPU tests were broken, and it turns out that I had never set them up to run on CI. This fixes the HostBuffer and gets the test suite running on CI.
2024-01-16 19:01:54 +00:00
Jonah Williams
6a1ac6c14a [Impeller] finish migration to new render pass API. (flutter/engine#49740)
Part of https://github.com/flutter/flutter/issues/140804

Migrate the rest of the commands in impeller to use the new API. Hide RenderPass::AddCommand. On subsequent changes I will be able to begin making some of these methods virtual so we can add more direct pass through. Though the vulkan backend will be blocked on changes to descriptor sets: https://github.com/flutter/engine/pull/49686
2024-01-12 21:13:19 +00:00
Jonah Williams
06ee89691e [Impeller] remove Buffer type and associated abstractions. (flutter/engine#49702)
Now that the HostBuffer isn't implementing Buffer, there is really no reason to have a Buffer/DeviceBuffer split. make BufferViews use a DeviceBuffer, and remove the data ptr from buffer views (as we can always reach into the device buffer).

Makes some other cleanups too, since we always use a std::shared_ptr<DeviceBuffer>, then we can eliminated the shared_from_this call for AsBufferView by making this a static method.
2024-01-12 20:22:11 +00:00
Dan Field
4681274469 [Impeller] Vulkan runtime effects/fragment program API (flutter/engine#49543)
Fixes https://github.com/flutter/flutter/issues/122823
Fixes https://github.com/flutter/flutter/issues/129659
Fixes https://github.com/flutter/flutter/issues/123741

This patch makes runtime stage/fragment program stuff work on Vulkan for Android.

It will need flutter/flutter#140976 for that to become a reality for flutter_tools users.

Compiling with relaxed Vulkan semantics still has an issue: shaders that use `sampler2D` with an explicitly set `location` on the `layout` will fail to compile with an error documented in https://github.com/flutter/flutter/issues/141219.

I think there might still be some issues with fragment programs on Vulkan, but this should at least be a good starting point and unblocks ink_sparkle.frag usage in the framework.

I've deleted some runtime_stage related code that would never get used - for example, enum related code that indicates we might support a bunch of data types that we do not and probably never will support in this API.
2024-01-11 02:25:05 +00:00
Jonah Williams
c18d6e3a08 [Impeller] reland: write directly to device buffer. (flutter/engine#49691)
Reland of https://github.com/flutter/engine/pull/49505

---

part of https://github.com/flutter/flutter/issues/140804

We can't use the existing host buffer abstraction as that requires us to collect all allocations up front. By itself, this isn't sufficient for #140804 , because we'll need a way to mark ranges as dirty and/or flush if we don't have host coherent memory. But by itself this change should be beneficial as we'll create fewer device buffers and should do less allocation in general.

The size of the device buffers is 1024 Kb, somewhat arbitrarily chosen.
2024-01-10 22:10:03 +00:00
auto-submit[bot]
6236178dac Reverts "[Impeller] have Hostbuffer write directly to block allocated device buffers." (flutter/engine#49688)
Reverts flutter/engine#49505
Initiated by: jonahwilliams
This change reverts the following previous change:
Original Description:
part of https://github.com/flutter/flutter/issues/140804

We can't use the existing host buffer abstraction as that requires us to collect all allocations up front. By itself, this isn't sufficient for #140804 , because we'll need a way to mark ranges as dirty and/or flush if we don't have host coherent memory. But by itself this change should be beneficial as we'll create fewer device buffers and should do less allocation in general.

The size of the device buffers is 1024 Kb, somewhat arbitrarily chosen.
2024-01-10 21:09:18 +00:00
Jonah Williams
eaae4c5d1a [Impeller] have Hostbuffer write directly to block allocated device buffers. (flutter/engine#49505)
part of https://github.com/flutter/flutter/issues/140804

We can't use the existing host buffer abstraction as that requires us to collect all allocations up front. By itself, this isn't sufficient for #140804 , because we'll need a way to mark ranges as dirty and/or flush if we don't have host coherent memory. But by itself this change should be beneficial as we'll create fewer device buffers and should do less allocation in general.

The size of the device buffers is 1024 Kb, somewhat arbitrarily chosen.
2024-01-10 17:18:07 +00:00
Jackson Gardner
e9e609ee85 Refactor flutter.js to do dart2wasm bootstrapping and CanvasKit/Skwasm preloading. (flutter/engine#49037)
This PR makes some major revisions to our flutter.js bootstrapper.
* Modularize flutter.js into multiple files to make it a little simpler to manage from source code. They are still bundled into a single .js file by esbuild.
* Added a `types.d.ts` file which contains declarations of the types of some of the objects used in the flutter.js API
* Deprecated the old `FlutterLoader.loadEntrypoint` API and added a new function simply called `FlutterLoader.load`, which has a few more capabilities:
  -  A build tool can inject a build config, that may describe multiple builds that `FlutterLoader.load` can attempt to use. It will use the first one that is compatible with the browser environment and the user's configuration.
  - It can also load wasm flutter apps.
  - It also pre-loads and instantiates CanvasKit (and Skwasm) as necessary depending on the build configuration.
  - `FlutterLoader.load` also immediately takes a flutter configuration object. If an `onEntrypointLoaded` callback is not provided by the user, it just does the expected thing and initializes the engine and immediately starts the app, passing the configuration along as needed.
 * `flutter.js` has the engine hash built into it now, which allows it to ascertain the correct CDN URLs for both CanvasKit and Skwasm.
2024-01-10 00:17:32 +00:00
Brandon DeRosier
5b0cee27ad [Flutter GPU] Track HostBuffer emplacements by offset. (flutter/engine#49618)
Make the wrapped HostBuffer wrapper track/look up emplacements using a
fake byte offset.

This is a trick to keep Flutter GPU working after
https://github.com/flutter/engine/pull/49505 lands. I'll likely swing
around and change how `BufferView` works later on. We can simplify a lot
by making Flutter GPU `BufferView`s just take `DeviceBuffer` handles.
2024-01-09 10:32:51 -08:00
Brandon DeRosier
fa43ada615 [Flutter GPU] Shader bundle improvements: Uniform structs & member offset reflection, GLES metadata, separate from runtime stage. (flutter/engine#49485)
* Switch from legacy uniform semantics to uniform structs.
* Completely separate shader bundle from runtime stage.
* Packing multiple backends per shader.
* Pack struct and member fields into the shader bundle flatbuffer.
* Bind uniforms with correct metadata for GLES.
* Add uniform struct size and member offset reflection.
2024-01-08 11:44:20 -08:00
Jonah Williams
2c700c6a90 [Impeller] remove SamplerLibrary forward declare. (flutter/engine#49573)
The forward declaration of SamplerLibrary in context.h is uncessary. remove it and clean up includes.
2024-01-06 19:20:39 +00:00
Tong Mu
ceaa4c9fc6 Revert skiping illegal render in Dart (flutter/engine#49473) 2024-01-03 10:45:16 -08:00
Dan Field
125a9161bb [Impeller] Allow multiple --runtime-stage-* parameters to impellerc (flutter/engine#49475)
This patch will be important for Android/Vulkan, where we'll need to bundle GLES, Vulkan, and SkSL (at least for now).

I've refactored impellerc_main to break up some of the larger methods into more granular ones.

I've also changed the way that the `IPLR` output works so that we create as many compilers as runtime stages requested.

We still are in a weird situation where we create one "Default" compiler for the reflection data and depfile. I don't think that needs to be addressed in this patch, but we should do something about this. I've talked a little with @bdero and @jonahwilliams - it will probably involve something like making the generated reflection data a bit more flexible than it currently is so that it can more ergonomically capture different platform anomalies - we could do this either by having a compiler type that is explicitly for generating reflection data rather than using one arbitrary one and making the reflector try to be platform agnostic. I've filed a couple TODOs related to this and linked them in the patch.

Fixes https://github.com/flutter/flutter/issues/140817
2024-01-03 06:55:29 +00:00
Yegor
7dce8b8825 [web] make TextStyle implementations consistent (flutter/engine#49465)
Make TextStyle implementations consistent across web renderers and consistent with the mobile implementation. This will allow us to unskip `test/painting/text_style_test.dart` on the framework side.
2024-01-02 20:41:08 +00:00
Harry Terkelsen
20ef29732d Reland "[web] Enforce onDrawFrame/onBeginFrame render rule" (flutter/engine#49336)
Enforces the render rule on the web except in the HTML renderer, which
must still render to the DOM even outside of `onDrawFrame` or
`onBegineFrame` scopes in order for golden tests to continue to work in
the framework.

This is a reland of https://github.com/flutter/engine/pull/49214 with
one change (checking for `renderer.rendererTag == 'html'` in the
`render` method).

## 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
2023-12-21 13:10:27 -08:00
Chris Bracken
535bb52c87 Revert onrender change (flutter/engine#49333)
This reverts https://github.com/flutter/engine/pull/49214 and
https://github.com/flutter/engine/pull/48758.

https://github.com/flutter/engine/pull/49214 appears to cause a Flutter
Gold diff during the engine roll. See
https://github.com/flutter/flutter/pull/140434 for an example. It's
unclear to me whether this is an expected diff and should be approved or
unexpected and should be reverting, so reverting to the last previous
rollable state.

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] 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.
- [ ] 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 `///`).
- [ ] I signed the [CLA].
- [ ] 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
2023-12-21 11:00:30 -08:00
Yegor
409fb68d25 [web] autofocus in new routes (flutter/engine#47727)
Fixes https://github.com/flutter/flutter/issues/138371

When a new route pops up the expectation is that the screen reader focuses on something in the new route. Since routes typically result in DOM nodes being replaced, the current effect is that the screen reader simply unfocuses from the page, causing the user to have to refocus on back on the page and look for elements to interact with, which is a poor user experience. The current workaround is to use `autofocus`, but that doesn't scale as it's easy to forget, and if the route in question is maintained by a different person you may not even have enough control over it to set `autofocus` on anything. For example, this is the case with Flutter's default date picker. All you have is `showDatePicker` and there's no way to control the focus.

With this change the route (managed by the `Dialog` primary role) will check if a widget requested explicit focus (perhaps using `autofocus`), and if not, looks for the first descendant that a screen reader can focus on, and requests focus on it. The auto-focused element does not have to be literally focusable. For example, plain `Text` nodes do not have input focus (i.e. they are not `isFocusable`) but screen readers can still focus on them. If such an element is found, the web engine requests that the browser move focus to it programmatically (`element.focus()`), which causes the screen reader to move the a11y focus to it as well, but it sets `tabindex=-1` so the element is not focusable via keyboard or mouse.
2023-12-21 18:11:13 +00:00
Jim Graham
910a5fa5d8 Ensure sorted rects in ui.Canvas for legacy compatibility (flutter/engine#49309)
Fixes https://github.com/flutter/flutter/issues/140490
2023-12-21 08:34:23 +00:00
Dan Field
ae9289f5c1 [Impeller] Make IPLR files multi-platform (flutter/engine#49253)
This is part of the work towards supporting OpenGLES and Vulkan for runtime stage shaders.

Removes some redundant work we had around SkSL. Now only bundles the shaders we actually ask for from the command line.

@bdero, we should figure out if this is the right approach for flutter_gpu.

With this change, the IPLR format goes from having a root table of shader related information to a root table of shader information per `sksl`, `metal`, `opengles`, and `vulkan` platforms. 

This may end up allowing us to revert https://github.com/flutter/engine/pull/47278, but I'm not sure I understand all the implications of that at this point.

I have run some but not all tests locally.
2023-12-21 06:17:26 +00:00