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;
66#define IMP_AIKSTEST(name) \
67 "impeller_Play_AiksTest_" #name "_Metal", \
68 "impeller_Play_AiksTest_" #name "_OpenGLES", \
69 "impeller_Play_AiksTest_" #name "_Vulkan"
78 "impeller_Play_AiksTest_CanRenderClippedRuntimeEffects_Vulkan",
82std::string GetTestName() {
83 std::string suite_name =
84 ::testing::UnitTest::GetInstance()->current_test_suite()->name();
85 std::string test_name =
86 ::testing::UnitTest::GetInstance()->current_test_info()->name();
88 ss <<
"impeller_" << suite_name <<
"_" << test_name;
89 std::string result = ss.str();
91 std::replace(result.begin(), result.end(),
'/',
'_');
95std::string GetGoldenFilename(
const std::string& postfix) {
96 return GetTestName() + postfix +
".png";
101 std::unique_ptr<testing::Screenshot> screenshot,
102 const std::string& postfix) {
103 if (!screenshot || !screenshot->GetBytes()) {
104 FML_LOG(ERROR) <<
"Failed to collect screenshot for test " << GetTestName();
107 std::string test_name = GetTestName();
108 std::string filename = GetGoldenFilename(postfix);
110 test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
111 if (!screenshot->WriteToPNG(
113 FML_LOG(ERROR) <<
"Failed to write screenshot to " << filename;
133 std::shared_ptr<TypographerContext> typographer_context) {
134 typographer_context_ = std::move(typographer_context);
138 ASSERT_FALSE(dlopen(
"/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
142 context->DisposeThreadLocalCachedResources();
147bool DoesSupportWideGamutTests() {
157 std::filesystem::path testing_assets_path =
159 std::filesystem::path target_path = testing_assets_path.parent_path()
163 std::filesystem::path icd_path = target_path /
"vk_swiftshader_icd.json";
164 setenv(
"VK_ICD_FILENAMES", icd_path.c_str(), 1);
166 std::string test_name = GetTestName();
169 test_name.find(
"WideGamut_") != std::string::npos;
171 test_name.find(
"ExperimentAntialiasLines_") != std::string::npos;
172 switch (GetParam()) {
177 if (!DoesSupportWideGamutTests()) {
179 <<
"This metal device doesn't support wide gamut golden tests.";
181 pimpl_->screenshotter =
182 std::make_unique<testing::MetalScreenshotter>(switches);
186 GTEST_SKIP() <<
"Vulkan doesn't support wide gamut golden tests.";
190 <<
"Vulkan doesn't support antialiased lines golden tests.";
192 const std::unique_ptr<PlaygroundImpl>& playground =
193 GetSharedVulkanPlayground(
true);
194 pimpl_->screenshotter =
195 std::make_unique<testing::VulkanScreenshotter>(playground);
200 GTEST_SKIP() <<
"OpenGLES doesn't support wide gamut golden tests.";
204 <<
"OpenGLES doesn't support antialiased lines golden tests.";
211 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
212 pimpl_->test_opengl_playground);
220 <<
"GoldenPlaygroundTest doesn't support interactive playground tests "
225 "gpu_string",
GetContext()->DescribeGpuModel());
236 std::unique_ptr<testing::Screenshot> screenshot;
237 Point content_scale =
238 pimpl_->screenshotter->GetPlayground().GetContentScale();
240 ISize physical_window_size(
241 std::round(pimpl_->window_size.width * content_scale.
x),
242 std::round(pimpl_->window_size.height * content_scale.
y));
243 for (
int i = 0;
i < 2; ++
i) {
247 screenshot = pimpl_->screenshotter->MakeScreenshot(renderer,
texture);
253 const sk_sp<flutter::DisplayList>& list) {
260 std::shared_ptr<Context> context =
GetContext();
261 Point content_scale =
262 pimpl_->screenshotter->GetPlayground().GetContentScale();
263 ISize size(std::round(pimpl_->window_size.width * content_scale.
x),
264 std::round(pimpl_->window_size.height * content_scale.
y));
266 std::unique_ptr<testing::Screenshot> screenshot;
269 for (
int i = 0;
i < 2; ++
i) {
271 context->GetResourceAllocator());
273 *context, size, 1,
"Golden Render Pass",
276 if (!render_target.
IsValid()) {
279 std::shared_ptr<CommandBuffer> command_buffer =
280 context->CreateCommandBuffer();
281 if (!command_buffer) {
284 std::shared_ptr<RenderPass> render_pass =
285 command_buffer->CreateRenderPass(render_target);
292 if (!render_pass->EncodeCommands()) {
295 if (!context->GetCommandQueue()->Submit({command_buffer}).ok()) {
298 screenshot = pimpl_->screenshotter->MakeScreenshot(
306 ImGuiWindowFlags flags) {
311 const char* fixture_name,
312 bool enable_mipmapping)
const {
313 std::shared_ptr<fml::Mapping> mapping =
318 result->SetLabel(fixture_name);
324 const char* fixture_name,
325 bool enable_mipmapping)
const {
326 std::shared_ptr<Texture>
texture =
332 const char* asset_name)
const {
333 const std::shared_ptr<fml::Mapping> fixture =
335 if (!fixture || fixture->GetSize() == 0) {
336 return absl::NotFoundError(
"Asset not found or empty.");
342 if (!pimpl_->screenshotter) {
345 return pimpl_->screenshotter->GetPlayground().GetContext();
353 bool enable_vulkan_validations =
true;
354 FML_CHECK(!pimpl_->test_vulkan_playground)
355 <<
"We don't support creating multiple contexts for one test";
356 pimpl_->test_vulkan_playground =
357 MakeVulkanPlayground(enable_vulkan_validations);
358 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
359 pimpl_->test_vulkan_playground);
360 return pimpl_->test_vulkan_playground->GetContext();
368 return pimpl_->screenshotter->GetPlayground().GetContentScale();
376 return pimpl_->window_size;
383void GoldenPlaygroundTest::GoldenPlaygroundTest::SetWindowSize(
ISize size) {
384 pimpl_->window_size = size;
388 const std::shared_ptr<Capabilities>& capabilities) {
389 return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
393 const sk_sp<flutter::DisplayList>& list) {
395 Point content_scale =
396 pimpl_->screenshotter->GetPlayground().GetContentScale();
398 ISize physical_window_size(
399 std::round(pimpl_->window_size.width * content_scale.
x),
400 std::round(pimpl_->window_size.height * content_scale.
y));
401 return pimpl_->screenshotter->MakeScreenshot(
406 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 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.
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)