5#define FML_USED_ON_EMBEDDER
21#include "impeller/fixtures/texture.frag.h"
22#include "impeller/fixtures/texture.vert.h"
28#include "gtest/gtest.h"
29#include "third_party/imgui/imgui.h"
38 backend_type, std::move(fixture));
52 isolate_ = CreateDartIsolate();
62 auto set_display_texture = [
this](Dart_NativeArguments
args) {
65 Dart_GetNativeArgument(
args, 0));
67 received_texture_ =
texture->GetTexture();
81 return isolate_.get();
87 const char* dart_function_name) {
93 ::Dart_Invoke(Dart_RootLibrary(),
100 FML_LOG(ERROR) <<
"Failed to invoke dart test function:"
101 << dart_function_name;
104 if (!received_texture_) {
105 FML_LOG(ERROR) <<
"Dart test function `" << dart_function_name
106 <<
"` did not invoke `drawToPlaygroundSurface`.";
109 return received_texture_;
119 ::Dart_Invoke(Dart_RootLibrary(),
134 [
this, &dart_function_name]() ->
bool {
138 ::Dart_Invoke(Dart_RootLibrary(),
159 assert(context !=
nullptr);
165 using TextureVS = TextureVertexShader;
166 using TextureFS = TextureFragmentShader;
170 TexturePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
171 if (!pipeline_desc.has_value()) {
172 FML_LOG(ERROR) <<
"Failed to create default pipeline descriptor.";
176 pipeline_desc->SetStencilAttachmentDescriptors(std::nullopt);
177 pipeline_desc->SetDepthStencilAttachmentDescriptor(std::nullopt);
182 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
183 if (!pipeline || !pipeline->IsValid()) {
184 FML_LOG(ERROR) <<
"Failed to create default pipeline.";
198 {{-0.5, -0.5, 0.0}, {0.0, 0.0}},
199 {{ 0.5, -0.5, 0.0}, {1.0, 0.0}},
200 {{ 0.5, 0.5, 0.0}, {1.0, 1.0}},
201 {{-0.5, -0.5, 0.0}, {0.0, 0.0}},
202 {{ 0.5, 0.5, 0.0}, {1.0, 1.0}},
203 {{-0.5, 0.5, 0.0}, {0.0, 1.0}},
211 const auto& sampler = context->GetSamplerLibrary()->GetSampler({});
213 FML_LOG(ERROR) <<
"Failed to create default sampler.";
228 context->GetResourceAllocator(), context->GetIdleWaiter(),
229 context->GetCapabilities()->GetMinimumUniformAlignment());
232 *context->GetResourceAllocator()));
234 TextureVS::UniformBuffer uniforms;
236 TextureVS::BindUniformBuffer(pass,
buffer->EmplaceUniform(uniforms));
237 TextureFS::BindTextureContents(pass,
texture, sampler);
239 pass.SetPipeline(pipeline);
241 if (!pass.Draw().ok()) {
250 std::unique_ptr<flutter::testing::AutoIsolateShutdown> CreateDartIsolate() {
253 current_task_runner_,
254 current_task_runner_,
255 current_task_runner_,
259 vm_ref_, settings, task_runners,
"main", {},
266 std::unique_ptr<flutter::testing::AutoIsolateShutdown> isolate_;
268 std::shared_ptr<Texture> received_texture_;
275 ImGui::Begin(
"Dart test",
nullptr);
277 "This test executes Dart code during the playground frame callback.");
280 return RunDartFunction(
"sayHi");
282 ASSERT_TRUE(OpenPlaygroundHere(
callback));
289 ASSERT_TRUE(RunDartFunction(
"instantiateDefaultContext"));
293 ASSERT_TRUE(RunDartFunction(
"canCreateShaderLibrary"));
297 ASSERT_TRUE(RunDartFunction(
"canReflectUniformStructs"));
301 ASSERT_TRUE(RenderDartToPlayground(
"canCreateRenderPassAndSubmit"));
static void SetOverrideContext(std::shared_ptr< impeller::Context > context)
static void SetOverride(fml::RefPtr< ShaderLibrary > override_shader_library)
Sets a return override for MakeFromAsset for testing purposes.
static fml::RefPtr< ShaderLibrary > MakeFromFlatbuffer(impeller::Context::BackendType backend_type, std::shared_ptr< fml::Mapping > payload)
bool RunInIsolateScope(const std::function< bool(void)> &closure)
virtual Settings CreateSettingsForFixture()
void AddNativeCallback(const std::string &name, Dart_NativeFunction callback)
static void EnsureInitializedForCurrentThread()
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter, size_t minimum_uniform_alignment)
bool OpenPlaygroundHere(const RenderCallback &render_callback)
bool IsPlaygroundEnabled() const
ISize GetWindowSize() const
std::function< bool(RenderPass &pass)> SinglePassCallback
std::shared_ptr< Context > GetContext() const
Render passes encode render commands directed as one specific render target into an underlying comman...
VertexBuffer CreateVertexBuffer(HostBuffer &data_host_buffer, HostBuffer &indexes_host_buffer) const
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
bool RunDartFunctionWithWindowSize(const char *dart_function_name)
Invokes a Dart function with the window's width and height as arguments.
std::shared_ptr< Texture > GetRenderedTextureFromDart(const char *dart_function_name)
Run a Dart function that's expected to create a texture and pass it back for rendering via drawToPlay...
bool RenderDartToPlayground(const char *dart_function_name)
Call a dart function that produces a texture and render the result in the playground.
bool RunDartFunction(const char *dart_function_name)
Invokes a Dart function.
flutter::testing::AutoIsolateShutdown * GetIsolate()
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
std::string GetDefaultKernelFilePath()
Returns the default path to kernel_blob.bin. This file is within the directory returned by GetFixture...
std::unique_ptr< AutoIsolateShutdown > RunDartCodeInIsolate(DartVMRef &vm_ref, const Settings &settings, const TaskRunners &task_runners, std::string entrypoint, const std::vector< std::string > &args, const std::string &kernel_file_path, fml::WeakPtr< IOManager > io_manager, std::unique_ptr< PlatformConfiguration > platform_configuration)
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.
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
static void InstantiateTestShaderLibrary(Context::BackendType backend_type)
TEST_P(AiksTest, DrawAtlasNoColor)
Dart_Handle ToDart(const T &object)
bool CheckAndHandleError(Dart_Handle handle)
#define INSTANTIATE_PLAYGROUND_SUITE(playground)
A 4x4 matrix using column-major storage.
An optional (but highly recommended) utility for creating pipelines from reflected shader information...
#define CREATE_NATIVE_ENTRY(native_entry)