180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkMemberInfo.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if SK_USE_CONDENSED_INFO == 1 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// SkCondensed.cpp is auto-generated 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// To generate it, execute SkDisplayType::BuildCondensedInfo() 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkCondensedDebug.cpp" 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#else 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkCondensedRelease.cpp" 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic int _searchByName(const unsigned char* lengths, int count, const char* strings, const char target[]) { 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int lo = 0; 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int hi = count - 1; 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (lo < hi) { 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int mid = (hi + lo) >> 1; 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (strcmp(&strings[lengths[mid << 2]], target) < 0) 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru lo = mid + 1; 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru else 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru hi = mid; 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (strcmp(&strings[lengths[hi << 2]], target) != 0) 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return -1; 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return hi; 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic int _searchByType(SkDisplayTypes type) { 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru unsigned char match = (unsigned char) type; 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int lo = 0; 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int hi = kTypeIDs - 1; 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (lo < hi) { 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int mid = (hi + lo) >> 1; 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (gTypeIDs[mid] < match) 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru lo = mid + 1; 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru else 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru hi = mid; 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (gTypeIDs[hi] != type) 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return -1; 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return hi; 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo* SkDisplayType::GetMembers(SkAnimateMaker* , SkDisplayTypes type, int* infoCountPtr) { 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int lookup = _searchByType(type); 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (lookup < 0) 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (infoCountPtr) 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *infoCountPtr = gInfoCounts[lookup]; 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return gInfoTables[lookup]; 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// !!! replace with inline 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo* SkDisplayType::GetMember(SkAnimateMaker* , SkDisplayTypes type, const char** matchPtr ) { 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* info = SkMemberInfo::Find(type, matchPtr); 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(info); 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return info; 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic const SkMemberInfo* _lookup(int lookup, const char** matchPtr) { 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int count = gInfoCounts[lookup]; 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* info = gInfoTables[lookup]; 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (info->fType == SkType_BaseClassInfo) { 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int baseTypeLookup = info->fOffset; 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* result = _lookup(baseTypeLookup, matchPtr); 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (result != NULL) 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result; 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (--count == 0) 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru info++; 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(info->fType != SkType_BaseClassInfo); 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const char* match = *matchPtr; 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const char* strings = gInfoNames[lookup]; 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int index = _searchByName(&info->fName, count, strings, match); 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (index < 0) 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return &info[index]; 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo* SkMemberInfo::Find(SkDisplayTypes type, int* index) { 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int count = gInfoCounts[lookup]; 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* info = gInfoTables[lookup]; 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (info->fType == SkType_BaseClassInfo) { 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int baseTypeLookup = info->fOffset; 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMemberInfo* result = Find(baseTypeLookup, index); 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (result != NULL) 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return result; 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (--count == 0) 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru info++; 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(info->fType != SkType_BaseClassInfo); 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (*index >= count) { 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *index -= count; 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return &info[index]; 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo* SkMemberInfo::Find(SkDisplayTypes type, const char** matchPtr) { 11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int lookup = _searchByType(type); 11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(lookup >= 0); 11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return _lookup(lookup, matchPtr); 11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo* SkMemberInfo::getInherited() const { 11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int baseTypeLookup = fOffset; 11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return gInfoTables[baseTypeLookup]; 11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 122