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
13class SkImage;
14
15class SkAnimCodecPlayer {
16public:
17 SkAnimCodecPlayer(std::unique_ptr<SkCodec> codec);
18 ~SkAnimCodecPlayer();
19
20 /**
21 * Returns the current frame of the animation. This defaults to the first frame for
22 * animated codecs (i.e. msec = 0). Calling this multiple times (without calling seek())
23 * will always return the same image object (or null if there was an error).
24 */
25 sk_sp<SkImage> getFrame();
26
27 /**
28 * Return the size of the image(s) that will be returned by getFrame().
29 */
30 SkISize dimensions();
31
32 /**
33 * Returns the total duration of the animation in milliseconds. Returns 0 for a single-frame
34 * image.
35 */
36 uint32_t duration() { return fTotalDuration; }
37
38 /**
39 * Finds the closest frame associated with the time code (in milliseconds) and sets that
40 * to be the current frame (call getFrame() to retrieve that image).
41 * Returns true iff this call to seek() changed the "current frame" for the animation.
42 * Thus if seek() returns false, then getFrame() will return the same image as it did
43 * before this call to seek().
44 */
45 bool seek(uint32_t msec);
46
47
48private:
49 std::unique_ptr<SkCodec> fCodec;
50 SkImageInfo fImageInfo;
51 std::vector<SkCodec::FrameInfo> fFrameInfos;
52 std::vector<sk_sp<SkImage> > fImages;
53 int fCurrIndex = 0;
54 uint32_t fTotalDuration;
55
56 sk_sp<SkImage> getFrameAt(int index);
57};
58
59#endif
60
61