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

[Impeller] Enable logging a warning when the user opts out of using Impeller. #51849

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ struct Settings {
bool enable_impeller = false;
#endif

// Log a warning during shell initialization if Impeller is not enabled.
bool warn_on_impeller_opt_out = false;

// The selected Android rendering API.
AndroidRenderingAPI android_rendering_api =
AndroidRenderingAPI::kSkiaOpenGLES;
Expand Down
8 changes: 8 additions & 0 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,14 @@ Shell::Shell(DartVMRef vm,
weak_factory_(this) {
FML_CHECK(!settings.enable_software_rendering || !settings.enable_impeller)
<< "Software rendering is incompatible with Impeller.";
if (!settings.enable_impeller && settings.warn_on_impeller_opt_out) {
FML_LOG(IMPORTANT)
<< "[Action Required] The application opted out of Impeller by either "
"using the --no-enable-impeller flag or FLTEnableImpeller=false "
"plist flag. This option is going to go away in an upcoming Flutter "
"release. Remove the explicit opt-out. If you need to opt-out, "
"report a bug describing the issue.";
}
FML_CHECK(vm_) << "Must have access to VM to create a shell.";
FML_DCHECK(task_runners_.IsValid());
FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
Expand Down
24 changes: 23 additions & 1 deletion shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <strstream>
#define FML_USED_ON_EMBEDDER

#include <algorithm>
#include <chrono>
#include <ctime>
#include <future>
#include <memory>
#include <strstream>
#include <thread>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -4916,6 +4916,28 @@ TEST_F(ShellTest, RuntimeStageBackendWithImpeller) {
}
#endif // IMPELLER_SUPPORTS_RENDERING

TEST_F(ShellTest, WillLogWarningWhenImpellerIsOptedOut) {
#if !IMPELLER_SUPPORTS_RENDERING
GTEST_SKIP() << "This platform doesn't support Impeller.";
#endif
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
settings.enable_impeller = false;
settings.warn_on_impeller_opt_out = true;
// Log captures are thread specific. Just put the shell in single threaded
// configuration.
const auto& runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
TaskRunners task_runners("test", runner, runner, runner, runner);
std::ostringstream stream;
fml::LogMessage::CaptureNextLog(&stream);
std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
ASSERT_TRUE(stream.str().find(
"[Action Required] The application opted out of Impeller") !=
std::string::npos);
ASSERT_TRUE(shell);
DestroyShell(std::move(shell), task_runners);
}

} // namespace testing
} // namespace flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ static BOOL DoesHardwareSupportWideGamut() {
}
}

settings.warn_on_impeller_opt_out = true;

NSNumber* enableTraceSystrace = [mainBundle objectForInfoDictionaryKey:@"FLTTraceSystrace"];
// Change the default only if the option is present.
if (enableTraceSystrace != nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ - (void)testDisableImpellerSettingIsCorrectlyParsed {
[mockMainBundle stopMocking];
}

- (void)testRequestsWarningWhenImpellerOptOut {
auto settings = FLTDefaultSettingsForBundle();
XCTAssertEqual(settings.warn_on_impeller_opt_out, YES);
}

- (void)testEnableImpellerSettingIsCorrectlyParsed {
id mockMainBundle = OCMPartialMock([NSBundle mainBundle]);
OCMStub([mockMainBundle objectForInfoDictionaryKey:@"FLTEnableImpeller"]).andReturn(@"YES");
Expand Down