Flutter Engine
 
Loading...
Searching...
No Matches
flutter::ReusableFragmentShader Class Reference

#include <fragment_shader.h>

Inheritance diagram for flutter::ReusableFragmentShader:
flutter::Shader flutter::RefCountedDartWrappable< Shader > fml::RefCountedThreadSafe< T > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Public Member Functions

 ~ReusableFragmentShader () override
 
void SetImageSampler (Dart_Handle index, Dart_Handle image)
 
bool ValidateSamplers ()
 
bool ValidateImageFilter ()
 
void Dispose ()
 
std::shared_ptr< DlColorSourceshader (DlImageSampling) override
 
std::shared_ptr< DlImageFilteras_image_filter () const
 
- Public Member Functions inherited from flutter::Shader
 ~Shader () override
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< Shader >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< T >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static Dart_Handle Create (Dart_Handle wrapper, Dart_Handle program, Dart_Handle float_count, Dart_Handle sampler_count)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields {
  kPeerIndex ,
  kNumberOfNativeFields
}
 
- Protected Member Functions inherited from flutter::Shader
 Shader ()
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< T >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 25 of file fragment_shader.h.

Constructor & Destructor Documentation

◆ ~ReusableFragmentShader()

flutter::ReusableFragmentShader::~ReusableFragmentShader ( )
overridedefault

References shader().

Member Function Documentation

◆ as_image_filter()

std::shared_ptr< DlImageFilter > flutter::ReusableFragmentShader::as_image_filter ( ) const

Definition at line 95 of file fragment_shader.cc.

95 {
96 FML_CHECK(program_);
97
98 // The lifetime of this object is longer than a frame, and the uniforms can be
99 // continually changed on the UI thread. So we take a copy of the uniforms
100 // before handing it to the DisplayList for consumption on the render thread.
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());
104
105 return program_->MakeDlImageFilter(std::move(uniform_data), samplers_);
106}
#define FML_CHECK(condition)
Definition logging.h:104

References FML_CHECK.

Referenced by flutter::ImageFilter::initShader().

◆ Create()

Dart_Handle flutter::ReusableFragmentShader::Create ( Dart_Handle  wrapper,
Dart_Handle  program,
Dart_Handle  float_count,
Dart_Handle  sampler_count 
)
static

Definition at line 29 of file fragment_shader.cc.

32 {
33 auto* fragment_program =
35 uint64_t float_count =
37 uint64_t sampler_count =
38 tonic::DartConverter<uint64_t>::FromDart(sampler_count_handle);
39
40 auto res = fml::MakeRefCounted<ReusableFragmentShader>(
41 fml::Ref(fragment_program), float_count, sampler_count);
42 res->AssociateWithDartWrapper(wrapper);
43
44 void* raw_uniform_data =
45 reinterpret_cast<void*>(res->uniform_data_->writable_data());
46 return Dart_NewExternalTypedData(Dart_TypedData_kFloat32, raw_uniform_data,
47 float_count);
48}
RefPtr< T > Ref(T *ptr)
Definition ref_ptr.h:242

References fml::Ref().

◆ Dispose()

void flutter::ReusableFragmentShader::Dispose ( )

Definition at line 144 of file fragment_shader.cc.

144 {
145 uniform_data_.reset();
146 program_ = nullptr;
147 samplers_.clear();
149}

◆ SetImageSampler()

void flutter::ReusableFragmentShader::SetImageSampler ( Dart_Handle  index,
Dart_Handle  image 
)

Definition at line 62 of file fragment_shader.cc.

63 {
64 uint64_t index = tonic::DartConverter<uint64_t>::FromDart(index_handle);
65 CanvasImage* image =
67 if (index >= samplers_.size()) {
68 Dart_ThrowException(tonic::ToDart("Sampler index out of bounds"));
69 return;
70 }
71 if (!image || !image->image()) {
72 Dart_ThrowException(tonic::ToDart("Image has been disposed"));
73 return;
74 }
75 if (!image->image()->isUIThreadSafe()) {
76 Dart_ThrowException(tonic::ToDart("Image is not thread-safe"));
77 return;
78 }
79
80 // TODO(115794): Once the DlImageSampling enum is replaced, expose the
81 // sampling options as a new default parameter for users.
82 samplers_[index] = DlColorSource::MakeImage(
85 // This should be true since we already checked the image above, but
86 // we check again for sanity.
87 FML_DCHECK(samplers_[index]->isUIThreadSafe());
88
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();
93}
static std::shared_ptr< DlColorSource > MakeImage(const sk_sp< const DlImage > &image, DlTileMode horizontal_tile_mode, DlTileMode vertical_tile_mode, DlImageSampling sampling=DlImageSampling::kLinear, const DlMatrix *matrix=nullptr)
FlutterVulkanImage * image
#define FML_DCHECK(condition)
Definition logging.h:122
Dart_Handle ToDart(const T &object)
FlutterVulkanImageHandle image
Definition embedder.h:931

References FML_DCHECK, FlutterVulkanImage::image, image, and tonic::ToDart().

◆ shader()

std::shared_ptr< DlColorSource > flutter::ReusableFragmentShader::shader ( DlImageSampling  sampling)
overridevirtual

Implements flutter::Shader.

Definition at line 108 of file fragment_shader.cc.

109 {
110 FML_CHECK(program_);
111
112 // The lifetime of this object is longer than a frame, and the uniforms can be
113 // continually changed on the UI thread. So we take a copy of the uniforms
114 // before handing it to the DisplayList for consumption on the render thread.
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());
118
119 auto source = program_->MakeDlColorSource(std::move(uniform_data), samplers_);
120 // The samplers should have been checked as they were added, this
121 // is a double-sanity-check.
122 FML_DCHECK(source->isUIThreadSafe());
123 return source;
124}

References FML_CHECK, and FML_DCHECK.

Referenced by ~ReusableFragmentShader().

◆ ValidateImageFilter()

bool flutter::ReusableFragmentShader::ValidateImageFilter ( )

Definition at line 128 of file fragment_shader.cc.

128 {
129 if (samplers_.size() < 1) {
130 return false;
131 }
132 // The first sampler does not need to be set.
133 for (auto i = 1u; i < samplers_.size(); i++) {
134 if (samplers_[i] == nullptr) {
135 return false;
136 }
137 // The samplers should have been checked as they were added, this
138 // is a double-sanity-check.
139 FML_DCHECK(samplers_[i]->isUIThreadSafe());
140 }
141 return true;
142}

References FML_DCHECK, and i.

◆ ValidateSamplers()

bool flutter::ReusableFragmentShader::ValidateSamplers ( )

Definition at line 50 of file fragment_shader.cc.

50 {
51 for (auto i = 0u; i < samplers_.size(); i++) {
52 if (samplers_[i] == nullptr) {
53 return false;
54 }
55 // The samplers should have been checked as they were added, this
56 // is a double-sanity-check.
57 FML_DCHECK(samplers_[i]->isUIThreadSafe());
58 }
59 return true;
60}

References FML_DCHECK, and i.


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