Flutter Engine
 
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, 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: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 107 of file picture.cc.

107 {
108 display_list_.reset();
110}

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

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

112 {
113 if (display_list_) {
114 return display_list_->bytes() + sizeof(Picture);
115 } else {
116 return sizeof(Picture);
117 }
118}

◆ RasterizeLayerTreeToImage()

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

Definition at line 128 of file picture.cc.

130 {
131 FML_DCHECK(layer_tree != nullptr);
132 auto frame_size = layer_tree->frame_size();
133 return DoRasterizeToImage(nullptr, std::move(layer_tree), frame_size.width,
134 frame_size.height, raw_image_callback);
135}
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:137

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

123 {
125 raw_image_callback);
126}

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,
Dart_Handle  raw_image_handle 
)
static

Definition at line 87 of file picture.cc.

90 {
91 auto* dart_state = UIDartState::Current();
92 if (!dart_state) {
93 return;
94 }
95 auto unref_queue = dart_state->GetSkiaUnrefQueue();
96 auto snapshot_delegate = dart_state->GetSnapshotDelegate();
97 auto raster_task_runner = dart_state->GetTaskRunners().GetRasterTaskRunner();
98
100 auto dl_image = CreateDeferredImage(
101 dart_state->IsImpellerEnabled(), std::move(display_list), width, height,
102 std::move(snapshot_delegate), std::move(raster_task_runner), unref_queue);
103 image->set_image(dl_image);
104 image->AssociateWithDartWrapper(raw_image_handle);
105}
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:120

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

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

References FML_DCHECK, height, RasterizeToImageSync(), and width.


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