• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkDisplayTypes.h"
11 #include "SkAnimateBase.h"
12 
canContainDependents() const13 bool SkDisplayDepend::canContainDependents() const {
14     return true;
15 }
16 
dirty()17 void SkDisplayDepend::dirty() {
18     SkDisplayable** last = fDependents.end();
19     for (SkDisplayable** depPtr = fDependents.begin(); depPtr < last; depPtr++) {
20         SkAnimateBase* animate = (SkAnimateBase* ) *depPtr;
21         animate->setChanged(true);
22     }
23 }
24 
25 // Boolean
26 #if SK_USE_CONDENSED_INFO == 0
27 
28 const SkMemberInfo SkDisplayBoolean::fInfo[] = {
29     SK_MEMBER(value, Boolean)
30 };
31 
32 #endif
33 
34 DEFINE_GET_MEMBER(SkDisplayBoolean);
35 
SkDisplayBoolean()36 SkDisplayBoolean::SkDisplayBoolean() : value(false) {
37 }
38 
39 #ifdef SK_DUMP_ENABLED
dump(SkAnimateMaker * maker)40 void SkDisplayBoolean::dump(SkAnimateMaker* maker){
41     dumpBase(maker);
42     SkDebugf("value=\"%s\" />\n", value ? "true" : "false");
43 }
44 #endif
45 
46 // int32_t
47 #if SK_USE_CONDENSED_INFO == 0
48 
49 const SkMemberInfo SkDisplayInt::fInfo[] = {
50     SK_MEMBER(value, Int)
51 };
52 
53 #endif
54 
55 DEFINE_GET_MEMBER(SkDisplayInt);
56 
SkDisplayInt()57 SkDisplayInt::SkDisplayInt() : value(0) {
58 }
59 
60 #ifdef SK_DUMP_ENABLED
dump(SkAnimateMaker * maker)61 void SkDisplayInt::dump(SkAnimateMaker* maker){
62     dumpBase(maker);
63     SkDebugf("value=\"%d\" />\n", value);
64 }
65 #endif
66 
67 // SkScalar
68 #if SK_USE_CONDENSED_INFO == 0
69 
70 const SkMemberInfo SkDisplayFloat::fInfo[] = {
71     SK_MEMBER(value, Float)
72 };
73 
74 #endif
75 
76 DEFINE_GET_MEMBER(SkDisplayFloat);
77 
SkDisplayFloat()78 SkDisplayFloat::SkDisplayFloat() : value(0) {
79 }
80 
81 #ifdef SK_DUMP_ENABLED
dump(SkAnimateMaker * maker)82 void SkDisplayFloat::dump(SkAnimateMaker* maker) {
83     dumpBase(maker);
84 #ifdef SK_CAN_USE_FLOAT
85     SkDebugf("value=\"%g\" />\n", SkScalarToFloat(value));
86 #else
87     SkDebugf("value=\"%x\" />\n", value);
88 #endif
89 }
90 #endif
91 
92 // SkString
93 enum SkDisplayString_Functions {
94     SK_FUNCTION(slice)
95 };
96 
97 enum SkDisplayString_Properties {
98     SK_PROPERTY(length)
99 };
100 
101 const SkFunctionParamType SkDisplayString::fFunctionParameters[] = {
102     (SkFunctionParamType) SkType_Int,   // slice
103     (SkFunctionParamType) SkType_Int,
104     (SkFunctionParamType) 0
105 };
106 
107 #if SK_USE_CONDENSED_INFO == 0
108 
109 const SkMemberInfo SkDisplayString::fInfo[] = {
110     SK_MEMBER_PROPERTY(length, Int),
111     SK_MEMBER_FUNCTION(slice, String),
112     SK_MEMBER(value, String)
113 };
114 
115 #endif
116 
117 DEFINE_GET_MEMBER(SkDisplayString);
118 
SkDisplayString()119 SkDisplayString::SkDisplayString() {
120 }
121 
SkDisplayString(SkString & copyFrom)122 SkDisplayString::SkDisplayString(SkString& copyFrom) : value(copyFrom) {
123 }
124 
executeFunction(SkDisplayable * target,int index,SkTDArray<SkScriptValue> & parameters,SkDisplayTypes type,SkScriptValue * scriptValue)125 void SkDisplayString::executeFunction(SkDisplayable* target, int index,
126         SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
127         SkScriptValue* scriptValue) {
128     if (scriptValue == NULL)
129         return;
130     SkASSERT(target == this);
131     switch (index) {
132         case SK_FUNCTION(slice):
133             scriptValue->fType = SkType_String;
134             SkASSERT(parameters[0].fType == SkType_Int);
135             int start =  parameters[0].fOperand.fS32;
136             if (start < 0)
137                 start = (int) (value.size() - start);
138             int end = (int) value.size();
139             if (parameters.count() > 1) {
140                 SkASSERT(parameters[1].fType == SkType_Int);
141                 end = parameters[1].fOperand.fS32;
142             }
143             //if (end >= 0 && end < (int) value.size())
144             if (end >= 0 && end <= (int) value.size())
145                 scriptValue->fOperand.fString = new SkString(&value.c_str()[start], end - start);
146             else
147                 scriptValue->fOperand.fString = new SkString(value);
148         break;
149     }
150 }
151 
getFunctionsParameters()152 const SkFunctionParamType* SkDisplayString::getFunctionsParameters() {
153     return fFunctionParameters;
154 }
155 
getProperty(int index,SkScriptValue * scriptValue) const156 bool SkDisplayString::getProperty(int index, SkScriptValue* scriptValue) const {
157     switch (index) {
158         case SK_PROPERTY(length):
159             scriptValue->fType = SkType_Int;
160             scriptValue->fOperand.fS32 = (int32_t) value.size();
161             break;
162         default:
163             SkASSERT(0);
164             return false;
165     }
166     return true;
167 }
168 
169 
170 // SkArray
171 #if 0   // !!! reason enough to qualify enum with class name or move typedArray into its own file
172 enum SkDisplayArray_Properties {
173     SK_PROPERTY(length)
174 };
175 #endif
176 
177 #if SK_USE_CONDENSED_INFO == 0
178 
179 const SkMemberInfo SkDisplayArray::fInfo[] = {
180     SK_MEMBER_PROPERTY(length, Int),
181     SK_MEMBER_ARRAY(values, Unknown)
182 };
183 
184 #endif
185 
186 DEFINE_GET_MEMBER(SkDisplayArray);
187 
SkDisplayArray()188 SkDisplayArray::SkDisplayArray() {
189 }
190 
SkDisplayArray(SkTypedArray & copyFrom)191 SkDisplayArray::SkDisplayArray(SkTypedArray& copyFrom) : values(copyFrom) {
192 
193 }
194 
~SkDisplayArray()195 SkDisplayArray::~SkDisplayArray() {
196     if (values.getType() == SkType_String) {
197         for (int index = 0; index < values.count(); index++)
198             delete values[index].fString;
199         return;
200     }
201     if (values.getType() == SkType_Array) {
202         for (int index = 0; index < values.count(); index++)
203             delete values[index].fArray;
204     }
205 }
206 
getProperty(int index,SkScriptValue * value) const207 bool SkDisplayArray::getProperty(int index, SkScriptValue* value) const {
208     switch (index) {
209         case SK_PROPERTY(length):
210             value->fType = SkType_Int;
211             value->fOperand.fS32 = values.count();
212             break;
213         default:
214             SkASSERT(0);
215             return false;
216     }
217     return true;
218 }
219 
220 
221 
222