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