fuchsia: Fix Flatland opacity (flutter/engine#29844)

This commit is contained in:
David Worsham 2021-11-19 11:58:20 -08:00 committed by GitHub
parent 4d13aa4829
commit 40d0af4eb2
5 changed files with 45 additions and 31 deletions

View File

@ -257,27 +257,37 @@ void FakeFlatland::SetClipBounds(
transform->clip_bounds = clip_bounds;
}
void FakeFlatland::SetOpacity(
fuchsia::ui::composition::TransformId transform_id,
float opacity) {
if (transform_id.value == 0) {
// TODO(fxb/85619): Raise a FlatlandError here
FML_CHECK(false) << "FakeFlatland::SetOpacity: TransformId 0 is invalid.";
return;
}
// TODO(fxbug.dev/89111): Re-enable once SDK rolls.
// void FakeFlatland::SetImageOpacity(
// fuchsia::ui::composition::ContentId content_id,
// float opacity) {
// if (content_id.value == 0) {
// // TODO(fxb/85619): Raise a FlatlandError here
// FML_CHECK(false)
// << "FakeFlatland::SetImageOpacity: ContentId 0 is invalid.";
// return;
// }
auto found_transform = pending_graph_.transform_map.find(transform_id.value);
if (found_transform == pending_graph_.transform_map.end()) {
// TODO(fxb/85619): Raise a FlatlandError here
FML_CHECK(false) << "FakeFlatland::SetOpacity: TransformId "
<< transform_id.value << " does not exist.";
return;
}
// auto found_content = pending_graph_.content_map.find(image_id.value);
// if (found_content == pending_graph_.content_map.end()) {
// // TODO(fxb/85619): Raise a FlatlandError here
// FML_CHECK(false) << "FakeFlatland::SetImageOpacity: ContentId "
// << image_id.value << " does not exist.";
// return;
// }
auto& transform = found_transform->second;
FML_CHECK(transform);
transform->opacity = opacity;
}
// auto& content = found_content->second;
// FML_CHECK(content);
// FakeImage* image = std::get_if<FakeImage>(content.get());
// if (image == nullptr) {
// // TODO(fxb/85619): Raise a FlatlandError here
// FML_CHECK(false) << "FakeFlatland::SetImageOpacity: ContentId "
// << image_id.value << " is not an Image.";
// return;
// }
// image->opacity = opacity;
// }
void FakeFlatland::AddChild(
fuchsia::ui::composition::TransformId parent_transform_id,

View File

@ -230,9 +230,10 @@ class FakeFlatland
void SetClipBounds(fuchsia::ui::composition::TransformId transform_id,
fuchsia::math::Rect clip_bounds) override;
// |fuchsia::ui::composition::Flatland|
void SetOpacity(fuchsia::ui::composition::TransformId transform_id,
float opacity) override;
// TODO(fxbug.dev/89111): Re-enable once SDK rolls.
// // |fuchsia::ui::composition::Flatland|
// void SetImageOpacity(fuchsia::ui::composition::ContentId image_id,
// float opacity) override;
// |fuchsia::ui::composition::Flatland|
void AddChild(

View File

@ -39,6 +39,7 @@ std::shared_ptr<FakeContent> CloneFakeContent(
.image_properties = fidl::Clone(image->image_properties),
.sample_region = image->sample_region,
.destination_size = image->destination_size,
.opacity = image->opacity,
.import_token = image->import_token,
.vmo_index = image->vmo_index,
});
@ -65,7 +66,6 @@ std::shared_ptr<FakeTransform> CloneFakeTransform(
.translation = transform->translation,
.clip_bounds = transform->clip_bounds,
.orientation = transform->orientation,
.opacity = transform->opacity,
.children = CloneFakeTransformVector(
transform->children, transform_cache),
.content = CloneFakeContent(transform->content),
@ -124,14 +124,14 @@ bool FakeImage::operator==(const FakeImage& other) const {
return id == other.id && image_properties == other.image_properties &&
sample_region == other.sample_region &&
destination_size == other.destination_size &&
import_token == other.import_token && vmo_index == other.vmo_index;
opacity == other.opacity && import_token == other.import_token &&
vmo_index == other.vmo_index;
}
bool FakeTransform::operator==(const FakeTransform& other) const {
return id == other.id && translation == other.translation &&
clip_bounds == other.clip_bounds && orientation == other.orientation &&
opacity == other.opacity && children == other.children &&
content == other.content;
children == other.children && content == other.content;
}
bool FakeGraph::operator==(const FakeGraph& other) const {

View File

@ -143,12 +143,14 @@ struct FakeImage {
constexpr static fuchsia::math::SizeU kDefaultImageSize{};
constexpr static fuchsia::math::RectF kDefaultSampleRegion{};
constexpr static fuchsia::math::SizeU kDefaultDestinationSize{};
constexpr static float kDefaultOpacity{1.f};
fuchsia::ui::composition::ContentId id{kInvalidContentId};
fuchsia::ui::composition::ImageProperties image_properties{};
fuchsia::math::RectF sample_region{kDefaultSampleRegion};
fuchsia::math::SizeU destination_size{kDefaultDestinationSize};
float opacity{kDefaultOpacity};
zx_koid_t import_token{};
uint32_t vmo_index{0};
@ -166,14 +168,12 @@ struct FakeTransform {
.height = 0};
constexpr static fuchsia::ui::composition::Orientation kDefaultOrientation{
fuchsia::ui::composition::Orientation::CCW_0_DEGREES};
constexpr static float kDefaultOpacity{1.f};
fuchsia::ui::composition::TransformId id{kInvalidTransformId};
fuchsia::math::Vec translation{kDefaultTranslation};
fuchsia::math::Rect clip_bounds{kDefaultClipBounds};
fuchsia::ui::composition::Orientation orientation{kDefaultOrientation};
float opacity{kDefaultOpacity};
std::vector<std::shared_ptr<FakeTransform>> children;
std::shared_ptr<FakeContent> content;

View File

@ -200,7 +200,7 @@ Matcher<FakeGraph> IsFlutterGraph(
Pointee(FieldsAre(
/*id*/ _, FakeTransform::kDefaultTranslation,
FakeTransform::kDefaultClipBounds, FakeTransform::kDefaultOrientation,
FakeTransform::kDefaultOpacity, ElementsAreArray(layer_matchers),
/*children*/ ElementsAreArray(layer_matchers),
/*content*/ Eq(nullptr))),
Eq(FakeView{
.view_token = viewport_token_koids.second,
@ -219,10 +219,12 @@ Matcher<std::shared_ptr<FakeTransform>> IsImageLayer(
return Pointee(FieldsAre(
/*id*/ _, FakeTransform::kDefaultTranslation,
FakeTransform::kDefaultClipBounds, FakeTransform::kDefaultOrientation,
FakeTransform::kDefaultOpacity, IsEmpty(),
/*children*/ IsEmpty(),
/*content*/
Pointee(VariantWith<FakeImage>(FieldsAre(
/*id*/ _, IsImageProperties(layer_size),
FakeImage::kDefaultSampleRegion, layer_size,
FakeImage::kDefaultOpacity,
/*buffer_import_token*/ _, /*vmo_index*/ 0)))));
}
@ -233,7 +235,8 @@ Matcher<std::shared_ptr<FakeTransform>> IsViewportLayer(
return Pointee(
FieldsAre(_ /* id */, view_transform, FakeTransform::kDefaultClipBounds,
FakeTransform::kDefaultOrientation,
FakeTransform::kDefaultOpacity, IsEmpty(),
/*children*/ IsEmpty(),
/*content*/
Pointee(VariantWith<FakeViewport>(FieldsAre(
/* id */ _, IsViewportProperties(view_logical_size),
/* viewport_token */ GetKoids(view_token).second,