From e2d4118adaae8dac7d61a8a1fccf4deb322feff7 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Tue, 11 Jul 2023 21:51:00 -0700 Subject: [PATCH] [Impeller] Document ColorSourceContents --- impeller/aiks/color_source.cc | 14 ++-- .../entity/contents/color_source_contents.cc | 6 +- .../entity/contents/color_source_contents.h | 74 +++++++++++++++++-- .../contents/color_source_text_contents.cc | 3 +- .../contents/conical_gradient_contents.cc | 8 +- impeller/entity/contents/contents.h | 20 +++++ .../contents/linear_gradient_contents.cc | 10 +-- .../contents/radial_gradient_contents.cc | 10 +-- .../entity/contents/solid_color_contents.cc | 2 +- .../contents/sweep_gradient_contents.cc | 10 +-- .../entity/contents/tiled_texture_contents.cc | 14 ++-- impeller/entity/entity_unittests.cc | 6 +- 12 files changed, 129 insertions(+), 48 deletions(-) diff --git a/impeller/aiks/color_source.cc b/impeller/aiks/color_source.cc index e5c6d13e4e2e7..ccb89c9e64ea9 100644 --- a/impeller/aiks/color_source.cc +++ b/impeller/aiks/color_source.cc @@ -50,7 +50,7 @@ ColorSource ColorSource::MakeLinearGradient(Point start_point, stops = std::move(stops), tile_mode, effect_transform](const Paint& paint) { auto contents = std::make_shared(); - contents->SetOpacity(paint.color.alpha); + contents->SetOpacityFactor(paint.color.alpha); contents->SetColors(colors); contents->SetStops(stops); contents->SetEndPoints(start_point, end_point); @@ -82,7 +82,7 @@ ColorSource ColorSource::MakeConicalGradient(Point center, tile_mode, effect_transform](const Paint& paint) { std::shared_ptr contents = std::make_shared(); - contents->SetOpacity(paint.color.alpha); + contents->SetOpacityFactor(paint.color.alpha); contents->SetColors(colors); contents->SetStops(stops); contents->SetCenterAndRadius(center, radius); @@ -113,7 +113,7 @@ ColorSource ColorSource::MakeRadialGradient(Point center, stops = std::move(stops), tile_mode, effect_transform](const Paint& paint) { auto contents = std::make_shared(); - contents->SetOpacity(paint.color.alpha); + contents->SetOpacityFactor(paint.color.alpha); contents->SetColors(colors); contents->SetStops(stops); contents->SetCenterAndRadius(center, radius); @@ -144,7 +144,7 @@ ColorSource ColorSource::MakeSweepGradient(Point center, stops = std::move(stops), tile_mode, effect_transform](const Paint& paint) { auto contents = std::make_shared(); - contents->SetOpacity(paint.color.alpha); + contents->SetOpacityFactor(paint.color.alpha); contents->SetCenterAndAngles(center, start_angle, end_angle); contents->SetColors(colors); contents->SetStops(stops); @@ -167,7 +167,7 @@ ColorSource ColorSource::MakeImage(std::shared_ptr texture, sampler_descriptor = std::move(sampler_descriptor), effect_transform](const Paint& paint) { auto contents = std::make_shared(); - contents->SetOpacity(paint.color.alpha); + contents->SetOpacityFactor(paint.color.alpha); contents->SetTexture(texture); contents->SetTileModes(x_tile_mode, y_tile_mode); contents->SetSamplerDescriptor(sampler_descriptor); @@ -197,7 +197,7 @@ ColorSource ColorSource::MakeRuntimeEffect( texture_inputs = std::move(texture_inputs)](const Paint& paint) { auto contents = std::make_shared(); - contents->SetOpacity(paint.color.alpha); + contents->SetOpacityFactor(paint.color.alpha); contents->SetRuntimeStage(runtime_stage); contents->SetUniformData(uniform_data); contents->SetTextureInputs(texture_inputs); @@ -213,7 +213,7 @@ ColorSource ColorSource::MakeScene(std::shared_ptr scene_node, result.proc_ = [scene_node = std::move(scene_node), camera_transform](const Paint& paint) { auto contents = std::make_shared(); - contents->SetOpacity(paint.color.alpha); + contents->SetOpacityFactor(paint.color.alpha); contents->SetNode(scene_node); contents->SetCameraTransform(camera_transform); return contents; diff --git a/impeller/entity/contents/color_source_contents.cc b/impeller/entity/contents/color_source_contents.cc index 12918b3ac6d3c..6737702dfc276 100644 --- a/impeller/entity/contents/color_source_contents.cc +++ b/impeller/entity/contents/color_source_contents.cc @@ -22,11 +22,11 @@ const std::shared_ptr& ColorSourceContents::GetGeometry() const { return geometry_; } -void ColorSourceContents::SetOpacity(Scalar alpha) { +void ColorSourceContents::SetOpacityFactor(Scalar alpha) { opacity_ = alpha; } -Scalar ColorSourceContents::GetOpacity() const { +Scalar ColorSourceContents::GetOpacityFactor() const { return opacity_ * inherited_opacity_; } @@ -34,7 +34,7 @@ void ColorSourceContents::SetEffectTransform(Matrix matrix) { inverse_matrix_ = matrix.Invert(); } -const Matrix& ColorSourceContents::GetInverseMatrix() const { +const Matrix& ColorSourceContents::GetInverseEffectTransform() const { return inverse_matrix_; } diff --git a/impeller/entity/contents/color_source_contents.h b/impeller/entity/contents/color_source_contents.h index 0d0392d6e7ccb..d6a580d2126ce 100644 --- a/impeller/entity/contents/color_source_contents.h +++ b/impeller/entity/contents/color_source_contents.h @@ -12,19 +12,83 @@ namespace impeller { +//------------------------------------------------------------------------------ +/// Color sources are geometry-ignostic `Contents` capable of shading any area +/// defined by an `impeller::Geometry`. Conceptually, +/// `impeller::ColorSourceContents` implement a particular color shading +/// behavior. +/// +/// This separation of concerns between geometry and color source output allows +/// Impeller to handle most possible draw combinations in a consistent way. +/// For example: There are color sources for handling solid colors, gradients, +/// textures, custom runtime effects, and even 3D scenes. +/// +/// There are some special rendering exceptions that deviate from this pattern +/// and cross geometry and color source concerns, such as text atlas and image +/// atlas rendering. Special `Contents` exist for rendering these behaviors +/// which don't implement `ColorSourceContents`. +/// +/// @see `impeller::Geometry` +/// class ColorSourceContents : public Contents { public: ColorSourceContents(); ~ColorSourceContents() override; + //---------------------------------------------------------------------------- + /// @brief Set the geometry that this contents will use to render. + /// void SetGeometry(std::shared_ptr geometry); - void SetEffectTransform(Matrix matrix); + //---------------------------------------------------------------------------- + /// @brief Get the geometry that this contents will use to render. + /// + const std::shared_ptr& GetGeometry() const; - const Matrix& GetInverseMatrix() const; + //---------------------------------------------------------------------------- + /// @brief Set the effect transform for this color source. + /// + /// The effect transform is a transformation matrix that is applied to + /// the shaded color output and does not impact geometry in any way. + /// + /// For example: With repeat tiling, any gradient or + /// `TiledTextureContents` could be used with an effect transform to + /// inexpensively draw an infinite scrolling background pattern. + /// + void SetEffectTransform(Matrix matrix); - void SetOpacity(Scalar opacity); + //---------------------------------------------------------------------------- + /// @brief Set the inverted effect transform for this color source. + /// + /// When the effect transform is set via `SetEffectTransform`, the + /// value is inverted upon storage. The reason for this is that most + /// color sources internally use the inverted transform. + /// + /// @return The inverse of the transform set by `SetEffectTransform`. + /// + /// @see `SetEffectTransform` + /// + const Matrix& GetInverseEffectTransform() const; + + //---------------------------------------------------------------------------- + /// @brief Set the opacity factor for this color source. + /// + void SetOpacityFactor(Scalar opacity); + + //---------------------------------------------------------------------------- + /// @brief Get the opacity factor for this color source. + /// + /// This value is is factored into the output of the color source in + /// addition to opacity information that may be supplied any other + /// inputs. + /// + /// @note If set, the output of this method factors factors in the inherited + /// opacity of this `Contents`. + /// + /// @see `Contents::CanInheritOpacity` + /// + Scalar GetOpacityFactor() const; // |Contents| std::optional GetCoverage(const Entity& entity) const override; @@ -39,10 +103,6 @@ class ColorSourceContents : public Contents { // |Contents| void SetInheritedOpacity(Scalar opacity) override; - Scalar GetOpacity() const; - - const std::shared_ptr& GetGeometry() const; - private: std::shared_ptr geometry_; Matrix inverse_matrix_; diff --git a/impeller/entity/contents/color_source_text_contents.cc b/impeller/entity/contents/color_source_text_contents.cc index 48929d3842956..a09e44c8dcb35 100644 --- a/impeller/entity/contents/color_source_text_contents.cc +++ b/impeller/entity/contents/color_source_text_contents.cc @@ -55,7 +55,8 @@ bool ColorSourceTextContents::Render(const ContentContext& renderer, // offset the color source so it behaves as if it were drawn in the original // position. auto effect_transform = - color_source_contents_->GetInverseMatrix().Invert().Translate(-position_); + color_source_contents_->GetInverseEffectTransform().Invert().Translate( + -position_); color_source_contents_->SetEffectTransform(effect_transform); auto new_texture = renderer.MakeSubpass( diff --git a/impeller/entity/contents/conical_gradient_contents.cc b/impeller/entity/contents/conical_gradient_contents.cc index ee979eaec6c00..b3705bf858b87 100644 --- a/impeller/entity/contents/conical_gradient_contents.cc +++ b/impeller/entity/contents/conical_gradient_contents.cc @@ -71,7 +71,7 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.radius = radius_; frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; - frag_info.alpha = GetOpacity(); + frag_info.alpha = GetOpacityFactor(); if (focus_) { frag_info.focus = focus_.value(); frag_info.focus_radius = focus_radius_; @@ -91,7 +91,7 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * entity.GetTransformation(); - frame_info.matrix = GetInverseMatrix(); + frame_info.matrix = GetInverseEffectTransform(); Command cmd; cmd.label = "ConicalGradientSSBOFill"; @@ -143,7 +143,7 @@ bool ConicalGradientContents::RenderTexture(const ContentContext& renderer, frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale(); - frag_info.alpha = GetOpacity(); + frag_info.alpha = GetOpacityFactor(); frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width, 0.5 / gradient_texture->GetSize().height); if (focus_) { @@ -159,7 +159,7 @@ bool ConicalGradientContents::RenderTexture(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.mvp = geometry_result.transform; - frame_info.matrix = GetInverseMatrix(); + frame_info.matrix = GetInverseEffectTransform(); Command cmd; cmd.label = "ConicalGradientFill"; diff --git a/impeller/entity/contents/contents.h b/impeller/entity/contents/contents.h index 62b1b155df96b..a80b82560d8e1 100644 --- a/impeller/entity/contents/contents.h +++ b/impeller/entity/contents/contents.h @@ -63,35 +63,45 @@ class Contents { const Entity& entity, RenderPass& pass) const = 0; + //---------------------------------------------------------------------------- /// @brief Get the screen space bounding rectangle that this contents affects. + /// virtual std::optional GetCoverage(const Entity& entity) const = 0; + //---------------------------------------------------------------------------- /// @brief Hint that specifies the coverage area of this Contents that will /// actually be used during rendering. This is for optimization /// purposes only and can not be relied on as a clip. May optionally /// affect the result of `GetCoverage()`. + /// void SetCoverageHint(std::optional coverage_hint); const std::optional& GetCoverageHint() const; + //---------------------------------------------------------------------------- /// @brief Whether this Contents only emits opaque source colors from the /// fragment stage. This value does not account for any entity /// properties (e.g. the blend mode), clips/visibility culling, or /// inherited opacity. + /// virtual bool IsOpaque() const; + //---------------------------------------------------------------------------- /// @brief Given the current screen space bounding rectangle of the stencil, /// return the expected stencil coverage after this draw call. This /// should only be implemented for contents that may write to the /// stencil buffer. + /// virtual StencilCoverage GetStencilCoverage( const Entity& entity, const std::optional& current_stencil_coverage) const; + //---------------------------------------------------------------------------- /// @brief Render this contents to a snapshot, respecting the entity's /// transform, path, stencil depth, and blend mode. /// The result texture size is always the size of /// `GetCoverage(entity)`. + /// virtual std::optional RenderToSnapshot( const ContentContext& renderer, const Entity& entity, @@ -103,15 +113,18 @@ class Contents { virtual bool ShouldRender(const Entity& entity, const std::optional& stencil_coverage) const; + //---------------------------------------------------------------------------- /// @brief Return the color source's intrinsic size, if available. /// /// For example, a gradient has a size based on its end and beginning /// points, ignoring any tiling. Solid colors and runtime effects have /// no size. + /// std::optional GetColorSourceSize() const; void SetColorSourceSize(Size size); + //---------------------------------------------------------------------------- /// @brief Whether or not this contents can accept the opacity peephole /// optimization. /// @@ -120,22 +133,28 @@ class Contents { /// a way that makes accepting opacity impossible. It is always safe /// to return false, especially if computing overlap would be /// computationally expensive. + /// virtual bool CanInheritOpacity(const Entity& entity) const; + //---------------------------------------------------------------------------- /// @brief Inherit the provided opacity. /// /// Use of this method is invalid if CanAcceptOpacity returns false. + /// virtual void SetInheritedOpacity(Scalar opacity); + //---------------------------------------------------------------------------- /// @brief Returns a color if this Contents will flood the given `target_size` /// with a color. This output color is the "Source" color that will be /// used for the Entity's blend operation. /// /// This is useful for absorbing full screen solid color draws into /// subpass clear colors. + /// virtual std::optional AsBackgroundColor(const Entity& entity, ISize target_size) const; + //---------------------------------------------------------------------------- /// @brief If possible, applies a color filter to this contents inputs on /// the CPU. /// @@ -150,6 +169,7 @@ class Contents { /// @return True if the color filter was able to be fully applied to all /// all relevant inputs. Otherwise, this operation is a no-op and /// false is returned. + /// [[nodiscard]] virtual bool ApplyColorFilter( const ColorFilterProc& color_filter_proc); diff --git a/impeller/entity/contents/linear_gradient_contents.cc b/impeller/entity/contents/linear_gradient_contents.cc index f1542919bb487..efe021a52900c 100644 --- a/impeller/entity/contents/linear_gradient_contents.cc +++ b/impeller/entity/contents/linear_gradient_contents.cc @@ -45,7 +45,7 @@ void LinearGradientContents::SetTileMode(Entity::TileMode tile_mode) { } bool LinearGradientContents::IsOpaque() const { - if (GetOpacity() < 1 || tile_mode_ == Entity::TileMode::kDecal) { + if (GetOpacityFactor() < 1 || tile_mode_ == Entity::TileMode::kDecal) { return false; } for (auto color : colors_) { @@ -84,7 +84,7 @@ bool LinearGradientContents::RenderTexture(const ContentContext& renderer, frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale(); - frag_info.alpha = GetOpacity(); + frag_info.alpha = GetOpacityFactor(); frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width, 0.5 / gradient_texture->GetSize().height); @@ -93,7 +93,7 @@ bool LinearGradientContents::RenderTexture(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.mvp = geometry_result.transform; - frame_info.matrix = GetInverseMatrix(); + frame_info.matrix = GetInverseEffectTransform(); Command cmd; cmd.label = "LinearGradientFill"; @@ -140,7 +140,7 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.end_point = end_point_; frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; - frag_info.alpha = GetOpacity(); + frag_info.alpha = GetOpacityFactor(); auto& host_buffer = pass.GetTransientsBuffer(); auto colors = CreateGradientColors(colors_, stops_); @@ -153,7 +153,7 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * entity.GetTransformation(); - frame_info.matrix = GetInverseMatrix(); + frame_info.matrix = GetInverseEffectTransform(); Command cmd; cmd.label = "LinearGradientSSBOFill"; diff --git a/impeller/entity/contents/radial_gradient_contents.cc b/impeller/entity/contents/radial_gradient_contents.cc index 9da36e6beb31c..2527b54898258 100644 --- a/impeller/entity/contents/radial_gradient_contents.cc +++ b/impeller/entity/contents/radial_gradient_contents.cc @@ -46,7 +46,7 @@ const std::vector& RadialGradientContents::GetStops() const { } bool RadialGradientContents::IsOpaque() const { - if (GetOpacity() < 1 || tile_mode_ == Entity::TileMode::kDecal) { + if (GetOpacityFactor() < 1 || tile_mode_ == Entity::TileMode::kDecal) { return false; } for (auto color : colors_) { @@ -77,7 +77,7 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.radius = radius_; frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; - frag_info.alpha = GetOpacity(); + frag_info.alpha = GetOpacityFactor(); auto& host_buffer = pass.GetTransientsBuffer(); auto colors = CreateGradientColors(colors_, stops_); @@ -90,7 +90,7 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * entity.GetTransformation(); - frame_info.matrix = GetInverseMatrix(); + frame_info.matrix = GetInverseEffectTransform(); Command cmd; cmd.label = "RadialGradientSSBOFill"; @@ -142,7 +142,7 @@ bool RadialGradientContents::RenderTexture(const ContentContext& renderer, frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale(); - frag_info.alpha = GetOpacity(); + frag_info.alpha = GetOpacityFactor(); frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width, 0.5 / gradient_texture->GetSize().height); @@ -151,7 +151,7 @@ bool RadialGradientContents::RenderTexture(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.mvp = geometry_result.transform; - frame_info.matrix = GetInverseMatrix(); + frame_info.matrix = GetInverseEffectTransform(); Command cmd; cmd.label = "RadialGradientFill"; diff --git a/impeller/entity/contents/solid_color_contents.cc b/impeller/entity/contents/solid_color_contents.cc index f0392e7df995d..02ecbf67365ad 100644 --- a/impeller/entity/contents/solid_color_contents.cc +++ b/impeller/entity/contents/solid_color_contents.cc @@ -21,7 +21,7 @@ void SolidColorContents::SetColor(Color color) { } Color SolidColorContents::GetColor() const { - return color_.WithAlpha(color_.alpha * GetOpacity()); + return color_.WithAlpha(color_.alpha * GetOpacityFactor()); } bool SolidColorContents::IsOpaque() const { diff --git a/impeller/entity/contents/sweep_gradient_contents.cc b/impeller/entity/contents/sweep_gradient_contents.cc index 951ff4f3ad60e..c730bb3d70452 100644 --- a/impeller/entity/contents/sweep_gradient_contents.cc +++ b/impeller/entity/contents/sweep_gradient_contents.cc @@ -51,7 +51,7 @@ const std::vector& SweepGradientContents::GetStops() const { } bool SweepGradientContents::IsOpaque() const { - if (GetOpacity() < 1 || tile_mode_ == Entity::TileMode::kDecal) { + if (GetOpacityFactor() < 1 || tile_mode_ == Entity::TileMode::kDecal) { return false; } for (auto color : colors_) { @@ -83,7 +83,7 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.scale = scale_; frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; - frag_info.alpha = GetOpacity(); + frag_info.alpha = GetOpacityFactor(); auto& host_buffer = pass.GetTransientsBuffer(); auto colors = CreateGradientColors(colors_, stops_); @@ -96,7 +96,7 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * entity.GetTransformation(); - frame_info.matrix = GetInverseMatrix(); + frame_info.matrix = GetInverseEffectTransform(); Command cmd; cmd.label = "SweepGradientSSBOFill"; @@ -149,7 +149,7 @@ bool SweepGradientContents::RenderTexture(const ContentContext& renderer, frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale(); frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; - frag_info.alpha = GetOpacity(); + frag_info.alpha = GetOpacityFactor(); frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width, 0.5 / gradient_texture->GetSize().height); @@ -158,7 +158,7 @@ bool SweepGradientContents::RenderTexture(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.mvp = geometry_result.transform; - frame_info.matrix = GetInverseMatrix(); + frame_info.matrix = GetInverseEffectTransform(); Command cmd; cmd.label = "SweepGradientFill"; diff --git a/impeller/entity/contents/tiled_texture_contents.cc b/impeller/entity/contents/tiled_texture_contents.cc index 2f2874dd3350f..c5172b71ca71b 100644 --- a/impeller/entity/contents/tiled_texture_contents.cc +++ b/impeller/entity/contents/tiled_texture_contents.cc @@ -100,7 +100,7 @@ bool TiledTextureContents::UsesEmulatedTileMode( // |Contents| bool TiledTextureContents::IsOpaque() const { - if (GetOpacity() < 1 || x_tile_mode_ == Entity::TileMode::kDecal || + if (GetOpacityFactor() < 1 || x_tile_mode_ == Entity::TileMode::kDecal || y_tile_mode_ == Entity::TileMode::kDecal) { return false; } @@ -128,8 +128,8 @@ bool TiledTextureContents::Render(const ContentContext& renderer, auto& host_buffer = pass.GetTransientsBuffer(); auto geometry_result = GetGeometry()->GetPositionUVBuffer( - Rect({0, 0}, Size(texture_size)), GetInverseMatrix(), renderer, entity, - pass); + Rect({0, 0}, Size(texture_size)), GetInverseEffectTransform(), renderer, + entity, pass); bool uses_emulated_tile_mode = UsesEmulatedTileMode(renderer.GetDeviceCapabilities()); @@ -158,11 +158,11 @@ bool TiledTextureContents::Render(const ContentContext& renderer, FS::FragInfo frag_info; frag_info.x_tile_mode = static_cast(x_tile_mode_); frag_info.y_tile_mode = static_cast(y_tile_mode_); - frag_info.alpha = GetOpacity(); + frag_info.alpha = GetOpacityFactor(); FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info)); } else { TextureFillFragmentShader::FragInfo frag_info; - frag_info.alpha = GetOpacity(); + frag_info.alpha = GetOpacityFactor(); TextureFillFragmentShader::BindFragInfo( cmd, host_buffer.EmplaceUniform(frag_info)); } @@ -202,12 +202,12 @@ std::optional TiledTextureContents::RenderToSnapshot( const std::optional& sampler_descriptor, bool msaa_enabled, const std::string& label) const { - if (GetInverseMatrix().IsIdentity()) { + if (GetInverseEffectTransform().IsIdentity()) { return Snapshot{ .texture = texture_, .transform = entity.GetTransformation(), .sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_), - .opacity = GetOpacity(), + .opacity = GetOpacityFactor(), }; } diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 91706559490a4..05818e84270f7 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -2168,14 +2168,14 @@ TEST_P(EntityTest, InheritOpacityTest) { auto tiled_texture = std::make_shared(); tiled_texture->SetGeometry( Geometry::MakeRect(Rect::MakeLTRB(100, 100, 200, 200))); - tiled_texture->SetOpacity(0.5); + tiled_texture->SetOpacityFactor(0.5); ASSERT_TRUE(tiled_texture->CanInheritOpacity(entity)); tiled_texture->SetInheritedOpacity(0.5); - ASSERT_EQ(tiled_texture->GetOpacity(), 0.25); + ASSERT_EQ(tiled_texture->GetOpacityFactor(), 0.25); tiled_texture->SetInheritedOpacity(0.5); - ASSERT_EQ(tiled_texture->GetOpacity(), 0.25); + ASSERT_EQ(tiled_texture->GetOpacityFactor(), 0.25); // Text contents can accept opacity if the text frames do not // overlap