-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Handle complex RSE rendering in the uber SDF pipeline #186434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5460f5e
initial implementation
walley892 5186240
compute all quadrants
walley892 c4dbac3
add tests
walley892 99b7bfd
Add comments
walley892 96c5935
More comments
walley892 2f7d8fb
Merge remote-tracking branch 'upstream/master' into rse-full
walley892 e6ff93c
comments
walley892 02f098e
Go back to split logic, clean up
walley892 9e074bd
break out complex RSE into a different type
walley892 35b6116
Merge remote-tracking branch 'upstream/master' into rse-full
walley892 0f4538e
Bot comments
walley892 48fc1d9
Merge remote-tracking branch 'upstream/master' into rse-full
walley892 8bded1a
malioc
walley892 60c2f91
Break out complex RSEs into a separate pipeline
walley892 f380fed
malioc
walley892 5c4fa9f
comments, opmitize symmetric RSE code, clean up
walley892 669d168
malioc
walley892 718b607
c->C
walley892 59cd46c
Merge remote-tracking branch 'upstream/master' into rse-full
walley892 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
172 changes: 172 additions & 0 deletions
172
engine/src/flutter/impeller/entity/contents/complex_rse_contents.cc
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,172 @@ | ||
| // 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 "impeller/entity/contents/complex_rse_contents.h" | ||
|
|
||
| #include "impeller/entity/contents/color_source_contents.h" | ||
| #include "impeller/entity/contents/content_context.h" | ||
| #include "impeller/entity/contents/pipelines.h" | ||
| #include "impeller/entity/geometry/geometry.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| namespace { | ||
|
|
||
| using PipelineBuilderCallback = | ||
| std::function<PipelineRef(ContentContextOptions)>; | ||
|
|
||
| using VS = ComplexRSEPipeline::VertexShader; | ||
| using FS = ComplexRSEPipeline::FragmentShader; | ||
|
|
||
| } // namespace | ||
|
|
||
| std::unique_ptr<ComplexRoundedSuperellipseContents> | ||
| ComplexRoundedSuperellipseContents::Make( | ||
| Color color, | ||
| const Rect& bounds, | ||
| const RoundSuperellipseParam& round_superellipse_params, | ||
| std::optional<StrokeParameters> stroke) { | ||
| return std::unique_ptr<ComplexRoundedSuperellipseContents>( | ||
| new ComplexRoundedSuperellipseContents( | ||
| color, bounds, round_superellipse_params, stroke)); | ||
| } | ||
|
|
||
| ComplexRoundedSuperellipseContents::ComplexRoundedSuperellipseContents( | ||
| Color color, | ||
| const Rect& bounds, | ||
| const RoundSuperellipseParam& round_superellipse_params, | ||
| std::optional<StrokeParameters> stroke) | ||
| : color_(color), | ||
| bounds_(bounds), | ||
| round_superellipse_params_(round_superellipse_params), | ||
| stroke_(stroke) { | ||
| if (stroke) { | ||
| geometry_ = Geometry::MakeRect(bounds_.Expand(stroke->width / 2.0f)); | ||
| } else { | ||
| geometry_ = Geometry::MakeRect(bounds_); | ||
| } | ||
| } | ||
|
|
||
| bool ComplexRoundedSuperellipseContents::Render(const ContentContext& renderer, | ||
| const Entity& entity, | ||
| RenderPass& pass) const { | ||
| auto& data_host_buffer = renderer.GetTransientsDataBuffer(); | ||
|
|
||
| Point center = bounds_.GetCenter(); | ||
|
|
||
| RoundSuperellipseParam::Quadrant top_right = | ||
| round_superellipse_params_.top_right; | ||
| RoundSuperellipseParam::Quadrant bottom_right = | ||
| round_superellipse_params_.bottom_right; | ||
| RoundSuperellipseParam::Quadrant bottom_left = | ||
| round_superellipse_params_.bottom_left; | ||
| RoundSuperellipseParam::Quadrant top_left = | ||
| round_superellipse_params_.top_left; | ||
|
|
||
| Point top_right_center_relative = top_right.offset - center; | ||
| Point bottom_right_center_relative = bottom_right.offset - center; | ||
| Point bottom_left_center_relative = bottom_left.offset - center; | ||
| Point top_left_center_relative = top_left.offset - center; | ||
|
|
||
| Point size = Point(bounds_.GetSize() * 0.5f); | ||
|
|
||
| VS::FrameInfo frame_info; | ||
| FS::FragInfo frag_info; | ||
|
|
||
| frag_info.color = color_.WithAlpha(color_.alpha * GetOpacityFactor()); | ||
| frag_info.center = center; | ||
| frag_info.size = size; | ||
| frag_info.stroked = stroke_ ? 1.0f : 0.0f; | ||
| frag_info.stroke_width = stroke_ ? stroke_->width : 0.0f; | ||
|
|
||
| frag_info.superellipse_degrees_top = | ||
| Vector4(bottom_right.top.se_n, top_right.top.se_n, bottom_left.top.se_n, | ||
| top_left.top.se_n); | ||
| frag_info.superellipse_degrees_right = | ||
| Vector4(bottom_right.right.se_n, top_right.right.se_n, | ||
| bottom_left.right.se_n, top_left.right.se_n); | ||
| frag_info.superellipse_semi_axes_top = | ||
| Vector4(bottom_right.top.se_a, top_right.top.se_a, bottom_left.top.se_a, | ||
| top_left.top.se_a); | ||
| frag_info.superellipse_semi_axes_right = | ||
| Vector4(bottom_right.right.se_a, top_right.right.se_a, | ||
| bottom_left.right.se_a, top_left.right.se_a); | ||
| frag_info.angle_spans_top = Vector4(bottom_right.top.circle_max_angle.radians, | ||
| top_right.top.circle_max_angle.radians, | ||
| bottom_left.top.circle_max_angle.radians, | ||
| top_left.top.circle_max_angle.radians); | ||
| frag_info.angle_spans_right = | ||
| Vector4(bottom_right.right.circle_max_angle.radians, | ||
| top_right.right.circle_max_angle.radians, | ||
| bottom_left.right.circle_max_angle.radians, | ||
| top_left.right.circle_max_angle.radians); | ||
| frag_info.octant_offsets_c = | ||
| Vector4(bottom_right.top.se_a - bottom_right.right.se_a, | ||
| top_right.top.se_a - top_right.right.se_a, | ||
| bottom_left.top.se_a - bottom_left.right.se_a, | ||
| top_left.top.se_a - top_left.right.se_a); | ||
| frag_info.radii_width = | ||
| Vector4(bottom_right.top.circle_radius, top_right.top.circle_radius, | ||
| bottom_left.top.circle_radius, top_left.top.circle_radius); | ||
| frag_info.radii_height = | ||
| Vector4(bottom_right.right.circle_radius, top_right.right.circle_radius, | ||
| bottom_left.right.circle_radius, top_left.right.circle_radius); | ||
| frag_info.circle_centers_top_x = | ||
| Vector4(bottom_right.top.circle_center.x, top_right.top.circle_center.x, | ||
| bottom_left.top.circle_center.x, top_left.top.circle_center.x); | ||
| frag_info.circle_centers_top_y = | ||
| Vector4(bottom_right.top.circle_center.y, top_right.top.circle_center.y, | ||
| bottom_left.top.circle_center.y, top_left.top.circle_center.y); | ||
| frag_info.circle_centers_right_x = Vector4( | ||
| bottom_right.right.circle_center.x, top_right.right.circle_center.x, | ||
| bottom_left.right.circle_center.x, top_left.right.circle_center.x); | ||
| frag_info.circle_centers_right_y = Vector4( | ||
| bottom_right.right.circle_center.y, top_right.right.circle_center.y, | ||
| bottom_left.right.circle_center.y, top_left.right.circle_center.y); | ||
| frag_info.superellipse_scales_x = | ||
| Vector4(bottom_right.signed_scale.Abs().x, top_right.signed_scale.Abs().x, | ||
| bottom_left.signed_scale.Abs().x, top_left.signed_scale.Abs().x); | ||
| frag_info.superellipse_scales_y = | ||
| Vector4(bottom_right.signed_scale.Abs().y, top_right.signed_scale.Abs().y, | ||
| bottom_left.signed_scale.Abs().y, top_left.signed_scale.Abs().y); | ||
| frag_info.quadrant_centers_x = | ||
| Vector4(bottom_right_center_relative.x, top_right_center_relative.x, | ||
| bottom_left_center_relative.x, top_left_center_relative.x); | ||
| frag_info.quadrant_centers_y = | ||
| Vector4(bottom_right_center_relative.y, top_right_center_relative.y, | ||
| bottom_left_center_relative.y, top_left_center_relative.y); | ||
| frag_info.quadrant_splits = | ||
| Vector4(round_superellipse_params_.top_split - center.x, | ||
| round_superellipse_params_.bottom_split - center.x, | ||
| round_superellipse_params_.left_split - center.y, | ||
| round_superellipse_params_.right_split - center.y); | ||
|
|
||
| auto geometry_result = | ||
| GetGeometry()->GetPositionBuffer(renderer, entity, pass); | ||
|
|
||
| PipelineBuilderCallback pipeline_callback = | ||
| [&renderer](ContentContextOptions options) { | ||
| return renderer.GetComplexRSEPipeline(options); | ||
| }; | ||
|
|
||
| return ColorSourceContents::DrawGeometry<VS>( | ||
| this, GetGeometry(), renderer, entity, pass, pipeline_callback, | ||
| frame_info, | ||
| /*bind_fragment_callback=*/ | ||
| [&frag_info, &data_host_buffer](RenderPass& pass) { | ||
| FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info)); | ||
| return true; | ||
| }); | ||
| } | ||
|
|
||
| std::optional<Rect> ComplexRoundedSuperellipseContents::GetCoverage( | ||
| const Entity& entity) const { | ||
| return GetGeometry()->GetCoverage(entity.GetTransform()); | ||
| } | ||
|
|
||
| const Geometry* ComplexRoundedSuperellipseContents::GetGeometry() const { | ||
| return geometry_.get(); | ||
| } | ||
|
|
||
| } // namespace impeller |
62 changes: 62 additions & 0 deletions
62
engine/src/flutter/impeller/entity/contents/complex_rse_contents.h
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,62 @@ | ||
| // 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. | ||
|
|
||
| #ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_COMPLEX_RSE_CONTENTS_H_ | ||
| #define FLUTTER_IMPELLER_ENTITY_CONTENTS_COMPLEX_RSE_CONTENTS_H_ | ||
|
|
||
| #include <memory> | ||
| #include <optional> | ||
|
|
||
| #include "flutter/impeller/entity/contents/color_source_contents.h" | ||
| #include "flutter/impeller/entity/contents/contents.h" | ||
| #include "impeller/entity/geometry/geometry.h" | ||
| #include "impeller/geometry/color.h" | ||
| #include "impeller/geometry/rect.h" | ||
| #include "impeller/geometry/round_superellipse_param.h" | ||
| #include "impeller/geometry/stroke_parameters.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| /// A Contents class that renders asymmetric rounded superellipses using SDFs. | ||
| /// | ||
| /// Separated from 'UberSDFContents' to reduce uniform bloat | ||
| class ComplexRoundedSuperellipseContents : public ColorSourceContents { | ||
| public: | ||
| static std::unique_ptr<ComplexRoundedSuperellipseContents> Make( | ||
| Color color, | ||
| const Rect& bounds, | ||
| const RoundSuperellipseParam& round_superellipse_params, | ||
| std::optional<StrokeParameters> stroke); | ||
|
|
||
| bool Render(const ContentContext& renderer, | ||
| const Entity& entity, | ||
| RenderPass& pass) const override; | ||
|
|
||
| std::optional<Rect> GetCoverage(const Entity& entity) const override; | ||
|
|
||
| const Geometry* GetGeometry() const override; | ||
|
|
||
| private: | ||
| explicit ComplexRoundedSuperellipseContents( | ||
| Color color, | ||
| const Rect& bounds, | ||
| const RoundSuperellipseParam& round_superellipse_params, | ||
| std::optional<StrokeParameters> stroke); | ||
|
|
||
| Color color_; | ||
| Rect bounds_; | ||
| RoundSuperellipseParam round_superellipse_params_; | ||
| std::optional<StrokeParameters> stroke_; | ||
| std::unique_ptr<Geometry> geometry_; | ||
|
|
||
| ComplexRoundedSuperellipseContents( | ||
| const ComplexRoundedSuperellipseContents&) = delete; | ||
|
|
||
| ComplexRoundedSuperellipseContents& operator=( | ||
| const ComplexRoundedSuperellipseContents&) = delete; | ||
| }; | ||
|
|
||
| } // namespace impeller | ||
|
|
||
| #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_COMPLEX_RSE_CONTENTS_H_ | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.