gfx/skia/trunk/src/animator/SkAnimateBase.cpp

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkAnimateBase.h"
michael@0 11 #include "SkAnimateMaker.h"
michael@0 12 #include "SkAnimateProperties.h"
michael@0 13 #include "SkAnimatorScript.h"
michael@0 14 #include "SkDisplayApply.h"
michael@0 15 #include "SkDrawable.h"
michael@0 16
michael@0 17 #if SK_USE_CONDENSED_INFO == 0
michael@0 18
michael@0 19 const SkMemberInfo SkAnimateBase::fInfo[] = {
michael@0 20 SK_MEMBER(begin, MSec),
michael@0 21 SK_MEMBER_ARRAY(blend, Float),
michael@0 22 SK_MEMBER(dur, MSec),
michael@0 23 SK_MEMBER_PROPERTY(dynamic, Boolean),
michael@0 24 SK_MEMBER(field, String), // name of member info in target
michael@0 25 SK_MEMBER(formula, DynamicString),
michael@0 26 SK_MEMBER(from, DynamicString),
michael@0 27 SK_MEMBER(lval, DynamicString),
michael@0 28 SK_MEMBER_PROPERTY(mirror, Boolean),
michael@0 29 SK_MEMBER(repeat, Float),
michael@0 30 SK_MEMBER_PROPERTY(reset, Boolean),
michael@0 31 SK_MEMBER_PROPERTY(step, Int),
michael@0 32 SK_MEMBER(target, DynamicString),
michael@0 33 SK_MEMBER(to, DynamicString),
michael@0 34 SK_MEMBER_PROPERTY(values, DynamicString)
michael@0 35 };
michael@0 36
michael@0 37 #endif
michael@0 38
michael@0 39 DEFINE_GET_MEMBER(SkAnimateBase);
michael@0 40
michael@0 41 SkAnimateBase::SkAnimateBase() : begin(0), dur(1), repeat(SK_Scalar1),
michael@0 42 fApply(NULL), fFieldInfo(NULL), fFieldOffset(0), fStart((SkMSec) -1), fTarget(NULL),
michael@0 43 fChanged(0), fDelayed(0), fDynamic(0), fHasEndEvent(0), fHasValues(0),
michael@0 44 fMirror(0), fReset(0), fResetPending(0), fTargetIsScope(0) {
michael@0 45 blend.setCount(1);
michael@0 46 blend[0] = SK_Scalar1;
michael@0 47 }
michael@0 48
michael@0 49 SkAnimateBase::~SkAnimateBase() {
michael@0 50 SkDisplayTypes type = fValues.getType();
michael@0 51 if (type == SkType_String || type == SkType_DynamicString) {
michael@0 52 SkASSERT(fValues.count() == 1);
michael@0 53 delete fValues[0].fString;
michael@0 54 }
michael@0 55 }
michael@0 56
michael@0 57 int SkAnimateBase::components() {
michael@0 58 return 1;
michael@0 59 }
michael@0 60
michael@0 61 SkDisplayable* SkAnimateBase::deepCopy(SkAnimateMaker* maker) {
michael@0 62 SkAnimateBase* result = (SkAnimateBase*) INHERITED::deepCopy(maker);
michael@0 63 result->fApply = fApply;
michael@0 64 result->fFieldInfo =fFieldInfo;
michael@0 65 result->fHasValues = false;
michael@0 66 return result;
michael@0 67 }
michael@0 68
michael@0 69 void SkAnimateBase::dirty() {
michael@0 70 fChanged = true;
michael@0 71 }
michael@0 72
michael@0 73 #ifdef SK_DUMP_ENABLED
michael@0 74 void SkAnimateBase::dump(SkAnimateMaker* maker) {
michael@0 75 dumpBase(maker);
michael@0 76 if (target.size() > 0)
michael@0 77 SkDebugf("target=\"%s\" ", target.c_str());
michael@0 78 else if (fTarget && strcmp(fTarget->id, ""))
michael@0 79 SkDebugf("target=\"%s\" ", fTarget->id);
michael@0 80 if (lval.size() > 0)
michael@0 81 SkDebugf("lval=\"%s\" ", lval.c_str());
michael@0 82 if (field.size() > 0)
michael@0 83 SkDebugf("field=\"%s\" ", field.c_str());
michael@0 84 else if (fFieldInfo)
michael@0 85 SkDebugf("field=\"%s\" ", fFieldInfo->fName);
michael@0 86 if (formula.size() > 0)
michael@0 87 SkDebugf("formula=\"%s\" ", formula.c_str());
michael@0 88 else {
michael@0 89 if (from.size() > 0)
michael@0 90 SkDebugf("from=\"%s\" ", from.c_str());
michael@0 91 SkDebugf("to=\"%s\" ", to.c_str());
michael@0 92 }
michael@0 93 if (begin != 0) {
michael@0 94 SkDebugf("begin=\"%g\" ", SkScalarToFloat(SkScalarDiv(begin,1000)));
michael@0 95 }
michael@0 96 }
michael@0 97 #endif
michael@0 98
michael@0 99 SkDisplayable* SkAnimateBase::getParent() const {
michael@0 100 return (SkDisplayable*) fApply;
michael@0 101 }
michael@0 102
michael@0 103 bool SkAnimateBase::getProperty(int index, SkScriptValue* value) const {
michael@0 104 int boolResult;
michael@0 105 switch (index) {
michael@0 106 case SK_PROPERTY(dynamic):
michael@0 107 boolResult = fDynamic;
michael@0 108 goto returnBool;
michael@0 109 case SK_PROPERTY(mirror):
michael@0 110 boolResult = fMirror;
michael@0 111 goto returnBool;
michael@0 112 case SK_PROPERTY(reset):
michael@0 113 boolResult = fReset;
michael@0 114 returnBool:
michael@0 115 value->fOperand.fS32 = SkToBool(boolResult);
michael@0 116 value->fType = SkType_Boolean;
michael@0 117 break;
michael@0 118 case SK_PROPERTY(step):
michael@0 119 if (fApply == NULL)
michael@0 120 return false; // !!! notify there's an error?
michael@0 121 fApply->getStep(value);
michael@0 122 break;
michael@0 123 case SK_PROPERTY(values):
michael@0 124 value->fOperand.fString = (SkString*) &to;
michael@0 125 value->fType = SkType_String;
michael@0 126 break;
michael@0 127 default:
michael@0 128 SkASSERT(0);
michael@0 129 return false;
michael@0 130 }
michael@0 131 return true;
michael@0 132 }
michael@0 133
michael@0 134 bool SkAnimateBase::hasExecute() const
michael@0 135 {
michael@0 136 return false;
michael@0 137 }
michael@0 138
michael@0 139 void SkAnimateBase::onEndElement(SkAnimateMaker& maker) {
michael@0 140 fChanged = false;
michael@0 141 setTarget(maker);
michael@0 142 if (field.size()) {
michael@0 143 SkASSERT(fTarget);
michael@0 144 fFieldInfo = fTarget->getMember(field.c_str());
michael@0 145 field.reset();
michael@0 146 }
michael@0 147 if (lval.size()) {
michael@0 148 // lval must be of the form x[y]
michael@0 149 const char* lvalStr = lval.c_str();
michael@0 150 const char* arrayEnd = strchr(lvalStr, '[');
michael@0 151 if (arrayEnd == NULL)
michael@0 152 return; //should this return an error?
michael@0 153 size_t arrayNameLen = arrayEnd - lvalStr;
michael@0 154 SkString arrayStr(lvalStr, arrayNameLen);
michael@0 155 SkASSERT(fTarget); //this return an error?
michael@0 156 fFieldInfo = fTarget->getMember(arrayStr.c_str());
michael@0 157 SkString scriptStr(arrayEnd + 1, lval.size() - arrayNameLen - 2);
michael@0 158 SkAnimatorScript::EvaluateInt(maker, this, scriptStr.c_str(), &fFieldOffset);
michael@0 159 }
michael@0 160 }
michael@0 161
michael@0 162 void SkAnimateBase::packARGB(SkScalar array[], int count, SkTDOperandArray* converted)
michael@0 163 {
michael@0 164 SkASSERT(count == 4);
michael@0 165 converted->setCount(1);
michael@0 166 SkColor color = SkColorSetARGB(SkScalarRoundToInt(array[0]),
michael@0 167 SkScalarRoundToInt(array[1]),
michael@0 168 SkScalarRoundToInt(array[2]),
michael@0 169 SkScalarRoundToInt(array[3]));
michael@0 170 (*converted)[0].fS32 = color;
michael@0 171 }
michael@0 172
michael@0 173
michael@0 174
michael@0 175 void SkAnimateBase::refresh(SkAnimateMaker& ) {
michael@0 176 }
michael@0 177
michael@0 178 bool SkAnimateBase::setParent(SkDisplayable* apply) {
michael@0 179 SkASSERT(apply->isApply());
michael@0 180 fApply = (SkApply*) apply;
michael@0 181 return false;
michael@0 182 }
michael@0 183
michael@0 184 bool SkAnimateBase::setProperty(int index, SkScriptValue& value) {
michael@0 185 bool boolValue = SkToBool(value.fOperand.fS32);
michael@0 186 switch (index) {
michael@0 187 case SK_PROPERTY(dynamic):
michael@0 188 fDynamic = boolValue;
michael@0 189 goto checkForBool;
michael@0 190 case SK_PROPERTY(values):
michael@0 191 fHasValues = true;
michael@0 192 SkASSERT(value.fType == SkType_String);
michael@0 193 to = *value.fOperand.fString;
michael@0 194 break;
michael@0 195 case SK_PROPERTY(mirror):
michael@0 196 fMirror = boolValue;
michael@0 197 goto checkForBool;
michael@0 198 case SK_PROPERTY(reset):
michael@0 199 fReset = boolValue;
michael@0 200 checkForBool:
michael@0 201 SkASSERT(value.fType == SkType_Boolean);
michael@0 202 break;
michael@0 203 default:
michael@0 204 return false;
michael@0 205 }
michael@0 206 return true;
michael@0 207 }
michael@0 208
michael@0 209 void SkAnimateBase::setTarget(SkAnimateMaker& maker) {
michael@0 210 if (target.size()) {
michael@0 211 SkAnimatorScript engine(maker, this, SkType_Displayable);
michael@0 212 const char* script = target.c_str();
michael@0 213 SkScriptValue scriptValue;
michael@0 214 bool success = engine.evaluateScript(&script, &scriptValue);
michael@0 215 if (success && scriptValue.fType == SkType_Displayable)
michael@0 216 fTarget = scriptValue.fOperand.fDrawable;
michael@0 217 else if (maker.find(target.c_str(), (SkDisplayable**) &fTarget) == false) {
michael@0 218 if (fApply->getMode() == SkApply::kMode_create)
michael@0 219 return; // may not be an error
michael@0 220 if (engine.getError() != SkScriptEngine::kNoError)
michael@0 221 maker.setScriptError(engine);
michael@0 222 else {
michael@0 223 maker.setErrorNoun(target);
michael@0 224 maker.setErrorCode(SkDisplayXMLParserError::kTargetIDNotFound);
michael@0 225 }
michael@0 226 return;
michael@0 227 }
michael@0 228 if (fApply && fApply->getMode() != SkApply::kMode_create)
michael@0 229 target.reset();
michael@0 230 }
michael@0 231 }
michael@0 232
michael@0 233 bool SkAnimateBase::targetNeedsInitialization() const {
michael@0 234 return false;
michael@0 235 }

mercurial