blob: 0f92989dccfd2506b09be816aa384d7233a900e9 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com8a1c16f2008-12-17 15:59:43 +00009
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
17const SkMemberInfo SkAnimate::fInfo[] = {
18 SK_MEMBER_INHERITED
19};
20
21#endif
22
23DEFINE_GET_MEMBER(SkAnimate);
24
25SkAnimate::SkAnimate() : fComponents(0) {
26}
27
28SkAnimate::~SkAnimate() {
29}
30
rmistry@google.comd6176b02012-08-23 18:14:13 +000031int SkAnimate::components() {
32 return fComponents;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033}
34
35#ifdef SK_DUMP_ENABLED
36void 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.com8a1c16f2008-12-17 15:59:43 +000044 SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
45 if (repeat != SK_Scalar1)
46 SkDebugf("repeat=\"%g\" ", SkScalarToFloat(repeat));
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 //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.comd6176b02012-08-23 18:14:13 +000053 if (!firstElem)
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 SkDebugf(",");
55 firstElem = false;
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 SkDebugf("%g", SkScalarToFloat(blend[i]));
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 }
58 SkDebugf("]\" ");
59 }
60 SkDebugf("/>\n");//i assume that if it IS, we will do it separately
61 }
62}
63#endif
64
65bool 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
72void 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.comd6176b02012-08-23 18:14:13 +000085 // !!! this needs to set fComponents
reed@android.com8a1c16f2008-12-17 15:59:43 +000086 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}