|
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 |
|
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 |
|
31 int SkAnimate::components() { |
|
32 return fComponents; |
|
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\" "); |
|
44 SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000))); |
|
45 if (repeat != SK_Scalar1) |
|
46 SkDebugf("repeat=\"%g\" ", SkScalarToFloat(repeat)); |
|
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++) { |
|
53 if (!firstElem) |
|
54 SkDebugf(","); |
|
55 firstElem = false; |
|
56 SkDebugf("%g", SkScalarToFloat(blend[i])); |
|
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); |
|
85 // !!! this needs to set fComponents |
|
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 } |