Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
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 ()
 
void Dispose ()
 
std::shared_ptr< DlColorSourceshader (DlImageSampling) override
 
- 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

Member Function Documentation

◆ Create()

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

Definition at line 36 of file fragment_shader.cc.

39 {
40 auto* fragment_program =
42 uint64_t float_count =
44 uint64_t sampler_count =
45 tonic::DartConverter<uint64_t>::FromDart(sampler_count_handle);
46
47 auto res = fml::MakeRefCounted<ReusableFragmentShader>(
48 fml::Ref(fragment_program), float_count, sampler_count);
49 res->AssociateWithDartWrapper(wrapper);
50
51 void* raw_uniform_data =
52 reinterpret_cast<void*>(res->uniform_data_->writable_data());
54 float_count);
55}
DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type, void *data, intptr_t length)
@ Dart_TypedData_kFloat32
Definition dart_api.h:2614
RefPtr< T > Ref(T *ptr)
Definition ref_ptr.h:237

◆ Dispose()

void flutter::ReusableFragmentShader::Dispose ( )

Definition at line 114 of file fragment_shader.cc.

114 {
115 uniform_data_.reset();
116 program_ = nullptr;
117 samplers_.clear();
119}
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310

◆ SetImageSampler()

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

Definition at line 69 of file fragment_shader.cc.

70 {
71 uint64_t index = tonic::DartConverter<uint64_t>::FromDart(index_handle);
72 CanvasImage* image =
74 if (index >= samplers_.size()) {
75 Dart_ThrowException(tonic::ToDart("Sampler index out of bounds"));
76 }
77 if (!image->image()->isUIThreadSafe()) {
78 Dart_ThrowException(tonic::ToDart("Image is not thread-safe"));
79 }
80
81 // TODO(115794): Once the DlImageSampling enum is replaced, expose the
82 // sampling options as a new default parameter for users.
83 samplers_[index] = std::make_shared<DlImageColorSource>(
86 // This should be true since we already checked the image above, but
87 // we check again for sanity.
88 FML_DCHECK(samplers_[index]->isUIThreadSafe());
89
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();
94}
void * writable_data()
Definition SkData.h:52
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
sk_sp< SkImage > image
Definition examples.cpp:29
#define FML_DCHECK(condition)
Definition logging.h:103
Dart_Handle ToDart(const T &object)

◆ shader()

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

Implements flutter::Shader.

Definition at line 96 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 auto source = program_->MakeDlColorSource(std::move(uniform_data), samplers_);
108 // The samplers should have been checked as they were added, this
109 // is a double-sanity-check.
110 FML_DCHECK(source->isUIThreadSafe());
111 return source;
112}
const uint8_t * bytes() const
Definition SkData.h:43
size_t size() const
Definition SkData.h:30
SkBitmap source
Definition examples.cpp:28
#define FML_CHECK(condition)
Definition logging.h:85

◆ ValidateSamplers()

bool flutter::ReusableFragmentShader::ValidateSamplers ( )

Definition at line 57 of file fragment_shader.cc.

57 {
58 for (auto i = 0u; i < samplers_.size(); i += 1) {
59 if (samplers_[i] == nullptr) {
60 return false;
61 }
62 // The samplers should have been checked as they were added, this
63 // is a double-sanity-check.
64 FML_DCHECK(samplers_[i]->isUIThreadSafe());
65 }
66 return true;
67}

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