Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[macOS] Refactor rendering infrastructure #37789

Merged
merged 34 commits into from
Dec 14, 2022

Conversation

knopp
Copy link
Member

@knopp knopp commented Nov 20, 2022

Notable changes:

  • Removed FlutterIOSurfaceHolder, FlutterResizableBackingStore
  • Replaced FlutterResizeSynchronizer with FlutterThreadSynchronizer
  • Changed the role of FlutterSurfaceManager
  • Unified most of the rendering codepath with and without compositor

High level overview

  • FlutterView owns FlutterSurfaceManager
  • FlutterCompositor and FlutterRenderer interact with FlutterSurfaceManager in order to
    • Obtain render surfaces, which are then represented as metal textures and provided to engine.
    • Present render surfaces, which FlutterSurfaceManager sets as contents of CALayers that it manages.
  • FlutterSurfaceManager caches surfaces so that during normal (no resizing) repaint IOSurfaces do not need to be recreated.
  • FlutterThreadSynchronizer is in charge of synchronising raster and platform thread:
    • During resizing blocks platform thread until content of requested size is available.
    • When rasterizing is done blocks raster thread while layers contents are updated and platform views are mutated (on platform thread).

Fixes

  • Simplifies rendering flow.
  • Fixes threading issues with platform views (FlutterEngine.Compositor test now works)
  • Fixes issue with IOSurfaces constantly being recreated during regular (non resizing) repaints when using platform views.

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

Fixes flutter/flutter#96668
Fixes flutter/flutter#113785

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

  • 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.

@knopp knopp force-pushed the macos_rendering_refactor branch 2 times, most recently from 296fc00 to 3bc00c7 Compare November 20, 2022 20:27
@knopp knopp force-pushed the macos_rendering_refactor branch 4 times, most recently from d368c3d to d949242 Compare November 21, 2022 12:50
@knopp knopp changed the title WIP: [macos] Refactor rendering process [macos] Refactor rendering process Nov 21, 2022
@knopp knopp force-pushed the macos_rendering_refactor branch from e4afa28 to 1881f57 Compare November 21, 2022 16:43
@flutter-dashboard

This comment was marked as outdated.

@knopp knopp force-pushed the macos_rendering_refactor branch from c7a3ad9 to 1c7d550 Compare November 21, 2022 17:40
@knopp knopp changed the title [macos] Refactor rendering process [macOS] Refactor rendering process Nov 21, 2022
@knopp knopp changed the title [macOS] Refactor rendering process [macOS] Refactor rendering infrastructure Nov 21, 2022
@knopp
Copy link
Member Author

knopp commented Nov 21, 2022

I updated @iskakaushik's platform view example if anyone wants to test platform views:

https://github.com/knopp/flutter_macos_platform_view_example

platform.view.example.mov

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks OK to me, but I don't have enough knowledge to make the final approval.

@knopp knopp force-pushed the macos_rendering_refactor branch 2 times, most recently from 6accd38 to 50a9413 Compare November 25, 2022 16:45
@knopp knopp force-pushed the macos_rendering_refactor branch from cb2b42f to 3d68042 Compare November 30, 2022 12:00
Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this is a really nice cleanup. Almost all of my comments are nitpicks.

Sending first round of comments. Still looking at FlutterSurfaceManager and FlutterThreadManager.

@skia-gold
Copy link

Gold has detected about 2 new digest(s) on patchset 8.
View them at https://flutter-engine-gold.skia.org/cl/github/37789

@knopp knopp force-pushed the macos_rendering_refactor branch from beb61ac to 768aca8 Compare December 13, 2022 19:12
Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM stamp from a Japanese personal seal

🎉🎉🎉

@knopp knopp merged commit 6cd8561 into flutter:main Dec 14, 2022
@knopp knopp deleted the macos_rendering_refactor branch December 14, 2022 19:41
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 14, 2022
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Dec 15, 2022
…117109)

* 1a1b1feee Roll Skia from 537e1e8c1ca6 to 729ccbfb87bc (7 revisions) (flutter/engine#38277)

* 3b18821e1 Roll Fuchsia Linux SDK from A0jnUUORf2LQu1z2V... to e2lfUFBW5ddtTZBbw... (flutter/engine#38280)

* beb94ea2c Roll Skia from 729ccbfb87bc to 3171deabd88a (4 revisions) (flutter/engine#38279)

* 8f9071ab9 Roll Fuchsia Mac SDK from FQQdl8AGAsALFniHl... to u-tC0QEGUT4xQ4KOo... (flutter/engine#38282)

* aa78cd8d6 add link to website (flutter/engine#38273)

* 955447b35 pylint all Python scripts under testing/ (flutter/engine#38268)

* 3f22e1958 [web] correct float count in runtime effect (flutter/engine#38288)

* 479bb736f Fix issues related to keyboard inset (flutter/engine#37719)

* 6cd85616b [macOS] Refactor rendering infrastructure (flutter/engine#37789)

* d1533d12b [web] Make Canvaskit's malloc more useful (flutter/engine#38130)

* db5605ea7 Fix new `unnecessary_parenthesis` diagnostics. (flutter/engine#38291)
CaseyHillers added a commit that referenced this pull request Dec 15, 2022
loic-sharma pushed a commit to loic-sharma/flutter-engine that referenced this pull request Dec 16, 2022
* [macos] Refactor rendering process

* Put includes and imports together

* Update shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm

Co-authored-by: Chris Bracken <[email protected]>

* Remove cast

* Do not manually add platform view layer to FlutterView

* Remove unnecesary _Internal header files

* Make surfaceManager a readonly property

* Add comment

* Style nit: Rewrite as a noun phrase.

* Naming nit for consistency with removeSurfaceForSize:

* Write as ternary conditional.

* Fix plural in comment.

* Offset and index are already set to 0.

* Remove FlutterSurfaceManager lookupSurface

And the associate bookkeeping of borrowed (lent) surfaces.

* Update shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManagerTest.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManagerTest.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManagerTest.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h

Co-authored-by: Chris Bracken <[email protected]>

* Fix build error

* Address nits

* Replace EVent with fml::AutoResetWaitableEvent

* Remove unecessary CATransaction

* Add GetRequiredFrameSize

Co-authored-by: Chris Bracken <[email protected]>
loic-sharma pushed a commit to loic-sharma/flutter-engine that referenced this pull request Jan 3, 2023
* [macos] Refactor rendering process

* Put includes and imports together

* Update shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm

Co-authored-by: Chris Bracken <[email protected]>

* Remove cast

* Do not manually add platform view layer to FlutterView

* Remove unnecesary _Internal header files

* Make surfaceManager a readonly property

* Add comment

* Style nit: Rewrite as a noun phrase.

* Naming nit for consistency with removeSurfaceForSize:

* Write as ternary conditional.

* Fix plural in comment.

* Offset and index are already set to 0.

* Remove FlutterSurfaceManager lookupSurface

And the associate bookkeeping of borrowed (lent) surfaces.

* Update shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManagerTest.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManagerTest.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManagerTest.mm

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h

Co-authored-by: Chris Bracken <[email protected]>

* Update shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h

Co-authored-by: Chris Bracken <[email protected]>

* Fix build error

* Address nits

* Replace EVent with fml::AutoResetWaitableEvent

* Remove unecessary CATransaction

* Add GetRequiredFrameSize

Co-authored-by: Chris Bracken <[email protected]>
gspencergoog pushed a commit to gspencergoog/flutter that referenced this pull request Jan 19, 2023
…lutter#117109)

* 1a1b1feee Roll Skia from 537e1e8c1ca6 to 729ccbfb87bc (7 revisions) (flutter/engine#38277)

* 3b18821e1 Roll Fuchsia Linux SDK from A0jnUUORf2LQu1z2V... to e2lfUFBW5ddtTZBbw... (flutter/engine#38280)

* beb94ea2c Roll Skia from 729ccbfb87bc to 3171deabd88a (4 revisions) (flutter/engine#38279)

* 8f9071ab9 Roll Fuchsia Mac SDK from FQQdl8AGAsALFniHl... to u-tC0QEGUT4xQ4KOo... (flutter/engine#38282)

* aa78cd8d6 add link to website (flutter/engine#38273)

* 955447b35 pylint all Python scripts under testing/ (flutter/engine#38268)

* 3f22e1958 [web] correct float count in runtime effect (flutter/engine#38288)

* 479bb736f Fix issues related to keyboard inset (flutter/engine#37719)

* 6cd85616b [macOS] Refactor rendering infrastructure (flutter/engine#37789)

* d1533d12b [web] Make Canvaskit's malloc more useful (flutter/engine#38130)

* db5605ea7 Fix new `unnecessary_parenthesis` diagnostics. (flutter/engine#38291)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[macOS] Rendering an empty scene after a scene with content does not clear old content. [macos] Platform views must be mutated on Main thread
5 participants