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

Commit 0563637

Browse files
author
Jonah Williams
authored
[impeller] fake image for fake tests. (#54974)
Simulator only change to allow toImage and toByteData to not fail when there is no metal context w/ impeller.
1 parent 7f2718d commit 0563637

File tree

7 files changed

+76
-9
lines changed

7 files changed

+76
-9
lines changed

display_list/image/dl_image.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <optional>
1010
#include <string>
1111

12-
#include "flutter/fml/macros.h"
12+
#include "flutter/fml/build_config.h"
1313
#include "third_party/skia/include/core/SkImage.h"
1414
#include "third_party/skia/include/core/SkRefCnt.h"
1515

@@ -118,6 +118,10 @@ class DlImage : public SkRefCnt {
118118
/// image.
119119
virtual std::optional<std::string> get_error() const;
120120

121+
#if FML_OS_IOS_SIMULATOR
122+
virtual bool IsFakeImage() const { return false; }
123+
#endif // FML_OS_IOS_SIMULATOR
124+
121125
bool Equals(const DlImage* other) const {
122126
if (!other) {
123127
return false;

impeller/display_list/dl_image_impeller.cc

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99

1010
namespace impeller {
1111

12+
#if FML_OS_IOS_SIMULATOR
13+
sk_sp<DlImageImpeller> DlImageImpeller::Make(std::shared_ptr<Texture> texture,
14+
OwningContext owning_context,
15+
bool is_fake_image) {
16+
if (!texture && !is_fake_image) {
17+
return nullptr;
18+
}
19+
return sk_sp<DlImageImpeller>(
20+
new DlImageImpeller(std::move(texture), owning_context, is_fake_image));
21+
}
22+
#else
1223
sk_sp<DlImageImpeller> DlImageImpeller::Make(std::shared_ptr<Texture> texture,
1324
OwningContext owning_context) {
1425
if (!texture) {
@@ -17,6 +28,7 @@ sk_sp<DlImageImpeller> DlImageImpeller::Make(std::shared_ptr<Texture> texture,
1728
return sk_sp<DlImageImpeller>(
1829
new DlImageImpeller(std::move(texture), owning_context));
1930
}
31+
#endif // FML_OS_IOS_SIMULATOR
2032

2133
sk_sp<DlImageImpeller> DlImageImpeller::MakeFromYUVTextures(
2234
AiksContext* aiks_context,
@@ -45,8 +57,20 @@ sk_sp<DlImageImpeller> DlImageImpeller::MakeFromYUVTextures(
4557
}
4658

4759
DlImageImpeller::DlImageImpeller(std::shared_ptr<Texture> texture,
48-
OwningContext owning_context)
49-
: texture_(std::move(texture)), owning_context_(owning_context) {}
60+
OwningContext owning_context
61+
#ifdef FML_OS_IOS_SIMULATOR
62+
,
63+
bool is_fake_image
64+
#endif // FML_OS_IOS_SIMULATOR
65+
)
66+
: texture_(std::move(texture)),
67+
owning_context_(owning_context)
68+
#ifdef FML_OS_IOS_SIMULATOR
69+
,
70+
is_fake_image_(is_fake_image)
71+
#endif // #ifdef FML_OS_IOS_SIMULATOR
72+
{
73+
}
5074

5175
// |DlImage|
5276
DlImageImpeller::~DlImageImpeller() = default;

impeller/display_list/dl_image_impeller.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ class DlImageImpeller final : public flutter::DlImage {
1616
public:
1717
static sk_sp<DlImageImpeller> Make(
1818
std::shared_ptr<Texture> texture,
19-
OwningContext owning_context = OwningContext::kIO);
19+
OwningContext owning_context = OwningContext::kIO
20+
#if FML_OS_IOS_SIMULATOR
21+
,
22+
bool is_fake_image = false
23+
#endif // FML_OS_IOS_SIMULATOR
24+
);
2025

2126
static sk_sp<DlImageImpeller> MakeFromYUVTextures(
2227
AiksContext* aiks_context,
@@ -51,12 +56,25 @@ class DlImageImpeller final : public flutter::DlImage {
5156
// |DlImage|
5257
OwningContext owning_context() const override { return owning_context_; }
5358

59+
#if FML_OS_IOS_SIMULATOR
60+
// |DlImage|
61+
bool IsFakeImage() const override { return is_fake_image_; }
62+
#endif // FML_OS_IOS_SIMULATOR
63+
5464
private:
5565
std::shared_ptr<Texture> texture_;
5666
OwningContext owning_context_;
67+
#if FML_OS_IOS_SIMULATOR
68+
bool is_fake_image_ = false;
69+
#endif // FML_OS_IOS_SIMULATOR
5770

5871
explicit DlImageImpeller(std::shared_ptr<Texture> texture,
59-
OwningContext owning_context = OwningContext::kIO);
72+
OwningContext owning_context = OwningContext::kIO
73+
#if FML_OS_IOS_SIMULATOR
74+
,
75+
bool is_fake_image = false
76+
#endif // FML_OS_IOS_SIMULATOR
77+
);
6078

6179
DlImageImpeller(const DlImageImpeller&) = delete;
6280

lib/ui/painting/image.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ int CanvasImage::colorSpace() {
5252
return ImageEncodingImpeller::GetColorSpace(image_->impeller_texture());
5353
#endif // IMPELLER_SUPPORTS_RENDERING
5454
}
55-
56-
return -1;
55+
return ColorSpace::kSRGB;
5756
}
5857

5958
} // namespace flutter

lib/ui/painting/image_encoding.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ Dart_Handle EncodeImage(CanvasImage* canvas_image,
178178
auto callback = std::make_unique<DartPersistentValue>(
179179
tonic::DartState::Current(), callback_handle);
180180

181+
#if IMPELLER_SUPPORTS_RENDERING && FML_OS_IOS_SIMULATOR
182+
if (canvas_image->image()->IsFakeImage()) {
183+
sk_sp<SkData> data = SkData::MakeEmpty();
184+
InvokeDataCallback(std::move(callback), data);
185+
return Dart_Null();
186+
}
187+
#endif // IMPELLER_SUPPORTS_RENDERING && FML_OS_IOS_SIMULATOR
188+
181189
const auto& task_runners = UIDartState::Current()->GetTaskRunners();
182190

183191
// The static leak checker gets confused by the use of fml::MakeCopyable.

lib/ui/painting/picture.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ Dart_Handle Picture::DoRasterizeToImage(const sk_sp<DisplayList>& display_list,
207207
height, ui_task,
208208
layer_tree = std::move(layer_tree)]() mutable {
209209
auto picture_bounds = SkISize::Make(width, height);
210-
sk_sp<DlImage> image;
211210
sk_sp<DisplayList> snapshot_display_list = display_list;
212211
if (layer_tree) {
213212
FML_DCHECK(picture_bounds == layer_tree->frame_size());

shell/common/snapshot_controller_impeller.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <algorithm>
88

99
#include "flutter/flow/surface.h"
10+
#include "flutter/fml/build_config.h"
1011
#include "flutter/fml/trace_event.h"
1112
#include "flutter/impeller/display_list/dl_dispatcher.h"
1213
#include "flutter/impeller/display_list/dl_image_impeller.h"
@@ -126,7 +127,6 @@ void SnapshotControllerImpeller::MakeRasterSnapshot(
126127
sk_sp<DisplayList> display_list,
127128
SkISize picture_size,
128129
std::function<void(const sk_sp<DlImage>&)> callback) {
129-
sk_sp<DlImage> result;
130130
std::shared_ptr<const fml::SyncSwitch> sync_switch =
131131
GetDelegate().GetIsGpuDisabledSyncSwitch();
132132
sync_switch->Execute(
@@ -143,10 +143,25 @@ void SnapshotControllerImpeller::MakeRasterSnapshot(
143143
},
144144
[callback]() { callback(nullptr); });
145145
} else {
146+
#if FML_OS_IOS_SIMULATOR
147+
callback(impeller::DlImageImpeller::Make(
148+
nullptr, DlImage::OwningContext::kRaster,
149+
/*is_fake_image=*/true));
150+
#else
146151
callback(nullptr);
152+
153+
#endif // FML_OS_IOS_SIMULATOR
147154
}
148155
})
149156
.SetIfFalse([&] {
157+
#if FML_OS_IOS_SIMULATOR
158+
if (!GetDelegate().GetAiksContext()) {
159+
callback(impeller::DlImageImpeller::Make(
160+
nullptr, DlImage::OwningContext::kRaster,
161+
/*is_fake_image=*/true));
162+
return;
163+
}
164+
#endif
150165
callback(DoMakeRasterSnapshot(display_list, picture_size,
151166
GetDelegate().GetAiksContext()));
152167
}));

0 commit comments

Comments
 (0)