diff --git a/ci/licenses_golden/excluded_files b/ci/licenses_golden/excluded_files index 76840d4082d30..baeb05a703512 100644 --- a/ci/licenses_golden/excluded_files +++ b/ci/licenses_golden/excluded_files @@ -140,6 +140,8 @@ ../../../flutter/impeller/compiler/shader_bundle_unittests.cc ../../../flutter/impeller/compiler/switches_unittests.cc ../../../flutter/impeller/core/allocator_unittests.cc +../../../flutter/impeller/display_list/dl_golden_unittests.cc +../../../flutter/impeller/display_list/dl_golden_unittests.h ../../../flutter/impeller/display_list/dl_unittests.cc ../../../flutter/impeller/display_list/skia_conversions_unittests.cc ../../../flutter/impeller/docs diff --git a/impeller/display_list/BUILD.gn b/impeller/display_list/BUILD.gn index d5acdc83a74ae..aa19bf425d897 100644 --- a/impeller/display_list/BUILD.gn +++ b/impeller/display_list/BUILD.gn @@ -49,31 +49,54 @@ impeller_component("display_list") { } } -impeller_component("display_list_unittests") { - testonly = true - - sources = [ +template("display_list_unittests_component") { + target_name = invoker.target_name + predefined_sources = [ + "dl_golden_unittests.cc", "dl_playground.cc", "dl_playground.h", "dl_unittests.cc", ] - - deps = [ - ":display_list", - "../playground:playground_test", - "//flutter/impeller/scene", - "//flutter/impeller/typographer/backends/stb:typographer_stb_backend", - "//flutter/third_party/txt", - ] - - if (!defined(defines)) { - defines = [] + additional_sources = [] + if (defined(invoker.sources)) { + additional_sources = invoker.sources } - if (impeller_enable_3d) { - defines += [ "IMPELLER_ENABLE_3D" ] + impeller_component(target_name) { + testonly = true + if (defined(invoker.defines)) { + defines = invoker.defines + } else { + defines = [] + } + defines += [ "_USE_MATH_DEFINES" ] + if (impeller_enable_3d) { + defines += [ "IMPELLER_ENABLE_3D" ] + } + + sources = predefined_sources + additional_sources + deps = [ + ":display_list", + "../playground:playground_test", + "//flutter/impeller/scene", + "//flutter/impeller/typographer/backends/stb:typographer_stb_backend", + "//flutter/third_party/txt", + ] + if (defined(invoker.public_configs)) { + public_configs = invoker.public_configs + } } } +display_list_unittests_component("display_list_unittests") { +} + +display_list_unittests_component("display_list_unittests_golden") { + defines = [ + "IMPELLER_GOLDEN_TESTS", + "IMPELLER_ENABLE_VALIDATION=1", + ] +} + impeller_component("skia_conversions_unittests") { testonly = true diff --git a/impeller/display_list/dl_golden_unittests.cc b/impeller/display_list/dl_golden_unittests.cc new file mode 100644 index 0000000000000..81f9e70b33d04 --- /dev/null +++ b/impeller/display_list/dl_golden_unittests.cc @@ -0,0 +1,52 @@ +// 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 "impeller/display_list/dl_golden_unittests.h" + +#include "flutter/display_list/dl_builder.h" +#include "flutter/testing/testing.h" +#include "gtest/gtest.h" + +namespace flutter { +namespace testing { + +using impeller::PlaygroundBackend; +using impeller::PlaygroundTest; + +INSTANTIATE_PLAYGROUND_SUITE(DlGoldenTest); + +TEST_P(DlGoldenTest, CanDrawPaint) { + auto draw = [](DlCanvas* canvas, + const std::vector>& images) { + canvas->Scale(0.2, 0.2); + DlPaint paint; + paint.setColor(DlColor::kCyan()); + canvas->DrawPaint(paint); + }; + + DisplayListBuilder builder; + draw(&builder, /*images=*/{}); + + ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); +} + +TEST_P(DlGoldenTest, CanRenderImage) { + auto draw = [](DlCanvas* canvas, const std::vector>& images) { + FML_CHECK(images.size() >= 1); + DlPaint paint; + paint.setColor(DlColor::kRed()); + canvas->DrawImage(images[0], SkPoint::Make(100.0, 100.0), + DlImageSampling::kLinear, &paint); + }; + + DisplayListBuilder builder; + std::vector> images; + images.emplace_back(CreateDlImageForFixture("kalimba.jpg")); + draw(&builder, images); + + ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); +} + +} // namespace testing +} // namespace flutter diff --git a/impeller/display_list/dl_golden_unittests.h b/impeller/display_list/dl_golden_unittests.h new file mode 100644 index 0000000000000..2722066822a4f --- /dev/null +++ b/impeller/display_list/dl_golden_unittests.h @@ -0,0 +1,23 @@ +// 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. + +#ifndef FLUTTER_IMPELLER_DISPLAY_LIST_DL_GOLDEN_UNITTESTS_H_ +#define FLUTTER_IMPELLER_DISPLAY_LIST_DL_GOLDEN_UNITTESTS_H_ + +#include "impeller/display_list/dl_playground.h" +#include "impeller/golden_tests/golden_playground_test.h" + +namespace flutter { +namespace testing { + +#ifdef IMPELLER_GOLDEN_TESTS +using DlGoldenTest = impeller::GoldenPlaygroundTest; +#else +using DlGoldenTest = impeller::DlPlayground; +#endif + +} // namespace testing +} // namespace flutter + +#endif // FLUTTER_IMPELLER_DISPLAY_LIST_DL_GOLDEN_UNITTESTS_H_ diff --git a/impeller/display_list/dl_playground.cc b/impeller/display_list/dl_playground.cc index ef33e13bc8b13..3378df47a2ec9 100644 --- a/impeller/display_list/dl_playground.cc +++ b/impeller/display_list/dl_playground.cc @@ -7,6 +7,7 @@ #include "flutter/testing/testing.h" #include "impeller/aiks/aiks_context.h" #include "impeller/display_list/dl_dispatcher.h" +#include "impeller/display_list/dl_image_impeller.h" #include "impeller/typographer/backends/skia/typographer_context_skia.h" #include "third_party/imgui/imgui.h" #include "third_party/skia/include/core/SkData.h" @@ -82,4 +83,17 @@ SkFont DlPlayground::CreateTestFont() { return CreateTestFontOfSize(50); } +sk_sp DlPlayground::CreateDlImageForFixture( + const char* fixture_name, + bool enable_mipmapping) const { + std::shared_ptr mapping = + flutter::testing::OpenFixtureAsMapping(fixture_name); + std::shared_ptr texture = Playground::CreateTextureForMapping( + GetContext(), mapping, enable_mipmapping); + if (texture) { + texture->SetLabel(fixture_name); + } + return DlImageImpeller::Make(texture); +} + } // namespace impeller diff --git a/impeller/display_list/dl_playground.h b/impeller/display_list/dl_playground.h index b49b1a556e156..3bc9e48d97733 100644 --- a/impeller/display_list/dl_playground.h +++ b/impeller/display_list/dl_playground.h @@ -31,6 +31,10 @@ class DlPlayground : public PlaygroundTest { SkFont CreateTestFont(); + sk_sp CreateDlImageForFixture( + const char* fixture_name, + bool enable_mipmapping = false) const; + private: DlPlayground(const DlPlayground&) = delete; diff --git a/impeller/golden_tests/BUILD.gn b/impeller/golden_tests/BUILD.gn index 8c8b5548833e0..cd1cae7cb8d58 100644 --- a/impeller/golden_tests/BUILD.gn +++ b/impeller/golden_tests/BUILD.gn @@ -14,6 +14,7 @@ impeller_component("golden_playground_test") { ":digest", "//flutter/fml", "//flutter/impeller/aiks", + "//flutter/impeller/display_list:display_list", "//flutter/impeller/playground", "//flutter/impeller/typographer/backends/skia:typographer_skia_backend", "//flutter/testing:testing_lib", @@ -82,6 +83,7 @@ if (is_mac) { ":metal_screenshot", "//flutter/impeller/aiks", "//flutter/impeller/aiks:aiks_unittests_golden", + "//flutter/impeller/display_list:display_list_unittests_golden", "//flutter/impeller/fixtures", "//flutter/third_party/angle:libEGL", "//flutter/third_party/angle:libGLESv2", diff --git a/impeller/golden_tests/golden_playground_test.h b/impeller/golden_tests/golden_playground_test.h index f57ceb2c543a2..5fdf6720db764 100644 --- a/impeller/golden_tests/golden_playground_test.h +++ b/impeller/golden_tests/golden_playground_test.h @@ -7,6 +7,8 @@ #include +#include "flutter/display_list/display_list.h" +#include "flutter/display_list/image/dl_image.h" #include "flutter/impeller/aiks/aiks_context.h" #include "flutter/impeller/playground/playground.h" #include "flutter/impeller/renderer/render_target.h" @@ -43,6 +45,8 @@ class GoldenPlaygroundTest bool OpenPlaygroundHere(AiksPlaygroundCallback callback); + bool OpenPlaygroundHere(const sk_sp& list); + static bool ImGuiBegin(const char* name, bool* p_open, ImGuiWindowFlags flags); @@ -51,6 +55,10 @@ class GoldenPlaygroundTest const char* fixture_name, bool enable_mipmapping = false) const; + sk_sp CreateDlImageForFixture( + const char* fixture_name, + bool enable_mipmapping = false) const; + RuntimeStage::Map OpenAssetAsRuntimeStage(const char* asset_name) const; std::shared_ptr GetContext() const; diff --git a/impeller/golden_tests/golden_playground_test_mac.cc b/impeller/golden_tests/golden_playground_test_mac.cc index 4fd99b49594ab..f90aaa91ed6ff 100644 --- a/impeller/golden_tests/golden_playground_test_mac.cc +++ b/impeller/golden_tests/golden_playground_test_mac.cc @@ -14,6 +14,8 @@ #include "flutter/impeller/golden_tests/vulkan_screenshotter.h" #include "flutter/third_party/abseil-cpp/absl/base/no_destructor.h" #include "fml/closure.h" +#include "impeller/display_list/dl_dispatcher.h" +#include "impeller/display_list/dl_image_impeller.h" #include "impeller/typographer/backends/skia/typographer_context_skia.h" #include "impeller/typographer/typographer_context.h" @@ -227,6 +229,14 @@ bool GoldenPlaygroundTest::OpenPlaygroundHere( return SaveScreenshot(std::move(screenshot)); } +bool GoldenPlaygroundTest::OpenPlaygroundHere( + const sk_sp& list) { + DlDispatcher dispatcher; + list->Dispatch(dispatcher); + Picture picture = dispatcher.EndRecordingAsPicture(); + return OpenPlaygroundHere(std::move(picture)); +} + bool GoldenPlaygroundTest::ImGuiBegin(const char* name, bool* p_open, ImGuiWindowFlags flags) { @@ -246,6 +256,14 @@ std::shared_ptr GoldenPlaygroundTest::CreateTextureForFixture( return result; } +sk_sp GoldenPlaygroundTest::CreateDlImageForFixture( + const char* fixture_name, + bool enable_mipmapping) const { + std::shared_ptr texture = + CreateTextureForFixture(fixture_name, enable_mipmapping); + return DlImageImpeller::Make(texture); +} + RuntimeStage::Map GoldenPlaygroundTest::OpenAssetAsRuntimeStage( const char* asset_name) const { const std::shared_ptr fixture = diff --git a/impeller/golden_tests/golden_playground_test_stub.cc b/impeller/golden_tests/golden_playground_test_stub.cc index 9d7568a1faff2..bfdb0495e36ae 100644 --- a/impeller/golden_tests/golden_playground_test_stub.cc +++ b/impeller/golden_tests/golden_playground_test_stub.cc @@ -37,11 +37,23 @@ bool GoldenPlaygroundTest::OpenPlaygroundHere( return false; } +bool GoldenPlaygroundTest::OpenPlaygroundHere( + const sk_sp& list) { + return false; +} + std::shared_ptr GoldenPlaygroundTest::CreateTextureForFixture( const char* fixture_name, bool enable_mipmapping) const { return nullptr; } + +sk_sp GoldenPlaygroundTest::CreateDlImageForFixture( + const char* fixture_name, + bool enable_mipmapping) const { + return nullptr; +} + RuntimeStage::Map GoldenPlaygroundTest::OpenAssetAsRuntimeStage( const char* asset_name) const { return {}; diff --git a/testing/impeller_golden_tests_output.txt b/testing/impeller_golden_tests_output.txt index 67fc0eb14d438..99704781e83be 100644 --- a/testing/impeller_golden_tests_output.txt +++ b/testing/impeller_golden_tests_output.txt @@ -773,4 +773,10 @@ impeller_Play_AiksTest_VerticesGeometryUVPositionDataWithTranslate_OpenGLES.png impeller_Play_AiksTest_VerticesGeometryUVPositionDataWithTranslate_Vulkan.png impeller_Play_AiksTest_VerticesGeometryUVPositionData_Metal.png impeller_Play_AiksTest_VerticesGeometryUVPositionData_OpenGLES.png -impeller_Play_AiksTest_VerticesGeometryUVPositionData_Vulkan.png \ No newline at end of file +impeller_Play_AiksTest_VerticesGeometryUVPositionData_Vulkan.png +impeller_Play_DlGoldenTest_CanDrawPaint_Metal.png +impeller_Play_DlGoldenTest_CanDrawPaint_OpenGLES.png +impeller_Play_DlGoldenTest_CanDrawPaint_Vulkan.png +impeller_Play_DlGoldenTest_CanRenderImage_Metal.png +impeller_Play_DlGoldenTest_CanRenderImage_OpenGLES.png +impeller_Play_DlGoldenTest_CanRenderImage_Vulkan.png \ No newline at end of file