OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkUtils.h" | 10 #include "SkUtils.h" |
11 #include "SkLazyFnPtr.h" | 11 #include "SkOnce.h" |
12 | 12 |
13 #if 0 | 13 #if 0 |
14 #define assign_16_longs(dst, value) \ | 14 #define assign_16_longs(dst, value) \ |
15 do { \ | 15 do { \ |
16 (dst)[0] = value; (dst)[1] = value; \ | 16 (dst)[0] = value; (dst)[1] = value; \ |
17 (dst)[2] = value; (dst)[3] = value; \ | 17 (dst)[2] = value; (dst)[3] = value; \ |
18 (dst)[4] = value; (dst)[5] = value; \ | 18 (dst)[4] = value; (dst)[5] = value; \ |
19 (dst)[6] = value; (dst)[7] = value; \ | 19 (dst)[6] = value; (dst)[7] = value; \ |
20 (dst)[8] = value; (dst)[9] = value; \ | 20 (dst)[8] = value; (dst)[9] = value; \ |
21 (dst)[10] = value; (dst)[11] = value; \ | 21 (dst)[10] = value; (dst)[11] = value; \ |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 do { | 106 do { |
107 *dst++ = value; | 107 *dst++ = value; |
108 } while (--count != 0); | 108 } while (--count != 0); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 static void sk_memcpy32_portable(uint32_t dst[], const uint32_t src[], int count
) { | 112 static void sk_memcpy32_portable(uint32_t dst[], const uint32_t src[], int count
) { |
113 memcpy(dst, src, count * sizeof(uint32_t)); | 113 memcpy(dst, src, count * sizeof(uint32_t)); |
114 } | 114 } |
115 | 115 |
116 static SkMemset16Proc choose_memset16() { | 116 static void choose_memset16(SkMemset16Proc* proc) { |
117 SkMemset16Proc proc = SkMemset16GetPlatformProc(); | 117 *proc = SkMemset16GetPlatformProc(); |
118 return proc ? proc : sk_memset16_portable; | 118 if (NULL == *proc) { |
| 119 *proc = &sk_memset16_portable; |
| 120 } |
119 } | 121 } |
120 | 122 |
121 void sk_memset16(uint16_t dst[], uint16_t value, int count) { | 123 void sk_memset16(uint16_t dst[], uint16_t value, int count) { |
122 SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemset16Proc, choice); | 124 SK_DECLARE_STATIC_ONCE(once); |
123 return choice.get(choose_memset16)(dst, value, count); | 125 static SkMemset16Proc proc = NULL; |
| 126 SkOnce(&once, choose_memset16, &proc); |
| 127 SkASSERT(proc != NULL); |
| 128 |
| 129 return proc(dst, value, count); |
124 } | 130 } |
125 | 131 |
126 static SkMemset32Proc choose_memset32() { | 132 static void choose_memset32(SkMemset32Proc* proc) { |
127 SkMemset32Proc proc = SkMemset32GetPlatformProc(); | 133 *proc = SkMemset32GetPlatformProc(); |
128 return proc ? proc : sk_memset32_portable; | 134 if (NULL == *proc) { |
| 135 *proc = &sk_memset32_portable; |
| 136 } |
129 } | 137 } |
130 | 138 |
131 void sk_memset32(uint32_t dst[], uint32_t value, int count) { | 139 void sk_memset32(uint32_t dst[], uint32_t value, int count) { |
132 SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemset32Proc, choice); | 140 SK_DECLARE_STATIC_ONCE(once); |
133 return choice.get(choose_memset32)(dst, value, count); | 141 static SkMemset32Proc proc = NULL; |
| 142 SkOnce(&once, choose_memset32, &proc); |
| 143 SkASSERT(proc != NULL); |
| 144 |
| 145 return proc(dst, value, count); |
134 } | 146 } |
135 | 147 |
136 static SkMemcpy32Proc choose_memcpy32() { | 148 static void choose_memcpy32(SkMemcpy32Proc* proc) { |
137 SkMemcpy32Proc proc = SkMemcpy32GetPlatformProc(); | 149 *proc = SkMemcpy32GetPlatformProc(); |
138 return proc ? proc : sk_memcpy32_portable; | 150 if (NULL == *proc) { |
| 151 *proc = &sk_memcpy32_portable; |
| 152 } |
139 } | 153 } |
140 | 154 |
141 void sk_memcpy32(uint32_t dst[], const uint32_t src[], int count) { | 155 void sk_memcpy32(uint32_t dst[], const uint32_t src[], int count) { |
142 SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemcpy32Proc, choice); | 156 SK_DECLARE_STATIC_ONCE(once); |
143 return choice.get(choose_memcpy32)(dst, src, count); | 157 static SkMemcpy32Proc proc = NULL; |
| 158 SkOnce(&once, choose_memcpy32, &proc); |
| 159 SkASSERT(proc != NULL); |
| 160 |
| 161 return proc(dst, src, count); |
144 } | 162 } |
145 | 163 |
146 /////////////////////////////////////////////////////////////////////////////// | 164 /////////////////////////////////////////////////////////////////////////////// |
147 | 165 |
148 /* 0xxxxxxx 1 total | 166 /* 0xxxxxxx 1 total |
149 10xxxxxx // never a leading byte | 167 10xxxxxx // never a leading byte |
150 110xxxxx 2 total | 168 110xxxxx 2 total |
151 1110xxxx 3 total | 169 1110xxxx 3 total |
152 11110xxx 4 total | 170 11110xxx 4 total |
153 | 171 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 425 } |
408 } else { | 426 } else { |
409 char* start = utf8; | 427 char* start = utf8; |
410 while (utf16 < stop) { | 428 while (utf16 < stop) { |
411 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); | 429 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); |
412 } | 430 } |
413 size = utf8 - start; | 431 size = utf8 - start; |
414 } | 432 } |
415 return size; | 433 return size; |
416 } | 434 } |
OLD | NEW |