Skip to content

Commit

Permalink
switched up FromSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke committed Feb 29, 2024
1 parent 9da273f commit ba6d65f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 33 deletions.
6 changes: 3 additions & 3 deletions impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ static std::optional<Entity> AdvancedBlend(
if (!dst_snapshot.has_value()) {
return std::nullopt;
}
return Entity::FromSnapshot(dst_snapshot, entity.GetBlendMode(),
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode(),
entity.GetClipDepth());
}
auto maybe_src_uvs = src_snapshot->GetCoverageUVs(coverage);
if (!maybe_src_uvs.has_value()) {
if (!dst_snapshot.has_value()) {
return std::nullopt;
}
return Entity::FromSnapshot(dst_snapshot, entity.GetBlendMode(),
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode(),
entity.GetClipDepth());
}
src_uvs = maybe_src_uvs.value();
Expand Down Expand Up @@ -426,7 +426,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
}

if (blend_mode == BlendMode::kDestination) {
return Entity::FromSnapshot(dst_snapshot, entity.GetBlendMode(),
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode(),
entity.GetClipDepth());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,8 @@ Entity ApplyBlurStyle(FilterContents::BlurStyle blur_style,
Entity blurred =
ApplyClippedBlurStyle(Entity::ClipOperation::kIntersect, entity,
input, input_snapshot, std::move(blur_entity));
Entity snapshot_entity =
Entity::FromSnapshot(input_snapshot, entity.GetBlendMode(),
entity.GetClipDepth())
.value();
Entity snapshot_entity = Entity::FromSnapshot(
input_snapshot, entity.GetBlendMode(), entity.GetClipDepth());
Entity result;
result.SetContents(Contents::MakeAnonymous(
fml::MakeCopyable([blurred = blurred.Clone(),
Expand Down Expand Up @@ -568,12 +566,8 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
.opacity = input_snapshot->opacity},
entity.GetBlendMode(), entity.GetClipDepth());

if (!blur_output_entity.has_value()) {
return std::nullopt;
}

return ApplyBlurStyle(blur_style_, entity, inputs[0], input_snapshot.value(),
std::move(blur_output_entity.value()));
std::move(blur_output_entity));
}

Scalar GaussianBlurFilterContents::CalculateBlurRadius(Scalar sigma) {
Expand Down
10 changes: 7 additions & 3 deletions impeller/entity/contents/filters/local_matrix_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ std::optional<Entity> LocalMatrixFilterContents::RenderFilter(
const Matrix& effect_transform,
const Rect& coverage,
const std::optional<Rect>& coverage_hint) const {
return Entity::FromSnapshot(
inputs[0]->GetSnapshot("LocalMatrix", renderer, entity),
entity.GetBlendMode(), entity.GetClipDepth());
std::optional<Snapshot> snapshot =
inputs[0]->GetSnapshot("LocalMatrix", renderer, entity);
if (!snapshot.has_value()) {
return std::nullopt;
}
return Entity::FromSnapshot(snapshot.value(), entity.GetBlendMode(),
entity.GetClipDepth());
}

} // namespace impeller
5 changes: 4 additions & 1 deletion impeller/entity/contents/filters/matrix_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ std::optional<Entity> MatrixFilterContents::RenderFilter(
snapshot->transform;

snapshot->sampler_descriptor = sampler_descriptor_;
return Entity::FromSnapshot(snapshot, entity.GetBlendMode(),
if (!snapshot.has_value()) {
return std::nullopt;
}
return Entity::FromSnapshot(snapshot.value(), entity.GetBlendMode(),
entity.GetClipDepth());
}

Expand Down
21 changes: 8 additions & 13 deletions impeller/entity/entity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,21 @@

namespace impeller {

std::optional<Entity> Entity::FromSnapshot(
const std::optional<Snapshot>& snapshot,
BlendMode blend_mode,
uint32_t clip_depth) {
if (!snapshot.has_value()) {
return std::nullopt;
}

auto texture_rect = Rect::MakeSize(snapshot->texture->GetSize());
Entity Entity::FromSnapshot(const Snapshot& snapshot,
BlendMode blend_mode,
uint32_t clip_depth) {
auto texture_rect = Rect::MakeSize(snapshot.texture->GetSize());

auto contents = TextureContents::MakeRect(texture_rect);
contents->SetTexture(snapshot->texture);
contents->SetSamplerDescriptor(snapshot->sampler_descriptor);
contents->SetTexture(snapshot.texture);
contents->SetSamplerDescriptor(snapshot.sampler_descriptor);
contents->SetSourceRect(texture_rect);
contents->SetOpacity(snapshot->opacity);
contents->SetOpacity(snapshot.opacity);

Entity entity;
entity.SetBlendMode(blend_mode);
entity.SetClipDepth(clip_depth);
entity.SetTransform(snapshot->transform);
entity.SetTransform(snapshot.transform);
entity.SetContents(contents);
return entity;
}
Expand Down
7 changes: 3 additions & 4 deletions impeller/entity/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ class Entity {
};

/// @brief Create an entity that can be used to render a given snapshot.
static std::optional<Entity> FromSnapshot(
const std::optional<Snapshot>& snapshot,
BlendMode blend_mode = BlendMode::kSourceOver,
uint32_t clip_depth = 0);
static Entity FromSnapshot(const Snapshot& snapshot,
BlendMode blend_mode = BlendMode::kSourceOver,
uint32_t clip_depth = 0);

Entity();

Expand Down

0 comments on commit ba6d65f

Please sign in to comment.