Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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, int32_t target_format, 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, SnapshotPixelFormat target_format, 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 18 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:28
#define FML_DCHECK(condition)
Definition logging.h:122

References display_list(), and FML_DCHECK.

Referenced by flutter::PictureRecorder::endRecording().

◆ display_list()

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

◆ dispose()

void flutter::Picture::dispose ( )

Definition at line 129 of file picture.cc.

129 {
130 display_list_.reset();
132}

References tonic::DartWrappable::ClearDartWrapper().

◆ 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 159 of file picture.cc.

163 {
164 // Either display_list or layer_tree should be provided.
165 FML_DCHECK((display_list == nullptr) != (layer_tree == nullptr));
166
167 if (Dart_IsNull(raw_image_callback) || !Dart_IsClosure(raw_image_callback)) {
168 return tonic::ToDart("Image callback was invalid");
169 }
170
171 if (width == 0 || height == 0) {
172 return tonic::ToDart("Image dimensions for scene were invalid.");
173 }
174
175 auto* dart_state = UIDartState::Current();
176 auto image_callback = std::make_unique<tonic::DartPersistentValue>(
177 dart_state, raw_image_callback);
178 auto unref_queue = dart_state->GetSkiaUnrefQueue();
179 auto ui_task_runner = dart_state->GetTaskRunners().GetUITaskRunner();
180 auto raster_task_runner = dart_state->GetTaskRunners().GetRasterTaskRunner();
181 auto snapshot_delegate = dart_state->GetSnapshotDelegate();
182
183 // We can't create an image on this task runner because we don't have a
184 // graphics context. Even if we did, it would be slow anyway. Also, this
185 // thread owns the sole reference to the layer tree. So we do it in the
186 // raster thread.
187
188 auto ui_task =
189 // The static leak checker gets confused by the use of fml::MakeCopyable.
190 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
191 fml::MakeCopyable([image_callback = std::move(image_callback),
192 unref_queue](sk_sp<DlImage> image) mutable {
193 auto dart_state = image_callback->dart_state().lock();
194 if (!dart_state) {
195 // The root isolate could have died in the meantime.
196 return;
197 }
198 tonic::DartState::Scope scope(dart_state);
199
200 if (!image) {
201 tonic::DartInvoke(image_callback->Get(), {Dart_Null()});
202 return;
203 }
204
205 if (!image->isUIThreadSafe()) {
206 // All images with impeller textures should already be safe.
207 FML_DCHECK(image->impeller_texture() == nullptr);
208 image =
209 DlImageGPU::Make({image->skia_image(), std::move(unref_queue)});
210 }
211
212 auto dart_image = CanvasImage::Create();
213 dart_image->set_image(image);
214 auto* raw_dart_image = tonic::ToDart(dart_image);
215
216 // All done!
217 tonic::DartInvoke(image_callback->Get(), {raw_dart_image});
218
219 // image_callback is associated with the Dart isolate and must be
220 // deleted on the UI thread.
221 image_callback.reset();
222 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
223 });
224
225 // Kick things off on the raster rask runner.
227 raster_task_runner,
228 fml::MakeCopyable([ui_task_runner, snapshot_delegate, display_list, width,
229 height, ui_task,
230 layer_tree = std::move(layer_tree)]() mutable {
231 auto picture_bounds = DlISize(width, height);
232 sk_sp<DisplayList> snapshot_display_list = display_list;
233 if (layer_tree) {
234 FML_DCHECK(picture_bounds == layer_tree->frame_size());
235 snapshot_display_list =
236 layer_tree->Flatten(DlRect::MakeWH(width, height),
237 snapshot_delegate->GetTextureRegistry(),
238 snapshot_delegate->GetGrContext());
239 }
240 snapshot_delegate->MakeRasterSnapshot(
241 snapshot_display_list, picture_bounds,
242 [ui_task_runner, ui_task](const sk_sp<DlImage>& image) {
244 ui_task_runner, [ui_task, image]() { ui_task(image); });
245 },
247 }));
248
249 return Dart_Null();
250 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
251}
static fml::RefPtr< CanvasImage > Create()
Definition image.h:36
static sk_sp< DlImageGPU > Make(SkiaGPUObject< SkImage > image)
static UIDartState * Current()
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
FlutterVulkanImage * image
impeller::ISize32 DlISize
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 TRect MakeWH(Type width, Type height)
Definition rect.h:140

References flutter::CanvasImage::Create(), flutter::UIDartState::Current(), tonic::DartInvoke(), display_list(), FML_DCHECK, height, image, flutter::kDontCare, flutter::DlImageGPU::Make(), fml::MakeCopyable(), impeller::TRect< Scalar >::MakeWH(), fml::TaskRunner::RunNowOrPostTask(), tonic::ToDart(), and width.

Referenced by RasterizeLayerTreeToImage(), and RasterizeToImage().

◆ GetAllocationSize()

size_t flutter::Picture::GetAllocationSize ( ) const

Definition at line 134 of file picture.cc.

134 {
135 if (display_list_) {
136 return display_list_->bytes() + sizeof(Picture);
137 } else {
138 return sizeof(Picture);
139 }
140}

◆ RasterizeLayerTreeToImage()

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

Definition at line 150 of file picture.cc.

152 {
153 FML_DCHECK(layer_tree != nullptr);
154 auto frame_size = layer_tree->frame_size();
155 return DoRasterizeToImage(nullptr, std::move(layer_tree), frame_size.width,
156 frame_size.height, raw_image_callback);
157}
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:159

References DoRasterizeToImage(), and FML_DCHECK.

Referenced by flutter::Scene::toImage().

◆ 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 142 of file picture.cc.

145 {
147 raw_image_callback);
148}

References display_list(), DoRasterizeToImage(), height, and width.

Referenced by toImage().

◆ RasterizeToImageSync()

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

Definition at line 107 of file picture.cc.

111 {
112 auto* dart_state = UIDartState::Current();
113 if (!dart_state) {
114 return;
115 }
116 auto unref_queue = dart_state->GetSkiaUnrefQueue();
117 auto snapshot_delegate = dart_state->GetSnapshotDelegate();
118 auto raster_task_runner = dart_state->GetTaskRunners().GetRasterTaskRunner();
119
120 auto image = CanvasImage::Create();
121 auto dl_image = CreateDeferredImage(
122 dart_state->IsImpellerEnabled(), std::move(display_list), width, height,
123 target_format, std::move(snapshot_delegate),
124 std::move(raster_task_runner), unref_queue);
125 image->set_image(dl_image);
126 image->AssociateWithDartWrapper(raw_image_handle);
127}
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, const fml::RefPtr< SkiaUnrefQueue > &unref_queue)
Definition scene.cc:74

References flutter::CanvasImage::Create(), flutter::CreateDeferredImage(), flutter::UIDartState::Current(), display_list(), height, image, and width.

Referenced by toImageSync().

◆ 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:142

References height, RasterizeToImage(), tonic::ToDart(), and width.

◆ toImageSync()

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

Definition at line 51 of file picture.cc.

54 {
55 FML_DCHECK(display_list_);
56 SnapshotPixelFormat snapshot_pixel_format;
57 // This must be kept in sync with painting.dart.
58 switch (target_format) {
59 case 0:
60 snapshot_pixel_format = SnapshotPixelFormat::kDontCare;
61 break;
62 case 1:
63 snapshot_pixel_format = SnapshotPixelFormat::kRGBA32Float;
64 break;
65 case 2:
66 snapshot_pixel_format = SnapshotPixelFormat::kR32Float;
67 break;
68 default:
69 FML_DCHECK(false) << "unknown target format: " << target_format;
70 snapshot_pixel_format = SnapshotPixelFormat::kDontCare;
71 break;
72 }
73 RasterizeToImageSync(display_list_, width, height, snapshot_pixel_format,
74 raw_image_handle);
75}
static void RasterizeToImageSync(sk_sp< DisplayList > display_list, uint32_t width, uint32_t height, SnapshotPixelFormat target_format, Dart_Handle raw_image_handle)
Definition picture.cc:107

References FML_DCHECK, height, flutter::kDontCare, flutter::kR32Float, flutter::kRGBA32Float, RasterizeToImageSync(), and width.


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