void SkApply::onEndElement(SkAnimateMaker& maker) { SkDrawable* scopePtr = scope; while (scopePtr && scopePtr->isApply()) { SkApply* scopedApply = (SkApply*) scopePtr; if (scopedApply->scope == this) { maker.setErrorCode(SkDisplayXMLParserError::kApplyScopesItself); return; } scopePtr = scopedApply->scope; } if (mode == kMode_create) return; if (scope != NULL && steps >= 0 && scope->isApply() == false && scope->isDrawable()) scope->setSteps(steps); for (SkAnimateBase** animPtr = fAnimators.begin(); animPtr < fAnimators.end(); animPtr++) { SkAnimateBase* anim = *animPtr; //for reusing apply statements with dynamic scope if (anim->fTarget == NULL || anim->fTargetIsScope) { anim->fTargetIsScope = true; if (scope) anim->fTarget = scope; else anim->setTarget(maker); anim->onEndElement(maker); // allows animate->fFieldInfo to be set } if (scope != NULL && steps >= 0 && anim->fTarget != scope && anim->fTarget->isDrawable()) anim->fTarget->setSteps(steps); } }
void SkApply::enableCreate(SkAnimateMaker& maker) { SkString newID; for (int step = 0; step <= steps; step++) { fLastTime = step * SK_MSec1; bool success = maker.computeID(scope, this, &newID); if (success == false) return; if (maker.find(newID.c_str(), NULL)) continue; SkApply* copy = (SkApply*) deepCopy(&maker); // work on copy of animator state if (mode == kMode_create) copy->mode = (Mode) -1; SkDrawable* copyScope = copy->scope = (SkDrawable*) scope->deepCopy(&maker); *fScopes.append() = copyScope; if (copyScope->resolveIDs(maker, scope, this)) { step = steps; // quit goto next; // resolveIDs failed } if (newID.size() > 0) maker.setID(copyScope, newID); if (copy->resolveIDs(maker, this, this)) { // fix up all fields, including target step = steps; // quit goto next; // resolveIDs failed } copy->activate(maker); copy->interpolate(maker, step * SK_MSec1); maker.removeActive(copy->fActive); next: delete copy; } }
int SkDisplayList::SearchForMatch(SkDrawable* match, SkTDDrawableArray** list, SkGroup** parent, SkGroup** found, SkTDDrawableArray**grandList) { *found = NULL; for (int index = 0; index < (*list)->count(); index++) { SkDrawable* draw = (**list)[index]; if (draw == match) return index; if (draw->isApply()) { SkApply* apply = (SkApply*) draw; if (apply->scope == match) return index; if (apply->scope->isGroup() && SearchGroupForMatch(apply->scope, match, list, parent, found, grandList, index)) return index; if (apply->mode == SkApply::kMode_create) { for (SkDrawable** ptr = apply->fScopes.begin(); ptr < apply->fScopes.end(); ptr++) { SkDrawable* scope = *ptr; if (scope == match) return index; //perhaps should call SearchGroupForMatch here as well (on scope) } } } if (draw->isGroup() && SearchGroupForMatch(draw, match, list, parent, found, grandList, index)) return index; } return -1; }
void SkGroup::initialize() { for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { SkDrawable* drawable = *ptr; if (drawable->isDrawable() == false) continue; drawable->initialize(); } }
void SkGroup::setSteps(int steps) { for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { SkDrawable* drawable = *ptr; if (drawable->isDrawable() == false) continue; drawable->setSteps(steps); } }
bool SkGroup::contains(SkDisplayable* match) { for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { SkDrawable* drawable = *ptr; if (drawable == match || drawable->contains(match)) return true; } return false; }
void SkDisplayList::reset() { for (int index = 0; index < fDrawList.count(); index++) { SkDrawable* draw = fDrawList[index]; if (draw->isApply() == false) continue; SkApply* apply = (SkApply*) draw; apply->reset(); } }
bool SkGroup::enable(SkAnimateMaker& maker ) { reset(); for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { SkDrawable* drawable = *ptr; if (ifCondition(maker, drawable, enableCondition) == false) continue; drawable->enable(maker); } return true; // skip add; already added so that scope is findable by children }
JSBool SkJSDisplayable::Draw(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { SkJSDisplayable *p = (SkJSDisplayable*) JS_GetPrivate(cx, obj); SkASSERT(p->fDisplayable->isDrawable()); SkDrawable* drawable = (SkDrawable*) p->fDisplayable; SkAnimateMaker maker(NULL, gCanvas, gPaint); drawable->draw(maker); return JS_TRUE; }
bool SkGroup::doEvent(SkDisplayEvent::Kind kind, SkEventState* state) { bool handled = false; for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { SkDrawable* drawable = *ptr; if (drawable->isDrawable() == false) continue; handled |= drawable->doEvent(kind, state); } return handled; }
bool SkGroup::resolveIDs(SkAnimateMaker& maker, SkDisplayable* orig, SkApply* apply) { SkGroup* original = (SkGroup*) orig; SkTDDrawableArray& originalChildren = original->fChildren; SkDrawable** originalPtr = originalChildren.begin(); SkDrawable** ptr = fChildren.begin(); SkDrawable** end = fChildren.end(); SkDrawable** origChild = ((SkGroup*) orig)->fChildren.begin(); while (ptr < end) { SkDrawable* drawable = *ptr++; maker.resolveID(drawable, *origChild++); if (drawable->resolveIDs(maker, *originalPtr++, apply) == true) return true; // failed } return false; }
bool SkGroup::draw(SkAnimateMaker& maker) { bool conditionTrue = ifCondition(maker, this, condition); bool result = false; for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { SkDrawable* drawable = *ptr; if (drawable->isDrawable() == false) continue; if (conditionTrue == false) { if (drawable->isApply()) ((SkApply*) drawable)->disable(); continue; } maker.validate(); result |= drawable->draw(maker); maker.validate(); } return result; }
int SkGroup::findGroup(SkDrawable* match, SkTDDrawableArray** list, SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandList) { *list = &fChildren; for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { SkDrawable* drawable = *ptr; if (drawable->isGroup()) { SkGroup* childGroup = (SkGroup*) drawable; if (childGroup->fOriginal == match) goto foundMatch; } if (drawable == match) { foundMatch: *parent = this; return (int) (ptr - fChildren.begin()); } } *grandList = &fChildren; return SkDisplayList::SearchForMatch(match, list, parent, found, grandList); }
bool SkActive::immediate(bool enable) { SkMSec time = 0; bool result = false; SkDrawable* drawable = fApply.scope; SkMSec final = fMaxTime; do { bool applied = fAnimators.count() == 0; fApply.fLastTime = time; fApply.refresh(fMaker); for (int index = 0; index < fAnimators.count(); index++) { SkAnimateBase* animate = fAnimators[index]; SkState& state = fState[index]; if (state.fMode != SkApply::kMode_immediate) continue; if (state.fBegin > time) continue; if (time > state.fBegin + state.fDuration) continue; applied = true; SkOperandInterpolator& interpolator = *fInterpolators[index]; int count = animate->components(); if (animate->formula.size() > 0) { SkTDOperandArray values; values.setCount(count); bool success = animate->fFieldInfo->setValue(fMaker, &values, 0, 0, NULL, animate->getValuesType(), animate->formula); SkASSERT(success); fApply.applyValues(index, values.begin(), count, animate->getValuesType(), time); } else { SkAutoSTMalloc<16, SkOperand> values(count); interpolator.timeToValues(time, values.get()); fApply.applyValues(index, values.get(), count, animate->getValuesType(), time); } } if (enable) drawable->enable(fMaker); else if (applied) result |= drawable->draw(fMaker); time += SK_MSec1; } while (time <= final); return result; }
DEF_TEST(FlattenDrawable, r) { // Create and serialize the test drawable sk_sp<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4)); SkPaint paint; paint.setColor(SK_ColorBLUE); sk_sp<RootDrawable> root(new RootDrawable(5, 6, 7, 8, paint, 9, 10, 11, 12, drawable.get())); SkBinaryWriteBuffer writeBuffer; writeBuffer.writeFlattenable(root.get()); // Copy the contents of the write buffer into a read buffer sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten()); writeBuffer.writeToMemory(data->writable_data()); SkReadBuffer readBuffer(data->data(), data->size()); register_test_drawables(readBuffer); // Deserialize and verify the drawable sk_sp<SkDrawable> out((SkDrawable*)readBuffer.readFlattenable(SkFlattenable::kSkDrawable_Type)); REPORTER_ASSERT(r, out); REPORTER_ASSERT(r, !strcmp("RootDrawable", out->getTypeName())); RootDrawable* rootOut = (RootDrawable*) out.get(); REPORTER_ASSERT(r, 5 == rootOut->compoundDrawable()->intDrawable()->a()); REPORTER_ASSERT(r, 6 == rootOut->compoundDrawable()->intDrawable()->b()); REPORTER_ASSERT(r, 7 == rootOut->compoundDrawable()->intDrawable()->c()); REPORTER_ASSERT(r, 8 == rootOut->compoundDrawable()->intDrawable()->d()); REPORTER_ASSERT(r, SK_ColorBLUE == rootOut->compoundDrawable()->paintDrawable()->paint().getColor()); REPORTER_ASSERT(r, 9 == rootOut->intDrawable()->a()); REPORTER_ASSERT(r, 10 == rootOut->intDrawable()->b()); REPORTER_ASSERT(r, 11 == rootOut->intDrawable()->c()); REPORTER_ASSERT(r, 12 == rootOut->intDrawable()->d()); // Note that we can still recognize the generic drawable as an IntDrawable SkDrawable* generic = rootOut->drawable(); REPORTER_ASSERT(r, !strcmp("IntDrawable", generic->getTypeName())); IntDrawable* integer = (IntDrawable*) generic; REPORTER_ASSERT(r, 1 == integer->a()); REPORTER_ASSERT(r, 2 == integer->b()); REPORTER_ASSERT(r, 3 == integer->c()); REPORTER_ASSERT(r, 4 == integer->d()); }
void SkGroup::dumpDrawables(SkAnimateMaker* maker) { SkDisplayList::fIndent += 4; int save = SkDisplayList::fDumpIndex; SkDisplayList::fDumpIndex = 0; bool closedYet = false; for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { if (closedYet == false) { closedYet = true; SkDebugf(">\n"); } SkDrawable* drawable = *ptr; drawable->dump(maker); SkDisplayList::fDumpIndex++; } SkDisplayList::fIndent -= 4; SkDisplayList::fDumpIndex = save; if (closedYet) //we had children, now it's time to close the group dumpEnd(maker); else //no children SkDebugf("/>\n"); }
bool SkDisplayList::draw(SkAnimateMaker& maker, SkMSec inTime) { validate(); fInTime = inTime; bool result = false; fInvalBounds.setEmpty(); if (fDrawList.count()) { for (SkActive** activePtr = fActiveList.begin(); activePtr < fActiveList.end(); activePtr++) { SkActive* active = *activePtr; active->reset(); } for (int index = 0; index < fDrawList.count(); index++) { SkDrawable* draw = fDrawList[index]; draw->initialize(); // allow matrices to reset themselves SkASSERT(draw->isDrawable()); validate(); result |= draw->draw(maker); } } validate(); return result; }
void SkDisplayList::validate() { for (int index = 0; index < fDrawList.count(); index++) { SkDrawable* draw = fDrawList[index]; draw->validate(); } }
void SkGroup::validate() { for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { SkDrawable* drawable = *ptr; drawable->validate(); } }
void SkGroup::dumpEvents() { for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { SkDrawable* drawable = *ptr; drawable->dumpEvents(); } }