1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/animator/SkBuildCondensedInfo.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,282 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#include "SkTypes.h" 1.14 +#if defined SK_BUILD_CONDENSED 1.15 +#include "SkMemberInfo.h" 1.16 +#if SK_USE_CONDENSED_INFO == 1 1.17 +#error "SK_USE_CONDENSED_INFO must be zero to build condensed info" 1.18 +#endif 1.19 +#if !defined SK_BUILD_FOR_WIN32 1.20 +#error "SK_BUILD_FOR_WIN32 must be defined to build condensed info" 1.21 +#endif 1.22 +#include "SkDisplayType.h" 1.23 +#include "SkIntArray.h" 1.24 +#include <stdio.h> 1.25 + 1.26 +SkTDMemberInfoArray gInfos; 1.27 +SkTDIntArray gInfosCounts; 1.28 +SkTDDisplayTypesArray gInfosTypeIDs; 1.29 +SkTDMemberInfoArray gUnknowns; 1.30 +SkTDIntArray gUnknownsCounts; 1.31 + 1.32 +static void AddInfo(SkDisplayTypes type, const SkMemberInfo* info, int infoCount) { 1.33 + SkASSERT(gInfos[type] == NULL); 1.34 + gInfos[type] = info; 1.35 + gInfosCounts[type] = infoCount; 1.36 + *gInfosTypeIDs.append() = type; 1.37 + size_t allStrs = 0; 1.38 + for (int inner = 0; inner < infoCount; inner++) { 1.39 + SkASSERT(info[inner].fCount < 256); 1.40 + int offset = (int) info[inner].fOffset; 1.41 + SkASSERT(offset < 128 && offset > -129); 1.42 + SkASSERT(allStrs < 256); 1.43 + if (info[inner].fType == SkType_BaseClassInfo) { 1.44 + const SkMemberInfo* innerInfo = (const SkMemberInfo*) info[inner].fName; 1.45 + if (gUnknowns.find(innerInfo) == -1) { 1.46 + *gUnknowns.append() = innerInfo; 1.47 + *gUnknownsCounts.append() = info[inner].fCount; 1.48 + } 1.49 + } 1.50 + if (info[inner].fType != SkType_BaseClassInfo && info[inner].fName) 1.51 + allStrs += strlen(info[inner].fName); 1.52 + allStrs += 1; 1.53 + SkASSERT(info[inner].fType < 256); 1.54 + } 1.55 +} 1.56 + 1.57 +static void WriteInfo(FILE* condensed, const SkMemberInfo* info, int infoCount, 1.58 + const char* typeName, bool draw, bool display) { 1.59 + fprintf(condensed, "static const char g%sStrings[] = \n", typeName); 1.60 + int inner; 1.61 + // write strings 1.62 + for (inner = 0; inner < infoCount; inner++) { 1.63 + const char* name = (info[inner].fType != SkType_BaseClassInfo && info[inner].fName) ? 1.64 + info[inner].fName : ""; 1.65 + const char* zero = inner < infoCount - 1 ? "\\0" : ""; 1.66 + fprintf(condensed, "\t\"%s%s\"\n", name, zero); 1.67 + } 1.68 + fprintf(condensed, ";\n\nstatic const SkMemberInfo g%s", draw ? "Draw" : display ? "Display" : ""); 1.69 + fprintf(condensed, "%sInfo[] = {", typeName); 1.70 + size_t nameOffset = 0; 1.71 + // write info tables 1.72 + for (inner = 0; inner < infoCount; inner++) { 1.73 + size_t offset = info[inner].fOffset; 1.74 + if (info[inner].fType == SkType_BaseClassInfo) { 1.75 + offset = (size_t) gInfos.find((const SkMemberInfo* ) info[inner].fName); 1.76 + SkASSERT((int) offset >= 0); 1.77 + offset = gInfosTypeIDs.find((SkDisplayTypes) offset); 1.78 + SkASSERT((int) offset >= 0); 1.79 + } 1.80 + fprintf(condensed, "\n\t{%d, %d, %d, %d}", nameOffset, offset, 1.81 + info[inner].fType, info[inner].fCount); 1.82 + if (inner < infoCount - 1) 1.83 + putc(',', condensed); 1.84 + if (info[inner].fType != SkType_BaseClassInfo && info[inner].fName) 1.85 + nameOffset += strlen(info[inner].fName); 1.86 + nameOffset += 1; 1.87 + } 1.88 + fprintf(condensed, "\n};\n\n"); 1.89 +} 1.90 + 1.91 +static void Get3DName(char* scratch, const char* name) { 1.92 + if (strncmp("skia3d:", name, sizeof("skia3d:") - 1) == 0) { 1.93 + strcpy(scratch, "3D_"); 1.94 + scratch[3]= name[7] & ~0x20; 1.95 + strcpy(&scratch[4], &name[8]); 1.96 + } else { 1.97 + scratch[0] = name[0] & ~0x20; 1.98 + strcpy(&scratch[1], &name[1]); 1.99 + } 1.100 +} 1.101 + 1.102 +int type_compare(const void* a, const void* b) { 1.103 + SkDisplayTypes first = *(SkDisplayTypes*) a; 1.104 + SkDisplayTypes second = *(SkDisplayTypes*) b; 1.105 + return first < second ? -1 : first == second ? 0 : 1; 1.106 +} 1.107 + 1.108 +void SkDisplayType::BuildCondensedInfo(SkAnimateMaker* maker) { 1.109 + gInfos.setCount(kNumberOfTypes); 1.110 + memset(gInfos.begin(), 0, sizeof(gInfos[0]) * kNumberOfTypes); 1.111 + gInfosCounts.setCount(kNumberOfTypes); 1.112 + memset(gInfosCounts.begin(), -1, sizeof(gInfosCounts[0]) * kNumberOfTypes); 1.113 + // check to see if it is condensable 1.114 + int index, infoCount; 1.115 + for (index = 0; index < kTypeNamesSize; index++) { 1.116 + const SkMemberInfo* info = GetMembers(maker, gTypeNames[index].fType, &infoCount); 1.117 + if (info == NULL) 1.118 + continue; 1.119 + AddInfo(gTypeNames[index].fType, info, infoCount); 1.120 + } 1.121 + const SkMemberInfo* extraInfo = 1.122 + SkDisplayType::GetMembers(maker, SkType_3D_Point, &infoCount); 1.123 + AddInfo(SkType_Point, extraInfo, infoCount); 1.124 + AddInfo(SkType_3D_Point, extraInfo, infoCount); 1.125 +// int baseInfos = gInfos.count(); 1.126 + do { 1.127 + SkTDMemberInfoArray oldRefs = gUnknowns; 1.128 + SkTDIntArray oldRefCounts = gUnknownsCounts; 1.129 + gUnknowns.reset(); 1.130 + gUnknownsCounts.reset(); 1.131 + for (index = 0; index < oldRefs.count(); index++) { 1.132 + const SkMemberInfo* info = oldRefs[index]; 1.133 + if (gInfos.find(info) == -1) { 1.134 + int typeIndex = 0; 1.135 + for (; typeIndex < kNumberOfTypes; typeIndex++) { 1.136 + const SkMemberInfo* temp = SkDisplayType::GetMembers( 1.137 + maker, (SkDisplayTypes) typeIndex, NULL); 1.138 + if (temp == info) 1.139 + break; 1.140 + } 1.141 + SkASSERT(typeIndex < kNumberOfTypes); 1.142 + AddInfo((SkDisplayTypes) typeIndex, info, oldRefCounts[index]); 1.143 + } 1.144 + } 1.145 + } while (gUnknowns.count() > 0); 1.146 + qsort(gInfosTypeIDs.begin(), gInfosTypeIDs.count(), sizeof(gInfosTypeIDs[0]), &type_compare); 1.147 +#ifdef SK_DEBUG 1.148 + FILE* condensed = fopen("../../src/animator/SkCondensedDebug.cpp", "w+"); 1.149 + fprintf(condensed, "#include \"SkTypes.h\"\n"); 1.150 + fprintf(condensed, "#ifdef SK_DEBUG\n"); 1.151 +#else 1.152 + FILE* condensed = fopen("../../src/animator/SkCondensedRelease.cpp", "w+"); 1.153 + fprintf(condensed, "#include \"SkTypes.h\"\n"); 1.154 + fprintf(condensed, "#ifdef SK_RELEASE\n"); 1.155 +#endif 1.156 + // write header 1.157 + fprintf(condensed, "// This file was automatically generated.\n"); 1.158 + fprintf(condensed, "// To change it, edit the file with the matching debug info.\n"); 1.159 + fprintf(condensed, "// Then execute SkDisplayType::BuildCondensedInfo() to " 1.160 + "regenerate this file.\n\n"); 1.161 + // write name of memberInfo 1.162 + int typeNameIndex = 0; 1.163 + int unknown = 1; 1.164 + for (index = 0; index < gInfos.count(); index++) { 1.165 + const SkMemberInfo* info = gInfos[index]; 1.166 + if (info == NULL) 1.167 + continue; 1.168 + char scratch[64]; 1.169 + bool drawPrefix, displayPrefix; 1.170 + while (gTypeNames[typeNameIndex].fType < index) 1.171 + typeNameIndex++; 1.172 + if (gTypeNames[typeNameIndex].fType == index) { 1.173 + Get3DName(scratch, gTypeNames[typeNameIndex].fName); 1.174 + drawPrefix = gTypeNames[typeNameIndex].fDrawPrefix; 1.175 + displayPrefix = gTypeNames[typeNameIndex].fDisplayPrefix; 1.176 + } else { 1.177 + sprintf(scratch, "Unknown%d", unknown++); 1.178 + drawPrefix = displayPrefix = false; 1.179 + } 1.180 + WriteInfo(condensed, info, gInfosCounts[index], scratch, drawPrefix, displayPrefix); 1.181 + } 1.182 + // write array of table pointers 1.183 +// start here; 1.184 + fprintf(condensed, "static const SkMemberInfo* const gInfoTables[] = {"); 1.185 + typeNameIndex = 0; 1.186 + unknown = 1; 1.187 + for (index = 0; index < gInfos.count(); index++) { 1.188 + const SkMemberInfo* info = gInfos[index]; 1.189 + if (info == NULL) 1.190 + continue; 1.191 + char scratch[64]; 1.192 + bool drawPrefix, displayPrefix; 1.193 + while (gTypeNames[typeNameIndex].fType < index) 1.194 + typeNameIndex++; 1.195 + if (gTypeNames[typeNameIndex].fType == index) { 1.196 + Get3DName(scratch, gTypeNames[typeNameIndex].fName); 1.197 + drawPrefix = gTypeNames[typeNameIndex].fDrawPrefix; 1.198 + displayPrefix = gTypeNames[typeNameIndex].fDisplayPrefix; 1.199 + } else { 1.200 + sprintf(scratch, "Unknown%d", unknown++); 1.201 + drawPrefix = displayPrefix = false; 1.202 + } 1.203 + fprintf(condensed, "\n\tg"); 1.204 + if (drawPrefix) 1.205 + fprintf(condensed, "Draw"); 1.206 + if (displayPrefix) 1.207 + fprintf(condensed, "Display"); 1.208 + fprintf(condensed, "%sInfo", scratch); 1.209 + if (index < gInfos.count() - 1) 1.210 + putc(',', condensed); 1.211 + } 1.212 + fprintf(condensed, "\n};\n\n"); 1.213 + // write the array of number of entries in the info table 1.214 + fprintf(condensed, "static const unsigned char gInfoCounts[] = {\n\t"); 1.215 + int written = 0; 1.216 + for (index = 0; index < gInfosCounts.count(); index++) { 1.217 + int count = gInfosCounts[index]; 1.218 + if (count < 0) 1.219 + continue; 1.220 + if (written > 0) 1.221 + putc(',', condensed); 1.222 + if (written % 20 == 19) 1.223 + fprintf(condensed, "\n\t"); 1.224 + fprintf(condensed, "%d",count); 1.225 + written++; 1.226 + } 1.227 + fprintf(condensed, "\n};\n\n"); 1.228 + // write array of type ids table entries correspond to 1.229 + fprintf(condensed, "static const unsigned char gTypeIDs[] = {\n\t"); 1.230 + int typeIDCount = 0; 1.231 + typeNameIndex = 0; 1.232 + unknown = 1; 1.233 + for (index = 0; index < gInfosCounts.count(); index++) { 1.234 + const SkMemberInfo* info = gInfos[index]; 1.235 + if (info == NULL) 1.236 + continue; 1.237 + typeIDCount++; 1.238 + char scratch[64]; 1.239 + while (gTypeNames[typeNameIndex].fType < index) 1.240 + typeNameIndex++; 1.241 + if (gTypeNames[typeNameIndex].fType == index) { 1.242 + Get3DName(scratch, gTypeNames[typeNameIndex].fName); 1.243 + } else 1.244 + sprintf(scratch, "Unknown%d", unknown++); 1.245 + fprintf(condensed, "%d%c // %s\n\t", index, 1.246 + index < gInfosCounts.count() ? ',' : ' ', scratch); 1.247 + } 1.248 + fprintf(condensed, "\n};\n\n"); 1.249 + fprintf(condensed, "static const int kTypeIDs = %d;\n\n", typeIDCount); 1.250 + // write the array of string pointers 1.251 + fprintf(condensed, "static const char* const gInfoNames[] = {"); 1.252 + typeNameIndex = 0; 1.253 + unknown = 1; 1.254 + written = 0; 1.255 + for (index = 0; index < gInfosCounts.count(); index++) { 1.256 + const SkMemberInfo* info = gInfos[index]; 1.257 + if (info == NULL) 1.258 + continue; 1.259 + if (written > 0) 1.260 + putc(',', condensed); 1.261 + written++; 1.262 + fprintf(condensed, "\n\tg"); 1.263 + char scratch[64]; 1.264 + while (gTypeNames[typeNameIndex].fType < index) 1.265 + typeNameIndex++; 1.266 + if (gTypeNames[typeNameIndex].fType == index) { 1.267 + Get3DName(scratch, gTypeNames[typeNameIndex].fName); 1.268 + } else 1.269 + sprintf(scratch, "Unknown%d", unknown++); 1.270 + fprintf(condensed, "%sStrings", scratch); 1.271 + } 1.272 + fprintf(condensed, "\n};\n\n"); 1.273 + fprintf(condensed, "#endif\n"); 1.274 + fclose(condensed); 1.275 + gInfos.reset(); 1.276 + gInfosCounts.reset(); 1.277 + gInfosTypeIDs.reset(); 1.278 + gUnknowns.reset(); 1.279 + gUnknownsCounts.reset(); 1.280 +} 1.281 + 1.282 +#elif defined SK_DEBUG 1.283 +#include "SkDisplayType.h" 1.284 +void SkDisplayType::BuildCondensedInfo(SkAnimateMaker* ) {} 1.285 +#endif