Home | History | Annotate | Download | only in animator
      1 /* libs/graphics/animator/SkGetCondensedInfo.cpp
      2 **
      3 ** Copyright 2006, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #include "SkMemberInfo.h"
     19 
     20 #if SK_USE_CONDENSED_INFO == 1
     21 
     22 // SkCondensed.cpp is auto-generated
     23 // To generate it, execute SkDisplayType::BuildCondensedInfo()
     24 #ifdef SK_DEBUG
     25 #include "SkCondensedDebug.cpp"
     26 #else
     27 #include "SkCondensedRelease.cpp"
     28 #endif
     29 
     30 static int _searchByName(const unsigned char* lengths, int count, const char* strings, const char target[]) {
     31     int lo = 0;
     32     int hi = count - 1;
     33     while (lo < hi) {
     34         int mid = (hi + lo) >> 1;
     35         if (strcmp(&strings[lengths[mid << 2]], target) < 0)
     36             lo = mid + 1;
     37         else
     38             hi = mid;
     39     }
     40     if (strcmp(&strings[lengths[hi << 2]], target) != 0)
     41         return -1;
     42     return hi;
     43 }
     44 
     45 static int _searchByType(SkDisplayTypes type) {
     46     unsigned char match = (unsigned char) type;
     47     int lo = 0;
     48     int hi = kTypeIDs - 1;
     49     while (lo < hi) {
     50         int mid = (hi + lo) >> 1;
     51         if (gTypeIDs[mid] < match)
     52             lo = mid + 1;
     53         else
     54             hi = mid;
     55     }
     56     if (gTypeIDs[hi] != type)
     57         return -1;
     58     return hi;
     59 }
     60 
     61 const SkMemberInfo* SkDisplayType::GetMembers(SkAnimateMaker* , SkDisplayTypes type, int* infoCountPtr) {
     62     int lookup = _searchByType(type);
     63     if (lookup < 0)
     64         return NULL;
     65     if (infoCountPtr)
     66         *infoCountPtr = gInfoCounts[lookup];
     67     return gInfoTables[lookup];
     68 }
     69 
     70 // !!! replace with inline
     71 const SkMemberInfo* SkDisplayType::GetMember(SkAnimateMaker* , SkDisplayTypes type, const char** matchPtr ) {
     72     const SkMemberInfo* info = SkMemberInfo::Find(type, matchPtr);
     73     SkASSERT(info);
     74     return info;
     75 }
     76 
     77 static const SkMemberInfo* _lookup(int lookup, const char** matchPtr) {
     78     int count = gInfoCounts[lookup];
     79     const SkMemberInfo* info = gInfoTables[lookup];
     80     if (info->fType == SkType_BaseClassInfo) {
     81         int baseTypeLookup = info->fOffset;
     82         const SkMemberInfo* result = _lookup(baseTypeLookup, matchPtr);
     83         if (result != NULL)
     84             return result;
     85         if (--count == 0)
     86             return NULL;
     87         info++;
     88     }
     89     SkASSERT(info->fType != SkType_BaseClassInfo);
     90     const char* match = *matchPtr;
     91     const char* strings = gInfoNames[lookup];
     92     int index = _searchByName(&info->fName, count, strings, match);
     93     if (index < 0)
     94         return NULL;
     95     return &info[index];
     96 }
     97 
     98 const SkMemberInfo* SkMemberInfo::Find(SkDisplayTypes type, int* index) {
     99     int count = gInfoCounts[lookup];
    100     const SkMemberInfo* info = gInfoTables[lookup];
    101     if (info->fType == SkType_BaseClassInfo) {
    102         int baseTypeLookup = info->fOffset;
    103         const SkMemberInfo* result = Find(baseTypeLookup, index);
    104         if (result != NULL)
    105             return result;
    106         if (--count == 0)
    107             return NULL;
    108         info++;
    109     }
    110     SkASSERT(info->fType != SkType_BaseClassInfo);
    111     if (*index >= count) {
    112         *index -= count;
    113         return NULL;
    114     }
    115     return &info[index];
    116 }
    117 
    118 const SkMemberInfo* SkMemberInfo::Find(SkDisplayTypes type, const char** matchPtr) {
    119     int lookup = _searchByType(type);
    120     SkASSERT(lookup >= 0);
    121     return _lookup(lookup, matchPtr);
    122 }
    123 
    124 const SkMemberInfo* SkMemberInfo::getInherited() const {
    125     int baseTypeLookup = fOffset;
    126     return gInfoTables[baseTypeLookup];
    127 }
    128 
    129 #endif
    130 
    131