180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkAnimateBase.h"
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkAnimateMaker.h"
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkAnimateProperties.h"
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkAnimatorScript.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDisplayApply.h"
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDrawable.h"
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if SK_USE_CONDENSED_INFO == 0
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo SkAnimateBase::fInfo[] = {
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER(begin, MSec),
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER_ARRAY(blend, Float),
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER(dur, MSec),
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER_PROPERTY(dynamic, Boolean),
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER(field, String),   // name of member info in target
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER(formula, DynamicString),
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER(from, DynamicString),
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER(lval, DynamicString),
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER_PROPERTY(mirror, Boolean),
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER(repeat, Float),
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER_PROPERTY(reset, Boolean),
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER_PROPERTY(step, Int),
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER(target, DynamicString),
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER(to, DynamicString),
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_MEMBER_PROPERTY(values, DynamicString)
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDEFINE_GET_MEMBER(SkAnimateBase);
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkAnimateBase::SkAnimateBase() : begin(0), dur(1), repeat(SK_Scalar1),
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fApply(NULL), fFieldInfo(NULL), fFieldOffset(0), fStart((SkMSec) -1), fTarget(NULL),
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fChanged(0), fDelayed(0), fDynamic(0), fHasEndEvent(0), fHasValues(0),
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fMirror(0), fReset(0), fResetPending(0), fTargetIsScope(0) {
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    blend.setCount(1);
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    blend[0] = SK_Scalar1;
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkAnimateBase::~SkAnimateBase() {
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkDisplayTypes type = fValues.getType();
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (type == SkType_String || type == SkType_DynamicString) {
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkASSERT(fValues.count() == 1);
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        delete fValues[0].fString;
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint SkAnimateBase::components() {
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return 1;
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkDisplayable* SkAnimateBase::deepCopy(SkAnimateMaker* maker) {
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkAnimateBase* result = (SkAnimateBase*) INHERITED::deepCopy(maker);
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    result->fApply = fApply;
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    result->fFieldInfo =fFieldInfo;
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    result->fHasValues = false;
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return result;
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimateBase::dirty() {
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    fChanged = true;
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DUMP_ENABLED
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimateBase::dump(SkAnimateMaker* maker) {
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    dumpBase(maker);
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (target.size() > 0)
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkDebugf("target=\"%s\" ", target.c_str());
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    else if (fTarget && strcmp(fTarget->id, ""))
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkDebugf("target=\"%s\" ", fTarget->id);
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (lval.size() > 0)
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkDebugf("lval=\"%s\" ", lval.c_str());
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (field.size() > 0)
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkDebugf("field=\"%s\" ", field.c_str());
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    else if (fFieldInfo)
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkDebugf("field=\"%s\" ", fFieldInfo->fName);
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (formula.size() > 0)
8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkDebugf("formula=\"%s\" ", formula.c_str());
8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    else {
8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (from.size() > 0)
9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            SkDebugf("from=\"%s\" ", from.c_str());
9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkDebugf("to=\"%s\" ", to.c_str());
9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (begin != 0) {
9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkDebugf("begin=\"%g\" ", SkScalarToFloat(SkScalarDiv(begin,1000)));
9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkDisplayable* SkAnimateBase::getParent() const {
10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return (SkDisplayable*) fApply;
10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimateBase::getProperty(int index, SkScriptValue* value) const {
10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    int boolResult;
10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    switch (index) {
10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case SK_PROPERTY(dynamic):
10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            boolResult = fDynamic;
10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            goto returnBool;
10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case SK_PROPERTY(mirror):
11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            boolResult = fMirror;
11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            goto returnBool;
11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case SK_PROPERTY(reset):
11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            boolResult = fReset;
11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QuerureturnBool:
11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            value->fOperand.fS32 = SkToBool(boolResult);
11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            value->fType = SkType_Boolean;
11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            break;
11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case SK_PROPERTY(step):
11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (fApply == NULL)
12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                return false;    // !!! notify there's an error?
12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            fApply->getStep(value);
12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            break;
12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case SK_PROPERTY(values):
12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            value->fOperand.fString = (SkString*) &to;
12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            value->fType = SkType_String;
12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            break;
12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        default:
12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            SkASSERT(0);
12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return false;
13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return true;
13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimateBase::hasExecute() const
13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return false;
13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimateBase::onEndElement(SkAnimateMaker& maker) {
14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    fChanged = false;
14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    setTarget(maker);
14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (field.size()) {
14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkASSERT(fTarget);
14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFieldInfo = fTarget->getMember(field.c_str());
14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        field.reset();
14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (lval.size()) {
14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        // lval must be of the form x[y]
14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const char* lvalStr = lval.c_str();
15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const char* arrayEnd = strchr(lvalStr, '[');
15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (arrayEnd == NULL)
15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return; //should this return an error?
15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        size_t arrayNameLen = arrayEnd - lvalStr;
15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkString arrayStr(lvalStr, arrayNameLen);
15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkASSERT(fTarget);  //this return an error?
15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFieldInfo = fTarget->getMember(arrayStr.c_str());
15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkString scriptStr(arrayEnd + 1, lval.size() - arrayNameLen - 2);
15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkAnimatorScript::EvaluateInt(maker, this, scriptStr.c_str(), &fFieldOffset);
15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimateBase::packARGB(SkScalar array[], int count, SkTDOperandArray* converted)
16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(count == 4);
16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    converted->setCount(1);
16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkColor color = SkColorSetARGB(SkScalarRound(array[0]), SkScalarRound(array[1]),
16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkScalarRound(array[2]), SkScalarRound(array[3]));
16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    (*converted)[0].fS32 = color;
16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimateBase::refresh(SkAnimateMaker& ) {
17480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
17580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimateBase::setParent(SkDisplayable* apply) {
17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(apply->isApply());
17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    fApply = (SkApply*) apply;
17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return false;
18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimateBase::setProperty(int index, SkScriptValue& value) {
18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool boolValue = SkToBool(value.fOperand.fS32);
18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    switch (index) {
18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case SK_PROPERTY(dynamic):
18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            fDynamic = boolValue;
18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            goto checkForBool;
18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case SK_PROPERTY(values):
18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            fHasValues = true;
19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            SkASSERT(value.fType == SkType_String);
19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            to = *value.fOperand.fString;
19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            break;
19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case SK_PROPERTY(mirror):
19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            fMirror = boolValue;
19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            goto checkForBool;
19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case SK_PROPERTY(reset):
19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            fReset = boolValue;
19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QuerucheckForBool:
19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            SkASSERT(value.fType == SkType_Boolean);
20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            break;
20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        default:
20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return false;
20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return true;
20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimateBase::setTarget(SkAnimateMaker& maker) {
20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (target.size()) {
20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkAnimatorScript engine(maker, this, SkType_Displayable);
21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        const char* script = target.c_str();
21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkScriptValue scriptValue;
21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        bool success = engine.evaluateScript(&script, &scriptValue);
21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (success && scriptValue.fType == SkType_Displayable)
21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            fTarget = scriptValue.fOperand.fDrawable;
21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        else if (maker.find(target.c_str(), (SkDisplayable**) &fTarget) == false) {
21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (fApply->getMode() == SkApply::kMode_create)
21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                return; // may not be an error
21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (engine.getError() != SkScriptEngine::kNoError)
21980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                maker.setScriptError(engine);
22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            else {
22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                maker.setErrorNoun(target);
22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                maker.setErrorCode(SkDisplayXMLParserError::kTargetIDNotFound);
22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
22480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return;
22580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
22680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (fApply && fApply->getMode() != SkApply::kMode_create)
22780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            target.reset();
22880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
22980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
23080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
23180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimateBase::targetNeedsInitialization() const {
23280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return false;
23380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
234