[impeller] drawVertices blend mode (flutter/engine#38985)
* [impeller] drawVertices blend mode * Squashed commit of the following: commit fd230d22123c0a0c06850e8460637b0ca09b7c72 Author: jonahwilliams <jonahwilliams@google.com> Date: Wed Jan 18 19:07:33 2023 -0800 fix opacity for pipeline blends commit 53a21899c12c2323060f0503897756aeb073dfb2 Author: jonahwilliams <jonahwilliams@google.com> Date: Wed Jan 18 15:32:16 2023 -0800 Use sub-contents commit e83fb612bc9ee9b7f03ad44ac13b11ec6f03d118 Author: jonahwilliams <jonahwilliams@google.com> Date: Wed Jan 18 12:05:53 2023 -0800 blending cleanup commit 040a83f7e3cbac0c7c90f806a231a397d39d2d4c Author: jonahwilliams <jonahwilliams@google.com> Date: Tue Jan 17 18:22:47 2023 -0800 remove atlas_fill from licenses commit 7d9e751ad49959fd76568350f38c98815e1808a7 Author: jonahwilliams <jonahwilliams@google.com> Date: Tue Jan 17 17:16:37 2023 -0800 ++ commit a4f25cd5cd2ff07890363935d9011475ee8631e0 Author: jonahwilliams <jonahwilliams@google.com> Date: Tue Jan 17 17:11:14 2023 -0800 ++ commit d8b3023899af301394273d57183c860d8f70006b Author: jonahwilliams <jonahwilliams@google.com> Date: Tue Jan 17 17:06:53 2023 -0800 ++ commit 997bb3fa337ed826b142745d3a0607d511a72ee0 Author: jonahwilliams <jonahwilliams@google.com> Date: Tue Jan 17 17:06:23 2023 -0800 back out vertices change commit 9dbe177ac398ba6ab754e40de2b8feede90ac5dd Merge: 94e6c24294032f8d9c19Author: jonahwilliams <jonahwilliams@google.com> Date: Tue Jan 17 11:19:08 2023 -0800 Merge branch 'master' of github.com:flutter/engine into drawAtlas commit 94e6c2429481b745540886e5735dacca4fca12f4 Author: jonahwilliams <jonahwilliams@google.com> Date: Fri Jan 13 13:37:33 2023 -0800 Delete color blending commit 426d6a19b0503baa6d0b9439f4806734f08ac2d3 Author: jonahwilliams <jonahwilliams@google.com> Date: Thu Jan 12 16:59:00 2023 -0800 ++ commit 3905cb17b3e77746cb697476bad795807d8daad5 Author: jonahwilliams <jonahwilliams@google.com> Date: Thu Jan 12 16:45:50 2023 -0800 ++ commit ca273f4417adce0c71b1dc8f48360c50f68162b2 Author: jonahwilliams <jonahwilliams@google.com> Date: Thu Jan 12 16:35:40 2023 -0800 ++ commit a3a94768ddb03c246b1c559d73ff4ca9219ff768 Author: jonahwilliams <jonahwilliams@google.com> Date: Thu Jan 12 16:35:02 2023 -0800 basic texture coordiantes work commit 785e18bdcb342b561545d00894d6b061a4bc66a6 Author: jonahwilliams <jonahwilliams@google.com> Date: Wed Jan 11 20:13:56 2023 -0800 ++ commit 79c13e50cba5ecceed00fa57065db02075e8ce81 Author: jonahwilliams <jonahwilliams@google.com> Date: Wed Jan 11 20:05:10 2023 -0800 some texture coordinates work commit 2a27640ee026bab3e55d94da34c48151ddbfdc0f Author: jonahwilliams <jonahwilliams@google.com> Date: Wed Jan 11 17:59:49 2023 -0800 CI cleanups commit 0c23ff48a6b0bef72d6323182bffd47c181468ae Author: jonahwilliams <jonahwilliams@google.com> Date: Wed Jan 11 16:59:11 2023 -0800 dont double divide commit 1a00d10a25a3a9a9ebc9257eb3121cf31cad933c Author: jonahwilliams <jonahwilliams@google.com> Date: Wed Jan 11 12:39:11 2023 -0800 test fixes commit 8a1caa1f90ac9f8aa6e3d831c6423f12e7e6f21d Author: jonahwilliams <jonahwilliams@google.com> Date: Wed Jan 11 11:58:23 2023 -0800 ++ commit 683e3064eb04dd571bdd3da3b18185cef73be8b0 Author: jonahwilliams <jonahwilliams@google.com> Date: Wed Jan 11 11:57:54 2023 -0800 add drawVertices uage commit 56bf47dc442b9b601370e4c34501dd5133a76475 Author: jonahwilliams <jonahwilliams@google.com> Date: Tue Jan 10 19:12:42 2023 -0800 ++ commit b2cc708eab39c034832c30e35e492b336a8543cb Merge: ff6f4de42cdce6ac238bAuthor: jonahwilliams <jonahwilliams@google.com> Date: Tue Jan 10 16:58:52 2023 -0800 Merge branch 'master' of github.com:flutter/engine into drawAtlas commit ff6f4de42ca558ce8c634df1ba6a4dd21b5f2bb4 Author: jonahwilliams <jonahwilliams@google.com> Date: Thu Dec 15 14:38:11 2022 -0800 fill out drawAtlas * update to use contents * ++ * ++ * ++ * ++ * add playground test * ++ * ++ * ++
This commit is contained in:
@@ -378,7 +378,7 @@ void Canvas::DrawTextFrame(const TextFrame& text_frame,
|
||||
GetCurrentPass().AddEntity(entity);
|
||||
}
|
||||
|
||||
void Canvas::DrawVertices(std::unique_ptr<VerticesGeometry> vertices,
|
||||
void Canvas::DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
|
||||
BlendMode blend_mode,
|
||||
const Paint& paint) {
|
||||
Entity entity;
|
||||
@@ -386,21 +386,24 @@ void Canvas::DrawVertices(std::unique_ptr<VerticesGeometry> vertices,
|
||||
entity.SetStencilDepth(GetStencilDepth());
|
||||
entity.SetBlendMode(paint.blend_mode);
|
||||
|
||||
if (paint.color_source.has_value()) {
|
||||
auto& source = paint.color_source.value();
|
||||
auto contents = source();
|
||||
contents->SetGeometry(std::move(vertices));
|
||||
contents->SetAlpha(paint.color.alpha);
|
||||
entity.SetContents(paint.WithFilters(std::move(contents), true));
|
||||
} else {
|
||||
std::shared_ptr<VerticesContents> contents =
|
||||
std::make_shared<VerticesContents>();
|
||||
contents->SetColor(paint.color);
|
||||
contents->SetBlendMode(blend_mode);
|
||||
contents->SetGeometry(std::move(vertices));
|
||||
entity.SetContents(paint.WithFilters(std::move(contents), true));
|
||||
if (!vertices->HasVertexColors()) {
|
||||
auto contents = paint.CreateContentsForGeometry(vertices);
|
||||
entity.SetContents(paint.WithFilters(std::move(contents)));
|
||||
GetCurrentPass().AddEntity(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
auto src_paint = paint;
|
||||
src_paint.color = paint.color.WithAlpha(1.0);
|
||||
auto src_contents = src_paint.CreateContentsForGeometry(vertices);
|
||||
|
||||
auto contents = std::make_shared<VerticesContents>();
|
||||
contents->SetAlpha(paint.color.alpha);
|
||||
contents->SetBlendMode(blend_mode);
|
||||
contents->SetGeometry(vertices);
|
||||
contents->SetSourceContents(std::move(src_contents));
|
||||
entity.SetContents(paint.WithFilters(std::move(contents)));
|
||||
|
||||
GetCurrentPass().AddEntity(entity);
|
||||
}
|
||||
|
||||
@@ -415,11 +418,6 @@ void Canvas::DrawAtlas(const std::shared_ptr<Image>& atlas,
|
||||
if (!atlas) {
|
||||
return;
|
||||
}
|
||||
auto size = atlas->GetSize();
|
||||
|
||||
if (size.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<AtlasContents> contents = std::make_shared<AtlasContents>();
|
||||
contents->SetColors(std::move(colors));
|
||||
|
||||
@@ -97,7 +97,7 @@ class Canvas {
|
||||
Point position,
|
||||
const Paint& paint);
|
||||
|
||||
void DrawVertices(std::unique_ptr<VerticesGeometry> vertices,
|
||||
void DrawVertices(const std::shared_ptr<VerticesGeometry>& vertices,
|
||||
BlendMode blend_mode,
|
||||
const Paint& paint);
|
||||
|
||||
|
||||
@@ -40,6 +40,21 @@ std::shared_ptr<Contents> Paint::CreateContentsForGeometry(
|
||||
return solid_color;
|
||||
}
|
||||
|
||||
std::shared_ptr<Contents> Paint::CreateContentsForGeometry(
|
||||
const std::shared_ptr<Geometry>& geometry) const {
|
||||
if (color_source.has_value()) {
|
||||
auto& source = color_source.value();
|
||||
auto contents = source();
|
||||
contents->SetGeometry(geometry);
|
||||
contents->SetAlpha(color.alpha);
|
||||
return contents;
|
||||
}
|
||||
auto solid_color = std::make_shared<SolidColorContents>();
|
||||
solid_color->SetGeometry(geometry);
|
||||
solid_color->SetColor(color);
|
||||
return solid_color;
|
||||
}
|
||||
|
||||
std::shared_ptr<Contents> Paint::WithFilters(
|
||||
std::shared_ptr<Contents> input,
|
||||
std::optional<bool> is_solid_color,
|
||||
|
||||
@@ -106,6 +106,9 @@ struct Paint {
|
||||
std::shared_ptr<Contents> CreateContentsForGeometry(
|
||||
std::unique_ptr<Geometry> geometry) const;
|
||||
|
||||
std::shared_ptr<Contents> CreateContentsForGeometry(
|
||||
const std::shared_ptr<Geometry>& geometry) const;
|
||||
|
||||
/// @brief Whether this paint has a color filter that can apply opacity
|
||||
bool HasColorFilter() const;
|
||||
|
||||
|
||||
@@ -34,6 +34,15 @@
|
||||
namespace impeller {
|
||||
namespace testing {
|
||||
|
||||
flutter::DlColor toColor(const float* components) {
|
||||
auto value = (((std::lround(components[3] * 255) & 0xff) << 24) |
|
||||
((std::lround(components[0] * 255) & 0xff) << 16) |
|
||||
((std::lround(components[1] * 255) & 0xff) << 8) |
|
||||
((std::lround(components[2] * 255) & 0xff) << 0)) &
|
||||
0xFFFFFFFF;
|
||||
return flutter::DlColor(value);
|
||||
}
|
||||
|
||||
using DisplayListTest = DisplayListPlayground;
|
||||
INSTANTIATE_PLAYGROUND_SUITE(DisplayListTest);
|
||||
|
||||
@@ -1164,6 +1173,97 @@ TEST_P(DisplayListTest, DrawShapes) {
|
||||
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
|
||||
}
|
||||
|
||||
TEST_P(DisplayListTest, DrawVerticesBlendModes) {
|
||||
std::vector<const char*> blend_mode_names;
|
||||
std::vector<flutter::DlBlendMode> blend_mode_values;
|
||||
{
|
||||
const std::vector<std::tuple<const char*, flutter::DlBlendMode>> blends = {
|
||||
// Pipeline blends (Porter-Duff alpha compositing)
|
||||
{"Clear", flutter::DlBlendMode::kClear},
|
||||
{"Source", flutter::DlBlendMode::kSrc},
|
||||
{"Destination", flutter::DlBlendMode::kDst},
|
||||
{"SourceOver", flutter::DlBlendMode::kSrcOver},
|
||||
{"DestinationOver", flutter::DlBlendMode::kDstOver},
|
||||
{"SourceIn", flutter::DlBlendMode::kSrcIn},
|
||||
{"DestinationIn", flutter::DlBlendMode::kDstIn},
|
||||
{"SourceOut", flutter::DlBlendMode::kSrcOut},
|
||||
{"DestinationOut", flutter::DlBlendMode::kDstOut},
|
||||
{"SourceATop", flutter::DlBlendMode::kSrcATop},
|
||||
{"DestinationATop", flutter::DlBlendMode::kDstATop},
|
||||
{"Xor", flutter::DlBlendMode::kXor},
|
||||
{"Plus", flutter::DlBlendMode::kPlus},
|
||||
{"Modulate", flutter::DlBlendMode::kModulate},
|
||||
// Advanced blends (color component blends)
|
||||
{"Screen", flutter::DlBlendMode::kScreen},
|
||||
{"Overlay", flutter::DlBlendMode::kOverlay},
|
||||
{"Darken", flutter::DlBlendMode::kDarken},
|
||||
{"Lighten", flutter::DlBlendMode::kLighten},
|
||||
{"ColorDodge", flutter::DlBlendMode::kColorDodge},
|
||||
{"ColorBurn", flutter::DlBlendMode::kColorBurn},
|
||||
{"HardLight", flutter::DlBlendMode::kHardLight},
|
||||
{"SoftLight", flutter::DlBlendMode::kSoftLight},
|
||||
{"Difference", flutter::DlBlendMode::kDifference},
|
||||
{"Exclusion", flutter::DlBlendMode::kExclusion},
|
||||
{"Multiply", flutter::DlBlendMode::kMultiply},
|
||||
{"Hue", flutter::DlBlendMode::kHue},
|
||||
{"Saturation", flutter::DlBlendMode::kSaturation},
|
||||
{"Color", flutter::DlBlendMode::kColor},
|
||||
{"Luminosity", flutter::DlBlendMode::kLuminosity},
|
||||
};
|
||||
assert(blends.size() ==
|
||||
static_cast<size_t>(flutter::DlBlendMode::kLastMode) + 1);
|
||||
for (const auto& [name, mode] : blends) {
|
||||
blend_mode_names.push_back(name);
|
||||
blend_mode_values.push_back(mode);
|
||||
}
|
||||
}
|
||||
|
||||
auto callback = [&]() {
|
||||
static int current_blend_index = 3;
|
||||
static float dst_alpha = 1;
|
||||
static float src_alpha = 1;
|
||||
static float color0[4] = {1.0f, 0.0f, 0.0f, 1.0f};
|
||||
static float color1[4] = {0.0f, 1.0f, 0.0f, 1.0f};
|
||||
static float color2[4] = {0.0f, 0.0f, 1.0f, 1.0f};
|
||||
static float src_color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
|
||||
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
{
|
||||
ImGui::ListBox("Blending mode", ¤t_blend_index,
|
||||
blend_mode_names.data(), blend_mode_names.size());
|
||||
ImGui::SliderFloat("Source alpha", &src_alpha, 0, 1);
|
||||
ImGui::ColorEdit4("Color A", color0);
|
||||
ImGui::ColorEdit4("Color B", color1);
|
||||
ImGui::ColorEdit4("Color C", color2);
|
||||
ImGui::ColorEdit4("Source Color", src_color);
|
||||
ImGui::SliderFloat("Destination alpha", &dst_alpha, 0, 1);
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
std::vector<SkPoint> positions = {SkPoint::Make(100, 300),
|
||||
SkPoint::Make(200, 100),
|
||||
SkPoint::Make(300, 300)};
|
||||
std::vector<flutter::DlColor> colors = {
|
||||
toColor(color0).modulateOpacity(dst_alpha),
|
||||
toColor(color1).modulateOpacity(dst_alpha),
|
||||
toColor(color2).modulateOpacity(dst_alpha)};
|
||||
|
||||
auto vertices = flutter::DlVertices::Make(
|
||||
flutter::DlVertexMode::kTriangles, 3, positions.data(),
|
||||
/*texture_coorindates=*/nullptr, colors.data());
|
||||
|
||||
flutter::DisplayListBuilder builder;
|
||||
flutter::DlPaint paint;
|
||||
|
||||
paint.setColor(toColor(src_color).modulateOpacity(src_alpha));
|
||||
builder.drawVertices(vertices, blend_mode_values[current_blend_index],
|
||||
paint);
|
||||
return builder.Build();
|
||||
};
|
||||
|
||||
ASSERT_TRUE(OpenPlaygroundHere(callback));
|
||||
}
|
||||
|
||||
#ifdef IMPELLER_ENABLE_3D
|
||||
TEST_P(DisplayListTest, SceneColorSource) {
|
||||
// Load up the scene.
|
||||
|
||||
@@ -58,9 +58,9 @@ static std::vector<uint16_t> fromFanIndices(
|
||||
/////// Vertices Geometry ///////
|
||||
|
||||
// static
|
||||
std::unique_ptr<VerticesGeometry> DLVerticesGeometry::MakeVertices(
|
||||
std::shared_ptr<VerticesGeometry> DLVerticesGeometry::MakeVertices(
|
||||
const flutter::DlVertices* vertices) {
|
||||
return std::make_unique<DLVerticesGeometry>(vertices);
|
||||
return std::make_shared<DLVerticesGeometry>(vertices);
|
||||
}
|
||||
|
||||
DLVerticesGeometry::DLVerticesGeometry(const flutter::DlVertices* vertices)
|
||||
@@ -100,6 +100,10 @@ static PrimitiveType GetPrimitiveType(const flutter::DlVertices* vertices) {
|
||||
}
|
||||
}
|
||||
|
||||
bool DLVerticesGeometry::HasVertexColors() const {
|
||||
return vertices_->colors() != nullptr;
|
||||
}
|
||||
|
||||
GeometryResult DLVerticesGeometry::GetPositionBuffer(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
@@ -154,9 +158,7 @@ GeometryResult DLVerticesGeometry::GetPositionBuffer(
|
||||
GeometryResult DLVerticesGeometry::GetPositionColorBuffer(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass,
|
||||
Color paint_color,
|
||||
BlendMode blend_mode) {
|
||||
RenderPass& pass) {
|
||||
using VS = GeometryColorPipeline::VertexShader;
|
||||
|
||||
auto index_count = normalized_indices_.size() == 0
|
||||
@@ -173,9 +175,9 @@ GeometryResult DLVerticesGeometry::GetPositionColorBuffer(
|
||||
{
|
||||
for (auto i = 0; i < vertex_count; i++) {
|
||||
auto dl_color = dl_colors[i];
|
||||
auto pre_color = Color(dl_color.getRedF(), dl_color.getGreenF(),
|
||||
dl_color.getBlueF(), dl_color.getAlphaF());
|
||||
auto color = Color::BlendColor(paint_color, pre_color, blend_mode);
|
||||
auto color = Color(dl_color.getRedF(), dl_color.getGreenF(),
|
||||
dl_color.getBlueF(), dl_color.getAlphaF())
|
||||
.Premultiply();
|
||||
auto sk_point = dl_vertices[i];
|
||||
vertex_data[i] = {
|
||||
.position = Point(sk_point.x(), sk_point.y()),
|
||||
|
||||
@@ -23,15 +23,13 @@ class DLVerticesGeometry : public VerticesGeometry {
|
||||
|
||||
~DLVerticesGeometry();
|
||||
|
||||
static std::unique_ptr<VerticesGeometry> MakeVertices(
|
||||
static std::shared_ptr<VerticesGeometry> MakeVertices(
|
||||
const flutter::DlVertices* vertices);
|
||||
|
||||
// |VerticesGeometry|
|
||||
GeometryResult GetPositionColorBuffer(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass,
|
||||
Color paint_color,
|
||||
BlendMode blend_mode) override;
|
||||
RenderPass& pass) override;
|
||||
|
||||
// |VerticesGeometry|
|
||||
GeometryResult GetPositionUVBuffer(const ContentContext& renderer,
|
||||
@@ -49,6 +47,9 @@ class DLVerticesGeometry : public VerticesGeometry {
|
||||
// |Geometry|
|
||||
GeometryVertexType GetVertexType() const override;
|
||||
|
||||
// |VerticesGeometry|
|
||||
bool HasVertexColors() const override;
|
||||
|
||||
private:
|
||||
void NormalizeIndices();
|
||||
|
||||
|
||||
@@ -126,8 +126,6 @@ bool AtlasContents::Render(const ContentContext& renderer,
|
||||
auto dst_contents = std::make_shared<AtlasColorContents>(*this);
|
||||
dst_contents->SetCoverage(coverage);
|
||||
|
||||
// For some reason this looks backwards compared to Skia unless
|
||||
// we reverse the src/dst.
|
||||
auto contents = ColorFilterContents::MakeBlend(
|
||||
blend_mode_,
|
||||
{FilterInput::Make(dst_contents), FilterInput::Make(src_contents)});
|
||||
|
||||
@@ -260,11 +260,12 @@ bool ContentContext::IsValid() const {
|
||||
|
||||
std::shared_ptr<Texture> ContentContext::MakeSubpass(
|
||||
ISize texture_size,
|
||||
const SubpassCallback& subpass_callback) const {
|
||||
const SubpassCallback& subpass_callback,
|
||||
bool msaa_enabled) const {
|
||||
auto context = GetContext();
|
||||
|
||||
RenderTarget subpass_target;
|
||||
if (context->SupportsOffscreenMSAA()) {
|
||||
if (context->SupportsOffscreenMSAA() && msaa_enabled) {
|
||||
subpass_target = RenderTarget::CreateOffscreenMSAA(*context, texture_size);
|
||||
} else {
|
||||
subpass_target = RenderTarget::CreateOffscreen(*context, texture_size);
|
||||
|
||||
@@ -432,9 +432,9 @@ class ContentContext {
|
||||
|
||||
/// @brief Creates a new texture of size `texture_size` and calls
|
||||
/// `subpass_callback` with a `RenderPass` for drawing to the texture.
|
||||
std::shared_ptr<Texture> MakeSubpass(
|
||||
ISize texture_size,
|
||||
const SubpassCallback& subpass_callback) const;
|
||||
std::shared_ptr<Texture> MakeSubpass(ISize texture_size,
|
||||
const SubpassCallback& subpass_callback,
|
||||
bool msaa_enabled = true) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Context> context_;
|
||||
|
||||
@@ -40,7 +40,8 @@ Contents::StencilCoverage Contents::GetStencilCoverage(
|
||||
|
||||
std::optional<Snapshot> Contents::RenderToSnapshot(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity) const {
|
||||
const Entity& entity,
|
||||
bool msaa_enabled) const {
|
||||
auto coverage = GetCoverage(entity);
|
||||
if (!coverage.has_value()) {
|
||||
return std::nullopt;
|
||||
@@ -56,7 +57,8 @@ std::optional<Snapshot> Contents::RenderToSnapshot(
|
||||
Matrix::MakeTranslation(Vector3(-coverage->origin)) *
|
||||
entity.GetTransformation());
|
||||
return contents.Render(renderer, sub_entity, pass);
|
||||
});
|
||||
},
|
||||
msaa_enabled);
|
||||
|
||||
if (!texture) {
|
||||
return std::nullopt;
|
||||
|
||||
@@ -60,7 +60,8 @@ class Contents {
|
||||
/// `GetCoverage(entity)`.
|
||||
virtual std::optional<Snapshot> RenderToSnapshot(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity) const;
|
||||
const Entity& entity,
|
||||
bool msaa_enabled = true) const;
|
||||
|
||||
virtual bool ShouldRender(const Entity& entity,
|
||||
const std::optional<Rect>& stencil_coverage) const;
|
||||
|
||||
@@ -205,7 +205,7 @@ static std::optional<Snapshot> PipelineBlend(
|
||||
FS::FragInfo frag_info;
|
||||
frag_info.texture_sampler_y_coord_scale =
|
||||
input->texture->GetYCoordScale();
|
||||
frag_info.input_alpha = absorb_opacity ? input->opacity : 1.0f;
|
||||
frag_info.input_alpha = absorb_opacity ? input->opacity : 1.0;
|
||||
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
|
||||
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
|
||||
|
||||
|
||||
@@ -236,7 +236,8 @@ std::optional<Rect> FilterContents::GetFilterCoverage(
|
||||
|
||||
std::optional<Snapshot> FilterContents::RenderToSnapshot(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity) const {
|
||||
const Entity& entity,
|
||||
bool msaa_enabled) const {
|
||||
Entity entity_with_local_transform = entity;
|
||||
entity_with_local_transform.SetTransformation(
|
||||
GetTransform(entity.GetTransformation()));
|
||||
|
||||
@@ -116,8 +116,10 @@ class FilterContents : public Contents {
|
||||
std::optional<Rect> GetCoverage(const Entity& entity) const override;
|
||||
|
||||
// |Contents|
|
||||
std::optional<Snapshot> RenderToSnapshot(const ContentContext& renderer,
|
||||
const Entity& entity) const override;
|
||||
std::optional<Snapshot> RenderToSnapshot(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
bool msaa_enabled = true) const override;
|
||||
|
||||
virtual Matrix GetLocalTransform(const Matrix& parent_transform) const;
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
ContentsFilterInput::ContentsFilterInput(std::shared_ptr<Contents> contents)
|
||||
: contents_(std::move(contents)) {}
|
||||
ContentsFilterInput::ContentsFilterInput(std::shared_ptr<Contents> contents,
|
||||
bool msaa_enabled)
|
||||
: contents_(std::move(contents)), msaa_enabled_(msaa_enabled) {}
|
||||
|
||||
ContentsFilterInput::~ContentsFilterInput() = default;
|
||||
|
||||
@@ -21,7 +22,7 @@ std::optional<Snapshot> ContentsFilterInput::GetSnapshot(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity) const {
|
||||
if (!snapshot_.has_value()) {
|
||||
snapshot_ = contents_->RenderToSnapshot(renderer, entity);
|
||||
snapshot_ = contents_->RenderToSnapshot(renderer, entity, msaa_enabled_);
|
||||
}
|
||||
return snapshot_;
|
||||
}
|
||||
|
||||
@@ -23,10 +23,11 @@ class ContentsFilterInput final : public FilterInput {
|
||||
std::optional<Rect> GetCoverage(const Entity& entity) const override;
|
||||
|
||||
private:
|
||||
ContentsFilterInput(std::shared_ptr<Contents> contents);
|
||||
ContentsFilterInput(std::shared_ptr<Contents> contents, bool msaa_enabled);
|
||||
|
||||
std::shared_ptr<Contents> contents_;
|
||||
mutable std::optional<Snapshot> snapshot_;
|
||||
bool msaa_enabled_;
|
||||
|
||||
friend FilterInput;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
FilterInput::Ref FilterInput::Make(Variant input) {
|
||||
FilterInput::Ref FilterInput::Make(Variant input, bool msaa_enabled) {
|
||||
if (auto filter = std::get_if<std::shared_ptr<FilterContents>>(&input)) {
|
||||
return std::static_pointer_cast<FilterInput>(
|
||||
std::shared_ptr<FilterContentsFilterInput>(
|
||||
@@ -25,7 +25,7 @@ FilterInput::Ref FilterInput::Make(Variant input) {
|
||||
if (auto contents = std::get_if<std::shared_ptr<Contents>>(&input)) {
|
||||
return std::static_pointer_cast<FilterInput>(
|
||||
std::shared_ptr<ContentsFilterInput>(
|
||||
new ContentsFilterInput(*contents)));
|
||||
new ContentsFilterInput(*contents, msaa_enabled)));
|
||||
}
|
||||
|
||||
if (auto texture = std::get_if<std::shared_ptr<Texture>>(&input)) {
|
||||
|
||||
@@ -36,7 +36,7 @@ class FilterInput {
|
||||
|
||||
virtual ~FilterInput();
|
||||
|
||||
static FilterInput::Ref Make(Variant input);
|
||||
static FilterInput::Ref Make(Variant input, bool msaa_enabled = true);
|
||||
|
||||
static FilterInput::Ref Make(std::shared_ptr<Texture> input,
|
||||
Matrix local_transform);
|
||||
|
||||
@@ -24,7 +24,7 @@ const Color& SolidColorContents::GetColor() const {
|
||||
return color_;
|
||||
}
|
||||
|
||||
void SolidColorContents::SetGeometry(std::unique_ptr<Geometry> geometry) {
|
||||
void SolidColorContents::SetGeometry(std::shared_ptr<Geometry> geometry) {
|
||||
geometry_ = std::move(geometry);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class SolidColorContents final : public Contents {
|
||||
static std::unique_ptr<SolidColorContents> Make(const Path& path,
|
||||
Color color);
|
||||
|
||||
void SetGeometry(std::unique_ptr<Geometry> geometry);
|
||||
void SetGeometry(std::shared_ptr<Geometry> geometry);
|
||||
|
||||
void SetColor(Color color);
|
||||
|
||||
@@ -48,7 +48,7 @@ class SolidColorContents final : public Contents {
|
||||
RenderPass& pass) const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Geometry> geometry_;
|
||||
std::shared_ptr<Geometry> geometry_;
|
||||
|
||||
Color color_;
|
||||
|
||||
|
||||
@@ -66,7 +66,8 @@ std::optional<Rect> TextureContents::GetCoverage(const Entity& entity) const {
|
||||
|
||||
std::optional<Snapshot> TextureContents::RenderToSnapshot(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity) const {
|
||||
const Entity& entity,
|
||||
bool msaa_enabled) const {
|
||||
auto bounds = path_.GetBoundingBox();
|
||||
if (!bounds.has_value()) {
|
||||
return std::nullopt;
|
||||
|
||||
@@ -52,8 +52,10 @@ class TextureContents final : public Contents {
|
||||
std::optional<Rect> GetCoverage(const Entity& entity) const override;
|
||||
|
||||
// |Contents|
|
||||
std::optional<Snapshot> RenderToSnapshot(const ContentContext& renderer,
|
||||
const Entity& entity) const override;
|
||||
std::optional<Snapshot> RenderToSnapshot(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
bool msaa_enabled = true) const override;
|
||||
|
||||
// |Contents|
|
||||
bool Render(const ContentContext& renderer,
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#include "vertices_contents.h"
|
||||
|
||||
#include "impeller/entity/contents/content_context.h"
|
||||
#include "impeller/entity/contents/filters/color_filter_contents.h"
|
||||
#include "impeller/entity/contents/filters/filter_contents.h"
|
||||
#include "impeller/entity/contents/texture_contents.h"
|
||||
#include "impeller/entity/position.vert.h"
|
||||
#include "impeller/entity/position_color.vert.h"
|
||||
#include "impeller/entity/position_uv.vert.h"
|
||||
@@ -25,12 +28,20 @@ std::optional<Rect> VerticesContents::GetCoverage(const Entity& entity) const {
|
||||
return geometry_->GetCoverage(entity.GetTransformation());
|
||||
};
|
||||
|
||||
void VerticesContents::SetGeometry(std::unique_ptr<VerticesGeometry> geometry) {
|
||||
void VerticesContents::SetGeometry(std::shared_ptr<VerticesGeometry> geometry) {
|
||||
geometry_ = std::move(geometry);
|
||||
}
|
||||
|
||||
void VerticesContents::SetColor(Color color) {
|
||||
color_ = color.Premultiply();
|
||||
void VerticesContents::SetSourceContents(std::shared_ptr<Contents> contents) {
|
||||
src_contents_ = std::move(contents);
|
||||
}
|
||||
|
||||
std::shared_ptr<VerticesGeometry> VerticesContents::GetGeometry() const {
|
||||
return geometry_;
|
||||
}
|
||||
|
||||
void VerticesContents::SetAlpha(Scalar alpha) {
|
||||
alpha_ = alpha;
|
||||
}
|
||||
|
||||
void VerticesContents::SetBlendMode(BlendMode blend_mode) {
|
||||
@@ -40,57 +51,65 @@ void VerticesContents::SetBlendMode(BlendMode blend_mode) {
|
||||
bool VerticesContents::Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const {
|
||||
auto& host_buffer = pass.GetTransientsBuffer();
|
||||
auto vertex_type = geometry_->GetVertexType();
|
||||
if (blend_mode_ == BlendMode::kClear) {
|
||||
return true;
|
||||
}
|
||||
auto dst_contents = std::make_shared<VerticesColorContents>(*this);
|
||||
|
||||
auto contents = ColorFilterContents::MakeBlend(
|
||||
blend_mode_, {FilterInput::Make(dst_contents, false),
|
||||
FilterInput::Make(src_contents_, false)});
|
||||
contents->SetAlpha(alpha_);
|
||||
|
||||
return contents->Render(renderer, entity, pass);
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
// VerticesColorContents
|
||||
|
||||
VerticesColorContents::VerticesColorContents(const VerticesContents& parent)
|
||||
: parent_(parent) {}
|
||||
|
||||
VerticesColorContents::~VerticesColorContents() {}
|
||||
|
||||
// |Contents|
|
||||
std::optional<Rect> VerticesColorContents::GetCoverage(
|
||||
const Entity& entity) const {
|
||||
return parent_.GetCoverage(entity);
|
||||
}
|
||||
|
||||
void VerticesColorContents::SetAlpha(Scalar alpha) {
|
||||
alpha_ = alpha;
|
||||
}
|
||||
|
||||
// |Contents|
|
||||
bool VerticesColorContents::Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const {
|
||||
using VS = GeometryColorPipeline::VertexShader;
|
||||
using FS = GeometryColorPipeline::FragmentShader;
|
||||
|
||||
Command cmd;
|
||||
cmd.label = "Vertices";
|
||||
cmd.stencil_reference = entity.GetStencilDepth();
|
||||
cmd.label = "VerticesColors";
|
||||
auto& host_buffer = pass.GetTransientsBuffer();
|
||||
auto geometry = parent_.GetGeometry();
|
||||
|
||||
auto geometry_result =
|
||||
geometry->GetPositionColorBuffer(renderer, entity, pass);
|
||||
auto opts = OptionsFromPassAndEntity(pass, entity);
|
||||
opts.primitive_type = geometry_result.type;
|
||||
cmd.pipeline = renderer.GetGeometryColorPipeline(opts);
|
||||
cmd.BindVertices(geometry_result.vertex_buffer);
|
||||
|
||||
switch (vertex_type) {
|
||||
case GeometryVertexType::kColor: {
|
||||
using VS = GeometryColorPipeline::VertexShader;
|
||||
VS::VertInfo vert_info;
|
||||
vert_info.mvp = geometry_result.transform;
|
||||
VS::BindVertInfo(cmd, host_buffer.EmplaceUniform(vert_info));
|
||||
|
||||
auto geometry_result = geometry_->GetPositionColorBuffer(
|
||||
renderer, entity, pass, color_, blend_mode_);
|
||||
opts.primitive_type = geometry_result.type;
|
||||
cmd.pipeline = renderer.GetGeometryColorPipeline(opts);
|
||||
cmd.BindVertices(geometry_result.vertex_buffer);
|
||||
|
||||
VS::VertInfo vert_info;
|
||||
vert_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
|
||||
entity.GetTransformation();
|
||||
VS::BindVertInfo(cmd, host_buffer.EmplaceUniform(vert_info));
|
||||
break;
|
||||
}
|
||||
case GeometryVertexType::kUV:
|
||||
case GeometryVertexType::kPosition: {
|
||||
using VS = GeometryPositionPipeline::VertexShader;
|
||||
|
||||
auto geometry_result =
|
||||
geometry_->GetPositionBuffer(renderer, entity, pass);
|
||||
opts.primitive_type = geometry_result.type;
|
||||
cmd.pipeline = renderer.GetGeometryPositionPipeline(opts);
|
||||
cmd.BindVertices(geometry_result.vertex_buffer);
|
||||
|
||||
VS::VertInfo vert_info;
|
||||
vert_info.mvp = geometry_result.transform;
|
||||
vert_info.color = color_.Premultiply();
|
||||
VS::BindVertInfo(cmd,
|
||||
pass.GetTransientsBuffer().EmplaceUniform(vert_info));
|
||||
break;
|
||||
}
|
||||
}
|
||||
using FS = GeometryColorPipeline::FragmentShader;
|
||||
FS::FragInfo frag_info;
|
||||
frag_info.alpha = 1.0;
|
||||
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
|
||||
frag_info.alpha = alpha_;
|
||||
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
|
||||
|
||||
pass.AddCommand(std::move(cmd));
|
||||
|
||||
return true;
|
||||
return pass.AddCommand(std::move(cmd));
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -25,12 +25,16 @@ class VerticesContents final : public Contents {
|
||||
|
||||
~VerticesContents() override;
|
||||
|
||||
void SetGeometry(std::unique_ptr<VerticesGeometry> geometry);
|
||||
void SetGeometry(std::shared_ptr<VerticesGeometry> geometry);
|
||||
|
||||
void SetColor(Color color);
|
||||
void SetAlpha(Scalar alpha);
|
||||
|
||||
void SetBlendMode(BlendMode blend_mode);
|
||||
|
||||
void SetSourceContents(std::shared_ptr<Contents> contents);
|
||||
|
||||
std::shared_ptr<VerticesGeometry> GetGeometry() const;
|
||||
|
||||
// |Contents|
|
||||
std::optional<Rect> GetCoverage(const Entity& entity) const override;
|
||||
|
||||
@@ -39,12 +43,36 @@ class VerticesContents final : public Contents {
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
public:
|
||||
Color color_;
|
||||
std::unique_ptr<VerticesGeometry> geometry_;
|
||||
private:
|
||||
Scalar alpha_;
|
||||
std::shared_ptr<VerticesGeometry> geometry_;
|
||||
BlendMode blend_mode_ = BlendMode::kSource;
|
||||
std::shared_ptr<Contents> src_contents_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(VerticesContents);
|
||||
};
|
||||
|
||||
class VerticesColorContents final : public Contents {
|
||||
public:
|
||||
explicit VerticesColorContents(const VerticesContents& parent);
|
||||
|
||||
~VerticesColorContents() override;
|
||||
|
||||
// |Contents|
|
||||
std::optional<Rect> GetCoverage(const Entity& entity) const override;
|
||||
|
||||
// |Contents|
|
||||
bool Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
void SetAlpha(Scalar alpha);
|
||||
|
||||
private:
|
||||
const VerticesContents& parent_;
|
||||
Scalar alpha_ = 1.0;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(VerticesColorContents);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -75,13 +75,13 @@ class VerticesGeometry : public Geometry {
|
||||
public:
|
||||
virtual GeometryResult GetPositionColorBuffer(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass,
|
||||
Color paint_color,
|
||||
BlendMode blend_mode) = 0;
|
||||
RenderPass& pass) = 0;
|
||||
|
||||
virtual GeometryResult GetPositionUVBuffer(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) = 0;
|
||||
|
||||
virtual bool HasVertexColors() const = 0;
|
||||
};
|
||||
|
||||
/// @brief A geometry that is created from a filled path object.
|
||||
|
||||
Reference in New Issue
Block a user