Skip to content

Commit ca7bea9

Browse files
authored
iOS: Eliminate use of IOSContextNoop in platform view tests (flutter#190419)
`FlutterPlatformViewsTest` used the internal engine class `flutter::IOSContextNoop` in a dozen places purely as a no-op context to hand to `submitFrame:withIosContext:`. This replaces those with a local `FakeIOSContext` that replicates the behaviour the tests rely on so that we can delete `IOSContextNoop` in a follow-up. Like `IOSContextNoop` `FakeIOSContext` reports the Impeller backend and returns no external texture, and inherits the null Impeller/Aiks contexts from the base class. The one place that uses the engine's real context (`GetIosContext`) is left untouched. I suspect we can eventually move this code to use the real Metal backend but for now, this is just refactoring with no semantic change. Back in ancient times, before the simulator required Metal, and when iOS still had a Skia software renderer, we ran that on the Simulator due to some issues with our OpenGL implementation. Later, Flutter on iOS migrated from Skia to Impeller. Skia supports a software backend but Impeller did not, and so when running on Impeller, we stubbed out the software backend to no-op context/surfaces, hence IOSContextNoop and IOSSurfaceNoop. The Simulator now *requires* Metal and Flutter has eliminated Skia support altogether so there's no longer a software mode at all, nor a need for a no-op path in case you're using Impeller and ask for a software backend. This is part of a series of changes to remove the dead no-op fallback. No behavioural change; just a test refactoring. Issue: flutter#190041 <!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent b29df1d commit ca7bea9

1 file changed

Lines changed: 42 additions & 29 deletions

File tree

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm‎

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,32 @@
2626
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTestHelper.h"
2727
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
2828
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTouchInterceptingView+Test.h"
29-
#include "flutter/shell/platform/darwin/ios/ios_context_noop.h"
29+
#include "flutter/shell/platform/darwin/ios/ios_context.h"
3030
#include "flutter/shell/platform/darwin/ios/platform_view_ios.h"
3131

3232
FLUTTER_ASSERT_ARC
3333

34+
namespace {
35+
// An IOSContext fake for tests that do not need a real GPU context.
36+
class FakeIOSContext : public flutter::IOSContext {
37+
public:
38+
FakeIOSContext() = default;
39+
~FakeIOSContext() override = default;
40+
41+
// |IOSContext|
42+
flutter::IOSRenderingBackend GetBackend() const override {
43+
return flutter::IOSRenderingBackend::kImpeller;
44+
}
45+
46+
// |IOSContext|
47+
std::unique_ptr<flutter::Texture> CreateExternalTexture(
48+
int64_t texture_id,
49+
NSObject<FlutterTexture>* texture) override {
50+
return nullptr;
51+
}
52+
};
53+
} // namespace
54+
3455
@class FlutterPlatformViewsTestMockPlatformView;
3556
__weak static UIView* gMockPlatformView = nil;
3657
const float kFloatCompareEpsilon = 0.001;
@@ -4225,9 +4246,8 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin
42254246
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return false; },
42264247
[](const flutter::SurfaceFrame& surface_frame) { return true; },
42274248
/*frame_size=*/flutter::DlISize(800, 600));
4228-
XCTAssertFalse([flutterPlatformViewsController
4229-
submitFrame:std::move(mock_surface)
4230-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
4249+
XCTAssertFalse([flutterPlatformViewsController submitFrame:std::move(mock_surface)
4250+
withIosContext:std::make_shared<FakeIOSContext>()]);
42314251

42324252
auto embeddedViewParams_2 =
42334253
std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, flutter::DlSize(300, 300), stack);
@@ -4242,9 +4262,8 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin
42424262
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
42434263
[](const flutter::SurfaceFrame& surface_frame) { return true; },
42444264
/*frame_size=*/flutter::DlISize(800, 600));
4245-
XCTAssertTrue([flutterPlatformViewsController
4246-
submitFrame:std::move(mock_surface_submit_true)
4247-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
4265+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface_submit_true)
4266+
withIosContext:std::make_shared<FakeIOSContext>()]);
42484267
}
42494268

42504269
- (void)
@@ -4431,9 +4450,8 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
44314450
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
44324451
[](const flutter::SurfaceFrame& surface_frame) { return true; },
44334452
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
4434-
XCTAssertTrue([flutterPlatformViewsController
4435-
submitFrame:std::move(mock_surface)
4436-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
4453+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
4454+
withIosContext:std::make_shared<FakeIOSContext>()]);
44374455

44384456
// platform view is wrapped by touch interceptor, which itself is wrapped by clipping view.
44394457
UIView* clippingView1 = view1.superview.superview;
@@ -4460,9 +4478,8 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
44604478
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
44614479
[](const flutter::SurfaceFrame& surface_frame) { return true; },
44624480
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
4463-
XCTAssertTrue([flutterPlatformViewsController
4464-
submitFrame:std::move(mock_surface)
4465-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
4481+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
4482+
withIosContext:std::make_shared<FakeIOSContext>()]);
44664483

44674484
XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] >
44684485
[flutterView.subviews indexOfObject:clippingView2],
@@ -4535,9 +4552,8 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
45354552
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
45364553
[](const flutter::SurfaceFrame& surface_frame) { return true; },
45374554
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
4538-
XCTAssertTrue([flutterPlatformViewsController
4539-
submitFrame:std::move(mock_surface)
4540-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
4555+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
4556+
withIosContext:std::make_shared<FakeIOSContext>()]);
45414557

45424558
// platform view is wrapped by touch interceptor, which itself is wrapped by clipping view.
45434559
UIView* clippingView1 = view1.superview.superview;
@@ -4564,9 +4580,8 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
45644580
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
45654581
[](const flutter::SurfaceFrame& surface_frame) { return true; },
45664582
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
4567-
XCTAssertTrue([flutterPlatformViewsController
4568-
submitFrame:std::move(mock_surface)
4569-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
4583+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
4584+
withIosContext:std::make_shared<FakeIOSContext>()]);
45704585

45714586
XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
45724587
[flutterView.subviews indexOfObject:clippingView2],
@@ -5015,9 +5030,8 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash {
50155030
[](const flutter::SurfaceFrame& surface_frame) { return true; },
50165031
/*frame_size=*/flutter::DlISize(800, 600), nullptr,
50175032
/*display_list_fallback=*/true);
5018-
XCTAssertTrue([flutterPlatformViewsController
5019-
submitFrame:std::move(mock_surface)
5020-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
5033+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
5034+
withIosContext:std::make_shared<FakeIOSContext>()]);
50215035

50225036
// Disposing won't remove embedded views until the view is removed from the composition_order_
50235037
XCTAssertEqual(flutterPlatformViewsController.embeddedViewCount, 2UL);
@@ -5042,9 +5056,8 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash {
50425056
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
50435057
[](const flutter::SurfaceFrame& surface_frame) { return true; },
50445058
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
5045-
XCTAssertTrue([flutterPlatformViewsController
5046-
submitFrame:std::move(mock_surface)
5047-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
5059+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
5060+
withIosContext:std::make_shared<FakeIOSContext>()]);
50485061

50495062
// Disposing won't remove embedded views until the view is removed from the composition_order_
50505063
XCTAssertEqual(flutterPlatformViewsController.embeddedViewCount, 1UL);
@@ -5108,7 +5121,7 @@ - (void)testOnlyPlatformViewsAreRemovedWhenReset {
51085121
[](const flutter::SurfaceFrame& surface_frame) { return true; },
51095122
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
51105123
[flutterPlatformViewsController submitFrame:std::move(mock_surface)
5111-
withIosContext:std::make_shared<flutter::IOSContextNoop>()];
5124+
withIosContext:std::make_shared<FakeIOSContext>()];
51125125

51135126
UIView* someView = [[UIView alloc] init];
51145127
[flutterView addSubview:someView];
@@ -5174,7 +5187,7 @@ - (void)testResetClearsPreviousCompositionOrder {
51745187
[](const flutter::SurfaceFrame& surface_frame) { return true; },
51755188
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
51765189
[flutterPlatformViewsController submitFrame:std::move(mock_surface)
5177-
withIosContext:std::make_shared<flutter::IOSContextNoop>()];
5190+
withIosContext:std::make_shared<FakeIOSContext>()];
51785191

51795192
// The above code should result in previousCompositionOrder having one viewId in it
51805193
XCTAssertEqual(flutterPlatformViewsController.previousCompositionOrder.count, 1ul);
@@ -5243,7 +5256,7 @@ - (void)testNilPlatformViewDoesntCrash {
52435256
[](const flutter::SurfaceFrame& surface_frame) { return true; },
52445257
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
52455258
[flutterPlatformViewsController submitFrame:std::move(mock_surface)
5246-
withIosContext:std::make_shared<flutter::IOSContextNoop>()];
5259+
withIosContext:std::make_shared<FakeIOSContext>()];
52475260

52485261
XCTAssertEqual(flutterView.subviews.count, 1u);
52495262
}
@@ -5354,7 +5367,7 @@ - (void)testFlutterPlatformViewControllerSubmitFramePreservingFrameDamage {
53545367
});
53555368

53565369
[flutterPlatformViewsController submitFrame:std::move(mock_surface)
5357-
withIosContext:std::make_shared<flutter::IOSContextNoop>()];
5370+
withIosContext:std::make_shared<FakeIOSContext>()];
53585371

53595372
XCTAssertTrue(submit_info.has_value());
53605373
XCTAssertEqual(*submit_info->frame_damage, flutter::DlIRect::MakeWH(800, 600));

0 commit comments

Comments
 (0)