• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MUTLI_FRAME_CODEC_H_
6 #define FLUTTER_LIB_UI_PAINTING_MUTLI_FRAME_CODEC_H_
7 
8 #include "flutter/fml/macros.h"
9 #include "flutter/lib/ui/painting/codec.h"
10 
11 namespace flutter {
12 
13 class MultiFrameCodec : public Codec {
14  public:
15   MultiFrameCodec(std::unique_ptr<SkCodec> codec);
16 
17   ~MultiFrameCodec() override;
18 
19   // |Codec|
20   int frameCount() const override;
21 
22   // |Codec|
23   int repetitionCount() const override;
24 
25   // |Codec|
26   Dart_Handle getNextFrame(Dart_Handle args) override;
27 
28  private:
29   const std::unique_ptr<SkCodec> codec_;
30   const int frameCount_;
31   const int repetitionCount_;
32   int nextFrameIndex_;
33 
34   // The last decoded frame that's required to decode any subsequent frames.
35   std::unique_ptr<SkBitmap> lastRequiredFrame_;
36   // The index of the last decoded required frame.
37   int lastRequiredFrameIndex_ = -1;
38 
39   sk_sp<SkImage> GetNextFrameImage(fml::WeakPtr<GrContext> resourceContext);
40 
41   void GetNextFrameAndInvokeCallback(
42       std::unique_ptr<DartPersistentValue> callback,
43       fml::RefPtr<fml::TaskRunner> ui_task_runner,
44       fml::WeakPtr<GrContext> resourceContext,
45       fml::RefPtr<flutter::SkiaUnrefQueue> unref_queue,
46       size_t trace_id);
47 
48   FML_FRIEND_MAKE_REF_COUNTED(MultiFrameCodec);
49   FML_FRIEND_REF_COUNTED_THREAD_SAFE(MultiFrameCodec);
50 };
51 
52 }  // namespace flutter
53 
54 #endif  // FLUTTER_LIB_UI_PAINTING_MUTLI_FRAME_CODEC_H_
55