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
44 changes: 23 additions & 21 deletions impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
return EntityPass::EntityResult::Skip();
}

std::shared_ptr<Contents> backdrop_contents = nullptr;
std::shared_ptr<Contents> backdrop_filter_contents = nullptr;
if (subpass->backdrop_filter_proc_.has_value()) {
auto texture = pass_context.GetTexture();
// Render the backdrop texture before any of the pass elements.
const auto& proc = subpass->backdrop_filter_proc_.value();
backdrop_contents =
backdrop_filter_contents =
proc(FilterInput::Make(std::move(texture)), subpass->xformation_);

// The subpass will need to read from the current pass texture when
Expand All @@ -288,12 +288,12 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(

auto subpass_coverage =
GetSubpassCoverage(*subpass, Rect::MakeSize(root_pass_size));
if (subpass->cover_whole_screen) {
if (subpass->cover_whole_screen_) {
subpass_coverage = Rect(
position, Size(pass_context.GetRenderTarget().GetRenderTargetSize()));
}
if (backdrop_contents) {
auto backdrop_coverage = backdrop_contents->GetCoverage(Entity{});
if (backdrop_filter_contents) {
auto backdrop_coverage = backdrop_filter_contents->GetCoverage(Entity{});
if (backdrop_coverage.has_value()) {
backdrop_coverage->origin += position;

Expand Down Expand Up @@ -355,7 +355,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
// time they are transient).
if (!subpass->OnRender(renderer, root_pass_size, subpass_target,
subpass_coverage->origin, position, ++pass_depth,
subpass->stencil_depth_, backdrop_contents)) {
subpass->stencil_depth_, backdrop_filter_contents)) {
return EntityPass::EntityResult::Failure();
}

Expand All @@ -371,14 +371,15 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
return EntityPass::EntityResult::Success(element_entity);
}

bool EntityPass::OnRender(ContentContext& renderer,
ISize root_pass_size,
RenderTarget render_target,
Point position,
Point parent_position,
uint32_t pass_depth,
size_t stencil_depth_floor,
std::shared_ptr<Contents> backdrop_contents) const {
bool EntityPass::OnRender(
ContentContext& renderer,
ISize root_pass_size,
RenderTarget render_target,
Point position,
Point parent_position,
uint32_t pass_depth,
size_t stencil_depth_floor,
std::shared_ptr<Contents> backdrop_filter_contents) const {
TRACE_EVENT0("impeller", "EntityPass::OnRender");

auto context = renderer.GetContext();
Expand All @@ -396,10 +397,6 @@ bool EntityPass::OnRender(ContentContext& renderer,
return false;
}

if (!element_entity.ShouldRender(result.pass->GetRenderTargetSize())) {
return true; // Nothing to render.
}

// If the pass context returns a texture, we need to draw it to the current
// pass. We do this because it's faster and takes significantly less memory
// than storing/loading large MSAA textures.
Expand All @@ -413,11 +410,16 @@ bool EntityPass::OnRender(ContentContext& renderer,

Entity msaa_backdrop_entity;
msaa_backdrop_entity.SetContents(std::move(msaa_backdrop_contents));
msaa_backdrop_entity.SetBlendMode(Entity::BlendMode::kSource);
if (!msaa_backdrop_entity.Render(renderer, *result.pass)) {
return false;
}
}

if (!element_entity.ShouldRender(result.pass->GetRenderTargetSize())) {
return true; // Nothing to render.
}

element_entity.SetStencilDepth(element_entity.GetStencilDepth() -
stencil_depth_floor);
if (!element_entity.Render(renderer, *result.pass)) {
Expand All @@ -427,12 +429,12 @@ bool EntityPass::OnRender(ContentContext& renderer,
};

if (backdrop_filter_proc_.has_value()) {
if (!backdrop_contents) {
if (!backdrop_filter_contents) {
return false;
}

Entity backdrop_entity;
backdrop_entity.SetContents(std::move(backdrop_contents));
backdrop_entity.SetContents(std::move(backdrop_filter_contents));
backdrop_entity.SetTransformation(
Matrix::MakeTranslation(Vector3(parent_position - position)));
backdrop_entity.SetStencilDepth(stencil_depth_floor);
Expand Down Expand Up @@ -554,7 +556,7 @@ void EntityPass::SetStencilDepth(size_t stencil_depth) {

void EntityPass::SetBlendMode(Entity::BlendMode blend_mode) {
blend_mode_ = blend_mode;
cover_whole_screen = Entity::BlendModeShouldCoverWholeScreen(blend_mode);
cover_whole_screen_ = Entity::BlendModeShouldCoverWholeScreen(blend_mode);
}

void EntityPass::SetBackdropFilter(std::optional<BackdropFilterProc> proc) {
Expand Down
19 changes: 10 additions & 9 deletions impeller/entity/entity_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,23 @@ class EntityPass {
uint32_t pass_depth,
size_t stencil_depth_floor) const;

bool OnRender(ContentContext& renderer,
ISize root_pass_size,
RenderTarget render_target,
Point position,
Point parent_position,
uint32_t pass_depth,
size_t stencil_depth_floor = 0,
std::shared_ptr<Contents> backdrop_contents = nullptr) const;
bool OnRender(
ContentContext& renderer,
ISize root_pass_size,
RenderTarget render_target,
Point position,
Point parent_position,
uint32_t pass_depth,
size_t stencil_depth_floor = 0,
std::shared_ptr<Contents> backdrop_filter_contents = nullptr) const;

std::vector<Element> elements_;

EntityPass* superpass_ = nullptr;
Matrix xformation_;
size_t stencil_depth_ = 0u;
Entity::BlendMode blend_mode_ = Entity::BlendMode::kSourceOver;
bool cover_whole_screen = false;
bool cover_whole_screen_ = false;

/// This value is incremented whenever something is added to the pass that
/// requires reading from the backdrop texture. Currently, this can happen in
Expand Down