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_SINGLE_FRAME_CODEC_H_
6#define FLUTTER_LIB_UI_PAINTING_SINGLE_FRAME_CODEC_H_
7
8#include "flutter/fml/macros.h"
9#include "flutter/lib/ui/painting/codec.h"
10#include "flutter/lib/ui/painting/frame_info.h"
11#include "flutter/lib/ui/painting/image_decoder.h"
12#include "flutter/lib/ui/painting/image_descriptor.h"
13
14namespace flutter {
15
16class SingleFrameCodec : public Codec {
17 public:
18 SingleFrameCodec(fml::RefPtr<ImageDescriptor> descriptor,
19 uint32_t target_width,
20 uint32_t target_height);
21
22 ~SingleFrameCodec() override;
23
24 // |Codec|
25 int frameCount() const override;
26
27 // |Codec|
28 int repetitionCount() const override;
29
30 // |Codec|
31 Dart_Handle getNextFrame(Dart_Handle args) override;
32
33 // |DartWrappable|
34 size_t GetAllocationSize() const override;
35
36 private:
37 enum class Status { kNew, kInProgress, kComplete };
38 Status status_;
39 fml::RefPtr<ImageDescriptor> descriptor_;
40 uint32_t target_width_;
41 uint32_t target_height_;
42 fml::RefPtr<FrameInfo> cached_frame_;
43 std::vector<DartPersistentValue> pending_callbacks_;
44
45 FML_FRIEND_MAKE_REF_COUNTED(SingleFrameCodec);
46 FML_FRIEND_REF_COUNTED_THREAD_SAFE(SingleFrameCodec);
47};
48
49} // namespace flutter
50
51#endif // FLUTTER_LIB_UI_PAINTING_SINGLE_FRAME_CODEC_H_
52