blob: 00dad67885545d61ad7d6ed11e888a04c02abcf5 [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
scroggo@google.comb5571b32013-09-25 21:34:24 +000016class SkStreamRewindable;
reed@android.com8a1c16f2008-12-17 15:59:43 +000017
18class SkMovie : public SkRefCnt {
19public:
mtklein2766c002015-06-26 11:45:03 -070020
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000021
reed@android.com8a1c16f2008-12-17 15:59:43 +000022 /** Try to create a movie from the stream. If the stream format is not
23 supported, return NULL.
24 */
scroggo@google.comb5571b32013-09-25 21:34:24 +000025 static SkMovie* DecodeStream(SkStreamRewindable*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000026 /** 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 SkMovie* 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 SkMovie* DecodeMemory(const void* data, size_t length);
38
39 SkMSec duration();
40 int width();
41 int height();
42 int isOpaque();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000043
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 /** 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();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054protected:
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 SkMovie();
68
69private:
70 Info fInfo;
71 SkMSec fCurrTime;
72 SkBitmap fBitmap;
73 bool fNeedBitmap;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000074
reed@android.com8a1c16f2008-12-17 15:59:43 +000075 void ensureInfo();
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000076
77 typedef SkRefCnt INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000078};
79
80#endif