• 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     SkDebugf("value=\"%g\" />\n", SkScalarToFloat(value));
85 }
86 #endif
87 
88 // SkString
89 enum SkDisplayString_Functions {
90     SK_FUNCTION(slice)
91 };
92 
93 enum SkDisplayString_Properties {
94     SK_PROPERTY(length)
95 };
96 
97 const SkFunctionParamType SkDisplayString::fFunctionParameters[] = {
98     (SkFunctionParamType) SkType_Int,   // slice
99     (SkFunctionParamType) SkType_Int,
100     (SkFunctionParamType) 0
101 };
102 
103 #if SK_USE_CONDENSED_INFO == 0
104 
105 const SkMemberInfo SkDisplayString::fInfo[] = {
106     SK_MEMBER_PROPERTY(length, Int),
107     SK_MEMBER_FUNCTION(slice, String),
108     SK_MEMBER(value, String)
109 };
110 
111 #endif
112 
113 DEFINE_GET_MEMBER(SkDisplayString);
114 
SkDisplayString()115 SkDisplayString::SkDisplayString() {
116 }
117 
SkDisplayString(SkString & copyFrom)118 SkDisplayString::SkDisplayString(SkString& copyFrom) : value(copyFrom) {
119 }
120 
executeFunction(SkDisplayable * target,int index,SkTDArray<SkScriptValue> & parameters,SkDisplayTypes type,SkScriptValue * scriptValue)121 void SkDisplayString::executeFunction(SkDisplayable* target, int index,
122         SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
123         SkScriptValue* scriptValue) {
124     if (scriptValue == nullptr)
125         return;
126     SkASSERT(target == this);
127     switch (index) {
128         case SK_FUNCTION(slice):
129             scriptValue->fType = SkType_String;
130             SkASSERT(parameters[0].fType == SkType_Int);
131             int start =  parameters[0].fOperand.fS32;
132             if (start < 0)
133                 start = (int) (value.size() - start);
134             int end = (int) value.size();
135             if (parameters.count() > 1) {
136                 SkASSERT(parameters[1].fType == SkType_Int);
137                 end = parameters[1].fOperand.fS32;
138             }
139             //if (end >= 0 && end < (int) value.size())
140             if (end >= 0 && end <= (int) value.size())
141                 scriptValue->fOperand.fString = new SkString(&value.c_str()[start], end - start);
142             else
143                 scriptValue->fOperand.fString = new SkString(value);
144         break;
145     }
146 }
147 
getFunctionsParameters()148 const SkFunctionParamType* SkDisplayString::getFunctionsParameters() {
149     return fFunctionParameters;
150 }
151 
getProperty(int index,SkScriptValue * scriptValue) const152 bool SkDisplayString::getProperty(int index, SkScriptValue* scriptValue) const {
153     switch (index) {
154         case SK_PROPERTY(length):
155             scriptValue->fType = SkType_Int;
156             scriptValue->fOperand.fS32 = (int32_t) value.size();
157             break;
158         default:
159             SkASSERT(0);
160             return false;
161     }
162     return true;
163 }
164 
165 
166 // SkArray
167 #if 0   // !!! reason enough to qualify enum with class name or move typedArray into its own file
168 enum SkDisplayArray_Properties {
169     SK_PROPERTY(length)
170 };
171 #endif
172 
173 #if SK_USE_CONDENSED_INFO == 0
174 
175 const SkMemberInfo SkDisplayArray::fInfo[] = {
176     SK_MEMBER_PROPERTY(length, Int),
177     SK_MEMBER_ARRAY(values, Unknown)
178 };
179 
180 #endif
181 
182 DEFINE_GET_MEMBER(SkDisplayArray);
183 
SkDisplayArray()184 SkDisplayArray::SkDisplayArray() {
185 }
186 
SkDisplayArray(SkTypedArray & copyFrom)187 SkDisplayArray::SkDisplayArray(SkTypedArray& copyFrom) : values(copyFrom) {
188 
189 }
190 
~SkDisplayArray()191 SkDisplayArray::~SkDisplayArray() {
192     if (values.getType() == SkType_String) {
193         for (int index = 0; index < values.count(); index++)
194             delete values[index].fString;
195         return;
196     }
197     if (values.getType() == SkType_Array) {
198         for (int index = 0; index < values.count(); index++)
199             delete values[index].fArray;
200     }
201 }
202 
getProperty(int index,SkScriptValue * value) const203 bool SkDisplayArray::getProperty(int index, SkScriptValue* value) const {
204     switch (index) {
205         case SK_PROPERTY(length):
206             value->fType = SkType_Int;
207             value->fOperand.fS32 = values.count();
208             break;
209         default:
210             SkASSERT(0);
211             return false;
212     }
213     return true;
214 }
215