gfx/skia/trunk/src/animator/SkDisplayPost.cpp

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkDisplayPost.h"
michael@0 11 #include "SkAnimateMaker.h"
michael@0 12 #include "SkAnimator.h"
michael@0 13 #include "SkDisplayMovie.h"
michael@0 14 #include "SkPostParts.h"
michael@0 15 #include "SkScript.h"
michael@0 16 #ifdef SK_DEBUG
michael@0 17 #include "SkDump.h"
michael@0 18 #include "SkTime.h"
michael@0 19 #endif
michael@0 20
michael@0 21 enum SkPost_Properties {
michael@0 22 SK_PROPERTY(target),
michael@0 23 SK_PROPERTY(type)
michael@0 24 };
michael@0 25
michael@0 26 #if SK_USE_CONDENSED_INFO == 0
michael@0 27
michael@0 28 const SkMemberInfo SkPost::fInfo[] = {
michael@0 29 SK_MEMBER(delay, MSec),
michael@0 30 // SK_MEMBER(initialized, Boolean),
michael@0 31 SK_MEMBER(mode, EventMode),
michael@0 32 SK_MEMBER(sink, String),
michael@0 33 SK_MEMBER_PROPERTY(target, String),
michael@0 34 SK_MEMBER_PROPERTY(type, String)
michael@0 35 };
michael@0 36
michael@0 37 #endif
michael@0 38
michael@0 39 DEFINE_GET_MEMBER(SkPost);
michael@0 40
michael@0 41 SkPost::SkPost() : delay(0), /*initialized(SkBool(-1)), */ mode(kImmediate), fMaker(NULL),
michael@0 42 fSinkID(0), fTargetMaker(NULL), fChildHasID(false), fDirty(false) {
michael@0 43 }
michael@0 44
michael@0 45 SkPost::~SkPost() {
michael@0 46 for (SkDataInput** part = fParts.begin(); part < fParts.end(); part++)
michael@0 47 delete *part;
michael@0 48 }
michael@0 49
michael@0 50 bool SkPost::addChild(SkAnimateMaker& , SkDisplayable* child) {
michael@0 51 SkASSERT(child && child->isDataInput());
michael@0 52 SkDataInput* part = (SkDataInput*) child;
michael@0 53 *fParts.append() = part;
michael@0 54 return true;
michael@0 55 }
michael@0 56
michael@0 57 bool SkPost::childrenNeedDisposing() const {
michael@0 58 return false;
michael@0 59 }
michael@0 60
michael@0 61 void SkPost::dirty() {
michael@0 62 fDirty = true;
michael@0 63 }
michael@0 64
michael@0 65 #ifdef SK_DUMP_ENABLED
michael@0 66 void SkPost::dump(SkAnimateMaker* maker) {
michael@0 67 dumpBase(maker);
michael@0 68 SkString* eventType = new SkString();
michael@0 69 fEvent.getType(eventType);
michael@0 70 if (eventType->equals("user")) {
michael@0 71 const char* target = fEvent.findString("id");
michael@0 72 SkDebugf("target=\"%s\" ", target);
michael@0 73 }
michael@0 74 else
michael@0 75 SkDebugf("type=\"%s\" ", eventType->c_str());
michael@0 76 delete eventType;
michael@0 77
michael@0 78 if (delay > 0) {
michael@0 79 SkDebugf("delay=\"%g\" ", SkScalarToFloat(SkScalarDiv(delay, 1000)));
michael@0 80 }
michael@0 81 // if (initialized == false)
michael@0 82 // SkDebugf("(uninitialized) ");
michael@0 83 SkString string;
michael@0 84 SkDump::GetEnumString(SkType_EventMode, mode, &string);
michael@0 85 if (!string.equals("immediate"))
michael@0 86 SkDebugf("mode=\"%s\" ", string.c_str());
michael@0 87 // !!! could enhance this to search through make hierarchy to show name of sink
michael@0 88 if (sink.size() > 0) {
michael@0 89 SkDebugf("sink=\"%s\" sinkID=\"%d\" ", sink.c_str(), fSinkID);
michael@0 90 } else if (fSinkID != maker->getAnimator()->getSinkID() && fSinkID != 0) {
michael@0 91 SkDebugf("sinkID=\"%d\" ", fSinkID);
michael@0 92 }
michael@0 93 const SkMetaData& meta = fEvent.getMetaData();
michael@0 94 SkMetaData::Iter iter(meta);
michael@0 95 SkMetaData::Type type;
michael@0 96 int number;
michael@0 97 const char* name;
michael@0 98 bool closedYet = false;
michael@0 99 SkDisplayList::fIndent += 4;
michael@0 100 //this seems to work, but kinda hacky
michael@0 101 //for some reason the last part is id, which i don't want
michael@0 102 //and the parts seem to be in the reverse order from the one in which we find the
michael@0 103 //data itself
michael@0 104 //SkDataInput** ptr = fParts.end();
michael@0 105 //SkDataInput* data;
michael@0 106 //const char* ID;
michael@0 107 while ((name = iter.next(&type, &number)) != NULL) {
michael@0 108 //ptr--;
michael@0 109 if (strcmp(name, "id") == 0)
michael@0 110 continue;
michael@0 111 if (closedYet == false) {
michael@0 112 SkDebugf(">\n");
michael@0 113 closedYet = true;
michael@0 114 }
michael@0 115 //data = *ptr;
michael@0 116 //if (data->id)
michael@0 117 // ID = data->id;
michael@0 118 //else
michael@0 119 // ID = "";
michael@0 120 SkDebugf("%*s<data name=\"%s\" ", SkDisplayList::fIndent, "", name);
michael@0 121 switch (type) {
michael@0 122 case SkMetaData::kS32_Type: {
michael@0 123 int32_t s32;
michael@0 124 meta.findS32(name, &s32);
michael@0 125 SkDebugf("int=\"%d\" ", s32);
michael@0 126 } break;
michael@0 127 case SkMetaData::kScalar_Type: {
michael@0 128 SkScalar scalar;
michael@0 129 meta.findScalar(name, &scalar);
michael@0 130 SkDebugf("float=\"%g\" ", SkScalarToFloat(scalar));
michael@0 131 } break;
michael@0 132 case SkMetaData::kString_Type:
michael@0 133 SkDebugf("string=\"%s\" ", meta.findString(name));
michael@0 134 break;
michael@0 135 case SkMetaData::kPtr_Type: {//when do we have a pointer
michael@0 136 void* ptr;
michael@0 137 meta.findPtr(name, &ptr);
michael@0 138 SkDebugf("0x%08x ", ptr);
michael@0 139 } break;
michael@0 140 case SkMetaData::kBool_Type: {
michael@0 141 bool boolean;
michael@0 142 meta.findBool(name, &boolean);
michael@0 143 SkDebugf("boolean=\"%s\" ", boolean ? "true " : "false ");
michael@0 144 } break;
michael@0 145 default:
michael@0 146 break;
michael@0 147 }
michael@0 148 SkDebugf("/>\n");
michael@0 149 //ptr++;
michael@0 150 /* perhaps this should only be done in the case of a pointer?
michael@0 151 SkDisplayable* displayable;
michael@0 152 if (maker->find(name, &displayable))
michael@0 153 displayable->dump(maker);
michael@0 154 else
michael@0 155 SkDebugf("\n");*/
michael@0 156 }
michael@0 157 SkDisplayList::fIndent -= 4;
michael@0 158 if (closedYet)
michael@0 159 dumpEnd(maker);
michael@0 160 else
michael@0 161 SkDebugf("/>\n");
michael@0 162
michael@0 163 }
michael@0 164 #endif
michael@0 165
michael@0 166 bool SkPost::enable(SkAnimateMaker& maker ) {
michael@0 167 if (maker.hasError())
michael@0 168 return true;
michael@0 169 if (fDirty) {
michael@0 170 if (sink.size() > 0)
michael@0 171 findSinkID();
michael@0 172 if (fChildHasID) {
michael@0 173 SkString preserveID(fEvent.findString("id"));
michael@0 174 fEvent.getMetaData().reset();
michael@0 175 if (preserveID.size() > 0)
michael@0 176 fEvent.setString("id", preserveID);
michael@0 177 for (SkDataInput** part = fParts.begin(); part < fParts.end(); part++) {
michael@0 178 if ((*part)->add())
michael@0 179 maker.setErrorCode(SkDisplayXMLParserError::kErrorAddingDataToPost);
michael@0 180 }
michael@0 181 }
michael@0 182 fDirty = false;
michael@0 183 }
michael@0 184 #ifdef SK_DUMP_ENABLED
michael@0 185 if (maker.fDumpPosts) {
michael@0 186 SkDebugf("post enable: ");
michael@0 187 dump(&maker);
michael@0 188 }
michael@0 189 #if defined SK_DEBUG_ANIMATION_TIMING
michael@0 190 SkString debugOut;
michael@0 191 SkMSec time = maker.getAppTime();
michael@0 192 debugOut.appendS32(time - maker.fDebugTimeBase);
michael@0 193 debugOut.append(" post id=");
michael@0 194 debugOut.append(_id);
michael@0 195 debugOut.append(" enable=");
michael@0 196 debugOut.appendS32(maker.fEnableTime - maker.fDebugTimeBase);
michael@0 197 debugOut.append(" delay=");
michael@0 198 debugOut.appendS32(delay);
michael@0 199 #endif
michael@0 200 #endif
michael@0 201 // SkMSec adjustedDelay = maker.adjustDelay(maker.fEnableTime, delay);
michael@0 202 SkMSec futureTime = maker.fEnableTime + delay;
michael@0 203 fEvent.setFast32(futureTime);
michael@0 204 #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
michael@0 205 debugOut.append(" future=");
michael@0 206 debugOut.appendS32(futureTime - maker.fDebugTimeBase);
michael@0 207 SkDebugf("%s\n", debugOut.c_str());
michael@0 208 #endif
michael@0 209 SkEventSinkID targetID = fSinkID;
michael@0 210 bool isAnimatorEvent = true;
michael@0 211 SkAnimator* anim = maker.getAnimator();
michael@0 212 if (targetID == 0) {
michael@0 213 isAnimatorEvent = fEvent.findString("id") != NULL;
michael@0 214 if (isAnimatorEvent)
michael@0 215 targetID = anim->getSinkID();
michael@0 216 else if (maker.fHostEventSinkID)
michael@0 217 targetID = maker.fHostEventSinkID;
michael@0 218 else
michael@0 219 return true;
michael@0 220 } else
michael@0 221 anim = fTargetMaker->getAnimator();
michael@0 222 if (delay == 0) {
michael@0 223 if (isAnimatorEvent && mode == kImmediate)
michael@0 224 fTargetMaker->doEvent(fEvent);
michael@0 225 else
michael@0 226 anim->onEventPost(new SkEvent(fEvent), targetID);
michael@0 227 } else
michael@0 228 anim->onEventPostTime(new SkEvent(fEvent), targetID, futureTime);
michael@0 229 return true;
michael@0 230 }
michael@0 231
michael@0 232 void SkPost::findSinkID() {
michael@0 233 // get the next delimiter '.' if any
michael@0 234 fTargetMaker = fMaker;
michael@0 235 const char* ch = sink.c_str();
michael@0 236 do {
michael@0 237 const char* end = strchr(ch, '.');
michael@0 238 size_t len = end ? (size_t) (end - ch) : strlen(ch);
michael@0 239 SkDisplayable* displayable = NULL;
michael@0 240 if (SK_LITERAL_STR_EQUAL("parent", ch, len)) {
michael@0 241 if (fTargetMaker->fParentMaker)
michael@0 242 fTargetMaker = fTargetMaker->fParentMaker;
michael@0 243 else {
michael@0 244 fTargetMaker->setErrorCode(SkDisplayXMLParserError::kNoParentAvailable);
michael@0 245 return;
michael@0 246 }
michael@0 247 } else {
michael@0 248 fTargetMaker->find(ch, len, &displayable);
michael@0 249 if (displayable == NULL || displayable->getType() != SkType_Movie) {
michael@0 250 fTargetMaker->setErrorCode(SkDisplayXMLParserError::kExpectedMovie);
michael@0 251 return;
michael@0 252 }
michael@0 253 SkDisplayMovie* movie = (SkDisplayMovie*) displayable;
michael@0 254 fTargetMaker = movie->fMovie.fMaker;
michael@0 255 }
michael@0 256 if (end == NULL)
michael@0 257 break;
michael@0 258 ch = ++end;
michael@0 259 } while (true);
michael@0 260 SkAnimator* anim = fTargetMaker->getAnimator();
michael@0 261 fSinkID = anim->getSinkID();
michael@0 262 }
michael@0 263
michael@0 264 bool SkPost::hasEnable() const {
michael@0 265 return true;
michael@0 266 }
michael@0 267
michael@0 268 void SkPost::onEndElement(SkAnimateMaker& maker) {
michael@0 269 fTargetMaker = fMaker = &maker;
michael@0 270 if (fChildHasID == false) {
michael@0 271 for (SkDataInput** part = fParts.begin(); part < fParts.end(); part++)
michael@0 272 delete *part;
michael@0 273 fParts.reset();
michael@0 274 }
michael@0 275 }
michael@0 276
michael@0 277 void SkPost::setChildHasID() {
michael@0 278 fChildHasID = true;
michael@0 279 }
michael@0 280
michael@0 281 bool SkPost::setProperty(int index, SkScriptValue& value) {
michael@0 282 SkASSERT(value.fType == SkType_String);
michael@0 283 SkString* string = value.fOperand.fString;
michael@0 284 switch(index) {
michael@0 285 case SK_PROPERTY(target): {
michael@0 286 fEvent.setType("user");
michael@0 287 fEvent.setString("id", *string);
michael@0 288 mode = kImmediate;
michael@0 289 } break;
michael@0 290 case SK_PROPERTY(type):
michael@0 291 fEvent.setType(*string);
michael@0 292 break;
michael@0 293 default:
michael@0 294 SkASSERT(0);
michael@0 295 return false;
michael@0 296 }
michael@0 297 return true;
michael@0 298 }

mercurial