/src/skia/modules/skresources/src/SkAnimCodecPlayer.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2018 Google Inc. |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license that can be |
5 | | * found in the LICENSE file. |
6 | | */ |
7 | | |
8 | | #ifndef SkAnimCodecPlayer_DEFINED |
9 | | #define SkAnimCodecPlayer_DEFINED |
10 | | |
11 | | #include "include/codec/SkCodec.h" |
12 | | #include "include/core/SkImageInfo.h" |
13 | | #include "include/core/SkRefCnt.h" |
14 | | #include "include/core/SkSize.h" |
15 | | |
16 | | #include <cstdint> |
17 | | #include <memory> |
18 | | #include <vector> |
19 | | |
20 | | class SkImage; |
21 | | |
22 | | class SkAnimCodecPlayer { |
23 | | public: |
24 | | SkAnimCodecPlayer(std::unique_ptr<SkCodec> codec); |
25 | | ~SkAnimCodecPlayer(); |
26 | | |
27 | | /** |
28 | | * Returns the current frame of the animation. This defaults to the first frame for |
29 | | * animated codecs (i.e. msec = 0). Calling this multiple times (without calling seek()) |
30 | | * will always return the same image object (or null if there was an error). |
31 | | */ |
32 | | sk_sp<SkImage> getFrame(); |
33 | | |
34 | | /** |
35 | | * Return the size of the image(s) that will be returned by getFrame(). |
36 | | */ |
37 | | SkISize dimensions() const; |
38 | | |
39 | | /** |
40 | | * Returns the total duration of the animation in milliseconds. Returns 0 for a single-frame |
41 | | * image. |
42 | | */ |
43 | 0 | uint32_t duration() const { return fTotalDuration; } |
44 | | |
45 | | /** |
46 | | * Finds the closest frame associated with the time code (in milliseconds) and sets that |
47 | | * to be the current frame (call getFrame() to retrieve that image). |
48 | | * Returns true iff this call to seek() changed the "current frame" for the animation. |
49 | | * Thus if seek() returns false, then getFrame() will return the same image as it did |
50 | | * before this call to seek(). |
51 | | */ |
52 | | bool seek(uint32_t msec); |
53 | | |
54 | | |
55 | | private: |
56 | | std::unique_ptr<SkCodec> fCodec; |
57 | | SkImageInfo fImageInfo; |
58 | | std::vector<SkCodec::FrameInfo> fFrameInfos; |
59 | | std::vector<sk_sp<SkImage> > fImages; |
60 | | int fCurrIndex = 0; |
61 | | uint32_t fTotalDuration; |
62 | | |
63 | | sk_sp<SkImage> getFrameAt(int index); |
64 | | }; |
65 | | |
66 | | #endif |
67 | | |