Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter::SingleFrameCodec Class Reference

#include <single_frame_codec.h>

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

Public Member Functions

 SingleFrameCodec (const fml::RefPtr< ImageDescriptor > &descriptor, uint32_t target_width, uint32_t target_height, ImageDecoder::TargetPixelFormat destination_format)
 
 ~SingleFrameCodec () override
 
int frameCount () const override
 
int repetitionCount () const override
 
Dart_Handle getNextFrame (Dart_Handle args) override
 
- Public Member Functions inherited from flutter::Codec
void dispose ()
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< Codec >
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
 

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 16 of file single_frame_codec.h.

Constructor & Destructor Documentation

◆ SingleFrameCodec()

flutter::SingleFrameCodec::SingleFrameCodec ( const fml::RefPtr< ImageDescriptor > &  descriptor,
uint32_t  target_width,
uint32_t  target_height,
ImageDecoder::TargetPixelFormat  destination_format 
)

Definition at line 12 of file single_frame_codec.cc.

17 : descriptor_(descriptor),
18 target_width_(target_width),
19 target_height_(target_height),
20 target_format_(target_format) {}

◆ ~SingleFrameCodec()

flutter::SingleFrameCodec::~SingleFrameCodec ( )
overridedefault

Member Function Documentation

◆ frameCount()

int flutter::SingleFrameCodec::frameCount ( ) const
overridevirtual

Implements flutter::Codec.

Definition at line 24 of file single_frame_codec.cc.

24 {
25 return 1;
26}

◆ getNextFrame()

Dart_Handle flutter::SingleFrameCodec::getNextFrame ( Dart_Handle  args)
overridevirtual

Implements flutter::Codec.

Definition at line 32 of file single_frame_codec.cc.

32 {
33 if (!Dart_IsClosure(callback_handle)) {
34 return tonic::ToDart("Callback must be a function");
35 }
36
37 if (status_ == Status::kComplete) {
38 if (!cached_image_->image()) {
39 return tonic::ToDart("Decoded image has been disposed");
40 }
41 tonic::DartInvoke(callback_handle, {tonic::ToDart(cached_image_),
43 return Dart_Null();
44 }
45
46 // This has to be valid because this method is called from Dart.
47 auto dart_state = UIDartState::Current();
48
49 pending_callbacks_.emplace_back(dart_state, callback_handle);
50
51 if (status_ == Status::kInProgress) {
52 // Another call to getNextFrame is in progress and will invoke the
53 // pending callbacks when decoding completes.
54 return Dart_Null();
55 }
56
57 auto decoder = dart_state->GetImageDecoder();
58
59 if (!decoder) {
60 return tonic::ToDart(
61 "Failed to access the internal image decoder "
62 "registry on this isolate. Please file a bug on "
63 "https://github.com/flutter/flutter/issues.");
64 }
65
66 // The SingleFrameCodec must be deleted on the UI thread. Allocate a RefPtr
67 // on the heap to ensure that the SingleFrameCodec remains alive until the
68 // decoder callback is invoked on the UI thread. The callback can then
69 // drop the reference.
70 fml::RefPtr<SingleFrameCodec>* raw_codec_ref =
72
73 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
74 decoder->Decode(
75 descriptor_,
76 {.target_width = target_width_,
77 .target_height = target_height_,
78 .target_format = target_format_},
79 [raw_codec_ref](const auto& image, const auto& decode_error) {
80 std::unique_ptr<fml::RefPtr<SingleFrameCodec>> codec_ref(raw_codec_ref);
81 fml::RefPtr<SingleFrameCodec> codec(std::move(*codec_ref));
82
83 auto state = codec->pending_callbacks_.front().dart_state().lock();
84
85 if (!state) {
86 // This is probably because the isolate has been terminated before the
87 // image could be decoded.
88
89 return;
90 }
91
92 tonic::DartState::Scope scope(state.get());
93
94 if (image) {
95 auto canvas_image = fml::MakeRefCounted<CanvasImage>();
96 canvas_image->set_image(std::move(image));
97
98 codec->cached_image_ = std::move(canvas_image);
99 }
100
101 // The cached frame is now available and should be returned to any
102 // future callers.
103 codec->status_ = Status::kComplete;
104
105 // Invoke any callbacks that were provided before the frame was decoded.
107 codec->pending_callbacks_) {
109 {tonic::ToDart(codec->cached_image_),
110 tonic::ToDart(0), tonic::ToDart(decode_error)});
111 }
112 codec->pending_callbacks_.clear();
113 });
114
115 // The encoded data is no longer needed now that it has been handed off
116 // to the decoder.
117 descriptor_ = nullptr;
118
119 status_ = Status::kInProgress;
120
121 return Dart_Null();
122}
static UIDartState * Current()
FlutterVulkanImage * image
FlutterDesktopBinaryReply callback
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)

References callback, flutter::UIDartState::Current(), tonic::DartInvoke(), image, and tonic::ToDart().

◆ repetitionCount()

int flutter::SingleFrameCodec::repetitionCount ( ) const
overridevirtual

Implements flutter::Codec.

Definition at line 28 of file single_frame_codec.cc.

28 {
29 return 0;
30}

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