Repository: flutter
Issue: Disable ANGLE's "force context check" build flag
Labels: platform-windows,a: desktop,P3,team-windows,triaged-windows

We should disable ANGLE's "force context check" flag to improve performance and align with ANGLE's defaults. Before doing this, we should make sure that the ANGLE bugs uncovered by disabling this flag are fixed.

## Background

In [angle@54dfb62](https://github.com/google/angle/commit/54dfb62c24ddd0fb825c874ad00ddbbd769fa2bc), ANGLE made the "force context check" flag off by default [to improve performance](https://chromium-review.googlesource.com/c/angle/angle/+/2809855). Disabling this flag uncovered several bugs in ANGLE's D3D11 renderer that can cause [Flutter 3.3.0 to crash](https://github.com/flutter/flutter/issues/110311). [This flag was re-enabled](https://github.com/flutter/engine/pull/37055) to bring Flutter back to the last known good state used by Flutter 3.0.5 and earlier.

### What is the "force context check" flag?

Per the ANGLE team:

> This flag is to allow our D3D11 backend to be multithreaded at the cost of additional synchronization. If flutter is using ANGLE from multiple threads on Windows, you should leave this flag enabled by default.

Flutter does not use ANGLE from multiple threads, so ideally Flutter would disable this flag.

### Next steps to fix the ANGLE bug?

The ANGLE team were very helpful, but their suggested patches to the D3D11 renderer uncovered more bugs. They asked for a minimal repro of this crash so that they could investigate further on their end.

<details>
<summary>Suggested D3D11 renderer patch...</summary>

Suggestion by syoussefi@

> ... given what `ANGLE_FORCE_CONTEXT_CHECK_EVERY_CALL` does (it forces the state to be resynced) and where mFramebuffer11 is set (in response to `DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING`), it must be that the framebuffer binding state is not dirty when eglMakeCurrent is called... which makes sense. ... There is no reason why these pointers should be reset; the state may not be dirty and no one is re-setting these opinters back (in your case, mFramebuffer11).

```diff
diff --git a/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp b/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp
index 663b23826..89d35085c 100644
--- a/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp
@@ -1795,9 +1795,9 @@ angle::Result StateManager11::onMakeCurrent(const gl::Context *context)
     }

     // Reset the cache objects.
-    mProgramD3D    = nullptr;
-    mVertexArray11 = nullptr;
-    mFramebuffer11 = nullptr;
+    // mProgramD3D    = nullptr;
+    // mVertexArray11 = nullptr;
+    // mFramebuffer11 = nullptr;

     return angle::Result::Continue;
 }
```

</details>


### Crash reproduction

Here are the steps to reproduce the ANGLE to crash:

1. Enable the "force context check" flag by switching to Flutter commit https://github.com/flutter/flutter/commit/220ffc77f3752ed9d59e66babddbe33527422e1b
2. Checkout [`MixinNetwork/flutter-plugins`@6f8458f](https://github.com/MixinNetwork/flutter-plugins/tree/6f8458fed6de65bf119d4812b2186c03d8c4b7b2)
3. Launch the desktop_webview_window example on Windows
    1. `cd packages/desktop_webview_window/example`
    2. `flutter run -d windows`
4. Press the `Open` button

The app should crash.