Home | History | Annotate | Download | only in images
      1 #include "SkMovie.h"
      2 #include "SkCanvas.h"
      3 #include "SkPaint.h"
      4 
      5 // We should never see this in normal operation since our time values are
      6 // 0-based. So we use it as a sentinal.
      7 #define UNINITIALIZED_MSEC ((SkMSec)-1)
      8 
      9 SkMovie::SkMovie()
     10 {
     11     fInfo.fDuration = UNINITIALIZED_MSEC;  // uninitialized
     12     fCurrTime = UNINITIALIZED_MSEC; // uninitialized
     13     fNeedBitmap = true;
     14 }
     15 
     16 void SkMovie::ensureInfo()
     17 {
     18     if (fInfo.fDuration == UNINITIALIZED_MSEC && !this->onGetInfo(&fInfo))
     19         memset(&fInfo, 0, sizeof(fInfo));   // failure
     20 }
     21 
     22 SkMSec SkMovie::duration()
     23 {
     24     this->ensureInfo();
     25     return fInfo.fDuration;
     26 }
     27 
     28 int SkMovie::width()
     29 {
     30     this->ensureInfo();
     31     return fInfo.fWidth;
     32 }
     33 
     34 int SkMovie::height()
     35 {
     36     this->ensureInfo();
     37     return fInfo.fHeight;
     38 }
     39 
     40 int SkMovie::isOpaque()
     41 {
     42     this->ensureInfo();
     43     return fInfo.fIsOpaque;
     44 }
     45 
     46 bool SkMovie::setTime(SkMSec time)
     47 {
     48     SkMSec dur = this->duration();
     49     if (time > dur)
     50         time = dur;
     51 
     52     bool changed = false;
     53     if (time != fCurrTime)
     54     {
     55         fCurrTime = time;
     56         changed = this->onSetTime(time);
     57         fNeedBitmap |= changed;
     58     }
     59     return changed;
     60 }
     61 
     62 const SkBitmap& SkMovie::bitmap()
     63 {
     64     if (fCurrTime == UNINITIALIZED_MSEC)    // uninitialized
     65         this->setTime(0);
     66 
     67     if (fNeedBitmap)
     68     {
     69         if (!this->onGetBitmap(&fBitmap))   // failure
     70             fBitmap.reset();
     71         fNeedBitmap = false;
     72     }
     73     return fBitmap;
     74 }
     75 
     76 ////////////////////////////////////////////////////////////////////
     77 
     78 #include "SkStream.h"
     79 
     80 SkMovie* SkMovie::DecodeMemory(const void* data, size_t length) {
     81     SkMemoryStream stream(data, length, false);
     82     return SkMovie::DecodeStream(&stream);
     83 }
     84 
     85 SkMovie* SkMovie::DecodeFile(const char path[])
     86 {
     87     SkMovie* movie = NULL;
     88 
     89     SkFILEStream stream(path);
     90     if (stream.isValid()) {
     91         movie = SkMovie::DecodeStream(&stream);
     92     }
     93 #ifdef SK_DEBUG
     94     else {
     95         SkDebugf("Movie file not found <%s>\n", path);
     96     }
     97 #endif
     98 
     99     return movie;
    100 }
    101 
    102