Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
flutter::SingleFrameCodec Class Reference

#include <single_frame_codec.h>

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

Public Member Functions

 SingleFrameCodec (const fml::RefPtr< ImageDescriptor > &descriptor, uint32_t target_width, uint32_t target_height)
 
 ~SingleFrameCodec () override
 
int frameCount () const override
 
int repetitionCount () const override
 
Dart_Handle getNextFrame (Dart_Handle args) override
 
- Public Member Functions inherited from flutter::Codec
virtual int frameCount () const =0
 
virtual int repetitionCount () const =0
 
virtual Dart_Handle getNextFrame (Dart_Handle callback_handle)=0
 
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< Codec >
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
 
virtual void RetainDartWrappableReference () const =0
 
virtual void ReleaseDartWrappableReference () 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< Codec >
 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 
)

Definition at line 12 of file single_frame_codec.cc.

16 : descriptor_(descriptor),
17 target_width_(target_width),
18 target_height_(target_height) {}

◆ ~SingleFrameCodec()

flutter::SingleFrameCodec::~SingleFrameCodec ( )
overridedefault

Member Function Documentation

◆ frameCount()

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

Implements flutter::Codec.

Definition at line 22 of file single_frame_codec.cc.

22 {
23 return 1;
24}

◆ getNextFrame()

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

Implements flutter::Codec.

Definition at line 30 of file single_frame_codec.cc.

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

◆ repetitionCount()

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

Implements flutter::Codec.

Definition at line 26 of file single_frame_codec.cc.

26 {
27 return 0;
28}

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