blob: 9f297e9d58812ee3ad120e3be38a9ab3c53f9319 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
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());
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +000053 if (displayList > 0 || (displayList != 0 && hasAttr == false))
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 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
sugoi@google.com93c7ee32013-03-12 14:36:57 +0000138bool SkDump::enable(SkAnimateMaker&) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000139 return true;
140}
141
142bool SkDump::hasEnable() const {
143 return true;
144}
145
sugoi@google.com93c7ee32013-03-12 14:36:57 +0000146bool SkDump::setProperty(int index, SkScriptValue&) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000147 return index <= SK_PROPERTY(posts);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000148}
149
150#endif