• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libs/graphics/animator/SkAnimateField.cpp
2 **
3 ** Copyright 2006, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 #include "SkAnimate.h"
19 #include "SkAnimateMaker.h"
20 #include "SkDrawable.h"
21 #include "SkParse.h"
22 
23 #if SK_USE_CONDENSED_INFO == 0
24 
25 const SkMemberInfo SkAnimate::fInfo[] = {
26     SK_MEMBER_INHERITED
27 };
28 
29 #endif
30 
31 DEFINE_GET_MEMBER(SkAnimate);
32 
SkAnimate()33 SkAnimate::SkAnimate() : fComponents(0) {
34 }
35 
~SkAnimate()36 SkAnimate::~SkAnimate() {
37 }
38 
components()39 int SkAnimate::components() {
40     return fComponents;
41 }
42 
43 #ifdef SK_DUMP_ENABLED
dump(SkAnimateMaker * maker)44 void SkAnimate::dump(SkAnimateMaker* maker) {
45     INHERITED::dump(maker); //from animateBase
46     //SkSet inherits from this class
47     if (getType() != SkType_Set) {
48         if (fMirror)
49             SkDebugf("mirror=\"true\" ");
50         if (fReset)
51             SkDebugf("reset=\"true\" ");
52 #ifdef SK_CAN_USE_FLOAT
53         SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
54         if (repeat != SK_Scalar1)
55             SkDebugf("repeat=\"%g\" ", SkScalarToFloat(repeat));
56 #else
57         SkDebugf("dur=\"%x\" ", SkScalarDiv(dur,1000));
58         if (repeat != SK_Scalar1)
59             SkDebugf("repeat=\"%x\" ", repeat);
60 #endif
61         //if (fHasValues)
62         //    SkDebugf("values=\"%s\" ", values);
63         if (blend.count() != 1 || blend[0] != SK_Scalar1) {
64             SkDebugf("blend=\"[");
65             bool firstElem = true;
66             for (int i = 0; i < blend.count(); i++) {
67                 if (!firstElem)
68                     SkDebugf(",");
69                 firstElem = false;
70 #ifdef SK_CAN_USE_FLOAT
71                 SkDebugf("%g", SkScalarToFloat(blend[i]));
72 #else
73                 SkDebugf("%x", blend[i]);
74 #endif
75             }
76             SkDebugf("]\" ");
77         }
78         SkDebugf("/>\n");//i assume that if it IS, we will do it separately
79     }
80 }
81 #endif
82 
resolveCommon(SkAnimateMaker & maker)83 bool SkAnimate::resolveCommon(SkAnimateMaker& maker) {
84     if (fTarget == NULL) // if NULL, recall onEndElement after apply closes and sets target to scope
85         return false;
86     INHERITED::onEndElement(maker);
87     return maker.hasError() == false;
88 }
89 
onEndElement(SkAnimateMaker & maker)90 void SkAnimate::onEndElement(SkAnimateMaker& maker) {
91     bool resolved = resolveCommon(maker);
92     if (resolved && fFieldInfo == NULL) {
93         maker.setErrorNoun(field);
94         maker.setErrorCode(SkDisplayXMLParserError::kFieldNotInTarget);
95     }
96     if (resolved == false || fFieldInfo == NULL)
97         return;
98     SkDisplayTypes outType = fFieldInfo->getType();
99     if (fHasValues) {
100         SkASSERT(to.size() > 0);
101         fFieldInfo->setValue(maker, &fValues, 0, 0, NULL, outType, to);
102         SkASSERT(0);
103         // !!! this needs to set fComponents
104         return;
105     }
106     fComponents = fFieldInfo->getCount();
107     if (fFieldInfo->fType == SkType_Array) {
108         SkTypedArray* array = (SkTypedArray*) fFieldInfo->memberData(fTarget);
109         int count = array->count();
110         if (count > 0)
111             fComponents = count;
112     }
113     if (outType == SkType_ARGB) {
114         fComponents <<= 2;  // four color components
115         outType = SkType_Float;
116     }
117     fValues.setType(outType);
118     if (formula.size() > 0){
119         fComponents = 1;
120         from.set("0");
121         to.set("dur");
122         outType = SkType_MSec;
123     }
124     int max = fComponents * 2;
125     fValues.setCount(max);
126     memset(fValues.begin(), 0, max * sizeof(fValues.begin()[0]));
127     fFieldInfo->setValue(maker, &fValues, fFieldOffset, max, this, outType, from);
128     fFieldInfo->setValue(maker, &fValues, fComponents + fFieldOffset, max, this, outType, to);
129 }
130 
131