29Dart_Handle ReusableFragmentShader::Create(Dart_Handle wrapper,
31 Dart_Handle float_count_handle,
32 Dart_Handle sampler_count_handle) {
33 auto* fragment_program =
35 uint64_t float_count =
37 uint64_t sampler_count =
40 auto res = fml::MakeRefCounted<ReusableFragmentShader>(
41 fml::Ref(fragment_program), float_count, sampler_count);
42 res->AssociateWithDartWrapper(wrapper);
44 void* raw_uniform_data =
45 reinterpret_cast<void*
>(res->uniform_data_->writable_data());
46 return Dart_NewExternalTypedData(Dart_TypedData_kFloat32, raw_uniform_data,
62void ReusableFragmentShader::SetImageSampler(Dart_Handle index_handle,
63 Dart_Handle image_handle) {
67 if (index >= samplers_.size()) {
68 Dart_ThrowException(
tonic::ToDart(
"Sampler index out of bounds"));
72 Dart_ThrowException(
tonic::ToDart(
"Image has been disposed"));
76 Dart_ThrowException(
tonic::ToDart(
"Image is not thread-safe"));
82 samplers_[index] = DlColorSource::MakeImage(
83 image->
image(), DlTileMode::kClamp, DlTileMode::kClamp,
84 DlImageSampling::kNearestNeighbor,
nullptr);
87 FML_DCHECK(samplers_[index]->isUIThreadSafe());
89 auto* uniform_floats =
90 reinterpret_cast<float*
>(uniform_data_->writable_data());
91 uniform_floats[float_count_ + 2 * index] =
image->width();
92 uniform_floats[float_count_ + 2 * index + 1] =
image->height();
95std::shared_ptr<DlImageFilter> ReusableFragmentShader::as_image_filter()
const {
101 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
102 uniform_data->resize(uniform_data_->size());
103 memcpy(uniform_data->data(), uniform_data_->bytes(), uniform_data->size());
105 return program_->MakeDlImageFilter(std::move(uniform_data), samplers_);
108std::shared_ptr<DlColorSource> ReusableFragmentShader::shader(
115 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
116 uniform_data->resize(uniform_data_->size());
117 memcpy(uniform_data->data(), uniform_data_->bytes(), uniform_data->size());
119 auto source = program_->MakeDlColorSource(std::move(uniform_data), samplers_);