Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
flutter::Picture Class Reference

#include <picture.h>

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

Public Member Functions

 ~Picture () override
 
sk_sp< DisplayListdisplay_list () const
 
Dart_Handle toImage (uint32_t width, uint32_t height, Dart_Handle raw_image_callback)
 
void toImageSync (uint32_t width, uint32_t height, Dart_Handle raw_image_handle)
 
void dispose ()
 
size_t GetAllocationSize () const
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< Picture >
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 void CreateAndAssociateWithDartWrapper (Dart_Handle dart_handle, sk_sp< DisplayList > display_list)
 
static void RasterizeToImageSync (sk_sp< DisplayList > display_list, uint32_t width, uint32_t height, Dart_Handle raw_image_handle)
 
static Dart_Handle RasterizeToImage (const sk_sp< DisplayList > &display_list, uint32_t width, uint32_t height, Dart_Handle raw_image_callback)
 
static Dart_Handle RasterizeLayerTreeToImage (std::unique_ptr< LayerTree > layer_tree, Dart_Handle raw_image_callback)
 
static Dart_Handle DoRasterizeToImage (const sk_sp< DisplayList > &display_list, std::unique_ptr< LayerTree > layer_tree, uint32_t width, uint32_t height, Dart_Handle raw_image_callback)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields { kPeerIndex , kNumberOfNativeFields }
 
- 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 17 of file picture.h.

Constructor & Destructor Documentation

◆ ~Picture()

flutter::Picture::~Picture ( )
overridedefault

Member Function Documentation

◆ CreateAndAssociateWithDartWrapper()

void flutter::Picture::CreateAndAssociateWithDartWrapper ( Dart_Handle  dart_handle,
sk_sp< DisplayList display_list 
)
static

Definition at line 29 of file picture.cc.

31 {
32 FML_DCHECK(display_list->isUIThreadSafe());
33 auto canvas_picture = fml::MakeRefCounted<Picture>(std::move(display_list));
34 canvas_picture->AssociateWithDartWrapper(dart_handle);
35}
sk_sp< DisplayList > display_list() const
Definition picture.h:27
#define FML_DCHECK(condition)
Definition logging.h:103

◆ display_list()

sk_sp< DisplayList > flutter::Picture::display_list ( ) const
inline

Definition at line 27 of file picture.h.

27{ return display_list_; }

◆ dispose()

void flutter::Picture::dispose ( )

Definition at line 103 of file picture.cc.

103 {
104 display_list_.reset();
106}

◆ DoRasterizeToImage()

Dart_Handle flutter::Picture::DoRasterizeToImage ( const sk_sp< DisplayList > &  display_list,
std::unique_ptr< LayerTree layer_tree,
uint32_t  width,
uint32_t  height,
Dart_Handle  raw_image_callback 
)
static

Definition at line 133 of file picture.cc.

137 {
138 // Either display_list or layer_tree should be provided.
139 FML_DCHECK((display_list == nullptr) != (layer_tree == nullptr));
140
141 if (Dart_IsNull(raw_image_callback) || !Dart_IsClosure(raw_image_callback)) {
142 return tonic::ToDart("Image callback was invalid");
143 }
144
145 if (width == 0 || height == 0) {
146 return tonic::ToDart("Image dimensions for scene were invalid.");
147 }
148
149 auto* dart_state = UIDartState::Current();
150 auto image_callback = std::make_unique<tonic::DartPersistentValue>(
151 dart_state, raw_image_callback);
152 auto unref_queue = dart_state->GetSkiaUnrefQueue();
153 auto ui_task_runner = dart_state->GetTaskRunners().GetUITaskRunner();
154 auto raster_task_runner = dart_state->GetTaskRunners().GetRasterTaskRunner();
155 auto snapshot_delegate = dart_state->GetSnapshotDelegate();
156
157 // We can't create an image on this task runner because we don't have a
158 // graphics context. Even if we did, it would be slow anyway. Also, this
159 // thread owns the sole reference to the layer tree. So we do it in the
160 // raster thread.
161
162 auto ui_task =
163 // The static leak checker gets confused by the use of fml::MakeCopyable.
164 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
165 fml::MakeCopyable([image_callback = std::move(image_callback),
166 unref_queue](sk_sp<DlImage> image) mutable {
167 auto dart_state = image_callback->dart_state().lock();
168 if (!dart_state) {
169 // The root isolate could have died in the meantime.
170 return;
171 }
172 tonic::DartState::Scope scope(dart_state);
173
174 if (!image) {
175 tonic::DartInvoke(image_callback->Get(), {Dart_Null()});
176 return;
177 }
178
179 if (!image->isUIThreadSafe()) {
180 // All images with impeller textures should already be safe.
181 FML_DCHECK(image->impeller_texture() == nullptr);
182 image =
183 DlImageGPU::Make({image->skia_image(), std::move(unref_queue)});
184 }
185
186 auto dart_image = CanvasImage::Create();
187 dart_image->set_image(image);
188 auto* raw_dart_image = tonic::ToDart(dart_image);
189
190 // All done!
191 tonic::DartInvoke(image_callback->Get(), {raw_dart_image});
192
193 // image_callback is associated with the Dart isolate and must be
194 // deleted on the UI thread.
195 image_callback.reset();
196 });
197
198 // Kick things off on the raster rask runner.
200 raster_task_runner,
201 fml::MakeCopyable([ui_task_runner, snapshot_delegate, display_list, width,
202 height, ui_task,
203 layer_tree = std::move(layer_tree)]() mutable {
204 auto picture_bounds = SkISize::Make(width, height);
206 if (layer_tree) {
207 FML_DCHECK(picture_bounds == layer_tree->frame_size());
208 auto display_list =
209 layer_tree->Flatten(SkRect::MakeWH(width, height),
210 snapshot_delegate->GetTextureRegistry(),
211 snapshot_delegate->GetGrContext());
212
213 image = snapshot_delegate->MakeRasterSnapshot(display_list,
214 picture_bounds);
215 } else {
216 image = snapshot_delegate->MakeRasterSnapshot(display_list,
217 picture_bounds);
218 }
219
221 ui_task_runner, [ui_task, image]() { ui_task(image); });
222 }));
223
224 return Dart_Null();
225}
static fml::RefPtr< CanvasImage > Create()
Definition image.h:28
static sk_sp< DlImageGPU > Make(SkiaGPUObject< SkImage > image)
static UIDartState * Current()
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
DART_EXPORT bool Dart_IsClosure(Dart_Handle object)
sk_sp< SkImage > image
Definition examples.cpp:29
internal::CopyableLambda< T > MakeCopyable(T lambda)
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
int32_t height
int32_t width
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

◆ GetAllocationSize()

size_t flutter::Picture::GetAllocationSize ( ) const

Definition at line 108 of file picture.cc.

108 {
109 if (display_list_) {
110 return display_list_->bytes() + sizeof(Picture);
111 } else {
112 return sizeof(Picture);
113 }
114}

◆ RasterizeLayerTreeToImage()

Dart_Handle flutter::Picture::RasterizeLayerTreeToImage ( std::unique_ptr< LayerTree layer_tree,
Dart_Handle  raw_image_callback 
)
static

Definition at line 124 of file picture.cc.

126 {
127 FML_DCHECK(layer_tree != nullptr);
128 auto frame_size = layer_tree->frame_size();
129 return DoRasterizeToImage(nullptr, std::move(layer_tree), frame_size.width(),
130 frame_size.height(), raw_image_callback);
131}
static Dart_Handle DoRasterizeToImage(const sk_sp< DisplayList > &display_list, std::unique_ptr< LayerTree > layer_tree, uint32_t width, uint32_t height, Dart_Handle raw_image_callback)
Definition picture.cc:133

◆ RasterizeToImage()

Dart_Handle flutter::Picture::RasterizeToImage ( const sk_sp< DisplayList > &  display_list,
uint32_t  width,
uint32_t  height,
Dart_Handle  raw_image_callback 
)
static

Definition at line 116 of file picture.cc.

119 {
121 raw_image_callback);
122}

◆ RasterizeToImageSync()

void flutter::Picture::RasterizeToImageSync ( sk_sp< DisplayList display_list,
uint32_t  width,
uint32_t  height,
Dart_Handle  raw_image_handle 
)
static

Definition at line 82 of file picture.cc.

85 {
86 auto* dart_state = UIDartState::Current();
87 if (!dart_state) {
88 return;
89 }
90 auto unref_queue = dart_state->GetSkiaUnrefQueue();
91 auto snapshot_delegate = dart_state->GetSnapshotDelegate();
92 auto raster_task_runner = dart_state->GetTaskRunners().GetRasterTaskRunner();
93
95 auto dl_image = CreateDeferredImage(
96 dart_state->IsImpellerEnabled(), std::move(display_list), width, height,
97 std::move(snapshot_delegate), std::move(raster_task_runner),
98 std::move(unref_queue));
99 image->set_image(dl_image);
100 image->AssociateWithDartWrapper(raw_image_handle);
101}
static sk_sp< DlImage > CreateDeferredImage(bool impeller, std::unique_ptr< LayerTree > layer_tree, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, fml::RefPtr< fml::TaskRunner > raster_task_runner, fml::RefPtr< SkiaUnrefQueue > unref_queue)
Definition scene.cc:87

◆ toImage()

Dart_Handle flutter::Picture::toImage ( uint32_t  width,
uint32_t  height,
Dart_Handle  raw_image_callback 
)

Definition at line 42 of file picture.cc.

44 {
45 if (!display_list_) {
46 return tonic::ToDart("Picture is null");
47 }
48 return RasterizeToImage(display_list_, width, height, raw_image_callback);
49}
static Dart_Handle RasterizeToImage(const sk_sp< DisplayList > &display_list, uint32_t width, uint32_t height, Dart_Handle raw_image_callback)
Definition picture.cc:116

◆ toImageSync()

void flutter::Picture::toImageSync ( uint32_t  width,
uint32_t  height,
Dart_Handle  raw_image_handle 
)

Definition at line 51 of file picture.cc.

53 {
54 FML_DCHECK(display_list_);
55 RasterizeToImageSync(display_list_, width, height, raw_image_handle);
56}
static void RasterizeToImageSync(sk_sp< DisplayList > display_list, uint32_t width, uint32_t height, Dart_Handle raw_image_handle)
Definition picture.cc:82

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