429 Commits

Author SHA1 Message Date
Loïc Sharma
12228ffd98 [Windows] Make the engine own a map of views (flutter/engine#51017)
Updates Windows engine's data structures to use a map of views.

This is a refactoring with no semantic changes. Flutter Windows's APIs restrict users to 0 or 1 view only - it is not possible to create multiple views yet.

_One small step for Windows. One giant leap for multi-view._

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-27 23:28:00 +00:00
Loïc Sharma
becf9fb52f [Windows] Remove TODONE (flutter/engine#51005)
This TODO is TODONE!

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-27 21:15:06 +00:00
Loïc Sharma
218151583f [Windows] Introduce an accessibility plugin (flutter/engine#50975)
_This is the same pull request as https://github.com/flutter/engine/pull/50898. GitHub broke on the previous pull request so I re-created it_

This moves the logic to handle `flutter/accessibility` messages to a new type, `AccessibilityPlugin`. 

Notable changes:

1. Windows app no longer crashes if it receives accessibility events it does not support
2. Windows app no longer crashes if it receives accessibility events while in headless mode

@yaakovschectman After playing around with this, I ended up using a different pattern than what what I suggested on https://github.com/flutter/engine/pull/50598#discussion_r1488728089. This message handler is simple enough that splitting into a child/base types felt like unnecessary boilerplate. The key thing is separating messaging and implementation logic, which was achieved through the `SetUp` method. Let me know what you think, and sorry for all my flip-flopping on this topic! 😅

This is preparation for: https://github.com/flutter/flutter/issues/143765

Sample app for manual testing: https://github.com/flutter/flutter/issues/113059

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-27 20:59:24 +00:00
yaakovschectman
ac3cb8cd7b Add Platform View Manager to Windows shell (flutter/engine#50598)
Create a manager for platform views accessible to the compositor, handle
the methods that the framework will send.

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

## 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 `///`).
- [ ] 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: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
2024-02-26 10:13:46 -05:00
Loïc Sharma
788179d383 [Windows] Refactor the a11y announcement test (flutter/engine#50888)
This refactors the Windows accessibility announcement test. This will make it easier to add a headless variant of this test as part of https://github.com/flutter/flutter/issues/143765.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-24 00:26:02 +00:00
Loïc Sharma
b73e827969 [Windows] Add helper for headless integration tests (flutter/engine#50885)
We'll add more headless mode tests as part of https://github.com/flutter/flutter/issues/143765.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-23 23:23:29 +00:00
Loïc Sharma
4865589c11 [Windows] Fix top-level message procedure order (flutter/engine#50797)
The Windows embedder registers "message procedures" to handle to top-level window events. These message procedures should be called in the order that they are registered.

For example, a plugin can override the embedder's app lifecycle behavior by registering a message procedure before the embedder's app lifecycle message procedure.

This did not always work as expected as the message procedures were ordered by their pointers instead of their insertion order.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-21 22:52:50 +00:00
Zachary Anderson
f6629ffe5c Use 'et format' in CI. Check formatting of all files in CI (flutter/engine#50810)
This PR changes the format check on CI to use the command added in
https://github.com/flutter/engine/pull/50747.

Additionally, while making this change, I noticed that the CI check was
not checking the formatting of all files, and that as a result, files
were present in the repo with incorrect formatting. I have fixed the
formatting and fixed the check to always check all files.
2024-02-21 09:38:08 -08:00
Loïc Sharma
7c8dcec741 [Windows] Add ID to views (flutter/engine#50788)
Adds an ID to a view:

1. `FlutterWindowsView` now has a ID
2. The `FlutterWindowsEngine::view(...)` accessor now requires a view ID parameter

This is a refactoring with no semantic changes.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-20 20:40:04 +00:00
Loïc Sharma
f3ad50c810 [Windows] Make the engine create the view (flutter/engine#50673)
This makes the Windows engine create views. Benefits:

1. This will allow the engine to assign IDs to views as it creates them. This will be added in a subsequent change
2. Previously views needed special logic to not crash if they were used before an engine was attached to them. Now, views are always attached to an engine.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-20 16:41:46 +00:00
Loïc Sharma
89b44f4fff [Windows] Improve FlutterWindow unit tests (flutter/engine#50676)
_This was split from https://github.com/flutter/engine/pull/50673 to reduce noise in that PR._

Previously `MockFlutterWindow` called a `FlutterWindow` constructor which created a window & resized it. This change introduces a minimal base constructor for testing purposes. This allows us to skip some noisy mocks in a subsequent change: https://github.com/flutter/engine/pull/50673

This also introduces a fixture for the window unit tests.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-16 00:38:18 +00:00
Chinmay Garde
6c17d7bf9d Use a GN variable (dart_src) to reference the location of the Dart checkout. (flutter/engine#50624)
Towards https://github.com/flutter/flutter/issues/143335
2024-02-14 21:12:23 -08:00
Loïc Sharma
729dd91430 [Windows] Refactor window destroyed app lifecycle event (flutter/engine#50565)
Improves Windows's lifecycle event for window destruction:

1. Made `FlutterWindowsView` generate the "window hidden" event when the HWND is destroyed instead of the `FlutterWindow`.
    1. Before the window would submit this event using a destroyed view:
        1. The `FlutterWindowsView` destructor runs to completion.
        2. The view owns the window, so the `FlutterWindow` is destroyed
        3. The window's destructor generates a "window hidden" event
        4. The window uses the destroyed view to notify the engine of the event
2. Adds an app lifecycle integration test to verify the `resumed` and `hidden` events are sent when an app is launched and closed.
3. Removed the `FlutterWindowTest` type as it was unused

Prepares for https://github.com/flutter/flutter/issues/137267

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-13 22:35:42 +00:00
Loïc Sharma
9c365da297 [Windows] Make the view own its EGL surface (flutter/engine#50421)
This makes the view own its EGL surface. This will allow us to support multiple EGL surfaces once the engine supports having multiple views.

Some notable changes:

1. EGL surface resizing logic is now entirely in `FlutterWindowsView`. Previously some resizing logic was in the `egl::Manager`, however, the view has to handle resizing failures so this unifies the logic in one place.
2. The `OnEmptyFrameGenerated` and `OnFrameGenerated` now return `false` (aka "don't present") if the surface is invalid. This simplifies the compositor as it no longer needs to check for invalid surfaces
3. This introduces a `ViewModifier` testing helper to allow overriding a view's surface. This isn't strictly necessary, tests can setup a surface by mocking several EGL methods and calling `FlutterWindowsView::CreateRenderSurface()`. However, this is verbose & heavily tied to implementation details. The `ViewModifier` avoids this boilerplate.
4. `CompositorOpenGL`'s initialization now makes the render context current without any render surfaces. Previously it also made the view's surface current, which was unnecessary.

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
2024-02-12 18:22:51 +00:00
Loïc Sharma
5251e0048f Reland "[Windows] Introduce egl::Surface and egl::WindowSurface" (flutter/engine#50148)
# Original pull request description

This introduces the `egl::Surface` and `egl::WindowSurface` types to abstract a raw `EGLSurface`. This also removes some - but not all - EGL surface logic out from `EGLManager`.

Subsequent pull requests will be necessary to:

1. Move ownership of the `egl::WindowSurface` from `egl::Manager` to `FlutterWindowsView`
2. Refactor external texture's off-screen EGL surface to use `egl::Surface`

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

# Reland

https://github.com/flutter/engine/pull/49983 was reverted as it introduced a crash if the render surface fails to be created even though EGL was initialized successfully.

This pull request is split into the following commits:

1. c0b11be79f is the original pull request unchanged
2. 1dc7813845 is the fix: it checks a surface is valid before using it. This also adds several tests to prevent this kind of regression.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-02-01 17:08:15 +00:00
Loïc Sharma
7918e2046c Revert "[Windows] Introduce egl::Surface and egl::WindowSurface" (flutter/engine#50104)
Reverts flutter/engine#49983
2024-01-27 19:15:04 +00:00
Hasan Mohsin
eb072d8928 [Windows] Set cursor immediately when framework requests update (flutter/engine#49784)
On Windows, when using a `MouseRegion` widget to change the cursor it is not actually updated until the cursor is moved. This is because the Windows embedder only updates the `current_cursor_` field but does not actually set the cursor until the window receives the `WM_SETCURSOR` message when the mouse moves. This change makes it set the cursor immediately.

Fixes flutter/flutter#76622
2024-01-25 00:48:23 +00:00
Loïc Sharma
7aecd394de [Windows] Introduce egl::Surface and egl::WindowSurface (flutter/engine#49983)
This introduces the `egl::Surface` and `egl::WindowSurface` types to abstract a raw `EGLSurface`. This also removes some - but not all - EGL surface logic out from `EGLManager`.

Subsequent pull requests will be necessary to:

1. Move ownership of the `egl::WindowSurface` from `egl::Manager` to `FlutterWindowsView`
2. Refactor external texture's off-screen EGL surface to use `egl::Surface`

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-25 00:30:53 +00:00
Loïc Sharma
7509954809 [Windows] Introduce egl::Context (flutter/engine#49954)
This introduces a new `egl::Context` type that abstracts a raw `EGLContext`. This also removes the EGL context logic out from `EGLManager`.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-23 20:17:02 +00:00
Loïc Sharma
e54858b901 [Windows] Rename and move EGL types (flutter/engine#49900)
This is a refactoring with no semantic changes. The following types were renamed:

* `flutter::AngleSurfaceManager` to `flutter::egl::Manager`. In subsequent pull requests, this type will _create_ but not _own_ surfaces. Furthermore, this type will be split up to introduce `flutter::egl::Surface` and `flutter::egl::Context`. The manager will own the contexts and each surface will be owned by its view.
* `flutter::GlProcTable` to `flutter::egl::ProcTable`

This also introduces an `egl` directory to the Windows embedder.

Previous pull request: https://github.com/flutter/engine/pull/49895

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-22 22:09:25 +00:00
Loïc Sharma
3ed2cd569f [Windows] Fix resize crash (flutter/engine#49935)
https://github.com/flutter/engine/pull/49872 introduced a crash in debug mode if the platform thread starts a window resize in between `OnFrameGenerated` and `OnFramePresented`.

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-22 19:08:56 +00:00
Loïc Sharma
78728e1649 [Windows] Refactor EGL initialization (flutter/engine#49895)
This is a refactoring with no semantic changes:

1. Fixes incorrect style in `AngleSurfaceManager`
2. Cleans `AngleSurfaceManager`'s initialization logic

Next pull request: https://github.com/flutter/engine/pull/49900

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-19 21:32:27 +00:00
Loïc Sharma
e47107cf38 [Windows] Refactor logic when window resize completes (flutter/engine#49872)
Changes:

1. Moves surface buffer swapping from `FlutterWindowsView` to `CompositorOpenGL`
1. Renames `FlutterWindowsView::SwapBuffers` to `FlutterWindowsView::OnFramePresented`
2. Previously, if a resize was pending and the window was not visible Windows would unblock the platform thread before swapping buffers. This trick aimed to reduce the time the platform thread was blocked as swapping buffers previously waited until the v-blank. This logic was removed as swapping buffers no longer waits until the v-blank.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2024-01-18 22:11:16 +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
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
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
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
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
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
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
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
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
Loïc Sharma
d5968a10c0 [Windows] Remove header guard from generated key map (flutter/engine#48993)
No tests as this is a refactoring with no semantic changes.

The generator was updated by https://github.com/flutter/flutter/pull/140082
2023-12-14 19:50:05 +00:00
auto-submit[bot]
171873ec88 Reverts "[Windows] Move to FlutterCompositor for rendering" (flutter/engine#49015)
Reverts flutter/engine#48849
Initiated by: loic-sharma
This change reverts the following previous change:
Original 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.

<details>
<summary>Tests...</summary>

* Verify OpenGL compositor's raster time isn't regressed and memory increase is reasonable
* Software compositor's raster time and memory isn't regressed

Test device configurations
* [x] Windows 11 (hardware acceleration enabled/disabled)
* [x] Windows Arm64 (hardware acceleration enabled/disabled)
* [x] Windows 7 (hardware acceleration enabled/disabled, DWM enabled/disabled)

</details>

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-14 05:03:20 +00:00
Loïc Sharma
d5a40e1093 [Windows] Move to FlutterCompositor for rendering (flutter/engine#48849)
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.

<details>
<summary>Tests...</summary>

* Verify OpenGL compositor's raster time isn't regressed and memory increase is reasonable
* Software compositor's raster time and memory isn't regressed

Test device configurations
* [x] Windows 11 (hardware acceleration enabled/disabled)
* [x] Windows Arm64 (hardware acceleration enabled/disabled)
* [x] Windows 7 (hardware acceleration enabled/disabled, DWM enabled/disabled)

</details>

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-13 23:21:56 +00:00
Loïc Sharma
5139925e3b [Windows] Refactor surface manager mocking (flutter/engine#48953)
See: https://github.com/flutter/engine/pull/48849#discussion_r1424535869
2023-12-13 17:42:52 +00:00
Loïc Sharma
ea34df3c56 [Windows] Set swap interval on raster thread after startup (flutter/engine#47787)
The EGL context can only be used by a single thread at a time. Currently:

1. The platform thread uses the EGL context to configure the render surface when a `FlutterViewController` is created
2. The raster thread uses the EGL context to render

In a multi-view world, a `FlutterViewController` can be created in parallel to a rendering operation. This results in multiple threads attempting to use the EGL context in parallel, which can crash (see https://github.com/flutter/flutter/issues/137973).

This change configures the render surface on the raster thread if the raster thread exists (aka the engine is running).

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

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-12-06 18:44:17 +00:00
Loïc Sharma
6c6f23360c [Windows] Refactor the GLES proc table (flutter/engine#48688)
GLES functions are resolved at runtime. This refactors how these functions are stored by introducing the `GlProcTable` abstraction.

This is a step towards switching the Windows embedder to `FlutterCompositor` rendering as the present callback will use the `GlProcTable` to render OpenGL backing stores.
 
Part of 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-06 18:19:36 +00:00
Loïc Sharma
20e5300477 [Windows] Decouple the GL context from the view (flutter/engine#48636)
In the future, the GL context will be shared between zero or more views. The engine will also need to be able to make the GL context current even if the app is currently in headless mode.

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

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-12-04 20:53:03 +00:00
Loïc Sharma
f5cacea14a [Windows] Begin decoupling text input plugin from the view (flutter/engine#47833)
Currently the text input plugin is strongly tied to a single view. This change makes the text input plugin tied to the engine in preparation for multi-view world.

Part of 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-30 21:49:14 +00:00
yaakovschectman
bb97ac1d3b Assign mojom kSwitch role to switches (flutter/engine#48146)
We have previously been using the `kToggleButton` role for any widget
that has a toggled state. Our AX library does not expect this role to be
used for switches, and so would not assign the checked state to switches
for MSAA. As far as I can tell, the `Switch` is the only widget that
uses the `toggled` semantic property (`ToggleButtons`, ironically, does
not), so we ought to be able to swap in the `kSwitch` role, for which
the proper states are presented. This will allow screen readers to
announce the state of a switch.

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

## 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 `///`).
- [ ] 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-17 14:21:23 -05: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
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
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
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