Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::PlaygroundTest Class Reference

#include <playground_test.h>

Inheritance diagram for impeller::PlaygroundTest:
impeller::Playground impeller::AiksPlayground impeller::DlPlayground impeller::EntityPlayground impeller::PlaygroundTestWithGoldens impeller::RuntimeStagePlayground impeller::interop::testing::PlaygroundTest impeller::testing::RendererDartTest impeller::AiksPlaygroundWithGoldens impeller::DlPlaygroundWithGoldens impeller::testing::BlendFilterContentsTest impeller::testing::GaussianBlurFilterContentsTest impeller::testing::MatrixFilterContentsTest impeller::testing::MorphologyFilterContentsTest

Public Member Functions

 PlaygroundTest ()
 
virtual ~PlaygroundTest ()
 
void SetUp () override
 
void TearDown () override
 
PlaygroundBackend GetBackend () const
 
std::unique_ptr< fml::MappingOpenAssetAsMapping (std::string asset_name) const override
 
absl::StatusOr< RuntimeStage::MapOpenAssetAsRuntimeStage (const char *asset_name) const
 
std::string GetWindowTitle () const override
 
testing::GoldenDigestManagerGetGoldenDigestManager () const override
 
- Public Member Functions inherited from impeller::Playground
 Playground (PlaygroundBackend backend, const PlaygroundSwitches &switches)
 
virtual ~Playground ()
 
bool IsPlaygroundEnabled () const
 
Point GetCursorPosition () const
 
ISize GetWindowSize () const
 
IRect GetWindowBounds () const
 
Point GetContentScale () const
 
Scalar GetSecondsElapsed () const
 Get the amount of time elapsed from the start of the playground's execution.
 
std::shared_ptr< ContextGetContext () const
 
std::shared_ptr< ContextMakeContext () const
 
ContentContextGetContentContext () const
 
std::shared_ptr< TypographerContextGetTypographerContext () const
 
bool ShouldWriteGoldenImage ()
 Whether this instance will write a golden image of the output from |OpenPlaygroundHere|.
 
void SetEnableWriteGolden (bool write_golden)
 Sets a particular test to either write a golden or not, false by default.
 
bool OpenPlaygroundHere (const RenderCallback &render_callback)
 
bool OpenPlaygroundHere (const SinglePassCallback &pass_callback)
 
std::shared_ptr< TextureCreateTextureForFixture (const char *fixture_name, bool enable_mipmapping=false) const
 
std::shared_ptr< TextureCreateTextureCubeForFixture (std::array< const char *, 6 > fixture_names) const
 
fml::Status SetCapabilities (const std::shared_ptr< Capabilities > &capabilities)
 
GLProcAddressResolver CreateGLProcAddressResolver () const
 
VKProcAddressResolver CreateVKProcAddressResolver () const
 
void SetGPUDisabled (bool disabled) const
 Mark the GPU as unavilable.
 
RuntimeStageBackend GetRuntimeStageBackend () const
 
bool InitializePipelineDescriptorForRendering (PipelineDescriptor &desc) const
 Initializes the provided |PipelineDescriptor| with appropriate default values to match the conditions under which a pipeline will be rendered.
 

Static Public Member Functions

static void SetupTestEnvironment ()
 
- Static Public Member Functions inherited from impeller::Playground
static void OnTearDownTestEnvironment ()
 
static bool ShouldOpenNewPlaygrounds ()
 
static std::shared_ptr< CompressedImageLoadFixtureImageCompressed (std::shared_ptr< fml::Mapping > mapping)
 
static std::optional< DecompressedImageDecodeImageRGBA (const std::shared_ptr< CompressedImage > &compressed)
 
static std::shared_ptr< TextureCreateTextureForMapping (const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)
 
static bool SupportsBackend (PlaygroundBackend backend)
 

Protected Member Functions

virtual bool IsGoldenTestSuite () const
 This method is overridden on a test suite basis and establishes whether a given set of tests is intended to generate goldens.
 
- Protected Member Functions inherited from impeller::Playground
void TearDownContextData ()
 
virtual void EnsureContextIsUnique ()
 Make sure that when the context is later created that it will not be shared with any other playgrounds.
 
bool PlatformSupportsWideGamutTests () const
 Returns true if the platform can support wide gamuts.
 
bool RenderingSupportsMSAA () const
 Returns true if the rendering path supports MSAA rendering.
 
SampleCount GetDefaultSampleCount () const
 Returns the default sample count of the rendering path.
 
virtual bool EnsureContextSupportsWideGamut ()
 Make sure that when the context is later created that it will support wide gamuts if the platform supports it. Returns whether the platform supports wide gamut.
 
const PlaygroundSwitchesGetSwitches () const
 Return an unmodifiable reference to the current switches. The switches might change at the start of a test as it has a brief opportunity to call any of the Ensure* methods that define the environment it expects, but should be stable by the time any subsequent methods that might perform work are called.
 
void SetTypographerContext (std::shared_ptr< TypographerContext > typographer_context)
 
void SetWindowSize (ISize size)
 

Additional Inherited Members

- Public Types inherited from impeller::Playground
using SinglePassCallback = std::function< bool(RenderPass &pass)>
 
using RenderCallback = std::function< bool(RenderTarget &render_target)>
 
using GLProcAddressResolver = std::function< void *(const char *proc_name)>
 
using VKProcAddressResolver = std::function< void *(void *instance, const char *proc_name)>
 

Detailed Description

Definition at line 23 of file playground_test.h.

Constructor & Destructor Documentation

◆ PlaygroundTest()

impeller::PlaygroundTest::PlaygroundTest ( )

Definition at line 20 of file playground_test.cc.

21 : Playground(GetParam(),
22 PlaygroundSwitches{flutter::testing::GetArgsForProcess()}) {
24 [](const char* message, const char* file, int line) -> bool {
25 // GTEST_MESSAGE_AT_ can only be used in a function that returns void.
26 // Hence the goofy lambda. The failure message and location will still
27 // be correct however.
28 //
29 // https://google.github.io/googletest/advanced.html#assertion-placement
30 [message, file, line]() -> void {
31 GTEST_MESSAGE_AT_(file, line, "Impeller Validation Error",
32 ::testing::TestPartResult::kFatalFailure)
33 << message;
34 }();
35 return true;
36 });
37}
Playground(PlaygroundBackend backend, const PlaygroundSwitches &switches)
const char * message
const fml::CommandLine & GetArgsForProcess()
Definition test_args.cc:11
void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback)
Sets a callback that callers (usually tests) can set to intercept validation failures.
Definition validation.cc:21

References impeller::ImpellerValidationErrorsSetCallback(), and message.

◆ ~PlaygroundTest()

impeller::PlaygroundTest::~PlaygroundTest ( )
virtual

Member Function Documentation

◆ GetBackend()

◆ GetGoldenDigestManager()

impeller::testing::GoldenDigestManager * impeller::PlaygroundTest::GetGoldenDigestManager ( ) const
overridevirtual

Reimplemented from impeller::Playground.

Definition at line 171 of file playground_test.cc.

172 {
173 return PlaygroundTestEnvironment::GetGoldenDigestManager();
174}

◆ GetWindowTitle()

std::string impeller::PlaygroundTest::GetWindowTitle ( ) const
overridevirtual

Implements impeller::Playground.

Definition at line 201 of file playground_test.cc.

201 {
202 std::stringstream stream;
203 stream << "Impeller Playground for '"
205 switch (GetBackend()) {
208 break;
211 if (GetSwitches().use_angle) {
212 stream << " (Angle) ";
213 }
214 break;
216 if (GetSwitches().use_swiftshader) {
217 stream << " (SwiftShader) ";
218 }
219 break;
220 }
221 stream << " (Press ESC to quit)";
222 return stream.str();
223}
const PlaygroundSwitches & GetSwitches() const
Return an unmodifiable reference to the current switches. The switches might change at the start of a...
Definition playground.h:183
PlaygroundBackend GetBackend() const
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition testing.cc:14

References GetBackend(), flutter::testing::GetCurrentTestName(), impeller::Playground::GetSwitches(), impeller::kMetal, impeller::kMetalSDF, impeller::kOpenGLES, impeller::kOpenGLESSDF, and impeller::kVulkan.

◆ IsGoldenTestSuite()

bool impeller::PlaygroundTest::IsGoldenTestSuite ( ) const
protectedvirtual

This method is overridden on a test suite basis and establishes whether a given set of tests is intended to generate goldens.

The return value of this method is used to set the default value of |PlaygroundShouldWriteGoldenImage|, but an individual test is still allowed to enable a golden image by calling |SetEnableWriteGolden|.

Returns
false by default unless overridden in a subclass

Reimplemented in impeller::AiksPlaygroundWithGoldens, impeller::DlPlaygroundWithGoldens, and impeller::PlaygroundTestWithGoldens.

Definition at line 176 of file playground_test.cc.

176 {
177 return false;
178}

Referenced by SetUp().

◆ OpenAssetAsMapping()

std::unique_ptr< fml::Mapping > impeller::PlaygroundTest::OpenAssetAsMapping ( std::string  asset_name) const
overridevirtual

Implements impeller::Playground.

Definition at line 185 of file playground_test.cc.

186 {
188}
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.
Definition testing.cc:58

References flutter::testing::OpenFixtureAsMapping().

Referenced by impeller::interop::testing::PlaygroundTest::OpenAssetAsHPPMapping(), and impeller::interop::testing::PlaygroundTest::OpenAssetAsHPPTexture().

◆ OpenAssetAsRuntimeStage()

absl::StatusOr< RuntimeStage::Map > impeller::PlaygroundTest::OpenAssetAsRuntimeStage ( const char *  asset_name) const

Definition at line 190 of file playground_test.cc.

191 {
192 const std::shared_ptr<fml::Mapping> fixture =
194 if (!fixture || fixture->GetSize() == 0) {
195 return absl::NotFoundError("Asset not found or empty.");
196 }
197 return RuntimeStage::DecodeRuntimeStages(fixture);
198}
static absl::StatusOr< Map > DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)

References impeller::RuntimeStage::DecodeRuntimeStages(), and flutter::testing::OpenFixtureAsMapping().

◆ SetUp()

void impeller::PlaygroundTest::SetUp ( )
override

Definition at line 43 of file playground_test.cc.

43 {
44 if (!Playground::SupportsBackend(GetParam())) {
45 GTEST_SKIP() << "Playground doesn't support this backend type.";
46 return;
47 }
48
50 GTEST_SKIP() << "Skipping due to user action.";
51 return;
52 }
53
55}
static bool ShouldOpenNewPlaygrounds()
static bool SupportsBackend(PlaygroundBackend backend)
void SetEnableWriteGolden(bool write_golden)
Sets a particular test to either write a golden or not, false by default.
virtual bool IsGoldenTestSuite() const
This method is overridden on a test suite basis and establishes whether a given set of tests is inten...

References IsGoldenTestSuite(), impeller::Playground::SetEnableWriteGolden(), impeller::Playground::ShouldOpenNewPlaygrounds(), and impeller::Playground::SupportsBackend().

Referenced by impeller::interop::testing::PlaygroundTest::SetUp().

◆ SetupTestEnvironment()

void impeller::PlaygroundTest::SetupTestEnvironment ( )
static

Definition at line 139 of file playground_test.cc.

139 {
140#ifdef ENABLE_VK_SWIFTSHADER
141 // Make sure environment is set up for VK swiftshader
142 std::filesystem::path testing_assets_path =
144 std::filesystem::path target_path = testing_assets_path.parent_path()
145 .parent_path()
146 .parent_path()
147 .parent_path();
148 std::filesystem::path icd_path = target_path / "vk_swiftshader_icd.json";
149 setenv("VK_ICD_FILENAMES", icd_path.c_str(), 1);
150#endif
151
152#ifdef APPLY_METAL_VALIDATION
153 // https://developer.apple.com/documentation/metal/diagnosing_metal_programming_issues_early?language=objc
154 // Enables all shader validation tests.
155 setenv("MTL_SHADER_VALIDATION", "1", true);
156 // Validates accesses to device and constant memory.
157 setenv("MTL_SHADER_VALIDATION_GLOBAL_MEMORY", "1", true);
158 // Validates accesses to threadgroup memory.
159 setenv("MTL_SHADER_VALIDATION_THREADGROUP_MEMORY", "1", true);
160 // Validates that texture references are not nil.
161 setenv("MTL_SHADER_VALIDATION_TEXTURE_USAGE", "1", true);
162 // Enables metal validation.
163 setenv("METAL_DEBUG_ERROR_MODE", "0", true);
164 // Enables metal validation.
165 setenv("METAL_DEVICE_WRAPPER_TYPE", "1", true);
166#endif
167
168 ::testing::AddGlobalTestEnvironment(new PlaygroundTestEnvironment());
169}
const char * GetTestingAssetsPath()
Returns the directory containing assets shared across all tests.

References flutter::testing::GetTestingAssetsPath().

Referenced by impeller::testing::ImpellerUnittestSetup().

◆ TearDown()

void impeller::PlaygroundTest::TearDown ( )
override

The documentation for this class was generated from the following files: