9 #include "display_list/display_list.h"
15 #include "flutter/third_party/abseil-cpp/absl/base/no_destructor.h"
16 #include "fml/closure.h"
23 #define GLFW_INCLUDE_NONE
24 #include "third_party/glfw/include/GLFW/glfw3.h"
29 std::unique_ptr<PlaygroundImpl> MakeVulkanPlayground(
bool enable_validations) {
30 FML_CHECK(::glfwInit() == GLFW_TRUE);
31 PlaygroundSwitches playground_switches;
32 playground_switches.enable_vulkan_validation = enable_validations;
38 const std::unique_ptr<PlaygroundImpl>& GetSharedVulkanPlayground(
39 bool enable_validations) {
40 if (enable_validations) {
41 static absl::NoDestructor<std::unique_ptr<PlaygroundImpl>>
42 vulkan_validation_playground(
43 MakeVulkanPlayground(
true));
46 static fml::ScopedCleanupClosure context_cleanup(
47 [&] { (*vulkan_validation_playground)->GetContext()->Shutdown(); });
48 return *vulkan_validation_playground;
50 static absl::NoDestructor<std::unique_ptr<PlaygroundImpl>>
51 vulkan_playground(MakeVulkanPlayground(
false));
54 static fml::ScopedCleanupClosure context_cleanup(
55 [&] { (*vulkan_playground)->GetContext()->Shutdown(); });
56 return *vulkan_playground;
62 #define IMP_AIKSTEST(name) \
63 "impeller_Play_AiksTest_" #name "_Metal", \
64 "impeller_Play_AiksTest_" #name "_OpenGLES", \
65 "impeller_Play_AiksTest_" #name "_Vulkan"
74 "impeller_Play_AiksTest_CanRenderClippedRuntimeEffects_Vulkan",
78 std::string GetTestName() {
79 std::string suite_name =
80 ::testing::UnitTest::GetInstance()->current_test_suite()->name();
81 std::string test_name =
82 ::testing::UnitTest::GetInstance()->current_test_info()->name();
84 ss <<
"impeller_" << suite_name <<
"_" << test_name;
85 std::string result = ss.str();
87 std::replace(result.begin(), result.end(),
'/',
'_');
91 std::string GetGoldenFilename(
const std::string& postfix) {
92 return GetTestName() + postfix +
".png";
97 std::unique_ptr<testing::Screenshot> screenshot,
98 const std::string& postfix) {
99 if (!screenshot || !screenshot->GetBytes()) {
100 FML_LOG(ERROR) <<
"Failed to collect screenshot for test " << GetTestName();
103 std::string test_name = GetTestName();
104 std::string filename = GetGoldenFilename(postfix);
106 test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
107 if (!screenshot->WriteToPNG(
109 FML_LOG(ERROR) <<
"Failed to write screenshot to " << filename;
129 std::shared_ptr<TypographerContext> typographer_context) {
130 typographer_context_ = std::move(typographer_context);
134 ASSERT_FALSE(dlopen(
"/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
138 bool DoesSupportWideGamutTests() {
148 std::filesystem::path testing_assets_path =
149 flutter::testing::GetTestingAssetsPath();
150 std::filesystem::path target_path = testing_assets_path.parent_path()
154 std::filesystem::path icd_path = target_path /
"vk_swiftshader_icd.json";
155 setenv(
"VK_ICD_FILENAMES", icd_path.c_str(), 1);
157 std::string test_name = GetTestName();
158 bool enable_wide_gamut = test_name.find(
"WideGamut_") != std::string::npos;
159 switch (GetParam()) {
161 if (!DoesSupportWideGamutTests()) {
163 <<
"This metal device doesn't support wide gamut golden tests.";
165 pimpl_->screenshotter =
166 std::make_unique<testing::MetalScreenshotter>(enable_wide_gamut);
169 if (enable_wide_gamut) {
170 GTEST_SKIP() <<
"Vulkan doesn't support wide gamut golden tests.";
172 const std::unique_ptr<PlaygroundImpl>& playground =
173 GetSharedVulkanPlayground(
true);
174 pimpl_->screenshotter =
175 std::make_unique<testing::VulkanScreenshotter>(playground);
179 if (enable_wide_gamut) {
180 GTEST_SKIP() <<
"OpenGLES doesn't support wide gamut golden tests.";
182 FML_CHECK(::glfwInit() == GLFW_TRUE);
187 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
188 pimpl_->test_opengl_playground);
196 <<
"GoldenPlaygroundTest doesn't support interactive playground tests "
201 "gpu_string",
GetContext()->DescribeGpuModel());
212 std::unique_ptr<testing::Screenshot> screenshot;
213 for (
int i = 0; i < 2; ++i) {
214 auto display_list = callback();
217 screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, texture);
223 const sk_sp<flutter::DisplayList>& list) {
229 ImGuiWindowFlags flags) {
234 const char* fixture_name,
235 bool enable_mipmapping)
const {
236 std::shared_ptr<fml::Mapping> mapping =
237 flutter::testing::OpenFixtureAsMapping(fixture_name);
241 result->SetLabel(fixture_name);
247 const char* fixture_name,
248 bool enable_mipmapping)
const {
249 std::shared_ptr<Texture> texture =
255 const char* asset_name)
const {
256 const std::shared_ptr<fml::Mapping> fixture =
257 flutter::testing::OpenFixtureAsMapping(asset_name);
258 if (!fixture || fixture->GetSize() == 0) {
265 return pimpl_->screenshotter->GetPlayground().GetContext();
273 bool enable_vulkan_validations =
true;
274 FML_CHECK(!pimpl_->test_vulkan_playground)
275 <<
"We don't support creating multiple contexts for one test";
276 pimpl_->test_vulkan_playground =
277 MakeVulkanPlayground(enable_vulkan_validations);
278 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
279 pimpl_->test_vulkan_playground);
280 return pimpl_->test_vulkan_playground->GetContext();
288 return pimpl_->screenshotter->GetPlayground().GetContentScale();
296 return pimpl_->window_size;
299 void GoldenPlaygroundTest::GoldenPlaygroundTest::SetWindowSize(
ISize size) {
300 pimpl_->window_size = size;
304 const std::shared_ptr<Capabilities>& capabilities) {
305 return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
309 const sk_sp<flutter::DisplayList>& list) {
312 return pimpl_->screenshotter->MakeScreenshot(