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

Commit 79aa167

Browse files
committed
[Impeller] Enable logging a warning when the user opts out of using Impeller. (#51849)
Part of flutter/flutter#144439 This does two things: * Logs a warning when the embedder requests a non-Impeller preference when creating a shell. * Makes the iOS embedder request a warning be logged when Impeller is not used. I decided to put the warning logs in the shell so that as we get more opinionated about Impeller on other platforms, those platforms can just flip a flag with common log origin.
1 parent 9755090 commit 79aa167

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

common/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ struct Settings {
229229
bool enable_impeller = false;
230230
#endif
231231

232+
// Log a warning during shell initialization if Impeller is not enabled.
233+
bool warn_on_impeller_opt_out = false;
234+
232235
// The selected Android rendering API.
233236
AndroidRenderingAPI android_rendering_api =
234237
AndroidRenderingAPI::kSkiaOpenGLES;

shell/common/shell.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,14 @@ Shell::Shell(DartVMRef vm,
450450
weak_factory_(this) {
451451
FML_CHECK(!settings.enable_software_rendering || !settings.enable_impeller)
452452
<< "Software rendering is incompatible with Impeller.";
453+
if (!settings.enable_impeller && settings.warn_on_impeller_opt_out) {
454+
FML_LOG(IMPORTANT)
455+
<< "[Action Required] The application opted out of Impeller by either "
456+
"using the --no-enable-impeller flag or FLTEnableImpeller=false "
457+
"plist flag. This option is going to go away in an upcoming Flutter "
458+
"release. Remove the explicit opt-out. If you need to opt-out, "
459+
"report a bug describing the issue.";
460+
}
453461
FML_CHECK(vm_) << "Must have access to VM to create a shell.";
454462
FML_DCHECK(task_runners_.IsValid());
455463
FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());

shell/common/shell_unittests.cc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include <strstream>
65
#define FML_USED_ON_EMBEDDER
76

87
#include <algorithm>
98
#include <chrono>
109
#include <ctime>
1110
#include <future>
1211
#include <memory>
12+
#include <strstream>
1313
#include <thread>
1414
#include <utility>
1515
#include <vector>
@@ -4689,6 +4689,28 @@ TEST_F(ShellTest, RuntimeStageBackendWithImpeller) {
46894689
}
46904690
#endif // IMPELLER_SUPPORTS_RENDERING
46914691

4692+
TEST_F(ShellTest, WillLogWarningWhenImpellerIsOptedOut) {
4693+
#if !IMPELLER_SUPPORTS_RENDERING
4694+
GTEST_SKIP() << "This platform doesn't support Impeller.";
4695+
#endif
4696+
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4697+
Settings settings = CreateSettingsForFixture();
4698+
settings.enable_impeller = false;
4699+
settings.warn_on_impeller_opt_out = true;
4700+
// Log captures are thread specific. Just put the shell in single threaded
4701+
// configuration.
4702+
const auto& runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
4703+
TaskRunners task_runners("test", runner, runner, runner, runner);
4704+
std::ostringstream stream;
4705+
fml::LogMessage::CaptureNextLog(&stream);
4706+
std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4707+
ASSERT_TRUE(stream.str().find(
4708+
"[Action Required] The application opted out of Impeller") !=
4709+
std::string::npos);
4710+
ASSERT_TRUE(shell);
4711+
DestroyShell(std::move(shell), task_runners);
4712+
}
4713+
46924714
} // namespace testing
46934715
} // namespace flutter
46944716

shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ static BOOL DoesHardwareSupportWideGamut() {
200200
}
201201
}
202202

203+
settings.warn_on_impeller_opt_out = true;
204+
203205
NSNumber* enableTraceSystrace = [mainBundle objectForInfoDictionaryKey:@"FLTTraceSystrace"];
204206
// Change the default only if the option is present.
205207
if (enableTraceSystrace != nil) {

shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ - (void)testDisableImpellerSettingIsCorrectlyParsed {
235235
[mockMainBundle stopMocking];
236236
}
237237

238+
- (void)testRequestsWarningWhenImpellerOptOut {
239+
auto settings = FLTDefaultSettingsForBundle();
240+
XCTAssertEqual(settings.warn_on_impeller_opt_out, YES);
241+
}
242+
238243
- (void)testEnableImpellerSettingIsCorrectlyParsed {
239244
id mockMainBundle = OCMPartialMock([NSBundle mainBundle]);
240245
OCMStub([mockMainBundle objectForInfoDictionaryKey:@"FLTEnableImpeller"]).andReturn(@"YES");

0 commit comments

Comments
 (0)