michael@0: michael@0: /* michael@0: * Copyright 2008 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkMovie_DEFINED michael@0: #define SkMovie_DEFINED michael@0: michael@0: #include "SkRefCnt.h" michael@0: #include "SkCanvas.h" michael@0: michael@0: class SkStreamRewindable; michael@0: michael@0: class SkMovie : public SkRefCnt { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkMovie) michael@0: michael@0: /** Try to create a movie from the stream. If the stream format is not michael@0: supported, return NULL. michael@0: */ michael@0: static SkMovie* DecodeStream(SkStreamRewindable*); michael@0: /** Try to create a movie from the specified file path. If the file is not michael@0: found, or the format is not supported, return NULL. If a movie is michael@0: returned, the stream may be retained by the movie (via ref()) until michael@0: the movie is finished with it (by calling unref()). michael@0: */ michael@0: static SkMovie* DecodeFile(const char path[]); michael@0: /** Try to create a movie from the specified memory. michael@0: If the format is not supported, return NULL. If a movie is returned, michael@0: the data will have been read or copied, and so the caller may free michael@0: it. michael@0: */ michael@0: static SkMovie* DecodeMemory(const void* data, size_t length); michael@0: michael@0: SkMSec duration(); michael@0: int width(); michael@0: int height(); michael@0: int isOpaque(); michael@0: michael@0: /** Specify the time code (between 0...duration) to sample a bitmap michael@0: from the movie. Returns true if this time code generated a different michael@0: bitmap/frame from the previous state (i.e. true means you need to michael@0: redraw). michael@0: */ michael@0: bool setTime(SkMSec); michael@0: michael@0: // return the right bitmap for the current time code michael@0: const SkBitmap& bitmap(); michael@0: michael@0: protected: michael@0: struct Info { michael@0: SkMSec fDuration; michael@0: int fWidth; michael@0: int fHeight; michael@0: bool fIsOpaque; michael@0: }; michael@0: michael@0: virtual bool onGetInfo(Info*) = 0; michael@0: virtual bool onSetTime(SkMSec) = 0; michael@0: virtual bool onGetBitmap(SkBitmap*) = 0; michael@0: michael@0: // visible for subclasses michael@0: SkMovie(); michael@0: michael@0: private: michael@0: Info fInfo; michael@0: SkMSec fCurrTime; michael@0: SkBitmap fBitmap; michael@0: bool fNeedBitmap; michael@0: michael@0: void ensureInfo(); michael@0: michael@0: typedef SkRefCnt INHERITED; michael@0: }; michael@0: michael@0: #endif