diff --git a/engine/src/flutter/shell/common/rasterizer.cc b/engine/src/flutter/shell/common/rasterizer.cc index 755bd191e4..287d5b0168 100644 --- a/engine/src/flutter/shell/common/rasterizer.cc +++ b/engine/src/flutter/shell/common/rasterizer.cc @@ -457,7 +457,9 @@ sk_sp Rasterizer::ConvertToRasterImage(sk_sp image) { // |SnapshotDelegate| void Rasterizer::CacheRuntimeStage( const std::shared_ptr& runtime_stage) { - snapshot_controller_->CacheRuntimeStage(runtime_stage); + if (snapshot_controller_) { + snapshot_controller_->CacheRuntimeStage(runtime_stage); + } } fml::Milliseconds Rasterizer::GetFrameBudget() const { diff --git a/engine/src/flutter/shell/common/rasterizer.h b/engine/src/flutter/shell/common/rasterizer.h index 00113b269a..806d83c282 100644 --- a/engine/src/flutter/shell/common/rasterizer.h +++ b/engine/src/flutter/shell/common/rasterizer.h @@ -670,6 +670,15 @@ class Rasterizer final : public SnapshotDelegate, return surface_; } + // |SnapshotController::Delegate| + bool IsAiksContextInitialized() const override { +#if IMPELLER_SUPPORTS_RENDERING + return surface_ && surface_->GetAiksContext(); +#else + return false; +#endif + } + // |SnapshotController::Delegate| std::shared_ptr GetAiksContext() const override { #if IMPELLER_SUPPORTS_RENDERING diff --git a/engine/src/flutter/shell/common/rasterizer_unittests.cc b/engine/src/flutter/shell/common/rasterizer_unittests.cc index 0cb44c143b..629fc57a80 100644 --- a/engine/src/flutter/shell/common/rasterizer_unittests.cc +++ b/engine/src/flutter/shell/common/rasterizer_unittests.cc @@ -135,6 +135,18 @@ TEST(RasterizerTest, create) { EXPECT_TRUE(rasterizer != nullptr); } +TEST(RasterizerTest, isAiksContextInitialized) { + NiceMock delegate; + Settings settings; + ON_CALL(delegate, GetSettings()).WillByDefault(ReturnRef(settings)); + auto rasterizer = std::make_shared(delegate); + + EXPECT_TRUE(rasterizer != nullptr); + std::shared_ptr snapshot_delegate = rasterizer; + + EXPECT_FALSE(snapshot_delegate->IsAiksContextInitialized()); +} + static std::unique_ptr CreateFinishedBuildRecorder( fml::TimePoint timestamp) { std::unique_ptr recorder = diff --git a/engine/src/flutter/shell/common/snapshot_controller.h b/engine/src/flutter/shell/common/snapshot_controller.h index bc8d7833e7..442d456fb2 100644 --- a/engine/src/flutter/shell/common/snapshot_controller.h +++ b/engine/src/flutter/shell/common/snapshot_controller.h @@ -24,6 +24,7 @@ class SnapshotController { public: virtual ~Delegate() = default; virtual const std::unique_ptr& GetSurface() const = 0; + virtual bool IsAiksContextInitialized() const = 0; virtual std::shared_ptr GetAiksContext() const = 0; virtual const std::unique_ptr& GetSnapshotSurfaceProducer() const = 0; diff --git a/engine/src/flutter/shell/common/snapshot_controller_impeller.cc b/engine/src/flutter/shell/common/snapshot_controller_impeller.cc index b60f82132e..119db75b36 100644 --- a/engine/src/flutter/shell/common/snapshot_controller_impeller.cc +++ b/engine/src/flutter/shell/common/snapshot_controller_impeller.cc @@ -146,12 +146,15 @@ sk_sp SnapshotControllerImpeller::MakeRasterSnapshotSync( void SnapshotControllerImpeller::CacheRuntimeStage( const std::shared_ptr& runtime_stage) { - impeller::RuntimeEffectContents runtime_effect; - runtime_effect.SetRuntimeStage(runtime_stage); + if (!GetDelegate().IsAiksContextInitialized()) { + return; + } auto context = GetDelegate().GetAiksContext(); if (!context) { return; } + impeller::RuntimeEffectContents runtime_effect; + runtime_effect.SetRuntimeStage(runtime_stage); runtime_effect.BootstrapShader(context->GetContentContext()); }