| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkDisplayApply.h" | 10 #include "SkDisplayApply.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 DEFINE_GET_MEMBER(SkApply); | 56 DEFINE_GET_MEMBER(SkApply); |
| 57 | 57 |
| 58 SkApply::SkApply() : begin(0), dontDraw(false), interval((SkMSec) -1), mode((Mod
e) -1), /*pickup(false), */ | 58 SkApply::SkApply() : begin(0), dontDraw(false), interval((SkMSec) -1), mode((Mod
e) -1), /*pickup(false), */ |
| 59 restore(false), scope(NULL), steps(-1), transition((Transition) -1), fActive
(NULL), /*fCurrentScope(NULL),*/ | 59 restore(false), scope(NULL), steps(-1), transition((Transition) -1), fActive
(NULL), /*fCurrentScope(NULL),*/ |
| 60 fLastTime(0), fAppended(false), fContainsScope(false), fDeleteScope(false),
fEmbedded(false), | 60 fLastTime(0), fAppended(false), fContainsScope(false), fDeleteScope(false),
fEmbedded(false), |
| 61 fEnabled(false), fEnabling(false) { | 61 fEnabled(false), fEnabling(false) { |
| 62 } | 62 } |
| 63 | 63 |
| 64 SkApply::~SkApply() { | 64 SkApply::~SkApply() { |
| 65 for (SkDrawable** curPtr = fScopes.begin(); curPtr < fScopes.end(); curPtr++
) | 65 for (SkADrawable** curPtr = fScopes.begin(); curPtr < fScopes.end(); curPtr+
+) |
| 66 delete *curPtr; | 66 delete *curPtr; |
| 67 if (fDeleteScope) | 67 if (fDeleteScope) |
| 68 delete scope; | 68 delete scope; |
| 69 // !!! caller must call maker.removeActive(fActive) | 69 // !!! caller must call maker.removeActive(fActive) |
| 70 delete fActive; | 70 delete fActive; |
| 71 } | 71 } |
| 72 | 72 |
| 73 void SkApply::activate(SkAnimateMaker& maker) { | 73 void SkApply::activate(SkAnimateMaker& maker) { |
| 74 if (fActive != NULL) { | 74 if (fActive != NULL) { |
| 75 if (fActive->fDrawIndex == 0 && fActive->fDrawMax == 0) | 75 if (fActive->fDrawIndex == 0 && fActive->fDrawMax == 0) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 if (type == SkType_String || type == SkType_DynamicString) | 146 if (type == SkType_String || type == SkType_DynamicString) |
| 147 info->setString(target, values->fString); | 147 info->setString(target, values->fString); |
| 148 else if (type == SkType_Drawable || type == SkType_Displayable) | 148 else if (type == SkType_Drawable || type == SkType_Displayable) |
| 149 target->setReference(info, values->fDisplayable); | 149 target->setReference(info, values->fDisplayable); |
| 150 else | 150 else |
| 151 info->setValue(target, values, count); | 151 info->setValue(target, values, count); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool SkApply::contains(SkDisplayable* child) { | 155 bool SkApply::contains(SkDisplayable* child) { |
| 156 for (SkDrawable** curPtr = fScopes.begin(); curPtr < fScopes.end(); curPtr++
) { | 156 for (SkADrawable** curPtr = fScopes.begin(); curPtr < fScopes.end(); curPtr+
+) { |
| 157 if (*curPtr == child || (*curPtr)->contains(child)) | 157 if (*curPtr == child || (*curPtr)->contains(child)) |
| 158 return true; | 158 return true; |
| 159 } | 159 } |
| 160 return fDeleteScope && scope == child; | 160 return fDeleteScope && scope == child; |
| 161 } | 161 } |
| 162 | 162 |
| 163 SkDisplayable* SkApply::deepCopy(SkAnimateMaker* maker) { | 163 SkDisplayable* SkApply::deepCopy(SkAnimateMaker* maker) { |
| 164 SkDrawable* saveScope = scope; | 164 SkADrawable* saveScope = scope; |
| 165 scope = NULL; | 165 scope = NULL; |
| 166 SkApply* result = (SkApply*) INHERITED::deepCopy(maker); | 166 SkApply* result = (SkApply*) INHERITED::deepCopy(maker); |
| 167 result->scope = scope = saveScope; | 167 result->scope = scope = saveScope; |
| 168 SkAnimateBase** end = fAnimators.end(); | 168 SkAnimateBase** end = fAnimators.end(); |
| 169 for (SkAnimateBase** animPtr = fAnimators.begin(); animPtr < end; animPtr++)
{ | 169 for (SkAnimateBase** animPtr = fAnimators.begin(); animPtr < end; animPtr++)
{ |
| 170 SkAnimateBase* anim = (SkAnimateBase*) (*animPtr)->deepCopy(maker); | 170 SkAnimateBase* anim = (SkAnimateBase*) (*animPtr)->deepCopy(maker); |
| 171 *result->fAnimators.append() = anim; | 171 *result->fAnimators.append() = anim; |
| 172 maker->helperAdd(anim); | 172 maker->helperAdd(anim); |
| 173 } | 173 } |
| 174 return result; | 174 return result; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 fActive->enable(); | 293 fActive->enable(); |
| 294 if (mode == kMode_create && scope != NULL) { | 294 if (mode == kMode_create && scope != NULL) { |
| 295 enableCreate(maker); | 295 enableCreate(maker); |
| 296 return true; | 296 return true; |
| 297 } | 297 } |
| 298 if (mode == kMode_immediate) { | 298 if (mode == kMode_immediate) { |
| 299 return scope->isApply() || scope->isDrawable() == false; | 299 return scope->isApply() || scope->isDrawable() == false; |
| 300 } | 300 } |
| 301 refresh(maker); | 301 refresh(maker); |
| 302 SkDisplayList& displayList = maker.fDisplayList; | 302 SkDisplayList& displayList = maker.fDisplayList; |
| 303 SkDrawable* drawable; | 303 SkADrawable* drawable; |
| 304 #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING | 304 #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING |
| 305 SkString debugOut; | 305 SkString debugOut; |
| 306 SkMSec time = maker.getAppTime(); | 306 SkMSec time = maker.getAppTime(); |
| 307 debugOut.appendS32(time - maker.fDebugTimeBase); | 307 debugOut.appendS32(time - maker.fDebugTimeBase); |
| 308 debugOut.append(" apply enable id="); | 308 debugOut.append(" apply enable id="); |
| 309 debugOut.append(_id); | 309 debugOut.append(_id); |
| 310 debugOut.append("; start="); | 310 debugOut.append("; start="); |
| 311 debugOut.appendS32(maker.fEnableTime - maker.fDebugTimeBase); | 311 debugOut.appendS32(maker.fEnableTime - maker.fDebugTimeBase); |
| 312 SkDebugf("%s\n", debugOut.c_str()); | 312 SkDebugf("%s\n", debugOut.c_str()); |
| 313 #endif | 313 #endif |
| (...skipping 19 matching lines...) Expand all Loading... |
| 333 } | 333 } |
| 334 #endif | 334 #endif |
| 335 // start here; | 335 // start here; |
| 336 // now that one apply might embed another, only the parent apply should repl
ace the scope | 336 // now that one apply might embed another, only the parent apply should repl
ace the scope |
| 337 // or get appended to the display list | 337 // or get appended to the display list |
| 338 // similarly, an apply added by an add immediate has already been located in
the display list | 338 // similarly, an apply added by an add immediate has already been located in
the display list |
| 339 // and should not get moved or added again here | 339 // and should not get moved or added again here |
| 340 if (fEmbedded) { | 340 if (fEmbedded) { |
| 341 return false; // already added to display list by embedder | 341 return false; // already added to display list by embedder |
| 342 } | 342 } |
| 343 drawable = (SkDrawable*) scope; | 343 drawable = (SkADrawable*) scope; |
| 344 SkTDDrawableArray* parentList; | 344 SkTDDrawableArray* parentList; |
| 345 SkTDDrawableArray* grandList; | 345 SkTDDrawableArray* grandList; |
| 346 SkGroup* parentGroup; | 346 SkGroup* parentGroup; |
| 347 SkGroup* thisGroup; | 347 SkGroup* thisGroup; |
| 348 int old = displayList.findGroup(drawable, &parentList, &parentGroup, &thisGr
oup, &grandList); | 348 int old = displayList.findGroup(drawable, &parentList, &parentGroup, &thisGr
oup, &grandList); |
| 349 if (old < 0) | 349 if (old < 0) |
| 350 goto append; | 350 goto append; |
| 351 else if (fContainsScope) { | 351 else if (fContainsScope) { |
| 352 if ((*parentList)[old] != this || restore) { | 352 if ((*parentList)[old] != this || restore) { |
| 353 append: | 353 append: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 365 SkASSERT(old < parentList->count()); | 365 SkASSERT(old < parentList->count()); |
| 366 if ((*parentList)[old]->isApply()) { | 366 if ((*parentList)[old]->isApply()) { |
| 367 SkApply* apply = (SkApply*) (*parentList)[old]; | 367 SkApply* apply = (SkApply*) (*parentList)[old]; |
| 368 if (apply != this && apply->fActive == NULL) | 368 if (apply != this && apply->fActive == NULL) |
| 369 apply->activate(maker); | 369 apply->activate(maker); |
| 370 apply->append(this); | 370 apply->append(this); |
| 371 parentGroup = NULL; | 371 parentGroup = NULL; |
| 372 } else { | 372 } else { |
| 373 if (parentGroup) | 373 if (parentGroup) |
| 374 parentGroup->markCopySize(old); | 374 parentGroup->markCopySize(old); |
| 375 SkDrawable** newApplyLocation = &(*parentList)[old]; | 375 SkADrawable** newApplyLocation = &(*parentList)[old]; |
| 376 SkGroup* pGroup; | 376 SkGroup* pGroup; |
| 377 int oldApply = displayList.findGroup(this, &parentList, &pGroup, &th
isGroup, &grandList); | 377 int oldApply = displayList.findGroup(this, &parentList, &pGroup, &th
isGroup, &grandList); |
| 378 if (oldApply >= 0) { | 378 if (oldApply >= 0) { |
| 379 (*parentList)[oldApply] = (SkDrawable*) SkDisplayType::CreateIns
tance(&maker, SkType_Apply); | 379 (*parentList)[oldApply] = (SkADrawable*) SkDisplayType::CreateIn
stance(&maker, SkType_Apply); |
| 380 parentGroup = NULL; | 380 parentGroup = NULL; |
| 381 fDeleteScope = true; | 381 fDeleteScope = true; |
| 382 } | 382 } |
| 383 *newApplyLocation = this; | 383 *newApplyLocation = this; |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 if (parentGroup) { | 386 if (parentGroup) { |
| 387 parentGroup->markCopySet(old); | 387 parentGroup->markCopySet(old); |
| 388 fDeleteScope = dynamicScope.size() == 0; | 388 fDeleteScope = dynamicScope.size() == 0; |
| 389 } | 389 } |
| 390 return true; | 390 return true; |
| 391 } | 391 } |
| 392 | 392 |
| 393 void SkApply::enableCreate(SkAnimateMaker& maker) { | 393 void SkApply::enableCreate(SkAnimateMaker& maker) { |
| 394 SkString newID; | 394 SkString newID; |
| 395 for (int step = 0; step <= steps; step++) { | 395 for (int step = 0; step <= steps; step++) { |
| 396 fLastTime = step * SK_MSec1; | 396 fLastTime = step * SK_MSec1; |
| 397 bool success = maker.computeID(scope, this, &newID); | 397 bool success = maker.computeID(scope, this, &newID); |
| 398 if (success == false) | 398 if (success == false) |
| 399 return; | 399 return; |
| 400 if (maker.find(newID.c_str(), NULL)) | 400 if (maker.find(newID.c_str(), NULL)) |
| 401 continue; | 401 continue; |
| 402 SkApply* copy = (SkApply*) deepCopy(&maker); // work on copy of animator
state | 402 SkApply* copy = (SkApply*) deepCopy(&maker); // work on copy of animator
state |
| 403 if (mode == kMode_create) | 403 if (mode == kMode_create) |
| 404 copy->mode = (Mode) -1; | 404 copy->mode = (Mode) -1; |
| 405 SkDrawable* copyScope = copy->scope = (SkDrawable*) scope->deepCopy(&mak
er); | 405 SkADrawable* copyScope = copy->scope = (SkADrawable*) scope->deepCopy(&m
aker); |
| 406 *fScopes.append() = copyScope; | 406 *fScopes.append() = copyScope; |
| 407 if (copyScope->resolveIDs(maker, scope, this)) { | 407 if (copyScope->resolveIDs(maker, scope, this)) { |
| 408 step = steps; // quit | 408 step = steps; // quit |
| 409 goto next; // resolveIDs failed | 409 goto next; // resolveIDs failed |
| 410 } | 410 } |
| 411 if (newID.size() > 0) | 411 if (newID.size() > 0) |
| 412 maker.setID(copyScope, newID); | 412 maker.setID(copyScope, newID); |
| 413 if (copy->resolveIDs(maker, this, this)) { // fix up all fields, includi
ng target | 413 if (copy->resolveIDs(maker, this, this)) { // fix up all fields, includi
ng target |
| 414 step = steps; // quit | 414 step = steps; // quit |
| 415 goto next; // resolveIDs failed | 415 goto next; // resolveIDs failed |
| (...skipping 21 matching lines...) Expand all Loading... |
| 437 SkDisplayable* oldChild = (*pList)[old]; | 437 SkDisplayable* oldChild = (*pList)[old]; |
| 438 if (oldChild->isApply() && found->copySet(old)) { | 438 if (oldChild->isApply() && found->copySet(old)) { |
| 439 found->markCopyClear(old); | 439 found->markCopyClear(old); |
| 440 // delete oldChild; | 440 // delete oldChild; |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 (*pList)[old] = scope; | 443 (*pList)[old] = scope; |
| 444 } else | 444 } else |
| 445 pList->remove(old); | 445 pList->remove(old); |
| 446 } | 446 } |
| 447 scope = (SkDrawable*) newScope; | 447 scope = (SkADrawable*) newScope; |
| 448 onEndElement(maker); | 448 onEndElement(maker); |
| 449 } | 449 } |
| 450 maker.removeActive(fActive); | 450 maker.removeActive(fActive); |
| 451 delete fActive; | 451 delete fActive; |
| 452 fActive = NULL; | 452 fActive = NULL; |
| 453 } | 453 } |
| 454 | 454 |
| 455 void SkApply::endSave(int index) { | 455 void SkApply::endSave(int index) { |
| 456 SkAnimateBase* animate = fActive->fAnimators[index]; | 456 SkAnimateBase* animate = fActive->fAnimators[index]; |
| 457 const SkMemberInfo* info = animate->fFieldInfo; | 457 const SkMemberInfo* info = animate->fFieldInfo; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 // SkASSERT(0); | 500 // SkASSERT(0); |
| 501 return false; | 501 return false; |
| 502 } | 502 } |
| 503 return true; | 503 return true; |
| 504 } | 504 } |
| 505 | 505 |
| 506 void SkApply::getStep(SkScriptValue* value) { | 506 void SkApply::getStep(SkScriptValue* value) { |
| 507 getProperty(SK_PROPERTY(step), value); | 507 getProperty(SK_PROPERTY(step), value); |
| 508 } | 508 } |
| 509 | 509 |
| 510 SkDrawable* SkApply::getTarget(SkAnimateBase* animate) { | 510 SkADrawable* SkApply::getTarget(SkAnimateBase* animate) { |
| 511 if (animate->fTargetIsScope == false || mode != kMode_create) | 511 if (animate->fTargetIsScope == false || mode != kMode_create) |
| 512 return animate->fTarget; | 512 return animate->fTarget; |
| 513 return scope; | 513 return scope; |
| 514 } | 514 } |
| 515 | 515 |
| 516 bool SkApply::hasDelayedAnimator() const { | 516 bool SkApply::hasDelayedAnimator() const { |
| 517 SkAnimateBase* const* animEnd = fAnimators.end(); | 517 SkAnimateBase* const* animEnd = fAnimators.end(); |
| 518 for (SkAnimateBase* const* animPtr = fAnimators.begin(); animPtr < animEnd;
animPtr++) { | 518 for (SkAnimateBase* const* animPtr = fAnimators.begin(); animPtr < animEnd;
animPtr++) { |
| 519 SkAnimateBase* const animator = *animPtr; | 519 SkAnimateBase* const animator = *animPtr; |
| 520 if (animator->fDelayed) | 520 if (animator->fDelayed) |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 void SkApply::initialize() { | 647 void SkApply::initialize() { |
| 648 if (scope == NULL) | 648 if (scope == NULL) |
| 649 return; | 649 return; |
| 650 if (scope->isApply() || scope->isDrawable() == false) | 650 if (scope->isApply() || scope->isDrawable() == false) |
| 651 return; | 651 return; |
| 652 scope->initialize(); | 652 scope->initialize(); |
| 653 } | 653 } |
| 654 | 654 |
| 655 void SkApply::onEndElement(SkAnimateMaker& maker) | 655 void SkApply::onEndElement(SkAnimateMaker& maker) |
| 656 { | 656 { |
| 657 SkDrawable* scopePtr = scope; | 657 SkADrawable* scopePtr = scope; |
| 658 while (scopePtr && scopePtr->isApply()) { | 658 while (scopePtr && scopePtr->isApply()) { |
| 659 SkApply* scopedApply = (SkApply*) scopePtr; | 659 SkApply* scopedApply = (SkApply*) scopePtr; |
| 660 if (scopedApply->scope == this) { | 660 if (scopedApply->scope == this) { |
| 661 maker.setErrorCode(SkDisplayXMLParserError::kApplyScopesItself); | 661 maker.setErrorCode(SkDisplayXMLParserError::kApplyScopesItself); |
| 662 return; | 662 return; |
| 663 } | 663 } |
| 664 scopePtr = scopedApply->scope; | 664 scopePtr = scopedApply->scope; |
| 665 } | 665 } |
| 666 if (mode == kMode_create) | 666 if (mode == kMode_create) |
| 667 return; | 667 return; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 void SkApply::setSteps(int _steps) { | 795 void SkApply::setSteps(int _steps) { |
| 796 steps = _steps; | 796 steps = _steps; |
| 797 } | 797 } |
| 798 | 798 |
| 799 #ifdef SK_DEBUG | 799 #ifdef SK_DEBUG |
| 800 void SkApply::validate() { | 800 void SkApply::validate() { |
| 801 if (fActive) | 801 if (fActive) |
| 802 fActive->validate(); | 802 fActive->validate(); |
| 803 } | 803 } |
| 804 #endif | 804 #endif |
| OLD | NEW |