gfx/skia/trunk/src/animator/SkAnimateField.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/animator/SkAnimateField.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2006 The Android Open Source Project
     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 +
    1.12 +
    1.13 +#include "SkAnimate.h"
    1.14 +#include "SkAnimateMaker.h"
    1.15 +#include "SkDrawable.h"
    1.16 +#include "SkParse.h"
    1.17 +
    1.18 +#if SK_USE_CONDENSED_INFO == 0
    1.19 +
    1.20 +const SkMemberInfo SkAnimate::fInfo[] = {
    1.21 +    SK_MEMBER_INHERITED
    1.22 +};
    1.23 +
    1.24 +#endif
    1.25 +
    1.26 +DEFINE_GET_MEMBER(SkAnimate);
    1.27 +
    1.28 +SkAnimate::SkAnimate() : fComponents(0) {
    1.29 +}
    1.30 +
    1.31 +SkAnimate::~SkAnimate() {
    1.32 +}
    1.33 +
    1.34 +int SkAnimate::components() {
    1.35 +    return fComponents;
    1.36 +}
    1.37 +
    1.38 +#ifdef SK_DUMP_ENABLED
    1.39 +void SkAnimate::dump(SkAnimateMaker* maker) {
    1.40 +    INHERITED::dump(maker); //from animateBase
    1.41 +    //SkSet inherits from this class
    1.42 +    if (getType() != SkType_Set) {
    1.43 +        if (fMirror)
    1.44 +            SkDebugf("mirror=\"true\" ");
    1.45 +        if (fReset)
    1.46 +            SkDebugf("reset=\"true\" ");
    1.47 +        SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
    1.48 +        if (repeat != SK_Scalar1)
    1.49 +            SkDebugf("repeat=\"%g\" ", SkScalarToFloat(repeat));
    1.50 +        //if (fHasValues)
    1.51 +        //    SkDebugf("values=\"%s\" ", values);
    1.52 +        if (blend.count() != 1 || blend[0] != SK_Scalar1) {
    1.53 +            SkDebugf("blend=\"[");
    1.54 +            bool firstElem = true;
    1.55 +            for (int i = 0; i < blend.count(); i++) {
    1.56 +                if (!firstElem)
    1.57 +                    SkDebugf(",");
    1.58 +                firstElem = false;
    1.59 +                SkDebugf("%g", SkScalarToFloat(blend[i]));
    1.60 +            }
    1.61 +            SkDebugf("]\" ");
    1.62 +        }
    1.63 +        SkDebugf("/>\n");//i assume that if it IS, we will do it separately
    1.64 +    }
    1.65 +}
    1.66 +#endif
    1.67 +
    1.68 +bool SkAnimate::resolveCommon(SkAnimateMaker& maker) {
    1.69 +    if (fTarget == NULL) // if NULL, recall onEndElement after apply closes and sets target to scope
    1.70 +        return false;
    1.71 +    INHERITED::onEndElement(maker);
    1.72 +    return maker.hasError() == false;
    1.73 +}
    1.74 +
    1.75 +void SkAnimate::onEndElement(SkAnimateMaker& maker) {
    1.76 +    bool resolved = resolveCommon(maker);
    1.77 +    if (resolved && fFieldInfo == NULL) {
    1.78 +        maker.setErrorNoun(field);
    1.79 +        maker.setErrorCode(SkDisplayXMLParserError::kFieldNotInTarget);
    1.80 +    }
    1.81 +    if (resolved == false || fFieldInfo == NULL)
    1.82 +        return;
    1.83 +    SkDisplayTypes outType = fFieldInfo->getType();
    1.84 +    if (fHasValues) {
    1.85 +        SkASSERT(to.size() > 0);
    1.86 +        fFieldInfo->setValue(maker, &fValues, 0, 0, NULL, outType, to);
    1.87 +        SkASSERT(0);
    1.88 +        // !!! this needs to set fComponents
    1.89 +        return;
    1.90 +    }
    1.91 +    fComponents = fFieldInfo->getCount();
    1.92 +    if (fFieldInfo->fType == SkType_Array) {
    1.93 +        SkTypedArray* array = (SkTypedArray*) fFieldInfo->memberData(fTarget);
    1.94 +        int count = array->count();
    1.95 +        if (count > 0)
    1.96 +            fComponents = count;
    1.97 +    }
    1.98 +    if (outType == SkType_ARGB) {
    1.99 +        fComponents <<= 2;  // four color components
   1.100 +        outType = SkType_Float;
   1.101 +    }
   1.102 +    fValues.setType(outType);
   1.103 +    if (formula.size() > 0){
   1.104 +        fComponents = 1;
   1.105 +        from.set("0");
   1.106 +        to.set("dur");
   1.107 +        outType = SkType_MSec;
   1.108 +    }
   1.109 +    int max = fComponents * 2;
   1.110 +    fValues.setCount(max);
   1.111 +    memset(fValues.begin(), 0, max * sizeof(fValues.begin()[0]));
   1.112 +    fFieldInfo->setValue(maker, &fValues, fFieldOffset, max, this, outType, from);
   1.113 +    fFieldInfo->setValue(maker, &fValues, fComponents + fFieldOffset, max, this, outType, to);
   1.114 +}

mercurial