• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libs/graphics/animator/SkDisplayMovie.cpp
2 **
3 ** Copyright 2006, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 #include "SkDisplayMovie.h"
19 #include "SkAnimateMaker.h"
20 #include "SkCanvas.h"
21 #include "SkPaint.h"
22 
23 #if SK_USE_CONDENSED_INFO == 0
24 
25 const SkMemberInfo SkDisplayMovie::fInfo[] = {
26     SK_MEMBER(src, String)
27 };
28 
29 #endif
30 
31 DEFINE_GET_MEMBER(SkDisplayMovie);
32 
SkDisplayMovie()33 SkDisplayMovie::SkDisplayMovie() : fDecodedSuccessfully(false), fLoaded(false), fMovieBuilt(false) {
34     fMovie.fMaker->fInMovie = true;
35 }
36 
~SkDisplayMovie()37 SkDisplayMovie::~SkDisplayMovie() {
38 }
39 
buildMovie()40 void SkDisplayMovie::buildMovie() {
41     if (fMovieBuilt)
42         return;
43     SkAnimateMaker* movieMaker = fMovie.fMaker;
44     SkAnimateMaker* parentMaker = movieMaker->fParentMaker;
45     if (src.size() == 0 || parentMaker == NULL)
46         return;
47     movieMaker->fPrefix.set(parentMaker->fPrefix);
48     fDecodedSuccessfully = fMovie.fMaker->decodeURI(src.c_str());
49     if (fDecodedSuccessfully == false) {
50 
51         if (movieMaker->getErrorCode() != SkXMLParserError::kNoError || movieMaker->getNativeCode() != -1) {
52             movieMaker->setInnerError(parentMaker, src);
53             parentMaker->setErrorCode(SkDisplayXMLParserError::kInMovie);
54         } else {
55             parentMaker->setErrorNoun(src);
56             parentMaker->setErrorCode(SkDisplayXMLParserError::kMovieNameUnknownOrMissing);
57         }
58     }
59     fMovieBuilt = true;
60 }
61 
deepCopy(SkAnimateMaker * maker)62 SkDisplayable* SkDisplayMovie::deepCopy(SkAnimateMaker* maker) {
63     SkDisplayMovie* copy = (SkDisplayMovie*) INHERITED::deepCopy(maker);
64     copy->fMovie.fMaker->fParentMaker = fMovie.fMaker->fParentMaker;
65     copy->fMovie.fMaker->fHostEventSinkID = fMovie.fMaker->fHostEventSinkID;
66     copy->fMovieBuilt = false;
67     *fMovie.fMaker->fParentMaker->fMovies.append() = copy;
68     return copy;
69 }
70 
dirty()71 void SkDisplayMovie::dirty() {
72     buildMovie();
73 }
74 
doEvent(SkDisplayEvent::Kind kind,SkEventState * state)75 bool SkDisplayMovie::doEvent(SkDisplayEvent::Kind kind, SkEventState* state) {
76     if (fLoaded == false)
77         return false;
78     fMovie.fMaker->fEnableTime = fMovie.fMaker->fParentMaker->fEnableTime;
79     return fMovie.fMaker->fEvents.doEvent(*fMovie.fMaker, kind, state);
80 }
81 
draw(SkAnimateMaker & maker)82 bool SkDisplayMovie::draw(SkAnimateMaker& maker) {
83     if (fDecodedSuccessfully == false)
84         return false;
85     if (fLoaded == false)
86         enable(maker);
87     maker.fCanvas->save();
88     SkPaint local = SkPaint(*maker.fPaint);
89     bool result = fMovie.draw(maker.fCanvas, &local,
90         maker.fDisplayList.getTime()) != SkAnimator::kNotDifferent;
91     maker.fDisplayList.fInvalBounds.join(fMovie.fMaker->fDisplayList.fInvalBounds);
92     maker.fCanvas->restore();
93     return result;
94 }
95 
96 #ifdef SK_DUMP_ENABLED
dump(SkAnimateMaker * maker)97 void SkDisplayMovie::dump(SkAnimateMaker* maker) {
98     dumpBase(maker);
99     SkDebugf("src=\"%s\"/>\n",  src.c_str());
100     SkAnimateMaker* movieMaker = fMovie.fMaker;
101     SkDisplayList::fIndent += 4;
102     movieMaker->fDisplayList.dumpInner(movieMaker);
103     SkDisplayList::fIndent -= 4;
104     dumpEnd(maker);
105 }
106 
dumpEvents()107 void SkDisplayMovie::dumpEvents() {
108     fMovie.fMaker->fEvents.dump(*fMovie.fMaker);
109 }
110 #endif
111 
enable(SkAnimateMaker & maker)112 bool SkDisplayMovie::enable(SkAnimateMaker& maker) {
113     if (fDecodedSuccessfully == false)
114         return false;
115     SkAnimateMaker* movieMaker = fMovie.fMaker;
116     movieMaker->fEvents.doEvent(*movieMaker, SkDisplayEvent::kOnload, NULL);
117     movieMaker->fEvents.removeEvent(SkDisplayEvent::kOnload, NULL);
118     fLoaded = true;
119     movieMaker->fLoaded = true;
120     return false;
121 }
122 
hasEnable() const123 bool SkDisplayMovie::hasEnable() const {
124     return true;
125 }
126 
onEndElement(SkAnimateMaker & maker)127 void SkDisplayMovie::onEndElement(SkAnimateMaker& maker) {
128 #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
129     fMovie.fMaker->fDebugTimeBase = maker.fDebugTimeBase;
130 #endif
131     fMovie.fMaker->fPrefix.set(maker.fPrefix);
132     fMovie.fMaker->fHostEventSinkID = maker.fHostEventSinkID;
133     fMovie.fMaker->fParentMaker = &maker;
134     buildMovie();
135     *maker.fMovies.append() = this;
136 }
137 
138 
139