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