xref: /aosp_15_r20/frameworks/base/libs/hwui/jni/Movie.h (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
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 "SkBitmap.h"
14 #include "SkCanvas.h"
15 #include "SkRefCnt.h"
16 #include "SkTypes.h"
17 
18 class SkStreamRewindable;
19 
20 class Movie : public SkRefCnt {
21 public:
22     using MSec = uint32_t; // millisecond duration
23 
24     /** Try to create a movie from the stream. If the stream format is not
25         supported, return NULL.
26     */
27     static Movie* DecodeStream(SkStreamRewindable*);
28     /** Try to create a movie from the specified file path. If the file is not
29         found, or the format is not supported, return NULL. If a movie is
30         returned, the stream may be retained by the movie (via ref()) until
31         the movie is finished with it (by calling unref()).
32     */
33     static Movie* DecodeFile(const char path[]);
34     /** Try to create a movie from the specified memory.
35         If the format is not supported, return NULL. If a movie is returned,
36         the data will have been read or copied, and so the caller may free
37         it.
38     */
39     static Movie* DecodeMemory(const void* data, size_t length);
40 
41     MSec    duration();
42     int     width();
43     int     height();
44     int     isOpaque();
45 
46     /** Specify the time code (between 0...duration) to sample a bitmap
47         from the movie. Returns true if this time code generated a different
48         bitmap/frame from the previous state (i.e. true means you need to
49         redraw).
50     */
51     bool setTime(MSec);
52 
53     // return the right bitmap for the current time code
54     const SkBitmap& bitmap();
55 
56 protected:
57     struct Info {
58         MSec    fDuration;
59         int     fWidth;
60         int     fHeight;
61         bool    fIsOpaque;
62     };
63 
64     virtual bool onGetInfo(Info*) = 0;
65     virtual bool onSetTime(MSec) = 0;
66     virtual bool onGetBitmap(SkBitmap*) = 0;
67 
68     // visible for subclasses
69     Movie();
70 
71 private:
72     Info        fInfo;
73     MSec        fCurrTime;
74     SkBitmap    fBitmap;
75     bool        fNeedBitmap;
76 
77     void ensureInfo();
78 
79     typedef SkRefCnt INHERITED;
80 };
81 
82 #endif
83