1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
/* libs/graphics/animator/SkBuildCondensedInfo.cpp
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#include "SkTypes.h"
#if defined SK_BUILD_CONDENSED
#include "SkMemberInfo.h"
#if SK_USE_CONDENSED_INFO == 1
#error "SK_USE_CONDENSED_INFO must be zero to build condensed info"
#endif
#if !defined SK_BUILD_FOR_WIN32
#error "SK_BUILD_FOR_WIN32 must be defined to build condensed info"
#endif
#include "SkDisplayType.h"
#include "SkIntArray.h"
#include <stdio.h>
SkTDMemberInfoArray gInfos;
SkTDIntArray gInfosCounts;
SkTDDisplayTypesArray gInfosTypeIDs;
SkTDMemberInfoArray gUnknowns;
SkTDIntArray gUnknownsCounts;
static void AddInfo(SkDisplayTypes type, const SkMemberInfo* info, int infoCount) {
SkASSERT(gInfos[type] == NULL);
gInfos[type] = info;
gInfosCounts[type] = infoCount;
*gInfosTypeIDs.append() = type;
size_t allStrs = 0;
for (int inner = 0; inner < infoCount; inner++) {
SkASSERT(info[inner].fCount < 256);
int offset = (int) info[inner].fOffset;
SkASSERT(offset < 128 && offset > -129);
SkASSERT(allStrs < 256);
if (info[inner].fType == SkType_BaseClassInfo) {
const SkMemberInfo* innerInfo = (const SkMemberInfo*) info[inner].fName;
if (gUnknowns.find(innerInfo) == -1) {
*gUnknowns.append() = innerInfo;
*gUnknownsCounts.append() = info[inner].fCount;
}
}
if (info[inner].fType != SkType_BaseClassInfo && info[inner].fName)
allStrs += strlen(info[inner].fName);
allStrs += 1;
SkASSERT(info[inner].fType < 256);
}
}
static void WriteInfo(FILE* condensed, const SkMemberInfo* info, int infoCount,
const char* typeName, bool draw, bool display) {
fprintf(condensed, "static const char g%sStrings[] = \n", typeName);
int inner;
// write strings
for (inner = 0; inner < infoCount; inner++) {
const char* name = (info[inner].fType != SkType_BaseClassInfo && info[inner].fName) ?
info[inner].fName : "";
const char* zero = inner < infoCount - 1 ? "\\0" : "";
fprintf(condensed, "\t\"%s%s\"\n", name, zero);
}
fprintf(condensed, ";\n\nstatic const SkMemberInfo g%s", draw ? "Draw" : display ? "Display" : "");
fprintf(condensed, "%sInfo[] = {", typeName);
size_t nameOffset = 0;
// write info tables
for (inner = 0; inner < infoCount; inner++) {
size_t offset = info[inner].fOffset;
if (info[inner].fType == SkType_BaseClassInfo) {
offset = (size_t) gInfos.find((const SkMemberInfo* ) info[inner].fName);
SkASSERT((int) offset >= 0);
offset = gInfosTypeIDs.find((SkDisplayTypes) offset);
SkASSERT((int) offset >= 0);
}
fprintf(condensed, "\n\t{%d, %d, %d, %d}", nameOffset, offset,
info[inner].fType, info[inner].fCount);
if (inner < infoCount - 1)
putc(',', condensed);
if (info[inner].fType != SkType_BaseClassInfo && info[inner].fName)
nameOffset += strlen(info[inner].fName);
nameOffset += 1;
}
fprintf(condensed, "\n};\n\n");
}
static void Get3DName(char* scratch, const char* name) {
if (strncmp("skia3d:", name, sizeof("skia3d:") - 1) == 0) {
strcpy(scratch, "3D_");
scratch[3]= name[7] & ~0x20;
strcpy(&scratch[4], &name[8]);
} else {
scratch[0] = name[0] & ~0x20;
strcpy(&scratch[1], &name[1]);
}
}
int type_compare(const void* a, const void* b) {
SkDisplayTypes first = *(SkDisplayTypes*) a;
SkDisplayTypes second = *(SkDisplayTypes*) b;
return first < second ? -1 : first == second ? 0 : 1;
}
void SkDisplayType::BuildCondensedInfo(SkAnimateMaker* maker) {
gInfos.setCount(kNumberOfTypes);
memset(gInfos.begin(), 0, sizeof(gInfos[0]) * kNumberOfTypes);
gInfosCounts.setCount(kNumberOfTypes);
memset(gInfosCounts.begin(), -1, sizeof(gInfosCounts[0]) * kNumberOfTypes);
// check to see if it is condensable
int index, infoCount;
for (index = 0; index < kTypeNamesSize; index++) {
const SkMemberInfo* info = GetMembers(maker, gTypeNames[index].fType, &infoCount);
if (info == NULL)
continue;
AddInfo(gTypeNames[index].fType, info, infoCount);
}
const SkMemberInfo* extraInfo =
SkDisplayType::GetMembers(maker, SkType_3D_Point, &infoCount);
AddInfo(SkType_Point, extraInfo, infoCount);
AddInfo(SkType_3D_Point, extraInfo, infoCount);
// int baseInfos = gInfos.count();
do {
SkTDMemberInfoArray oldRefs = gUnknowns;
SkTDIntArray oldRefCounts = gUnknownsCounts;
gUnknowns.reset();
gUnknownsCounts.reset();
for (index = 0; index < oldRefs.count(); index++) {
const SkMemberInfo* info = oldRefs[index];
if (gInfos.find(info) == -1) {
int typeIndex = 0;
for (; typeIndex < kNumberOfTypes; typeIndex++) {
const SkMemberInfo* temp = SkDisplayType::GetMembers(
maker, (SkDisplayTypes) typeIndex, NULL);
if (temp == info)
break;
}
SkASSERT(typeIndex < kNumberOfTypes);
AddInfo((SkDisplayTypes) typeIndex, info, oldRefCounts[index]);
}
}
} while (gUnknowns.count() > 0);
qsort(gInfosTypeIDs.begin(), gInfosTypeIDs.count(), sizeof(gInfosTypeIDs[0]), &type_compare);
#ifdef SK_DEBUG
FILE* condensed = fopen("../../src/animator/SkCondensedDebug.cpp", "w+");
fprintf(condensed, "#include \"SkTypes.h\"\n");
fprintf(condensed, "#ifdef SK_DEBUG\n");
#else
FILE* condensed = fopen("../../src/animator/SkCondensedRelease.cpp", "w+");
fprintf(condensed, "#include \"SkTypes.h\"\n");
fprintf(condensed, "#ifdef SK_RELEASE\n");
#endif
// write header
fprintf(condensed, "// This file was automatically generated.\n");
fprintf(condensed, "// To change it, edit the file with the matching debug info.\n");
fprintf(condensed, "// Then execute SkDisplayType::BuildCondensedInfo() to "
"regenerate this file.\n\n");
// write name of memberInfo
int typeNameIndex = 0;
int unknown = 1;
for (index = 0; index < gInfos.count(); index++) {
const SkMemberInfo* info = gInfos[index];
if (info == NULL)
continue;
char scratch[64];
bool drawPrefix, displayPrefix;
while (gTypeNames[typeNameIndex].fType < index)
typeNameIndex++;
if (gTypeNames[typeNameIndex].fType == index) {
Get3DName(scratch, gTypeNames[typeNameIndex].fName);
drawPrefix = gTypeNames[typeNameIndex].fDrawPrefix;
displayPrefix = gTypeNames[typeNameIndex].fDisplayPrefix;
} else {
sprintf(scratch, "Unknown%d", unknown++);
drawPrefix = displayPrefix = false;
}
WriteInfo(condensed, info, gInfosCounts[index], scratch, drawPrefix, displayPrefix);
}
// write array of table pointers
// start here;
fprintf(condensed, "static const SkMemberInfo* const gInfoTables[] = {");
typeNameIndex = 0;
unknown = 1;
for (index = 0; index < gInfos.count(); index++) {
const SkMemberInfo* info = gInfos[index];
if (info == NULL)
continue;
char scratch[64];
bool drawPrefix, displayPrefix;
while (gTypeNames[typeNameIndex].fType < index)
typeNameIndex++;
if (gTypeNames[typeNameIndex].fType == index) {
Get3DName(scratch, gTypeNames[typeNameIndex].fName);
drawPrefix = gTypeNames[typeNameIndex].fDrawPrefix;
displayPrefix = gTypeNames[typeNameIndex].fDisplayPrefix;
} else {
sprintf(scratch, "Unknown%d", unknown++);
drawPrefix = displayPrefix = false;
}
fprintf(condensed, "\n\tg");
if (drawPrefix)
fprintf(condensed, "Draw");
if (displayPrefix)
fprintf(condensed, "Display");
fprintf(condensed, "%sInfo", scratch);
if (index < gInfos.count() - 1)
putc(',', condensed);
}
fprintf(condensed, "\n};\n\n");
// write the array of number of entries in the info table
fprintf(condensed, "static const unsigned char gInfoCounts[] = {\n\t");
int written = 0;
for (index = 0; index < gInfosCounts.count(); index++) {
int count = gInfosCounts[index];
if (count < 0)
continue;
if (written > 0)
putc(',', condensed);
if (written % 20 == 19)
fprintf(condensed, "\n\t");
fprintf(condensed, "%d",count);
written++;
}
fprintf(condensed, "\n};\n\n");
// write array of type ids table entries correspond to
fprintf(condensed, "static const unsigned char gTypeIDs[] = {\n\t");
int typeIDCount = 0;
typeNameIndex = 0;
unknown = 1;
for (index = 0; index < gInfosCounts.count(); index++) {
const SkMemberInfo* info = gInfos[index];
if (info == NULL)
continue;
typeIDCount++;
char scratch[64];
while (gTypeNames[typeNameIndex].fType < index)
typeNameIndex++;
if (gTypeNames[typeNameIndex].fType == index) {
Get3DName(scratch, gTypeNames[typeNameIndex].fName);
} else
sprintf(scratch, "Unknown%d", unknown++);
fprintf(condensed, "%d%c // %s\n\t", index,
index < gInfosCounts.count() ? ',' : ' ', scratch);
}
fprintf(condensed, "\n};\n\n");
fprintf(condensed, "static const int kTypeIDs = %d;\n\n", typeIDCount);
// write the array of string pointers
fprintf(condensed, "static const char* const gInfoNames[] = {");
typeNameIndex = 0;
unknown = 1;
written = 0;
for (index = 0; index < gInfosCounts.count(); index++) {
const SkMemberInfo* info = gInfos[index];
if (info == NULL)
continue;
if (written > 0)
putc(',', condensed);
written++;
fprintf(condensed, "\n\tg");
char scratch[64];
while (gTypeNames[typeNameIndex].fType < index)
typeNameIndex++;
if (gTypeNames[typeNameIndex].fType == index) {
Get3DName(scratch, gTypeNames[typeNameIndex].fName);
} else
sprintf(scratch, "Unknown%d", unknown++);
fprintf(condensed, "%sStrings", scratch);
}
fprintf(condensed, "\n};\n\n");
fprintf(condensed, "#endif\n");
fclose(condensed);
gInfos.reset();
gInfosCounts.reset();
gInfosTypeIDs.reset();
gUnknowns.reset();
gUnknownsCounts.reset();
}
#elif defined SK_DEBUG
#include "SkDisplayType.h"
void SkDisplayType::BuildCondensedInfo(SkAnimateMaker* ) {}
#endif
|