25#include "third_party/abseil-cpp/absl/base/no_destructor.h"
27#define GLFW_INCLUDE_NONE
28#include "third_party/glfw/include/GLFW/glfw3.h"
33std::unique_ptr<PlaygroundImpl> MakeVulkanPlayground(
bool enable_validations) {
35 PlaygroundSwitches playground_switches;
36 playground_switches.enable_vulkan_validation = enable_validations;
42const std::unique_ptr<PlaygroundImpl>& GetSharedVulkanPlayground(
43 bool enable_validations) {
44 if (enable_validations) {
45 static absl::NoDestructor<std::unique_ptr<PlaygroundImpl>>
46 vulkan_validation_playground(
47 MakeVulkanPlayground(
true));
51 [&] { (*vulkan_validation_playground)->GetContext()->Shutdown(); });
52 return *vulkan_validation_playground;
54 static absl::NoDestructor<std::unique_ptr<PlaygroundImpl>>
55 vulkan_playground(MakeVulkanPlayground(
false));
59 [&] { (*vulkan_playground)->GetContext()->Shutdown(); });
60 return *vulkan_playground;
64std::unique_ptr<PlaygroundImpl> MakeOpenGLESPlayground(
bool use_sdfs =
false) {
66 PlaygroundSwitches playground_switches;
67 playground_switches.use_angle =
true;
68 playground_switches.flags.use_sdfs = use_sdfs;
76const std::unique_ptr<PlaygroundImpl>& GetSharedOpenGLESPlayground(
79 static absl::NoDestructor<std::unique_ptr<PlaygroundImpl>>
80 opengl_playground(MakeOpenGLESPlayground(
true));
82 [&] { (*opengl_playground)->GetContext()->Shutdown(); });
83 return *opengl_playground;
85 static absl::NoDestructor<std::unique_ptr<PlaygroundImpl>>
86 opengl_playground(MakeOpenGLESPlayground(
false));
90 [&] { (*opengl_playground)->GetContext()->Shutdown(); });
91 return *opengl_playground;
97#define IMP_AIKSTEST(name) \
98 "impeller_Play_AiksTest_" #name "_Metal", \
99 "impeller_Play_AiksTest_" #name "_OpenGLES", \
100 "impeller_Play_AiksTest_" #name "_Vulkan"
109 "impeller_Play_AiksTest_CanRenderClippedRuntimeEffects_Vulkan",
113std::string GetTestName() {
114 std::string suite_name =
115 ::testing::UnitTest::GetInstance()->current_test_suite()->name();
116 std::string test_name =
117 ::testing::UnitTest::GetInstance()->current_test_info()->name();
118 std::stringstream ss;
119 ss <<
"impeller_" << suite_name <<
"_" << test_name;
120 std::string result = ss.str();
122 std::replace(result.begin(), result.end(),
'/',
'_');
126std::string GetGoldenFilename(
const std::string& postfix) {
127 return GetTestName() + postfix +
".png";
132 std::unique_ptr<testing::Screenshot> screenshot,
133 const std::string& postfix) {
134 if (!screenshot || !screenshot->GetBytes()) {
135 FML_LOG(ERROR) <<
"Failed to collect screenshot for test " << GetTestName();
138 std::string test_name = GetTestName();
139 std::string filename = GetGoldenFilename(postfix);
141 test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
142 if (!screenshot->WriteToPNG(
144 FML_LOG(ERROR) <<
"Failed to write screenshot to " << filename;
164 std::shared_ptr<TypographerContext> typographer_context) {
165 typographer_context_ = std::move(typographer_context);
169 ASSERT_FALSE(dlopen(
"/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
173 context->DisposeThreadLocalCachedResources();
178bool DoesSupportWideGamutTests() {
192 std::filesystem::path testing_assets_path =
194 std::filesystem::path target_path = testing_assets_path.parent_path()
198 std::filesystem::path icd_path = target_path /
"vk_swiftshader_icd.json";
199 setenv(
"VK_ICD_FILENAMES", icd_path.c_str(), 1);
201 std::string test_name = GetTestName();
204 test_name.find(
"WideGamut_") != std::string::npos;
206 test_name.find(
"ExperimentAntialiasLines_") != std::string::npos;
207 switch (GetParam()) {
212 if (!DoesSupportWideGamutTests()) {
214 <<
"This metal device doesn't support wide gamut golden tests.";
216 pimpl_->screenshotter =
217 std::make_unique<testing::MetalScreenshotter>(switches);
221 GTEST_SKIP() <<
"Vulkan doesn't support wide gamut golden tests.";
225 <<
"Vulkan doesn't support antialiased lines golden tests.";
227 const std::unique_ptr<PlaygroundImpl>& playground =
228 GetSharedVulkanPlayground(
true);
229 pimpl_->screenshotter =
230 std::make_unique<testing::VulkanScreenshotter>(playground);
238 GTEST_SKIP() <<
"OpenGLES doesn't support wide gamut golden tests.";
242 <<
"OpenGLES doesn't support antialiased lines golden tests.";
244 const std::unique_ptr<PlaygroundImpl>& playground =
246 ::glfwMakeContextCurrent(
247 reinterpret_cast<GLFWwindow*
>(playground->GetWindowHandle()));
248 pimpl_->screenshotter =
249 std::make_unique<testing::VulkanScreenshotter>(playground);
257 <<
"GoldenPlaygroundTest doesn't support interactive playground tests "
262 "gpu_string",
GetContext()->DescribeGpuModel());
273 std::unique_ptr<testing::Screenshot> screenshot;
274 Point content_scale =
275 pimpl_->screenshotter->GetPlayground().GetContentScale();
277 ISize physical_window_size(
278 std::round(pimpl_->window_size.width * content_scale.
x),
279 std::round(pimpl_->window_size.height * content_scale.
y));
280 for (
int i = 0;
i < 2; ++
i) {
284 screenshot = pimpl_->screenshotter->MakeScreenshot(renderer,
texture);
290 const sk_sp<flutter::DisplayList>& list) {
298 Point content_scale =
299 pimpl_->screenshotter->GetPlayground().GetContentScale();
300 ISize size(std::round(pimpl_->window_size.width * content_scale.
x),
301 std::round(pimpl_->window_size.height * content_scale.
y));
303 std::unique_ptr<testing::Screenshot> screenshot;
306 for (
int i = 0;
i < 2; ++
i) {
308 context->GetResourceAllocator());
310 *
context, size, 1,
"Golden Render Pass",
313 if (!render_target.
IsValid()) {
317 context->CreateCommandBuffer();
332 if (!
context->GetCommandQueue()->Submit({command_buffer}).ok()) {
335 screenshot = pimpl_->screenshotter->MakeScreenshot(
343 ImGuiWindowFlags flags) {
348 const char* fixture_name,
349 bool enable_mipmapping)
const {
350 std::shared_ptr<fml::Mapping> mapping =
355 result->SetLabel(fixture_name);
361 const char* fixture_name,
362 bool enable_mipmapping)
const {
363 std::shared_ptr<Texture>
texture =
369 const char* asset_name)
const {
370 const std::shared_ptr<fml::Mapping> fixture =
372 if (!fixture || fixture->GetSize() == 0) {
373 return absl::NotFoundError(
"Asset not found or empty.");
379 if (!pimpl_->screenshotter) {
382 return pimpl_->screenshotter->GetPlayground().GetContext();
391 bool enable_vulkan_validations =
true;
392 FML_CHECK(!pimpl_->test_vulkan_playground)
393 <<
"We don't support creating multiple contexts for one test";
394 pimpl_->test_vulkan_playground =
395 MakeVulkanPlayground(enable_vulkan_validations);
396 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
397 pimpl_->test_vulkan_playground);
398 return pimpl_->test_vulkan_playground->GetContext();
401 FML_CHECK(!pimpl_->test_opengl_playground)
402 <<
"We don't support creating multiple contexts for one test";
404 pimpl_->test_opengl_playground = MakeOpenGLESPlayground(use_sdfs);
405 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
406 pimpl_->test_opengl_playground);
407 return pimpl_->test_opengl_playground->GetContext();
415 return pimpl_->screenshotter->GetPlayground().GetContentScale();
423 return pimpl_->window_size;
430void GoldenPlaygroundTest::GoldenPlaygroundTest::SetWindowSize(
ISize size) {
431 pimpl_->window_size = size;
435 const std::shared_ptr<Capabilities>& capabilities) {
436 return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
440 const sk_sp<flutter::DisplayList>& list) {
442 Point content_scale =
443 pimpl_->screenshotter->GetPlayground().GetContentScale();
445 ISize physical_window_size(
446 std::round(pimpl_->window_size.width * content_scale.
x),
447 std::round(pimpl_->window_size.height * content_scale.
y));
448 return pimpl_->screenshotter->MakeScreenshot(
453 return pimpl_->screenshotter->GetPlayground().GetRuntimeStageBackend();
Wraps a closure that is invoked in the destructor unless released by the caller.
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
IRect GetWindowBounds() const
PlaygroundBackend GetBackend() const
ISize GetWindowSize() const
RuntimeStageBackend GetRuntimeStageBackend() const
sk_sp< flutter::DlImage > CreateDlImageForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Point GetContentScale() const
fml::Status SetCapabilities(const std::shared_ptr< Capabilities > &capabilities)
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
std::shared_ptr< Context > MakeContext() const
static bool SaveScreenshot(std::unique_ptr< testing::Screenshot > screenshot, const std::string &postfix="")
std::unique_ptr< testing::Screenshot > MakeScreenshot(const sk_sp< flutter::DisplayList > &list)
Scalar GetSecondsElapsed() const
bool PlatformSupportsWideGamutTests() const
bool OpenPlaygroundHere(Picture picture)
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
std::function< sk_sp< flutter::DisplayList >()> AiksDlPlaygroundCallback
~GoldenPlaygroundTest() override
absl::StatusOr< RuntimeStage::Map > OpenAssetAsRuntimeStage(const char *asset_name) const
std::shared_ptr< Context > GetContext() const
std::shared_ptr< Texture > CreateTextureForFixture(const char *fixture_name, bool enable_mipmapping=false) const
std::function< bool(RenderPass &pass)> SinglePassCallback
static std::shared_ptr< Texture > CreateTextureForMapping(const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...
virtual RenderTarget CreateOffscreen(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr, std::optional< PixelFormat > target_pixel_format=std::nullopt)
std::shared_ptr< Texture > GetRenderTargetTexture() const
static constexpr AttachmentConfig kDefaultColorAttachmentConfig
static absl::StatusOr< Map > DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
static GoldenDigest * Instance()
void AddDimension(const std::string &name, const std::string &value)
void AddImage(const std::string &test_name, const std::string &filename, int32_t width, int32_t height)
std::string GetFilenamePath(const std::string &filename) const
static WorkingDirectory * Instance()
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define IMP_AIKSTEST(name)
const char * GetTestingAssetsPath()
Returns the directory containing assets shared across all tests.
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
static const std::vector< std::string > kSkipTests
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips, std::optional< PixelFormat > target_pixel_format)
Render the provided display list to a texture with the given size.
std::shared_ptr< ContextGLES > context
std::shared_ptr< RenderPass > render_pass
std::shared_ptr< CommandBuffer > command_buffer
bool antialiased_lines
When turned on DrawLine will use the experimental antialiased path.
bool use_sdfs
Use SDFs for rendering.
std::unique_ptr< PlaygroundImpl > test_vulkan_playground
std::unique_ptr< testing::Screenshotter > screenshotter
std::unique_ptr< PlaygroundImpl > test_opengl_playground
static constexpr TRect MakeSize(const TSize< U > &size)