OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkFlattenable.h" | 8 #include "SkFlattenable.h" |
9 #include "SkPtrRecorder.h" | 9 #include "SkPtrRecorder.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 /////////////////////////////////////////////////////////////////////////////// | 49 /////////////////////////////////////////////////////////////////////////////// |
50 | 50 |
51 #define MAX_ENTRY_COUNT 1024 | 51 #define MAX_ENTRY_COUNT 1024 |
52 | 52 |
53 struct Entry { | 53 struct Entry { |
54 const char* fName; | 54 const char* fName; |
55 SkFlattenable::Factory fFactory; | 55 SkFlattenable::Factory fFactory; |
56 SkFlattenable::Type fType; | 56 SkFlattenable::Type fType; |
57 }; | 57 }; |
58 | 58 |
59 static int gCount; | 59 static int gCount = 0; |
60 static Entry gEntries[MAX_ENTRY_COUNT]; | 60 static Entry gEntries[MAX_ENTRY_COUNT]; |
61 | 61 |
62 void SkFlattenable::Register(const char name[], Factory factory, SkFlattenable::
Type type) { | 62 void SkFlattenable::Register(const char name[], Factory factory, SkFlattenable::
Type type) { |
63 SkASSERT(name); | 63 SkASSERT(name); |
64 SkASSERT(factory); | 64 SkASSERT(factory); |
65 | |
66 static bool gOnce = false; | |
67 if (!gOnce) { | |
68 gCount = 0; | |
69 gOnce = true; | |
70 } | |
71 | |
72 SkASSERT(gCount < MAX_ENTRY_COUNT); | 65 SkASSERT(gCount < MAX_ENTRY_COUNT); |
73 | 66 |
74 gEntries[gCount].fName = name; | 67 gEntries[gCount].fName = name; |
75 gEntries[gCount].fFactory = factory; | 68 gEntries[gCount].fFactory = factory; |
76 gEntries[gCount].fType = type; | 69 gEntries[gCount].fType = type; |
77 gCount += 1; | 70 gCount += 1; |
78 } | 71 } |
79 | 72 |
80 #ifdef SK_DEBUG | 73 #ifdef SK_DEBUG |
81 static void report_no_entries(const char* functionName) { | 74 static void report_no_entries(const char* functionName) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 report_no_entries(__FUNCTION__); | 116 report_no_entries(__FUNCTION__); |
124 #endif | 117 #endif |
125 const Entry* entries = gEntries; | 118 const Entry* entries = gEntries; |
126 for (int i = gCount - 1; i >= 0; --i) { | 119 for (int i = gCount - 1; i >= 0; --i) { |
127 if (entries[i].fFactory == fact) { | 120 if (entries[i].fFactory == fact) { |
128 return entries[i].fName; | 121 return entries[i].fName; |
129 } | 122 } |
130 } | 123 } |
131 return nullptr; | 124 return nullptr; |
132 } | 125 } |
OLD | NEW |