This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Reland of Simplify Advanced Blend color filters with a foreground color. #40927
Merged
auto-submit
merged 9 commits into
flutter-team-archive:main
from
jonahwilliams:pipeline_blend_simplify
Apr 10, 2023
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
afb596d
fix advanced blend inlining
09a3026
Merge branch 'master' of github.com:flutter/engine into pipeline_blen…
8cf0278
++
0410f7b
move around
5ab53e3
++
f682b36
use anon contents
6d65a18
use getCoverageUVs correctly
f3ce098
Merge branch 'main' into pipeline_blend_simplify
16734d2
Merge branch 'main' into pipeline_blend_simplify
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "foreground_blend_contents.h" | ||
| #include <iostream> | ||
|
|
||
| #include "flutter/impeller/entity/contents/content_context.h" | ||
| #include "flutter/impeller/renderer/render_pass.h" | ||
| #include "flutter/impeller/renderer/sampler_library.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| AdvancedForegroundBlendContents::AdvancedForegroundBlendContents() {} | ||
|
|
||
| AdvancedForegroundBlendContents::~AdvancedForegroundBlendContents() {} | ||
|
|
||
| void AdvancedForegroundBlendContents::SetBlendMode(BlendMode blend_mode) { | ||
| FML_DCHECK(blend_mode > Entity::kLastPipelineBlendMode); | ||
| blend_mode_ = blend_mode; | ||
| } | ||
|
|
||
| void AdvancedForegroundBlendContents::SetSrcInput( | ||
| std::shared_ptr<FilterInput> input) { | ||
| input_ = std::move(input); | ||
| } | ||
|
|
||
| void AdvancedForegroundBlendContents::SetForegroundColor(Color color) { | ||
| foreground_color_ = color; | ||
| } | ||
|
|
||
| void AdvancedForegroundBlendContents::SetCoverage(Rect rect) { | ||
| rect_ = rect; | ||
| } | ||
|
|
||
| std::optional<Rect> AdvancedForegroundBlendContents::GetCoverage( | ||
| const Entity& entity) const { | ||
| return rect_.TransformBounds(entity.GetTransformation()); | ||
| } | ||
|
|
||
| bool AdvancedForegroundBlendContents::Render(const ContentContext& renderer, | ||
| const Entity& entity, | ||
| RenderPass& pass) const { | ||
| using VS = BlendScreenPipeline::VertexShader; | ||
| using FS = BlendScreenPipeline::FragmentShader; | ||
|
|
||
| auto& host_buffer = pass.GetTransientsBuffer(); | ||
|
|
||
| auto dst_snapshot = input_->GetSnapshot(renderer, entity); | ||
| if (!dst_snapshot.has_value()) { | ||
| return false; | ||
| } | ||
| auto maybe_dst_uvs = dst_snapshot->GetCoverageUVs(rect_); | ||
| if (!maybe_dst_uvs.has_value()) { | ||
| return false; | ||
| } | ||
| auto dst_uvs = maybe_dst_uvs.value(); | ||
|
|
||
| auto size = rect_.size; | ||
| VertexBufferBuilder<VS::PerVertexData> vtx_builder; | ||
| // hack | ||
| dst_uvs[0] = Point(0.0, 0.0); | ||
| dst_uvs[1] = Point(1.0, 0.0); | ||
| dst_uvs[2] = Point(0.0, 1.0); | ||
| dst_uvs[3] = Point(1.0, 1.0); | ||
|
|
||
| vtx_builder.AddVertices({ | ||
| {rect_.origin, dst_uvs[0], dst_uvs[0]}, | ||
| {Point(rect_.origin.x + size.width, rect_.origin.y), dst_uvs[1], | ||
| dst_uvs[1]}, | ||
| {Point(rect_.origin.x + size.width, rect_.origin.y + size.height), | ||
| dst_uvs[3], dst_uvs[3]}, | ||
| {rect_.origin, dst_uvs[0], dst_uvs[0]}, | ||
| {Point(rect_.origin.x + size.width, rect_.origin.y + size.height), | ||
| dst_uvs[3], dst_uvs[3]}, | ||
| {Point(rect_.origin.x, rect_.origin.y + size.height), dst_uvs[2], | ||
| dst_uvs[2]}, | ||
| }); | ||
| auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer); | ||
|
|
||
| Command cmd; | ||
| cmd.label = "Foreground Advanced Blend Filter"; | ||
| cmd.BindVertices(vtx_buffer); | ||
| cmd.stencil_reference = entity.GetStencilDepth(); | ||
| auto options = OptionsFromPass(pass); | ||
|
|
||
| switch (blend_mode_) { | ||
| case BlendMode::kScreen: | ||
| cmd.pipeline = renderer.GetBlendScreenPipeline(options); | ||
| break; | ||
| case BlendMode::kOverlay: | ||
| cmd.pipeline = renderer.GetBlendOverlayPipeline(options); | ||
| break; | ||
| case BlendMode::kDarken: | ||
| cmd.pipeline = renderer.GetBlendDarkenPipeline(options); | ||
| break; | ||
| case BlendMode::kLighten: | ||
| cmd.pipeline = renderer.GetBlendLightenPipeline(options); | ||
| break; | ||
| case BlendMode::kColorDodge: | ||
| cmd.pipeline = renderer.GetBlendColorDodgePipeline(options); | ||
| break; | ||
| case BlendMode::kColorBurn: | ||
| cmd.pipeline = renderer.GetBlendColorBurnPipeline(options); | ||
| break; | ||
| case BlendMode::kHardLight: | ||
| cmd.pipeline = renderer.GetBlendHardLightPipeline(options); | ||
| break; | ||
| case BlendMode::kSoftLight: | ||
| cmd.pipeline = renderer.GetBlendSoftLightPipeline(options); | ||
| break; | ||
| case BlendMode::kDifference: | ||
| cmd.pipeline = renderer.GetBlendDifferencePipeline(options); | ||
| break; | ||
| case BlendMode::kExclusion: | ||
| cmd.pipeline = renderer.GetBlendExclusionPipeline(options); | ||
| break; | ||
| case BlendMode::kMultiply: | ||
| cmd.pipeline = renderer.GetBlendMultiplyPipeline(options); | ||
| break; | ||
| case BlendMode::kHue: | ||
| cmd.pipeline = renderer.GetBlendHuePipeline(options); | ||
| break; | ||
| case BlendMode::kSaturation: | ||
| cmd.pipeline = renderer.GetBlendSaturationPipeline(options); | ||
| break; | ||
| case BlendMode::kColor: | ||
| cmd.pipeline = renderer.GetBlendColorPipeline(options); | ||
| break; | ||
| case BlendMode::kLuminosity: | ||
| cmd.pipeline = renderer.GetBlendLuminosityPipeline(options); | ||
| break; | ||
| default: | ||
| return false; | ||
| } | ||
|
|
||
| FS::BlendInfo blend_info; | ||
| VS::FrameInfo frame_info; | ||
|
|
||
| auto dst_sampler_descriptor = dst_snapshot->sampler_descriptor; | ||
| if (renderer.GetDeviceCapabilities().SupportsDecalTileMode()) { | ||
| dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal; | ||
| dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal; | ||
| } | ||
| auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler( | ||
| dst_sampler_descriptor); | ||
| FS::BindTextureSamplerDst(cmd, dst_snapshot->texture, dst_sampler); | ||
| frame_info.dst_y_coord_scale = dst_snapshot->texture->GetYCoordScale(); | ||
| blend_info.dst_input_alpha = dst_snapshot->opacity; | ||
|
|
||
| blend_info.color_factor = 1; | ||
| blend_info.color = foreground_color_; | ||
| // This texture will not be sampled from due to the color factor. But | ||
| // this is present so that validation doesn't trip on a missing | ||
| // binding. | ||
| FS::BindTextureSamplerSrc(cmd, dst_snapshot->texture, dst_sampler); | ||
|
|
||
| auto blend_uniform = host_buffer.EmplaceUniform(blend_info); | ||
| FS::BindBlendInfo(cmd, blend_uniform); | ||
|
|
||
| frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()); | ||
|
|
||
| auto uniform_view = host_buffer.EmplaceUniform(frame_info); | ||
| VS::BindFrameInfo(cmd, uniform_view); | ||
|
|
||
| return pass.AddCommand(cmd); | ||
| } | ||
|
|
||
| } // namespace impeller | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "flutter/fml/macros.h" | ||
| #include "flutter/impeller/core/texture.h" | ||
| #include "flutter/impeller/entity/contents/color_source_contents.h" | ||
| #include "flutter/impeller/entity/contents/filters/inputs/filter_input.h" | ||
| #include "flutter/impeller/entity/entity.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| /// @brief Optimized advanced blend that avoids a second subpass when there is | ||
| /// only a single input and a foreground color. | ||
| /// | ||
| /// These contents cannot absorb opacity. | ||
| class AdvancedForegroundBlendContents : public Contents { | ||
| public: | ||
| AdvancedForegroundBlendContents(); | ||
|
|
||
| ~AdvancedForegroundBlendContents(); | ||
|
|
||
| void SetBlendMode(BlendMode blend_mode); | ||
|
|
||
| void SetSrcInput(std::shared_ptr<FilterInput> input); | ||
|
|
||
| void SetForegroundColor(Color color); | ||
|
|
||
| void SetCoverage(Rect rect); | ||
|
|
||
| private: | ||
| // |Contents| | ||
| std::optional<Rect> GetCoverage(const Entity& entity) const override; | ||
|
|
||
| // |Contents| | ||
| bool Render(const ContentContext& renderer, | ||
| const Entity& entity, | ||
| RenderPass& pass) const override; | ||
|
|
||
| Color foreground_color_; | ||
| BlendMode blend_mode_; | ||
| std::shared_ptr<FilterInput> input_; | ||
| Rect rect_; | ||
|
|
||
| FML_DISALLOW_COPY_AND_ASSIGN(AdvancedForegroundBlendContents); | ||
| }; | ||
|
|
||
| } // namespace impeller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From reading render_filter, it appears that the coverage rect we are given already has the CTM applied. So we have two choices here: either directly use the values for the coordinates (and don't apply it to the MVP - or invert the transform and likewise.
Of course, if you don't invert the transform and fix the coordinates, then the UVs come out wrong and that's why I've "Fixed" them below.
I'm not sure exactly why this worked before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there is some difference in a snapshot that is created by a contents, and a snapshot that is forwarded through from an entity pass. I'm tempted just to say, for this particular case, we should just set the UVs using the coverage rect, since that coverage rect already includes the CTM it is correct for both entity subpasses and for contents. But I'm still not really sure how I should be using the snapshot GetCoverageUVs directly which is concerning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess more of a question for @bdero, but what is the correct way to use snapshot.GetCoverageUVs ?