Skip to content

Commit 497ab92

Browse files
authored
iOS: Eliminate use of IOSContextNoop in platform view tests (reland) (flutter#190509)
This relands flutter#190419, which I reverted in flutter#190501 because it broke the tree due to a (non-merge) conflict with flutter#190416. flutter#190419 added a local `FakeIOSContext` whose `GetBackend()` override returned `flutter::IOSRenderingBackend::kImpeller`. flutter#190416 landed immediately before it and removed the `IOSContext::GetBackend()` virtual and the `IOSRenderingBackend` enum, so the two changes had no merge conflicts but `FakeIOSContext` no longer compiled once both were in the tree. This reland is identical other than deleting the `GetBackend()` override. `FakeIOSContext` still inherits the null Impeller/Aiks contexts from the base class and returns no external texture, matching the behaviour the tests rely on. Original change: `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. 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 89b263d commit 497ab92

1 file changed

Lines changed: 37 additions & 29 deletions

File tree

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

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,27 @@
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+
std::unique_ptr<flutter::Texture> CreateExternalTexture(
43+
int64_t texture_id,
44+
NSObject<FlutterTexture>* texture) override {
45+
return nullptr;
46+
}
47+
};
48+
} // namespace
49+
3450
@class FlutterPlatformViewsTestMockPlatformView;
3551
__weak static UIView* gMockPlatformView = nil;
3652
const float kFloatCompareEpsilon = 0.001;
@@ -4225,9 +4241,8 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin
42254241
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return false; },
42264242
[](const flutter::SurfaceFrame& surface_frame) { return true; },
42274243
/*frame_size=*/flutter::DlISize(800, 600));
4228-
XCTAssertFalse([flutterPlatformViewsController
4229-
submitFrame:std::move(mock_surface)
4230-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
4244+
XCTAssertFalse([flutterPlatformViewsController submitFrame:std::move(mock_surface)
4245+
withIosContext:std::make_shared<FakeIOSContext>()]);
42314246

42324247
auto embeddedViewParams_2 =
42334248
std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, flutter::DlSize(300, 300), stack);
@@ -4242,9 +4257,8 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin
42424257
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
42434258
[](const flutter::SurfaceFrame& surface_frame) { return true; },
42444259
/*frame_size=*/flutter::DlISize(800, 600));
4245-
XCTAssertTrue([flutterPlatformViewsController
4246-
submitFrame:std::move(mock_surface_submit_true)
4247-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
4260+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface_submit_true)
4261+
withIosContext:std::make_shared<FakeIOSContext>()]);
42484262
}
42494263

42504264
- (void)
@@ -4431,9 +4445,8 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
44314445
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
44324446
[](const flutter::SurfaceFrame& surface_frame) { return true; },
44334447
/*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>()]);
4448+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
4449+
withIosContext:std::make_shared<FakeIOSContext>()]);
44374450

44384451
// platform view is wrapped by touch interceptor, which itself is wrapped by clipping view.
44394452
UIView* clippingView1 = view1.superview.superview;
@@ -4460,9 +4473,8 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
44604473
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
44614474
[](const flutter::SurfaceFrame& surface_frame) { return true; },
44624475
/*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>()]);
4476+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
4477+
withIosContext:std::make_shared<FakeIOSContext>()]);
44664478

44674479
XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] >
44684480
[flutterView.subviews indexOfObject:clippingView2],
@@ -4535,9 +4547,8 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
45354547
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
45364548
[](const flutter::SurfaceFrame& surface_frame) { return true; },
45374549
/*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>()]);
4550+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
4551+
withIosContext:std::make_shared<FakeIOSContext>()]);
45414552

45424553
// platform view is wrapped by touch interceptor, which itself is wrapped by clipping view.
45434554
UIView* clippingView1 = view1.superview.superview;
@@ -4564,9 +4575,8 @@ - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder {
45644575
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
45654576
[](const flutter::SurfaceFrame& surface_frame) { return true; },
45664577
/*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>()]);
4578+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
4579+
withIosContext:std::make_shared<FakeIOSContext>()]);
45704580

45714581
XCTAssertTrue([flutterView.subviews indexOfObject:clippingView1] <
45724582
[flutterView.subviews indexOfObject:clippingView2],
@@ -5015,9 +5025,8 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash {
50155025
[](const flutter::SurfaceFrame& surface_frame) { return true; },
50165026
/*frame_size=*/flutter::DlISize(800, 600), nullptr,
50175027
/*display_list_fallback=*/true);
5018-
XCTAssertTrue([flutterPlatformViewsController
5019-
submitFrame:std::move(mock_surface)
5020-
withIosContext:std::make_shared<flutter::IOSContextNoop>()]);
5028+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
5029+
withIosContext:std::make_shared<FakeIOSContext>()]);
50215030

50225031
// Disposing won't remove embedded views until the view is removed from the composition_order_
50235032
XCTAssertEqual(flutterPlatformViewsController.embeddedViewCount, 2UL);
@@ -5042,9 +5051,8 @@ - (void)testDisposingViewInCompositionOrderDoNotCrash {
50425051
[](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true; },
50435052
[](const flutter::SurfaceFrame& surface_frame) { return true; },
50445053
/*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>()]);
5054+
XCTAssertTrue([flutterPlatformViewsController submitFrame:std::move(mock_surface)
5055+
withIosContext:std::make_shared<FakeIOSContext>()]);
50485056

50495057
// Disposing won't remove embedded views until the view is removed from the composition_order_
50505058
XCTAssertEqual(flutterPlatformViewsController.embeddedViewCount, 1UL);
@@ -5108,7 +5116,7 @@ - (void)testOnlyPlatformViewsAreRemovedWhenReset {
51085116
[](const flutter::SurfaceFrame& surface_frame) { return true; },
51095117
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
51105118
[flutterPlatformViewsController submitFrame:std::move(mock_surface)
5111-
withIosContext:std::make_shared<flutter::IOSContextNoop>()];
5119+
withIosContext:std::make_shared<FakeIOSContext>()];
51125120

51135121
UIView* someView = [[UIView alloc] init];
51145122
[flutterView addSubview:someView];
@@ -5174,7 +5182,7 @@ - (void)testResetClearsPreviousCompositionOrder {
51745182
[](const flutter::SurfaceFrame& surface_frame) { return true; },
51755183
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
51765184
[flutterPlatformViewsController submitFrame:std::move(mock_surface)
5177-
withIosContext:std::make_shared<flutter::IOSContextNoop>()];
5185+
withIosContext:std::make_shared<FakeIOSContext>()];
51785186

51795187
// The above code should result in previousCompositionOrder having one viewId in it
51805188
XCTAssertEqual(flutterPlatformViewsController.previousCompositionOrder.count, 1ul);
@@ -5243,7 +5251,7 @@ - (void)testNilPlatformViewDoesntCrash {
52435251
[](const flutter::SurfaceFrame& surface_frame) { return true; },
52445252
/*frame_size=*/flutter::DlISize(800, 600), nullptr, /*display_list_fallback=*/true);
52455253
[flutterPlatformViewsController submitFrame:std::move(mock_surface)
5246-
withIosContext:std::make_shared<flutter::IOSContextNoop>()];
5254+
withIosContext:std::make_shared<FakeIOSContext>()];
52475255

52485256
XCTAssertEqual(flutterView.subviews.count, 1u);
52495257
}
@@ -5354,7 +5362,7 @@ - (void)testFlutterPlatformViewControllerSubmitFramePreservingFrameDamage {
53545362
});
53555363

53565364
[flutterPlatformViewsController submitFrame:std::move(mock_surface)
5357-
withIosContext:std::make_shared<flutter::IOSContextNoop>()];
5365+
withIosContext:std::make_shared<FakeIOSContext>()];
53585366

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

0 commit comments

Comments
 (0)