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"
39 backend_type, std::move(fixture));
50 if (
queue ==
nullptr) {
53 queue->RunMicrotasks();
67 isolate_ = CreateDartIsolate();
77 auto set_display_texture = [
this](Dart_NativeArguments
args) {
80 Dart_GetNativeArgument(
args, 0));
82 received_texture_ =
texture->GetTexture();
96 return isolate_.get();
102 const char* dart_function_name) {
108 ::Dart_Invoke(Dart_RootLibrary(),
115 FML_LOG(ERROR) <<
"Failed to invoke dart test function:"
116 << dart_function_name;
119 if (!received_texture_) {
120 FML_LOG(ERROR) <<
"Dart test function `" << dart_function_name
121 <<
"` did not invoke `drawToPlaygroundSurface`.";
124 return received_texture_;
134 ::Dart_Invoke(Dart_RootLibrary(),
149 [
this, &dart_function_name]() ->
bool {
153 ::Dart_Invoke(Dart_RootLibrary(),
180 using TextureVS = TextureVertexShader;
181 using TextureFS = TextureFragmentShader;
185 TexturePipelineBuilder::MakeDefaultPipelineDescriptor(*
context);
186 if (!pipeline_desc.has_value()) {
187 FML_LOG(ERROR) <<
"Failed to create default pipeline descriptor.";
191 pipeline_desc->SetStencilAttachmentDescriptors(std::nullopt);
192 pipeline_desc->SetDepthStencilAttachmentDescriptor(std::nullopt);
197 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
199 FML_LOG(ERROR) <<
"Failed to create default pipeline.";
213 {{-0.5, -0.5, 0.0}, {0.0, 0.0}},
214 {{ 0.5, -0.5, 0.0}, {1.0, 0.0}},
215 {{ 0.5, 0.5, 0.0}, {1.0, 1.0}},
216 {{-0.5, -0.5, 0.0}, {0.0, 0.0}},
217 {{ 0.5, 0.5, 0.0}, {1.0, 1.0}},
218 {{-0.5, 0.5, 0.0}, {0.0, 1.0}},
226 const auto& sampler =
context->GetSamplerLibrary()->GetSampler({});
228 FML_LOG(ERROR) <<
"Failed to create default sampler.";
244 context->GetCapabilities()->GetMinimumUniformAlignment());
247 *
context->GetResourceAllocator()));
249 TextureVS::UniformBuffer uniforms;
251 TextureVS::BindUniformBuffer(pass,
buffer->EmplaceUniform(uniforms));
252 TextureFS::BindTextureContents(pass,
texture, sampler);
256 if (!pass.Draw().ok()) {
265 std::unique_ptr<flutter::testing::AutoIsolateShutdown> CreateDartIsolate() {
268 current_task_runner_,
269 current_task_runner_,
270 current_task_runner_,
274 vm_ref_, settings, task_runners,
"main", {},
281 std::unique_ptr<flutter::testing::AutoIsolateShutdown> isolate_;
283 std::shared_ptr<Texture> received_texture_;
290 ImGui::Begin(
"Dart test",
nullptr);
292 "This test executes Dart code during the playground frame callback.");
295 return RunDartFunction(
"sayHi");
297 ASSERT_TRUE(OpenPlaygroundHere(
callback));
304 ASSERT_TRUE(RunDartFunction(
"instantiateDefaultContext"));
308 ASSERT_TRUE(RunDartFunction(
"canCreateShaderLibrary"));
312 ASSERT_TRUE(RunDartFunction(
"canReflectUniformStructs"));
316 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, std::string library_id="")
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()
static DartMicrotaskQueue * GetForCurrentThread()
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 bool DrainMicrotasks()
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)
std::shared_ptr< ContextGLES > context
std::shared_ptr< PipelineGLES > pipeline
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)