diff --git a/display_list/image/dl_image.h b/display_list/image/dl_image.h index aecb58b8f7631..7f0828171e3ae 100644 --- a/display_list/image/dl_image.h +++ b/display_list/image/dl_image.h @@ -9,7 +9,7 @@ #include #include -#include "flutter/fml/macros.h" +#include "flutter/fml/build_config.h" #include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkRefCnt.h" @@ -118,6 +118,10 @@ class DlImage : public SkRefCnt { /// image. virtual std::optional get_error() const; +#if FML_OS_IOS_SIMULATOR + virtual bool IsFakeImage() const { return false; } +#endif // FML_OS_IOS_SIMULATOR + bool Equals(const DlImage* other) const { if (!other) { return false; diff --git a/impeller/display_list/dl_image_impeller.cc b/impeller/display_list/dl_image_impeller.cc index e5af07f6a2ffc..88127ab9818c9 100644 --- a/impeller/display_list/dl_image_impeller.cc +++ b/impeller/display_list/dl_image_impeller.cc @@ -9,6 +9,17 @@ namespace impeller { +#if FML_OS_IOS_SIMULATOR +sk_sp DlImageImpeller::Make(std::shared_ptr texture, + OwningContext owning_context, + bool is_fake_image) { + if (!texture && !is_fake_image) { + return nullptr; + } + return sk_sp( + new DlImageImpeller(std::move(texture), owning_context, is_fake_image)); +} +#else sk_sp DlImageImpeller::Make(std::shared_ptr texture, OwningContext owning_context) { if (!texture) { @@ -17,6 +28,7 @@ sk_sp DlImageImpeller::Make(std::shared_ptr texture, return sk_sp( new DlImageImpeller(std::move(texture), owning_context)); } +#endif // FML_OS_IOS_SIMULATOR sk_sp DlImageImpeller::MakeFromYUVTextures( AiksContext* aiks_context, @@ -45,8 +57,20 @@ sk_sp DlImageImpeller::MakeFromYUVTextures( } DlImageImpeller::DlImageImpeller(std::shared_ptr texture, - OwningContext owning_context) - : texture_(std::move(texture)), owning_context_(owning_context) {} + OwningContext owning_context +#ifdef FML_OS_IOS_SIMULATOR + , + bool is_fake_image +#endif // FML_OS_IOS_SIMULATOR + ) + : texture_(std::move(texture)), + owning_context_(owning_context) +#ifdef FML_OS_IOS_SIMULATOR + , + is_fake_image_(is_fake_image) +#endif // #ifdef FML_OS_IOS_SIMULATOR +{ +} // |DlImage| DlImageImpeller::~DlImageImpeller() = default; diff --git a/impeller/display_list/dl_image_impeller.h b/impeller/display_list/dl_image_impeller.h index 920c21fc8f138..0faf2f1491a5b 100644 --- a/impeller/display_list/dl_image_impeller.h +++ b/impeller/display_list/dl_image_impeller.h @@ -16,7 +16,12 @@ class DlImageImpeller final : public flutter::DlImage { public: static sk_sp Make( std::shared_ptr texture, - OwningContext owning_context = OwningContext::kIO); + OwningContext owning_context = OwningContext::kIO +#if FML_OS_IOS_SIMULATOR + , + bool is_fake_image = false +#endif // FML_OS_IOS_SIMULATOR + ); static sk_sp MakeFromYUVTextures( AiksContext* aiks_context, @@ -51,12 +56,25 @@ class DlImageImpeller final : public flutter::DlImage { // |DlImage| OwningContext owning_context() const override { return owning_context_; } +#if FML_OS_IOS_SIMULATOR + // |DlImage| + bool IsFakeImage() const override { return is_fake_image_; } +#endif // FML_OS_IOS_SIMULATOR + private: std::shared_ptr texture_; OwningContext owning_context_; +#if FML_OS_IOS_SIMULATOR + bool is_fake_image_ = false; +#endif // FML_OS_IOS_SIMULATOR explicit DlImageImpeller(std::shared_ptr texture, - OwningContext owning_context = OwningContext::kIO); + OwningContext owning_context = OwningContext::kIO +#if FML_OS_IOS_SIMULATOR + , + bool is_fake_image = false +#endif // FML_OS_IOS_SIMULATOR + ); DlImageImpeller(const DlImageImpeller&) = delete; diff --git a/lib/ui/painting/image.cc b/lib/ui/painting/image.cc index b31ceb71ed73a..dba1a2aa410ec 100644 --- a/lib/ui/painting/image.cc +++ b/lib/ui/painting/image.cc @@ -52,8 +52,7 @@ int CanvasImage::colorSpace() { return ImageEncodingImpeller::GetColorSpace(image_->impeller_texture()); #endif // IMPELLER_SUPPORTS_RENDERING } - - return -1; + return ColorSpace::kSRGB; } } // namespace flutter diff --git a/lib/ui/painting/image_encoding.cc b/lib/ui/painting/image_encoding.cc index 152551ee26ffb..da88fe41b8315 100644 --- a/lib/ui/painting/image_encoding.cc +++ b/lib/ui/painting/image_encoding.cc @@ -178,6 +178,14 @@ Dart_Handle EncodeImage(CanvasImage* canvas_image, auto callback = std::make_unique( tonic::DartState::Current(), callback_handle); +#if IMPELLER_SUPPORTS_RENDERING && FML_OS_IOS_SIMULATOR + if (canvas_image->image()->IsFakeImage()) { + sk_sp data = SkData::MakeEmpty(); + InvokeDataCallback(std::move(callback), data); + return Dart_Null(); + } +#endif // IMPELLER_SUPPORTS_RENDERING && FML_OS_IOS_SIMULATOR + const auto& task_runners = UIDartState::Current()->GetTaskRunners(); // The static leak checker gets confused by the use of fml::MakeCopyable. diff --git a/lib/ui/painting/picture.cc b/lib/ui/painting/picture.cc index 019ec845065d3..a8a0e957a828d 100644 --- a/lib/ui/painting/picture.cc +++ b/lib/ui/painting/picture.cc @@ -207,7 +207,6 @@ Dart_Handle Picture::DoRasterizeToImage(const sk_sp& display_list, height, ui_task, layer_tree = std::move(layer_tree)]() mutable { auto picture_bounds = SkISize::Make(width, height); - sk_sp image; sk_sp snapshot_display_list = display_list; if (layer_tree) { FML_DCHECK(picture_bounds == layer_tree->frame_size()); diff --git a/shell/common/snapshot_controller_impeller.cc b/shell/common/snapshot_controller_impeller.cc index 1dfbd3ff55ba9..2b06c04e4d113 100644 --- a/shell/common/snapshot_controller_impeller.cc +++ b/shell/common/snapshot_controller_impeller.cc @@ -7,6 +7,7 @@ #include #include "flutter/flow/surface.h" +#include "flutter/fml/build_config.h" #include "flutter/fml/trace_event.h" #include "flutter/impeller/display_list/dl_dispatcher.h" #include "flutter/impeller/display_list/dl_image_impeller.h" @@ -126,7 +127,6 @@ void SnapshotControllerImpeller::MakeRasterSnapshot( sk_sp display_list, SkISize picture_size, std::function&)> callback) { - sk_sp result; std::shared_ptr sync_switch = GetDelegate().GetIsGpuDisabledSyncSwitch(); sync_switch->Execute( @@ -143,10 +143,25 @@ void SnapshotControllerImpeller::MakeRasterSnapshot( }, [callback]() { callback(nullptr); }); } else { +#if FML_OS_IOS_SIMULATOR + callback(impeller::DlImageImpeller::Make( + nullptr, DlImage::OwningContext::kRaster, + /*is_fake_image=*/true)); +#else callback(nullptr); + +#endif // FML_OS_IOS_SIMULATOR } }) .SetIfFalse([&] { +#if FML_OS_IOS_SIMULATOR + if (!GetDelegate().GetAiksContext()) { + callback(impeller::DlImageImpeller::Make( + nullptr, DlImage::OwningContext::kRaster, + /*is_fake_image=*/true)); + return; + } +#endif callback(DoMakeRasterSnapshot(display_list, picture_size, GetDelegate().GetAiksContext())); }));