michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: #include "SkMovie.h" michael@0: #include "SkCanvas.h" michael@0: #include "SkPaint.h" michael@0: michael@0: // We should never see this in normal operation since our time values are michael@0: // 0-based. So we use it as a sentinal. michael@0: #define UNINITIALIZED_MSEC ((SkMSec)-1) michael@0: michael@0: SkMovie::SkMovie() michael@0: { michael@0: fInfo.fDuration = UNINITIALIZED_MSEC; // uninitialized michael@0: fCurrTime = UNINITIALIZED_MSEC; // uninitialized michael@0: fNeedBitmap = true; michael@0: } michael@0: michael@0: void SkMovie::ensureInfo() michael@0: { michael@0: if (fInfo.fDuration == UNINITIALIZED_MSEC && !this->onGetInfo(&fInfo)) michael@0: memset(&fInfo, 0, sizeof(fInfo)); // failure michael@0: } michael@0: michael@0: SkMSec SkMovie::duration() michael@0: { michael@0: this->ensureInfo(); michael@0: return fInfo.fDuration; michael@0: } michael@0: michael@0: int SkMovie::width() michael@0: { michael@0: this->ensureInfo(); michael@0: return fInfo.fWidth; michael@0: } michael@0: michael@0: int SkMovie::height() michael@0: { michael@0: this->ensureInfo(); michael@0: return fInfo.fHeight; michael@0: } michael@0: michael@0: int SkMovie::isOpaque() michael@0: { michael@0: this->ensureInfo(); michael@0: return fInfo.fIsOpaque; michael@0: } michael@0: michael@0: bool SkMovie::setTime(SkMSec time) michael@0: { michael@0: SkMSec dur = this->duration(); michael@0: if (time > dur) michael@0: time = dur; michael@0: michael@0: bool changed = false; michael@0: if (time != fCurrTime) michael@0: { michael@0: fCurrTime = time; michael@0: changed = this->onSetTime(time); michael@0: fNeedBitmap |= changed; michael@0: } michael@0: return changed; michael@0: } michael@0: michael@0: const SkBitmap& SkMovie::bitmap() michael@0: { michael@0: if (fCurrTime == UNINITIALIZED_MSEC) // uninitialized michael@0: this->setTime(0); michael@0: michael@0: if (fNeedBitmap) michael@0: { michael@0: if (!this->onGetBitmap(&fBitmap)) // failure michael@0: fBitmap.reset(); michael@0: fNeedBitmap = false; michael@0: } michael@0: return fBitmap; michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////// michael@0: michael@0: #include "SkStream.h" michael@0: michael@0: SkMovie* SkMovie::DecodeMemory(const void* data, size_t length) { michael@0: SkMemoryStream stream(data, length, false); michael@0: return SkMovie::DecodeStream(&stream); michael@0: } michael@0: michael@0: SkMovie* SkMovie::DecodeFile(const char path[]) { michael@0: SkAutoTUnref stream(SkStream::NewFromFile(path)); michael@0: return stream.get() ? SkMovie::DecodeStream(stream) : NULL; michael@0: }