15 #include "flutter/third_party/abseil-cpp/absl/base/no_destructor.h"
19 #define GLFW_INCLUDE_NONE
20 #include "third_party/glfw/include/GLFW/glfw3.h"
25 std::unique_ptr<PlaygroundImpl> MakeVulkanPlayground(
bool enable_validations) {
26 FML_CHECK(::glfwInit() == GLFW_TRUE);
27 PlaygroundSwitches playground_switches;
28 playground_switches.enable_vulkan_validation = enable_validations;
34 const std::unique_ptr<PlaygroundImpl>& GetSharedVulkanPlayground(
35 bool enable_validations) {
36 if (enable_validations) {
37 static absl::NoDestructor<std::unique_ptr<PlaygroundImpl>>
38 vulkan_validation_playground(
39 MakeVulkanPlayground(
true));
42 static fml::ScopedCleanupClosure context_cleanup(
43 [&] { (*vulkan_validation_playground)->GetContext()->Shutdown(); });
44 return *vulkan_validation_playground;
46 static absl::NoDestructor<std::unique_ptr<PlaygroundImpl>>
47 vulkan_playground(MakeVulkanPlayground(
false));
50 static fml::ScopedCleanupClosure context_cleanup(
51 [&] { (*vulkan_playground)->GetContext()->Shutdown(); });
52 return *vulkan_playground;
57 #define IMP_AIKSTEST(name) \
58 "impeller_Play_AiksTest_" #name "_Metal", \
59 "impeller_Play_AiksTest_" #name "_OpenGLES", \
60 "impeller_Play_AiksTest_" #name "_Vulkan"
69 "impeller_Play_AiksTest_CanRenderClippedRuntimeEffects_Vulkan",
73 std::string GetTestName() {
74 std::string suite_name =
75 ::testing::UnitTest::GetInstance()->current_test_suite()->name();
76 std::string test_name =
77 ::testing::UnitTest::GetInstance()->current_test_info()->name();
79 ss <<
"impeller_" << suite_name <<
"_" << test_name;
80 std::string result = ss.str();
82 std::replace(result.begin(), result.end(),
'/',
'_');
86 std::string GetGoldenFilename() {
87 return GetTestName() +
".png";
90 bool SaveScreenshot(std::unique_ptr<testing::Screenshot> screenshot) {
91 if (!screenshot || !screenshot->GetBytes()) {
92 FML_LOG(ERROR) <<
"Failed to collect screenshot for test " << GetTestName();
95 std::string test_name = GetTestName();
96 std::string filename = GetGoldenFilename();
98 test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
99 if (!screenshot->WriteToPNG(
101 FML_LOG(ERROR) <<
"Failed to write screenshot to " << filename;
123 std::shared_ptr<TypographerContext> typographer_context) {
124 typographer_context_ = std::move(typographer_context);
128 ASSERT_FALSE(dlopen(
"/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
132 std::filesystem::path testing_assets_path =
133 flutter::testing::GetTestingAssetsPath();
134 std::filesystem::path target_path = testing_assets_path.parent_path()
138 std::filesystem::path icd_path = target_path /
"vk_swiftshader_icd.json";
139 setenv(
"VK_ICD_FILENAMES", icd_path.c_str(), 1);
141 switch (GetParam()) {
143 pimpl_->screenshotter = std::make_unique<testing::MetalScreenshotter>();
146 const std::unique_ptr<PlaygroundImpl>& playground =
147 GetSharedVulkanPlayground(
true);
148 pimpl_->screenshotter =
149 std::make_unique<testing::VulkanScreenshotter>(playground);
153 FML_CHECK(::glfwInit() == GLFW_TRUE);
158 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
159 pimpl_->test_opengl_playground);
164 pimpl_->screenshotter = std::make_unique<testing::MetalScreenshotter>();
166 const std::unique_ptr<PlaygroundImpl>& playground =
167 GetSharedVulkanPlayground(
true);
168 pimpl_->screenshotter =
169 std::make_unique<testing::VulkanScreenshotter>(playground);
172 std::string test_name = GetTestName();
176 "GoldenPlaygroundTest doesn't support interactive playground tests "
181 "gpu_string",
GetContext()->DescribeGpuModel());
191 auto screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, picture,
192 pimpl_->window_size);
193 return SaveScreenshot(std::move(screenshot));
201 std::optional<Picture> picture;
202 std::unique_ptr<testing::Screenshot> screenshot;
203 for (
int i = 0; i < 2; ++i) {
204 picture = callback(renderer);
205 if (!picture.has_value()) {
208 screenshot = pimpl_->screenshotter->MakeScreenshot(
209 renderer, picture.value(), pimpl_->window_size);
212 return SaveScreenshot(std::move(screenshot));
217 ImGuiWindowFlags flags) {
222 const char* fixture_name,
223 bool enable_mipmapping)
const {
224 std::shared_ptr<fml::Mapping> mapping =
225 flutter::testing::OpenFixtureAsMapping(fixture_name);
229 result->SetLabel(fixture_name);
235 const char* asset_name)
const {
236 const std::shared_ptr<fml::Mapping> fixture =
237 flutter::testing::OpenFixtureAsMapping(asset_name);
238 if (!fixture || fixture->GetSize() == 0) {
245 return pimpl_->screenshotter->GetPlayground().GetContext();
253 bool enable_vulkan_validations =
true;
254 FML_CHECK(!pimpl_->test_vulkan_playground)
255 <<
"We don't support creating multiple contexts for one test";
256 pimpl_->test_vulkan_playground =
257 MakeVulkanPlayground(enable_vulkan_validations);
258 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
259 pimpl_->test_vulkan_playground);
260 return pimpl_->test_vulkan_playground->GetContext();
268 return pimpl_->screenshotter->GetPlayground().GetContentScale();
276 return pimpl_->window_size;
279 void GoldenPlaygroundTest::GoldenPlaygroundTest::SetWindowSize(
ISize size) {
280 pimpl_->window_size = size;
284 const std::shared_ptr<Capabilities>& capabilities) {
285 return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);