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

[impeller] fake image for fake tests. #54974

Merged
merged 2 commits into from
Sep 6, 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
6 changes: 5 additions & 1 deletion display_list/image/dl_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <optional>
#include <string>

#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"

Expand Down Expand Up @@ -118,6 +118,10 @@ class DlImage : public SkRefCnt {
/// image.
virtual std::optional<std::string> 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;
Expand Down
28 changes: 26 additions & 2 deletions impeller/display_list/dl_image_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@

namespace impeller {

#if FML_OS_IOS_SIMULATOR
sk_sp<DlImageImpeller> DlImageImpeller::Make(std::shared_ptr<Texture> texture,
OwningContext owning_context,
bool is_fake_image) {
if (!texture && !is_fake_image) {
return nullptr;
}
return sk_sp<DlImageImpeller>(
new DlImageImpeller(std::move(texture), owning_context, is_fake_image));
}
#else
sk_sp<DlImageImpeller> DlImageImpeller::Make(std::shared_ptr<Texture> texture,
OwningContext owning_context) {
if (!texture) {
Expand All @@ -17,6 +28,7 @@ sk_sp<DlImageImpeller> DlImageImpeller::Make(std::shared_ptr<Texture> texture,
return sk_sp<DlImageImpeller>(
new DlImageImpeller(std::move(texture), owning_context));
}
#endif // FML_OS_IOS_SIMULATOR

sk_sp<DlImageImpeller> DlImageImpeller::MakeFromYUVTextures(
AiksContext* aiks_context,
Expand Down Expand Up @@ -45,8 +57,20 @@ sk_sp<DlImageImpeller> DlImageImpeller::MakeFromYUVTextures(
}

DlImageImpeller::DlImageImpeller(std::shared_ptr<Texture> 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;
Expand Down
22 changes: 20 additions & 2 deletions impeller/display_list/dl_image_impeller.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ class DlImageImpeller final : public flutter::DlImage {
public:
static sk_sp<DlImageImpeller> Make(
std::shared_ptr<Texture> 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<DlImageImpeller> MakeFromYUVTextures(
AiksContext* aiks_context,
Expand Down Expand Up @@ -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> 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> 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;

Expand Down
3 changes: 1 addition & 2 deletions lib/ui/painting/image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ int CanvasImage::colorSpace() {
return ImageEncodingImpeller::GetColorSpace(image_->impeller_texture());
#endif // IMPELLER_SUPPORTS_RENDERING
}

return -1;
return ColorSpace::kSRGB;
}

} // namespace flutter
8 changes: 8 additions & 0 deletions lib/ui/painting/image_encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ Dart_Handle EncodeImage(CanvasImage* canvas_image,
auto callback = std::make_unique<DartPersistentValue>(
tonic::DartState::Current(), callback_handle);

#if IMPELLER_SUPPORTS_RENDERING && FML_OS_IOS_SIMULATOR
if (canvas_image->image()->IsFakeImage()) {
sk_sp<SkData> 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.
Expand Down
1 change: 0 additions & 1 deletion lib/ui/painting/picture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ Dart_Handle Picture::DoRasterizeToImage(const sk_sp<DisplayList>& display_list,
height, ui_task,
layer_tree = std::move(layer_tree)]() mutable {
auto picture_bounds = SkISize::Make(width, height);
sk_sp<DlImage> image;
sk_sp<DisplayList> snapshot_display_list = display_list;
if (layer_tree) {
FML_DCHECK(picture_bounds == layer_tree->frame_size());
Expand Down
17 changes: 16 additions & 1 deletion shell/common/snapshot_controller_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <algorithm>

#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"
Expand Down Expand Up @@ -126,7 +127,6 @@ void SnapshotControllerImpeller::MakeRasterSnapshot(
sk_sp<DisplayList> display_list,
SkISize picture_size,
std::function<void(const sk_sp<DlImage>&)> callback) {
sk_sp<DlImage> result;
std::shared_ptr<const fml::SyncSwitch> sync_switch =
GetDelegate().GetIsGpuDisabledSyncSwitch();
sync_switch->Execute(
Expand All @@ -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()));
}));
Expand Down