epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2008 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkMovie_DEFINED |
| 11 | #define SkMovie_DEFINED |
| 12 | |
| 13 | #include "SkRefCnt.h" |
| 14 | #include "SkCanvas.h" |
| 15 | |
scroggo@google.com | b5571b3 | 2013-09-25 21:34:24 +0000 | [diff] [blame] | 16 | class SkStreamRewindable; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 17 | |
| 18 | class SkMovie : public SkRefCnt { |
| 19 | public: |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 20 | |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 21 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | /** Try to create a movie from the stream. If the stream format is not |
| 23 | supported, return NULL. |
| 24 | */ |
scroggo@google.com | b5571b3 | 2013-09-25 21:34:24 +0000 | [diff] [blame] | 25 | static SkMovie* DecodeStream(SkStreamRewindable*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 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.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 43 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 53 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | protected: |
| 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 | |
| 69 | private: |
| 70 | Info fInfo; |
| 71 | SkMSec fCurrTime; |
| 72 | SkBitmap fBitmap; |
| 73 | bool fNeedBitmap; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 74 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 75 | void ensureInfo(); |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 76 | |
| 77 | typedef SkRefCnt INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | #endif |