1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2008 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkMovie_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkMovie_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.comclass SkStreamRewindable;
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkMovie : public SkRefCnt {
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
2015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    SK_DECLARE_INST_COUNT(SkMovie)
2115e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Try to create a movie from the stream. If the stream format is not
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        supported, return NULL.
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
25b5571b3324cf18629a255ec85e189447069c9b14scroggo@google.com    static SkMovie* DecodeStream(SkStreamRewindable*);
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Try to create a movie from the specified file path. If the file is not
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        found, or the format is not supported, return NULL. If a movie is
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        returned, the stream may be retained by the movie (via ref()) until
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the movie is finished with it (by calling unref()).
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static SkMovie* DecodeFile(const char path[]);
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Try to create a movie from the specified memory.
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        If the format is not supported, return NULL. If a movie is returned,
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the data will have been read or copied, and so the caller may free
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        it.
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static SkMovie* DecodeMemory(const void* data, size_t length);
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMSec  duration();
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int     width();
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int     height();
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int     isOpaque();
43fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Specify the time code (between 0...duration) to sample a bitmap
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        from the movie. Returns true if this time code generated a different
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap/frame from the previous state (i.e. true means you need to
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        redraw).
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool setTime(SkMSec);
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // return the right bitmap for the current time code
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const SkBitmap& bitmap();
53fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    struct Info {
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkMSec  fDuration;
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int     fWidth;
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int     fHeight;
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool    fIsOpaque;
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool onGetInfo(Info*) = 0;
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool onSetTime(SkMSec) = 0;
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool onGetBitmap(SkBitmap*) = 0;
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // visible for subclasses
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMovie();
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Info        fInfo;
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMSec      fCurrTime;
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBitmap    fBitmap;
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool        fNeedBitmap;
74fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void ensureInfo();
7615e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
7715e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    typedef SkRefCnt INHERITED;
788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
81