| OLD | NEW |
| (Empty) |
| 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::DecodeFile(const char path[]) | |
| 81 { | |
| 82 SkMovie* movie = NULL; | |
| 83 | |
| 84 // since the movie might hold onto the stream | |
| 85 // we dynamically allocate it and then unref() | |
| 86 SkFILEStream* stream = new SkFILEStream(path); | |
| 87 if (stream->isValid()) | |
| 88 movie = SkMovie::DecodeStream(stream); | |
| 89 #ifdef SK_DEBUG | |
| 90 else | |
| 91 SkDebugf("Movie file not found <%s>\n", path); | |
| 92 #endif | |
| 93 stream->unref(); | |
| 94 | |
| 95 return movie; | |
| 96 } | |
| 97 | |
| OLD | NEW |