1
2/*
3 * Copyright 2008 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef Movie_DEFINED
11#define Movie_DEFINED
12
13#include "SkRefCnt.h"
14#include "SkCanvas.h"
15
16class SkStreamRewindable;
17
18class Movie : public SkRefCnt {
19public:
20    /** Try to create a movie from the stream. If the stream format is not
21        supported, return NULL.
22    */
23    static Movie* DecodeStream(SkStreamRewindable*);
24    /** Try to create a movie from the specified file path. If the file is not
25        found, or the format is not supported, return NULL. If a movie is
26        returned, the stream may be retained by the movie (via ref()) until
27        the movie is finished with it (by calling unref()).
28    */
29    static Movie* DecodeFile(const char path[]);
30    /** Try to create a movie from the specified memory.
31        If the format is not supported, return NULL. If a movie is returned,
32        the data will have been read or copied, and so the caller may free
33        it.
34    */
35    static Movie* DecodeMemory(const void* data, size_t length);
36
37    SkMSec  duration();
38    int     width();
39    int     height();
40    int     isOpaque();
41
42    /** Specify the time code (between 0...duration) to sample a bitmap
43        from the movie. Returns true if this time code generated a different
44        bitmap/frame from the previous state (i.e. true means you need to
45        redraw).
46    */
47    bool setTime(SkMSec);
48
49    // return the right bitmap for the current time code
50    const SkBitmap& bitmap();
51
52protected:
53    struct Info {
54        SkMSec  fDuration;
55        int     fWidth;
56        int     fHeight;
57        bool    fIsOpaque;
58    };
59
60    virtual bool onGetInfo(Info*) = 0;
61    virtual bool onSetTime(SkMSec) = 0;
62    virtual bool onGetBitmap(SkBitmap*) = 0;
63
64    // visible for subclasses
65    Movie();
66
67private:
68    Info        fInfo;
69    SkMSec      fCurrTime;
70    SkBitmap    fBitmap;
71    bool        fNeedBitmap;
72
73    void ensureInfo();
74
75    typedef SkRefCnt INHERITED;
76};
77
78#endif
79