[Impeller] Cover ShouldRender in tests. (flutter/engine#34749)

This commit is contained in:
Brandon DeRosier 2022-07-19 09:27:45 -07:00 committed by GitHub
parent c64bbb073e
commit d5a8db658b
8 changed files with 48 additions and 12 deletions

View File

@ -37,7 +37,7 @@ std::optional<Rect> ClipContents::GetCoverage(const Entity& entity) const {
};
bool ClipContents::ShouldRender(const Entity& entity,
const RenderPass& pass) const {
const ISize& target_size) const {
return true;
}
@ -120,7 +120,7 @@ std::optional<Rect> ClipRestoreContents::GetCoverage(
};
bool ClipRestoreContents::ShouldRender(const Entity& entity,
const RenderPass& pass) const {
const ISize& target_size) const {
return true;
}

View File

@ -29,7 +29,7 @@ class ClipContents final : public Contents {
// |Contents|
bool ShouldRender(const Entity& entity,
const RenderPass& pass) const override;
const ISize& target_size) const override;
// |Contents|
bool Render(const ContentContext& renderer,
@ -54,7 +54,7 @@ class ClipRestoreContents final : public Contents {
// |Contents|
bool ShouldRender(const Entity& entity,
const RenderPass& pass) const override;
const ISize& target_size) const override;
// |Contents|
bool Render(const ContentContext& renderer,

View File

@ -58,11 +58,10 @@ std::optional<Snapshot> Contents::RenderToSnapshot(
}
bool Contents::ShouldRender(const Entity& entity,
const RenderPass& pass) const {
const ISize& target_size) const {
auto coverage = GetCoverage(entity);
return coverage.has_value() &&
Rect::MakeSize(Size(pass.GetRenderTargetSize()))
.IntersectsWithRect(coverage.value());
Rect::MakeSize(target_size).IntersectsWithRect(coverage.value());
}
} // namespace impeller

View File

@ -47,7 +47,8 @@ class Contents {
const ContentContext& renderer,
const Entity& entity) const;
virtual bool ShouldRender(const Entity& entity, const RenderPass& pass) const;
virtual bool ShouldRender(const Entity& entity,
const ISize& target_size) const;
protected:

View File

@ -41,8 +41,8 @@ std::optional<Rect> Entity::GetCoverage() const {
return contents_->GetCoverage(*this);
}
bool Entity::ShouldRender(const RenderPass& pass) const {
return contents_->ShouldRender(*this, pass);
bool Entity::ShouldRender(const ISize& target_size) const {
return contents_->ShouldRender(*this, target_size);
}
void Entity::SetContents(std::shared_ptr<Contents> contents) {

View File

@ -81,7 +81,7 @@ class Entity {
std::optional<Rect> GetCoverage() const;
bool ShouldRender(const RenderPass& pass) const;
bool ShouldRender(const ISize& target_size) const;
void SetContents(std::shared_ptr<Contents> contents);

View File

@ -363,7 +363,7 @@ bool EntityPass::OnRender(ContentContext& renderer,
stencil_depth_floor);
auto pass = pass_context.GetRenderPass(pass_depth);
if (!element_entity.ShouldRender(*pass)) {
if (!element_entity.ShouldRender(pass->GetRenderTargetSize())) {
return true; // Nothing to render.
}

View File

@ -6,6 +6,7 @@
#include <optional>
#include "flutter/testing/testing.h"
#include "impeller/entity/contents/clip_contents.h"
#include "impeller/entity/contents/filters/blend_filter_contents.h"
#include "impeller/entity/contents/filters/filter_contents.h"
#include "impeller/entity/contents/filters/inputs/filter_input.h"
@ -1114,5 +1115,40 @@ TEST_P(EntityTest, SolidFillCoverageIsCorrect) {
}
}
TEST_P(EntityTest, SolidFillShouldRenderIsCorrect) {
// No path.
{
auto fill = std::make_shared<SolidColorContents>();
fill->SetColor(Color::CornflowerBlue());
ASSERT_FALSE(fill->ShouldRender(Entity{}, {100, 100}));
}
// With path.
{
auto fill = std::make_shared<SolidColorContents>();
fill->SetColor(Color::CornflowerBlue());
fill->SetPath(
PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 100, 100)).TakePath());
ASSERT_TRUE(fill->ShouldRender(Entity{}, {100, 100}));
}
}
TEST_P(EntityTest, ClipContentsShouldRenderIsCorrect) {
// Clip.
{
auto clip = std::make_shared<ClipContents>();
ASSERT_TRUE(clip->ShouldRender(Entity{}, {100, 100}));
clip->SetPath(
PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 100, 100)).TakePath());
ASSERT_TRUE(clip->ShouldRender(Entity{}, {100, 100}));
}
// Clip restore.
{
auto restore = std::make_shared<ClipRestoreContents>();
ASSERT_TRUE(restore->ShouldRender(Entity{}, {100, 100}));
}
}
} // namespace testing
} // namespace impeller