Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Adds impeller display list golden tests #52690

Merged
merged 10 commits into from
May 9, 2024
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
2 changes: 2 additions & 0 deletions ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 40 additions & 17 deletions impeller/display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 52 additions & 0 deletions impeller/display_list/dl_golden_unittests.cc
Original file line number Diff line number Diff line change
@@ -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,
Copy link
Member Author

Choose a reason for hiding this comment

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

I considered making an OpenPlaygroundHere that takes in this lambda, but decided to stick with the existing API. The lambda API would remove boilerplate, but this makes the golden tests more accessible to old tests if we want.

const std::vector<std::unique_ptr<DlImage>>& 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<sk_sp<DlImage>>& 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<sk_sp<DlImage>> images;
images.emplace_back(CreateDlImageForFixture("kalimba.jpg"));
draw(&builder, images);

ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

} // namespace testing
} // namespace flutter
23 changes: 23 additions & 0 deletions impeller/display_list/dl_golden_unittests.h
Original file line number Diff line number Diff line change
@@ -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_
14 changes: 14 additions & 0 deletions impeller/display_list/dl_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -82,4 +83,17 @@ SkFont DlPlayground::CreateTestFont() {
return CreateTestFontOfSize(50);
}

sk_sp<flutter::DlImage> DlPlayground::CreateDlImageForFixture(
const char* fixture_name,
bool enable_mipmapping) const {
std::shared_ptr<fml::Mapping> mapping =
flutter::testing::OpenFixtureAsMapping(fixture_name);
std::shared_ptr<Texture> texture = Playground::CreateTextureForMapping(
GetContext(), mapping, enable_mipmapping);
if (texture) {
texture->SetLabel(fixture_name);
}
return DlImageImpeller::Make(texture);
}

} // namespace impeller
4 changes: 4 additions & 0 deletions impeller/display_list/dl_playground.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class DlPlayground : public PlaygroundTest {

SkFont CreateTestFont();

sk_sp<flutter::DlImage> CreateDlImageForFixture(
const char* fixture_name,
bool enable_mipmapping = false) const;

private:
DlPlayground(const DlPlayground&) = delete;

Expand Down
2 changes: 2 additions & 0 deletions impeller/golden_tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions impeller/golden_tests/golden_playground_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <memory>

#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"
Expand Down Expand Up @@ -43,6 +45,8 @@ class GoldenPlaygroundTest

bool OpenPlaygroundHere(AiksPlaygroundCallback callback);

bool OpenPlaygroundHere(const sk_sp<flutter::DisplayList>& list);

static bool ImGuiBegin(const char* name,
bool* p_open,
ImGuiWindowFlags flags);
Expand All @@ -51,6 +55,10 @@ class GoldenPlaygroundTest
const char* fixture_name,
bool enable_mipmapping = false) const;

sk_sp<flutter::DlImage> CreateDlImageForFixture(
const char* fixture_name,
bool enable_mipmapping = false) const;

RuntimeStage::Map OpenAssetAsRuntimeStage(const char* asset_name) const;

std::shared_ptr<Context> GetContext() const;
Expand Down
18 changes: 18 additions & 0 deletions impeller/golden_tests/golden_playground_test_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -227,6 +229,14 @@ bool GoldenPlaygroundTest::OpenPlaygroundHere(
return SaveScreenshot(std::move(screenshot));
}

bool GoldenPlaygroundTest::OpenPlaygroundHere(
const sk_sp<flutter::DisplayList>& 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) {
Expand All @@ -246,6 +256,14 @@ std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
return result;
}

sk_sp<flutter::DlImage> GoldenPlaygroundTest::CreateDlImageForFixture(
const char* fixture_name,
bool enable_mipmapping) const {
std::shared_ptr<Texture> texture =
CreateTextureForFixture(fixture_name, enable_mipmapping);
return DlImageImpeller::Make(texture);
}

RuntimeStage::Map GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
const char* asset_name) const {
const std::shared_ptr<fml::Mapping> fixture =
Expand Down
12 changes: 12 additions & 0 deletions impeller/golden_tests/golden_playground_test_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,23 @@ bool GoldenPlaygroundTest::OpenPlaygroundHere(
return false;
}

bool GoldenPlaygroundTest::OpenPlaygroundHere(
const sk_sp<flutter::DisplayList>& list) {
return false;
}

std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
const char* fixture_name,
bool enable_mipmapping) const {
return nullptr;
}

sk_sp<flutter::DlImage> GoldenPlaygroundTest::CreateDlImageForFixture(
const char* fixture_name,
bool enable_mipmapping) const {
return nullptr;
}

RuntimeStage::Map GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
const char* asset_name) const {
return {};
Expand Down
8 changes: 7 additions & 1 deletion testing/impeller_golden_tests_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
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