Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
render_pipeline.h File Reference

Go to the source code of this file.

Classes

class  flutter::gpu::RenderPipeline
 

Namespaces

namespace  flutter
 
namespace  flutter::gpu
 

Functions

FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_RenderPipeline_Initialize (Dart_Handle wrapper, flutter::gpu::Context *gpu_context, flutter::gpu::Shader *vertex_shader, flutter::gpu::Shader *fragment_shader, Dart_Handle buffer_layouts_handle, Dart_Handle attributes_handle, Dart_Handle attribute_names_handle)
 

Function Documentation

◆ InternalFlutterGpu_RenderPipeline_Initialize()

FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_RenderPipeline_Initialize ( Dart_Handle  wrapper,
flutter::gpu::Context gpu_context,
flutter::gpu::Shader vertex_shader,
flutter::gpu::Shader fragment_shader,
Dart_Handle  buffer_layouts_handle,
Dart_Handle  attributes_handle,
Dart_Handle  attribute_names_handle 
)
extern

Exports

Definition at line 282 of file render_pipeline.cc.

289 {
290 // Lazily register the shaders synchronously if they haven't been already.
291 vertex_shader->RegisterSync(*gpu_context);
292 fragment_shader->RegisterSync(*gpu_context);
293
294 std::shared_ptr<impeller::VertexDescriptor> vertex_descriptor;
295
296 const bool buffer_layouts_provided = !Dart_IsNull(buffer_layouts_handle);
297 const bool attributes_provided = !Dart_IsNull(attributes_handle);
298 const bool attribute_names_provided = !Dart_IsNull(attribute_names_handle);
299 if (buffer_layouts_provided != attributes_provided ||
300 attributes_provided != attribute_names_provided) {
301 return tonic::ToDart(
302 "VertexLayout requires buffer layouts, attributes, and attribute "
303 "names to be provided together.");
304 }
305
306 if (buffer_layouts_provided) {
307 // Copy the packed Dart-side ByteData buffers into local vectors so the
308 // tonic::DartByteData typed-data handles are released before we make any
309 // call back into the Dart VM (e.g. tonic::ToDart for an error string).
310 // Holding a typed-data handle while calling into the VM raises
311 // "Callbacks into the Dart VM are currently prohibited." Errors raised
312 // inside the inner scope must therefore be deferred to a local string
313 // and returned only after the typed-data handles go out of scope.
314 std::vector<int32_t> buffer_layouts_ints;
315 std::vector<int32_t> attribute_ints;
316 std::vector<char> attribute_names_bytes;
317 std::string copy_error;
318 {
319 tonic::DartByteData buffer_layouts_data(buffer_layouts_handle);
320 tonic::DartByteData attributes_data(attributes_handle);
321 tonic::DartByteData attribute_names_data(attribute_names_handle);
322 if (buffer_layouts_data.length_in_bytes() %
323 (flutter::gpu::kBufferLayoutInts * sizeof(int32_t)) !=
324 0) {
325 copy_error =
326 "Internal error: buffer layouts ByteData has invalid length.";
327 } else if (attributes_data.length_in_bytes() %
328 (flutter::gpu::kAttributeInts * sizeof(int32_t)) !=
329 0) {
330 copy_error = "Internal error: attributes ByteData has invalid length.";
331 } else {
332 const auto* buffer_layouts_src =
333 static_cast<const int32_t*>(buffer_layouts_data.data());
334 const auto* attributes_src =
335 static_cast<const int32_t*>(attributes_data.data());
336 const auto* names_src =
337 static_cast<const char*>(attribute_names_data.data());
338 buffer_layouts_ints.assign(
339 buffer_layouts_src,
340 buffer_layouts_src +
341 buffer_layouts_data.length_in_bytes() / sizeof(int32_t));
342 attribute_ints.assign(
343 attributes_src, attributes_src + attributes_data.length_in_bytes() /
344 sizeof(int32_t));
345 attribute_names_bytes.assign(
346 names_src, names_src + attribute_names_data.length_in_bytes());
347 }
348 }
349 if (!copy_error.empty()) {
350 return tonic::ToDart(copy_error);
351 }
352
353 absl::StatusOr<std::shared_ptr<impeller::VertexDescriptor>> built =
354 flutter::gpu::BuildCustomVertexDescriptor(
355 *vertex_shader,
356 std::span<const int32_t>(buffer_layouts_ints.data(),
357 buffer_layouts_ints.size()),
358 std::span<const int32_t>(attribute_ints.data(),
359 attribute_ints.size()),
360 std::span<const char>(attribute_names_bytes.data(),
361 attribute_names_bytes.size()));
362 if (!built.ok()) {
363 return tonic::ToDart(std::string(built.status().message()));
364 }
365 vertex_descriptor = *std::move(built);
366 } else {
367 vertex_descriptor = vertex_shader->CreateVertexDescriptor();
368 }
369
370 auto res = fml::MakeRefCounted<flutter::gpu::RenderPipeline>(
371 fml::RefPtr<flutter::gpu::Shader>(vertex_shader), //
372 fml::RefPtr<flutter::gpu::Shader>(fragment_shader), //
373 std::move(vertex_descriptor));
374 res->AssociateWithDartWrapper(wrapper);
375
376 return Dart_Null();
377}
bool RegisterSync(Context &context)
Definition shader.cc:77
std::shared_ptr< impeller::VertexDescriptor > CreateVertexDescriptor() const
Definition shader.cc:97
Dart_Handle ToDart(const T &object)

References flutter::gpu::Shader::CreateVertexDescriptor(), tonic::DartByteData::data(), tonic::DartByteData::length_in_bytes(), flutter::gpu::Shader::RegisterSync(), and tonic::ToDart().