[Impeller] Fix up coverage hints for blending/vertices, fix TiledTextureContents::RenderToSnapshot (flutter/engine#43017)
Fixes https://github.com/flutter/flutter/issues/128329 Fixes https://github.com/flutter/flutter/issues/128807 The panorama example app is still not quite visually on par with skia - the scaling or filtering or something isn't quite as nice as in the skia backend - but it does render now and no longer tries to create gigantical textures.
This commit is contained in:
@@ -49,9 +49,8 @@ std::shared_ptr<Texture> Allocator::CreateTexture(
|
||||
const TextureDescriptor& desc) {
|
||||
const auto max_size = GetMaxTextureSizeSupported();
|
||||
if (desc.size.width > max_size.width || desc.size.height > max_size.height) {
|
||||
VALIDATION_LOG
|
||||
<< "Requested texture size exceeds maximum supported size of "
|
||||
<< desc.size;
|
||||
VALIDATION_LOG << "Requested texture size " << desc.size
|
||||
<< " exceeds maximum supported size of " << max_size;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,8 +168,15 @@ static std::optional<Entity> AdvancedBlend(
|
||||
return true;
|
||||
};
|
||||
|
||||
auto out_texture = renderer.MakeSubpass("Advanced Blend Filter",
|
||||
ISize(coverage.size), callback);
|
||||
auto subpass_size = ISize(coverage.size);
|
||||
if (entity.GetContents()) {
|
||||
auto coverage_hint = entity.GetContents()->GetCoverageHint();
|
||||
if (coverage_hint.has_value()) {
|
||||
subpass_size = subpass_size.Min(ISize(coverage_hint->size));
|
||||
}
|
||||
}
|
||||
auto out_texture =
|
||||
renderer.MakeSubpass("Advanced Blend Filter", subpass_size, callback);
|
||||
if (!out_texture) {
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -531,7 +538,8 @@ static std::optional<Entity> PipelineBlend(
|
||||
|
||||
VS::FrameInfo frame_info;
|
||||
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
|
||||
Matrix::MakeTranslation(-coverage.origin) *
|
||||
Matrix::MakeTranslation(
|
||||
-input->GetCoverage().value_or(coverage).origin) *
|
||||
input->transform;
|
||||
frame_info.texture_sampler_y_coord_scale =
|
||||
input->texture->GetYCoordScale();
|
||||
@@ -587,8 +595,16 @@ static std::optional<Entity> PipelineBlend(
|
||||
return true;
|
||||
};
|
||||
|
||||
auto out_texture = renderer.MakeSubpass("Pipeline Blend Filter",
|
||||
ISize(coverage.size), callback);
|
||||
auto subpass_size = ISize(coverage.size);
|
||||
if (entity.GetContents()) {
|
||||
auto coverage_hint = entity.GetContents()->GetCoverageHint();
|
||||
if (coverage_hint.has_value()) {
|
||||
subpass_size = subpass_size.Min(ISize(coverage_hint->size));
|
||||
}
|
||||
}
|
||||
auto out_texture =
|
||||
renderer.MakeSubpass("Pipeline Blend Filter", subpass_size, callback);
|
||||
|
||||
if (!out_texture) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ std::optional<Snapshot> ContentsFilterInput::GetSnapshot(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
std::optional<Rect> coverage_limit) const {
|
||||
if (!coverage_limit.has_value() && entity.GetContents()) {
|
||||
coverage_limit = entity.GetContents()->GetCoverageHint();
|
||||
}
|
||||
if (!snapshot_.has_value()) {
|
||||
snapshot_ = contents_->RenderToSnapshot(
|
||||
renderer, // renderer
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "impeller/entity/contents/contents.h"
|
||||
#include "impeller/entity/entity.h"
|
||||
#include "impeller/geometry/rect.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class ContentContext;
|
||||
class Entity;
|
||||
class FilterContents;
|
||||
|
||||
/// `FilterInput` is a lazy/single eval `Snapshot` which may be shared across
|
||||
|
||||
@@ -198,4 +198,29 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<Snapshot> TiledTextureContents::RenderToSnapshot(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
std::optional<Rect> coverage_limit,
|
||||
const std::optional<SamplerDescriptor>& sampler_descriptor,
|
||||
bool msaa_enabled,
|
||||
const std::string& label) const {
|
||||
if (GetInverseMatrix().IsIdentity()) {
|
||||
return Snapshot{
|
||||
.texture = texture_,
|
||||
.transform = entity.GetTransformation(),
|
||||
.sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_),
|
||||
.opacity = GetOpacity(),
|
||||
};
|
||||
}
|
||||
|
||||
return Contents::RenderToSnapshot(
|
||||
renderer, // renderer
|
||||
entity, // entity
|
||||
std::nullopt, // coverage_limit
|
||||
sampler_descriptor.value_or(sampler_descriptor_), // sampler_descriptor
|
||||
true, // msaa_enabled
|
||||
label); // label
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -53,6 +53,15 @@ class TiledTextureContents final : public ColorSourceContents {
|
||||
/// much smaller size that its original texture size.
|
||||
void SetColorFilter(std::optional<ColorFilterProc> color_filter);
|
||||
|
||||
// |Contents|
|
||||
std::optional<Snapshot> RenderToSnapshot(
|
||||
const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
std::optional<Rect> coverage_limit = std::nullopt,
|
||||
const std::optional<SamplerDescriptor>& sampler_descriptor = std::nullopt,
|
||||
bool msaa_enabled = true,
|
||||
const std::string& label = "Tiled Texture Snapshot") const override;
|
||||
|
||||
private:
|
||||
std::optional<std::shared_ptr<Texture>> CreateFilterTexture(
|
||||
const ContentContext& renderer) const;
|
||||
|
||||
@@ -57,8 +57,10 @@ bool VerticesContents::Render(const ContentContext& renderer,
|
||||
return true;
|
||||
}
|
||||
std::shared_ptr<Contents> src_contents = src_contents_;
|
||||
src_contents->SetCoverageHint(GetCoverageHint());
|
||||
if (geometry_->HasTextureCoordinates()) {
|
||||
auto contents = std::make_shared<VerticesUVContents>(*this);
|
||||
contents->SetCoverageHint(GetCoverageHint());
|
||||
if (!geometry_->HasVertexColors()) {
|
||||
contents->SetAlpha(alpha_);
|
||||
return contents->Render(renderer, entity, pass);
|
||||
@@ -67,6 +69,7 @@ bool VerticesContents::Render(const ContentContext& renderer,
|
||||
}
|
||||
|
||||
auto dst_contents = std::make_shared<VerticesColorContents>(*this);
|
||||
dst_contents->SetCoverageHint(GetCoverageHint());
|
||||
|
||||
std::shared_ptr<Contents> contents;
|
||||
if (blend_mode_ == BlendMode::kDestination) {
|
||||
@@ -76,9 +79,11 @@ bool VerticesContents::Render(const ContentContext& renderer,
|
||||
blend_mode_, {FilterInput::Make(dst_contents, false),
|
||||
FilterInput::Make(src_contents, false)});
|
||||
color_filter_contents->SetAlpha(alpha_);
|
||||
color_filter_contents->SetCoverageHint(GetCoverageHint());
|
||||
contents = color_filter_contents;
|
||||
}
|
||||
|
||||
FML_DCHECK(contents->GetCoverageHint() == GetCoverageHint());
|
||||
return contents->Render(renderer, entity, pass);
|
||||
}
|
||||
|
||||
@@ -108,11 +113,11 @@ bool VerticesUVContents::Render(const ContentContext& renderer,
|
||||
auto src_contents = parent_.GetSourceContents();
|
||||
|
||||
auto snapshot =
|
||||
src_contents->RenderToSnapshot(renderer, // renderer
|
||||
entity, // entity
|
||||
std::nullopt, // coverage_limit
|
||||
std::nullopt, // sampler_descriptor
|
||||
true, // msaa_enabled
|
||||
src_contents->RenderToSnapshot(renderer, // renderer
|
||||
entity, // entity
|
||||
GetCoverageHint(), // coverage_limit
|
||||
std::nullopt, // sampler_descriptor
|
||||
true, // msaa_enabled
|
||||
"VerticesUVContents Snapshot"); // label
|
||||
if (!snapshot.has_value()) {
|
||||
return false;
|
||||
|
||||
@@ -154,6 +154,11 @@ bool Entity::Render(const ContentContext& renderer,
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!contents_->GetCoverageHint().has_value()) {
|
||||
contents_->SetCoverageHint(
|
||||
Rect::MakeSize(parent_pass.GetRenderTargetSize()));
|
||||
}
|
||||
|
||||
return contents_->Render(renderer, *this, parent_pass);
|
||||
}
|
||||
|
||||
|
||||
@@ -2415,6 +2415,26 @@ TEST_P(EntityTest, PointFieldGeometryDivisions) {
|
||||
ASSERT_EQ(PointFieldGeometry::ComputeCircleDivisions(20000.0, true), 140u);
|
||||
}
|
||||
|
||||
TEST_P(EntityTest, ColorFilterContentsWithLargeGeometry) {
|
||||
Entity entity;
|
||||
entity.SetTransformation(Matrix::MakeScale(GetContentScale()));
|
||||
auto src_contents = std::make_shared<SolidColorContents>();
|
||||
src_contents->SetGeometry(
|
||||
Geometry::MakeRect(Rect::MakeLTRB(-300, -500, 30000, 50000)));
|
||||
src_contents->SetColor(Color::Red());
|
||||
|
||||
auto dst_contents = std::make_shared<SolidColorContents>();
|
||||
dst_contents->SetGeometry(
|
||||
Geometry::MakeRect(Rect::MakeLTRB(300, 500, 20000, 30000)));
|
||||
dst_contents->SetColor(Color::Blue());
|
||||
|
||||
auto contents = ColorFilterContents::MakeBlend(
|
||||
BlendMode::kSourceOver, {FilterInput::Make(dst_contents, false),
|
||||
FilterInput::Make(src_contents, false)});
|
||||
entity.SetContents(std::move(contents));
|
||||
ASSERT_TRUE(OpenPlaygroundHere(entity));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
|
||||
Reference in New Issue
Block a user