From f1582eec0a87e20cb91107d9f7f04a3a1604fd87 Mon Sep 17 00:00:00 2001 From: luckysmg <2539699336@qq.com> Date: Sat, 4 Feb 2023 08:49:03 +0800 Subject: [PATCH] [iOS] Ensure FlutterView's background color is not nil to avoid CAMetalLayer nextDrawable being time-consuming (flutter/engine#39359) * ++ * Add tests * ++ --- .../platform/darwin/ios/framework/Source/FlutterView.mm | 6 ++++++ .../platform/darwin/ios/framework/Source/FlutterViewTest.mm | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm index 7c188be871..dcab55d404 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -47,6 +47,12 @@ if (self) { _delegate = delegate; self.layer.opaque = opaque; + + // This line is necessary. CoreAnimation(or UIKit) may take this to do + // something to compute the final frame presented on screen, if we don't set this, + // it will make it take long time for us to take next CAMetalDrawable and will + // cause constant junk during rendering. + self.backgroundColor = UIColor.clearColor; } return self; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm index c14bee16a6..d264933b0b 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm @@ -49,4 +49,10 @@ XCTAssertTrue(delegate.callbackCalled); } +- (void)testFlutterViewBackgroundColorIsNotNil { + FakeDelegate* delegate = [[FakeDelegate alloc] init]; + FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO]; + XCTAssertNotNil(view.backgroundColor); +} + @end