5#define FML_USED_ON_EMBEDDER
9#include "flutter/common/settings.h"
10#include "flutter/common/task_runners.h"
11#include "flutter/lib/gpu/context.h"
12#include "flutter/lib/gpu/shader_library.h"
13#include "flutter/lib/gpu/texture.h"
14#include "flutter/runtime/dart_isolate.h"
15#include "flutter/runtime/dart_vm_lifecycle.h"
16#include "flutter/testing/dart_fixture.h"
17#include "flutter/testing/dart_isolate_runner.h"
18#include "flutter/testing/test_dart_native_resolver.h"
19#include "flutter/testing/testing.h"
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();
67 received_texture_ =
texture->GetTexture();
81 return isolate_.get();
87 const char* dart_function_name) {
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_;
134 [
this, &dart_function_name]() ->
bool {
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()) {
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({});
230 *context->GetResourceAllocator()));
232 TextureVS::UniformBuffer uniforms;
234 TextureVS::BindUniformBuffer(pass,
buffer->EmplaceUniform(uniforms));
235 TextureFS::BindTextureContents(pass,
texture, sampler);
237 pass.SetPipeline(pipeline);
239 if (!pass.Draw().ok()) {
248 std::unique_ptr<flutter::testing::AutoIsolateShutdown> CreateDartIsolate() {
251 current_task_runner_,
252 current_task_runner_,
253 current_task_runner_,
257 vm_ref_, settings, task_runners,
"main", {},
264 std::unique_ptr<flutter::testing::AutoIsolateShutdown> isolate_;
266 std::shared_ptr<Texture> received_texture_;
273 ImGui::Begin(
"Dart test",
nullptr);
275 "This test executes Dart code during the playground frame callback.");
278 return RunDartFunction(
"sayHi");
280 ASSERT_TRUE(OpenPlaygroundHere(
callback));
287 ASSERT_TRUE(RunDartFunction(
"instantiateDefaultContext"));
291 ASSERT_TRUE(RunDartFunction(
"canCreateShaderLibrary"));
295 ASSERT_TRUE(RunDartFunction(
"canReflectUniformStructs"));
299 ASSERT_TRUE(RunDartFunction(
"uniformBindFailsForInvalidHostBufferOffset"));
303 ASSERT_TRUE(RenderDartToPlayground(
"canCreateRenderPassAndSubmit"));
static sk_sp< Effect > Create()
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)
bool IsPlaygroundEnabled() const
ISize GetWindowSize() const
std::function< bool(RenderPass &pass)> SinglePassCallback
std::shared_ptr< Context > GetContext() const
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Render passes encode render commands directed as one specific render target into an underlying comman...
VertexBuffer CreateVertexBuffer(HostBuffer &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()
struct _Dart_Handle * Dart_Handle
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
struct _Dart_NativeArguments * Dart_NativeArguments
DART_EXPORT Dart_Handle Dart_RootLibrary(void)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static const uint8_t buffer[]
#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::shared_ptr< VolatilePathTracker > volatile_path_tracker, 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.
static void InstantiateTestShaderLibrary(Context::BackendType backend_type)
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
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)