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