michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project 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: michael@0: michael@0: #include "SkAnimate.h" michael@0: #include "SkAnimateMaker.h" michael@0: #include "SkDrawable.h" michael@0: #include "SkParse.h" michael@0: michael@0: #if SK_USE_CONDENSED_INFO == 0 michael@0: michael@0: const SkMemberInfo SkAnimate::fInfo[] = { michael@0: SK_MEMBER_INHERITED michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: DEFINE_GET_MEMBER(SkAnimate); michael@0: michael@0: SkAnimate::SkAnimate() : fComponents(0) { michael@0: } michael@0: michael@0: SkAnimate::~SkAnimate() { michael@0: } michael@0: michael@0: int SkAnimate::components() { michael@0: return fComponents; michael@0: } michael@0: michael@0: #ifdef SK_DUMP_ENABLED michael@0: void SkAnimate::dump(SkAnimateMaker* maker) { michael@0: INHERITED::dump(maker); //from animateBase michael@0: //SkSet inherits from this class michael@0: if (getType() != SkType_Set) { michael@0: if (fMirror) michael@0: SkDebugf("mirror=\"true\" "); michael@0: if (fReset) michael@0: SkDebugf("reset=\"true\" "); michael@0: SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000))); michael@0: if (repeat != SK_Scalar1) michael@0: SkDebugf("repeat=\"%g\" ", SkScalarToFloat(repeat)); michael@0: //if (fHasValues) michael@0: // SkDebugf("values=\"%s\" ", values); michael@0: if (blend.count() != 1 || blend[0] != SK_Scalar1) { michael@0: SkDebugf("blend=\"["); michael@0: bool firstElem = true; michael@0: for (int i = 0; i < blend.count(); i++) { michael@0: if (!firstElem) michael@0: SkDebugf(","); michael@0: firstElem = false; michael@0: SkDebugf("%g", SkScalarToFloat(blend[i])); michael@0: } michael@0: SkDebugf("]\" "); michael@0: } michael@0: SkDebugf("/>\n");//i assume that if it IS, we will do it separately michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: bool SkAnimate::resolveCommon(SkAnimateMaker& maker) { michael@0: if (fTarget == NULL) // if NULL, recall onEndElement after apply closes and sets target to scope michael@0: return false; michael@0: INHERITED::onEndElement(maker); michael@0: return maker.hasError() == false; michael@0: } michael@0: michael@0: void SkAnimate::onEndElement(SkAnimateMaker& maker) { michael@0: bool resolved = resolveCommon(maker); michael@0: if (resolved && fFieldInfo == NULL) { michael@0: maker.setErrorNoun(field); michael@0: maker.setErrorCode(SkDisplayXMLParserError::kFieldNotInTarget); michael@0: } michael@0: if (resolved == false || fFieldInfo == NULL) michael@0: return; michael@0: SkDisplayTypes outType = fFieldInfo->getType(); michael@0: if (fHasValues) { michael@0: SkASSERT(to.size() > 0); michael@0: fFieldInfo->setValue(maker, &fValues, 0, 0, NULL, outType, to); michael@0: SkASSERT(0); michael@0: // !!! this needs to set fComponents michael@0: return; michael@0: } michael@0: fComponents = fFieldInfo->getCount(); michael@0: if (fFieldInfo->fType == SkType_Array) { michael@0: SkTypedArray* array = (SkTypedArray*) fFieldInfo->memberData(fTarget); michael@0: int count = array->count(); michael@0: if (count > 0) michael@0: fComponents = count; michael@0: } michael@0: if (outType == SkType_ARGB) { michael@0: fComponents <<= 2; // four color components michael@0: outType = SkType_Float; michael@0: } michael@0: fValues.setType(outType); michael@0: if (formula.size() > 0){ michael@0: fComponents = 1; michael@0: from.set("0"); michael@0: to.set("dur"); michael@0: outType = SkType_MSec; michael@0: } michael@0: int max = fComponents * 2; michael@0: fValues.setCount(max); michael@0: memset(fValues.begin(), 0, max * sizeof(fValues.begin()[0])); michael@0: fFieldInfo->setValue(maker, &fValues, fFieldOffset, max, this, outType, from); michael@0: fFieldInfo->setValue(maker, &fValues, fComponents + fFieldOffset, max, this, outType, to); michael@0: }