Skip to content

Commit

Permalink
Migration to PlatformDispatcher and multi-window (flutter#20496)
Browse files Browse the repository at this point in the history
This is a PR for converting the dart:ui code in the engine to use a multi-window API. The goal here is to convert from the window singleton to an API that has the concept of multiple windows. Also, I'm matching up the new PlatformDispatcher class to talk directly to the PlatformConfiguration class in the engine. I'm not attempting to actually enable creating multiple windows here, just migrate to an API that has a concept of multiple windows. The multi-window API in this PR currently only ever creates one window.

The design doc for this change is here.

The major changes in this PR:

Move the platfom-specific attributes out of Window, and into the new PlatformDispatcher class that holds all of the platform state, so that the platform code need only update the configuration on this class.
Create FlutterView, FlutterWindow, and SingletonFlutterWindow classes to separate out the concepts of a view (of which there may be multiple in a window), a window (of which there may be multiple on a screen, and they host views), and a window where there is only ever expected to be one (this hosts the entire API of the former Window class, and will eventually be the type of the window singleton).
Next step after this PR lands:

Remove the Window class entirely (it is replaced by SingletonFlutterWindow). Some minor changes in the Framework are needed to switch to using SingletonFlutterWindow directly first.

The Window class still exists in this PR, but will be removed as soon as the framework is converted to point to the SingletonFlutterWindow class instead. They share the same API, just have different names (Window is currently a subclass of SingletonFlutterWindow). The intention is that the Window name will be freed up to use as a widget class name in the framework for managing windows. The singleton called window will remain, and keep the same API it has now.
  • Loading branch information
gspencergoog authored Oct 9, 2020
1 parent 11d756a commit 85b0031
Show file tree
Hide file tree
Showing 73 changed files with 4,066 additions and 2,546 deletions.
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ FILE: ../../../flutter/lib/ui/painting/single_frame_codec.h
FILE: ../../../flutter/lib/ui/painting/vertices.cc
FILE: ../../../flutter/lib/ui/painting/vertices.h
FILE: ../../../flutter/lib/ui/painting/vertices_unittests.cc
FILE: ../../../flutter/lib/ui/platform_dispatcher.dart
FILE: ../../../flutter/lib/ui/plugins.dart
FILE: ../../../flutter/lib/ui/plugins/callback_cache.cc
FILE: ../../../flutter/lib/ui/plugins/callback_cache.h
Expand Down Expand Up @@ -499,6 +500,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/keyboard.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/mouse_cursor.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/onscreen_logging.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/picture.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/platform_views.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/plugins.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/pointer_binding.dart
Expand Down Expand Up @@ -553,6 +555,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/ui/natives.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/painting.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/path.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/path_metrics.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/platform_dispatcher.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/pointer.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/semantics.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/test_embedding.dart
Expand Down
22 changes: 11 additions & 11 deletions lib/ui/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ part of dart.ui;
///
/// To create a Scene object, use a [SceneBuilder].
///
/// Scene objects can be displayed on the screen using the
/// [Window.render] method.
/// Scene objects can be displayed on the screen using the [FlutterView.render]
/// method.
@pragma('vm:entry-point')
class Scene extends NativeFieldWrapperClass2 {
/// This class is created by the engine, and should not be instantiated
Expand Down Expand Up @@ -186,7 +186,7 @@ class PhysicalShapeEngineLayer extends _EngineLayerWrapper {

/// Builds a [Scene] containing the given visuals.
///
/// A [Scene] can then be rendered using [Window.render].
/// A [Scene] can then be rendered using [FlutterView.render].
///
/// To draw graphical operations onto a [Scene], first create a
/// [Picture] using a [PictureRecorder] and a [Canvas], and then add
Expand Down Expand Up @@ -655,13 +655,13 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
/// - 0x08: visualizeEngineStatistics - graph UI thread frame times
/// Set enabledOptions to 0x0F to enable all the currently defined features.
///
/// The "UI thread" is the thread that includes all the execution of
/// the main Dart isolate (the isolate that can call
/// [Window.render]). The UI thread frame time is the total time
/// spent executing the [Window.onBeginFrame] callback. The "raster
/// thread" is the thread (running on the CPU) that subsequently
/// processes the [Scene] provided by the Dart code to turn it into
/// GPU commands and send it to the GPU.
/// The "UI thread" is the thread that includes all the execution of the main
/// Dart isolate (the isolate that can call [FlutterView.render]). The UI
/// thread frame time is the total time spent executing the
/// [PlatformDispatcher.onBeginFrame] callback. The "raster thread" is the
/// thread (running on the CPU) that subsequently processes the [Scene]
/// provided by the Dart code to turn it into GPU commands and send it to the
/// GPU.
///
/// See also the [PerformanceOverlayOption] enum in the rendering library.
/// for more details.
Expand Down Expand Up @@ -802,7 +802,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
///
/// Returns a [Scene] containing the objects that have been added to
/// this scene builder. The [Scene] can then be displayed on the
/// screen with [Window.render].
/// screen with [FlutterView.render].
///
/// After calling this function, the scene builder object is invalid and
/// cannot be used further.
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/compositing/scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Scene::Scene(std::shared_ptr<flutter::Layer> rootLayer,
uint32_t rasterizerTracingThreshold,
bool checkerboardRasterCacheImages,
bool checkerboardOffscreenLayers) {
// Currently only supports a single window.
auto viewport_metrics = UIDartState::Current()
->platform_configuration()
->window()
->get_window(0)
->viewport_metrics();

layer_tree_ = std::make_unique<LayerTree>(
Expand Down
1 change: 1 addition & 0 deletions lib/ui/dart_ui.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dart_ui_files = [
"//flutter/lib/ui/lerp.dart",
"//flutter/lib/ui/natives.dart",
"//flutter/lib/ui/painting.dart",
"//flutter/lib/ui/platform_dispatcher.dart",
"//flutter/lib/ui/plugins.dart",
"//flutter/lib/ui/pointer.dart",
"//flutter/lib/ui/semantics.dart",
Expand Down
Loading

0 comments on commit 85b0031

Please sign in to comment.