diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:30:35 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:30:35 -0800 |
commit | 0910916c0f7b951ee55c4b7c6358295b9bca0565 (patch) | |
tree | 059e9645510636ae148ba4594b3d6009918655e2 /src/images/SkMovie.cpp | |
parent | 6eb364108744656fcd23a96a478aa772cd4e85bc (diff) | |
download | external_skia-0910916c0f7b951ee55c4b7c6358295b9bca0565.zip external_skia-0910916c0f7b951ee55c4b7c6358295b9bca0565.tar.gz external_skia-0910916c0f7b951ee55c4b7c6358295b9bca0565.tar.bz2 |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'src/images/SkMovie.cpp')
-rw-r--r-- | src/images/SkMovie.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/images/SkMovie.cpp b/src/images/SkMovie.cpp new file mode 100644 index 0000000..7186ed5 --- /dev/null +++ b/src/images/SkMovie.cpp @@ -0,0 +1,101 @@ +#include "SkMovie.h" +#include "SkCanvas.h" +#include "SkPaint.h" + +// We should never see this in normal operation since our time values are +// 0-based. So we use it as a sentinal. +#define UNINITIALIZED_MSEC ((SkMSec)-1) + +SkMovie::SkMovie() +{ + fInfo.fDuration = UNINITIALIZED_MSEC; // uninitialized + fCurrTime = UNINITIALIZED_MSEC; // uninitialized + fNeedBitmap = true; +} + +void SkMovie::ensureInfo() +{ + if (fInfo.fDuration == UNINITIALIZED_MSEC && !this->onGetInfo(&fInfo)) + memset(&fInfo, 0, sizeof(fInfo)); // failure +} + +SkMSec SkMovie::duration() +{ + this->ensureInfo(); + return fInfo.fDuration; +} + +int SkMovie::width() +{ + this->ensureInfo(); + return fInfo.fWidth; +} + +int SkMovie::height() +{ + this->ensureInfo(); + return fInfo.fHeight; +} + +int SkMovie::isOpaque() +{ + this->ensureInfo(); + return fInfo.fIsOpaque; +} + +bool SkMovie::setTime(SkMSec time) +{ + SkMSec dur = this->duration(); + if (time > dur) + time = dur; + + bool changed = false; + if (time != fCurrTime) + { + fCurrTime = time; + changed = this->onSetTime(time); + fNeedBitmap |= changed; + } + return changed; +} + +const SkBitmap& SkMovie::bitmap() +{ + if (fCurrTime == UNINITIALIZED_MSEC) // uninitialized + this->setTime(0); + + if (fNeedBitmap) + { + if (!this->onGetBitmap(&fBitmap)) // failure + fBitmap.reset(); + fNeedBitmap = false; + } + return fBitmap; +} + +//////////////////////////////////////////////////////////////////// + +#include "SkStream.h" + +SkMovie* SkMovie::DecodeMemory(const void* data, size_t length) { + SkMemoryStream stream(data, length, false); + return SkMovie::DecodeStream(&stream); +} + +SkMovie* SkMovie::DecodeFile(const char path[]) +{ + SkMovie* movie = NULL; + + SkFILEStream stream(path); + if (stream.isValid()) { + movie = SkMovie::DecodeStream(&stream); + } +#ifdef SK_DEBUG + else { + SkDebugf("Movie file not found <%s>\n", path); + } +#endif + + return movie; +} + |