180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2008 The Android Open Source Project
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkMovie_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkMovie_DEFINED
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkRefCnt.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkCanvas.h"
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
160a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenbergerclass SkStreamRewindable;
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkMovie : public SkRefCnt {
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_DECLARE_INST_COUNT(SkMovie)
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Try to create a movie from the stream. If the stream format is not
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        supported, return NULL.
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
250a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger    static SkMovie* DecodeStream(SkStreamRewindable*);
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Try to create a movie from the specified file path. If the file is not
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        found, or the format is not supported, return NULL. If a movie is
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        returned, the stream may be retained by the movie (via ref()) until
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        the movie is finished with it (by calling unref()).
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static SkMovie* DecodeFile(const char path[]);
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Try to create a movie from the specified memory.
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        If the format is not supported, return NULL. If a movie is returned,
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        the data will have been read or copied, and so the caller may free
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        it.
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static SkMovie* DecodeMemory(const void* data, size_t length);
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkMSec  duration();
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int     width();
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int     height();
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int     isOpaque();
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Specify the time code (between 0...duration) to sample a bitmap
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        from the movie. Returns true if this time code generated a different
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        bitmap/frame from the previous state (i.e. true means you need to
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        redraw).
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool setTime(SkMSec);
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // return the right bitmap for the current time code
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SkBitmap& bitmap();
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprotected:
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    struct Info {
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkMSec  fDuration;
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int     fWidth;
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int     fHeight;
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        bool    fIsOpaque;
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool onGetInfo(Info*) = 0;
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool onSetTime(SkMSec) = 0;
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool onGetBitmap(SkBitmap*) = 0;
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // visible for subclasses
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkMovie();
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    Info        fInfo;
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkMSec      fCurrTime;
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkBitmap    fBitmap;
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool        fNeedBitmap;
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void ensureInfo();
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    typedef SkRefCnt INHERITED;
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
81