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

Commit c7a3ad9

Browse files
committed
Reenable the FlutterEngine.Compositor test
1 parent 1881f57 commit c7a3ad9

7 files changed

+66
-18
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@
7979
void FlutterCompositor::PresentPlatformView(FlutterView* default_base_view,
8080
const FlutterLayer* layer,
8181
size_t layer_position) {
82-
// TODO (https://github.com/flutter/flutter/issues/96668)
83-
// once the issue is fixed, this check will pass.
8482
FML_DCHECK([[NSThread currentThread] isMainThread])
8583
<< "Must be on the main thread to present platform views";
8684

@@ -94,6 +92,7 @@
9492
layer->size.width / scale, layer->size.height / scale);
9593
if (platform_view.superview == nil) {
9694
[default_base_view addSubview:platform_view];
95+
[default_base_view.layer addSublayer:platform_view.layer];
9796
}
9897
platform_view.layer.zPosition = layer_position;
9998
}

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

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ @interface FlutterEngine (Test)
3030
@property(nonatomic, readonly, nullable) flutter::FlutterCompositor* macOSCompositor;
3131
@end
3232

33+
@interface TestPlatformViewFactory : NSObject <FlutterPlatformViewFactory>
34+
@end
35+
36+
@implementation TestPlatformViewFactory
37+
- (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable id)args {
38+
if (viewId == 42) {
39+
return [[NSView alloc] init];
40+
} else {
41+
return nil;
42+
}
43+
}
44+
45+
@end
46+
3347
namespace flutter::testing {
3448

3549
TEST_F(FlutterEngineTest, CanLaunch) {
@@ -447,9 +461,7 @@ @interface FlutterEngine (Test)
447461
ASSERT_TRUE(latch_called);
448462
}
449463

450-
#if 0
451-
// TODO(iskakaushik): Enable after https://github.com/flutter/flutter/issues/96668 is fixed.
452-
TEST(FlutterEngine, DISABLED_Compositor) {
464+
TEST(FlutterEngine, Compositor) {
453465
NSString* fixtures = @(flutter::testing::GetFixturesPath());
454466
FlutterDartProject* project = [[FlutterDartProject alloc]
455467
initWithAssetsPath:fixtures
@@ -463,27 +475,28 @@ @interface FlutterEngine (Test)
463475

464476
EXPECT_TRUE([engine runWithEntrypoint:@"canCompositePlatformViews"]);
465477

466-
// Latch to ensure the entire layer tree has been generated and presented.
467-
fml::AutoResetWaitableEvent latch;
468-
auto compositor = engine.macOSCompositor;
469-
compositor->SetPresentCallback([&](bool has_flutter_content) {
470-
latch.Signal();
471-
return true;
472-
});
473-
latch.Wait();
478+
[engine.platformViewController registerViewFactory:[[TestPlatformViewFactory alloc] init]
479+
withId:@"factory_id"];
480+
[engine.platformViewController
481+
handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"create"
482+
arguments:@{
483+
@"id" : @(42),
484+
@"viewType" : @"factory_id",
485+
}]
486+
result:^(id result){
487+
}];
488+
489+
[viewController.flutterView.threadSynchronizer blockUntilFrameAvailable];
474490

475491
CALayer* rootLayer = viewController.flutterView.layer;
476492

477493
// There are three layers total - the root layer and two sublayers.
478-
// This test will need to be updated when PlatformViews are supported, as
479-
// there are two PlatformView layers in this test.
480-
EXPECT_EQ(rootLayer.sublayers.count, 2u);
494+
EXPECT_EQ(rootLayer.sublayers.count, 3u);
481495

482496
// TODO(gw280): add support for screenshot tests in this test harness
483497

484498
[engine shutDownEngine];
485-
}
486-
#endif
499+
} // namespace flutter::testing
487500

488501
TEST(FlutterEngine, DartEntrypointArguments) {
489502
NSString* fixtures = @(flutter::testing::GetFixturesPath());

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ - (void)onCreateWithViewID:(int64_t)viewId
5353
}
5454

5555
NSView* platform_view = [factory createWithViewIdentifier:viewId arguments:nil];
56+
// Force view to be layer-backed.
57+
[platform_view setWantsLayer:YES];
5658
_platformViews[viewId] = platform_view;
5759
result(nil);
5860
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
*/
66
@interface FlutterThreadSynchronizer : NSObject
77

8+
/**
9+
* Blocks current thread until there is frame available.
10+
* Used in FlutterEngineTest.
11+
*/
12+
- (void)blockUntilFrameAvailable;
13+
814
/**
915
* Called from platform thread. Blocks until commit with given size (or empty)
1016
* is requested.

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ - (void)drain {
5656
_scheduledBlocks.clear();
5757
}
5858

59+
- (void)blockUntilFrameAvailable {
60+
std::unique_lock<std::mutex> lock(_mutex);
61+
62+
_beginResizeWaiting = YES;
63+
64+
while (CGSizeEqualToSize(_contentSize, CGSizeZero) && !_shuttingDown) {
65+
_condBlockBeginResize.wait(lock);
66+
[self drain];
67+
}
68+
69+
_beginResizeWaiting = NO;
70+
}
71+
5972
- (void)beginResize:(CGSize)size notify:(nonnull dispatch_block_t)notify {
6073
std::unique_lock<std::mutex> lock(_mutex);
6174

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#import <Cocoa/Cocoa.h>
66

77
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
8+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.h"
89

910
#include <stdint.h>
1011

@@ -71,3 +72,13 @@ constexpr uint64_t kFlutterDefaultViewId = 0;
7172
- (void)setBackgroundColor:(nonnull NSColor*)color;
7273

7374
@end
75+
76+
@interface FlutterView (FlutterViewPrivate)
77+
78+
/**
79+
* Returns FlutterThreadSynchronizer for this view.
80+
* Used for FlutterEngineTest.
81+
*/
82+
- (nonnull FlutterThreadSynchronizer*)threadSynchronizer;
83+
84+
@end

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ - (FlutterSurfaceManager*)surfaceManager {
4545
return _surfaceManager;
4646
}
4747

48+
- (FlutterThreadSynchronizer*)threadSynchronizer {
49+
return _threadSynchronizer;
50+
}
51+
4852
- (void)reshaped {
4953
CGSize scaledSize = [self convertSizeToBacking:self.bounds.size];
5054
[_threadSynchronizer beginResize:scaledSize

0 commit comments

Comments
 (0)