From 5b75036229c4933feda069fa68f16f459c96f5d2 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Thu, 2 Nov 2023 17:37:09 -0700 Subject: [PATCH 1/3] [Impeller] Add simple checkerboard test and example of testing entities without goldens. --- impeller/entity/BUILD.gn | 1 + .../checkerboard_contents_unittests.cc | 48 +++++++++++++++++++ impeller/entity/entity_playground.cc | 10 ++-- impeller/entity/entity_playground.h | 2 + impeller/entity/entity_unittests.cc | 10 ---- 5 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 impeller/entity/contents/checkerboard_contents_unittests.cc diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index 4e1ce88280d4a..7fde22aaaa8a6 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -245,6 +245,7 @@ impeller_component("entity_unittests") { "entity_playground.h", "entity_unittests.cc", "geometry/geometry_unittests.cc", + "contents/checkerboard_contents_unittests.cc" ] deps = [ diff --git a/impeller/entity/contents/checkerboard_contents_unittests.cc b/impeller/entity/contents/checkerboard_contents_unittests.cc new file mode 100644 index 0000000000000..008184d2f742a --- /dev/null +++ b/impeller/entity/contents/checkerboard_contents_unittests.cc @@ -0,0 +1,48 @@ +// 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 +#include + +#include "gtest/gtest.h" + +#include "impeller/entity/contents/checkerboard_contents.h" +#include "impeller/entity/contents/contents.h" +#include "impeller/entity/entity.h" +#include "impeller/entity/entity_playground.h" +#include "impeller/renderer/render_target.h" + +namespace impeller { +namespace testing { + +using EntityTest = EntityPlayground; +INSTANTIATE_PLAYGROUND_SUITE(EntityTest); + +TEST(EntityTest, HasNulloptCoverage) { + auto contents = std::make_shared(); + + Entity entity; + ASSERT_EQ(contents->GetCoverage(entity), std::nullopt); +} + +TEST_P(EntityTest, RendersWithoutError) { + auto contents = std::make_shared(); + contents->SetColor(Color::Aqua()); + contents->SetSquareSize(10); + + auto content_context = GetContentContext(); + auto buffer = content_context->GetContext()->CreateCommandBuffer(); + auto render_target = RenderTarget::CreateOffscreenMSAA( + *content_context->GetContext(), + *GetContentContext()->GetRenderTargetCache(), {100, 100}); + auto render_pass = buffer->CreateRenderPass(render_target); + Entity entity; + + ASSERT_TRUE(render_pass->GetCommands().empty()); + ASSERT_TRUE(contents->Render(*content_context, entity, *render_pass)); + ASSERT_FALSE(render_pass->GetCommands().empty()); +} + +} // namespace testing +} // namespace impeller diff --git a/impeller/entity/entity_playground.cc b/impeller/entity/entity_playground.cc index 0f9eebe3ab0d0..bd13db3c18c14 100644 --- a/impeller/entity/entity_playground.cc +++ b/impeller/entity/entity_playground.cc @@ -36,17 +36,21 @@ bool EntityPlayground::OpenPlaygroundHere(EntityPass& entity_pass) { return Playground::OpenPlaygroundHere(callback); } +std::shared_ptr EntityPlayground::GetContentContext() const { + return std::make_shared(GetContext(), typographer_context_); +} + bool EntityPlayground::OpenPlaygroundHere(Entity entity) { if (!switches_.enable_playground) { return true; } - ContentContext content_context(GetContext(), typographer_context_); - if (!content_context.IsValid()) { + auto content_context = GetContentContext(); + if (!content_context->IsValid()) { return false; } SinglePassCallback callback = [&](RenderPass& pass) -> bool { - return entity.Render(content_context, pass); + return entity.Render(*content_context, pass); }; return Playground::OpenPlaygroundHere(callback); } diff --git a/impeller/entity/entity_playground.h b/impeller/entity/entity_playground.h index 62ed08f8954e1..10604f607237c 100644 --- a/impeller/entity/entity_playground.h +++ b/impeller/entity/entity_playground.h @@ -32,6 +32,8 @@ class EntityPlayground : public PlaygroundTest { bool OpenPlaygroundHere(EntityPlaygroundCallback callback); + std::shared_ptr GetContentContext() const; + private: std::shared_ptr typographer_context_; diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 1eb9cf149ad77..ea564dfa8e029 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -2,24 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include #include -#include #include #include -#include "flutter/testing/testing.h" #include "fml/logging.h" -#include "fml/time/time_point.h" #include "gtest/gtest.h" #include "impeller/core/texture_descriptor.h" #include "impeller/entity/contents/atlas_contents.h" #include "impeller/entity/contents/clip_contents.h" #include "impeller/entity/contents/conical_gradient_contents.h" #include "impeller/entity/contents/contents.h" -#include "impeller/entity/contents/filters/blend_filter_contents.h" #include "impeller/entity/contents/filters/color_filter_contents.h" #include "impeller/entity/contents/filters/filter_contents.h" #include "impeller/entity/contents/filters/inputs/filter_input.h" @@ -28,11 +23,9 @@ #include "impeller/entity/contents/runtime_effect_contents.h" #include "impeller/entity/contents/solid_color_contents.h" #include "impeller/entity/contents/solid_rrect_blur_contents.h" -#include "impeller/entity/contents/sweep_gradient_contents.h" #include "impeller/entity/contents/text_contents.h" #include "impeller/entity/contents/texture_contents.h" #include "impeller/entity/contents/tiled_texture_contents.h" -#include "impeller/entity/contents/vertices_contents.h" #include "impeller/entity/entity.h" #include "impeller/entity/entity_pass.h" #include "impeller/entity/entity_pass_delegate.h" @@ -50,11 +43,8 @@ #include "impeller/renderer/command.h" #include "impeller/renderer/render_pass.h" #include "impeller/renderer/vertex_buffer_builder.h" -#include "impeller/runtime_stage/runtime_stage.h" -#include "impeller/tessellator/tessellator.h" #include "impeller/typographer/backends/skia/text_frame_skia.h" #include "impeller/typographer/backends/skia/typographer_context_skia.h" -#include "include/core/SkBlendMode.h" #include "third_party/imgui/imgui.h" #include "third_party/skia/include/core/SkTextBlob.h" From 6ee15210eb6bcedc68323508b33ec53476908782 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Thu, 2 Nov 2023 17:37:35 -0700 Subject: [PATCH 2/3] ++ --- impeller/entity/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index 7fde22aaaa8a6..18d1e0035e0d5 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -240,12 +240,12 @@ impeller_component("entity_unittests") { testonly = true sources = [ + "contents/checkerboard_contents_unittests.cc", "contents/filters/inputs/filter_input_unittests.cc", "entity_playground.cc", "entity_playground.h", "entity_unittests.cc", "geometry/geometry_unittests.cc", - "contents/checkerboard_contents_unittests.cc" ] deps = [ From 30bf4f944d8e409d44d9c3a91f3b9d9c0b38e59f Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Thu, 2 Nov 2023 17:55:08 -0700 Subject: [PATCH 3/3] ++ --- ci/licenses_golden/excluded_files | 1 + impeller/entity/contents/checkerboard_contents.h | 1 - impeller/entity/contents/checkerboard_contents_unittests.cc | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/licenses_golden/excluded_files b/ci/licenses_golden/excluded_files index 1551a8af648cf..e2f7aedbf9f3f 100644 --- a/ci/licenses_golden/excluded_files +++ b/ci/licenses_golden/excluded_files @@ -134,6 +134,7 @@ ../../../flutter/impeller/display_list/dl_unittests.cc ../../../flutter/impeller/display_list/skia_conversions_unittests.cc ../../../flutter/impeller/docs +../../../flutter/impeller/entity/contents/checkerboard_contents_unittests.cc ../../../flutter/impeller/entity/contents/filters/inputs/filter_input_unittests.cc ../../../flutter/impeller/entity/entity_unittests.cc ../../../flutter/impeller/entity/geometry/geometry_unittests.cc diff --git a/impeller/entity/contents/checkerboard_contents.h b/impeller/entity/contents/checkerboard_contents.h index 2629822a8d322..1c8682a28764b 100644 --- a/impeller/entity/contents/checkerboard_contents.h +++ b/impeller/entity/contents/checkerboard_contents.h @@ -4,7 +4,6 @@ #pragma once -#include "flutter/fml/macros.h" #include "impeller/entity/contents/contents.h" namespace impeller { diff --git a/impeller/entity/contents/checkerboard_contents_unittests.cc b/impeller/entity/contents/checkerboard_contents_unittests.cc index 008184d2f742a..b69ab65992745 100644 --- a/impeller/entity/contents/checkerboard_contents_unittests.cc +++ b/impeller/entity/contents/checkerboard_contents_unittests.cc @@ -19,6 +19,7 @@ namespace testing { using EntityTest = EntityPlayground; INSTANTIATE_PLAYGROUND_SUITE(EntityTest); +#ifdef IMPELLER_DEBUG TEST(EntityTest, HasNulloptCoverage) { auto contents = std::make_shared(); @@ -43,6 +44,7 @@ TEST_P(EntityTest, RendersWithoutError) { ASSERT_TRUE(contents->Render(*content_context, entity, *render_pass)); ASSERT_FALSE(render_pass->GetCommands().empty()); } +#endif // IMPELLER_DEBUG } // namespace testing } // namespace impeller