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 "SkDisplayMovie.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkAnimateMaker.h" 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkCanvas.h" 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkPaint.h" 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if SK_USE_CONDENSED_INFO == 0 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo SkDisplayMovie::fInfo[] = { 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER(src, String) 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDEFINE_GET_MEMBER(SkDisplayMovie); 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkDisplayMovie::SkDisplayMovie() : fDecodedSuccessfully(false), fLoaded(false), fMovieBuilt(false) { 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMovie.fMaker->fInMovie = true; 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkDisplayMovie::~SkDisplayMovie() { 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkDisplayMovie::buildMovie() { 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fMovieBuilt) 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAnimateMaker* movieMaker = fMovie.fMaker; 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAnimateMaker* parentMaker = movieMaker->fParentMaker; 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (src.size() == 0 || parentMaker == NULL) 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return; 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru movieMaker->fPrefix.set(parentMaker->fPrefix); 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fDecodedSuccessfully = fMovie.fMaker->decodeURI(src.c_str()); 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fDecodedSuccessfully == false) { 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (movieMaker->getErrorCode() != SkXMLParserError::kNoError || movieMaker->getNativeCode() != -1) { 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru movieMaker->setInnerError(parentMaker, src); 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parentMaker->setErrorCode(SkDisplayXMLParserError::kInMovie); 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } else { 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parentMaker->setErrorNoun(src); 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parentMaker->setErrorCode(SkDisplayXMLParserError::kMovieNameUnknownOrMissing); 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMovieBuilt = true; 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkDisplayable* SkDisplayMovie::deepCopy(SkAnimateMaker* maker) { 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayMovie* copy = (SkDisplayMovie*) INHERITED::deepCopy(maker); 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru copy->fMovie.fMaker->fParentMaker = fMovie.fMaker->fParentMaker; 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru copy->fMovie.fMaker->fHostEventSinkID = fMovie.fMaker->fHostEventSinkID; 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru copy->fMovieBuilt = false; 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *fMovie.fMaker->fParentMaker->fMovies.append() = copy; 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return copy; 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkDisplayMovie::dirty() { 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru buildMovie(); 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDisplayMovie::doEvent(SkDisplayEvent::Kind kind, SkEventState* state) { 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fLoaded == false) 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMovie.fMaker->fEnableTime = fMovie.fMaker->fParentMaker->fEnableTime; 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return fMovie.fMaker->fEvents.doEvent(*fMovie.fMaker, kind, state); 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDisplayMovie::draw(SkAnimateMaker& maker) { 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fDecodedSuccessfully == false) 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fLoaded == false) 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru enable(maker); 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru maker.fCanvas->save(); 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPaint local = SkPaint(*maker.fPaint); 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool result = fMovie.draw(maker.fCanvas, &local, 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru maker.fDisplayList.getTime()) != SkAnimator::kNotDifferent; 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru maker.fDisplayList.fInvalBounds.join(fMovie.fMaker->fDisplayList.fInvalBounds); 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru maker.fCanvas->restore(); 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result; 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DUMP_ENABLED 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkDisplayMovie::dump(SkAnimateMaker* maker) { 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dumpBase(maker); 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("src=\"%s\"/>\n", src.c_str()); 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAnimateMaker* movieMaker = fMovie.fMaker; 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayList::fIndent += 4; 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru movieMaker->fDisplayList.dumpInner(movieMaker); 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayList::fIndent -= 4; 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dumpEnd(maker); 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkDisplayMovie::dumpEvents() { 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMovie.fMaker->fEvents.dump(*fMovie.fMaker); 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 104096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenbergerbool SkDisplayMovie::enable(SkAnimateMaker&) { 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fDecodedSuccessfully == false) 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAnimateMaker* movieMaker = fMovie.fMaker; 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru movieMaker->fEvents.doEvent(*movieMaker, SkDisplayEvent::kOnload, NULL); 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru movieMaker->fEvents.removeEvent(SkDisplayEvent::kOnload, NULL); 11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fLoaded = true; 11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru movieMaker->fLoaded = true; 11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDisplayMovie::hasEnable() const { 11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkDisplayMovie::onEndElement(SkAnimateMaker& maker) { 12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING 12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMovie.fMaker->fDebugTimeBase = maker.fDebugTimeBase; 12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMovie.fMaker->fPrefix.set(maker.fPrefix); 12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMovie.fMaker->fHostEventSinkID = maker.fHostEventSinkID; 12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMovie.fMaker->fParentMaker = &maker; 12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru buildMovie(); 12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *maker.fMovies.append() = this; 12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 129