| Flutter Impeller |

Public Member Functions | List of all members
impeller::testing::RendererDartTest Class Reference
Inheritance diagram for impeller::testing::RendererDartTest:

## Public Member Functions
| RendererDartTest ()
flutter::testing::AutoIsolateShutdown * | GetIsolate ()
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 `drawToPlayground`. More...
bool | RunDartFunction (const char *dart_function_name)
| Invokes a Dart function. More...
bool | RunDartFunctionWithWindowSize (const char *dart_function_name)
| Invokes a Dart function with the window's width and height as arguments. More...
bool | RenderDartToPlayground (const char *dart_function_name)
| Call a dart function that produces a texture and render the result in the playground. More...
Public Member Functions inherited from impeller::PlaygroundTest
| PlaygroundTest ()
virtual | ~PlaygroundTest ()
void | SetUp () override
void | TearDown () override
PlaygroundBackend | GetBackend () const
std::unique_ptr< fml::Mapping > | OpenAssetAsMapping (std::string asset_name) const override
RuntimeStage::Map | OpenAssetAsRuntimeStage (const char *asset_name) const
std::string | GetWindowTitle () const override
Public Member Functions inherited from impeller::Playground
| Playground (PlaygroundSwitches switches)
virtual | ~Playground ()
void | SetupContext (PlaygroundBackend backend, const PlaygroundSwitches &switches)
void | SetupWindow ()
void | TeardownWindow ()
bool | IsPlaygroundEnabled () const
Point | GetCursorPosition () const
ISize | GetWindowSize () const
Point | GetContentScale () const
Scalar | GetSecondsElapsed () const
| Get the amount of time elapsed from the start of the playground's execution. More...
std::shared_ptr< Context > | GetContext () const
std::shared_ptr< Context > | MakeContext () const
bool | OpenPlaygroundHere (const RenderCallback &render_callback)
bool | OpenPlaygroundHere (SinglePassCallback pass_callback)
std::shared_ptr< Texture > | CreateTextureForFixture (const char *fixture_name, bool enable_mipmapping=false) const
std::shared_ptr< Texture > | CreateTextureCubeForFixture (std::array< const char *, 6 > fixture_names) const
fml::Status | SetCapabilities (const std::shared_ptr< Capabilities > &capabilities)
bool | WillRenderSomething () const
| Returns true if `OpenPlaygroundHere` will actually render anything. More...
GLProcAddressResolver | CreateGLProcAddressResolver () const
VKProcAddressResolver | CreateVKProcAddressResolver () const

## 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)>
Static Public Member Functions inherited from impeller::Playground
static bool | ShouldOpenNewPlaygrounds ()
static std::shared_ptr< CompressedImage > | LoadFixtureImageCompressed (std::shared_ptr< fml::Mapping > mapping)
static std::optional< DecompressedImage > | DecodeImageRGBA (const std::shared_ptr< CompressedImage > &compressed)
static std::shared_ptr< Texture > | CreateTextureForMapping (const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)
static bool | SupportsBackend (PlaygroundBackend backend)
Protected Member Functions inherited from impeller::Playground
void | SetWindowSize (ISize size)
Protected Attributes inherited from impeller::Playground
const PlaygroundSwitches | switches_

## Detailed Description

Definition at line 42 of file renderer_dart_unittests.cc.

## Constructor & Destructor Documentation

## ◆ RendererDartTest()

impeller::testing::RendererDartTest::RendererDartTest | ( |  | ) |
| inline

Definition at line 45 of file renderer_dart_unittests.cc.

46 : settings_(CreateSettingsForFixture()),
47 vm_ref_(flutter::DartVMRef::Create(settings_)) {
48 fml::MessageLoop::EnsureInitializedForCurrentThread();
49
50 current_task_runner_ = fml::MessageLoop::GetCurrent().GetTaskRunner();
51
52 isolate_ = CreateDartIsolate();
53 assert(isolate_);
54 assert(isolate_->get()->GetPhase() == flutter::DartIsolate::Phase::Running);
55
56 // Set up native callbacks.
57 //
58 // Note: The Dart isolate is configured (by
59 // `RendererDartTest::CreateDartIsolate`) to use the main thread, so
60 // there's no need for additional synchronization.
61 {
62 auto set_display_texture = [this](Dart_NativeArguments args) {
63 flutter::gpu::Texture* texture =
64 tonic::DartConverter<flutter::gpu::Texture*>::FromDart(
65 Dart_GetNativeArgument(args, 0));
66 assert(texture != nullptr); // Should always be a valid pointer.
67 received_texture_ = texture->GetTexture();
68 };
69 AddNativeCallback("SetDisplayTexture",
70 CREATE_NATIVE_ENTRY(set_display_texture));
71 }
72 }
impeller::interop::Create
ScopedObject< Object > Create(CtorArgs &&... args)
Definition: object.h:161

## Member Function Documentation

## ◆ GetIsolate()

flutter::testing::AutoIsolateShutdown* impeller::testing::RendererDartTest::GetIsolate | ( |  | ) |
| inline

Definition at line 74 of file renderer_dart_unittests.cc.

74 {
75 // Sneak the context into the Flutter GPU API.
76 assert(GetContext() != nullptr);
77 flutter::gpu::Context::SetOverrideContext(GetContext());
78
79 InstantiateTestShaderLibrary(GetContext()->GetBackendType());
80
81 return isolate_.get();
82 }
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:91
impeller::testing::InstantiateTestShaderLibrary
static void InstantiateTestShaderLibrary(Context::BackendType backend_type)
Definition: renderer_dart_unittests.cc:34

References impeller::Playground::GetContext(), and impeller::testing::InstantiateTestShaderLibrary().

Referenced by GetRenderedTextureFromDart(), RunDartFunction(), and RunDartFunctionWithWindowSize().

## ◆ GetRenderedTextureFromDart()

std::shared_ptr<Texture> impeller::testing::RendererDartTest::GetRenderedTextureFromDart | ( | const char * | dart_function_name | ) |
| inline

Run a Dart function that's expected to create a texture and pass it back for rendering via `drawToPlayground`.

Definition at line 86 of file renderer_dart_unittests.cc.

87 {
88 bool success =
89 GetIsolate()->RunInIsolateScope([this, &dart_function_name]() -> bool {
90 Dart_Handle args[] = {tonic::ToDart(GetWindowSize().width),
91 tonic::ToDart(GetWindowSize().height)};
92 if (tonic::CheckAndHandleError(
93 ::Dart_Invoke(Dart_RootLibrary(),
94 tonic::ToDart(dart_function_name), 2, args))) {
95 return false;
96 }
97 return true;
98 });
99 if (!success) {
100 FML_LOG(ERROR) << "Failed to invoke dart test function:"
101 << dart_function_name;
102 return nullptr;
103 }
104 if (!received_texture_) {
105 FML_LOG(ERROR) << "Dart test function `" << dart_function_name
106 << "` did not invoke `drawToPlaygroundSurface`.";
107 return nullptr;
108 }
109 return received_texture_;
110 }
impeller::Playground::GetWindowSize
ISize GetWindowSize() const
Definition: playground.cc:185
impeller::testing::RendererDartTest::GetIsolate
flutter::testing::AutoIsolateShutdown * GetIsolate()
Definition: renderer_dart_unittests.cc:74

References GetIsolate(), and impeller::Playground::GetWindowSize().

Referenced by RenderDartToPlayground().

## ◆ RenderDartToPlayground()

bool impeller::testing::RendererDartTest::RenderDartToPlayground | ( | const char * | dart_function_name | ) |
| inline

Call a dart function that produces a texture and render the result in the playground.

If the playground isn't enabled, the function is simply run once in order to verify that it doesn't throw any unhandled exceptions.

Prepare pipeline.

Prepare vertex data.

Prepare sampler.

Render to playground.

Definition at line 151 of file renderer_dart_unittests.cc.

151 {
152 if (!IsPlaygroundEnabled()) {
153 // If the playground is not enabled, run the function instead to at least
154 // verify that it doesn't crash.
155 return RunDartFunctionWithWindowSize(dart_function_name);
156 }
157
158 auto context = GetContext();
159 assert(context != nullptr);
160
161 //------------------------------------------------------------------------------
162 /// Prepare pipeline.
163 ///
164
165 using TextureVS = TextureVertexShader;
166 using TextureFS = TextureFragmentShader;
167 using TexturePipelineBuilder = PipelineBuilder<TextureVS, TextureFS>;
168
169 auto pipeline_desc =
170 TexturePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
171 if (!pipeline_desc.has_value()) {
172 FML_LOG(ERROR) << "Failed to create default pipeline descriptor.";
173 return false;
174 }
175 pipeline_desc->SetSampleCount(SampleCount::kCount4);
176 pipeline_desc->SetStencilAttachmentDescriptors(std::nullopt);
177 pipeline_desc->SetDepthStencilAttachmentDescriptor(std::nullopt);
178 pipeline_desc->SetStencilPixelFormat(PixelFormat::kUnknown);
179 pipeline_desc->SetDepthPixelFormat(PixelFormat::kUnknown);
180
181 auto pipeline =
182 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
183 if (!pipeline || !pipeline->IsValid()) {
184 FML_LOG(ERROR) << "Failed to create default pipeline.";
185 return false;
186 }
187
188 //------------------------------------------------------------------------------
189 /// Prepare vertex data.
190 ///
191
192 VertexBufferBuilder<TextureVS::PerVertexData> texture_vtx_builder;
193
194 // Always stretch out the texture to fill the screen.
195
196 // clang-format off
197 texture_vtx_builder.AddVertices({
198 {{-0.5, -0.5, 0.0}, {0.0, 0.0}}, // 1
199 {{ 0.5, -0.5, 0.0}, {1.0, 0.0}}, // 2
200 {{ 0.5, 0.5, 0.0}, {1.0, 1.0}}, // 3
201 {{-0.5, -0.5, 0.0}, {0.0, 0.0}}, // 1
202 {{ 0.5, 0.5, 0.0}, {1.0, 1.0}}, // 3
203 {{-0.5, 0.5, 0.0}, {0.0, 1.0}}, // 4
204 });
205 // clang-format on
206
207 //------------------------------------------------------------------------------
208 /// Prepare sampler.
209 ///
210
211 const auto& sampler = context->GetSamplerLibrary()->GetSampler({});
212 if (!sampler) {
213 FML_LOG(ERROR) << "Failed to create default sampler.";
214 return false;
215 }
216
217 //------------------------------------------------------------------------------
218 /// Render to playground.
219 ///
220
221 SinglePassCallback callback = [&](RenderPass& pass) {
222 auto texture = GetRenderedTextureFromDart(dart_function_name);
223 if (!texture) {
224 return false;
225 }
226
227 auto buffer = HostBuffer::Create(context->GetResourceAllocator(),
228 context->GetIdleWaiter());
229
230 pass.SetVertexBuffer(texture_vtx_builder.CreateVertexBuffer(
231 *context->GetResourceAllocator()));
232
233 TextureVS::UniformBuffer uniforms;
234 uniforms.mvp = Matrix();
235 TextureVS::BindUniformBuffer(pass, buffer->EmplaceUniform(uniforms));
236 TextureFS::BindTextureContents(pass, texture, sampler);
237
238 pass.SetPipeline(pipeline);
239
240 if (!pass.Draw().ok()) {
241 return false;
242 }
243 return true;
244 };
245 return OpenPlaygroundHere(callback);
246 }
impeller::HostBuffer::Create
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter)
Definition: host_buffer.cc:21
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const RenderCallback &render_callback)
Definition: playground.cc:201
impeller::Playground::IsPlaygroundEnabled
bool IsPlaygroundEnabled() const
Definition: playground.cc:147
impeller::Playground::SinglePassCallback
std::function< bool(RenderPass &pass)> SinglePassCallback
Definition: playground.h:50
impeller::testing::RendererDartTest::RunDartFunctionWithWindowSize
bool RunDartFunctionWithWindowSize(const char *dart_function_name)
Invokes a Dart function with the window's width and height as arguments.
Definition: renderer_dart_unittests.cc:132
impeller::testing::RendererDartTest::GetRenderedTextureFromDart
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...
Definition: renderer_dart_unittests.cc:86
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::SampleCount::kCount4
@ kCount4

References impeller::VertexBufferBuilder< VertexType_, IndexType_ >::AddVertices(), impeller::HostBuffer::Create(), impeller::VertexBufferBuilder< VertexType_, IndexType_ >::CreateVertexBuffer(), impeller::Playground::GetContext(), GetRenderedTextureFromDart(), impeller::Playground::IsPlaygroundEnabled(), impeller::kCount4, impeller::kUnknown, impeller::Playground::OpenPlaygroundHere(), and RunDartFunctionWithWindowSize().

## ◆ RunDartFunction()

bool impeller::testing::RendererDartTest::RunDartFunction | ( | const char * | dart_function_name | ) |
| inline

Invokes a Dart function.

        Returns false if invoking the function failed or if any unhandled
        exceptions were thrown.

Definition at line 116 of file renderer_dart_unittests.cc.

116 {
117 return GetIsolate()->RunInIsolateScope([&dart_function_name]() -> bool {
118 if (tonic::CheckAndHandleError(
119 ::Dart_Invoke(Dart_RootLibrary(),
120 tonic::ToDart(dart_function_name), 0, nullptr))) {
121 return false;
122 }
123 return true;
124 });
125 }

References GetIsolate().

## ◆ RunDartFunctionWithWindowSize()

bool impeller::testing::RendererDartTest::RunDartFunctionWithWindowSize | ( | const char * | dart_function_name | ) |
| inline

Invokes a Dart function with the window's width and height as arguments.

Returns false if invoking the function failed or if any unhandled exceptions were thrown.

Definition at line 132 of file renderer_dart_unittests.cc.

132 {
133 return GetIsolate()->RunInIsolateScope(
134 [this, &dart_function_name]() -> bool {
135 Dart_Handle args[] = {tonic::ToDart(GetWindowSize().width),
136 tonic::ToDart(GetWindowSize().height)};
137 if (tonic::CheckAndHandleError(
138 ::Dart_Invoke(Dart_RootLibrary(),
139 tonic::ToDart(dart_function_name), 2, args))) {
140 return false;
141 }
142 return true;
143 });
144 }

References GetIsolate(), and impeller::Playground::GetWindowSize().

Referenced by RenderDartToPlayground().

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

- impeller/renderer/renderer_dart_unittests.cc