731 Commits

Author SHA1 Message Date
chunhtai
03195e6990
Reapply "Add set semantics enabled API and wire iOS a11y bridge" (#174163)
<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->


Previous pr is reverted due to internal test failure

This is a straight reland, no change from previous. only need to migrate
internal code

fixes https://github.com/flutter/flutter/issues/158399

## 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], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-08-29 19:29:12 +00:00
Camille Simon
daadbba856
[Android] Restrict AOT shared library engine flag to trusted paths (#173359)
### Overview

Restricts the `--aot-shared-library-name` flag used for launching
`FlutterFragment`s to only accept paths that point to the application's
internal storage.

### Why restrict the path at all

Currently, when an application launches a `FlutterFragment` with an
`Intent` that passes the `--aot-shared-library-name` flag, the Flutter
engine [will call
`dlopen`](f45a8f8b71/engine/src/flutter/fml/platform/posix/native_library_posix.cc (L14))
on the native code that lives where the passed path points with no
checks. So, if that path points to malicious code, we've got a problem.
See go/flutter-fragment-flag-security-analysis for full context.

By restricting the path to a trusted location, we ensure that the
application developer is either writing their own native code (that we
can assume not to be malicious) or is importing third party code and
manually packaging it with their application code, ensuring that it has
been vetted by the application author (or at least indicating that it
should be vetted).

### Why restrict the path to the application's internal storage

The [native code directory within internal
storage](https://developer.android.com/reference/android/content/pm/ApplicationInfo#nativeLibraryDir)
is where native JNI libraries are stored by default when the AGP
[`useLegacyPackaging`
option](https://developer.android.com/build/releases/past-releases/agp-4-2-0-release-notes#compress-native-libs-dsl)
is set to true, so any compiled native code that's part of an Android
app will live there.

If `useLegacyPackaging` is set to false or the application developer
wishes to reference native code some other way, they can manually
package it within internal storage, which is generally a secure place to
store files for your application needs. Also, as far as I'm aware, this
is the only secure place the application developers could reference
native code *by path* in their application (for example, developers
could put their native code in the `app/src/main/assets` directory, then
copy it into internal storage for reference by path).

_My primary sources:_
https://developer.android.com/ndk/guides/concepts
https://developer.android.com/studio/projects/add-native-code
https://developer.android.com/training/data-storage

### Prior art

Flutter has enforced a similar sort of path restriction for the
`file_selector_android` package; see
https://github.com/flutter/packages/pull/8184. Just like that PR does,
this PR makes sure to canonicalize paths passed to the flag and attempts
to test sneaky partial internal storage paths to mitigate path traversal
attacks.

### Future work

As mentioned in my TODO, the pattern of willy-nilly adding any flags
passed in an `Intent` to launch a `FlutterFragment` is dangerous. We
plan to address this vulnerability in a future PR:
https://github.com/flutter/flutter/issues/172553

### P.S. This PR also renames `application_library_path` to
`application_library_paths`

This is actually a vector of AOT shared library (plural) paths that can
include the one passed with the `--aot-shared-library-name` flag as well
as the fallbacks.

## 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], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-08-27 16:24:28 +00:00
auto-submit[bot]
960d1078f8
Reverts "Reapply "Add set semantics enabled API and wire iOS a11y bridge (#161… (#171198)" (#174153)
<!-- start_original_pr_link -->
Reverts: flutter/flutter#171198
<!-- end_original_pr_link -->
<!-- start_initiating_author -->
Initiated by: chunhtai
<!-- end_initiating_author -->
<!-- start_revert_reason -->
Reason for reverting: breaking internal tests
<!-- end_revert_reason -->
<!-- start_original_pr_author -->
Original PR Author: chunhtai
<!-- end_original_pr_author -->

<!-- start_reviewers -->
Reviewed By: {jmagman, mdebbar}
<!-- end_reviewers -->

<!-- start_revert_body -->
This change reverts the following previous change:
…265)"

This reverts commit cc04ca4e5594fe9cd87adde34a5eedf14221fc3b.

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

fixes https://github.com/flutter/flutter/issues/158399

## 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], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] 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/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

<!-- end_revert_body -->

Co-authored-by: auto-submit[bot] <flutter-engprod-team@google.com>
2025-08-20 19:43:47 +00:00
chunhtai
3e4d171664
Reapply "Add set semantics enabled API and wire iOS a11y bridge (#161… (#171198)
…265)"

This reverts commit cc04ca4e5594fe9cd87adde34a5eedf14221fc3b.

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

fixes https://github.com/flutter/flutter/issues/158399

## 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], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] 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/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-08-19 17:33:07 +00:00
Derek Xu
f4b9249d60
Add --profile-startup switch (#172879)
This PR adds a switch that can be used to set [the Dart VM's
`profile_startup`
flag](21ce423b26/runtime/vm/profiler.cc (L68)).
2025-07-30 14:39:37 +00:00
Derek Xu
10f0589a14
Activate microtask profiling in dart:async when Switch::ProfileMicrotasks is set (#171035)
Here is the logic in the Dart VM that is analogous to the logic in this
PR:
2be548666d/runtime/bin/dartutils.cc (L540-L561).
2025-06-30 13:59:34 +00:00
Derek Xu
b6d2b3552b
Add --profile-microtasks switch (#170690)
This PR adds a switch that can be used to set [the Dart VM's
`profile_microtasks`
flag](c48dd51b90/runtime/vm/microtask_mirror_queues.cc (L18-L23)).
2025-06-18 14:13:32 +00:00
Jia Hao
32b513bbb2
Revert "Add call to Dart_NotifyDestroyed when the flutter view is des… (#170309)
…troyed. (flutter/engine#37539)"

This reverts commit 7296b2b66dac82f04ebe9017320bde81a7b5f486.

In b/422322882, we have done a small experiment on addtoapp Android,
with and without a patched engine where `Dart_NotifyDestroyed` is not
called:

1. Add a Flutter view
2. Measure memory with `adb shell dumpsys meminfo`
3. Call detach
5. Measure memory again

"Call detach" refers to the following pseudocode:

```kt
    flutterViewContainer.removeView(flutterView)
    engine.activityControlSurface.detachFromActivity()
    engine.lifecycleChannel.appIsDetached()
    flutterView!!.detachFromFlutterEngine()
```

We observed that the memory recordings with and without the patched
engine are mostly the same. @a-siva also mentioned that
7296b2b66dac82f04ebe9017320bde81a7b5f486 could be no longer needed
today.

## 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], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [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/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-06-10 21:34:29 +00:00
Ben Konyi
51eef3db10
Remove Observatory build rules and remaining references from the engine (#169945)
Work towards https://github.com/dart-lang/sdk/issues/50233

FYI @a-siva
2025-06-03 21:09:30 +00:00
Jonah Williams
c0c12a759e
[Impeller] reland: defer impeller context initialization onto the raster thread. (#167765)
Attempt to speed up vulkan startup by ensuring vulkan driver
initialization happens on raster thread. Prev. we immediately
initialized the impeller::Context, unfortunately setting up the vulkan
context can take upwards of 100ms. This time is running on the platform
thread and blocking startup.

Instead, I attempt to hide/defer as much as possible what backend is
being used - this requires us to access the impeller context via a
shared_future in some cases instead of immediately knowing it is valid.
2025-04-25 18:01:19 +00:00
auto-submit[bot]
bf108a5474
Reverts "[Impeller] defer impeller context initialization onto the raster thread. (#167527)" (#167748)
<!-- start_original_pr_link -->
Reverts: flutter/flutter#167527
<!-- end_original_pr_link -->
<!-- start_initiating_author -->
Initiated by: gmackall
<!-- end_initiating_author -->
<!-- start_revert_reason -->
Reason for reverting: failing postsubmit `Linux_mokey
flutter_engine_group_performance`
<!-- end_revert_reason -->
<!-- start_original_pr_author -->
Original PR Author: jonahwilliams
<!-- end_original_pr_author -->

<!-- start_reviewers -->
Reviewed By: {jason-simmons}
<!-- end_reviewers -->

<!-- start_revert_body -->
This change reverts the following previous change:
Attempt to speed up vulkan startup by ensuring vulkan driver
initialization happens on raster thread. Prev. we immediately
initialized the impeller::Context, unfortunately setting up the vulkan
context can take upwards of 100ms. This time is running on the platform
thread and blocking startup.

Instead, I attempt to hide/defer as much as possible what backend is
being used - this requires us to access the impeller context via a
shared_future in some cases instead of immediately knowing it is valid.

<!-- end_revert_body -->

Co-authored-by: auto-submit[bot] <flutter-engprod-team@google.com>
2025-04-24 19:20:38 +00:00
Jonah Williams
97f358fd0a
[Impeller] defer impeller context initialization onto the raster thread. (#167527)
Attempt to speed up vulkan startup by ensuring vulkan driver
initialization happens on raster thread. Prev. we immediately
initialized the impeller::Context, unfortunately setting up the vulkan
context can take upwards of 100ms. This time is running on the platform
thread and blocking startup.

Instead, I attempt to hide/defer as much as possible what backend is
being used - this requires us to access the impeller context via a
shared_future in some cases instead of immediately knowing it is valid.
2025-04-24 17:35:25 +00:00
Jason Simmons
731d2d9e77
Reland "Reduce app startup latency by initializing the engine on a separate thread (#166918)" (#167519)
This includes a fix for a race seen in
EmbedderTest.PlatformThreadIsolatesWithCustomPlatformTaskRunner

The implementaion of MergedPlatformUIThread::kMergeAfterLaunch required
changing the interface of the TaskObserverAdd/TaskObserverRemove
callbacks so that TaskObserverAdd returned the TaskQueueId where the
observer was added. That TaskQueueId would later be given to
TaskObserverRemove.

The original implementation of this PR updated the embedder library's
implementation of TaskObserverAdd to return TaskQueueId::kInvalid to
signal that the observer was not added. However, this conflicted with
the embedder's EmbedderTaskRunner, whose implementation of
GetTaskQueueId returns TaskQueueId::kInvalid as a placeholder.

This PR reverts the embedder's TaskObserverAdd/TaskObserverRemove to the
original implementation which adds the observer to the current thread's
message loop and does not call GetTaskQueueId.

See https://github.com/flutter/flutter/issues/167418
2025-04-22 16:36:21 +00:00
Jason Simmons
c5864174d0
Revert "Reduce app startup latency by initializing the engine on a separate thread (#166918)" (#167427)
This reverts commit c53fdbdf24daba4bc81ccc6d274ce13d7d34d05e.

See https://github.com/flutter/flutter/issues/167418
2025-04-19 01:03:26 +00:00
Jason Simmons
c53fdbdf24
Reduce app startup latency by initializing the engine on a separate thread (#166918)
If settings.merged_platform_ui_thread is set to kMergeAfterLaunch, then
the engine will be started on the UI thread. After engine setup
completes and the Dart isolate is loaded, the UI task runner will be
merged into the platform thread and all future Dart execution will run
on the platform thread.

This makes it possible for other work to run on the platform thread
while the engine starts.

See https://github.com/flutter/flutter/issues/163064
2025-04-17 21:40:08 +00:00
Jonah Williams
3ef252e5b5
Add runtime flag for enable flutter_gpu, off by default. (#165337)
Flag flutter_gpu off by default.
2025-04-09 23:43:12 +00:00
chunhtai
bf6481104d
Revert "Add set semantics enabled API and wire iOS a11y bridge (#1612… (#165901)
…65)"

This reverts commit 26037dff87ade9d9dee04cc2ef90b3fe5cf0faf3.

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

PR causes internal test failures

## 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], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] 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/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-03-25 18:24:46 +00:00
chunhtai
26037dff87
Add set semantics enabled API and wire iOS a11y bridge (#161265)
fixes https://github.com/flutter/flutter/issues/158399

old pr https://github.com/flutter/engine/pull/56691

previously the only correct way to enable semantics is that ios
embedding receive signal from native OS, it call SetSemanticsEnabled to
shell and then to dart to enable semantics tree generation.

If for some reason framework decide to enable semantics first, e.g.
through SemanticsBinding.instance.ensureSemantics(typically due to
integration test or ci that wants to test semantics), the update will be
dropped in shell. Even if it later on receive signal from native OS to
turn on semantics, it can't construct the complete accessibility tree in
embedding because the updatesemantics sends diff update and previous
updates are gone forever. It will end up in a broken state.

This pr changes so that the only source of truth will be in the
framework side. When framework starts generating the the semantics tree,
it will call SetSemanticsTreeEnabled through dart:ui, and the embedding
needs to prepare itself to accept semantics update after receiving the
message.

This however require some refactoring on iOS embedding because it will
only create a11y bridge when receiving OS notification when assitive
technologies turns on.

This requires three phase transition

add an empty dart:ui API setSemanticsTreeEnabled
makes framework calls the empty API.
merge this pr with actual implementation of setSemanticsTreeEnabled

I will do the android part in a separate pr


## 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], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] 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/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-03-24 20:11:13 +00:00
Jason Simmons
08d2703016
Roll libcxx to bd557f6f (#165621)
Changes required for this roll:
* addition of LLVM libc (which is now a dependency of libcxx)
* updates the to license script
* patching the verify_exported check to allow some symbols added by
libcxx
* annotations for clang-tidy warnings
2025-03-24 15:39:26 +00:00
Matthew Kosarek
554c814ada
(#112207) Adding view_id parameter to DispatchSemanticsAction and UpdateSemantics (#164577)
fixes #112207

## What's new?
- Added a `view_id` on `UpdateSemantics`
- Added a `view_id` on `DispatchSemanticsAction`
- Piped the `view_id` all over creation
- Updated tests for these actions across the different platforms
- Added `FlutterEngineSendSemanticsAction` to the embedder API in order
to not break `FlutterEngineDispatchSemanticsAction`
- Using this view ID properly on the Windows platform (see
`engine/src/flutter/shell/platform/windows/flutter_windows_engine.cc`)

## How to test
1. Checkout
[foundation-plus-framework](https://github.com/canonical/flutter/pull/36)
from canonical/flutter
2. Merge this branch into it
3. Enable the "Narrator" screen reader on windows
4. Run the Multi window reference app (see
[PR](https://github.com/canonical/flutter/pull/36) for details)
5. Open up another window, and note that the right buttons and things
are being highlighted, as the screenreader would expect 🎉

## 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], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
2025-03-20 16:30:07 +00:00
Jason Simmons
47a710ba99
Move flutter/third_party/txt into flutter/txt (#164248)
The flutter/txt library does not currently contain any third-party code.
2025-03-04 16:13:40 +00:00
zijiehe@
80d0a8b8de
[Fuchsia] Enable extra test suits and correct the error reasons (#164338)
Fuchsia does not support Dart_LoadELF, the tests are expected to fail.
So this change explicitly disables the related tests instead of removing
the suites.

b/394632376

## 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], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [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/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-03-03 17:39:14 +00:00
Matej Knopp
b831b269c5
Add PlatformDispatcher.engineId (#163476)
Fixes https://github.com/flutter/flutter/issues/163430.

This PR adds `engineId` field to `PlatformDispatcher`. When provided by
the engine, this can be used to retrieve the engine instance from native
code.

Dart code:
```dart
final identifier = PlatformDispatcher.instance.engineId!;
```

macOS, iOS: 
```objc
FlutterEngine *engine = [FlutterEngine engineForIdentifier: identifier];
```

Android:
```java
FlutterEngine engine = FlutterEngine.engineForId(identifier);
```

Linux
```cpp
FlEngine *engine = fl_engine_for_id(identifier);
```

Windows
```cpp
FlutterDesktopEngineRef engine = FlutterDesktopEngineForId(identifier);
```

*If you had to change anything in the [flutter/tests] repo, include a
link to the migration guide as per the [breaking change policy].*

## 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], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [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/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-02-28 22:20:11 +00:00
Liam Appelbe
0f3b092a10
Use the Dart isolate ownership API on the root isolate (#163703)
The isolate ownership API was [introduced
recently](https://dart-review.googlesource.com/c/sdk/+/407700) to solve
[some deadlock bugs](https://github.com/dart-lang/native/issues/1908) in
native callbacks.

A native callback is a call from native code into a Dart function.
Currently all such callbacks must run that Dart function in the isolate
that created the callback (called the target isolate). The only native
callback primitives at the moment are `NativeCallable.isolateLocal`
(blocking, but must be invoked from the same thread as the target
isolate, and the target isolate must be currently entered on that
thread) and `NativeCallable.listener` (non-blocking, can be invoked from
any thread).

To build blocking callbacks that can be called from any thread, we can
use a `NativeCallable.listener`, and use a synchronization object like a
mutex or a condition variable to block until the callback is complete.
However, if we try to do this on the thread that is currently entered in
the target isolate, we will deadlock: we invoke the listener, a message
is sent to the target isolate, and we block waiting for the message to
be handled, so we never pass control flow back to the isolate to handle
the message, and never stop waiting.

To fix this deadlock, Ffigen and Jnigen both have a mechanism that
checks if we're on the target isolate's thread first:
- If the native caller is already on the same thread as the target
isolate, and the target isolate is entered:
- Call the Dart function directly using `NativeCallable.isolateLocal` or
similar
- Otherwise, if the native caller is coming from a different thread:
- Call the Dart function asynchronously using `NativeCallable.listener`
or similar
  - Block until the callback finishes

However, this neglects the case where we're on the target isolate's
thread, but not entered into the isolate. This case happens in Flutter
when the callback is invoked from the UI thread (or the platform thread
when thread merging is enabled), and the target isolate is the root
isolate. When the native callback is invoked, the root isolate is not
entered, so we hit the second case: we send a message to the root
isolate, and block to wait for a response. Since the root isolate is
exclusively run on the UI thread, and we're blocking the UI thread, the
message will never be handled, and we deadlock.

The isolate ownership API fixes this by allowing the embedder to inform
the VM that it will run a particular isolate exclusively on a particular
thread, using `Dart_SetCurrentThreadOwnsIsolate`. Other native code can
then query that ownership using `Dart_GetCurrentThreadOwnsIsolate`. This
lets us add a third case to our conditional:

- If the native caller is on the thread that is currently entered in the
target isolate:
- Call the Dart function directly using `NativeCallable.isolateLocal` or
similar
- Otherwise, if the native caller is on the thread that owns the target
isolate
  - Enter the target isolate
- Call the Dart function directly using `NativeCallable.isolateLocal `or
similar
  - Exit the target isolate
- Otherwise, the native caller is coming from an unrelated thread:
- Call the Dart function asynchronously using `NativeCallable.listener`
or similar
  - Block until the callback finishes

**Note:** We don't need to set the ownership of VM managed threads,
because they run in a thread pool exclusively used by the VM, so there's
no way for native code to be executed on the thread (except by FFI, in
which case we're entered into the isolate anyway). We only need this for
Flutter's root isolate because work can be sent to the UI
thread/platform thread using OS specific APIs like Android's
`Looper.getMainLooper()`.
2025-02-27 00:05:53 +00:00
Matej Knopp
940fb3c8b1
[Embedder] Wire view focus event and focus request (#163930)
This wires `PlatformDispatcher.onViewFocusChange` and
`PlatformDispatches.requestViewFocusChange` through embedder API.

*If you had to change anything in the [flutter/tests] repo, include a
link to the migration guide as per the [breaking change policy].*

## 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 readand followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [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/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Matthew Kosarek <matt.kosarek@canonical.com>
Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
2025-02-25 17:37:06 +00:00
Matej Knopp
94cd4b14c9
[Embedder] Implement merged platform and UI thread (#162944)
Fixes https://github.com/flutter/flutter/issues/152337

Introduces `ui_task_runner` field on `FlutterCustomTaskRunners`. This
lets the embedder to specify task runner for UI isolate tasks, allowing
for merging platform and UI threads.

With custom UI task runner there is no `MessageLoop` anymore for the UI
thread, so the message loop task observer can no longer be used to flush
microtask queue. Instead the microtask queue is flushed at the end of
each `FlutterEngineRunTask` invocation if needed. This is handled
internally by the embedder.

## 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], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [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/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Jonah Williams <jonahwilliams@google.com>
Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
2025-02-11 12:24:13 +00:00
Michael Goderbauer
8e0993eda8
Auto-format Dart code in engine (#160576)
This auto-formats all *.dart files in the `engine` subdirectory and
enforces that these files stay formatted with a presubmit check.
2024-12-19 17:13:07 +00:00
gaaclarke
3d8fc3c652 removed c style casts and enabled the lint (flutter/engine#57162)
test exempt: should have no functional change

## 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/blob/master/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/engine/blob/main/docs/testing/Testing-the-engine.md
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
2024-12-12 15:33:37 -08:00
LN Liberda
daed210840 IWYU: add some missing includes failing with libstdc++13/14 (flutter/engine#56822)
Fixes builds of engine with libstdc++13 and libstdc++14.

*List which issues are fixed by this PR. You must list at least one issue.*
closes https://github.com/flutter/flutter/issues/159513

*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
2024-11-27 20:11:17 +00:00
Daco Harkes
09e3b52bdf [native assets] Consume NativeAssetsManifest.json (flutter/engine#56727)
This PR introduces a `NativeAssetsManifest.json` next to the `AssetManifest.json` and `FontManifest.json`. This removes the need for embedding the native assets mapping inside the kernel file and will enable decoupling native assets building and bundling from the kernel compilation in flutter tools. This will then allow us to remove dry-run from the build hook protocol.

(It also means all isolate groups will have the same native assets. However, since Flutter does not support `Isolate.spawnUri` from kernel files anyways, this is not a regression.)

This manifest is parsed eagerly on startup by the engine in a manner similar to how the font manifest is parsed. The manifest contents need to be available in the callback for resolving assets, which does not have access to the engine. Therefore the parsed manifest is `NativeAssetsManager` stored in the `IsolateGroupData`. The engine passes it in on isolate group creation, and the FFI callbacks access it from the isolate group data.

Issue:

* https://github.com/flutter/flutter/issues/154425

Related PRs:

* https://dart-review.googlesource.com/c/sdk/+/388161

Follow up work:

* This PR does not yet remove the engine callbacks registered via the dart_api that rely on kernel embedding. If we were to do that in this PR, it would require a manual roll of the engine into flutter/flutter with the PR that switches flutter_tools to emit the native assets manifest instead of embedding in kernel, and a manual roll into g3 to switch emitting a manifest instead of embedding in kernel. A TODO is left in the code for those callbacks to be removed.

## Testing

Most of this PR cannot be tested in isolation. The code in this PR is heavily exercised in the follow up flutter_tools PR which creates the `NativeAssetsManifest.json` and removes the embedding of native assets in kernel files.

* This PR adds a unit test for parsing the JSON manifest.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-11-21 18:01:46 +00:00
Jason Simmons
ef5c2fc014 Do not stop flutter_tester if microtasks are still pending (flutter/engine#56432)
Flutter_tester has a task observer that checks whether the test's Dart code has finished execution.  If Dart no longer has live ports but does have pending microtasks, then flutter_tester should continue running and force a drain of the microtask queue.

Fixes https://github.com/flutter/flutter/issues/158129
2024-11-11 19:22:07 +00:00
Siva
5e7994be0c Manual roll Dart SDK from cfa1826c3df1 to 307869c696e8 (1 revision) (flutter/engine#56460)
https://dart.googlesource.com/sdk.git/+log/cfa1826c3df1..307869c696e8

2024-11-08 dart-internal-merge@dart-ci-internal.iam.gserviceaccount.com
Version 3.7.0-121.0.dev

---------

Co-authored-by: skia-flutter-autoroll <skia-flutter-autoroll@skia.org>
2024-11-08 13:57:39 -08:00
Liam Appelbe
118cc70a56 Delete DartIsolateTest.PlatformIsolateSendAndReceive (flutter/engine#55722)
This test is flaky on the mac bots, but I can't repro the failure locally. Sending and receiving messages from the platform isolate is covered more realistically by the [Dart test](f100ecaab7/testing/dart/platform_isolate_test.dart (L65)), so this test isn't very useful anyway.

Closes https://github.com/flutter/flutter/issues/156251
2024-10-08 03:17:23 +00:00
Jonah Williams
152dfb2fcf [engine] set platform thread name to ui. (flutter/engine#55362)
When running with merged platform and ui threads, set the dart thread name of the main thread to io.futter.ui. Also change the thread mask settings to avoid creating an unused UI thread.
2024-09-25 22:06:37 +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
Jonah Williams
0a0883219e [engine] dispatch platform channel messages through event loop, except navigation on start. (flutter/engine#55027)
This is a re-land of https://github.com/flutter/engine/pull/55006, except that we special case the navigation channel to immediately dispatch its message if the isolate is not yet running.

This preserves the existing behavior relied upon by several iOS add2app tests, as well as the still used embedder v1 - and potentially undicovered future embedders.
2024-09-08 17:38:18 +00:00
Matan Lurey
d68876bb1d More diagnostic clean ups (flutter/engine#54265)
Towards https://github.com/flutter/flutter/issues/152636.

Almost all changes are `dart --fix`.
2024-08-22 21:04:17 +00:00
Chinmay Garde
c2992b3273 Remove shared mutex from FML and use the C++17 variants. (flutter/engine#54482)
We used to require this only on iOS because the standard library till iOS 9 didn't have support for this. We have moved past that version. No change on other platforms.
2024-08-09 22:59:58 +00:00
Chinmay Garde
f60c0e325a Remove fml::size. (flutter/engine#54476)
std::size because standard in C++17.
2024-08-09 20:01:28 +00:00
Chinmay Garde
e83e23a6c5 Delete //flutter/fml/compiler_specific.h (flutter/engine#54330)
There were two macros for doing identical things and you can do the thing using standard C++17.
2024-08-03 01:47:49 +00:00
Matan Lurey
bed7aa4dea Cleanup dart analyze diagnostics in ignored directories. (flutter/engine#54262)
Towards https://github.com/flutter/flutter/issues/152636.

I also deleted some code that was TODO'd 10 years ago.
2024-07-31 22:47:58 +00:00
Jonah Williams
9808dcbb8f [engine] remove raster stats feature. (flutter/engine#54187)
This debugging tool does not give accurate measurements and we've decided to remove it.

See also: https://github.com/flutter/flutter/issues/131941
2024-07-29 20:30:52 +00:00
Daco Harkes
f7a4157683 Setup NativeAssetsApi during isolate group creation (flutter/engine#53329)
This initializes the `NativeAssetsApi` for native assets resolution in the isolate group creation callback.

* https://github.com/dart-lang/sdk/issues/55523

## Implementation considerations

The DartIO initialization lives in its own GN target. This doesn't work for the native assets initialization due to it having to look up the `script_uri` in one of the callbacks. Since the callbacks are function pointers, we can't have a lambda that captures the script uri. So instead, the native assets initialization lives in the flutter/runtime target.

The import from dart should probably be `runtime/include/bin/native_assets_api.h` to mirror what we're doing with dart IO, rather than directly importing from `runtime/bin/native_assets.h`.

## Testing

All native asset testing is in flutter_tools, so those tests will only run once this rolls into flutter/flutter. I have done manual testing locally with a Dart branch that removes the fallback: https://dart-review.googlesource.com/c/sdk/+/370740

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-06-18 06:21:20 +00:00
Tong Mu
48799ceebf Make pointer events ignore invalid views (flutter/engine#51925)
With this PR, Flutter will now ignore pointer events for an invalid view, i.e. views that have not been add or have been removed.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-06-06 07:18:20 +00:00
Alexander Aprelev
8bd9e60267 Use new Dart_PortEx api to ensure SendPort can be rebuild properly. (flutter/engine#52498)
Currently used Dart API can not be reliably used to rebuild dart
SendPort object, [new API was introduced in dart sdk
](https://dart.googlesource.com/sdk/+/de4029ee1ba3bc89d839ae7d2fd0706d29abae58)
and this PR moves flutter engine to use that new API.

BUG: https://github.com/flutter/flutter/issues/147469
2024-05-02 09:06:38 -07:00
Jonah Williams
584a0394aa [Impeller] remove image upload from IO thread, limit concurrent worker threads. (flutter/engine#52423)
Fixes https://github.com/flutter/flutter/issues/123058
Fixes https://github.com/flutter/flutter/issues/135443

We're currently using the IO thread to bottleneck image uploads. Instead, just use fewer concurrent worker threads - and cap the limit at something small. For a Pixel device, this should use about 2 threads maximum, instead of  5 (4 worker and 1 IO).
2024-04-28 17:22:15 +00:00
Tong Mu
94448fc97f Move PointerDataPacketConverter from PlatformView to RuntimeController (flutter/engine#51952)
This is a refactor that moves the `PointerDataPacketConverter` from `PlatformView` to `RuntimeController`. 

This change is made for the following reasons:
- Currently, the pointer data conversion contains no platform specific logic (because the current converter's only responsibility is to make the event sequence conform Flutter's protocol). Therefore these logics should reside in a platform-independent place.
- The converter typically converts one event to many. It's better to have this conversion later than earlier.
- It removes a member from `PlatformView`, making it closer to a pure virtual class.

The reason to choose `RuntimeController` as the destination is because `RuntimeController` manages a map for views, which is required for the converter to implement a later patch https://github.com/flutter/engine/pull/51925.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-04-26 23:45:21 +00:00
Loïc Sharma
b363028a18 [Embedder API] Add view (flutter/engine#51523)
Adds `FlutterEngineAddView` to the embedder API. This will be used to add a view.

Design doc: https://flutter.dev/go/multi-view-embedder-apis

Part of https://github.com/flutter/flutter/issues/144806
Part of https://github.com/flutter/flutter/issues/142845

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-04-02 21:04:54 +00:00
Loïc Sharma
a01206ad39 Add completion callback to Shell::AddView (flutter/engine#51659)
In the future, `FlutterEngineAddView` will be added to the embedder API to allow embedders to add views. `FlutterEngineAddView` will accept a callback that notifies the embedder once the view has been added.

This embedder API will be powered by `Shell::AddView`. This change adds a completion callback to `Shell::AddView` to prepare for the embedder API.

Design doc: https://flutter.dev/go/multi-view-embedder-apis

Part of https://github.com/flutter/flutter/issues/144806
Part of https://github.com/flutter/flutter/issues/142845

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-03-29 00:39:10 +00:00
Jason Simmons
171221580e Post Dart message handling tasks directly to the platform task runner for isolates running on the platform thread (flutter/engine#51573)
Some embedders use a custom platform task runner that does not support fml::MessageLoopTaskQueues and may not have an fml::MessageLoop.

To support those embedders, DartIsolate::SetMessageHandlingTaskRunner will not use fml::MessageLoopTaskQueues for platform isolates.

See https://github.com/flutter/engine/pull/48551#issuecomment-1962190896
2024-03-22 14:33:03 +00:00