gfx/skia/trunk/src/images/SkMovie.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/images/SkMovie.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +#include "SkMovie.h"
    1.12 +#include "SkCanvas.h"
    1.13 +#include "SkPaint.h"
    1.14 +
    1.15 +// We should never see this in normal operation since our time values are
    1.16 +// 0-based. So we use it as a sentinal.
    1.17 +#define UNINITIALIZED_MSEC ((SkMSec)-1)
    1.18 +
    1.19 +SkMovie::SkMovie()
    1.20 +{
    1.21 +    fInfo.fDuration = UNINITIALIZED_MSEC;  // uninitialized
    1.22 +    fCurrTime = UNINITIALIZED_MSEC; // uninitialized
    1.23 +    fNeedBitmap = true;
    1.24 +}
    1.25 +
    1.26 +void SkMovie::ensureInfo()
    1.27 +{
    1.28 +    if (fInfo.fDuration == UNINITIALIZED_MSEC && !this->onGetInfo(&fInfo))
    1.29 +        memset(&fInfo, 0, sizeof(fInfo));   // failure
    1.30 +}
    1.31 +
    1.32 +SkMSec SkMovie::duration()
    1.33 +{
    1.34 +    this->ensureInfo();
    1.35 +    return fInfo.fDuration;
    1.36 +}
    1.37 +
    1.38 +int SkMovie::width()
    1.39 +{
    1.40 +    this->ensureInfo();
    1.41 +    return fInfo.fWidth;
    1.42 +}
    1.43 +
    1.44 +int SkMovie::height()
    1.45 +{
    1.46 +    this->ensureInfo();
    1.47 +    return fInfo.fHeight;
    1.48 +}
    1.49 +
    1.50 +int SkMovie::isOpaque()
    1.51 +{
    1.52 +    this->ensureInfo();
    1.53 +    return fInfo.fIsOpaque;
    1.54 +}
    1.55 +
    1.56 +bool SkMovie::setTime(SkMSec time)
    1.57 +{
    1.58 +    SkMSec dur = this->duration();
    1.59 +    if (time > dur)
    1.60 +        time = dur;
    1.61 +
    1.62 +    bool changed = false;
    1.63 +    if (time != fCurrTime)
    1.64 +    {
    1.65 +        fCurrTime = time;
    1.66 +        changed = this->onSetTime(time);
    1.67 +        fNeedBitmap |= changed;
    1.68 +    }
    1.69 +    return changed;
    1.70 +}
    1.71 +
    1.72 +const SkBitmap& SkMovie::bitmap()
    1.73 +{
    1.74 +    if (fCurrTime == UNINITIALIZED_MSEC)    // uninitialized
    1.75 +        this->setTime(0);
    1.76 +
    1.77 +    if (fNeedBitmap)
    1.78 +    {
    1.79 +        if (!this->onGetBitmap(&fBitmap))   // failure
    1.80 +            fBitmap.reset();
    1.81 +        fNeedBitmap = false;
    1.82 +    }
    1.83 +    return fBitmap;
    1.84 +}
    1.85 +
    1.86 +////////////////////////////////////////////////////////////////////
    1.87 +
    1.88 +#include "SkStream.h"
    1.89 +
    1.90 +SkMovie* SkMovie::DecodeMemory(const void* data, size_t length) {
    1.91 +    SkMemoryStream stream(data, length, false);
    1.92 +    return SkMovie::DecodeStream(&stream);
    1.93 +}
    1.94 +
    1.95 +SkMovie* SkMovie::DecodeFile(const char path[]) {
    1.96 +    SkAutoTUnref<SkStreamRewindable> stream(SkStream::NewFromFile(path));
    1.97 +    return stream.get() ? SkMovie::DecodeStream(stream) : NULL;
    1.98 +}

mercurial