|
19 | 19 | #include "impeller/entity/contents/filters/color_filter_contents.h"
|
20 | 20 | #include "impeller/entity/contents/filters/inputs/filter_input.h"
|
21 | 21 | #include "impeller/entity/contents/framebuffer_blend_contents.h"
|
22 |
| -#include "impeller/entity/contents/solid_color_contents.h" |
23 | 22 | #include "impeller/entity/contents/texture_contents.h"
|
24 | 23 | #include "impeller/entity/entity.h"
|
25 | 24 | #include "impeller/entity/inline_pass_context.h"
|
@@ -340,9 +339,9 @@ bool EntityPass::Render(ContentContext& renderer,
|
340 | 339 | // and then blit the results onto the onscreen texture. If using this branch,
|
341 | 340 | // there's no need to set up a stencil attachment on the root render target.
|
342 | 341 | if (reads_from_onscreen_backdrop) {
|
343 |
| - auto offscreen_target = |
344 |
| - CreateRenderTarget(renderer, root_render_target.GetRenderTargetSize(), |
345 |
| - GetClearColor(render_target.GetRenderTargetSize())); |
| 342 | + auto offscreen_target = CreateRenderTarget( |
| 343 | + renderer, root_render_target.GetRenderTargetSize(), |
| 344 | + GetClearColorOrDefault(render_target.GetRenderTargetSize())); |
346 | 345 |
|
347 | 346 | if (!OnRender(renderer, // renderer
|
348 | 347 | capture, // capture
|
@@ -447,7 +446,8 @@ bool EntityPass::Render(ContentContext& renderer,
|
447 | 446 | }
|
448 | 447 |
|
449 | 448 | // Set up the clear color of the root pass.
|
450 |
| - color0.clear_color = GetClearColor(render_target.GetRenderTargetSize()); |
| 449 | + color0.clear_color = |
| 450 | + GetClearColorOrDefault(render_target.GetRenderTargetSize()); |
451 | 451 | root_render_target.SetColorAttachment(color0, 0);
|
452 | 452 |
|
453 | 453 | EntityPassTarget pass_target(
|
@@ -600,9 +600,9 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
|
600 | 600 | }
|
601 | 601 |
|
602 | 602 | auto subpass_target = CreateRenderTarget(
|
603 |
| - renderer, // renderer |
604 |
| - subpass_size, // size |
605 |
| - subpass->GetClearColor(subpass_size)); // clear_color |
| 603 | + renderer, // renderer |
| 604 | + subpass_size, // size |
| 605 | + subpass->GetClearColorOrDefault(subpass_size)); // clear_color |
606 | 606 |
|
607 | 607 | if (!subpass_target.IsValid()) {
|
608 | 608 | VALIDATION_LOG << "Subpass render target is invalid.";
|
@@ -845,8 +845,7 @@ bool EntityPass::OnRender(
|
845 | 845 | }
|
846 | 846 | auto clear_color_size = pass_target.GetRenderTarget().GetRenderTargetSize();
|
847 | 847 |
|
848 |
| - if (!collapsed_parent_pass && |
849 |
| - !GetClearColor(clear_color_size).IsTransparent()) { |
| 848 | + if (!collapsed_parent_pass && GetClearColor(clear_color_size).has_value()) { |
850 | 849 | // Force the pass context to create at least one new pass if the clear color
|
851 | 850 | // is present.
|
852 | 851 | pass_context.GetRenderPass(pass_depth);
|
@@ -958,7 +957,7 @@ bool EntityPass::OnRender(
|
958 | 957 | // If all previous elements were skipped due to clear color
|
959 | 958 | // optimization, then provide the clear color as the foreground of the
|
960 | 959 | // advanced blend.
|
961 |
| - foreground_color = GetClearColor(clear_color_size); |
| 960 | + foreground_color = GetClearColorOrDefault(clear_color_size); |
962 | 961 | coverage = Rect::MakeSize(clear_color_size);
|
963 | 962 | } else {
|
964 | 963 | coverage = result.entity.GetCoverage();
|
@@ -1139,21 +1138,29 @@ void EntityPass::SetBlendMode(BlendMode blend_mode) {
|
1139 | 1138 | flood_clip_ = Entity::IsBlendModeDestructive(blend_mode);
|
1140 | 1139 | }
|
1141 | 1140 |
|
1142 |
| -Color EntityPass::GetClearColor(ISize target_size) const { |
1143 |
| - Color result = Color::BlackTransparent(); |
| 1141 | +Color EntityPass::GetClearColorOrDefault(ISize size) const { |
| 1142 | + return GetClearColor(size).value_or(Color::BlackTransparent()); |
| 1143 | +} |
| 1144 | + |
| 1145 | +std::optional<Color> EntityPass::GetClearColor(ISize target_size) const { |
1144 | 1146 | if (backdrop_filter_proc_) {
|
1145 |
| - return result; |
| 1147 | + return std::nullopt; |
1146 | 1148 | }
|
1147 | 1149 |
|
| 1150 | + std::optional<Color> result = std::nullopt; |
1148 | 1151 | for (const Element& element : elements_) {
|
1149 | 1152 | auto [entity_color, blend_mode] =
|
1150 | 1153 | ElementAsBackgroundColor(element, target_size);
|
1151 | 1154 | if (!entity_color.has_value()) {
|
1152 | 1155 | break;
|
1153 | 1156 | }
|
1154 |
| - result = result.Blend(entity_color.value(), blend_mode); |
| 1157 | + result = result.value_or(Color::BlackTransparent()) |
| 1158 | + .Blend(entity_color.value(), blend_mode); |
| 1159 | + } |
| 1160 | + if (result.has_value()) { |
| 1161 | + return result->Premultiply(); |
1155 | 1162 | }
|
1156 |
| - return result.Premultiply(); |
| 1163 | + return result; |
1157 | 1164 | }
|
1158 | 1165 |
|
1159 | 1166 | void EntityPass::SetBackdropFilter(BackdropFilterProc proc) {
|
|
0 commit comments