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

Commit 78cecee

Browse files
Reverts "Reland: [macOS] Use CVDisplayLink to drive repaint (#51126)" (#51192)
Reverts #51126 Initiated by: cbracken Reason for reverting: looks like this regressed Skia benchmarks: https://flutter-flutter-perf.skia.org/e/?keys=Xbf8dce9c233bce34d20e2280e3f1d8db&selected=commit%3D39653%26name%3D%2Carch%3Dintel%2Cbranch%3Dmaster%2Cconfig%3Ddefault%2Cdevice_type%3Dnone%2Cdevice_version%3Dnone%2Chost_type%3Dmac%2Csub_result%3DtimeToFirstFrameRasterizedMicros%2Ctest%3Dflutter_gallery_macos__start_up%2C&xbaroffset=39569 The regression s Original PR Author: knopp Reviewed By: {cbracken} This change reverts the following previous change: Original Description: This relands the PR reverted in #51095 Changes since the original PR: - The macOS embedder does not assume particular clock when calling the embedder API, but converts CAMediaTime to engine time and back (`FlutterTimeConverter`) - `FlutterVSyncWaiter` does not wait for displaylink callback during warmup frame. This should prevent `timeToFirstFrameRasterizedMicros` regressions. - When enforcing frame pacing the raster thread is not blocked. This should prevent `average_frame_rasterizer_time_millis` regressions. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 6250b9f commit 78cecee

29 files changed

+102
-1349
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36597,7 +36597,6 @@ ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCom
3659736597
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm + ../../../flutter/LICENSE
3659836598
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm + ../../../flutter/LICENSE
3659936599
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h + ../../../flutter/LICENSE
36600-
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLinkTest.mm + ../../../flutter/LICENSE
3660136600
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm + ../../../flutter/LICENSE
3660236601
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.h + ../../../flutter/LICENSE
3660336602
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.mm + ../../../flutter/LICENSE
@@ -36647,10 +36646,7 @@ ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTex
3664736646
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.h + ../../../flutter/LICENSE
3664836647
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm + ../../../flutter/LICENSE
3664936648
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizerTest.mm + ../../../flutter/LICENSE
36650-
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTimeConverter.h + ../../../flutter/LICENSE
36651-
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTimeConverter.mm + ../../../flutter/LICENSE
3665236649
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterUmbrellaImportTests.m + ../../../flutter/LICENSE
36653-
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiterTest.mm + ../../../flutter/LICENSE
3665436650
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h + ../../../flutter/LICENSE
3665536651
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm + ../../../flutter/LICENSE
3665636652
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm + ../../../flutter/LICENSE
@@ -39471,9 +39467,6 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompo
3947139467
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm
3947239468
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm
3947339469
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h
39474-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLink.h
39475-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLink.mm
39476-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLinkTest.mm
3947739470
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm
3947839471
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.h
3947939472
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.mm
@@ -39523,12 +39516,7 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTextu
3952339516
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.h
3952439517
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm
3952539518
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizerTest.mm
39526-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTimeConverter.h
39527-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTimeConverter.mm
3952839519
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterUmbrellaImportTests.m
39529-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiter.h
39530-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiter.mm
39531-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiterTest.mm
3953239520
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h
3953339521
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm
3953439522
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm

shell/platform/darwin/macos/BUILD.gn

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ source_set("flutter_framework_source") {
6666
"framework/Source/FlutterCompositor.mm",
6767
"framework/Source/FlutterDartProject.mm",
6868
"framework/Source/FlutterDartProject_Internal.h",
69-
"framework/Source/FlutterDisplayLink.h",
70-
"framework/Source/FlutterDisplayLink.mm",
7169
"framework/Source/FlutterEmbedderKeyResponder.h",
7270
"framework/Source/FlutterEmbedderKeyResponder.mm",
7371
"framework/Source/FlutterEngine.mm",
@@ -103,10 +101,6 @@ source_set("flutter_framework_source") {
103101
"framework/Source/FlutterTextureRegistrar.mm",
104102
"framework/Source/FlutterThreadSynchronizer.h",
105103
"framework/Source/FlutterThreadSynchronizer.mm",
106-
"framework/Source/FlutterTimeConverter.h",
107-
"framework/Source/FlutterTimeConverter.mm",
108-
"framework/Source/FlutterVSyncWaiter.h",
109-
"framework/Source/FlutterVSyncWaiter.mm",
110104
"framework/Source/FlutterView.h",
111105
"framework/Source/FlutterView.mm",
112106
"framework/Source/FlutterViewController.mm",
@@ -179,7 +173,6 @@ executable("flutter_desktop_darwin_unittests") {
179173
"framework/Source/FlutterAppDelegateTest.mm",
180174
"framework/Source/FlutterAppLifecycleDelegateTest.mm",
181175
"framework/Source/FlutterChannelKeyResponderTest.mm",
182-
"framework/Source/FlutterDisplayLinkTest.mm",
183176
"framework/Source/FlutterEmbedderExternalTextureTest.mm",
184177
"framework/Source/FlutterEmbedderKeyResponderTest.mm",
185178
"framework/Source/FlutterEngineTest.mm",
@@ -194,7 +187,6 @@ executable("flutter_desktop_darwin_unittests") {
194187
"framework/Source/FlutterTextInputPluginTest.mm",
195188
"framework/Source/FlutterTextInputSemanticsObjectTest.mm",
196189
"framework/Source/FlutterThreadSynchronizerTest.mm",
197-
"framework/Source/FlutterVSyncWaiterTest.mm",
198190
"framework/Source/FlutterViewControllerTest.mm",
199191
"framework/Source/FlutterViewControllerTestUtils.h",
200192
"framework/Source/FlutterViewControllerTestUtils.mm",

shell/platform/darwin/macos/framework/Source/FlutterCompositor.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010

1111
#include "flutter/fml/macros.h"
1212
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController.h"
13-
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTimeConverter.h"
1413
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h"
1514
#include "flutter/shell/platform/embedder/embedder.h"
1615

1716
@class FlutterMutatorView;
1817

1918
namespace flutter {
2019

21-
class PlatformViewLayer;
22-
23-
typedef std::pair<PlatformViewLayer, size_t> PlatformViewLayerWithIndex;
24-
2520
// FlutterCompositor creates and manages the backing stores used for
2621
// rendering Flutter content and presents Flutter content and Platform views.
2722
// Platform views are not yet supported.
@@ -35,7 +30,6 @@ class FlutterCompositor {
3530
// which are used for presenting and creating backing stores.
3631
// It must not be null, and is typically FlutterViewEngineProvider.
3732
explicit FlutterCompositor(id<FlutterViewProvider> view_provider,
38-
FlutterTimeConverter* time_converter,
3933
FlutterPlatformViewController* platform_views_controller);
4034

4135
~FlutterCompositor() = default;
@@ -61,21 +55,19 @@ class FlutterCompositor {
6155

6256
private:
6357
void PresentPlatformViews(FlutterView* default_base_view,
64-
const std::vector<PlatformViewLayerWithIndex>& platform_views_layers);
58+
const FlutterLayer** layers,
59+
size_t layers_count);
6560

6661
// Presents the platform view layer represented by `layer`. `layer_index` is
6762
// used to position the layer in the z-axis. If the layer does not have a
6863
// superview, it will become subview of `default_base_view`.
6964
FlutterMutatorView* PresentPlatformView(FlutterView* default_base_view,
70-
const PlatformViewLayer& layer,
71-
size_t index);
65+
const FlutterLayer* layer,
66+
size_t layer_position);
7267

7368
// Where the compositor can query FlutterViews. Must not be null.
7469
id<FlutterViewProvider> const view_provider_;
7570

76-
// Converts between engine time and core animation media time.
77-
FlutterTimeConverter* const time_converter_;
78-
7971
// The controller used to manage creation and deletion of platform views.
8072
const FlutterPlatformViewController* platform_view_controller_;
8173

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

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,9 @@
99

1010
namespace flutter {
1111

12-
namespace {
13-
std::vector<PlatformViewLayerWithIndex> CopyPlatformViewLayers(const FlutterLayer** layers,
14-
size_t layer_count) {
15-
std::vector<PlatformViewLayerWithIndex> platform_views;
16-
for (size_t i = 0; i < layer_count; i++) {
17-
if (layers[i]->type == kFlutterLayerContentTypePlatformView) {
18-
platform_views.push_back(std::make_pair(PlatformViewLayer(layers[i]), i));
19-
}
20-
}
21-
return platform_views;
22-
}
23-
} // namespace
24-
2512
FlutterCompositor::FlutterCompositor(id<FlutterViewProvider> view_provider,
26-
FlutterTimeConverter* time_converter,
2713
FlutterPlatformViewController* platform_view_controller)
2814
: view_provider_(view_provider),
29-
time_converter_(time_converter),
3015
platform_view_controller_(platform_view_controller),
3116
mutator_views_([NSMapTable strongToStrongObjectsMapTable]) {
3217
FML_CHECK(view_provider != nullptr) << "view_provider cannot be nullptr";
@@ -84,38 +69,28 @@
8469
}
8570
}
8671

87-
CFTimeInterval presentation_time = 0;
88-
89-
if (layers_count > 0 && layers[0]->presentation_time != 0) {
90-
presentation_time = [time_converter_ engineTimeToCAMediaTime:layers[0]->presentation_time];
91-
}
92-
93-
// Notify block below may be called asynchronously, hence the need to copy
94-
// the layer information instead of passing the original pointers from embedder.
95-
auto platform_views_layers = std::make_shared<std::vector<PlatformViewLayerWithIndex>>(
96-
CopyPlatformViewLayers(layers, layers_count));
97-
98-
[view.surfaceManager presentSurfaces:surfaces
99-
atTime:presentation_time
100-
notify:^{
101-
PresentPlatformViews(view, *platform_views_layers);
102-
}];
72+
[view.surfaceManager present:surfaces
73+
notify:^{
74+
PresentPlatformViews(view, layers, layers_count);
75+
}];
10376

10477
return true;
10578
}
10679

107-
void FlutterCompositor::PresentPlatformViews(
108-
FlutterView* default_base_view,
109-
const std::vector<PlatformViewLayerWithIndex>& platform_views) {
80+
void FlutterCompositor::PresentPlatformViews(FlutterView* default_base_view,
81+
const FlutterLayer** layers,
82+
size_t layers_count) {
11083
FML_DCHECK([[NSThread currentThread] isMainThread])
11184
<< "Must be on the main thread to present platform views";
11285

11386
// Active mutator views for this frame.
11487
NSMutableArray<FlutterMutatorView*>* present_mutators = [NSMutableArray array];
11588

116-
for (const auto& platform_view : platform_views) {
117-
[present_mutators addObject:PresentPlatformView(default_base_view, platform_view.first,
118-
platform_view.second)];
89+
for (size_t i = 0; i < layers_count; i++) {
90+
FlutterLayer* layer = (FlutterLayer*)layers[i];
91+
if (layer->type == kFlutterLayerContentTypePlatformView) {
92+
[present_mutators addObject:PresentPlatformView(default_base_view, layer, i)];
93+
}
11994
}
12095

12196
NSMutableArray<FlutterMutatorView*>* obsolete_mutators =
@@ -131,12 +106,12 @@
131106
}
132107

133108
FlutterMutatorView* FlutterCompositor::PresentPlatformView(FlutterView* default_base_view,
134-
const PlatformViewLayer& layer,
135-
size_t index) {
109+
const FlutterLayer* layer,
110+
size_t layer_position) {
136111
FML_DCHECK([[NSThread currentThread] isMainThread])
137112
<< "Must be on the main thread to present platform views";
138113

139-
int64_t platform_view_id = layer.identifier();
114+
int64_t platform_view_id = layer->platform_view->identifier;
140115
NSView* platform_view = [platform_view_controller_ platformViewWithID:platform_view_id];
141116

142117
FML_DCHECK(platform_view) << "Platform view not found for id: " << platform_view_id;
@@ -149,8 +124,8 @@
149124
[default_base_view addSubview:container];
150125
}
151126

152-
container.layer.zPosition = index;
153-
[container applyFlutterLayer:&layer];
127+
container.layer.zPosition = layer_position;
128+
[container applyFlutterLayer:layer];
154129

155130
return container;
156131
}

shell/platform/darwin/macos/framework/Source/FlutterDisplayLink.h

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)