[Impeller] Obtain the subpass texture after calling OnRender (flutter/engine#41052)

[Impeller] Obtain the subpass texture after calling OnRender
This commit is contained in:
Jason Simmons
2023-04-11 07:41:08 -07:00
committed by GitHub
parent a365cec57c
commit c9147eae32

View File

@@ -404,28 +404,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
subpass->GetTotalPassReads(renderer) > 0, //
clear_color_);
auto subpass_texture =
subpass_target.GetRenderTarget().GetRenderTargetTexture();
if (!subpass_texture) {
return EntityPass::EntityResult::Failure();
}
auto offscreen_texture_contents =
subpass->delegate_->CreateContentsForSubpassTarget(
subpass_texture,
Matrix::MakeTranslation(Vector3{-global_pass_position}) *
subpass->xformation_);
if (!offscreen_texture_contents) {
// This is an error because the subpass delegate said the pass couldn't
// be collapsed into its parent. Yet, when asked how it want's to
// postprocess the offscreen texture, it couldn't give us an answer.
//
// Theoretically, we could collapse the pass now. But that would be
// wasteful as we already have the offscreen texture and we don't want
// to discard it without ever using it. Just make the delegate do the
// right thing.
if (!subpass_target.GetRenderTarget().GetRenderTargetTexture()) {
return EntityPass::EntityResult::Failure();
}
@@ -445,6 +424,28 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
return EntityPass::EntityResult::Failure();
}
// The subpass target's texture may have changed during OnRender.
auto subpass_texture =
subpass_target.GetRenderTarget().GetRenderTargetTexture();
auto offscreen_texture_contents =
subpass->delegate_->CreateContentsForSubpassTarget(
subpass_texture,
Matrix::MakeTranslation(Vector3{-global_pass_position}) *
subpass->xformation_);
if (!offscreen_texture_contents) {
// This is an error because the subpass delegate said the pass couldn't
// be collapsed into its parent. Yet, when asked how it want's to
// postprocess the offscreen texture, it couldn't give us an answer.
//
// Theoretically, we could collapse the pass now. But that would be
// wasteful as we already have the offscreen texture and we don't want
// to discard it without ever using it. Just make the delegate do the
// right thing.
return EntityPass::EntityResult::Failure();
}
element_entity.SetContents(std::move(offscreen_texture_contents));
element_entity.SetStencilDepth(subpass->stencil_depth_);
element_entity.SetBlendMode(subpass->blend_mode_);