gfx/skia/trunk/src/animator/SkDump.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 "SkDump.h"
michael@0 11
michael@0 12 #ifdef SK_DUMP_ENABLED
michael@0 13
michael@0 14 #include "SkAnimateMaker.h"
michael@0 15 #include "SkAnimatorScript.h"
michael@0 16 #include "SkDisplayEvents.h"
michael@0 17 #include "SkDisplayList.h"
michael@0 18 #include "SkString.h"
michael@0 19
michael@0 20 #if SK_USE_CONDENSED_INFO == 0
michael@0 21
michael@0 22 const SkMemberInfo SkDump::fInfo[] = {
michael@0 23 SK_MEMBER(displayList, Boolean),
michael@0 24 SK_MEMBER(eventList, Boolean),
michael@0 25 SK_MEMBER(events, Boolean),
michael@0 26 SK_MEMBER(groups, Boolean),
michael@0 27 SK_MEMBER(name, String),
michael@0 28 SK_MEMBER(posts, Boolean),
michael@0 29 SK_MEMBER(script, String)
michael@0 30 };
michael@0 31
michael@0 32 #endif
michael@0 33
michael@0 34 DEFINE_GET_MEMBER(SkDump);
michael@0 35
michael@0 36 SkDump::SkDump() : displayList(-1), eventList(-1), events(-1), groups(-1), posts(-1) {
michael@0 37 }
michael@0 38
michael@0 39 bool SkDump::enable(SkAnimateMaker& maker ) {
michael@0 40 if (script.size() > 0)
michael@0 41 return evaluate(maker);
michael@0 42 bool hasAttr = false;
michael@0 43 if (events > 0)
michael@0 44 hasAttr |= maker.fDumpEvents = true;
michael@0 45 if (posts > 0)
michael@0 46 hasAttr |= maker.fDumpPosts = true;
michael@0 47 if (groups > 0)
michael@0 48 hasAttr |= maker.fDumpGConditions = true;
michael@0 49 if ((hasAttr |= (eventList > 0)) == true)
michael@0 50 maker.fEvents.dump(maker);
michael@0 51 if ((hasAttr |= (name.size() > 0)) == true)
michael@0 52 maker.dump(name.c_str());
michael@0 53 if (displayList > 0 || (displayList != 0 && hasAttr == false))
michael@0 54 maker.fDisplayList.dump(&maker);
michael@0 55 return true;
michael@0 56 }
michael@0 57
michael@0 58 bool SkDump::evaluate(SkAnimateMaker &maker) {
michael@0 59 SkAnimatorScript scriptEngine(maker, NULL, SkType_Int);
michael@0 60 SkScriptValue value;
michael@0 61 const char* cScript = script.c_str();
michael@0 62 bool success = scriptEngine.evaluateScript(&cScript, &value);
michael@0 63 SkDebugf("%*s<dump script=\"%s\" answer=\" ", SkDisplayList::fIndent, "", script.c_str());
michael@0 64 if (success == false) {
michael@0 65 SkDebugf("INVALID\" />\n");
michael@0 66 return false;
michael@0 67 }
michael@0 68 switch (value.fType) {
michael@0 69 case SkType_Float:
michael@0 70 SkDebugf("%g\" />\n", SkScalarToFloat(value.fOperand.fScalar));
michael@0 71 break;
michael@0 72 case SkType_Int:
michael@0 73 SkDebugf("%d\" />\n", value.fOperand.fS32);
michael@0 74 break;
michael@0 75 case SkType_String:
michael@0 76 SkDebugf("%s\" />\n", value.fOperand.fString->c_str());
michael@0 77 break;
michael@0 78 default:
michael@0 79 return false;
michael@0 80 }
michael@0 81 return true;
michael@0 82 }
michael@0 83
michael@0 84 bool SkDump::hasEnable() const {
michael@0 85 return true;
michael@0 86 }
michael@0 87
michael@0 88 void SkDump::GetEnumString(SkDisplayTypes type, int index, SkString* result) {
michael@0 89 int badEnum = index;
michael@0 90 const SkDisplayEnumMap& map = SkAnimatorScript::GetEnumValues(type);
michael@0 91 const char* str = map.fValues;
michael@0 92 while (--index >= 0) {
michael@0 93 str = strchr(str, '|');
michael@0 94 if (str == NULL) {
michael@0 95 result->reset();
michael@0 96 result->appendS32(badEnum);
michael@0 97 return;
michael@0 98 }
michael@0 99 str += 1;
michael@0 100 }
michael@0 101 const char* end = strchr(str, '|');
michael@0 102 if (end == NULL)
michael@0 103 end = str + strlen(str);
michael@0 104 result->set(str, end - str);
michael@0 105 }
michael@0 106
michael@0 107 #else
michael@0 108
michael@0 109 // in the release version, <dump> is allowed, and its attributes are defined, but
michael@0 110 // are not stored and have no effect
michael@0 111
michael@0 112 #if SK_USE_CONDENSED_INFO == 0
michael@0 113
michael@0 114 enum SkDump_Properties {
michael@0 115 SK_PROPERTY(displayList),
michael@0 116 SK_PROPERTY(eventList),
michael@0 117 SK_PROPERTY(events),
michael@0 118 SK_PROPERTY(groups),
michael@0 119 SK_PROPERTY(name),
michael@0 120 SK_PROPERTY(posts),
michael@0 121 SK_PROPERTY(script)
michael@0 122 };
michael@0 123
michael@0 124 const SkMemberInfo SkDump::fInfo[] = {
michael@0 125 SK_MEMBER_PROPERTY(displayList, Boolean),
michael@0 126 SK_MEMBER_PROPERTY(eventList, Boolean),
michael@0 127 SK_MEMBER_PROPERTY(events, Boolean),
michael@0 128 SK_MEMBER_PROPERTY(groups, Boolean),
michael@0 129 SK_MEMBER_PROPERTY(name, String),
michael@0 130 SK_MEMBER_PROPERTY(posts, Boolean),
michael@0 131 SK_MEMBER_PROPERTY(script, String)
michael@0 132 };
michael@0 133
michael@0 134 #endif
michael@0 135
michael@0 136 DEFINE_GET_MEMBER(SkDump);
michael@0 137
michael@0 138 bool SkDump::enable(SkAnimateMaker&) {
michael@0 139 return true;
michael@0 140 }
michael@0 141
michael@0 142 bool SkDump::hasEnable() const {
michael@0 143 return true;
michael@0 144 }
michael@0 145
michael@0 146 bool SkDump::setProperty(int index, SkScriptValue&) {
michael@0 147 return index <= SK_PROPERTY(posts);
michael@0 148 }
michael@0 149
michael@0 150 #endif

mercurial