180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkAnimator.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkAnimateMaker.h" 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkCanvas.h" 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDisplayApply.h" 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDisplayMovie.h" 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDisplayTypes.h" 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDisplayXMLParser.h" 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkStream.h" 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkScript.h" 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkScript2.h" // compiled script experiment 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkSystemEventTypes.h" 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTypedArray.h" 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_BUILD_FOR_ANDROID 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDrawExtraPathEffect.h" 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTime.h" 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if defined SK_BUILD_FOR_WIN32 && defined SK_DEBUG 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #define _static 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru extern const char gMathPrimerText[]; 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru extern const char gMathPrimerBinary[]; 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#else 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #define _static static 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru_static const char gMathPrimerText[] = 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru"<screenplay>" 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru "<Math id=\"Math\"/>" 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru "<Number id=\"Number\"/>" 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru"</screenplay>"; 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define gMathPrimer gMathPrimerText 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkAnimator::SkAnimator() : fMaker(NULL) { 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru initialize(); 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkAnimator::~SkAnimator() { 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDELETE(fMaker); 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::addExtras(SkExtras* extras) { 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *fMaker->fExtras.append() = extras; 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::appendStream(SkStream* stream) { 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return decodeStream(stream); 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::decodeMemory(const void* buffer, size_t size) 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fFileName.reset(); 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayXMLParser parser(*fMaker); 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return parser.parse((const char*)buffer, size); 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::decodeStream(SkStream* stream) 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayXMLParser parser(*fMaker); 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool result = parser.parse(*stream); 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->setErrorString(); 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result; 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::decodeDOM(const SkDOM& dom, const SkDOMNode* node) 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fFileName.reset(); 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayXMLParser parser(*fMaker); 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return parser.parse(dom, node); 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::decodeURI(const char uri[]) { 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// SkDebugf("animator decode %s\n", uri); 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// SkStream* stream = SkStream::GetURIStream(fMaker->fPrefix.c_str(), uri); 87096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(uri)); 88096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger if (stream.get()) { 89096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger this->setURIBase(uri); 90096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger return decodeStream(stream); 91096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger } else { 92096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger return false; 93096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger } 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::doCharEvent(SkUnichar code) { 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (code == 0) 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru struct SkEventState state; 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru state.fCode = code; 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fEnableTime = fMaker->getAppTime(); 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kKeyChar, &state); 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->notifyInval(); 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result; 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::doClickEvent(int clickState, SkScalar x, SkScalar y) { 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(clickState >= 0 && clickState <= 2); 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru struct SkEventState state; 11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru state.fX = x; 11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru state.fY = y; 11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fEnableTime = fMaker->getAppTime(); 11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool result = fMaker->fEvents.doEvent(*fMaker, 11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru clickState == 0 ? SkDisplayEvent::kMouseDown : 11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru clickState == 1 ? SkDisplayEvent::kMouseDrag : 11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayEvent::kMouseUp, &state); 11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->notifyInval(); 11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result; 11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::doKeyEvent(SkKey code) { 12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (code == 0) 12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru struct SkEventState state; 12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru state.fCode = code; 12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fEnableTime = fMaker->getAppTime(); 12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kKeyPress, &state); 12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->notifyInval(); 12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result; 13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::doKeyUpEvent(SkKey code) { 13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (code == 0) 13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru struct SkEventState state; 13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru state.fCode = code; 13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fEnableTime = fMaker->getAppTime(); 13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kKeyPressUp, &state); 13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->notifyInval(); 14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result; 14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::doUserEvent(const SkEvent& evt) { 14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fEnableTime = fMaker->getAppTime(); 14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return onEvent(evt); 14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkAnimator::DifferenceType SkAnimator::draw(SkCanvas* canvas, SkPaint* paint, SkMSec time) { 14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (paint == NULL) 15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return draw(canvas, time); 15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fScreenplay.time = time; 15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fCanvas = canvas; 15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fPaint = paint; 15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fDisplayList.fHasUnion = false; 15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int result = fMaker->fDisplayList.draw(*fMaker, time); 15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (result) 15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru result += fMaker->fDisplayList.fHasUnion; 15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return (DifferenceType) result; 15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkAnimator::DifferenceType SkAnimator::draw(SkCanvas* canvas, SkMSec time) { 16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPaint paint; 16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return draw(canvas, &paint, time); 16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::eventDone(const SkEvent& ) { 16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::findClickEvent(SkScalar x, SkScalar y) { 17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru struct SkEventState state; 17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru state.fDisable = true; 17480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru state.fX = x; 17580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru state.fY = y; 17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fEnableTime = fMaker->getAppTime(); 17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kMouseDown, &state); 17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->notifyInval(); 17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result; 18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkAnimator* SkAnimator::getAnimator(const SkDisplayable* displayable) const { 18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (displayable->getType() != SkType_Movie) 18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayMovie* movie = (const SkDisplayMovie*) displayable; 18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return movie->getAnimator(); 18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkDisplayable* SkAnimator::getElement(const char* id) { 19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* element; 19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fMaker->find(id, &element) == false) 19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return (const SkDisplayable*) element; 19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkElementType SkAnimator::getElementType(const SkDisplayable* ae) { 19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* element = (SkDisplayable*) ae; 19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* info = SkDisplayType::GetMembers(fMaker, element->getType(), NULL); 19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return (SkElementType) SkDisplayType::Find(fMaker, info); 20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkElementType SkAnimator::getElementType(const char* id) { 20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayable* element = getElement(id); 20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getElementType(element); 20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo* SkAnimator::getField(const SkDisplayable* ae, const char* field) { 20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* element = (SkDisplayable*) ae; 20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* info = element->getMember(field); 21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return (const SkMemberInfo*) info; 21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo* SkAnimator::getField(const char* elementID, const char* field) { 21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayable* element = getElement(elementID); 21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getField(element, field); 21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkFieldType SkAnimator::getFieldType(const SkMemberInfo* ai) { 21980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* info = (const SkMemberInfo*) ai; 22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return (SkFieldType) info->getType(); 22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkFieldType SkAnimator::getFieldType(const char* id, const char* fieldID) { 22480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(id, fieldID); 22580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getFieldType(field); 22680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 22780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 228096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenbergerstatic bool getArrayCommon(const SkDisplayable* ae, const SkMemberInfo* ai, 229096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger int index, SkOperand* operand) { 23080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayable* element = (const SkDisplayable*) ae; 23180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* info = (const SkMemberInfo*) ai; 23280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(info->fType == SkType_Array); 23380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return info->getArrayValue(element, index, operand); 23480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 23580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 23680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint32_t SkAnimator::getArrayInt(const SkDisplayable* ae, 23780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* ai, int index) { 23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkOperand operand; 239096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger bool result = getArrayCommon(ae, ai, index, &operand); 24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result ? operand.fS32 : SK_NaN32; 24180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 24280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 24380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint32_t SkAnimator::getArrayInt(const char* id, const char* fieldID, int index) { 24480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayable* element = getElement(id); 24580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (element == NULL) 24680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_NaN32; 24780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(element, fieldID); 24880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (field == NULL) 24980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_NaN32; 25080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getArrayInt(element, field, index); 25180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 25280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 25380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkScalar SkAnimator::getArrayScalar(const SkDisplayable* ae, 25480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* ai, int index) { 25580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkOperand operand; 256096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger bool result = getArrayCommon(ae, ai, index, &operand); 25780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result ? operand.fScalar : SK_ScalarNaN; 25880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 25980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 26080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkScalar SkAnimator::getArrayScalar(const char* id, const char* fieldID, int index) { 26180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayable* element = getElement(id); 26280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (element == NULL) 26380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_ScalarNaN; 26480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(element, fieldID); 26580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (field == NULL) 26680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_ScalarNaN; 26780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getArrayScalar(element, field, index); 26880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 26980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 27080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* SkAnimator::getArrayString(const SkDisplayable* ae, 27180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* ai, int index) { 27280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkOperand operand; 273096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger bool result = getArrayCommon(ae, ai, index, &operand); 27480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result ? operand.fString->c_str() : NULL; 27580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 27680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 27780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* SkAnimator::getArrayString(const char* id, const char* fieldID, int index) { 27880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayable* element = getElement(id); 27980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (element == NULL) 28080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 28180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(element, fieldID); 28280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (field == NULL) 28380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 28480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getArrayString(element, field, index); 28580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 28680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 28780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkMSec SkAnimator::getInterval() { 28880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return fMaker->fMinimumInterval == (SkMSec) -1 ? 0 : fMaker->fMinimumInterval; 28980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 29080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 29180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::getInvalBounds(SkRect* inval) { 29280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fMaker->fDisplayList.fHasUnion) { 29380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru inval->fLeft = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fLeft); 29480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru inval->fTop = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fTop); 29580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru inval->fRight = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fRight); 29680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru inval->fBottom = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fBottom); 29780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } else { 29880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru inval->fLeft = inval->fTop = -SK_ScalarMax; 29980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru inval->fRight = inval->fBottom = SK_ScalarMax; 30080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 30180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 30280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 30380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkXMLParserError* SkAnimator::getParserError() { 30480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return &fMaker->fError; 30580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 30680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 30780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* SkAnimator::getParserErrorString() { 30880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fMaker->fErrorString.size() == 0 && fMaker->fError.hasError()) 30980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->setErrorString(); 31080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return fMaker->fErrorString.c_str(); 31180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 31280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 31380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint32_t SkAnimator::getInt(const SkDisplayable* element, const SkMemberInfo* info) { 31480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (info->fType != SkType_MemberProperty) { 31580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkOperand operand; 31680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (info->getType() == SkType_Int) { 31780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru info->getValue(element, &operand, 1); 31880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return operand.fS32; 31980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 32080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_NaN32; 32180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 32280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScriptValue scriptValue; 32380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool success = element->getProperty(info->propertyIndex(), &scriptValue); 32480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (success && scriptValue.fType == SkType_Int) 32580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return scriptValue.fOperand.fS32; 32680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_NaN32; 32780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 32880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 32980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint32_t SkAnimator::getInt(const char* id, const char* fieldID) { 33080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayable* element = getElement(id); 33180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (element == NULL) 33280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_NaN32; 33380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(element, fieldID); 33480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (field == NULL) 33580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_NaN32; 33680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getInt(element, field); 33780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 33880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 33980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkScalar SkAnimator::getScalar(const SkDisplayable* element, const SkMemberInfo* info) { 34080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (info->fType != SkType_MemberProperty) { 34180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkOperand operand; 34280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (info->getType() == SkType_Float) { 34380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru info->getValue(element, &operand, 1); 34480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return operand.fScalar; 34580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 34680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_ScalarNaN; 34780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 34880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScriptValue scriptValue; 34980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool success = element->getProperty(info->propertyIndex(), &scriptValue); 35080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (success && scriptValue.fType == SkType_Float) 35180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return scriptValue.fOperand.fScalar; 35280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_ScalarNaN; 35380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 35480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 35580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkScalar SkAnimator::getScalar(const char* id, const char* fieldID) { 35680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayable* element = getElement(id); 35780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (element == NULL) 35880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_ScalarNaN; 35980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(element, fieldID); 36080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (field == NULL) 36180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return SK_ScalarNaN; 36280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getScalar(element, field); 36380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 36480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 36580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* SkAnimator::getString(const SkDisplayable* ae, 36680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* ai) { 36780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayable* element = (const SkDisplayable*) ae; 36880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* info = (const SkMemberInfo*) ai; 36980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkString* temp; 37080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru info->getString(element, &temp); 37180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return temp->c_str(); 37280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 37380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 37480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* SkAnimator::getString(const char* id, const char* fieldID) { 37580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkDisplayable* element = getElement(id); 37680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (element == NULL) 37780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 37880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(element, fieldID); 37980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (field == NULL) 38080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 38180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getString(element, field); 38280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 38380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 38480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* SkAnimator::getURIBase() { 38580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return fMaker->fPrefix.c_str(); 38680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 38780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 38880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::initialize() { 38980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDELETE(fMaker); 39080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker = SkNEW_ARGS(SkAnimateMaker, (this, NULL, NULL)); 39180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru decodeMemory(gMathPrimer, sizeof(gMathPrimer)-1); 39280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_BUILD_FOR_ANDROID 39380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru InitializeSkExtraPathEffects(this); 39480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 39580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 39680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 39780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 39880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 39980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::isTrackingEvents() { 40080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 40180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 40280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 40380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 40480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::onEvent(const SkEvent& evt) { 40580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 40680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAnimator* root = fMaker->getRoot(); 40780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (root == NULL) 40880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru root = this; 40980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (root->isTrackingEvents()) 41080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru root->eventDone(evt); 41180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 41280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (evt.isType(SK_EventType_OnEnd)) { 41380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkEventState eventState; 414096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger SkDEBUGCODE(bool success =) evt.findPtr("anim", (void**) &eventState.fDisplayable); 41580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(success); 416096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger SkDEBUGCODE(success =) evt.findS32("time", (int32_t*) &fMaker->fEnableTime); 41780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(success); 41880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fAdjustedStart = fMaker->getAppTime() - fMaker->fEnableTime; 41980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kOnEnd, &eventState); 42080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fAdjustedStart = 0; 42180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru goto inval; 42280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 42380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (evt.isType(SK_EventType_Delay)) { 42480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->doDelayedEvent(); 42580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru goto inval; 42680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 42780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 42880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const char* id = evt.findString("id"); 42980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (id == NULL) 43080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 43180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable** firstMovie = fMaker->fMovies.begin(); 43280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable** endMovie = fMaker->fMovies.end(); 43380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (SkDisplayable** ptr = firstMovie; ptr < endMovie; ptr++) { 43480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayMovie* movie = (SkDisplayMovie*) *ptr; 43580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru movie->doEvent(evt); 43680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 43780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 43880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* event; 43980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fMaker->find(id, &event) == false) 44080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 44180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING 44280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkString debugOut; 44380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkMSec realTime = fMaker->getAppTime(); 44480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru debugOut.appendS32(realTime - fMaker->fDebugTimeBase); 44580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru debugOut.append(" onEvent id="); 44680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru debugOut.append(id); 44780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #endif 44880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkMSec time = evt.getFast32(); 44980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (time != 0) { 45080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkMSec app = fMaker->getAppTime(); 45180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->setEnableTime(app, time); 45280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING 45380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru debugOut.append(" time="); 45480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru debugOut.appendS32(time - fMaker->fDebugTimeBase); 45580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru debugOut.append(" adjust="); 45680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru debugOut.appendS32(fMaker->fAdjustedStart); 45780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #endif 45880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 45980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING 46080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("%s\n", debugOut.c_str()); 46180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #endif 46280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(event->isEvent()); 46380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayEvent* displayEvent = (SkDisplayEvent*) event; 46480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru displayEvent->populateInput(*fMaker, evt); 46580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru displayEvent->enableEvent(*fMaker); 46680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 46780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 46880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruinval: 46980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->notifyInval(); 47080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 47180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 47280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 47380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::onEventPost(SkEvent* evt, SkEventSinkID sinkID) 47480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 47580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 47680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAnimator* root = fMaker->getRoot(); 47780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (root) { 47880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru root->onEventPost(evt, sinkID); 47980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 48080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 48180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#else 48280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(sinkID == this->getSinkID() || this->getHostEventSinkID() == sinkID); 48380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 48480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru evt->setTargetID(sinkID)->post(); 48580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 48680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 48780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::onEventPostTime(SkEvent* evt, SkEventSinkID sinkID, SkMSec time) 48880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 48980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 49080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAnimator* root = fMaker->getRoot(); 49180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (root) { 49280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru root->onEventPostTime(evt, sinkID, time); 49380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 49480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 49580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#else 49680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(sinkID == this->getSinkID() || this->getHostEventSinkID() == sinkID); 49780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 49880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru evt->setTargetID(sinkID)->postTime(time); 49980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 50080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 50180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::reset() { 50280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fDisplayList.reset(); 50380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 50480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 50580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkEventSinkID SkAnimator::getHostEventSinkID() const { 50680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return fMaker->fHostEventSinkID; 50780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 50880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 50980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::setHostEventSinkID(SkEventSinkID target) { 51080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fHostEventSinkID = target; 51180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 51280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 51380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::onSetHostHandler(Handler ) { 51480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 51580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 51680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::setJavaOwner(Handler ) { 51780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 51880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 51980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::setArrayString(const char* id, const char* fieldID, const char** array, int num) 52080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 52180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkTypedArray tArray(SkType_String); 52280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru tArray.setCount(num); 52380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (int i = 0; i < num; i++) { 52480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkOperand op; 52580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru op.fString = new SkString(array[i]); 52680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru tArray[i] = op; 52780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 52880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return setArray(id, fieldID, tArray); 52980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 53080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::setArrayInt(const char* id, const char* fieldID, const int* array, int num) 53180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 53280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkTypedArray tArray(SkType_Int); 53380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru tArray.setCount(num); 53480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (int i = 0; i < num; i++) { 53580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkOperand op; 53680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru op.fS32 = array[i]; 53780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru tArray[i] = op; 53880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 53980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return setArray(id, fieldID, tArray); 54080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 54180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 54280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::setArray(SkDisplayable* element, const SkMemberInfo* info, SkTypedArray array) { 54380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (info->fType != SkType_Array) 54480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; //the field is not an array 54580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru //i think we can handle the case where the displayable itself is an array differently from the 54680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru //case where it has an array - for one thing, if it is an array, i think we can change its type 54780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru //if it's not, we cannot 54880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayTypes type = element->getType(); 54980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (type == SkType_Array) { 55080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayArray* dispArray = (SkDisplayArray*) element; 55180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dispArray->values = array; 55280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 55380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 55480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru else 55580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; //currently i don't care about this case 55680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 55780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 55880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::setArray(const char* id, const char* fieldID, SkTypedArray array) { 55980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* element = (SkDisplayable*) getElement(id); 56080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru //should I go ahead and change all 'NULL's to 'NULL'? 56180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (element == NULL) 56280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 56380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(element, fieldID); 56480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (field == NULL) 56580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 56680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return setArray(element, field, array); 56780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 56880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 56980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::setInt(SkDisplayable* element, const SkMemberInfo* info, int32_t s32) { 57080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (info->fType != SkType_MemberProperty) { 57180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkOperand operand; 57280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru operand.fS32 = s32; 57380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(info->getType() == SkType_Int); 57480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru info->setValue(element, &operand, 1); 57580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } else { 57680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScriptValue scriptValue; 57780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru scriptValue.fType = SkType_Int; 57880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru scriptValue.fOperand.fS32 = s32; 57980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru element->setProperty(info->propertyIndex(), scriptValue); 58080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 58180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 58280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 58380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 58480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::setInt(const char* id, const char* fieldID, int32_t s32) { 58580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* element = (SkDisplayable*) getElement(id); 58680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (element == NULL) 58780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 58880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(element, fieldID); 58980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (field == NULL) 59080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 59180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return setInt(element, field, s32); 59280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 59380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 59480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::setScalar(SkDisplayable* element, const SkMemberInfo* info, SkScalar scalar) { 59580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (info->fType != SkType_MemberProperty) { 59680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkOperand operand; 59780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru operand.fScalar = scalar; 59880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(info->getType() == SkType_Float); 59980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru info->setValue(element, &operand, 1); 60080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } else { 60180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScriptValue scriptValue; 60280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru scriptValue.fType = SkType_Float; 60380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru scriptValue.fOperand.fScalar = scalar; 60480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru element->setProperty(info->propertyIndex(), scriptValue); 60580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 60680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 60780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 60880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 60980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::setScalar(const char* id, const char* fieldID, SkScalar scalar) { 61080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* element = (SkDisplayable*) getElement(id); 61180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (element == NULL) 61280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 61380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(element, fieldID); 61480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (field == NULL) 61580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 61680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return setScalar(element, field, scalar); 61780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 61880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 61980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::setString(SkDisplayable* element, 62080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* info, const char* str) { 62180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // !!! until this is fixed, can't call script with global references from here 62280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru info->setValue(*fMaker, NULL, 0, info->fCount, element, info->getType(), str, strlen(str)); 62380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 62480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 62580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 62680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::setString(const char* id, const char* fieldID, const char* str) { 62780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* element = (SkDisplayable*) getElement(id); 62880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (element == NULL) 62980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 63080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* field = getField(element, fieldID); 63180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (field == NULL) 63280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 63380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return setString(element, field, str); 63480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 63580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 63680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::setTimeline(const Timeline& timeline) { 63780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fTimeline = &timeline; 63880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 63980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 64080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::setURIBase(const char* uri) { 64180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (uri) 64280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 64380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const char* tail = strrchr(uri, '/'); 64480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (tail) { 64580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkString prefix(uri, tail - uri + 1); 64680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (uri[0] != '.' /*SkStream::IsAbsoluteURI(uri)*/) 64780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fPrefix.reset(); 64880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fPrefix.append(prefix); 64980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fFileName.set(tail + 1); 65080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } else 65180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMaker->fFileName.set(uri); 65280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 65380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 65480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 65580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 65680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkAnimator::NoLeaks() { 65780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_BUILD_FOR_MAC 65880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (SkDisplayable::fAllocations.count() == 0) 65980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 66080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// return SkDisplayable::fAllocationCount == 0; 66180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("!!! leaked %d displayables:\n", SkDisplayable::fAllocations.count()); 66280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (SkDisplayable** leak = SkDisplayable::fAllocations.begin(); leak < SkDisplayable::fAllocations.end(); leak++) 66380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("%08x %s\n", *leak, (*leak)->id); 66480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 66580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 66680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 66780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 66880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 66980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_SUPPORT_UNITTEST 67080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkAnimatorScript.h" 67180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkBase64.h" 67280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkParse.h" 67380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkMemberInfo.h" 67480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 67580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define unittestline(type) { #type , type::UnitTest } 67680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 67780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 67880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 67980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_SUPPORT_UNITTEST 680096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenbergervoid SkAnimator::Init(bool runUnitTests) { 68180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (runUnitTests == false) 68280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 68380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static const struct { 68480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const char* fTypeName; 68580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void (*fUnitTest)( ); 68680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } gUnitTests[] = { 68780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru unittestline(SkBase64), 68880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru unittestline(SkDisplayType), 68980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru unittestline(SkParse), 69080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru unittestline(SkScriptEngine), 69180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// unittestline(SkScriptEngine2), // compiled script experiment 69280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru unittestline(SkAnimatorScript) 69380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 69480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (int i = 0; i < (int)SK_ARRAY_COUNT(gUnitTests); i++) 69580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 69680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("SkAnimator: Running UnitTest for %s\n", gUnitTests[i].fTypeName); 69780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru gUnitTests[i].fUnitTest(); 69880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("SkAnimator: End UnitTest for %s\n", gUnitTests[i].fTypeName); 69980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 70080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 701096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger#else 702096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenbergervoid SkAnimator::Init(bool) {} 703096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger#endif 70480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 70580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkAnimator::Term() { 70680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 707