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