Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
shader_library.cc File Reference
#include "flutter/lib/gpu/shader_library.h"
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#include "flutter/assets/asset_manager.h"
#include "flutter/lib/gpu/shader.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/platform_configuration.h"
#include "fml/mapping.h"
#include "fml/memory/ref_ptr.h"
#include "impeller/base/validation.h"
#include "impeller/core/shader_types.h"
#include "impeller/renderer/shader_key.h"
#include "impeller/shader_bundle/shader_bundle_flatbuffers.h"
#include "lib/gpu/context.h"
#include "third_party/tonic/typed_data/dart_byte_data.h"

Go to the source code of this file.

Namespaces

namespace  flutter
 
namespace  flutter::gpu
 

Functions

 flutter::gpu::IMPLEMENT_WRAPPERTYPEINFO (flutter_gpu, ShaderLibrary)
 
static impeller::ShaderStage flutter::gpu::ToShaderStage (impeller::fb::shaderbundle::ShaderStage stage)
 
static impeller::ShaderType flutter::gpu::FromInputType (impeller::fb::shaderbundle::InputDataType input_type)
 
static impeller::ShaderType flutter::gpu::FromUniformType (impeller::fb::shaderbundle::UniformDataType uniform_type)
 
static size_t flutter::gpu::SizeOfInputType (impeller::fb::shaderbundle::InputDataType input_type)
 
static const impeller::fb::shaderbundle::BackendShader * flutter::gpu::GetShaderBackend (impeller::Context::BackendType backend_type, const impeller::fb::shaderbundle::Shader *shader)
 
static ShaderLibrary::ShaderMap flutter::gpu::ParseShaderBundle (impeller::Context::BackendType backend_type, const std::shared_ptr< fml::Mapping > &payload, const std::string &library_id)
 
Dart_Handle InternalFlutterGpu_ShaderLibrary_InitializeWithAsset (Dart_Handle wrapper, Dart_Handle asset_name)
 
Dart_Handle InternalFlutterGpu_ShaderLibrary_ReinitializeWithAsset (flutter::gpu::ShaderLibrary *wrapper, Dart_Handle asset_name)
 
Dart_Handle InternalFlutterGpu_ShaderLibrary_InitializeWithBytes (Dart_Handle wrapper, Dart_Handle byte_data)
 
Dart_Handle InternalFlutterGpu_ShaderLibrary_ReinitializeWithBytes (flutter::gpu::ShaderLibrary *wrapper, Dart_Handle byte_data)
 
Dart_Handle InternalFlutterGpu_ShaderLibrary_GetShader (flutter::gpu::ShaderLibrary *wrapper, Dart_Handle shader_name, Dart_Handle shader_wrapper)
 

Function Documentation

◆ InternalFlutterGpu_ShaderLibrary_GetShader()

Dart_Handle InternalFlutterGpu_ShaderLibrary_GetShader ( flutter::gpu::ShaderLibrary wrapper,
Dart_Handle  shader_name,
Dart_Handle  shader_wrapper 
)

Definition at line 569 of file shader_library.cc.

572 {
573 FML_DCHECK(Dart_IsString(shader_name));
574 auto shader =
575 wrapper->GetShader(tonic::StdStringFromDart(shader_name), shader_wrapper);
576 if (!shader) {
577 return Dart_Null();
578 }
579 return tonic::ToDart(shader.get());
580}
fml::RefPtr< Shader > GetShader(const std::string &shader_name, Dart_Handle shader_wrapper)
#define FML_DCHECK(condition)
Definition logging.h:122
Dart_Handle ToDart(const T &object)
std::string StdStringFromDart(Dart_Handle handle)

References FML_DCHECK, flutter::gpu::ShaderLibrary::GetShader(), tonic::StdStringFromDart(), and tonic::ToDart().

◆ InternalFlutterGpu_ShaderLibrary_InitializeWithAsset()

Dart_Handle InternalFlutterGpu_ShaderLibrary_InitializeWithAsset ( Dart_Handle  wrapper,
Dart_Handle  asset_name 
)

Exports

Definition at line 475 of file shader_library.cc.

477 {
478 if (!Dart_IsString(asset_name)) {
479 return tonic::ToDart("Asset name must be a string");
480 }
481
482 std::optional<std::string> out_error;
483 auto impeller_context = flutter::gpu::Context::GetDefaultContext(out_error);
484 if (out_error.has_value()) {
485 return tonic::ToDart(out_error.value());
486 }
487
488 std::string error;
490 impeller_context->GetBackendType(), tonic::StdStringFromDart(asset_name),
491 error);
492 if (!res) {
493 return tonic::ToDart(error);
494 }
495 res->AssociateWithDartWrapper(wrapper);
496 return Dart_Null();
497}
static std::shared_ptr< impeller::Context > GetDefaultContext(std::optional< std::string > &out_error)
Definition context.cc:39
static fml::RefPtr< ShaderLibrary > MakeFromAsset(impeller::Context::BackendType backend_type, const std::string &name, std::string &out_error)
const uint8_t uint32_t uint32_t GError ** error

References error, flutter::gpu::Context::GetDefaultContext(), flutter::gpu::ShaderLibrary::MakeFromAsset(), tonic::StdStringFromDart(), and tonic::ToDart().

◆ InternalFlutterGpu_ShaderLibrary_InitializeWithBytes()

Dart_Handle InternalFlutterGpu_ShaderLibrary_InitializeWithBytes ( Dart_Handle  wrapper,
Dart_Handle  byte_data 
)

Definition at line 520 of file shader_library.cc.

522 {
523 std::optional<std::string> out_error;
524 auto impeller_context = flutter::gpu::Context::GetDefaultContext(out_error);
525 if (out_error.has_value()) {
526 return tonic::ToDart(out_error.value());
527 }
528
529 std::shared_ptr<fml::Mapping> payload =
530 ShaderBundleMappingFromByteData(byte_data);
531 if (payload == nullptr) {
532 return tonic::ToDart("Shader bundle bytes must be a ByteData.");
533 }
534
536 impeller_context->GetBackendType(), std::move(payload));
537 if (!res) {
538 return tonic::ToDart(
539 "Failed to parse the shader bundle bytes. The bytes must be a shader "
540 "bundle compiled by a compatible impellerc.");
541 }
542 res->AssociateWithDartWrapper(wrapper);
543 return Dart_Null();
544}
static fml::RefPtr< ShaderLibrary > MakeFromFlatbuffer(impeller::Context::BackendType backend_type, std::shared_ptr< fml::Mapping > payload, std::string library_id="")

References flutter::gpu::Context::GetDefaultContext(), flutter::gpu::ShaderLibrary::MakeFromFlatbuffer(), and tonic::ToDart().

◆ InternalFlutterGpu_ShaderLibrary_ReinitializeWithAsset()

Dart_Handle InternalFlutterGpu_ShaderLibrary_ReinitializeWithAsset ( flutter::gpu::ShaderLibrary wrapper,
Dart_Handle  asset_name 
)

Definition at line 499 of file shader_library.cc.

501 {
502 if (!Dart_IsString(asset_name)) {
503 return tonic::ToDart("Asset name must be a string");
504 }
505
506 std::optional<std::string> out_error;
507 auto impeller_context = flutter::gpu::Context::GetDefaultContext(out_error);
508 if (out_error.has_value()) {
509 return tonic::ToDart(out_error.value());
510 }
511
512 std::string error = wrapper->ReloadFromAsset(
513 impeller_context->GetBackendType(), tonic::StdStringFromDart(asset_name));
514 if (!error.empty()) {
515 return tonic::ToDart(error);
516 }
517 return Dart_Null();
518}
std::string ReloadFromAsset(impeller::Context::BackendType backend_type, const std::string &name)

References error, flutter::gpu::Context::GetDefaultContext(), flutter::gpu::ShaderLibrary::ReloadFromAsset(), tonic::StdStringFromDart(), and tonic::ToDart().

◆ InternalFlutterGpu_ShaderLibrary_ReinitializeWithBytes()

Dart_Handle InternalFlutterGpu_ShaderLibrary_ReinitializeWithBytes ( flutter::gpu::ShaderLibrary wrapper,
Dart_Handle  byte_data 
)

Definition at line 546 of file shader_library.cc.

548 {
549 std::optional<std::string> out_error;
550 auto impeller_context = flutter::gpu::Context::GetDefaultContext(out_error);
551 if (out_error.has_value()) {
552 return tonic::ToDart(out_error.value());
553 }
554
555 std::shared_ptr<fml::Mapping> payload =
556 ShaderBundleMappingFromByteData(byte_data);
557 if (payload == nullptr) {
558 return tonic::ToDart("Shader bundle bytes must be a ByteData.");
559 }
560
561 std::string error = wrapper->ReloadFromFlatbuffer(
562 impeller_context->GetBackendType(), std::move(payload));
563 if (!error.empty()) {
564 return tonic::ToDart(error);
565 }
566 return Dart_Null();
567}
std::string ReloadFromFlatbuffer(impeller::Context::BackendType backend_type, std::shared_ptr< fml::Mapping > payload)

References error, flutter::gpu::Context::GetDefaultContext(), flutter::gpu::ShaderLibrary::ReloadFromFlatbuffer(), and tonic::ToDart().