Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
4 changes: 2 additions & 2 deletions impeller/aiks/paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::shared_ptr<Contents> Paint::CreateContentsForGeometry(
auto& source = color_source.value();
auto contents = source();
contents->SetGeometry(std::move(geometry));
contents->SetAlpha(color.alpha);
contents->SetOpacity(color.alpha);
return contents;
}
auto solid_color = std::make_shared<SolidColorContents>();
Expand All @@ -46,7 +46,7 @@ std::shared_ptr<Contents> Paint::CreateContentsForGeometry(
auto& source = color_source.value();
auto contents = source();
contents->SetGeometry(geometry);
contents->SetAlpha(color.alpha);
contents->SetOpacity(color.alpha);
return contents;
}
auto solid_color = std::make_shared<SolidColorContents>();
Expand Down
2 changes: 1 addition & 1 deletion impeller/aiks/paint_pass_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool OpacityPeepholePassDelegate::CanCollapseIntoParentPass(
auto had_subpass = entity_pass->IterateUntilSubpass(
[&all_coverages, &all_can_accept](Entity& entity) {
auto contents = entity.GetContents();
if (!contents->CanAcceptOpacity(entity)) {
if (!contents->CanInheritOpacity(entity)) {
all_can_accept = false;
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/clip_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool ClipContents::ShouldRender(
return true;
}

bool ClipContents::CanAcceptOpacity(const Entity& entity) const {
bool ClipContents::CanInheritOpacity(const Entity& entity) const {
return true;
}

Expand Down Expand Up @@ -172,7 +172,7 @@ bool ClipRestoreContents::ShouldRender(
return true;
}

bool ClipRestoreContents::CanAcceptOpacity(const Entity& entity) const {
bool ClipRestoreContents::CanInheritOpacity(const Entity& entity) const {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/clip_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ClipContents final : public Contents {
const Entity& entity,
RenderPass& pass) const override;
// |Contents|
bool CanAcceptOpacity(const Entity& entity) const override;
bool CanInheritOpacity(const Entity& entity) const override;

// |Contents|
void SetInheritedOpacity(Scalar opacity) override;
Expand Down Expand Up @@ -84,7 +84,7 @@ class ClipRestoreContents final : public Contents {
RenderPass& pass) const override;

// |Contents|
bool CanAcceptOpacity(const Entity& entity) const override;
bool CanInheritOpacity(const Entity& entity) const override;

// |Contents|
void SetInheritedOpacity(Scalar opacity) override;
Expand Down
12 changes: 6 additions & 6 deletions impeller/entity/contents/color_source_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const std::shared_ptr<Geometry>& ColorSourceContents::GetGeometry() const {
return geometry_;
}

void ColorSourceContents::SetAlpha(Scalar alpha) {
alpha_ = alpha;
void ColorSourceContents::SetOpacity(Scalar alpha) {
opacity_ = alpha;
}

Scalar ColorSourceContents::GetAlpha() const {
return alpha_;
Scalar ColorSourceContents::GetOpacity() const {
return opacity_ * inherited_opacity_;
}

void ColorSourceContents::SetEffectTransform(Matrix matrix) {
Expand All @@ -42,12 +42,12 @@ std::optional<Rect> ColorSourceContents::GetCoverage(
return geometry_->GetCoverage(entity.GetTransformation());
};

bool ColorSourceContents::CanAcceptOpacity(const Entity& entity) const {
bool ColorSourceContents::CanInheritOpacity(const Entity& entity) const {
return true;
}

void ColorSourceContents::SetInheritedOpacity(Scalar opacity) {
SetAlpha(GetAlpha() * opacity);
inherited_opacity_ = opacity;
}

bool ColorSourceContents::ShouldRender(
Expand Down
13 changes: 7 additions & 6 deletions impeller/entity/contents/color_source_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ColorSourceContents : public Contents {

const Matrix& GetInverseMatrix() const;

void SetAlpha(Scalar alpha);
void SetOpacity(Scalar opacity);

// |Contents|
std::optional<Rect> GetCoverage(const Entity& entity) const override;
Expand All @@ -33,21 +33,22 @@ class ColorSourceContents : public Contents {
bool ShouldRender(const Entity& entity,
const std::optional<Rect>& stencil_coverage) const override;

// | Contents|
bool CanAcceptOpacity(const Entity& entity) const override;
// |Contents|
bool CanInheritOpacity(const Entity& entity) const override;

// | Contents|
// |Contents|
void SetInheritedOpacity(Scalar opacity) override;

Scalar GetAlpha() const;
Scalar GetOpacity() const;

protected:
const std::shared_ptr<Geometry>& GetGeometry() const;

private:
std::shared_ptr<Geometry> geometry_;
Matrix inverse_matrix_;
Scalar alpha_ = 1.0;
Scalar opacity_ = 1.0;
Scalar inherited_opacity_ = 1.0;

FML_DISALLOW_COPY_AND_ASSIGN(ColorSourceContents);
};
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/conical_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer,
frag_info.center = center_;
frag_info.radius = radius_;
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.alpha = GetAlpha();
frag_info.alpha = GetOpacity();
if (focus_) {
frag_info.focus = focus_.value();
frag_info.focus_radius = focus_radius_;
Expand Down Expand Up @@ -141,7 +141,7 @@ bool ConicalGradientContents::RenderTexture(const ContentContext& renderer,
frag_info.radius = radius_;
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale();
frag_info.alpha = GetAlpha();
frag_info.alpha = GetOpacity();
frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width,
0.5 / gradient_texture->GetSize().height);
if (focus_) {
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ std::optional<Snapshot> Contents::RenderToSnapshot(
return snapshot;
}

bool Contents::CanAcceptOpacity(const Entity& entity) const {
bool Contents::CanInheritOpacity(const Entity& entity) const {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ 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 CanAcceptOpacity(const Entity& entity) const;
virtual bool CanInheritOpacity(const Entity& entity) const;

/// @brief Inherit the provided opacity.
///
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/linear_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool LinearGradientContents::RenderTexture(const ContentContext& renderer,
frag_info.end_point = end_point_;
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale();
frag_info.alpha = GetAlpha();
frag_info.alpha = GetOpacity();
frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width,
0.5 / gradient_texture->GetSize().height);

Expand Down Expand Up @@ -126,7 +126,7 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer,
frag_info.start_point = start_point_;
frag_info.end_point = end_point_;
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.alpha = GetAlpha();
frag_info.alpha = GetOpacity();

auto& host_buffer = pass.GetTransientsBuffer();
auto colors = CreateGradientColors(colors_, stops_);
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/radial_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer,
frag_info.center = center_;
frag_info.radius = radius_;
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.alpha = GetAlpha();
frag_info.alpha = GetOpacity();

auto& host_buffer = pass.GetTransientsBuffer();
auto colors = CreateGradientColors(colors_, stops_);
Expand Down Expand Up @@ -128,7 +128,7 @@ bool RadialGradientContents::RenderTexture(const ContentContext& renderer,
frag_info.radius = radius_;
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale();
frag_info.alpha = GetAlpha();
frag_info.alpha = GetOpacity();
frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width,
0.5 / gradient_texture->GetSize().height);

Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void RuntimeEffectContents::SetTextureInputs(
texture_inputs_ = std::move(texture_inputs);
}

bool RuntimeEffectContents::CanAcceptOpacity(const Entity& entity) const {
bool RuntimeEffectContents::CanInheritOpacity(const Entity& entity) const {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/runtime_effect_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RuntimeEffectContents final : public ColorSourceContents {
void SetTextureInputs(std::vector<TextureInput> texture_inputs);

// | Contents|
bool CanAcceptOpacity(const Entity& entity) const override;
bool CanInheritOpacity(const Entity& entity) const override;

// |Contents|
bool Render(const ContentContext& renderer,
Expand Down
13 changes: 6 additions & 7 deletions impeller/entity/contents/solid_color_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,27 @@ void SolidColorContents::SetColor(Color color) {
color_ = color;
}

const Color& SolidColorContents::GetColor() const {
return color_;
Color SolidColorContents::GetColor() const {
return color_.WithAlpha(color_.alpha * inherited_opacity_);
}

void SolidColorContents::SetGeometry(std::shared_ptr<Geometry> geometry) {
geometry_ = std::move(geometry);
}

// | Contents|
bool SolidColorContents::CanAcceptOpacity(const Entity& entity) const {
bool SolidColorContents::CanInheritOpacity(const Entity& entity) const {
return true;
}

// | Contents|
void SolidColorContents::SetInheritedOpacity(Scalar opacity) {
auto color = color_;
color_ = color.WithAlpha(color.alpha * opacity);
inherited_opacity_ = opacity;
}

std::optional<Rect> SolidColorContents::GetCoverage(
const Entity& entity) const {
if (color_.IsTransparent()) {
if (GetColor().IsTransparent()) {
return std::nullopt;
}
if (geometry_ == nullptr) {
Expand Down Expand Up @@ -86,7 +85,7 @@ bool SolidColorContents::Render(const ContentContext& renderer,
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));

FS::FragInfo frag_info;
frag_info.color = color_.Premultiply();
frag_info.color = GetColor().Premultiply();
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));

if (!pass.AddCommand(std::move(cmd))) {
Expand Down
5 changes: 3 additions & 2 deletions impeller/entity/contents/solid_color_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class SolidColorContents final : public Contents {

void SetColor(Color color);

const Color& GetColor() const;
Color GetColor() const;

// | Contents|
bool CanAcceptOpacity(const Entity& entity) const override;
bool CanInheritOpacity(const Entity& entity) const override;

// | Contents|
void SetInheritedOpacity(Scalar opacity) override;
Expand All @@ -57,6 +57,7 @@ class SolidColorContents final : public Contents {
std::shared_ptr<Geometry> geometry_;

Color color_;
Scalar inherited_opacity_ = 1.0;

FML_DISALLOW_COPY_AND_ASSIGN(SolidColorContents);
};
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/sweep_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer,
frag_info.bias = bias_;
frag_info.scale = scale_;
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.alpha = GetAlpha();
frag_info.alpha = GetOpacity();

auto& host_buffer = pass.GetTransientsBuffer();
auto colors = CreateGradientColors(colors_, stops_);
Expand Down Expand Up @@ -135,7 +135,7 @@ bool SweepGradientContents::RenderTexture(const ContentContext& renderer,
frag_info.scale = scale_;
frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale();
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
frag_info.alpha = GetAlpha();
frag_info.alpha = GetOpacity();
frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width,
0.5 / gradient_texture->GetSize().height);

Expand Down
16 changes: 8 additions & 8 deletions impeller/entity/contents/text_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ void TextContents::SetColor(Color color) {
}

Color TextContents::GetColor() const {
return color_;
return color_.WithAlpha(color_.alpha * inherited_opacity_);
}

bool TextContents::CanAcceptOpacity(const Entity& entity) const {
bool TextContents::CanInheritOpacity(const Entity& entity) const {
return !frame_.MaybeHasOverlapping();
}

void TextContents::SetInheritedOpacity(Scalar opacity) {
auto color = color_;
color_ = color.WithAlpha(color.alpha * opacity);
inherited_opacity_ = opacity;
}

void TextContents::SetInverseMatrix(Matrix matrix) {
Expand Down Expand Up @@ -230,13 +229,14 @@ bool TextContents::RenderSdf(const ContentContext& renderer,
cmd.stencil_reference = entity.GetStencilDepth();

return CommonRender<GlyphAtlasSdfPipeline>(
renderer, entity, pass, color_, frame_, inverse_matrix_, atlas, cmd);
renderer, entity, pass, GetColor(), frame_, inverse_matrix_, atlas, cmd);
}

bool TextContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
if (color_.IsTransparent()) {
auto color = GetColor();
if (color.IsTransparent()) {
return true;
}

Expand Down Expand Up @@ -264,8 +264,8 @@ bool TextContents::Render(const ContentContext& renderer,
cmd.pipeline = renderer.GetGlyphAtlasPipeline(opts);
cmd.stencil_reference = entity.GetStencilDepth();

return CommonRender<GlyphAtlasPipeline>(renderer, entity, pass, color_,
frame_, inverse_matrix_, atlas, cmd);
return CommonRender<GlyphAtlasPipeline>(renderer, entity, pass, color, frame_,
inverse_matrix_, atlas, cmd);
}

} // namespace impeller
3 changes: 2 additions & 1 deletion impeller/entity/contents/text_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TextContents final : public Contents {

Color GetColor() const;

bool CanAcceptOpacity(const Entity& entity) const override;
bool CanInheritOpacity(const Entity& entity) const override;

void SetInheritedOpacity(Scalar opacity) override;

Expand All @@ -56,6 +56,7 @@ class TextContents final : public Contents {
private:
TextFrame frame_;
Color color_;
Scalar inherited_opacity_;
mutable std::shared_ptr<LazyGlyphAtlas> lazy_atlas_;
Matrix inverse_matrix_;

Expand Down
Loading