Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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, int filterQualityIndex)
 
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 97 of file fragment_shader.cc.

97 {
98 FML_CHECK(program_);
99
100 // The lifetime of this object is longer than a frame, and the uniforms can be
101 // continually changed on the UI thread. So we take a copy of the uniforms
102 // before handing it to the DisplayList for consumption on the render thread.
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());
106
107 return program_->MakeDlImageFilter(std::move(uniform_data), samplers_);
108}
#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 30 of file fragment_shader.cc.

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

References fml::Ref().

◆ Dispose()

void flutter::ReusableFragmentShader::Dispose ( )

Definition at line 146 of file fragment_shader.cc.

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

◆ SetImageSampler()

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

Definition at line 63 of file fragment_shader.cc.

65 {
66 uint64_t index = tonic::DartConverter<uint64_t>::FromDart(index_handle);
67 CanvasImage* image =
69 if (index >= samplers_.size()) {
70 Dart_ThrowException(tonic::ToDart("Sampler index out of bounds"));
71 return;
72 }
73 if (!image || !image->image()) {
74 Dart_ThrowException(tonic::ToDart("Image has been disposed"));
75 return;
76 }
77 if (!image->image()->isUIThreadSafe()) {
78 Dart_ThrowException(tonic::ToDart("Image is not thread-safe"));
79 return;
80 }
81
82 // TODO(115794): Once the DlImageSampling enum is replaced, expose the
83 // sampling options as a new default parameter for users.
84 samplers_[index] = DlColorSource::MakeImage(
86 ImageFilter::SamplingFromIndex(filterQualityIndex), nullptr);
87 // This should be true since we already checked the image above, but
88 // we check again for sanity.
89 FML_DCHECK(samplers_[index]->isUIThreadSafe());
90
91 auto* uniform_floats =
92 reinterpret_cast<float*>(uniform_data_->writable_data());
93 uniform_floats[float_count_ + 2 * index] = image->width();
94 uniform_floats[float_count_ + 2 * index + 1] = image->height();
95}
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)
static DlImageSampling SamplingFromIndex(int filterQualityIndex)
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 110 of file fragment_shader.cc.

111 {
112 FML_CHECK(program_);
113
114 // The lifetime of this object is longer than a frame, and the uniforms can be
115 // continually changed on the UI thread. So we take a copy of the uniforms
116 // before handing it to the DisplayList for consumption on the render thread.
117 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
118 uniform_data->resize(uniform_data_->size());
119 memcpy(uniform_data->data(), uniform_data_->bytes(), uniform_data->size());
120
121 auto source = program_->MakeDlColorSource(std::move(uniform_data), samplers_);
122 // The samplers should have been checked as they were added, this
123 // is a double-sanity-check.
124 FML_DCHECK(source->isUIThreadSafe());
125 return source;
126}

References FML_CHECK, and FML_DCHECK.

Referenced by ~ReusableFragmentShader().

◆ ValidateImageFilter()

bool flutter::ReusableFragmentShader::ValidateImageFilter ( )

Definition at line 130 of file fragment_shader.cc.

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

References FML_DCHECK, and i.

◆ ValidateSamplers()

bool flutter::ReusableFragmentShader::ValidateSamplers ( )

Definition at line 51 of file fragment_shader.cc.

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

References FML_DCHECK, and i.


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