Leon Scroggins III | b5e74b9 | 2016-10-26 09:45:45 -0400 | [diff] [blame] | 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 Movie_DEFINED |
| 11 | #define Movie_DEFINED |
| 12 | |
Leon Scroggins III | 1a55a35 | 2017-05-03 13:15:39 -0400 | [diff] [blame] | 13 | #include "SkBitmap.h" |
Leon Scroggins III | b5e74b9 | 2016-10-26 09:45:45 -0400 | [diff] [blame] | 14 | #include "SkCanvas.h" |
Leon Scroggins III | 1a55a35 | 2017-05-03 13:15:39 -0400 | [diff] [blame] | 15 | #include "SkRefCnt.h" |
Leon Scroggins III | b5e74b9 | 2016-10-26 09:45:45 -0400 | [diff] [blame] | 16 | |
| 17 | class SkStreamRewindable; |
| 18 | |
| 19 | class Movie : public SkRefCnt { |
| 20 | public: |
| 21 | /** Try to create a movie from the stream. If the stream format is not |
| 22 | supported, return NULL. |
| 23 | */ |
| 24 | static Movie* DecodeStream(SkStreamRewindable*); |
| 25 | /** Try to create a movie from the specified file path. If the file is not |
| 26 | found, or the format is not supported, return NULL. If a movie is |
| 27 | returned, the stream may be retained by the movie (via ref()) until |
| 28 | the movie is finished with it (by calling unref()). |
| 29 | */ |
| 30 | static Movie* DecodeFile(const char path[]); |
| 31 | /** Try to create a movie from the specified memory. |
| 32 | If the format is not supported, return NULL. If a movie is returned, |
| 33 | the data will have been read or copied, and so the caller may free |
| 34 | it. |
| 35 | */ |
| 36 | static Movie* DecodeMemory(const void* data, size_t length); |
| 37 | |
| 38 | SkMSec duration(); |
| 39 | int width(); |
| 40 | int height(); |
| 41 | int isOpaque(); |
| 42 | |
| 43 | /** Specify the time code (between 0...duration) to sample a bitmap |
| 44 | from the movie. Returns true if this time code generated a different |
| 45 | bitmap/frame from the previous state (i.e. true means you need to |
| 46 | redraw). |
| 47 | */ |
| 48 | bool setTime(SkMSec); |
| 49 | |
| 50 | // return the right bitmap for the current time code |
| 51 | const SkBitmap& bitmap(); |
| 52 | |
| 53 | protected: |
| 54 | struct Info { |
| 55 | SkMSec fDuration; |
| 56 | int fWidth; |
| 57 | int fHeight; |
| 58 | bool fIsOpaque; |
| 59 | }; |
| 60 | |
| 61 | virtual bool onGetInfo(Info*) = 0; |
| 62 | virtual bool onSetTime(SkMSec) = 0; |
| 63 | virtual bool onGetBitmap(SkBitmap*) = 0; |
| 64 | |
| 65 | // visible for subclasses |
| 66 | Movie(); |
| 67 | |
| 68 | private: |
| 69 | Info fInfo; |
| 70 | SkMSec fCurrTime; |
| 71 | SkBitmap fBitmap; |
| 72 | bool fNeedBitmap; |
| 73 | |
| 74 | void ensureInfo(); |
| 75 | |
| 76 | typedef SkRefCnt INHERITED; |
| 77 | }; |
| 78 | |
| 79 | #endif |