5533 Commits

Author SHA1 Message Date
Dan Field
d38b0967a0 [Impeller] Gate Vulkan selection on API 29 (flutter/engine#48089)
Platform Views on Android require API 29 when using Vulkan.

~~I'm not sure if I did the CI changes right, want to run it here and see. The added test needs to run on a device or emulator with API 29 or above and API 28 or below to be valid.~~

Makes the following changes to CI:

- Runs the emulator tests on presubmit, but only if `shell/platform/android/**` or `lib/ui/**` or `.ci.yaml` changes.
- Changes the emulator tests to be a regular engine_v2 test that spawns an x86 build. Unfortunately, the older API level emulators are only available for x86, not x86_64, and you cannot run the binary we create unless it matches the ABI.
- Runs the new test on both API 28 and API 34.

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

/cc @johnmccutchan fyi
2023-11-16 02:04:41 +00:00
Chris Bracken
17d7e20c16 [macOS] Clean up allocations in menu plugin test (flutter/engine#48093)
Runs all FlutterMenuPlugin tests in an AutoReleasepoolTest, which                   
ensures all allocations are cleaned up.                                             
                                                                                    
Also extracts out some hackery into the FlutterMenuPluginTest fixture to            
ensure that NSApplication instantiates everything necessary to do menu              
bar manipulation.                                                                   
                                                                                    
Also replaces the use of OCMock in FlutterMenuPluginTest.mm with a fake             
FakePluginRegistrar class. This avoids unnecessary use of OCMock in the             
tests, which has been responsible for flakiness in some tests, in                   
particular where the mock is used across threads. This test was not                 
problematic, but the fake makes the tests more readable.                            
                                                                                    
Also fixes linter warnings about using NSLocalizedString for user-facing            
strings.

Issue: https://github.com/flutter/flutter/issues/104789
Issue: https://github.com/flutter/flutter/issues/127441
Issue: https://github.com/flutter/flutter/issues/124840
2023-11-15 16:40:39 -08: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
hellohuanlin
058ffbe73f [ios]fix ios 16 auto correction highlight showing on top left corner (flutter/engine#47279)
This PR hides the system highlights in iOS 16 (except when scribble is enabled). 

Note that auto correction highlight is still drawn by flutter, so it still works. 

I don't think we need to CP this, since it's iOS 16 only, and iOS 17 is already out. 

## Why not use system highlight? 

Unlike iOS 17, the iOS 16 system highlight only respect the width provided by `firstRectForRange`, but not the height. I have audited all sizing related APIs in UITextInput (doc [here](https://developer.apple.com/documentation/uikit/uitextinput#1653155)), specifically, `firstRect(for:)`, `caretRect(for:)` and `selectionRects(for:)`, and they all return the correct height. 

## About scribble
The initial implementation of `firstRectForRange` (that returns the first selection rect) was introduced for the scribble feature on iPad (code [here](1d3165a31c (diff-4c7b102c0690b8ec5e2212b079f5d69fe3f816c84e47ce94bc7bc89312f39e40R1487-R1505))). 

It turns out that a non-zero rect is required for scribble's advanced feature to work (e.g. inserting a space with a vertical bar). So we can't apply this fix for scribble. 

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

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

*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
2023-11-15 19:37:22 +00:00
Greg Spencer
28d807f326 Update keycode output (flutter/engine#47988)
## Description

This updates the keycode definitions to match what the keycode generator produces, to keep them in sync.
2023-11-15 17:29:34 +00:00
Chris Bracken
ce85176a4e [macOS] Clean up allocations in key responder tests (flutter/engine#48048)
Runs all FlutterChannelKeyResponderTest tests in an AutoReleasepoolTest, which ensures all allocations are cleaned up.

Also replaces the use of OCMock in FlutterChannelKeyResponderTest with a fake FlutterBasicMessageChannel subclass. This avoids unnecessary use of OCMock in the tests, which has been responsible for flakiness in some tests, in particular where the mock is used across threads. This test was not problematic, but the fake makes the tests more readable.

Issue: https://github.com/flutter/flutter/issues/104789
Issue: https://github.com/flutter/flutter/issues/127441
Issue: https://github.com/flutter/flutter/issues/124840

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-15 02:19:12 +00:00
Chris Bracken
50979ef389 [macOS] Eliminate unused OCMock includes (flutter/engine#48031)
As part of the broader quest to reduce our dependence on OCMock in macOS
embedder tests, this removes #includes of OCMock into files where OCMock
is not actually used.

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [X] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [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-11-14 12:12:53 -08:00
hellohuanlin
28fc24fd05 [ios17][text_input]fix ios 17.0 keyboard freeze when switching languages (without relying on text affinity) (flutter/engine#47566)
After close examination of the UIKit's default string tokenizer, when querying the line enclosing the end of doc position **in forward direction**, we should return nil (regardless whether the position is forward or backward affinity). 

This aligns with the [API doc](https://developer.apple.com/documentation/uikit/uitextinputtokenizer/1614464-rangeenclosingposition?language=objc): 

> If the text position is at a text-unit boundary, it is considered enclosed only if the next position in the given direction is entirely enclosed.

Will cherry pick this soon. Otherwise it will be less and less important as users upgrade to iOS 17.1. 

### Why my previous workaround also works? 

It turns out my previous workaround PR https://github.com/flutter/engine/pull/46591 works only because our misuse of text affinity in our text input. Specifically, when adding text affinity support, we only added it to `FlutterTextPosition`, but not `FlutterTextRange`. So when getting the beginning/end position from the range, we assign arbitrary affinities. 

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

https://github.com/flutter/engine/pull/46591

*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
2023-11-14 19:58:06 +00:00
John McCutchan
4a2f6eacfa Revert "Add an AndroidManifest.xml flag to disable ImageReader backend Platform Views (#46430)" (flutter/engine#48024)
This reverts commit af107ceba5d188019df780e0be192dd7092ea35a. It is no
longer needed as we have resolved the flickering issue in the
ImageReader backend.
2023-11-14 10:26:39 -08:00
Zachary Anderson
ef11fee4ed Move Skia to //flutter/third_party/skia (flutter/engine#47913)
As part of eliminating the Flutter buildroot
(https://github.com/flutter/flutter/issues/67373), we are moving all
third-party dependencies from //third_party to //flutter/third_party.

Once all third-party dependencies have been migrated, tooling and config
will be moved and the buildroot will be eliminated altogether.

To land this PR, we'll need to:
1. Stop the Skia -> Engine autoroller
1. Update the license goldens in this PR.
1. Update
https://skia.googlesource.com/skia-autoroll-internal-config/+/refs/heads/main/skia-infra-public/skia-flutter.cfg#55
1. Land this PR.
1. Re-start the Skia -> Engine autoroller
2023-11-13 20:04:35 -08:00
auto-submit[bot]
e5da8d9a87 Reverts "Bump minSdk to 19 for Android tests" (flutter/engine#47935)
Reverts flutter/engine#47686
Initiated by: zanderso
This change reverts the following previous change:
Original Description:
The latest Robolectric version, 4.11.x, removed the support for SDKs < 19 by following AndroidX strategy. Also following https://github.com/flutter/buildroot/pull/750, and removing obsolete SDK checking in code to pass android_lint checking after bumping minSdk to 19 for testing target.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-10 23:06:18 +00:00
utzcoz
1e558fcece Bump minSdk to 19 for Android tests (flutter/engine#47686)
The latest Robolectric version, 4.11.x, removed the support for SDKs < 19 by following AndroidX strategy. Also following https://github.com/flutter/buildroot/pull/750, and removing obsolete SDK checking in code to pass android_lint checking after bumping minSdk to 19 for testing target.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-10 21:35:57 +00:00
Camille Simon
809cc6c652 [Android] Bump robolectric version to support unit testing on Android 34 (flutter/engine#47768)
Bumps robolectric version from 4.10.3 --> 4.11 to support unit testing on Android 34!

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-10 16:54:16 +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
Michael Goderbauer
ba990078f8 Reland "Remove physical geometry" (flutter/engine#47872)
Relands #47825 with a doc fix (see second commit).
2023-11-09 19:39:20 +00:00
Gray Mackall
1dc6423dac [Re-land] Upgrade Android SDK to 34 "UpsideDownCake" (flutter/engine#47839)
The difference between this PR and the original is the change to the `AndroidManifest.xml`. For context, right before the original PR landed, [a change to upgrade the target sdk](https://github.com/flutter/engine/pull/47683) in the manifest from 31 to 33 landed. It also removed the lint complaining about using an old target sdk version from the baseline lint file. So this change upgrading the sdk, but not the target sdk in the manifest, triggered the lint again.

For the rest of the PR, [see the description of the original PR](https://github.com/flutter/engine/pull/47609).

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-09 18:02:18 +00:00
auto-submit[bot]
aa4fb605c3 Reverts "Remove physical geometry" (flutter/engine#47862)
Reverts flutter/engine#47825
Initiated by: zanderso
This change reverts the following previous change:
Original Description:
Looks like this was proactively added in https://github.com/flutter/engine/pull/20496, but never wired up to anything on any platform. It is also unused in framework and customer code; we never exposed this on e.g. MediaQuery.

Related framework PR: https://github.com/flutter/flutter/pull/138103 (Checks will fail until that PR is submitted).
2023-11-09 16:06:19 +00:00
Michael Goderbauer
c273bd8d71 Remove physical geometry (flutter/engine#47825)
Looks like this was proactively added in https://github.com/flutter/engine/pull/20496, but never wired up to anything on any platform. It is also unused in framework and customer code; we never exposed this on e.g. MediaQuery.

Related framework PR: https://github.com/flutter/flutter/pull/138103 (Checks will fail until that PR is submitted).
2023-11-09 02:18:24 +00:00
Loïc Sharma
9aee1bdaff [Windows] Remove global state in keyboard tests (flutter/engine#47829)
Currently the keyboard tests use global state to track key calls. As a result, a good test can fail if a bad test leaves key calls in the global state. This removes the global state and ensures each test is isolated.

Preparation for https://github.com/flutter/flutter/issues/115611

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-09 00:10:05 +00:00
Greg Spencer
68166947cc Move window state update to window realize callback (flutter/engine#47713)
## Description

This moves the state update to only happen on realizing the window instead of at initialization time, based on [the comment from](https://github.com/flutter/flutter/issues/137262#issuecomment-1792020246) @robert-ancell .

## Related Issues
 - https://github.com/flutter/flutter/issues/137262

## Tests
 - I tried to add tests, but it doesn't seem possible to create a view without an actual display connected (and making a mock of it defeats the purpose of the test). I'm happy to be proven wrong, though.
2023-11-08 23:56:01 +00:00
auto-submit[bot]
f5605fa8aa Reverts "Upgrade Android SDK to 34 "UpsideDownCake"" (flutter/engine#47834)
Reverts flutter/engine#47609
Initiated by: zanderso
This change reverts the following previous change:
Original Description:
~**This should not land until https://github.com/flutter/buildroot/pull/790 (re)lands, and I swap the buildroot url back to the latest commit.**~ ~Reland of PR to update buildroot at https://github.com/flutter/buildroot/pull/792. ~ <- landed, and changed the buildroot commit to the latest in DEPS

Upgrades to android api 34

Also:
1. Upgrades to java 17 in DEPS/ci, because the linter now requires it.
2. Stops running some roboelectric tests on android apis 16-18, because Roboelectric indicated those versions were unsupported and we don't support them either.
3. Applies the four trivial new suggestions from the newer linter.
4. Updates the baseline lint to include the new non-trivial lint ([fixed in a different PR](https://github.com/flutter/engine/pull/47817/files)).
5. Changes some instances where we were hardcoding android apis as numbers (e.g. `sdk = 16') to use version codes (see the [comment below](https://github.com/flutter/engine/pull/47609#issuecomment-1800308658)).

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-08 22:57:25 +00:00
Gray Mackall
542d29dedd Upgrade Android SDK to 34 "UpsideDownCake" (flutter/engine#47609)
~**This should not land until https://github.com/flutter/buildroot/pull/790 (re)lands, and I swap the buildroot url back to the latest commit.**~ ~Reland of PR to update buildroot at https://github.com/flutter/buildroot/pull/792. ~ <- landed, and changed the buildroot commit to the latest in DEPS

Upgrades to android api 34

Also:
1. Upgrades to java 17 in DEPS/ci, because the linter now requires it.
2. Stops running some roboelectric tests on android apis 16-18, because Roboelectric indicated those versions were unsupported and we don't support them either.
3. Applies the four trivial new suggestions from the newer linter.
4. Updates the baseline lint to include the new non-trivial lint ([fixed in a different PR](https://github.com/flutter/engine/pull/47817/files)).
5. Changes some instances where we were hardcoding android apis as numbers (e.g. `sdk = 16') to use version codes (see the [comment below](https://github.com/flutter/engine/pull/47609#issuecomment-1800308658)).

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-08 22:15:17 +00:00
Chris Bracken
c5b1d11b65 [macOS] Allocate textures as unique_ptr earlier (flutter/engine#47786)
This cleans up several places where instead of allocating a
std::unique_ptr immediately, we were making allocations with the new
operator, then later wrapping in a unique_ptr. The previous code was
correct but there was no reason not to allocate a unique_ptr
immediately.

This code makes no semantic changes; just applies a stylistic
improvement that makes the code very slightly safer.


## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [X] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [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-11-08 13:50:42 -08:00
utzcoz
3382ab50ac Use targetSdkVersion 33 for Android platform AndroidManifest.xml (flutter/engine#47683)
buildroot has switched to use 33 as default target sdk version.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-08 17:15:16 +00:00
Jonah Williams
5dd5cd253a [Impeller] null check drawable. (flutter/engine#47488)
Speculative fix for the first crash noted in https://github.com/flutter/flutter/issues/136628#issue-1944779964

nextDrawble can return null if the method times out.

Fixes https://github.com/flutter/flutter/issues/136525
2023-11-08 16:35:03 +00:00
Chris Bracken
c947cfce7e [macOS] Clean up resources in ViewController tests (flutter/engine#47792)
Wraps all FlutterViewController tests in an autorelease pool to ensure
resources are cleaned up.

Adds a MockFlutterEngineTest subclass of AutoreleasePoolTest that
creates an OCPartialMock FlutterEngine and shuts it down at the end of
the test. Previously we were not shutting down any FlutterEngine
instances we allocated, resulting in potentially thousands of threads
and graphics contexts being allocated.

Prior to this change, running these tests via:

    ../out/host_debug_unopt_arm64/flutter_desktop_darwin_unittests \
        --gtest_filter='FlutterViewController.*' --gtest_repeat=1000

resulted in test failures and sometimes segfaults. This ensures
resources are cleaned up

Eventually all unit tests should configure their FlutterEngine via
either FlutterEngineTest (which should be an AutoreleasePoolTest) or
MockFlutterEngineTest, and the CreateMockFlutterEngine function moved to
a static used in the implementation of these.

Issue: https://github.com/flutter/flutter/issues/104789
Issue: https://github.com/flutter/flutter/issues/127441
Issue: https://github.com/flutter/flutter/issues/124840

## 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-11-07 23:50:31 -08:00
Jia Hao
2156a17b9a Fix narrowing conversion lint (flutter/engine#47740)
Internally we have a lint that surfaces this as a warning. Googlers, please refer to go/al-rule/NarrowingConversion.

Related: b/309552840

When we do:
```
coords.toolMajor = (float) (double) coordsList.get(3) * density;
```

`coordsList.get(3)` is casted to a `double`, then a `float`, before the multiplication happens. 

I don't think this is intentional. The intention of the code here seems to be:

- Cast to a `double`: `coordsList` is a `List<Object>` so the cast narrows the value
- Cast to a `float`: To fit the resulting value into [`coords.toolMajor`](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords#toolMajor), which is a `float`.

As such, add parenthesis to address this.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-08 01:41:25 +00:00
Chris Bracken
7a923cd1d9 [macOS] Bail out of tests if engine not running (flutter/engine#47771)
In engine tests where we require a running engine to proceed with the
test, immediately fail if the engine isn't running rather than carrying
on with the test. In most cases, the fixture test proceeds to block the
main thread on a latch until it's released from the UI thread, so this
results in quicker test failures.

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [X] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [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-11-07 17:27:14 -08:00
Chris Bracken
229331bcff [testing] Extract StreamCapture test utility (flutter/engine#47774)
Factors out an RAII-based class that can be used to capture std::cout, std::cerr, or technically any other std::ostream, though that's unlikely to be useful.

This makes the logic reusable but more importantly, ensures the capture is cleaned up at the end of the test.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-08 01:18:16 +00:00
Loïc Sharma
9b3d3b0231 [Windows] Reduce warnings produced by unit tests (flutter/engine#47724)
This PR contains no functional changes but improves existing unit tests to reduce the number of warnings output when the tests are ran:

1. Replaced `ON_CALL` with `EXPECT_CALL` for expected method calls
2. Added some missing mocks

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-07 21:13:33 +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
Zachary Anderson
e24e3b5746 Don't use Skia BUILD.gn files (flutter/engine#47677)
The new `BUILD.gn` files in the Engine tree can't go under
`build/secondary` because Skia still has its own, and they'd be selected
first. So, this PR puts the new `BUILD.gn` files under `flutter/skia`.
2023-11-07 11:12:29 -08:00
Jia Hao
847c0f704b Fix ImmutableEnum lint (flutter/engine#47739)
This was introduced in https://github.com/flutter/engine/pull/47315. Internally, this lint breaks the build with the following error:

```
shell/platform/android/io/flutter/embedding/android/KeyData.java:78: Error: DeviceType is an enum, which should be immutable, but field DeviceType.value is not final [ImmutableEnum]
    private long value;
    ~~~~~~~~~~~~~~~~~~~
```

See also https://errorprone.info/bugpattern/ImmutableEnumChecker.

Fixes: b/309552840

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-07 07:21:23 +00:00
Greg Spencer
0f880e9200 Add KeyEventDeviceType to KeyData (flutter/engine#47315)
## Description

Before we deprecate the `RawKeyEvent` code, it needs to provide parity in functionality. One thing that is missing is the `eventSource` field from the `RawKeyEventDataAndroid` class, which provides the device type for the event.

See https://developer.android.com/reference/android/view/InputDevice#SOURCE_KEYBOARD for an example.

This PR implements that support, and sets the source to `KeyEventDeviceType.keyboard` for platforms that don't provide this information. The main thing it does is add the enum `KeyEventDeviceType`, and a new field `KeyData.deviceType`.

## Related Issues
 - https://github.com/flutter/flutter/issues/136419

## Tests
 - Updated tests to also read/write/verify this property.
2023-11-06 22:58:24 +00:00
Zachary Anderson
2431498922 Move some Dart packages to //flutter/third_party/pkg (flutter/engine#47654)
As part of eliminating the Flutter buildroot
(https://github.com/flutter/flutter/issues/67373), we are moving all
third-party dependencies from //third_party to //flutter/third_party.

Once all third-party dependencies have been migrated, tooling and config
will be moved and the buildroot will be eliminated altogether.

No tests changed because there is no semantic change to this PR. This is
simply relocating a dependency.
2023-11-06 06:59:27 -08:00
Jason Simmons
cd32fb6c82 Update DisplayList tests to explicitly select the Roboto font (flutter/engine#47493)
Skia is removing the API for constructing a default typeface (see https://issues.skia.org/issues/305780908)

Fixes https://github.com/flutter/flutter/issues/137565
2023-11-02 14:42:00 +00:00
Jason Simmons
cce2f9ced2 Consolidate all the copies of the OpenFixtureAsSkData testing helper function (flutter/engine#47491) 2023-11-01 17:03:05 +00:00
Chris Bracken
44c1e92369 [macOS] Delete FlutterCompositor tests (flutter/engine#47527)
The tests for FlutterCompositor are not useful. The current tests test two things:
1. That the mocks we set up behave the way we set them up to behave.
2. That the implementation of FlutterCompositor is the current implementation of FlutterCompositor.

As an example, consider FlutterCompositorTest.TestPresent: 70317028f2/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm (L107-L137)

Ostensibly, this test verifies that the onPresent callback configured in our fake FlutterViewProvider implementation is called when FlutterCompositor::Present() is called.

However, taking a look at the mocking setup:
70317028f2/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm (L47-L85)

We do the following:
1. Mock out FlutterSurfaceManager such that when a surface is requested, we hand back a mock surface. A little gross since we're relying on some knowledge of implementation details of the compositor, but let's take this as reasonable for now.
2. We mock out `FlutterSurface asFlutterMetalTexture` to return a mock texture. Again, we're getting a bit deep into implementation details that the test shouldn't know about, but let's assume this gets us somewhere.
3. We mock out `FlutterSurfaceManager present:notify:` to actually call the `onPresent` callback if it's passed in.

In effect, we're testing that:
1. We configured our mock for `FlutterSurfaceManager present:notify:` to call onPresent.
2. That `FlutterCompositor::Present` actually calls `FlutterSurfaceManager present:notify:` despite that being a simple implementation detail of that call.

This removes these tests. I have filed the following issue to track refactoring this class for testability and adding tests: https://github.com/flutter/flutter/issues/137648

Encountered these tests as part of deflaking and cleaning up memory allocations throughout the macOS desktop tests.

Issue: https://github.com/flutter/flutter/issues/137648
Issue: https://github.com/flutter/flutter/issues/104789
Issue: https://github.com/flutter/flutter/issues/127441
Issue: https://github.com/flutter/flutter/issues/124840

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-01 00:11:52 +00:00
gaaclarke
52fcefb32a Made clang tidy use arm64 if on an arm64 mac. (flutter/engine#47494)
fixes https://github.com/flutter/flutter/issues/137260

## 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

---------

Co-authored-by: Zachary Anderson <zanderso@users.noreply.github.com>
2023-10-31 15:35:36 -07:00
Chris Bracken
6fbf2e7123 [macOS] Wrap external texture tests in autorelease pool (flutter/engine#47492)
Wraps all FlutterExternalTexture tests in an autorelease pool to ensure resources are cleaned up between tests.

Prior to this change, running these tests via:

    ../out/host_debug_unopt_arm64/flutter_desktop_darwin_unittests \
        --gtest_filter='FlutterEmbedderExternalTextureUnittests.*'

Resuling in a segfault:

    [ERROR:flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.mm(35)]
    Could not create Metal command queue.
    zsh: segmentation fault
    ../out/host_debug_unopt_arm64/flutter_desktop_darwin_unittests

Issue: https://github.com/flutter/flutter/issues/104789
Issue: https://github.com/flutter/flutter/issues/127441
Issue: https://github.com/flutter/flutter/issues/124840

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-10-30 23:47:18 +00:00
Kevin Lubick
6cf3dac92a Remove call to SkTypeface::MakeDefault (flutter/engine#47344)
Skia plans to remove the default (global) SkFontMgr, which in turn,
requires the removal of a default typeface (e.g. the
typeface returned by `SkTypeface::MakeDefault` and when `nullptr` passed
in to the `SkFont` constructor).

See https://g-issues.skia.org/issues/305780908

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2023-10-30 07:48:30 -04:00
gaaclarke
caa9f39916 Made FlutterTaskQueue visible for Swift. (flutter/engine#47348)
fixes https://github.com/flutter/flutter/issues/118832

This makes the `FlutterTaskQueue` protocol visible, but keeps the
`dispatch:` selector private. Under the covers there are runtime checks
to make sure `dispatch:` is available since we can't have compile time
checks anymore.

## 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-27 11:01:08 -07:00
Zachary Anderson
e1fc52e2b6 Move rapidjson to flutter/third_party (flutter/engine#47354)
As part of eliminating the Flutter buildroot
(https://github.com/flutter/flutter/issues/67373), we are moving all
third-party dependencies from //third_party to //flutter/third_party.

Once all third-party dependencies have been migrated, tooling and config
will be moved and the buildroot will be eliminated altogether.

No tests changed because there is no semantic change to this PR. This is
simply relocating a dependency.
2023-10-27 08:00:56 -07:00
John McCutchan
632d65292d Don't re-initialize the default RenderSurface when returning from hybrid composition mode (flutter/engine#47358)
When we enter hybrid composition mode we 'pause' the default RenderSurface (implemented by SurfaceView or TextureView) and swap to an ImageReader based RenderSurface.

When we return from hybrid composition mode we recreate and re-initialize the real RenderSurface as if it was being used for the first time.

This broke Platform Views in an internal app b/306122497 because we would incorrectly tell the texture to attach when it was never detached.

This CL changes the protocol so that when we return from hybrid composition mode we only swap the RenderSurface and do not re-create it. This avoids doing a bunch of unnecessary work and fixes the logic error of re-attaching textures that were never detached.

*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.*

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

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-10-27 00:33:23 +00:00
Tong Mu
a98c3dc263 Skip invalid renders in Dart (flutter/engine#47323)
With this PR, invalid renders are skipped in Dart in both release build and debug build.

Part of https://github.com/flutter/flutter/issues/137073 and part of relanding https://github.com/flutter/engine/pull/45555.

Unit tests will be relanded in a following PR once this PR is confirmed performance-safe.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-10-26 22:09:10 +00:00
Chris Bracken
987dac0ae1 [macOS] Reuse NSWindow instance across unit tests (flutter/engine#47350)
Adds a gtest test fixture mixin and convenience class that instantiates an NSAutoreleasePool at the beginning of each test and flushes it at the end; this allows Objective-C tests using ARC to free  allocations at the end of each test.

Adds a subclass for the macOS accessibility bridge tests that instantiates and re-uses an NSWindow* across any tests that use it. This is because instantiating, closing, and immediately collecting an NSWindow results in a crash.

Prior to this patch, tests started failing (on my machine) around the 855th iteration, and issued the following warning on the 101st iteration:

```
2023-10-26 13:02:45.390829-0700 flutter_desktop_darwin_unittests[40837:1509026] [Window] WARNING: NSWindow has detected an excessive live window count of 101. Window 0x1423 of class 'NSWindow' created after passing the threshold of 100. This window is not necessarily the cause, and this warning will only be shown once per window class. (
  0   AppKit                              0x0000000192820d28 -[NSWindow _setWindowNumber:] + 684
  1   AppKit                              0x00000001933050e4 _NXCreateWindow + 284
  2   AppKit                              0x0000000192901ae0 -[NSWindow _commonAwake] + 672
  3   AppKit                              0x000000019281ff00 -[NSWindow _commonInitFrame:styleMask:backing:defer:] + 972
  4   AppKit                              0x000000019281f798 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 796
  5   AppKit                              0x000000019281f470 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 48
  6   flutter_desktop_darwin_unittests    0x0000000100001e3c _ZN7flutter7testing89AccessibilityBridgeMacTest_SendsAccessibilityCreateNotificationToWindowOfFlutterView_Test8TestBodyEv + 328
```

See: http://www.openradar.me/FB13291861

Issue: https://github.com/flutter/flutter/issues/104789
Issue: https://github.com/flutter/flutter/issues/127441
Issue: https://github.com/flutter/flutter/issues/124840

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-10-26 21:17:01 +00:00
auto-submit[bot]
24debb363e Reverts "[Impeller] Disable layer tree screenshots." (flutter/engine#47356)
Reverts flutter/engine#46171
Initiated by: jonahwilliams
This change reverts the following previous change:
Original Description:
The "rasterizer screenshot" VM service API uses the Skia software backend, even when running with impeller. At best, this leads to confusing half working screenshots that are missing images.

See https://github.com/flutter/flutter/issues/135052

We should disable this functionality when running with impeller. Perhaps this could be reworked to use picture toImage instead of the offscreen so that it uses the "real" backend regardless of the platform it is running on.

Fixes https://github.com/flutter/flutter/issues/135052
2023-10-26 20:34:17 +00:00
Loïc Sharma
f06b89215e [Windows] Refactor high contrast mode detection (flutter/engine#47314)
This refactors how high contrast is implemented on Windows:

1. Added a test to verify accessibility features are updated when a view is created. This prevents staleness issues as the Windows embedder isn't notified of accessibility changes while in headless mode.
1. Moved high contrast mode detection to `WindowsProcTable` from `FlutterWindow` to remove engine to view to window plumbing.
1. `FlutterWindow` and `FlutterWindowsEngine` now share their `WindowsProcTable` (which is used for mocking and polyfilling win32 APIs) to reduce redundant dynamic loading.

This pull request contains no functional changes.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-10-26 20:22:15 +00:00
Jonah Williams
912c891a1d [Impeller] Disable layer tree screenshots. (flutter/engine#46171)
The "rasterizer screenshot" VM service API uses the Skia software backend, even when running with impeller. At best, this leads to confusing half working screenshots that are missing images.

See https://github.com/flutter/flutter/issues/135052

We should disable this functionality when running with impeller. Perhaps this could be reworked to use picture toImage instead of the offscreen so that it uses the "real" backend regardless of the platform it is running on.

Fixes https://github.com/flutter/flutter/issues/135052
2023-10-26 20:16:09 +00:00
Loïc Sharma
acadeba222 [Windows] Introduce FlutterWindowsViewController (flutter/engine#47242)
This change begins the migration to the Windows embedder's new ownership model:

1. Renames `FlutterDesktopViewControllerState` to `FlutterWindowsViewController`
2. Moves ownership of the `FlutterWindowsEngine` from the `FlutterWindowsView` to the `FlutterWindowsViewController`

For more information, refer to: [flutter.dev/go/windows-multi-view-ownership-updates](https://flutter.dev/go/windows-multi-view-ownership-updates)

Part of https://github.com/flutter/flutter/issues/137267

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-10-25 22:06:16 +00:00