blob: d633d935f5662026a1b34ddd929cbb1ec5d44379 [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:
Kaylee Lubick84642f82024-09-09 19:44:27 +000022 using MSec = uint32_t; // millisecond duration
23
Leon Scroggins IIIb5e74b92016-10-26 09:45:45 -040024 /** 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
Kaylee Lubick84642f82024-09-09 19:44:27 +000041 MSec duration();
Leon Scroggins IIIb5e74b92016-10-26 09:45:45 -040042 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 */
Kaylee Lubick84642f82024-09-09 19:44:27 +000051 bool setTime(MSec);
Leon Scroggins IIIb5e74b92016-10-26 09:45:45 -040052
53 // return the right bitmap for the current time code
54 const SkBitmap& bitmap();
55
56protected:
57 struct Info {
Kaylee Lubick84642f82024-09-09 19:44:27 +000058 MSec fDuration;
Leon Scroggins IIIb5e74b92016-10-26 09:45:45 -040059 int fWidth;
60 int fHeight;
61 bool fIsOpaque;
62 };
63
64 virtual bool onGetInfo(Info*) = 0;
Kaylee Lubick84642f82024-09-09 19:44:27 +000065 virtual bool onSetTime(MSec) = 0;
Leon Scroggins IIIb5e74b92016-10-26 09:45:45 -040066 virtual bool onGetBitmap(SkBitmap*) = 0;
67
68 // visible for subclasses
69 Movie();
70
71private:
72 Info fInfo;
Kaylee Lubick84642f82024-09-09 19:44:27 +000073 MSec fCurrTime;
Leon Scroggins IIIb5e74b92016-10-26 09:45:45 -040074 SkBitmap fBitmap;
75 bool fNeedBitmap;
76
77 void ensureInfo();
78
79 typedef SkRefCnt INHERITED;
80};
81
82#endif