blob: f52a78638e71704519d614fb72bc0f5cc59f430e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2008 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkMovie_DEFINED
11#define SkMovie_DEFINED
12
13#include "SkRefCnt.h"
14#include "SkCanvas.h"
15
16class SkStream;
17
18class SkMovie : 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 SkMovie* DecodeStream(SkStream*);
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 SkMovie* 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 SkMovie* 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 SkMovie();
66
67private:
68 Info fInfo;
69 SkMSec fCurrTime;
70 SkBitmap fBitmap;
71 bool fNeedBitmap;
72
73 void ensureInfo();
74};
75
76#endif