epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkAnimate.h" |
| 11 | #include "SkAnimateMaker.h" |
| 12 | #include "SkDrawable.h" |
| 13 | #include "SkParse.h" |
| 14 | |
| 15 | #if SK_USE_CONDENSED_INFO == 0 |
| 16 | |
| 17 | const SkMemberInfo SkAnimate::fInfo[] = { |
| 18 | SK_MEMBER_INHERITED |
| 19 | }; |
| 20 | |
| 21 | #endif |
| 22 | |
| 23 | DEFINE_GET_MEMBER(SkAnimate); |
| 24 | |
| 25 | SkAnimate::SkAnimate() : fComponents(0) { |
| 26 | } |
| 27 | |
| 28 | SkAnimate::~SkAnimate() { |
| 29 | } |
| 30 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 31 | int SkAnimate::components() { |
| 32 | return fComponents; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | #ifdef SK_DUMP_ENABLED |
| 36 | void SkAnimate::dump(SkAnimateMaker* maker) { |
| 37 | INHERITED::dump(maker); //from animateBase |
| 38 | //SkSet inherits from this class |
| 39 | if (getType() != SkType_Set) { |
| 40 | if (fMirror) |
| 41 | SkDebugf("mirror=\"true\" "); |
| 42 | if (fReset) |
| 43 | SkDebugf("reset=\"true\" "); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000))); |
| 45 | if (repeat != SK_Scalar1) |
| 46 | SkDebugf("repeat=\"%g\" ", SkScalarToFloat(repeat)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 47 | //if (fHasValues) |
| 48 | // SkDebugf("values=\"%s\" ", values); |
| 49 | if (blend.count() != 1 || blend[0] != SK_Scalar1) { |
| 50 | SkDebugf("blend=\"["); |
| 51 | bool firstElem = true; |
| 52 | for (int i = 0; i < blend.count(); i++) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 53 | if (!firstElem) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | SkDebugf(","); |
| 55 | firstElem = false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | SkDebugf("%g", SkScalarToFloat(blend[i])); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | } |
| 58 | SkDebugf("]\" "); |
| 59 | } |
| 60 | SkDebugf("/>\n");//i assume that if it IS, we will do it separately |
| 61 | } |
| 62 | } |
| 63 | #endif |
| 64 | |
| 65 | bool SkAnimate::resolveCommon(SkAnimateMaker& maker) { |
| 66 | if (fTarget == NULL) // if NULL, recall onEndElement after apply closes and sets target to scope |
| 67 | return false; |
| 68 | INHERITED::onEndElement(maker); |
| 69 | return maker.hasError() == false; |
| 70 | } |
| 71 | |
| 72 | void SkAnimate::onEndElement(SkAnimateMaker& maker) { |
| 73 | bool resolved = resolveCommon(maker); |
| 74 | if (resolved && fFieldInfo == NULL) { |
| 75 | maker.setErrorNoun(field); |
| 76 | maker.setErrorCode(SkDisplayXMLParserError::kFieldNotInTarget); |
| 77 | } |
| 78 | if (resolved == false || fFieldInfo == NULL) |
| 79 | return; |
| 80 | SkDisplayTypes outType = fFieldInfo->getType(); |
| 81 | if (fHasValues) { |
| 82 | SkASSERT(to.size() > 0); |
| 83 | fFieldInfo->setValue(maker, &fValues, 0, 0, NULL, outType, to); |
| 84 | SkASSERT(0); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 85 | // !!! this needs to set fComponents |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | return; |
| 87 | } |
| 88 | fComponents = fFieldInfo->getCount(); |
| 89 | if (fFieldInfo->fType == SkType_Array) { |
| 90 | SkTypedArray* array = (SkTypedArray*) fFieldInfo->memberData(fTarget); |
| 91 | int count = array->count(); |
| 92 | if (count > 0) |
| 93 | fComponents = count; |
| 94 | } |
| 95 | if (outType == SkType_ARGB) { |
| 96 | fComponents <<= 2; // four color components |
| 97 | outType = SkType_Float; |
| 98 | } |
| 99 | fValues.setType(outType); |
| 100 | if (formula.size() > 0){ |
| 101 | fComponents = 1; |
| 102 | from.set("0"); |
| 103 | to.set("dur"); |
| 104 | outType = SkType_MSec; |
| 105 | } |
| 106 | int max = fComponents * 2; |
| 107 | fValues.setCount(max); |
| 108 | memset(fValues.begin(), 0, max * sizeof(fValues.begin()[0])); |
| 109 | fFieldInfo->setValue(maker, &fValues, fFieldOffset, max, this, outType, from); |
| 110 | fFieldInfo->setValue(maker, &fValues, fComponents + fFieldOffset, max, this, outType, to); |
| 111 | } |