1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #include "SkMemberInfo.h"
11 
12 #if SK_USE_CONDENSED_INFO == 1
13 
14 // SkCondensed.inc is auto-generated
15 // To generate it, execute SkDisplayType::BuildCondensedInfo()
16 #ifdef SK_DEBUG
17 #include "SkCondensedDebug.inc"
18 #else
19 #include "SkCondensedRelease.inc"
20 #endif
21 
_searchByName(const unsigned char * lengths,int count,const char * strings,const char target[])22 static int _searchByName(const unsigned char* lengths, int count, const char* strings, const char target[]) {
23     int lo = 0;
24     int hi = count - 1;
25     while (lo < hi) {
26         int mid = (hi + lo) >> 1;
27         if (strcmp(&strings[lengths[mid << 2]], target) < 0)
28             lo = mid + 1;
29         else
30             hi = mid;
31     }
32     if (strcmp(&strings[lengths[hi << 2]], target) != 0)
33         return -1;
34     return hi;
35 }
36 
_searchByType(SkDisplayTypes type)37 static int _searchByType(SkDisplayTypes type) {
38     unsigned char match = (unsigned char) type;
39     int lo = 0;
40     int hi = kTypeIDs - 1;
41     while (lo < hi) {
42         int mid = (hi + lo) >> 1;
43         if (gTypeIDs[mid] < match)
44             lo = mid + 1;
45         else
46             hi = mid;
47     }
48     if (gTypeIDs[hi] != type)
49         return -1;
50     return hi;
51 }
52 
GetMembers(SkAnimateMaker *,SkDisplayTypes type,int * infoCountPtr)53 const SkMemberInfo* SkDisplayType::GetMembers(SkAnimateMaker* , SkDisplayTypes type, int* infoCountPtr) {
54     int lookup = _searchByType(type);
55     if (lookup < 0)
56         return nullptr;
57     if (infoCountPtr)
58         *infoCountPtr = gInfoCounts[lookup];
59     return gInfoTables[lookup];
60 }
61 
62 // !!! replace with inline
GetMember(SkAnimateMaker *,SkDisplayTypes type,const char ** matchPtr)63 const SkMemberInfo* SkDisplayType::GetMember(SkAnimateMaker* , SkDisplayTypes type, const char** matchPtr ) {
64     const SkMemberInfo* info = SkMemberInfo::Find(type, matchPtr);
65     SkASSERT(info);
66     return info;
67 }
68 
_lookup(int lookup,const char ** matchPtr)69 static const SkMemberInfo* _lookup(int lookup, const char** matchPtr) {
70     int count = gInfoCounts[lookup];
71     const SkMemberInfo* info = gInfoTables[lookup];
72     if (info->fType == SkType_BaseClassInfo) {
73         int baseTypeLookup = info->fOffset;
74         const SkMemberInfo* result = _lookup(baseTypeLookup, matchPtr);
75         if (result != nullptr)
76             return result;
77         if (--count == 0)
78             return nullptr;
79         info++;
80     }
81     SkASSERT(info->fType != SkType_BaseClassInfo);
82     const char* match = *matchPtr;
83     const char* strings = gInfoNames[lookup];
84     int index = _searchByName(&info->fName, count, strings, match);
85     if (index < 0)
86         return nullptr;
87     return &info[index];
88 }
89 
Find(SkDisplayTypes type,int * index)90 const SkMemberInfo* SkMemberInfo::Find(SkDisplayTypes type, int* index) {
91     int count = gInfoCounts[lookup];
92     const SkMemberInfo* info = gInfoTables[lookup];
93     if (info->fType == SkType_BaseClassInfo) {
94         int baseTypeLookup = info->fOffset;
95         const SkMemberInfo* result = Find(baseTypeLookup, index);
96         if (result != nullptr)
97             return result;
98         if (--count == 0)
99             return nullptr;
100         info++;
101     }
102     SkASSERT(info->fType != SkType_BaseClassInfo);
103     if (*index >= count) {
104         *index -= count;
105         return nullptr;
106     }
107     return &info[index];
108 }
109 
Find(SkDisplayTypes type,const char ** matchPtr)110 const SkMemberInfo* SkMemberInfo::Find(SkDisplayTypes type, const char** matchPtr) {
111     int lookup = _searchByType(type);
112     SkASSERT(lookup >= 0);
113     return _lookup(lookup, matchPtr);
114 }
115 
getInherited() const116 const SkMemberInfo* SkMemberInfo::getInherited() const {
117     int baseTypeLookup = fOffset;
118     return gInfoTables[baseTypeLookup];
119 }
120 
121 #endif
122