OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkTypes.h" | 10 #include "SkTypes.h" |
11 #if defined SK_BUILD_CONDENSED | 11 #if defined SK_BUILD_CONDENSED |
12 #include "SkMemberInfo.h" | 12 #include "SkMemberInfo.h" |
13 #if SK_USE_CONDENSED_INFO == 1 | 13 #if SK_USE_CONDENSED_INFO == 1 |
14 #error "SK_USE_CONDENSED_INFO must be zero to build condensed info" | 14 #error "SK_USE_CONDENSED_INFO must be zero to build condensed info" |
15 #endif | 15 #endif |
16 #if !defined SK_BUILD_FOR_WIN32 | 16 #if !defined SK_BUILD_FOR_WIN32 |
17 #error "SK_BUILD_FOR_WIN32 must be defined to build condensed info" | 17 #error "SK_BUILD_FOR_WIN32 must be defined to build condensed info" |
18 #endif | 18 #endif |
19 #include "SkDisplayType.h" | 19 #include "SkDisplayType.h" |
20 #include "SkIntArray.h" | 20 #include "SkIntArray.h" |
21 #include <stdio.h> | 21 #include <stdio.h> |
22 | 22 |
23 SkTDMemberInfoArray gInfos; | 23 SkTDMemberInfoArray gInfos; |
24 SkTDIntArray gInfosCounts; | 24 SkTDIntArray gInfosCounts; |
25 SkTDDisplayTypesArray gInfosTypeIDs; | 25 SkTDDisplayTypesArray gInfosTypeIDs; |
26 SkTDMemberInfoArray gUnknowns; | 26 SkTDMemberInfoArray gUnknowns; |
27 SkTDIntArray gUnknownsCounts; | 27 SkTDIntArray gUnknownsCounts; |
28 | 28 |
29 static void AddInfo(SkDisplayTypes type, const SkMemberInfo* info, int infoCount
) { | 29 static void AddInfo(SkDisplayTypes type, const SkMemberInfo* info, int infoCount
) { |
30 SkASSERT(gInfos[type] == NULL); | 30 SkASSERT(gInfos[type] == nullptr); |
31 gInfos[type] = info; | 31 gInfos[type] = info; |
32 gInfosCounts[type] = infoCount; | 32 gInfosCounts[type] = infoCount; |
33 *gInfosTypeIDs.append() = type; | 33 *gInfosTypeIDs.append() = type; |
34 size_t allStrs = 0; | 34 size_t allStrs = 0; |
35 for (int inner = 0; inner < infoCount; inner++) { | 35 for (int inner = 0; inner < infoCount; inner++) { |
36 SkASSERT(info[inner].fCount < 256); | 36 SkASSERT(info[inner].fCount < 256); |
37 int offset = (int) info[inner].fOffset; | 37 int offset = (int) info[inner].fOffset; |
38 SkASSERT(offset < 128 && offset > -129); | 38 SkASSERT(offset < 128 && offset > -129); |
39 SkASSERT(allStrs < 256); | 39 SkASSERT(allStrs < 256); |
40 if (info[inner].fType == SkType_BaseClassInfo) { | 40 if (info[inner].fType == SkType_BaseClassInfo) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 void SkDisplayType::BuildCondensedInfo(SkAnimateMaker* maker) { | 105 void SkDisplayType::BuildCondensedInfo(SkAnimateMaker* maker) { |
106 gInfos.setCount(kNumberOfTypes); | 106 gInfos.setCount(kNumberOfTypes); |
107 memset(gInfos.begin(), 0, sizeof(gInfos[0]) * kNumberOfTypes); | 107 memset(gInfos.begin(), 0, sizeof(gInfos[0]) * kNumberOfTypes); |
108 gInfosCounts.setCount(kNumberOfTypes); | 108 gInfosCounts.setCount(kNumberOfTypes); |
109 memset(gInfosCounts.begin(), -1, sizeof(gInfosCounts[0]) * kNumberOfTypes); | 109 memset(gInfosCounts.begin(), -1, sizeof(gInfosCounts[0]) * kNumberOfTypes); |
110 // check to see if it is condensable | 110 // check to see if it is condensable |
111 int index, infoCount; | 111 int index, infoCount; |
112 for (index = 0; index < kTypeNamesSize; index++) { | 112 for (index = 0; index < kTypeNamesSize; index++) { |
113 const SkMemberInfo* info = GetMembers(maker, gTypeNames[index].fType, &i
nfoCount); | 113 const SkMemberInfo* info = GetMembers(maker, gTypeNames[index].fType, &i
nfoCount); |
114 if (info == NULL) | 114 if (info == nullptr) |
115 continue; | 115 continue; |
116 AddInfo(gTypeNames[index].fType, info, infoCount); | 116 AddInfo(gTypeNames[index].fType, info, infoCount); |
117 } | 117 } |
118 const SkMemberInfo* extraInfo = | 118 const SkMemberInfo* extraInfo = |
119 SkDisplayType::GetMembers(maker, SkType_3D_Point, &infoCount); | 119 SkDisplayType::GetMembers(maker, SkType_3D_Point, &infoCount); |
120 AddInfo(SkType_Point, extraInfo, infoCount); | 120 AddInfo(SkType_Point, extraInfo, infoCount); |
121 AddInfo(SkType_3D_Point, extraInfo, infoCount); | 121 AddInfo(SkType_3D_Point, extraInfo, infoCount); |
122 // int baseInfos = gInfos.count(); | 122 // int baseInfos = gInfos.count(); |
123 do { | 123 do { |
124 SkTDMemberInfoArray oldRefs = gUnknowns; | 124 SkTDMemberInfoArray oldRefs = gUnknowns; |
125 SkTDIntArray oldRefCounts = gUnknownsCounts; | 125 SkTDIntArray oldRefCounts = gUnknownsCounts; |
126 gUnknowns.reset(); | 126 gUnknowns.reset(); |
127 gUnknownsCounts.reset(); | 127 gUnknownsCounts.reset(); |
128 for (index = 0; index < oldRefs.count(); index++) { | 128 for (index = 0; index < oldRefs.count(); index++) { |
129 const SkMemberInfo* info = oldRefs[index]; | 129 const SkMemberInfo* info = oldRefs[index]; |
130 if (gInfos.find(info) == -1) { | 130 if (gInfos.find(info) == -1) { |
131 int typeIndex = 0; | 131 int typeIndex = 0; |
132 for (; typeIndex < kNumberOfTypes; typeIndex++) { | 132 for (; typeIndex < kNumberOfTypes; typeIndex++) { |
133 const SkMemberInfo* temp = SkDisplayType::GetMembers( | 133 const SkMemberInfo* temp = SkDisplayType::GetMembers( |
134 maker, (SkDisplayTypes) typeIndex, NULL); | 134 maker, (SkDisplayTypes) typeIndex, nullptr); |
135 if (temp == info) | 135 if (temp == info) |
136 break; | 136 break; |
137 } | 137 } |
138 SkASSERT(typeIndex < kNumberOfTypes); | 138 SkASSERT(typeIndex < kNumberOfTypes); |
139 AddInfo((SkDisplayTypes) typeIndex, info, oldRefCounts[index]); | 139 AddInfo((SkDisplayTypes) typeIndex, info, oldRefCounts[index]); |
140 } | 140 } |
141 } | 141 } |
142 } while (gUnknowns.count() > 0); | 142 } while (gUnknowns.count() > 0); |
143 qsort(gInfosTypeIDs.begin(), gInfosTypeIDs.count(), sizeof(gInfosTypeIDs[0])
, &type_compare); | 143 qsort(gInfosTypeIDs.begin(), gInfosTypeIDs.count(), sizeof(gInfosTypeIDs[0])
, &type_compare); |
144 #ifdef SK_DEBUG | 144 #ifdef SK_DEBUG |
145 FILE* condensed = fopen("../../src/animator/SkCondensedDebug.cpp", "w+"); | 145 FILE* condensed = fopen("../../src/animator/SkCondensedDebug.cpp", "w+"); |
146 fprintf(condensed, "#include \"SkTypes.h\"\n"); | 146 fprintf(condensed, "#include \"SkTypes.h\"\n"); |
147 fprintf(condensed, "#ifdef SK_DEBUG\n"); | 147 fprintf(condensed, "#ifdef SK_DEBUG\n"); |
148 #else | 148 #else |
149 FILE* condensed = fopen("../../src/animator/SkCondensedRelease.cpp", "w+"); | 149 FILE* condensed = fopen("../../src/animator/SkCondensedRelease.cpp", "w+"); |
150 fprintf(condensed, "#include \"SkTypes.h\"\n"); | 150 fprintf(condensed, "#include \"SkTypes.h\"\n"); |
151 fprintf(condensed, "#ifdef SK_RELEASE\n"); | 151 fprintf(condensed, "#ifdef SK_RELEASE\n"); |
152 #endif | 152 #endif |
153 // write header | 153 // write header |
154 fprintf(condensed, "// This file was automatically generated.\n"); | 154 fprintf(condensed, "// This file was automatically generated.\n"); |
155 fprintf(condensed, "// To change it, edit the file with the matching debug i
nfo.\n"); | 155 fprintf(condensed, "// To change it, edit the file with the matching debug i
nfo.\n"); |
156 fprintf(condensed, "// Then execute SkDisplayType::BuildCondensedInfo() to " | 156 fprintf(condensed, "// Then execute SkDisplayType::BuildCondensedInfo() to " |
157 "regenerate this file.\n\n"); | 157 "regenerate this file.\n\n"); |
158 // write name of memberInfo | 158 // write name of memberInfo |
159 int typeNameIndex = 0; | 159 int typeNameIndex = 0; |
160 int unknown = 1; | 160 int unknown = 1; |
161 for (index = 0; index < gInfos.count(); index++) { | 161 for (index = 0; index < gInfos.count(); index++) { |
162 const SkMemberInfo* info = gInfos[index]; | 162 const SkMemberInfo* info = gInfos[index]; |
163 if (info == NULL) | 163 if (info == nullptr) |
164 continue; | 164 continue; |
165 char scratch[64]; | 165 char scratch[64]; |
166 bool drawPrefix, displayPrefix; | 166 bool drawPrefix, displayPrefix; |
167 while (gTypeNames[typeNameIndex].fType < index) | 167 while (gTypeNames[typeNameIndex].fType < index) |
168 typeNameIndex++; | 168 typeNameIndex++; |
169 if (gTypeNames[typeNameIndex].fType == index) { | 169 if (gTypeNames[typeNameIndex].fType == index) { |
170 Get3DName(scratch, gTypeNames[typeNameIndex].fName); | 170 Get3DName(scratch, gTypeNames[typeNameIndex].fName); |
171 drawPrefix = gTypeNames[typeNameIndex].fDrawPrefix; | 171 drawPrefix = gTypeNames[typeNameIndex].fDrawPrefix; |
172 displayPrefix = gTypeNames[typeNameIndex].fDisplayPrefix; | 172 displayPrefix = gTypeNames[typeNameIndex].fDisplayPrefix; |
173 } else { | 173 } else { |
174 sprintf(scratch, "Unknown%d", unknown++); | 174 sprintf(scratch, "Unknown%d", unknown++); |
175 drawPrefix = displayPrefix = false; | 175 drawPrefix = displayPrefix = false; |
176 } | 176 } |
177 WriteInfo(condensed, info, gInfosCounts[index], scratch, drawPrefix, dis
playPrefix); | 177 WriteInfo(condensed, info, gInfosCounts[index], scratch, drawPrefix, dis
playPrefix); |
178 } | 178 } |
179 // write array of table pointers | 179 // write array of table pointers |
180 // start here; | 180 // start here; |
181 fprintf(condensed, "static const SkMemberInfo* const gInfoTables[] = {"); | 181 fprintf(condensed, "static const SkMemberInfo* const gInfoTables[] = {"); |
182 typeNameIndex = 0; | 182 typeNameIndex = 0; |
183 unknown = 1; | 183 unknown = 1; |
184 for (index = 0; index < gInfos.count(); index++) { | 184 for (index = 0; index < gInfos.count(); index++) { |
185 const SkMemberInfo* info = gInfos[index]; | 185 const SkMemberInfo* info = gInfos[index]; |
186 if (info == NULL) | 186 if (info == nullptr) |
187 continue; | 187 continue; |
188 char scratch[64]; | 188 char scratch[64]; |
189 bool drawPrefix, displayPrefix; | 189 bool drawPrefix, displayPrefix; |
190 while (gTypeNames[typeNameIndex].fType < index) | 190 while (gTypeNames[typeNameIndex].fType < index) |
191 typeNameIndex++; | 191 typeNameIndex++; |
192 if (gTypeNames[typeNameIndex].fType == index) { | 192 if (gTypeNames[typeNameIndex].fType == index) { |
193 Get3DName(scratch, gTypeNames[typeNameIndex].fName); | 193 Get3DName(scratch, gTypeNames[typeNameIndex].fName); |
194 drawPrefix = gTypeNames[typeNameIndex].fDrawPrefix; | 194 drawPrefix = gTypeNames[typeNameIndex].fDrawPrefix; |
195 displayPrefix = gTypeNames[typeNameIndex].fDisplayPrefix; | 195 displayPrefix = gTypeNames[typeNameIndex].fDisplayPrefix; |
196 } else { | 196 } else { |
(...skipping 25 matching lines...) Expand all Loading... |
222 written++; | 222 written++; |
223 } | 223 } |
224 fprintf(condensed, "\n};\n\n"); | 224 fprintf(condensed, "\n};\n\n"); |
225 // write array of type ids table entries correspond to | 225 // write array of type ids table entries correspond to |
226 fprintf(condensed, "static const unsigned char gTypeIDs[] = {\n\t"); | 226 fprintf(condensed, "static const unsigned char gTypeIDs[] = {\n\t"); |
227 int typeIDCount = 0; | 227 int typeIDCount = 0; |
228 typeNameIndex = 0; | 228 typeNameIndex = 0; |
229 unknown = 1; | 229 unknown = 1; |
230 for (index = 0; index < gInfosCounts.count(); index++) { | 230 for (index = 0; index < gInfosCounts.count(); index++) { |
231 const SkMemberInfo* info = gInfos[index]; | 231 const SkMemberInfo* info = gInfos[index]; |
232 if (info == NULL) | 232 if (info == nullptr) |
233 continue; | 233 continue; |
234 typeIDCount++; | 234 typeIDCount++; |
235 char scratch[64]; | 235 char scratch[64]; |
236 while (gTypeNames[typeNameIndex].fType < index) | 236 while (gTypeNames[typeNameIndex].fType < index) |
237 typeNameIndex++; | 237 typeNameIndex++; |
238 if (gTypeNames[typeNameIndex].fType == index) { | 238 if (gTypeNames[typeNameIndex].fType == index) { |
239 Get3DName(scratch, gTypeNames[typeNameIndex].fName); | 239 Get3DName(scratch, gTypeNames[typeNameIndex].fName); |
240 } else | 240 } else |
241 sprintf(scratch, "Unknown%d", unknown++); | 241 sprintf(scratch, "Unknown%d", unknown++); |
242 fprintf(condensed, "%d%c // %s\n\t", index, | 242 fprintf(condensed, "%d%c // %s\n\t", index, |
243 index < gInfosCounts.count() ? ',' : ' ', scratch); | 243 index < gInfosCounts.count() ? ',' : ' ', scratch); |
244 } | 244 } |
245 fprintf(condensed, "\n};\n\n"); | 245 fprintf(condensed, "\n};\n\n"); |
246 fprintf(condensed, "static const int kTypeIDs = %d;\n\n", typeIDCount); | 246 fprintf(condensed, "static const int kTypeIDs = %d;\n\n", typeIDCount); |
247 // write the array of string pointers | 247 // write the array of string pointers |
248 fprintf(condensed, "static const char* const gInfoNames[] = {"); | 248 fprintf(condensed, "static const char* const gInfoNames[] = {"); |
249 typeNameIndex = 0; | 249 typeNameIndex = 0; |
250 unknown = 1; | 250 unknown = 1; |
251 written = 0; | 251 written = 0; |
252 for (index = 0; index < gInfosCounts.count(); index++) { | 252 for (index = 0; index < gInfosCounts.count(); index++) { |
253 const SkMemberInfo* info = gInfos[index]; | 253 const SkMemberInfo* info = gInfos[index]; |
254 if (info == NULL) | 254 if (info == nullptr) |
255 continue; | 255 continue; |
256 if (written > 0) | 256 if (written > 0) |
257 putc(',', condensed); | 257 putc(',', condensed); |
258 written++; | 258 written++; |
259 fprintf(condensed, "\n\tg"); | 259 fprintf(condensed, "\n\tg"); |
260 char scratch[64]; | 260 char scratch[64]; |
261 while (gTypeNames[typeNameIndex].fType < index) | 261 while (gTypeNames[typeNameIndex].fType < index) |
262 typeNameIndex++; | 262 typeNameIndex++; |
263 if (gTypeNames[typeNameIndex].fType == index) { | 263 if (gTypeNames[typeNameIndex].fType == index) { |
264 Get3DName(scratch, gTypeNames[typeNameIndex].fName); | 264 Get3DName(scratch, gTypeNames[typeNameIndex].fName); |
265 } else | 265 } else |
266 sprintf(scratch, "Unknown%d", unknown++); | 266 sprintf(scratch, "Unknown%d", unknown++); |
267 fprintf(condensed, "%sStrings", scratch); | 267 fprintf(condensed, "%sStrings", scratch); |
268 } | 268 } |
269 fprintf(condensed, "\n};\n\n"); | 269 fprintf(condensed, "\n};\n\n"); |
270 fprintf(condensed, "#endif\n"); | 270 fprintf(condensed, "#endif\n"); |
271 fclose(condensed); | 271 fclose(condensed); |
272 gInfos.reset(); | 272 gInfos.reset(); |
273 gInfosCounts.reset(); | 273 gInfosCounts.reset(); |
274 gInfosTypeIDs.reset(); | 274 gInfosTypeIDs.reset(); |
275 gUnknowns.reset(); | 275 gUnknowns.reset(); |
276 gUnknownsCounts.reset(); | 276 gUnknownsCounts.reset(); |
277 } | 277 } |
278 | 278 |
279 #elif defined SK_DEBUG | 279 #elif defined SK_DEBUG |
280 #include "SkDisplayType.h" | 280 #include "SkDisplayType.h" |
281 void SkDisplayType::BuildCondensedInfo(SkAnimateMaker* ) {} | 281 void SkDisplayType::BuildCondensedInfo(SkAnimateMaker* ) {} |
282 #endif | 282 #endif |
OLD | NEW |