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

Commit fe3287b

Browse files
committed
[fuchsia] Set blending mode on flatland images
1 parent 0e7213c commit fe3287b

File tree

6 files changed

+67
-14
lines changed

6 files changed

+67
-14
lines changed

shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ void FlatlandExternalViewEmbedder::SubmitFrame(
258258
{static_cast<uint32_t>(surface_for_layer->GetSize().width()),
259259
static_cast<uint32_t>(surface_for_layer->GetSize().height())});
260260

261+
// Flutter Embedder lacks an API to detect if a layer has alpha or not.
262+
// For now, we assume any layer beyond the first has alpha.
263+
flatland_.flatland()->SetImageBlendingFunction(
264+
{surface_for_layer->GetImageId()},
265+
flatland_layer_index == 0
266+
? fuchsia::ui::composition::BlendMode::SRC
267+
: fuchsia::ui::composition::BlendMode::SRC_OVER);
268+
261269
// Attach the FlatlandLayer to the main scene graph.
262270
flatland_.flatland()->AddChild(
263271
root_transform_id_,
@@ -267,7 +275,6 @@ void FlatlandExternalViewEmbedder::SubmitFrame(
267275
}
268276

269277
// Reset for the next pass:
270-
// +The next layer will not be the first layer.
271278
flatland_layer_index++;
272279
}
273280
}

shell/platform/fuchsia/flutter/tests/fakes/scenic/fake_flatland.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,37 @@ void FakeFlatland::SetImageDestinationSize(
621621
image->destination_size = size;
622622
}
623623

624+
void FakeFlatland::SetImageBlendingFunction(
625+
fuchsia::ui::composition::ContentId image_id,
626+
fuchsia::ui::composition::BlendMode blend_mode) {
627+
if (image_id.value == 0) {
628+
// TODO(fxb/85619): Raise a FlatlandError here
629+
FML_CHECK(false)
630+
<< "FakeFlatland::SetImageDestinationSize: ContentId 0 is invalid.";
631+
return;
632+
}
633+
634+
auto found_content = pending_graph_.content_map.find(image_id.value);
635+
if (found_content == pending_graph_.content_map.end()) {
636+
// TODO(fxb/85619): Raise a FlatlandError here
637+
FML_CHECK(false) << "FakeFlatland::SetImageDestinationSize: ContentId "
638+
<< image_id.value << " does not exist.";
639+
return;
640+
}
641+
642+
auto& content = found_content->second;
643+
FML_CHECK(content);
644+
FakeImage* image = std::get_if<FakeImage>(content.get());
645+
if (image == nullptr) {
646+
// TODO(fxb/85619): Raise a FlatlandError here
647+
FML_CHECK(false) << "FakeFlatland::SetImageDestinationSize: ContentId "
648+
<< image_id.value << " is not an Image.";
649+
return;
650+
}
651+
652+
image->blend_mode = blend_mode;
653+
}
654+
624655
void FakeFlatland::SetViewportProperties(
625656
fuchsia::ui::composition::ContentId viewport_id,
626657
fuchsia::ui::composition::ViewportProperties properties) {

shell/platform/fuchsia/flutter/tests/fakes/scenic/fake_flatland.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ class FakeFlatland
276276
void SetImageDestinationSize(fuchsia::ui::composition::ContentId image_id,
277277
fuchsia::math::SizeU size) override;
278278

279+
// |fuchsia::ui::composition::Flatland|
280+
void SetImageBlendingFunction(
281+
fuchsia::ui::composition::ContentId image_id,
282+
fuchsia::ui::composition::BlendMode blend_mode) override;
283+
279284
// |fuchsia::ui::composition::Flatland|
280285
void SetViewportProperties(
281286
fuchsia::ui::composition::ContentId viewport_id,

shell/platform/fuchsia/flutter/tests/fakes/scenic/fake_flatland_types.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ std::shared_ptr<FakeContent> CloneFakeContent(
4040
.sample_region = image->sample_region,
4141
.destination_size = image->destination_size,
4242
.opacity = image->opacity,
43+
.blend_mode = image->blend_mode,
4344
.import_token = image->import_token,
4445
.vmo_index = image->vmo_index,
4546
});
@@ -124,8 +125,8 @@ bool FakeImage::operator==(const FakeImage& other) const {
124125
return id == other.id && image_properties == other.image_properties &&
125126
sample_region == other.sample_region &&
126127
destination_size == other.destination_size &&
127-
opacity == other.opacity && import_token == other.import_token &&
128-
vmo_index == other.vmo_index;
128+
opacity == other.opacity && blend_mode == other.blend_mode &&
129+
import_token == other.import_token && vmo_index == other.vmo_index;
129130
}
130131

131132
bool FakeTransform::operator==(const FakeTransform& other) const {

shell/platform/fuchsia/flutter/tests/fakes/scenic/fake_flatland_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,16 @@ struct FakeImage {
144144
constexpr static fuchsia::math::RectF kDefaultSampleRegion{};
145145
constexpr static fuchsia::math::SizeU kDefaultDestinationSize{};
146146
constexpr static float kDefaultOpacity{1.f};
147+
constexpr static fuchsia::ui::composition::BlendMode kDefaultBlendMode{
148+
fuchsia::ui::composition::BlendMode::SRC_OVER};
147149

148150
fuchsia::ui::composition::ContentId id{kInvalidContentId};
149151

150152
fuchsia::ui::composition::ImageProperties image_properties{};
151153
fuchsia::math::RectF sample_region{kDefaultSampleRegion};
152154
fuchsia::math::SizeU destination_size{kDefaultDestinationSize};
153155
float opacity{kDefaultOpacity};
156+
fuchsia::ui::composition::BlendMode blend_mode{kDefaultBlendMode};
154157

155158
zx_koid_t import_token{};
156159
uint32_t vmo_index{0};

shell/platform/fuchsia/flutter/tests/flatland_external_view_embedder_unittests.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ using ::testing::VariantWith;
5151
namespace flutter_runner::testing {
5252
namespace {
5353

54+
constexpr static fuchsia::ui::composition::BlendMode kFirstLayerBlendMode{
55+
fuchsia::ui::composition::BlendMode::SRC};
56+
constexpr static fuchsia::ui::composition::BlendMode kUpperLayerBlendMode{
57+
fuchsia::ui::composition::BlendMode::SRC_OVER};
58+
5459
class FakeSurfaceProducerSurface : public SurfaceProducerSurface {
5560
public:
5661
explicit FakeSurfaceProducerSurface(
@@ -215,7 +220,8 @@ Matcher<FakeGraph> IsFlutterGraph(
215220
}
216221

217222
Matcher<std::shared_ptr<FakeTransform>> IsImageLayer(
218-
const fuchsia::math::SizeU& layer_size) {
223+
const fuchsia::math::SizeU& layer_size,
224+
fuchsia::ui::composition::BlendMode blend_mode) {
219225
return Pointee(FieldsAre(
220226
/*id*/ _, FakeTransform::kDefaultTranslation,
221227
FakeTransform::kDefaultClipBounds, FakeTransform::kDefaultOrientation,
@@ -224,7 +230,7 @@ Matcher<std::shared_ptr<FakeTransform>> IsImageLayer(
224230
Pointee(VariantWith<FakeImage>(FieldsAre(
225231
/*id*/ _, IsImageProperties(layer_size),
226232
FakeImage::kDefaultSampleRegion, layer_size,
227-
FakeImage::kDefaultOpacity,
233+
FakeImage::kDefaultOpacity, blend_mode,
228234
/*buffer_import_token*/ _, /*vmo_index*/ 0)))));
229235
}
230236

@@ -440,13 +446,13 @@ TEST_F(FlatlandExternalViewEmbedderTest, SimpleScene) {
440446
IsFlutterGraph(parent_viewport_watcher, viewport_creation_token,
441447
view_ref));
442448

443-
// Pump the message loop. The scene updates should propagate to flatland.
449+
// Pump the message loop. The scene updates should propagate to flatland.
444450
loop().RunUntilIdle();
445451
EXPECT_THAT(
446452
fake_flatland().graph(),
447453
IsFlutterGraph(parent_viewport_watcher, viewport_creation_token, view_ref,
448454
/*layers*/
449-
{IsImageLayer(frame_size)}));
455+
{IsImageLayer(frame_size, kFirstLayerBlendMode)}));
450456
}
451457

452458
TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneView) {
@@ -535,9 +541,9 @@ TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneView) {
535541
fake_flatland().graph(),
536542
IsFlutterGraph(
537543
parent_viewport_watcher, viewport_creation_token, view_ref, /*layers*/
538-
{IsImageLayer(frame_size),
544+
{IsImageLayer(frame_size, kFirstLayerBlendMode),
539545
IsViewportLayer(child_view_token, child_view_size, {0, 0}),
540-
IsImageLayer(frame_size)}));
546+
IsImageLayer(frame_size, kUpperLayerBlendMode)}));
541547

542548
// Destroy the view. The scene graph shouldn't change yet.
543549
external_view_embedder.DestroyView(
@@ -546,9 +552,9 @@ TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneView) {
546552
fake_flatland().graph(),
547553
IsFlutterGraph(
548554
parent_viewport_watcher, viewport_creation_token, view_ref, /*layers*/
549-
{IsImageLayer(frame_size),
555+
{IsImageLayer(frame_size, kFirstLayerBlendMode),
550556
IsViewportLayer(child_view_token, child_view_size, {0, 0}),
551-
IsImageLayer(frame_size)}));
557+
IsImageLayer(frame_size, kUpperLayerBlendMode)}));
552558

553559
// Draw another frame without the view. The scene graph shouldn't change yet.
554560
DrawSimpleFrame(
@@ -567,16 +573,16 @@ TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneView) {
567573
fake_flatland().graph(),
568574
IsFlutterGraph(
569575
parent_viewport_watcher, viewport_creation_token, view_ref, /*layers*/
570-
{IsImageLayer(frame_size),
576+
{IsImageLayer(frame_size, kFirstLayerBlendMode),
571577
IsViewportLayer(child_view_token, child_view_size, {0, 0}),
572-
IsImageLayer(frame_size)}));
578+
IsImageLayer(frame_size, kUpperLayerBlendMode)}));
573579

574580
// Pump the message loop. The scene updates should propagate to flatland.
575581
loop().RunUntilIdle();
576582
EXPECT_THAT(fake_flatland().graph(),
577583
IsFlutterGraph(parent_viewport_watcher, viewport_creation_token,
578584
view_ref, /*layers*/
579-
{IsImageLayer(frame_size)}));
585+
{IsImageLayer(frame_size, kFirstLayerBlendMode)}));
580586
}
581587

582588
} // namespace flutter_runner::testing

0 commit comments

Comments
 (0)