1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkAnimator.h" 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkAnimateMaker.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h" 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDisplayApply.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDisplayMovie.h" 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDisplayTypes.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDisplayXMLParser.h" 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkStream.h" 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScript.h" 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScript2.h" // compiled script experiment 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkSystemEventTypes.h" 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypedArray.h" 22fa394d491b6e625159f83787619fcb852d245471djsollen@google.com#ifdef SK_BUILD_FOR_ANDROID 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDrawExtraPathEffect.h" 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTime.h" 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if defined SK_BUILD_FOR_WIN32 && defined SK_DEBUG 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #define _static 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com extern const char gMathPrimerText[]; 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com extern const char gMathPrimerBinary[]; 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#else 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #define _static static 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 37d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com_static const char gMathPrimerText[] = 38ec10d21eb9a17639688188b0defce6d757331eb4reed@android.com"<screenplay>" 39ec10d21eb9a17639688188b0defce6d757331eb4reed@android.com "<Math id=\"Math\"/>" 40ec10d21eb9a17639688188b0defce6d757331eb4reed@android.com "<Number id=\"Number\"/>" 41ec10d21eb9a17639688188b0defce6d757331eb4reed@android.com"</screenplay>"; 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 43ec10d21eb9a17639688188b0defce6d757331eb4reed@android.com#define gMathPrimer gMathPrimerText 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkAnimator::SkAnimator() : fMaker(NULL) { 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com initialize(); 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkAnimator::~SkAnimator() { 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDELETE(fMaker); 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::addExtras(SkExtras* extras) { 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *fMaker->fExtras.append() = extras; 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::appendStream(SkStream* stream) { 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return decodeStream(stream); 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::decodeMemory(const void* buffer, size_t size) 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fFileName.reset(); 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayXMLParser parser(*fMaker); 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return parser.parse((const char*)buffer, size); 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::decodeStream(SkStream* stream) 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayXMLParser parser(*fMaker); 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool result = parser.parse(*stream); 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->setErrorString(); 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return result; 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::decodeDOM(const SkDOM& dom, const SkDOMNode* node) 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fFileName.reset(); 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayXMLParser parser(*fMaker); 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return parser.parse(dom, node); 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::decodeURI(const char uri[]) { 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("animator decode %s\n", uri); 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkStream* stream = SkStream::GetURIStream(fMaker->fPrefix.c_str(), uri); 87f381162e5616daacdbcc06d693aca5111aeeebe8mike@reedtribe.org SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(uri)); 88f381162e5616daacdbcc06d693aca5111aeeebe8mike@reedtribe.org if (stream.get()) { 89f381162e5616daacdbcc06d693aca5111aeeebe8mike@reedtribe.org this->setURIBase(uri); 90f381162e5616daacdbcc06d693aca5111aeeebe8mike@reedtribe.org return decodeStream(stream); 91f381162e5616daacdbcc06d693aca5111aeeebe8mike@reedtribe.org } else { 92f381162e5616daacdbcc06d693aca5111aeeebe8mike@reedtribe.org return false; 93f381162e5616daacdbcc06d693aca5111aeeebe8mike@reedtribe.org } 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::doCharEvent(SkUnichar code) { 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (code == 0) 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com struct SkEventState state; 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fCode = code; 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fEnableTime = fMaker->getAppTime(); 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kKeyChar, &state); 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->notifyInval(); 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return result; 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::doClickEvent(int clickState, SkScalar x, SkScalar y) { 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(clickState >= 0 && clickState <= 2); 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com struct SkEventState state; 1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fX = x; 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fY = y; 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fEnableTime = fMaker->getAppTime(); 113d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com bool result = fMaker->fEvents.doEvent(*fMaker, 114d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com clickState == 0 ? SkDisplayEvent::kMouseDown : 115d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com clickState == 1 ? SkDisplayEvent::kMouseDrag : 1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayEvent::kMouseUp, &state); 1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->notifyInval(); 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return result; 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::doKeyEvent(SkKey code) { 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (code == 0) 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com struct SkEventState state; 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fCode = code; 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fEnableTime = fMaker->getAppTime(); 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kKeyPress, &state); 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->notifyInval(); 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return result; 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::doKeyUpEvent(SkKey code) { 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (code == 0) 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com struct SkEventState state; 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fCode = code; 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fEnableTime = fMaker->getAppTime(); 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kKeyPressUp, &state); 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->notifyInval(); 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return result; 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::doUserEvent(const SkEvent& evt) { 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fEnableTime = fMaker->getAppTime(); 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return onEvent(evt); 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkAnimator::DifferenceType SkAnimator::draw(SkCanvas* canvas, SkPaint* paint, SkMSec time) { 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint == NULL) 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return draw(canvas, time); 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fScreenplay.time = time; 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fCanvas = canvas; 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fPaint = paint; 1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fDisplayList.fHasUnion = false; 1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int result = fMaker->fDisplayList.draw(*fMaker, time); 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (result) 1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com result += fMaker->fDisplayList.fHasUnion; 1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (DifferenceType) result; 1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkAnimator::DifferenceType SkAnimator::draw(SkCanvas* canvas, SkMSec time) { 1628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint paint; 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return draw(canvas, &paint, time); 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 165d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::eventDone(const SkEvent& ) { 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::findClickEvent(SkScalar x, SkScalar y) { 1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com struct SkEventState state; 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fDisable = true; 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fX = x; 1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fY = y; 1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fEnableTime = fMaker->getAppTime(); 1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kMouseDown, &state); 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->notifyInval(); 1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return result; 1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkAnimator* SkAnimator::getAnimator(const SkDisplayable* displayable) const { 1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (displayable->getType() != SkType_Movie) 1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayMovie* movie = (const SkDisplayMovie*) displayable; 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return movie->getAnimator(); 1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkDisplayable* SkAnimator::getElement(const char* id) { 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayable* element; 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fMaker->find(id, &element) == false) 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (const SkDisplayable*) element; 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkElementType SkAnimator::getElementType(const SkDisplayable* ae) { 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayable* element = (SkDisplayable*) ae; 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* info = SkDisplayType::GetMembers(fMaker, element->getType(), NULL); 1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (SkElementType) SkDisplayType::Find(fMaker, info); 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkElementType SkAnimator::getElementType(const char* id) { 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayable* element = getElement(id); 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return getElementType(element); 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkMemberInfo* SkAnimator::getField(const SkDisplayable* ae, const char* field) { 2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayable* element = (SkDisplayable*) ae; 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* info = element->getMember(field); 2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (const SkMemberInfo*) info; 2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkMemberInfo* SkAnimator::getField(const char* elementID, const char* field) { 2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayable* element = getElement(elementID); 2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return getField(element, field); 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkFieldType SkAnimator::getFieldType(const SkMemberInfo* ai) { 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* info = (const SkMemberInfo*) ai; 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (SkFieldType) info->getType(); 2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkFieldType SkAnimator::getFieldType(const char* id, const char* fieldID) { 2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(id, fieldID); 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return getFieldType(field); 2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22893c7ee34dc5c8f6bfad65809f4b39f8d00d7f0d4sugoi@google.comstatic bool getArrayCommon(const SkDisplayable* ae, const SkMemberInfo* ai, 22993c7ee34dc5c8f6bfad65809f4b39f8d00d7f0d4sugoi@google.com int index, SkOperand* operand) { 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayable* element = (const SkDisplayable*) ae; 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* info = (const SkMemberInfo*) ai; 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(info->fType == SkType_Array); 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return info->getArrayValue(element, index, operand); 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 236d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.comint32_t SkAnimator::getArrayInt(const SkDisplayable* ae, 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* ai, int index) { 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkOperand operand; 23993c7ee34dc5c8f6bfad65809f4b39f8d00d7f0d4sugoi@google.com bool result = getArrayCommon(ae, ai, index, &operand); 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return result ? operand.fS32 : SK_NaN32; 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comint32_t SkAnimator::getArrayInt(const char* id, const char* fieldID, int index) { 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayable* element = getElement(id); 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (element == NULL) 2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_NaN32; 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(element, fieldID); 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (field == NULL) 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_NaN32; 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return getArrayInt(element, field, index); 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 253d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.comSkScalar SkAnimator::getArrayScalar(const SkDisplayable* ae, 2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* ai, int index) { 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkOperand operand; 25693c7ee34dc5c8f6bfad65809f4b39f8d00d7f0d4sugoi@google.com bool result = getArrayCommon(ae, ai, index, &operand); 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return result ? operand.fScalar : SK_ScalarNaN; 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkScalar SkAnimator::getArrayScalar(const char* id, const char* fieldID, int index) { 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayable* element = getElement(id); 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (element == NULL) 2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ScalarNaN; 2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(element, fieldID); 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (field == NULL) 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ScalarNaN; 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return getArrayScalar(element, field, index); 2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 270d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.comconst char* SkAnimator::getArrayString(const SkDisplayable* ae, 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* ai, int index) { 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkOperand operand; 27393c7ee34dc5c8f6bfad65809f4b39f8d00d7f0d4sugoi@google.com bool result = getArrayCommon(ae, ai, index, &operand); 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return result ? operand.fString->c_str() : NULL; 2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst char* SkAnimator::getArrayString(const char* id, const char* fieldID, int index) { 2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayable* element = getElement(id); 2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (element == NULL) 2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(element, fieldID); 2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (field == NULL) 2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return getArrayString(element, field, index); 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkMSec SkAnimator::getInterval() { 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fMaker->fMinimumInterval == (SkMSec) -1 ? 0 : fMaker->fMinimumInterval; 2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::getInvalBounds(SkRect* inval) { 2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fMaker->fDisplayList.fHasUnion) { 2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inval->fLeft = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fLeft); 2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inval->fTop = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fTop); 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inval->fRight = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fRight); 2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inval->fBottom = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fBottom); 2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inval->fLeft = inval->fTop = -SK_ScalarMax; 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inval->fRight = inval->fBottom = SK_ScalarMax; 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkXMLParserError* SkAnimator::getParserError() { 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return &fMaker->fError; 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst char* SkAnimator::getParserErrorString() { 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fMaker->fErrorString.size() == 0 && fMaker->fError.hasError()) 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->setErrorString(); 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fMaker->fErrorString.c_str(); 3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comint32_t SkAnimator::getInt(const SkDisplayable* element, const SkMemberInfo* info) { 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (info->fType != SkType_MemberProperty) { 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkOperand operand; 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (info->getType() == SkType_Int) { 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com info->getValue(element, &operand, 1); 3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return operand.fS32; 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_NaN32; 3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScriptValue scriptValue; 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool success = element->getProperty(info->propertyIndex(), &scriptValue); 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (success && scriptValue.fType == SkType_Int) 3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return scriptValue.fOperand.fS32; 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_NaN32; 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comint32_t SkAnimator::getInt(const char* id, const char* fieldID) { 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayable* element = getElement(id); 3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (element == NULL) 3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_NaN32; 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(element, fieldID); 3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (field == NULL) 3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_NaN32; 3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return getInt(element, field); 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkScalar SkAnimator::getScalar(const SkDisplayable* element, const SkMemberInfo* info) { 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (info->fType != SkType_MemberProperty) { 3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkOperand operand; 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (info->getType() == SkType_Float) { 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com info->getValue(element, &operand, 1); 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return operand.fScalar; 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ScalarNaN; 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScriptValue scriptValue; 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool success = element->getProperty(info->propertyIndex(), &scriptValue); 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (success && scriptValue.fType == SkType_Float) 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return scriptValue.fOperand.fScalar; 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ScalarNaN; 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkScalar SkAnimator::getScalar(const char* id, const char* fieldID) { 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayable* element = getElement(id); 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (element == NULL) 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ScalarNaN; 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(element, fieldID); 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (field == NULL) 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SK_ScalarNaN; 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return getScalar(element, field); 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 365d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.comconst char* SkAnimator::getString(const SkDisplayable* ae, 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* ai) { 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayable* element = (const SkDisplayable*) ae; 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* info = (const SkMemberInfo*) ai; 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkString* temp; 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com info->getString(element, &temp); 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return temp->c_str(); 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst char* SkAnimator::getString(const char* id, const char* fieldID) { 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkDisplayable* element = getElement(id); 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (element == NULL) 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(element, fieldID); 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (field == NULL) 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return getString(element, field); 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst char* SkAnimator::getURIBase() { 3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fMaker->fPrefix.c_str(); 3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::initialize() { 3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDELETE(fMaker); 3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker = SkNEW_ARGS(SkAnimateMaker, (this, NULL, NULL)); 3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com decodeMemory(gMathPrimer, sizeof(gMathPrimer)-1); 392fa394d491b6e625159f83787619fcb852d245471djsollen@google.com#ifdef SK_BUILD_FOR_ANDROID 3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com InitializeSkExtraPathEffects(this); 3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::isTrackingEvents() { 4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::onEvent(const SkEvent& evt) { 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAnimator* root = fMaker->getRoot(); 4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (root == NULL) 4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com root = this; 4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (root->isTrackingEvents()) 4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com root->eventDone(evt); 4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (evt.isType(SK_EventType_OnEnd)) { 4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEventState eventState; 4149c55f801a35b0d6c39f007fae432bd13094f3c52sugoi@google.com SkDEBUGCODE(bool success =) evt.findPtr("anim", (void**) &eventState.fDisplayable); 4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(success); 4169c55f801a35b0d6c39f007fae432bd13094f3c52sugoi@google.com SkDEBUGCODE(success =) evt.findS32("time", (int32_t*) &fMaker->fEnableTime); 4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(success); 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fAdjustedStart = fMaker->getAppTime() - fMaker->fEnableTime; 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kOnEnd, &eventState); 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fAdjustedStart = 0; 4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com goto inval; 4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (evt.isType(SK_EventType_Delay)) { 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->doDelayedEvent(); 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com goto inval; 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* id = evt.findString("id"); 4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (id == NULL) 4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayable** firstMovie = fMaker->fMovies.begin(); 4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayable** endMovie = fMaker->fMovies.end(); 4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (SkDisplayable** ptr = firstMovie; ptr < endMovie; ptr++) { 4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayMovie* movie = (SkDisplayMovie*) *ptr; 4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com movie->doEvent(evt); 4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayable* event; 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fMaker->find(id, &event) == false) 4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING 4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkString debugOut; 4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMSec realTime = fMaker->getAppTime(); 4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com debugOut.appendS32(realTime - fMaker->fDebugTimeBase); 4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com debugOut.append(" onEvent id="); 4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com debugOut.append(id); 4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #endif 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMSec time = evt.getFast32(); 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (time != 0) { 4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMSec app = fMaker->getAppTime(); 4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->setEnableTime(app, time); 4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING 4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com debugOut.append(" time="); 4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com debugOut.appendS32(time - fMaker->fDebugTimeBase); 4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com debugOut.append(" adjust="); 4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com debugOut.appendS32(fMaker->fAdjustedStart); 4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #endif 4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDebugf("%s\n", debugOut.c_str()); 4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #endif 4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(event->isEvent()); 4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayEvent* displayEvent = (SkDisplayEvent*) event; 4648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com displayEvent->populateInput(*fMaker, evt); 4658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com displayEvent->enableEvent(*fMaker); 4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.cominval: 4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->notifyInval(); 4708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::onEventPost(SkEvent* evt, SkEventSinkID sinkID) 4748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 4758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 4768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAnimator* root = fMaker->getRoot(); 4778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (root) { 4788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com root->onEventPost(evt, sinkID); 4798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#else 4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(sinkID == this->getSinkID() || this->getHostEventSinkID() == sinkID); 4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 48487fac4abd7ea446c05d5cfd4a8ad27420223b591reed@google.com evt->setTargetID(sinkID)->post(); 4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::onEventPostTime(SkEvent* evt, SkEventSinkID sinkID, SkMSec time) 4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 4898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 4908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAnimator* root = fMaker->getRoot(); 4918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (root) { 4928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com root->onEventPostTime(evt, sinkID, time); 4938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#else 4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(sinkID == this->getSinkID() || this->getHostEventSinkID() == sinkID); 4978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 49887fac4abd7ea446c05d5cfd4a8ad27420223b591reed@google.com evt->setTargetID(sinkID)->postTime(time); 4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::reset() { 5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fDisplayList.reset(); 5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkEventSinkID SkAnimator::getHostEventSinkID() const { 506d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return fMaker->fHostEventSinkID; 5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::setHostEventSinkID(SkEventSinkID target) { 510d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com fMaker->fHostEventSinkID = target; 5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::onSetHostHandler(Handler ) { 5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::setJavaOwner(Handler ) { 5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::setArrayString(const char* id, const char* fieldID, const char** array, int num) 5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTypedArray tArray(SkType_String); 5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tArray.setCount(num); 5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < num; i++) { 5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkOperand op; 5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com op.fString = new SkString(array[i]); 5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tArray[i] = op; 5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return setArray(id, fieldID, tArray); 5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::setArrayInt(const char* id, const char* fieldID, const int* array, int num) 5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTypedArray tArray(SkType_Int); 5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tArray.setCount(num); 5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < num; i++) { 535d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com SkOperand op; 5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com op.fS32 = array[i]; 5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tArray[i] = op; 5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return setArray(id, fieldID, tArray); 5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::setArray(SkDisplayable* element, const SkMemberInfo* info, SkTypedArray array) { 5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (info->fType != SkType_Array) 5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; //the field is not an array 5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //i think we can handle the case where the displayable itself is an array differently from the 5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //case where it has an array - for one thing, if it is an array, i think we can change its type 5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //if it's not, we cannot 5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayTypes type = element->getType(); 5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (type == SkType_Array) { 5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayArray* dispArray = (SkDisplayArray*) element; 551d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com dispArray->values = array; 5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com else 5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; //currently i don't care about this case 5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::setArray(const char* id, const char* fieldID, SkTypedArray array) { 5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayable* element = (SkDisplayable*) getElement(id); 5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //should I go ahead and change all 'NULL's to 'NULL'? 5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (element == NULL) 5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(element, fieldID); 5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (field == NULL) 5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return setArray(element, field, array); 5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::setInt(SkDisplayable* element, const SkMemberInfo* info, int32_t s32) { 5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (info->fType != SkType_MemberProperty) { 5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkOperand operand; 5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com operand.fS32 = s32; 5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(info->getType() == SkType_Int); 5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com info->setValue(element, &operand, 1); 5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScriptValue scriptValue; 5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scriptValue.fType = SkType_Int; 5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scriptValue.fOperand.fS32 = s32; 5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com element->setProperty(info->propertyIndex(), scriptValue); 5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 5828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::setInt(const char* id, const char* fieldID, int32_t s32) { 5858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayable* element = (SkDisplayable*) getElement(id); 5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (element == NULL) 5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(element, fieldID); 5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (field == NULL) 5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return setInt(element, field, s32); 5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::setScalar(SkDisplayable* element, const SkMemberInfo* info, SkScalar scalar) { 5958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (info->fType != SkType_MemberProperty) { 5968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkOperand operand; 5978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com operand.fScalar = scalar; 5988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(info->getType() == SkType_Float); 5998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com info->setValue(element, &operand, 1); 6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 6018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScriptValue scriptValue; 6028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scriptValue.fType = SkType_Float; 6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scriptValue.fOperand.fScalar = scalar; 6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com element->setProperty(info->propertyIndex(), scriptValue); 6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::setScalar(const char* id, const char* fieldID, SkScalar scalar) { 6108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayable* element = (SkDisplayable*) getElement(id); 6118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (element == NULL) 6128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 6138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(element, fieldID); 6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (field == NULL) 6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return setScalar(element, field, scalar); 6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 619d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.combool SkAnimator::setString(SkDisplayable* element, 6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* info, const char* str) { 621d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com // !!! until this is fixed, can't call script with global references from here 6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com info->setValue(*fMaker, NULL, 0, info->fCount, element, info->getType(), str, strlen(str)); 6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::setString(const char* id, const char* fieldID, const char* str) { 6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDisplayable* element = (SkDisplayable*) getElement(id); 6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (element == NULL) 6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMemberInfo* field = getField(element, fieldID); 6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (field == NULL) 6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return setString(element, field, str); 6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::setTimeline(const Timeline& timeline) { 6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fTimeline = &timeline; 6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::setURIBase(const char* uri) { 6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (uri) 6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* tail = strrchr(uri, '/'); 6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (tail) { 6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkString prefix(uri, tail - uri + 1); 6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (uri[0] != '.' /*SkStream::IsAbsoluteURI(uri)*/) 6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fPrefix.reset(); 6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fPrefix.append(prefix); 6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fFileName.set(tail + 1); 6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else 6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMaker->fFileName.set(uri); 6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 6568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkAnimator::NoLeaks() { 6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_BUILD_FOR_MAC 6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkDisplayable::fAllocations.count() == 0) 6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// return SkDisplayable::fAllocationCount == 0; 6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDebugf("!!! leaked %d displayables:\n", SkDisplayable::fAllocations.count()); 6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (SkDisplayable** leak = SkDisplayable::fAllocations.begin(); leak < SkDisplayable::fAllocations.end(); leak++) 6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDebugf("%08x %s\n", *leak, (*leak)->id); 6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_SUPPORT_UNITTEST 6708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkAnimatorScript.h" 6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBase64.h" 6728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkParse.h" 6738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMemberInfo.h" 6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define unittestline(type) { #type , type::UnitTest } 6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_SUPPORT_UNITTEST 68093c7ee34dc5c8f6bfad65809f4b39f8d00d7f0d4sugoi@google.comvoid SkAnimator::Init(bool runUnitTests) { 6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (runUnitTests == false) 6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static const struct { 6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* fTypeName; 6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void (*fUnitTest)( ); 6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } gUnitTests[] = { 6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unittestline(SkBase64), 6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unittestline(SkDisplayType), 6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unittestline(SkParse), 6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unittestline(SkScriptEngine), 6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// unittestline(SkScriptEngine2), // compiled script experiment 6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unittestline(SkAnimatorScript) 6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < (int)SK_ARRAY_COUNT(gUnitTests); i++) 6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDebugf("SkAnimator: Running UnitTest for %s\n", gUnitTests[i].fTypeName); 6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com gUnitTests[i].fUnitTest(); 6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDebugf("SkAnimator: End UnitTest for %s\n", gUnitTests[i].fTypeName); 6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 70193c7ee34dc5c8f6bfad65809f4b39f8d00d7f0d4sugoi@google.com#else 70293c7ee34dc5c8f6bfad65809f4b39f8d00d7f0d4sugoi@google.comvoid SkAnimator::Init(bool) {} 70393c7ee34dc5c8f6bfad65809f4b39f8d00d7f0d4sugoi@google.com#endif 7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkAnimator::Term() { 7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 707