void SkActive::initState(SkApply* apply, int offset) { int count = fState.count(); for (int index = offset; index < count; index++) { SkState& state = fState[index]; SkAnimateBase* animate = fAnimators[index]; #if 0 // def SK_DEBUG if (animate->fHasEndEvent) SkDebugf("%8x %8x active initState:\n", this, animate); #endif SkOperand* from = animate->getValues(); state.fStartTime = state.fBegin = apply->begin + animate->begin; state.fMode = apply->mode; state.fTransition = apply->transition; #if 0 state.fPickup = (SkBool8) apply->pickup; #endif state.fRestore = (SkBool8) apply->restore; state.fSave = apply->begin; state.fStarted = false; state.fSteps = apply->steps; state.fTicks = 0; state.fUnpostedEndEvent = (SkBool8) animate->fHasEndEvent; calcDurations(index); setInterpolator(index, from); } if (count == 0 && (apply->mode == SkApply::kMode_immediate || apply->mode == SkApply::kMode_create)) fMaxTime = apply->begin + apply->steps * SK_MSec1; }
void SkActive::pickUp(SkActive* existing) { SkTDOperandArray existingValues; for (int index = 0; index < fAnimators.count(); index++) { SkAnimateBase* animate = fAnimators[index]; SkASSERT(animate->getValuesType() == SkType_Float); int components = animate->components(); SkOperand* from = animate->getValues(); SkOperand* to = &from[animate->components()]; existingValues.setCount(components); existing->fInterpolators[index]->timeToValues( existing->fState[index].fTicks - existing->fState[index].fStartTime, existingValues.begin()); SkScalar originalSum = 0; SkScalar workingSum = 0; for (int cIndex = 0; cIndex < components; cIndex++) { SkScalar delta = to[cIndex].fScalar - from[cIndex].fScalar; originalSum += SkScalarMul(delta, delta); delta = to[cIndex].fScalar - existingValues[cIndex].fScalar; workingSum += SkScalarMul(delta, delta); } if (workingSum < originalSum) { SkScalar originalDistance = SkScalarSqrt(originalSum); SkScalar workingDistance = SkScalarSqrt(workingSum); existing->fState[index].fDuration = (SkMSec) SkScalarMulDiv(fState[index].fDuration, workingDistance, originalDistance); } fInterpolators[index]->reset(components, 2, SkType_Float); fInterpolators[index]->setKeyFrame(0, 0, existingValues.begin(), animate->blend[0]); fInterpolators[index]->setKeyFrame(1, fState[index].fDuration, to, animate->blend[0]); } }
void SkActive::resetInterpolators() { int animators = fAnimators.count(); for (int index = 0; index < animators; index++) { SkAnimateBase* animate = fAnimators[index]; SkOperand* values = animate->getValues(); setInterpolator(index, values); } }
void SkActive::fixInterpolator(SkBool save) { int animators = fAnimators.count(); for (int index = 0; index < animators; index++) { SkAnimateBase* animate = fAnimators[index]; if (save) { // saved slots increased animate->refresh(fMaker); SkOperand* values = animate->getValues(); setInterpolator(index, values); saveInterpolatorValues(index); } else restoreInterpolatorValues(index); } }