5089 Commits

Author SHA1 Message Date
Chris Bracken
49afcc0101 [macOS] Refactor PlatformView mutators (flutter/engine#42130)
This refactors `[FlutterMutatorView applyLayer:]` to split out orthogonal behaviour into smaller functions for better readability/maintainability.

Extracts:
* General transform composition to CATransformFromMutations
* Opacity handling
* MasterClip computation
* RoundedRectClip computation

This change is a cleanup change for readability and makes no semantic changes to how mutator views are applied. Existing unit tests in [FlutterMutatorViewTest.mm](https://github.com/flutter/engine/blob/main/shell/platform/darwin/macos/framework/Source/FlutterMutatorViewTest.mm) are expected to pass without changes.

This is refactoring prior to applying a fix for rotation handling.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-05-18 20:41:05 +00:00
Bruno Leroux
d35d4dc958 [Android] Return keyboard pressed state (flutter/engine#41695)
## Description

This PR updates the Android engine in order to answer to keyboard pressed state queries from the framework (as implemented in https://github.com/flutter/flutter/pull/122885).

## Related Issue

Fixes https://github.com/flutter/flutter/issues/122441
Android engine implementation for https://github.com/flutter/flutter/issues/87391

## Tests

Adds 2 tests.
2023-05-18 20:35:21 +00:00
chunhtai
d21dc12d2f Make iOS embedding to send full uri for deeplinks (flutter/engine#41992)
related https://github.com/flutter/flutter/issues/100624

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-05-18 20:31:17 +00:00
Chris Bracken
871632b29b [macOS] Clean up PlatformView mutator scaling (flutter/engine#42110)
When applying platform view mutators, the mutations array includes a
transform from logical to physical coordinates. Since Cocoa deals only
in logical points, we inject a physical to logical coordinate transform
to counteract this.

Rather than applying this multiple times throughout the
`[FlutterMutatorView applyFlutterLayer]` method we gather a list of
transforms that includes the additional physical to logical scale
transform.

This change is a cleanup change for readability and makes no semantic
changes to how mutator views are applied. Existing unit tests in
[FlutterMutatorViewTest.mm](https://github.com/flutter/engine/blob/main/shell/platform/darwin/macos/framework/Source/FlutterMutatorViewTest.mm)
are expected to pass without changes.

## 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 Hixie said 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
[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-05-17 17:11:51 -07:00
Xilai Zhang
3b3f315061 [g3 roll] Revert "add non-rendering operation culling to DisplayListBuilder" (flutter/engine#42097)
temporary revert of flutter/engine#41463

context: b/283038609
2023-05-17 23:48:04 +00:00
Renzo Olivares
79df264a52 [Android] Do not collapse text selection on shift key up (flutter/engine#42075)
Fixes https://github.com/flutter/flutter/issues/101569

This block of code was originally introduced in https://github.com/flutter/engine/pull/15560 , but removing it does not have any affect on the software text editing controls in GBoard.

Before this change
* shift + arrow right/left selection would collapse after releasing the shift key. 
* shift + mouse click to expand selection would collapse after releasing the shift key.

After this change
* shift key up no longer collapses the selection.
2023-05-17 18:53:03 +00:00
Dan Field
ae728938fc Report displays for macOS (flutter/engine#41998)
https://github.com/flutter/flutter/issues/125939 and https://github.com/flutter/flutter/issues/125938 for macOS

fixes https://github.com/flutter/flutter/issues/121352
2023-05-17 17:17:23 +00:00
gaaclarke
837b7df872 [Impeller] Turned on wide gamut support by default. (#39801) (flutter/engine#41965)
relands flutter/engine#39801

forward fix for internal customers at cl/531288297

## 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 Hixie said 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
[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-05-17 09:11:42 -07:00
Zachary Anderson
df51526b1d Revert "[ios_platform_view] only recycle maskView when the view is applying mutators" (flutter/engine#42080)
Reverts flutter/engine#41573

Crashing on Framework CI
2023-05-16 14:32:18 -07:00
Greg Spencer
f4ac622197 [macOS] Wait for binding to be ready before requesting exits from framework (flutter/engine#41753)
Similar to https://github.com/flutter/engine/pull/41733 and
https://github.com/flutter/engine/pull/41782, this causes the macos
embedding to wait until it hears that the scheduler binding has
registered itself before proceeding to send termination requests to the
framework.

This allows applications that don't use the framework (just use
`dart:ui` directly) to exit automatically when the last window is
closed. Without this change, the last window closes, but the app does
not exit.

Depends on framework PR https://github.com/flutter/flutter/pull/126075
landing first.
2023-05-16 14:29:32 -07:00
Greg Spencer
4eebfb2246 [linux] Wait for binding to be ready before requesting exits from framework (flutter/engine#41782)
## Description

Similar to https://github.com/flutter/engine/pull/41733 and https://github.com/flutter/engine/pull/41753 this causes the linux embedding to wait until it hears that the scheduler binding has registered itself before proceeding to send termination requests to the framework.

This allows applications that don't use the framework (just use `dart:ui` directly) to exit automatically when the last window is closed.  Without this change, the app does not exit when the window is closed.

Depends on framework PR https://github.com/flutter/flutter/pull/126075 landing first.

## Related PRs
 - https://github.com/flutter/engine/pull/41733
 - https://github.com/flutter/engine/pull/41753

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

## Tests
 - Added a test to make sure that it doesn't send a termination request if the binding hasn't notified that it is ready yet.
2023-05-16 20:34:05 +00:00
Loïc Sharma
ac25948dcc [Windows] Add force redraw to the C++ client wrapper (flutter/engine#42061)
This change adds a C++ client wrapper to Windows's "force redraw" C API. This API can be used to schedule a frame.

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

## Background

The Windows runner has a race at startup:

1. **Platform thread**: creates a hidden window
2. **Platform thread**: launches the Flutter engine
3. **UI/Raster threads**: renders the first frame
4. **Platform thread**: Registers a callback to show the window once the next frame has been rendered.

Steps 3 and 4 happen in parallel and it is possible for step 3 to complete before step 4 starts. In this scenario, the next frame callback is never called and the window is never shown.

The Windows runner will be updated to call the "force redraw" API after it registers the next frame callback. If step 3 hasn't completed yet, the "force redraw" will no-op as a frame is already scheduled. If step 3 has already completed, the "force redraw" will schedule another frame, which will call the next frame callback and show the window.

See this discussion below on why we cannot avoid changing the Windows runner to fix this issue: https://github.com/flutter/engine/pull/42061#issuecomment-1550080722

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-05-16 18:07:15 +00:00
Chris Yang
259217c7aa [ios_platform_view] only recycle maskView when the view is applying mutators (flutter/engine#41573)
A mistake was introduced in https://github.com/flutter/engine/pull/39498  where the maskViews are already recycles each frame. 

Sometimes a PlatformView does not need to be re-composite: (https://github.com/flutter/engine/blob/main/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm#L398-L401), so the mask view for such PlatformView should not be recycled.

This PR changed the `recycleMaskViews` API to allow individual maskviews to be recycled. `ApplyMutator` then only recycle the maskView for that particular PlatformView.

The MaskViewPool is also reworked to be simpler. 

- The pool now contains a single set of mask views, there is no index counter needed.
- When a maskView is needed, try to get it from the pool. 
  - If pool is empty, create a new view.
  - If pool has an available maskview, remove it from the pool.
- When a PlatformView starts to `applyMutator`, it removes current the maskView, insert the maskView to the pool.
- When the above PlatformView needs to a maskView, it grabs one from the pool. 

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-05-16 16:24:05 +00:00
Chris Yang
9640e89255 [ios_platform_view] Only remove platform views from flutter view in reset. (flutter/engine#41709)
Add a class type check during reset when removing the PlatformViews.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-05-16 04:21:04 +00:00
gaaclarke
47b14888c5 [Impeller] switches the wide gamut surface to f16 (flutter/engine#41994)
**requires https://github.com/flutter/flutter/pull/126712 to land
first**

fixes https://github.com/flutter/flutter/issues/126620
integration test at: https://github.com/flutter/flutter/pull/126715

## 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 Hixie said 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
[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-05-15 10:25:43 -07:00
Kevin Lubick
0946d27add Migrate uses of SkSurface factories (flutter/engine#41978)
In http://review.skia.org/687639, many SkSurface static methods were moved and one was deleted (SkSurface::MakeRasterN32Premul). (SkSurface::MakeNull was omitted accidentally and http://review.skia.org/696537glesource.com/c/skia/+/696537 has not rolled into Flutter yet)

This changes the calls in Flutter to match those moved functions. There should be no functional difference and everything was done pretty mechanically (e.g. find and replace)

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-05-15 16:41:10 +00:00
Casey Hillers
c77155e442 [Impeller] Include AndroidSurfaceVulkanImpeller behind a flag (flutter/engine#42033)
Fixes b/282290672

Google Testing currently does not support vulkan, and constructors like
this need to be behind a flag.

## 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 Hixie said 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.
2023-05-14 22:29:19 -07:00
Jim Graham
820d1dbbde add non-rendering operation culling to DisplayListBuilder (flutter/engine#41463)
This optimization avoids recording unnecessary render operations that will not affect the output and also eliminates the need for "draw detection" mechanisms like `DlOpSpy` and `CanvasSpy` by remembering if any non-transparent operations were included. The `DlOpSpy` unit tests were updated to check if the results from that object match the new `DisplayList::affects_transparent_surface()` method.

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

In addition, this change will unblock some other Issues:

- https://github.com/flutter/flutter/issues/125318
- https://github.com/flutter/flutter/issues/125403
2023-05-14 02:14:33 +00:00
Bruno Leroux
80c4704ddf [macOS - TextInput] Insert new line only when TextInputAction.newline (flutter/engine#41977)
## Description

This PR updates the macOS text input plugin to avoid adding a new line on a multiline text field when action is not set to `TextInputAction.newline`.

## Related Issue

macOS implementation for https://github.com/flutter/flutter/issues/125879.
(similar to the Linux implementation in https://github.com/flutter/engine/pull/41895).

## Tests

Adds 2 tests.
2023-05-13 06:48:14 +00:00
Dan Field
29c5e7808b [Impeller] [Android] Refactor the Android context/surface implementation to work more like Skia. (flutter/engine#41059)
Noticed this while working on  https://github.com/flutter/flutter/issues/124181

In Impeller right now, Android creates a context for each surface - but in Skia, Android creates one context and shares it across surfaces. For the multiple-engine scenario this matters. This also makes it possible for Android to provide the impeller::Context independently of surface creation.
2023-05-12 07:10:05 +00:00
Bruno Leroux
8a9edf40aa [Linux - TextInput] Do not add new line for send action (flutter/engine#41895)
Respects input action.
2023-05-11 16:32:43 -07:00
Callum Moffat
1b72600567 iPhone floating cursor selection (flutter/engine#36643)
Floating cursor selection hasn't worked as we haven't been returning a real value for `caretRectForPosition:`. If we have the selection rectangles, we can do so. 

Fixes [#30476](https://github.com/flutter/flutter/issues/30476)

Requires selection rects to be turned on for iPhone (https://github.com/flutter/flutter/pull/113048)

writing and running engine tests.
2023-05-11 22:19:01 +00:00
Kevin Lubick
0c3dbe50e1 Use moved SkImage procs (flutter/engine#41947)
Use relocated SkImages context typedefs

In http://review.skia.org/661059, we moved many SkImage related methods, including these typedefs. This updates Flutter to use the moved types.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-05-11 20:16:54 +00:00
Greg Spencer
96db8b56f6 [Android] Lifecycle defaults to focused instead of unfocused (flutter/engine#41875)
## Description

In https://github.com/flutter/engine/pull/41702, the default state of the focus bit is "false", assuming that Android will send an `onWindowFocusChanged(true)` when the window is first focused, but there appear to be some cases where that doesn't happen.

This change puts the initial state back to what it used to be: in the absence of focus change events, entering the "onResume" Android state will report the `resumed` state in Flutter. Before this PR, and after https://github.com/flutter/engine/pull/41702, if no focus events were received, it would default to `inactive`.

## Tests
 - Updated tests to match.
2023-05-11 18:08:04 +00:00
Chris Bracken
de7c02c2cb [macos] Disable background colour tests (flutter/engine#41904)
These tests are flaky. Until they've been deflaked, disable the
following two tests:
* FlutterEngineTest.BackgroundIsBlack
* FlutterEngineTest.CanOverrideBackgroundColor

Issue: https://github.com/flutter/flutter/issues/124677
2023-05-10 16:03:58 -07:00
hellohuanlin
80c0f9d47f [backdrop_filter]Avoid relying on internal class details (flutter/engine#41873)
The original code creates an internal `class` which is alarming: 

`NSClassFromString(@"_UIVisualEffectBackdropView")`

This PR removes such usage. 

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

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

*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-05-10 20:31:11 +00:00
yaakovschectman
e0b8175ef4 Only register top level window message listener upon registering service binding (flutter/engine#41733)
Move registering the `WM_CLOSE` message listener in the engine from
initialization to in response to a message sent from `ServiceBinding`
upon its initialization so that we do not intercept window messages when
there is no binding registered.

Addresses https://github.com/flutter/flutter/issues/126033.

## 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 Hixie said 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 `///`).
- [ ] 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
[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: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
2023-05-10 07:55:39 -04:00
Ian McKellar
4579687380 [fuchsia] Stop calling FIDL from Dart in Flutter integration tests (flutter/engine#41669)
As we move the Dart FIDL bindings we need to stop calling FIDL methods
from Dart in the Flutter repo. This only affects some integration tests.

This moves the FIDL calls into C++ and uses platform messages to make
the functionality available to the Dart tests.
2023-05-09 11:34:21 +10:00
drwez
de642efdac [tests] Remove unused fuchsia.sys protocol reference (flutter/engine#41826)
Remove reference to unused fuchsia.sys.Environment protocol in test
Realm setup. Besides being unused,
the reference was not correctly matched by an #include, nor a GN build
dependency.

Bug: fxbug.dev/81285
2023-05-09 11:34:08 +10:00
Jonathan Cole
cb8854c7d6 [Android] Fix incorrect viewInsets during keyboard animation with EdgeToEdge (flutter/engine#39391)
Currently during the keyboard animation, the navigation bar insets are subtracted from the keyboard insets. This is correct when the app isn't laid out behind the navigation bar, but results in incorrect viewInsets when the app's running in edge-to-edge or fullscreen.

This change checks if the app is being laid out behind the navigation bar and adjusts the bottom insets accordingly during the keyboard animation.

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

Tested on Android 13 (Pixel 7) using the code sample here: https://github.com/flutter/flutter/issues/109623

### Before

https://user-images.githubusercontent.com/20386860/216786596-24c764b1-a71c-42cf-97a2-3ba10b717819.mp4

### After

https://user-images.githubusercontent.com/20386860/216786591-155ec6a6-b3c5-41e0-a45f-169861077ce2.mp4
2023-05-08 19:57:47 +00:00
Dan Field
ea5131772d Add a Display API to dart:ui that reports the physical size, DPR, and refresh rate of the main display (flutter/engine#41685)
Fixes https://github.com/flutter/flutter/issues/123307 - for Android, iOS, and Web, for the main display only (https://github.com/flutter/flutter/issues/125938 tracks supporting multiple displays, https://github.com/flutter/flutter/issues/125939 for desktop).

Desktop will need to be implemented for this, but given priority for a couple of our customers targetting foldable devices on Android I'm inclined to get this in before desktop can be finished.

The main concern for this right now is that on some Android foldable devices, setting a preferred orientation will cause letterboxing and the `MediaQuery` will _never_ get the full screen size when unfolded. This causes apps to think the screen is smaller than it is, as they've mainly been using `MediaQueryData.size` to figure this out. Android's recommendation is to not set a preferred orientation, and if you must to use the new method introduced in `ViewUtil.java` to calculate the maximal window size.
2023-05-06 18:28:22 +00:00
Tong Mu
05036058d7 Remove single window assumption from SceneBuilder (flutter/engine#41559)
This PR fixes https://github.com/flutter/flutter/issues/112202. `Scene`
is no longer tied to views, but receives method arguments for view
properties, clearing the path to multiview Flutter.

`Scene` no longer creates a `LayerTree` on construction, but only part
of the config. When a output method is called (`toImage`, `toImageSync`,
or `takeLayerTree`), the `LayerTree` is constructed on the spot. In this
way, all `LayerTree`s return to being `unique_ptr`s instead of
`shared_ptr`s, reverting part of
https://github.com/flutter/engine/pull/35608 . And `Scene` no longer
needs to disfunction after one `takeLayerTree`, since the layer tree
config is never really taken away.

A `device_pixel_ratio` is now added to the parameter list of `Engine::Render` and `Animator::Render`.

## 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 Hixie said 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
[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-05-05 11:25:55 -07:00
Tong Mu
0d1d5a7d34 [macOS] Change view ID's type to signed and a typedef (flutter/engine#41653)
This PR changes the view ID type to `int64_t` and typedef it to
`FlutterViewId`

## Pre-launch Checklist

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

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[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-05-04 23:08:57 -07:00
陈昱
aa95b83a0d Close connection on keyboard close (flutter/engine#41500)
Fix:
- https://github.com/flutter/flutter/issues/123523
- https://github.com/flutter/flutter/issues/124890

### Before this patch:

https://user-images.githubusercontent.com/30322203/228413196-29c57bb0-3220-495b-9e73-f58777de440f.mp4

### After this patch:

https://user-images.githubusercontent.com/30322203/228413249-fc06f49d-6579-4476-9788-90f12a53b8c3.mp4
2023-05-05 02:55:05 +00:00
Jenn Magder
29dc3361f0 Fix flaky FlutterChannelsTests, stop mocking NSObject (flutter/engine#41747)
I don't know why this is only flaking on arm64 Macs, but instead of mocking out `NSObject` which seems to continue to be mocked on some background thread, instead mock out the more-specific `FlutterTaskQueue` protocol.  Turn the tests back on.

Fixes https://github.com/flutter/flutter/issues/126013
Reverts https://github.com/flutter/engine/pull/41740

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-05-04 22:58:12 +00:00
Dan Field
ee7376a670 Disable flaky tests on arm64 (flutter/engine#41740)
Reduces severity of https://github.com/flutter/flutter/issues/126013
2023-05-04 12:22:18 -07:00
Tong Mu
a7c3f6162c [macOS] Remove view ID from public (flutter/engine#41712)
This is a reland of https://github.com/flutter/engine/pull/39958, but
only contains the minimal changes that removes all references to viewId
from public interfaces, reverting these changes from
https://github.com/flutter/engine/pull/39576.

Flutter doesn't really support multi-view anyway. These methods
currently only works for view 0. We better remove them until we mark
multi-view stable. It was a mistake that I decided to add them to public
interfaces.

For the reason why https://github.com/flutter/engine/pull/39958 failed,
I'm pretty sure it's the change to
[platform_dispatcher.dart](https://github.com/flutter/engine/pull/39958/files#diff-57d6953e215d0e5dd7260ee60b665c812aa730566ef0b30f7ff1e3d661143585)
that mysteriously and unintentionally appeared in the change list.

## Pre-launch Checklist

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

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[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-05-03 15:40:14 -07:00
Jonah Williams
dfff522046 Remove physical model layer (flutter/engine#41593)
Removes the physical model layer and associated engine code. This was already deprecated and removed in the framework. By removing it in the engine, we can also remove the need for layer tree diff/paint/preroll to have the device pixel ratio. This will simplify some of the multi-view work

Fixes https://github.com/flutter/flutter/issues/125720
2023-05-03 20:28:53 +00:00
Greg Spencer
18125adcfc Reland: "Determine lifecycle by looking at window focus also" (#41094) (flutter/engine#41702)
## Description

This reverts commit e49577708d9d5315fa6c001d7dc20ee80d04cd35 to re-land #41094 because the Google test failures have been fixed. There are no changes to the original PR, since the fixes were in the Google code.
2023-05-03 19:21:58 +00:00
Kevin Lubick
e05e7a8552 Migrate SkSurface::getBackend* methods to static functions (flutter/engine#41693)
In https://skia-review.googlesource.com/c/skia/+/687642, Skia moved some
gpu-related methods on SkSurface to be static functions in a different
header. This updates those callsites in Flutter.

## 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 Hixie said 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
[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-05-03 09:03:39 -07:00
Jason Simmons
5e4cd80437 Clone the parent Android engine's asset provider into a spawned engine (flutter/engine#41642)
Typically the AndroidShellHolder's apk_asset_provider_ is set by AndroidShellHolder::Launch when the DartExecutor runs the engine's entrypoint.

But if the engine was started by Spawn, then the apk_asset_provider_ was not being set.  This would cause a crash if the resulting engine was later used to spawn another engine.

Fixes https://github.com/flutter/flutter/issues/122364
2023-05-02 14:50:58 +00:00
Wu Zhong
b0de18ba41 [macOS] Add lookupKeyForAsset to FlutterPluginRegistrar (flutter/engine#37421)
Fixes https://github.com/flutter/flutter/issues/47681

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-05-02 11:28:41 +00:00
Jim Graham
6ad6014776 [Impeller] take advantage of DisplayList culling (flutter/engine#41606)
Switching the calls to dispatch into an Impeller Dispatcher to use a cull rect to enable pre-culling of the out-of-bounds ops.

This change showed an improvement of around 2x on the rendering performance of the non-intersecting platform view benchmark, but that was measured without the recent changes to the destructive blend modes in Impeller renderer.
2023-05-01 23:27:52 +00:00
Xilai Zhang
e49577708d [flutter roll] Revert "Determine lifecycle by looking at window focus also" (flutter/engine#41626)
Reverts flutter/engine#41094.

context: updated the java/android timeouts and details in b/280204906
2023-05-01 16:46:02 +00:00
Loïc Sharma
b786d923f5 Remove single view assumption from pointer events (flutter/engine#41602)
This change removes the assumption that that all pointer events go to the view ID `0`. This change also adds a test for pointer events.

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

## Background

All pointer events are sent to [`PlatformDispatcher.onPointerDataPacket`](https://api.flutter.dev/flutter/dart-ui/PlatformDispatcher/onPointerDataPacket.html). In the future, a `viewId` property will be added [`PointerData`](https://api.flutter.dev/flutter/dart-ui/PointerData-class.html), which the framework (specifically, `GestureBinding`) will use to route the event to the proper view. This `viewId` property's value will be set by the embedders.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-04-29 03:47:10 +00:00
Chris Yang
d8e93afbc2 [platform_view] Only dispose view when it is removed from the composition order (flutter/engine#41521)
DisposeView happens every frame before laying out PlatformViews, with the order specified in `composition_order_`. Because `view_to_dispose_` is determined on UI thread and `composition_order_` is determined on the platform thread, there could be a race if the dart code on the UI thread runs faster than the rasterizer on the Platform thread, causing a view in `view_to_dispose_` is still in the `composition_order_`.

This PR delays the views in the `composition_order_` being disposed and wait for the next frame to dispose them. 

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-04-28 18:21:14 +00:00
Greg Spencer
962cbf0a22 Determine lifecycle by looking at window focus also (flutter/engine#41094)
## Description

This incorporates additional signal from `Activity.onWindowFocusChanged` to help decide if the application is `resumed` or `inactive`.

When the user pulls down the notification shade or opens the app switcher in iOS, then iOS sends a notification to the application that it no longer has input focus (is no longer "active" in Apple terminology). 

However, Android (at least on a Pixel) doesn't send `onPause` and `onResume` events for these things, as one might expect. Instead, this PR changes things so that we listen to `Activity.onWindowFocusChanged` and see if any of the windows still have focus.

If it doesn't have focus, then the lifecycle switches to `inactive` (even if `onPause` hasn't been called), and if it does have focus (and `onResume` hasn't been called) then we should go to `resumed`.

State changes are determined and deduped in the `LifecycleChannel` class.

Here's the old state table:

| Android State | Flutter state |
| ------------- | ------------- |
| Resumed  | resumed |
| Paused  | inactive |
| Stopped | paused |
| Detached | detached |

Here's the new state table:

| Android State | Window focused | Flutter state |
| ------------- | ------------- | ------------- |
| Resumed  | true  | resumed |
| Resumed  | false  | _inactive_ * |
| Paused  | true  | inactive |
| Paused  | false  | inactive |
| Stopped  | true  | paused |
| Stopped | false  | paused |
| Detached | true  | detached |
| Detached | false  | detached |

* = This is the relevant change in this PR.

("Window focused" means one or more windows managed by Flutter are focused)

The `inactive` state is for when the application is running and visible, but doesn't have the input focus.  An example where this currently happens are when a phone call is in progress on top of the app, or on some OEMs when going into the app switcher (I've tested on Realme and it does that, at least).  With the PR, it will also go into `inactive` when the app has lost input focus, but is still in the Android `onResume` state. This means that on phones that don't pause the app when they go into the app switcher or the notification window shade (Pixel, others), the app will go into `inactive` when it didn't before. If developers weren't doing anything special in the `inactive` state before, then this PR will have no change for them. If they were, they will go into that state more often (but more consistently across OEMs).

## Related Issues

  - Fixes  https://github.com/flutter/flutter/issues/124591

## Tests

  - Added unit tests for handling `onWindowFocusChanged`.
2023-04-28 17:43:36 +00:00
Jonah Williams
8167e14475 [Impeller] partial repaint for Impeller/iOS. (flutter/engine#40959)
Implements partial repaint for Impeller.

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

The new code that manages the damage regions is more or less a copy paste from the existing Skia implementation. Compared to Skia, there are a few differences:

Normally Impeller wants to use the drawable as the resolve texture for the root MSAA pass. Unfortunately this will unconditonally clear that texture. Thus to do a partial repaint, we have to allocate a separate texture to resolve to and then blit into the drawable.

The blit seems to take about 500ns for a full screen on an iPhone 13. That implies that partial repaint is likely not worth doing if the screen is significantly changed. Thus I've added code in compositor_context.cc that computes the percentage of width or height that is part of the dirty rect. Above a threshold of (abitrarily chosen) 70%, we just render as normal. This should mean there is only a very minor hit from performing the diff on screens that are highly changed.

The other special case, is that sometimes we get damage rects that are empty - that is the drawable is already completely up to date with what we want to render. IN that case I shortcircuit all of the impeller code and just present immediately. I previously tried returning without a present but this resulted in Xcode reporting dropped frames. One caveat here is that if you use the XCode frame debugger and attempt to capture a frame where we early present, then it will claim it couldn't capture any command buffers (because we didn't create any).

To facilitate all of this, I added some additonal plumbing so that the impeller surface can get the clip rect from the submit info. Additionally, rather than using a clip rect impeller will translate and then shrink the root surface texture. This reduces memory usage compared to just clippling.
2023-04-26 21:13:03 +00:00
Brandon DeRosier
280c4f0e46 [Impeller] iOS/macOS: Only wait for command scheduling prior to present (redux) (flutter/engine#41501)
Reverts https://github.com/flutter/engine/pull/40895.
Resolves https://github.com/flutter/flutter/issues/120399 (again).

A bunch of frames get pumped on the main thread _without a transaction_
just before unmerging occurs (I don't know why this happens), and so
checking the current thread to determine whether we need to present with
a transaction or not isn't sufficient. In the prior fix, after the
unmerge, the raster thread would hang for one second while waiting for
the next drawable to get freed up (happens on the second raster thread
frame post-unmerge), and then subsequent presents would just do nothing
for a while, but eventually recover.

`presentsWithTransaction` works whether the `CATransaction` stack is
empty or not, and so the only difference here is that
`presentsWithTransaction` is always turned on and `presentDrawable` is
always avoided (otherwise it tries to present too early and nothing
renders when platform views are present).
2023-04-26 10:50:51 -07:00
gaaclarke
c2ebd9ebc2 Made sure not to turn on wide gamut support without impeller. (flutter/engine#41460)
fixes https://github.com/flutter/flutter/issues/125430

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