433 Commits

Author SHA1 Message Date
Dan Field
28fbba2098 Delete unused/test only code from FML (flutter/engine#48327)
This is more-or-less a revert of https://github.com/flutter/engine/pull/14011

This code never ended up being used outside of tests, and it's not how we handle asset loading at this point anyway.

I was hopeful we could kill off all runtime dependencies on Dart in `FML` when looking at this, but it looks like trace_event.h still wants to import dart_api_tools.h for some Dart enum types. This may or may not matter if we ever want to build FML for web/wasm. /cc @eyebrowsoffire. If we really need to do that, we can refactor the trace event stuff so that it has a web and Dart implementation that's selected at build time.
2023-11-22 20:49:56 +00:00
Matan Lurey
b1a29657a9 Make {flow|fml|impeller}/... compatible with .clang_tidy. (flutter/engine#48241)
Another few stragglers.
2023-11-21 18:53:06 +00:00
Matan Lurey
aa07289b98 Make fml/... compatible with .clang-tidy. (flutter/engine#48150) 2023-11-17 22:14:38 +00:00
Matan Lurey
6f19a763ec Actually make status_or.h compatible with .clang-tidy. (flutter/engine#48151)
I needed to actually convince the checker I wasn't causing a value read
on a non-value. I think this is right?
2023-11-17 09:07:05 -08:00
Matan Lurey
0371968293 Make fml/status_or.h compatible with .clang_tidy. (flutter/engine#48002)
Work towards https://github.com/flutter/flutter/issues/134969.
2023-11-15 18:08:56 -08:00
Matan Lurey
da57416cbe Re-land "Make fml/... compatible with .clang_tidy (flutter/engine#48030)
Reverts flutter/engine#48004
2023-11-16 00:09:24 +00:00
Chris Yang
c07e3193e7 [ios] introduce weak_nsobject (flutter/engine#47947)
Introduce weak_nsobject from chromium. 

There are some usages of weak_ptr wrapping Objective-C ids, weak_ptr is not really designed for ids and such usages are blocking the arc migration. 

This PR mostly copies the weak_nsobject from chromium, at the same hash that we copied the ARC/MRC compatible scoped_nsobject: fd625125b8

To match how we used weak_ptr for those ids, I made some changes to the weak_nsobject:
- WeakNSObjects needs to be generated by a WeakNSObjectFactory. The WeakNSObjectFactory is owned by the objc class and acts as the generator of the WeakNSObjects. All the WeakNSObjects' derefing thread should be the same of the WeakNSObjectFactory's creation thread.
- chromuim's WeakNSObjects can be detached from the thread and re-attached to a new thread. To match our weak_ptr behavior, I changed WeakNSObjects to be only accessed from a single thread, the same as weak_ptr

This PR also moves the FlutterEngine to use WeakNSObject and updated related classes.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-15 23:43:24 +00:00
auto-submit[bot]
a934a9bcd8 Reverts "Make fml/... compatible with .clang_tidy." (flutter/engine#48004)
Reverts flutter/engine#47992
Initiated by: bdero
This change reverts the following previous change:
Original Description:
Work towards https://github.com/flutter/flutter/issues/134969.

All changes were made automatically (i.e. with `--fix`).
2023-11-14 00:17:26 +00:00
Matan Lurey
e47c5864ef Make fml/... compatible with .clang_tidy. (flutter/engine#47992)
Work towards https://github.com/flutter/flutter/issues/134969.

All changes were made automatically (i.e. with `--fix`).
2023-11-13 22:52:51 +00:00
gaaclarke
002ab77448 Expanded the performance lints (flutter/engine#47868)
fixes https://github.com/flutter/flutter/issues/137372

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-09 23:54:01 +00:00
Chris Yang
5c12a78db9 [ios] making objective-C smart pointers support ARC (flutter/engine#47612)
Moving the implementation from https://codereview.chromium.org/1855483004 into the code base, including:

- scoped_nsobject, scoped_nsprotocol, scoped_block will support both mrc and arc
- Added parent class scoped_typeref for shared code between scoped_block and scoped_nsobject
- moving OwnershipPolicy to its own file

The implementation of the smart pointers are almost identical to https://codereview.chromium.org/1855483004 besides some syntax preference differences between chromium and flutter.

This PR also migrated [VsyncWaiterIosTest.mm](https://github.com/flutter/engine/pull/47612/files#diff-c98ce1a2aca65c29bbc444523b66921a53ecce5ff39a420b4eda7dbfe8ca1cc7) to ARC with scoped_nsobject

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-07 19:25:45 +00:00
John O'Neil
58bb0adf2c Fix for undefined uint8_t seen on Clang-15+GCC13 (flutter/engine#47288)
This PR is to address an issue we're seeing compiling flutter+impeller in certain configurations. Specifically:

1. Compiling with `clang-15`
2. using the GCC 13 backend to provide headers and cstdlib.

Via the `clang-15` version flag:

```
clang-15 -v
Debian clang version 15.0.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
```

We were building using the gcc 12 backend for a while, but picked up an update that forced us to 13, and then saw this issue.

The issue is seen as `uint8_t` being undefined as in the following partial messages:

```
hex_codec.cc:18:5: error: unknown type name 'uint8_t'
base32.cc:29:32: error: unknown type name 'uint8_t'
```

I'm not sure this is the cleanest fix, or if it might be better handled by adding some compile time switches, but I wanted to provide this to start conversation.

I'm also hoping to get a better idea of tests run against a PR. If there's any I should run manually we can discuss that here.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-10-26 21:10:04 +00:00
Jonah Williams
792bf6d2e2 [Impeller] Allocate exact descriptor count, populate in one go. (flutter/engine#47200)
Rather than doing a guess and check, since we have all of our cmds already stored we can add up the binding counts and allocate the exact descriptor size and populate them in one call.

Also makes render_pass and compute_pass share more (though not all) code.
2023-10-24 19:22:38 +00:00
Chinmay Garde
daa95690cd Update fml::ThreadPriority enum to match style guide. (flutter/engine#47255) 2023-10-24 06:14:21 +00:00
Chinmay Garde
eb3e4ac1c5 Add missing headers to the fml source_set. (flutter/engine#47232)
These being missing came up when internal build rules were being derived from the ones here.
2023-10-23 20:45:23 +00:00
Jia Hao
ff7829558f Add missing import (flutter/engine#47083)
Fixes the following:

c8aa0844f2 results in the following error appearing internally when compiling for Android:

```
In file included from fml/synchronization/sync_switch.cc:5:
./fml/synchronization/sync_switch.h:74:34: error: implicit instantiation of undefined template 'std::vector<fml::SyncSwitch::Observer *>'
  mutable std::vector<Observer*> observers_;
                                 ^
<...>: note: template is declared here
class _LIBCPP_TEMPLATE_VIS vector;
                           ^
1 error generated.
```

*List which issues are fixed by this PR. You must list at least one issue.*
b/306266542

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-10-19 16:47:20 +00:00
Chris Bracken
6fd06e4039 [fml][embedder] Improve thread-check logging (flutter/engine#47020)
Developers working their app's runner code or in the native parts of
plugins are often required to call methods from the platform thread, or
face a crash.
Makes a minor improvement to fml::ThreadChecker's
IsCreationThreadCurrent log message.
This patch originally proposed to emit a much more specific error
message when calling methods that must be called on the platform thread
(typically originating in calls from plugins), however, given that we
don't ship debug engines as part of the SDK, this is really only going
to be useful to engine developpers, or people brave enough to run with
their own local engine build, in any case. 

Issue: https://github.com/flutter/flutter/issues/135345

No changed tests since no functional change, just an error message
cleanup.

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [ ] I added new tests to check the change I am making or feature I am
adding, or 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-10-17 15:32:50 -07:00
Jason Simmons
128b1d06d0 Workaround for a clang-tidy warning in CPUSpeedTracker (flutter/engine#47024)
The newly rolled version of clang-tidy is warning about some accesses to std::optional values.  The function does a has_value check before accessing the values, but the analyzer does not detect that.
2023-10-17 21:50:05 +00:00
gaaclarke
c8aa0844f2 [Impeller] implements a retry mechanism for dart:ui/Image.toByteData. (flutter/engine#46840)
Design doc: [link](https://docs.google.com/document/d/1Uuiw3pdQxNFTA8OQuZ-kuvYg1NB42XgccQCZeqr4oII/edit#heading=h.hn6wreyrz6fm)
fixes: https://github.com/flutter/flutter/issues/135245

One slight deviation from the design doc is that I decided to make ContextMTL respond to changes to the SyncSwitch instead of having it observe the app state directly.  The benefits are:
1) This keeps that functionality in one location
1) It makes writing tests much easier
1) There's no need of conditional compilation between macos and ios
1) There is no need to add an objc class

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-10-16 18:31:13 +00:00
gaaclarke
c053bc814b [Impeller] Started throwing errors if dart:ui/Image.toByteData fails (flutter/engine#46738)
issue: https://github.com/flutter/flutter/issues/135245

This is a first step.  Next we'll implement a retry.

## 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-10-13 09:04:47 -07:00
Chinmay Garde
b66daf88a6 Remove workaround for older versions of MSVC. (flutter/engine#46689)
We don't use the MSVC frontend now anyway. And haven't for a while.
2023-10-10 13:11:51 -07:00
Chinmay Garde
e53f10f782 Remove obsolete tests that were time sensitive. (flutter/engine#46686)
These were always filtered away. On Fuchsia, where the filters were not
in place, there was an ifdef guard.

Followup to
https://github.com/flutter/flutter/issues/80457#issuecomment-1753419263

---------

Co-authored-by: Zachary Anderson <zanderso@users.noreply.github.com>
2023-10-09 13:39:21 -07:00
Matan Lurey
3cea82e53b More Clang Tidy --fix[es] to header files (flutter/engine#46151)
More work towards https://github.com/flutter/flutter/issues/134969.

I decided not to touch the `LOG_X` variables since they are just used in macro expansion.
2023-09-21 21:16:16 +00:00
Matan Lurey
476b46954c Migrate from LOG_X to kLogX. (flutter/engine#46107)
These should be entirely non-breaking, i.e. 1:1 and same backing `int`
value.

(See https://github.com/flutter/engine/pull/46052)
2023-09-20 13:24:01 -07:00
Matan Lurey
792830c13f Make a variety of low-impact Clang tidy fixes. (flutter/engine#46114)
Work towards https://github.com/flutter/flutter/issues/134969.

These are all self-contained, so I bundled them all together.

All fixes are generated by `clang-tidy --fix`, and manual search/replace if that wasn't sufficient.
2023-09-20 19:52:03 +00:00
Jonah Williams
dc05767b39 [Impeller] Affinity adjustments for Vulkan backend. (flutter/engine#46063)
Runs the waiter threads with efficiency affinity and the worker thread with "not performance" affinity.
2023-09-19 23:34:11 +00:00
Matan Lurey
1475e52d11 Deprecate fml::LOG_X in favor of kLogX. (flutter/engine#46052)
This is required to eventually land https://github.com/flutter/flutter/issues/134969 (lint header files).

No changes in behavior in this PR. Future steps:

 - Change existing `LOG_X` references to `kLogX`
 - Delete `LOG_X`
2023-09-19 18:05:38 +00:00
Jonah Williams
88e963e0fd [Android] Add support for setting thread affinity based on core speed. (flutter/engine#45673)
https://github.com/flutter/flutter/issues/134452

This patch parses the speed of all CPU data out of /proc and constructs a table that allows us to request high level CPU affinities: performance, efficiency, and not performance. These affinties are applied where appropriate during Android thread construction.
2023-09-19 03:50:05 +00:00
Matan Lurey
0f4cb0b4c8 Make fml::ScopedCleanupClosure std::move-able and add unit tests. (flutter/engine#45772)
Fixes https://github.com/flutter/flutter/issues/134568.
2023-09-14 18:37:49 +00:00
Jason Simmons
2ae4942db0 Use the Clang unreachable code warning flag in the engine tree (flutter/engine#44458) 2023-08-08 17:40:03 +00:00
Jason Simmons
75f91264d1 Do not log exceptions from JNI lookups of APIs that are known to be unavailable on older devices (flutter/engine#44357)
These exceptions are benign but were being logged every time an app is launched on a device with an Android API level below 26.
2023-08-07 14:35:05 +00:00
Derek Xu
dedec555f2 Handle deprecation of Dart_TimelineEvent Embedder API (flutter/engine#42497)
This PR changes usages of `Dart_TimelineEvent` to
`Dart_RecordTimelineEvent` as `Dart_TimelineEvent` was deprecated in
https://dart-review.googlesource.com/c/sdk/+/308721.
2023-08-02 16:09:31 -04:00
Jia Hao
409cd83cb4 Revert "Log dlopen errors in opt builds (#41477)" (flutter/engine#43677)
This reverts commit 2b0b0a0e7882a7af5efa843b598a4d42b49b47b4.

This didn't seem to help with debugging b/276657840. Fixes https://github.com/flutter/flutter/issues/125523.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-07-18 04:52:48 +00:00
Chris Yang
4e696fc84d Unmerge threads if the current merger is the only one that's merged. (flutter/engine#43652)
`UnMergeNowIfLastOne` is called during shell destruction. When there are other shells with threads unmerged and the current destroying shell with thread merged. `UnMergeNowIfLastOne` should unmerge the threads. 

This PR Make `UnMergeNowIfLastOne` not only unmerge if the current merger is the last merger, but also unmerge if the current merger is the last merger that is merged.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-07-13 22:17:21 +00:00
Jason Simmons
2b231a05fd Release the mutex in the CanCreateConcurrentMessageLoop test before waking the latch (flutter/engine#43574)
If the wake happens while thread_ids_mutex is still held, then the test function may exit and destroy thread_ids_mutex before the pool thread task releases it.

Fixes https://github.com/flutter/flutter/issues/130344
2023-07-11 23:18:48 +00:00
Dan Field
f7ba78c7b0 Release log capture at end of test (flutter/engine#43429)
Fixes https://github.com/flutter/flutter/issues/130036

Also fixes a potential issue where the shell wasn't getting destroyed at the end of the test.

Since no log is actually printed ont he second go, the destructor of `LogMessage` never clears the static pointer, and the next test that tries to print a log tries to print to that pointer which is now garbage.
2023-07-06 15:05:01 +00:00
Jonah Williams
ac3ce651f3 [Impeller] Give Impeller a dedicated raster priority level worker loop. (flutter/engine#43166)
We'd like to (or already are) using the concurrent message loop for high priority rendering tasks like PSO construction and render pass encoding. The default priority level for the engine managed concurrent message loop is 2, which is a significantly lower priority than the raster thread at -5. This is almost certainly causing priority inversion.

We must move back to dedicated runners so we can adjust thread priorities.
2023-06-27 18:08:49 +00:00
Dan Field
b6fa0a20a5 Print a warning when a message channel is used on the wrong thread. (flutter/engine#42928)
Fixes https://github.com/flutter/flutter/issues/128746

Prints a warning the first time a platform channel sends a message from the wrong thread with instructions/link to the site about how to fix this.
2023-06-22 18:16:40 +00:00
Jason Simmons
ea621b65bb Wrap concurrent message loop tasks in an autorelease pool on iOS/Mac platforms (flutter/engine#42459)
See https://github.com/flutter/flutter/issues/127482
2023-06-02 19:58:43 +00:00
Zachary Anderson
9022cac6f8 Enables bugprone-unchecked-optional-access for some files (flutter/engine#42428) 2023-05-30 16:52:58 -07:00
Zachary Anderson
5633d0d833 Enable bugprone-unchecked-optional-access, disable in files with warnings (flutter/engine#42359)
First part of https://github.com/flutter/flutter/issues/127701
2023-05-26 21:58:46 +00:00
Jason Simmons
4c29368376 [Impeller] Create an autorelease pool for Impeller tests running on macOS. (flutter/engine#42265)
See https://github.com/flutter/flutter/issues/127358
2023-05-24 19:16:13 +00:00
gaaclarke
9258309eed Turned back on debug unit tests (flutter/engine#42261)
I refactored the `EXPECT_EXIT` tests since they are unsafe to execute in a process with multiple threads.

This leaves `flutter_desktop_darwin_unittests` disabled since it has existing issues.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-05-23 23:13:35 +00:00
Dan Field
ccd8afabde Make FML_LOG safe from static initialization (flutter/engine#42219)
I ran into this while trying to get some printing going for places where we're creating thread local keys. 

Supposedly, just including `<iostream>` should statically initialize `std::cout/cerr`, but it gets really hard to reason about whether your statically initialized code is going to be initialized before or after that happens. I tried making sure that the TU for `fml/logging.cc` did that initialization statically, but that also failed in the verison of the test included here (it passed in some other iterations that modified run_all_unittests.cc). We _could_ make sure it happens each and every time we touch `std::cerr` but ... we could also just use `fprintf(stderr, ...)` and it works just fine.

/cc @flar who ran into problems around this a little while back and was asking about it.
2023-05-23 00:02:17 +00:00
Jia Hao
2b0b0a0e78 Log dlopen errors in opt builds (flutter/engine#41477)
As the Engine uses `dlopen` to find the `libapp.so`, https://github.com/flutter/flutter/issues/59834 can happen which will prevent `dlopen` from finding the binary. In theory this should be mitigated by https://github.com/flutter/engine/pull/9762, but an internal customer observed errors that could be related. 

The additional logging here can help to rule out that hypothesis. For Googlers, see b/276657840 for more details.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-04-26 08:16:05 +00:00
Brandon DeRosier
b4271c24de Add missing header guards (flutter/engine#41322)
These keep turning up, so I did a little bash-fu to find them all.
```bash
grep -lL "#pragma once" $(grep -lL "#ifndef .*_H_" $(find . | grep "\.h$")) | cut -c 3-
```
2023-04-19 21:20:21 +00:00
Chris Bracken
3bf49d72e4 Support disabling backtrace support (flutter/engine#40980)
This adds a gn flag (--backtrace, --no-backtrace) that defaults to
enabling backtraces, which drives a gn variable `enable_backtrace` which
is defaulted true for debug builds.

Backtrace collection is supported on Windows, and on POSIX-like
operating systems via execinfo.h. execinfo support exists in Android,
macOS/iOS, and in glibc and uclibc on Linux. musl libc notably does not
include execinfo support, so this provides an escape hatch to build with
backtrace_stub.cc for situations in which compile time support doesn't
exist.

Proposed as an alternative to
https://github.com/flutter/engine/pull/40958 by @selfisekai.

Issue: https://github.com/flutter/flutter/issues/124285
2023-04-06 17:21:34 -07:00
Chris Bracken
1404722d05 Add doc comment to Pipeline (flutter/engine#40388)
Add doc comment to Pipeline
2023-03-17 20:38:55 +00:00
Jonah Williams
726df65356 Reland: Move asset opening to background thread, fix dart persistent value destruction (flutter/engine#40183)
Reland: Move asset opening to background thread, fix dart persistent value destruction
2023-03-09 22:58:04 +00:00
Zachary Anderson
44947b8822 Revert "[engine] move asset mapping copy to background thread (#39918)" (flutter/engine#40147)
Revert "[engine] move asset mapping copy to background thread"
2023-03-08 19:30:27 +00:00