Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions impeller/core/allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
26 changes: 21 additions & 5 deletions impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/filters/inputs/filter_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Copy link
Copy Markdown
Member

@bdero bdero Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This optimization will be a nice win for a lot of apps.

}

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
9 changes: 9 additions & 0 deletions impeller/entity/contents/tiled_texture_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions impeller/entity/contents/vertices_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions impeller/entity/entity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
20 changes: 20 additions & 0 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down