• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SkMovie_DEFINED
11 #define SkMovie_DEFINED
12 
13 #include "SkRefCnt.h"
14 #include "SkCanvas.h"
15 
16 class SkStream;
17 
18 class SkMovie : public SkRefCnt {
19 public:
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 
52 protected:
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 
67 private:
68     Info        fInfo;
69     SkMSec      fCurrTime;
70     SkBitmap    fBitmap;
71     bool        fNeedBitmap;
72 
73     void ensureInfo();
74 };
75 
76 #endif
77