8#include "flutter/lib/ui/painting/fragment_shader.h"
10#include "flutter/display_list/dl_tile_mode.h"
11#include "flutter/display_list/effects/dl_color_source.h"
12#include "flutter/lib/ui/dart_wrapper.h"
13#include "flutter/lib/ui/painting/fragment_program.h"
14#include "flutter/lib/ui/ui_dart_state.h"
26ReusableFragmentShader::ReusableFragmentShader(
29 uint64_t sampler_count)
30 : program_(
std::move(program)),
31 uniform_data_(
SkData::MakeUninitialized(
32 (float_count + 2 * sampler_count) * sizeof(
float))),
33 samplers_(sampler_count),
34 float_count_(float_count) {}
40 auto* fragment_program =
42 uint64_t float_count =
44 uint64_t sampler_count =
47 auto res = fml::MakeRefCounted<ReusableFragmentShader>(
48 fml::Ref(fragment_program), float_count, sampler_count);
49 res->AssociateWithDartWrapper(wrapper);
51 void* raw_uniform_data =
52 reinterpret_cast<void*
>(res->uniform_data_->writable_data());
57bool ReusableFragmentShader::ValidateSamplers() {
58 for (
auto i = 0u;
i < samplers_.size();
i += 1) {
59 if (samplers_[
i] ==
nullptr) {
69void ReusableFragmentShader::SetImageSampler(
Dart_Handle index_handle,
74 if (index >= samplers_.size()) {
77 if (!
image->image()->isUIThreadSafe()) {
83 samplers_[index] = std::make_shared<DlImageColorSource>(
84 image->image(), DlTileMode::kClamp, DlTileMode::kClamp,
85 DlImageSampling::kNearestNeighbor,
nullptr);
88 FML_DCHECK(samplers_[index]->isUIThreadSafe());
90 auto* uniform_floats =
91 reinterpret_cast<float*
>(uniform_data_->writable_data());
92 uniform_floats[float_count_ + 2 * index] =
image->
width();
93 uniform_floats[float_count_ + 2 * index + 1] =
image->
height();
96std::shared_ptr<DlColorSource> ReusableFragmentShader::shader(
103 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
104 uniform_data->resize(uniform_data_->size());
105 memcpy(uniform_data->data(), uniform_data_->bytes(), uniform_data->size());
107 auto source = program_->MakeDlColorSource(std::move(uniform_data), samplers_);
114void ReusableFragmentShader::Dispose() {
115 uniform_data_.
reset();
121ReusableFragmentShader::~ReusableFragmentShader() =
default;
static sk_sp< Effect > Create()
DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type, void *data, intptr_t length)
struct _Dart_Handle * Dart_Handle
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
@ Dart_TypedData_kFloat32
#define FML_CHECK(condition)
#define FML_DCHECK(condition)
sk_sp< const SkImage > image
SkSamplingOptions sampling
IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, FlutterGpuTestClass)
Dart_Handle ToDart(const T &object)