1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SkMovie_DEFINED 18 #define SkMovie_DEFINED 19 20 #include "SkRefCnt.h" 21 #include "SkCanvas.h" 22 23 class SkStream; 24 25 class SkMovie : public SkRefCnt { 26 public: 27 /** Try to create a movie from the stream. If the stream format is not 28 supported, return NULL. 29 */ 30 static SkMovie* DecodeStream(SkStream*); 31 /** Try to create a movie from the specified file path. If the file is not 32 found, or the format is not supported, return NULL. If a movie is 33 returned, the stream may be retained by the movie (via ref()) until 34 the movie is finished with it (by calling unref()). 35 */ 36 static SkMovie* DecodeFile(const char path[]); 37 /** Try to create a movie from the specified memory. 38 If the format is not supported, return NULL. If a movie is returned, 39 the data will have been read or copied, and so the caller may free 40 it. 41 */ 42 static SkMovie* DecodeMemory(const void* data, size_t length); 43 44 SkMSec duration(); 45 int width(); 46 int height(); 47 int isOpaque(); 48 49 /** Specify the time code (between 0...duration) to sample a bitmap 50 from the movie. Returns true if this time code generated a different 51 bitmap/frame from the previous state (i.e. true means you need to 52 redraw). 53 */ 54 bool setTime(SkMSec); 55 56 // return the right bitmap for the current time code 57 const SkBitmap& bitmap(); 58 59 protected: 60 struct Info { 61 SkMSec fDuration; 62 int fWidth; 63 int fHeight; 64 bool fIsOpaque; 65 }; 66 67 virtual bool onGetInfo(Info*) = 0; 68 virtual bool onSetTime(SkMSec) = 0; 69 virtual bool onGetBitmap(SkBitmap*) = 0; 70 71 // visible for subclasses 72 SkMovie(); 73 74 private: 75 Info fInfo; 76 SkMSec fCurrTime; 77 SkBitmap fBitmap; 78 bool fNeedBitmap; 79 80 void ensureInfo(); 81 }; 82 83 #endif 84