5643 Commits

Author SHA1 Message Date
Bruno Leroux
d925ac1a53 [Android] Reset IME state in TextInputPlugin.clearTextInputClient (flutter/engine#49829)
## Description

This PR calls Android API `InputMethodManager.restartInput` to reset IMEs internal states. Otherwise some IMEs (Gboard for instance) keep reacting based on the previous input configuration until a new configuration is set.

- On Android native, `restartInput` is called in several places, for instance in f219798774/android/widget/TextView.java (L2458).
- On Compose, https://github.com/flutter/flutter/issues/70546#issuecomment-1088345561 pointed out where it is called.
- On Flutter, it is called at some point but mainly when another `TextField` is focused (it is mainly called in `setTextInputEditingState`).

## Related Issue

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

## Tests

Adds 1 test.
2024-01-18 06:38:34 +00:00
Loïc Sharma
31bf4a3285 [Windows] Reduce Visual Studio build errors caused by keyboard unit tests (flutter/engine#49814)
The `EXPECT_CALL_IS_EVENT` macro used features that are not supported by Visual Studio 2022's intellisense, which results in >130 errors when editing in Visual Studio. These issues only affect the editing experience, building still works as expected.

This change reduces false errors in Visual Studio by making `EXPECT_CALL_IS_EVENT` buildable in Visual Studio.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-17 23:36:22 +00:00
Loïc Sharma
e38b6f14f6 [Windows] Remove unnecessary statics in keyboard (flutter/engine#49834)
Windows's `KeyboardManager` has several top-level helper functions. These are already wrapped in an anonymous C++ namespace, which is the C++ equivalent of the C `static` keyword.

No tests are updated as this PR is a refactoring with no semantic changes.
  

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-17 23:31:33 +00:00
Jenn Magder
a7e652c7d8 Remove iOS 12 availability checks (flutter/engine#49771)
iOS minimum is now 12: https://github.com/flutter/buildroot/pull/808.  Remove `@available` checks for that version.  

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-16 23:09:58 +00:00
Loïc Sharma
9792c4bd03 Reland "[Windows] Move to FlutterCompositor for rendering" (flutter/engine#49726)
## Original pull request description

This migrates the Windows embedder to `FlutterCompositor` so that the engine renders off-screen to a framebuffer instead of directly onto the window's surface. This will allow us to support platform views and multiple views on Windows.

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

## Reland (again)

https://github.com/flutter/engine/pull/49262 was reverted as it regressed [`package:material_floating_search_bar_2`](https://pub.dev/packages/material_floating_search_bar_2/versions/0.5.0). See: https://github.com/flutter/flutter/issues/140828

This pull request is split into the following commits:

1. d337378a74 is the previous reland pull request, unchanged
2. e866af0229 disables the scissor test before blitting the framebuffer, allowing us to "force" copy the framebuffer's contents by ignoring scissoring values

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-16 22:14:02 +00:00
Loïc Sharma
005c214a4b [Windows] Add README (flutter/engine#49779)
[Link to preview](https://github.com/loic-sharma/flutter-engine/blob/windows_readme/shell/platform/windows/README.md)

Inspired by the Android README @matanlurey added here: https://github.com/flutter/engine/tree/main/shell/platform/android#readme

This gives people quick pointers that might be useful when starting their Windows journey.
2024-01-16 17:51:33 +00:00
Jia Hao
f03cc19612 Add flutter prefix to import (flutter/engine#49793)
This keeps things consistent with other imports and fixes the internal breakage (b/320443454).

While the build system here is able to handle imports both with and without the flutter prefix, the internal mechanism that rewrites these imports is currently unable to handle the latter case.
2024-01-16 16:11:19 +00:00
Ivan Inozemtsev
445a8fb328 Support running sound null safe kernels from dart_runner (flutter/engine#49598)
Before starting an isolate, `dart[_test]_component_controller` detects
sound null safety status for all given kernels and fails if they aren't
the same, and uses the result to set `null_safety` in isolate flags.

Also switch to `core` snapshots from `core-jit` snapshots, based on
https://github.com/flutter/engine/pull/30744, as it looks like
`core-jit` snapshots are not null safety agnostic.

See b/315776399


## 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.
2024-01-16 07:58:01 -08:00
Tong Mu
f15bc4cb13 [Linux] Remove the usage of std::function in FlKeyEmbedderResponder (flutter/engine#49293)
Fixes https://github.com/flutter/flutter/issues/140183

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-12 23:08:52 +00:00
Matan Lurey
5a61efcfff Add SurfaceTextureSurfaceProducer (flutter/engine#49653)
Unblocks https://github.com/flutter/flutter/issues/139702.

The next step will be local validation that this API works for at least a few of our internal plugins (video_player, camera).
2024-01-11 23:32:54 +00:00
Jonah Williams
c18d6e3a08 [Impeller] reland: write directly to device buffer. (flutter/engine#49691)
Reland of https://github.com/flutter/engine/pull/49505

---

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

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

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

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

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

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

The size of the device buffers is 1024 Kb, somewhat arbitrarily chosen.
2024-01-10 17:18:07 +00:00
Matan Lurey
670e54688a Follow various best practices in FlutterRenderer (flutter/engine#49651)
All of these are non-semantics changing and all were auto-applied by
IntelliJ:

- Make always `final` stuff final
- Avoid unnecessary casts
- Annotate `@NonNull` overrides
- Avoid initializing callbacks outside of the constructor, and use Java
lambdas when applicable
- Avoid cases where something is known to be non-null or non-false
- Use `<>` when applicable
2024-01-09 22:12:12 -08:00
LongCatIsLooong
c1458c9efd Fix macOS text composing (flutter/engine#49314)
Fixes https://github.com/flutter/flutter/issues/68547 (almost, this requires an oneliner framework patch to work).

The selection wasn't being updated correctly before this so there were no highlights. Now the selection is properly highlighted (although it seems the styling has been updated in sonoma but it's better than offering no visual feedback):

https://github.com/flutter/engine/assets/31859944/ab8557f4-7215-46de-8a9d-c2e3982695eb

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-09 22:37:49 +00:00
Matan Lurey
f0ed60a2a5 Make shell/platform/android IDE-friendly, and add documentation (flutter/engine#49612)
Closes https://github.com/flutter/flutter/issues/141043.

Nothing in this change should impact:

- End-user apps
- Testing and/or CI

I've added what I believe is the minimum required to get a reasonable
Android Studio experience with the `shell/platform/android` folder. More
could definitely be done, but this unblocks me (i.e.
https://github.com/flutter/flutter/issues/139702) and adds instructions
for the next person.

_I'm open to suggestions on how to improve this further, but unless they
are critical, I'd rather land this as-is and review your PRs tweaking my
documentation further (I have limited time to work exclusively on
docs)._

---

Example after this:


![image](https://github.com/flutter/engine/assets/168174/97dfd46b-b617-4bb5-9144-0802d88e2864)
2024-01-09 14:01:04 -08:00
John McCutchan
53769525bd Simplify PlatformViewRenderTarget interface (flutter/engine#49639)
- Enable ImageReader/SurfaceProducer backends for Android >= 29.
- This removes the need for a weird Android 29-specific fix in
SurfaceTexturePlatformViewRenderTarget.
- Now that we don't need the weird fix we can simplify the
PlatformViewRenderTarget interface.
2024-01-09 10:30:39 -08:00
John McCutchan
47f9722185 Resize the RenderTarget before creating and passing its Surface to the VirtualDisplay (flutter/engine#49619)
This change ensures that we first set the default buffer size on the
underlying SurfaceTexture before creating the Surface for it.

This fixes a bug that only occurs on Android devices running 28 or
older: see https://github.com/flutter/flutter/issues/141068.

This also removes some unnecessary init code and cleans up tests.
2024-01-09 09:00:16 -08:00
Jason Simmons
dd45c95e49 Fix memory leaks in some embedder unit tests that send key events (flutter/engine#49548)
FlutterEngineSendKeyEvent sends a platform message.  The test's embedder configuration must have a platform message callback that calls FlutterEngineSendPlatformMessageResponse to free the message's response handle.
2024-01-08 19:58:52 +00:00
Matej Knopp
6818b23a15 Enforce consistent stack size for Flutter threads (flutter/engine#49111)
Fixes https://github.com/flutter/flutter/issues/72156

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

## Pre-launch Checklist

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

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2024-01-08 10:31:02 +01:00
Dan Field
3078ba7036 Allow spawning additional UI isolates in flutter_tester (flutter/engine#48706)
This enables work ongoing by @derekxu16 to improve performance in flutter_tester when running multiple files from large test suites.

Specifically, it:

- Exposes a `Spawn` C symbol from flutter_tester that runs the current kernel in a new UI isolate with a different entrypoint and/or route name
- Exposes two symbols from flutter_tester to allow a test harness to more efficiently load particular kernel files or to lookup an entrypoint from an imported source file.
- Avoids re-loading the kernel file completely when spawning a new UI isolate

Googlers can look at go/flutter-tester-isolates for some more context. If anyone wants I'm happy to create a public version of that doc.
2024-01-05 17:13:59 +00:00
zoujunhua
b98cd15293 Add build dependencies for Android Embedder (flutter/engine#48397)
The build of embedded Android depends on the symbols of the
'icudtl.dat', as described in the change
'cf6fbe1fdcda6db2ed5d18a254b2c7c91f54f7aa' and
'7922a335e88dcb12bf6a1c681ffd6770234bbf24'.

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


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

---------

Co-authored-by: Zachary Anderson <zanderso@users.noreply.github.com>
2024-01-05 09:02:48 -08:00
John McCutchan
718ac2c814 Fix a crash in the new SurfaceProducer external texture (flutter/engine#49496)
The following sequence of events would lead to a crash:

- Reader A is created.
- Reader A produces a frame (A0)
- Texture is resized.
- Reader B is created and reader A is scheduled to be closed.
- Reader A produces a frame (A1). This is skipped.
- Reader A is closed.
- Frame A0 is acquired.

Because we closed Reader A the frame A0 is invalid.

The fix is to not close Reader A when it is the last reader to produce a
frame.

Fixes internal bug b/318458306
2024-01-03 10:56:46 -08:00
Tong Mu
ceaa4c9fc6 Revert skiping illegal render in Dart (flutter/engine#49473) 2024-01-03 10:45:16 -08:00
Loïc Sharma
8be4835c7c Revert "Reland "[Windows] Move to FlutterCompositor for rendering" (flutter/engine#49461)
This reverts https://github.com/flutter/engine/pull/49262 (f3381e1080) as it regressed [`material_floating_search_bar`](https://pub.dev/packages/material_floating_search_bar_2)'s animation.

This revert was created manually due to merge conflicts.

Issue tracking bug: https://github.com/flutter/flutter/issues/140828

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

<details>
<summary>Minimal repro of the broken animation...</summary>

Here's what the animation is supposed to look like:
![good](https://publish-01.obsidian.md/access/b48ac8ca270cd9dac18c4a64d11b1c02/assets/2023-12-28-compositor_animation_regression_good.gif)

Here's what the animation actually looks like: ![bad](https://publish-01.obsidian.md/access/b48ac8ca270cd9dac18c4a64d11b1c02/assets/2023-12-28-compositor_animation_regression_bad.gif)

Here is a minimal repro of the broken animation:

```dart
// The Windows compositor changes regresses the animation in
// the `material_floating_search_bar_2` package:
// 
// https://pub.dev/packages/material_floating_search_bar_2/versions/0.5.0
//
// Below is a minimal repro of the broken animation. This has two pieces:
//
//  1. The background fades to a grey color
//  2. A box is "revealed" using a custom clipper
//
// On framework commit b417fb828b332b0a4b0c80b742d86aa922de2649 this animation is broken on Windows.
// On framework commit 9c2a7560096223090d38bbd5b4c46760be396bc1 this animation works as expected on Windows.
//
// Good gif: https://publish-01.obsidian.md/access/b48ac8ca270cd9dac18c4a64d11b1c02/assets/2023-12-28-compositor_animation_regression_good.gif
// Bad gif: https://publish-01.obsidian.md/access/b48ac8ca270cd9dac18c4a64d11b1c02/assets/2023-12-28-compositor_animation_regression_bad.gif
import 'dart:math';
import 'dart:ui';

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    // Not using `MaterialApp` is necessary to reproduce:
    return Container(
      color: Colors.white,
      child: const Directionality(
        textDirection: TextDirection.ltr,
        child: FloatingSearchBar(),
      ),
    );

    // Switching to `MaterialApp` fixes the issue:
    // return const MaterialApp(
    //   home: Scaffold(
    //     body: FloatingSearchBar(),
    //   ),
    // );
  }
}

class FloatingSearchBar extends StatefulWidget {
  const FloatingSearchBar({super.key});

  @override
  FloatingSearchBarState createState() => FloatingSearchBarState();
}

class FloatingSearchBarState extends State<FloatingSearchBar> with SingleTickerProviderStateMixin {
  late final AnimationController _controller = AnimationController(
    vsync: this,
    duration: const Duration(seconds: 2),
  );

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  void _animate() {
    if (_controller.isDismissed || _controller.status == AnimationStatus.reverse) {
      _controller.forward();
    } else {
      _controller.reverse();
    }
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: _controller,
      builder: (BuildContext context, _) {
        return Stack(
          children: <Widget>[
            if (!_controller.isDismissed)
              FadeTransition(
                opacity: _controller,
                child: const SizedBox.expand(
                  child: DecoratedBox(
                    decoration: BoxDecoration(color: Colors.black26),
                  ),
                ),
              ),

            _buildSearchBar(),
          ],
        );
      },
    );
  }

  Widget _buildSearchBar() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        // This is where the search text input would go...
        GestureDetector(
          onTap: () => _animate(),
          child: Text(
            switch (_controller.status) {
              AnimationStatus.forward || AnimationStatus.completed => 'Click to close',
              AnimationStatus.reverse || AnimationStatus.dismissed => 'Click to open',
            },
            style: const TextStyle(color: Colors.black),
          ),
        ),
        
        // Below are where the search results would be. Clicking on the search
        // input above reveals the results below.

        // Removing this fixes the background's fade transition.
        ClipOval(
          clipper: _CircularRevealClipper(
            fraction: _controller.value,
          ),
          child: DecoratedBox(
            decoration: BoxDecoration(
              color: Colors.white,
              // Removing this line fixes the background's fade transition.
              borderRadius: BorderRadius.circular(16.0),
            ),
            child: const Padding(
              padding: EdgeInsets.all(64.0),
              child: Text(
                'Hello world',
                style: TextStyle(color: Colors.black),
              ),
            ),
          ),
        ),
      ],
    );
  }
}

class _CircularRevealClipper extends CustomClipper<Rect> {
  const _CircularRevealClipper({required this.fraction});

  final double fraction;

  @override
  Rect getClip(Size size) {
    final double halfWidth = size.width * 0.5;
    final double maxRadius = sqrt(halfWidth * halfWidth + size.height * size.height);
    final double radius = lerpDouble(0.0, maxRadius, fraction) ?? 0;

    return Rect.fromCircle(
      center: Offset(halfWidth, 0),
      radius: radius,
    );
  }

  @override
  bool shouldReclip(CustomClipper<Rect> oldClipper) {
    if (oldClipper is _CircularRevealClipper) {
      return oldClipper.fraction != fraction;
    }

    return true;
  }
}

```

</details>

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-02 23:31:04 +00:00
John McCutchan
6518198fc6 Android Platform Views support Verified Input Events (flutter/engine#49268)
Android Platform Views process MotionEvents in a complicated way:

1. MotionEvent is captured and delivered to
PlatformViewWrapper.onTouchEvent (TLHC) or
FlutterMutatorView.onTouchEvent (HC)
2. MotionEvent is transformed by the AndroidTouchProcessor into a
PointerEvent
3. AndroidTouchProcessor sends the PointerEvent over the
PlatformViewChannel
4. Framework processes the PointerEvent
5. Framework sends the PointerEvent over the PlatformViewChannel.
6. in PlatformViewsController.onTouch a new MotionEvent is synthesized
7. The MotionEvent is delivered to the platform view

After step (6) the MotionEvent will fail Verification
(`android.hardware.input.InputManager.verifyInputEvent`).

The fix requires that in step (6) we use the original motion event
delivered in step (1) instead of synthesizing a new instance.
2024-01-02 11:32:06 -08:00
Rulong Chen(陈汝龙)
ba2b335b99 Fix NPE when platform plugin delegate is null (flutter/engine#49391)
Fixes: 
https://github.com/flutter/flutter/issues/140600
https://github.com/flutter/flutter/issues/140031

## 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.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2024-01-02 08:54:39 -08:00
Rulong Chen(陈汝龙)
62abbc2a03 Add try-with-resource support to TraceSection (flutter/engine#49445)
This PR adds a new way to define scoped trace events in Java, using the try-with-resource construct. This makes code simpler to read, and less error-prone.

Before:
```java
try {
  TraceSection.begin("name");
  // ....
} finally {
  TraceSection.end();
}
```

Now:
```java
try (TraceSection e = TraceSection.scoped("name")) {
  // ...
}
```

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-02 16:35:19 +00:00
Loïc Sharma
e7b8646416 [Windows] Move DWM flush to Windows proc table for mocking (flutter/engine#49398)
The `FlutterWindowsView` uses the `DwmFlush` win32 API to prevent artifacts during window resizing.

Currently, the view used the `FlutterWindow` to allow mocking this win32 API. However, the window is a complex type with lots of other responsibilities. The `WindowsProcTable` is the new preferred type for mocking win32 API.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-12-27 23:41:19 +00:00
Loïc Sharma
ed5f58647f [Windows] Move DWM composition status to Windows proc table for mocking (flutter/engine#49397)
The `FlutterWindowsView` needs the `DwmIsCompositionEnabled` win32 API to check whether it should block presents until the v-blank to prevent screen tearing.

Currently, the view used the `FlutterWindow` to allow mocking this win32 API. However, the window is a complex type with lots of other responsibilities. The `WindowsProcTable` is the new preferred type for mocking win32 API.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-12-26 23:08:34 +00:00
Loïc Sharma
e18aa559bd [Windows] Remove PlatformWindow and RenderTarget abstractions (flutter/engine#49312)
The Windows embedder has three ways to get an `HWND`:

1. `GetWindowHandle` which returns the `HWND`
2. `GetPlatformWindow` which returns the `HWND` wrapped as a `PlatformWindow`
3. `GetRenderTarget` which returns the `HWND` wrapped as a `RenderTarget`

These abstractions are no longer useful now that we removed the UWP embedder. This change removes `PlatformWindow` and `RenderTarget` and uses `HWND` directly.

This change is a refactoring with no semantic changes.
2023-12-26 19:34:06 +00:00
Dan Field
cfdadd3c74 Fix GetImpellerContext for ShellTestPlatformViewGL (flutter/engine#49337)
I tried to do this for Vulkan too but hit the limit of my patience for today on debugging why the Vulkan backend was segfaulting on shutdown.

Half of https://github.com/flutter/flutter/issues/140419
2023-12-22 00:52:23 +00:00
Loïc Sharma
6e4ab692e7 [Windows] Fix incorrect surface manager comment (flutter/engine#49335)
https://github.com/flutter/engine/pull/24428 attempted to make surface resizing less expensive by using ANGLE's automatic resizing instead of manually destroying and then re-creating the surface. This caused 
some issues:

1. Flutter's surface size synchronization logic broke: https://github.com/flutter/engine/pull/24682
2. Resizing frameless windows caused the content to wiggle: https://github.com/flutter/flutter/issues/76465

The second issue caused the automatic resizing change to be reverted. However, the first fix was not reverted resulting in an incorrect comment.

Relanding this resizing performance improvement is tracked by https://github.com/flutter/flutter/issues/79427
2023-12-21 21:58:41 +00:00
Dan Field
ae9289f5c1 [Impeller] Make IPLR files multi-platform (flutter/engine#49253)
This is part of the work towards supporting OpenGLES and Vulkan for runtime stage shaders.

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

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

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

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

I have run some but not all tests locally.
2023-12-21 06:17:26 +00:00
Loïc Sharma
f3381e1080 Reland "[Windows] Move to FlutterCompositor for rendering" (flutter/engine#49262)
## Reland

https://github.com/flutter/engine/pull/48849 was reverted as it incorrectly expected to receive always 1 layer. However, the engine will present 0 layers on an ["empty" app](6981fe6fd3/dev/integration_tests/ui/lib/empty.dart (L8-L19)). This pull request is split into two commits:

1. df604a16c0 is the original pull request, unchanged
2. c30b369289 adds the ability to "clear" the view if the engine presents 0 layers

## Original pull request description

This migrates the Windows embedder to `FlutterCompositor` so that the engine renders off-screen to a framebuffer instead of directly onto the window's surface. This will allow us to support platform views and multiple views on Windows.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-12-21 01:23:20 +00:00
Tong Mu
e986324f93 Multiview pipeline Pt. 1: Skip illegal render calls (flutter/engine#49266)
This is one of a series of changes to reland https://github.com/flutter/engine/pull/47239.

This PR changes `Animator` so that if `Render` is not called after a `BeginFrame`, this call is ignored.

Note that this is slightly different from https://github.com/flutter/engine/pull/47239. Instead of saying that we should ultimately change this skip to an assertion, this PR aims to keep the skip as the final shape. This is because a while ago we (with @goderbauer and @loic-sharma) decided that `PlatformDispatcher` should contain as little logic as possible to allow testing, and instead serve as a minimal native function binding, which means that we should eventually move the code that validates calling convention to the engine. 

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-12-20 22:50:09 +00:00
Bartek Pacia
94d48e76c1 SemanticsUpdateBuilder: make all args non-null (flutter/engine#49148)
This PR is inspired by [the suggestion made here](https://github.com/flutter/engine/pull/47961#discussion_r1406581284).
2023-12-20 22:41:13 +00:00
Tong Mu
2e551cb5c3 Multi-view pointer event (flutter/engine#46213)
This PR adds a new field `view_id` to embedder API's `FlutterPointerEvent`, allowing platforms to specify the source view of pointer events.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-12-20 19:21:22 +00:00
Sergiy Dubovik
b7264de08d [macos] FlutterKeyboardManager memory leak fix (flutter/engine#48824)
We are embedding Flutter into MacOS app, and noticed that there is a
leak. `leaks` tool says there is a cycle reference:

```
12 (2.11K) ROOT CYCLE: <FlutterKeyboardManager 0x29ec55f40> [80]
       8 (432 bytes) __strong _primaryResponders --> ROOT CYCLE: <NSMutableArray 0x29ec560a0> [64]
          7 (368 bytes) ROOT CYCLE: <NSMutableArray (Storage) 0x29ec56140> [32]
             4 (224 bytes) ROOT CYCLE: <FlutterEmbedderKeyResponder 0x29ec56310> [80]
                1 (48 bytes) __strong _sendEvent --> ROOT CYCLE: <__NSMallocBlock__ 0x29ec56360> [48]
                   __strong [capture] --> CYCLE BACK TO <FlutterKeyboardManager 0x29ec55f40> [80]
                1 (48 bytes) __strong _pendingResponses --> <NSMutableDictionary 0x29ec563c0> [48]
                1 (48 bytes) __strong _pressingRecords --> <NSMutableDictionary 0x29ec56390> [48]
             2 (112 bytes) <FlutterChannelKeyResponder 0x29ec56450> [48]
                1 (64 bytes) __strong _channel --> <FlutterBasicMessageChannel 0x29ec564e0> [64]
       2 (1.55K) __strong _layoutMap --> <NSMutableDictionary 0x29ec56630> [48]
          1 (1.50K) <NSMutableDictionary (Storage) 0x123c34a00> [1536]
       1 (64 bytes) __strong _pendingEvents --> <NSMutableArray 0x29ec565f0> [64]
```

This patch uses `weak` pointer to `self` instead of implicit `strong`.

## 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.
2023-12-20 09:04:10 -08:00
Tong Mu
927fd200ed Revert "Reland 2: Multiview Pipeline (#47239)" (flutter/engine#49238)
This reverts commit 87171e73397f7edfd4c145fbaebdd7208954debf.

Internal performance test shows that this PR negatively affects startup time. I'll reland this PR in parts.

b/307872797

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-12-19 22:30:01 +00:00
Zachary Anderson
971c03d9e3 Rolls clang to 725656bdd885483c39f482a01ea25d67acf39c46 (flutter/engine#49248)
We're on a version of clang that crashes a lot on macOS. This PR rolls
clang forward to a new release from the Fuchsia toolchain team. If it
does not fix the crash, we can roll back with
https://github.com/flutter/engine/pull/49249. Both rolling forward and
back require the fixes to the `.mm` file in this PR.
2023-12-19 13:35:42 -08:00
John McCutchan
294a05da81 Use new SurfaceProducer external texture class for rendering platform views (flutter/engine#49201)
- Fix lots of bugs in the implementation of ImageReaderSurfaceProducer
- Add test that we drop frames produced from the wrong size
- Hookup platform views to use new external texture class

Related: [#139230](https://github.com/flutter/flutter/issues/139230)
Related: [#139702](https://github.com/flutter/flutter/issues/139702)
2023-12-19 10:08:46 -08:00
Code Otaku
7f0343f6fc Makes PlatformViewsController view to use tracked event's action & pointer count (flutter/engine#47424)
related issue https://github.com/flutter/flutter/issues/111268,
https://github.com/flutter/flutter/issues/106190

### Motivation:
- At https://github.com/flutter/flutter/issues/111268, we found that
Android PlatformView scrolls slowly after #34182 commit

### Modification:
- Makes `PlatformViewsController` view to use `tracked event`'s action &
pointer count

### Result:
- Now PlatformView scrolls not slowly
- Close https://github.com/flutter/flutter/issues/111268,
https://github.com/flutter/flutter/issues/106190


- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.

Co-authored-by: John McCutchan <john@johnmccutchan.com>
2023-12-18 20:41:02 -08:00
Jim Graham
91806f60d6 [Impeller] Make Rect origin and size fields private (flutter/engine#49168)
Make the implementation fields of Rect private in preparation for switching its internal operations from XYWH to LTRB fields.
2023-12-18 22:48:10 +00:00
Matej Knopp
33a6339c63 Add FlutterMetalLayer as optional alternative to CAMetalLayer (flutter/engine#48226)
This PR implements `FlutterMetalLayer`, a drop-in (as far as Flutter is
concerned) replacement for `CAMetalLayer`. The biggest difference is
that `FlutterMetalLayer` can present frames from background thread
within a `CATransaction`.

`FlutterMetalLayer` is disabled by default. To opt-in, add the following
item to `Info.plist`:

```xml
        <key>FLTUseFlutterMetalLayer</key>
	<true/>
```

The performance seems quite good, consistent 120hz on iPhone 13 Pro.

Benefits
- presenting with transaction from background thread, which, down the
line, would allow for platform views without thread merging.
- fine control over how the surface is displayed - we can display single
surface on multiple `CALayers`, each showing different part, allowing
for performant implementation of unobstructed platform views.
 
Drawbacks
- this not being a metal layer makes working with metal instrument tools
more awkward
2023-12-16 21:53:32 +01:00
Dan Field
19726b1650 Statically link swiftshader into flutter_tester (flutter/engine#48708)
Depends on https://swiftshader-review.googlesource.com/c/SwiftShader/+/72768

Fixes https://github.com/flutter/flutter/issues/138169
2023-12-16 00:47:57 +00:00
gaaclarke
a53bf6a572 [Impeller] split out gradient tests from aiks_unittests (flutter/engine#49050)
issue https://github.com/flutter/flutter/issues/140106

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-12-15 01:12:53 +00:00
Matan Lurey
02f6c46771 Fix header-guard naming convention in shell/. (flutter/engine#49006)
Part of landing https://github.com/flutter/engine/pull/48903.

Some of these actually seem like potential owchy spots, i.e. `#ifndef FLUTTER_FLUTTER_H_`.
2023-12-14 23:37:22 +00:00
Lau Ching Jun
2363abacfe Suppress warning for the new Activity library. (flutter/engine#49046)
Context: cl/582573869
2023-12-14 23:09:54 +00:00
Jenn Magder
2d0010fcb6 Fix NSPrivacyCollectedDataTypes array in privacy manifest (flutter/engine#49041)
In https://github.com/flutter/engine/pull/48951 `NSPrivacyCollectedDataTypes` is an array with an empty dictionary, but the privacy report wants an empty array or it errors:

<img width="523" alt="Screenshot 2023-12-14 at 10 02 52 AM" src="https://github.com/flutter/flutter/assets/682784/a128b384-db2f-49d7-8b71-7965f2826de8">

When this is fixed the privacy report is blank, but that seems to be an Xcode bug?  Will investigate.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-12-14 20:26:05 +00:00