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