Flutter Engine
The Flutter Engine
multi_frame_codec.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_LIB_UI_PAINTING_MULTI_FRAME_CODEC_H_
6#define FLUTTER_LIB_UI_PAINTING_MULTI_FRAME_CODEC_H_
7
8#include "flutter/fml/macros.h"
9#include "flutter/lib/ui/painting/codec.h"
10#include "flutter/lib/ui/painting/image_generator.h"
11
12#include <utility>
13
14namespace flutter {
15
16class MultiFrameCodec : public Codec {
17 public:
18 explicit MultiFrameCodec(std::shared_ptr<ImageGenerator> generator);
19
20 ~MultiFrameCodec() override;
21
22 // |Codec|
23 int frameCount() const override;
24
25 // |Codec|
26 int repetitionCount() const override;
27
28 // |Codec|
30
31 private:
32 // Captures the state shared between the IO and UI task runners.
33 //
34 // The state is initialized on the UI task runner when the Dart object is
35 // created. Decoding occurs on the IO task runner. Since it is possible for
36 // the UI object to be collected independently of the IO task runner work,
37 // it is not safe for this state to live directly on the MultiFrameCodec.
38 // Instead, the MultiFrameCodec creates this object when it is constructed,
39 // shares it with the IO task runner's decoding work, and sets the live_
40 // member to false when it is destructed.
41 struct State {
42 explicit State(std::shared_ptr<ImageGenerator> generator);
43
44 const std::shared_ptr<ImageGenerator> generator_;
45 const int frameCount_;
46 const int repetitionCount_;
47 bool is_impeller_enabled_ = false;
48
49 // The non-const members and functions below here are only read or written
50 // to on the IO thread. They are not safe to access or write on the UI
51 // thread.
52 int nextFrameIndex_ = 0;
53 // The last decoded frame that's required to decode any subsequent frames.
54 std::optional<SkBitmap> lastRequiredFrame_;
55 // The index of the last decoded required frame.
56 int lastRequiredFrameIndex_ = -1;
57
58 // The rectangle that should be cleared if the previous frame's disposal
59 // method was kRestoreBGColor.
60 std::optional<SkIRect> restoreBGColorRect_;
61
62 std::pair<sk_sp<DlImage>, std::string> GetNextFrameImage(
63 fml::WeakPtr<GrDirectContext> resourceContext,
64 const std::shared_ptr<const fml::SyncSwitch>& gpu_disable_sync_switch,
65 const std::shared_ptr<impeller::Context>& impeller_context,
67
68 void GetNextFrameAndInvokeCallback(
69 std::unique_ptr<tonic::DartPersistentValue> callback,
70 const fml::RefPtr<fml::TaskRunner>& ui_task_runner,
71 fml::WeakPtr<GrDirectContext> resourceContext,
73 const std::shared_ptr<const fml::SyncSwitch>& gpu_disable_sync_switch,
74 size_t trace_id,
75 const std::shared_ptr<impeller::Context>& impeller_context);
76 };
77
78 // Shared across the UI and IO task runners.
79 std::shared_ptr<State> state_;
80
81 FML_FRIEND_MAKE_REF_COUNTED(MultiFrameCodec);
82 FML_FRIEND_REF_COUNTED_THREAD_SAFE(MultiFrameCodec);
83};
84
85} // namespace flutter
86
87#endif // FLUTTER_LIB_UI_PAINTING_MULTI_FRAME_CODEC_H_
int repetitionCount() const override
int frameCount() const override
MultiFrameCodec(std::shared_ptr< ImageGenerator > generator)
Dart_Handle getNextFrame(Dart_Handle args) override
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback