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" |
(...skipping 95 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 namespace { |
| 117 // These three methods technically need external linkage to be passed as templat
e parameters. |
| 118 // Since they can't be static, we hide them in an anonymous namespace instead. |
| 119 |
| 120 SkMemset16Proc choose_memset16() { |
117 SkMemset16Proc proc = SkMemset16GetPlatformProc(); | 121 SkMemset16Proc proc = SkMemset16GetPlatformProc(); |
118 return proc ? proc : sk_memset16_portable; | 122 return proc ? proc : sk_memset16_portable; |
119 } | 123 } |
120 | 124 |
121 void sk_memset16(uint16_t dst[], uint16_t value, int count) { | 125 SkMemset32Proc choose_memset32() { |
122 SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemset16Proc, choice); | |
123 return choice.get(choose_memset16)(dst, value, count); | |
124 } | |
125 | |
126 static SkMemset32Proc choose_memset32() { | |
127 SkMemset32Proc proc = SkMemset32GetPlatformProc(); | 126 SkMemset32Proc proc = SkMemset32GetPlatformProc(); |
128 return proc ? proc : sk_memset32_portable; | 127 return proc ? proc : sk_memset32_portable; |
129 } | 128 } |
130 | 129 |
131 void sk_memset32(uint32_t dst[], uint32_t value, int count) { | 130 SkMemcpy32Proc choose_memcpy32() { |
132 SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemset32Proc, choice); | |
133 return choice.get(choose_memset32)(dst, value, count); | |
134 } | |
135 | |
136 static SkMemcpy32Proc choose_memcpy32() { | |
137 SkMemcpy32Proc proc = SkMemcpy32GetPlatformProc(); | 131 SkMemcpy32Proc proc = SkMemcpy32GetPlatformProc(); |
138 return proc ? proc : sk_memcpy32_portable; | 132 return proc ? proc : sk_memcpy32_portable; |
139 } | 133 } |
140 | 134 |
| 135 } // namespace |
| 136 |
| 137 void sk_memset16(uint16_t dst[], uint16_t value, int count) { |
| 138 SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemset16Proc, proc, choose_memset16); |
| 139 proc.get()(dst, value, count); |
| 140 } |
| 141 |
| 142 void sk_memset32(uint32_t dst[], uint32_t value, int count) { |
| 143 SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemset32Proc, proc, choose_memset32); |
| 144 proc.get()(dst, value, count); |
| 145 } |
| 146 |
141 void sk_memcpy32(uint32_t dst[], const uint32_t src[], int count) { | 147 void sk_memcpy32(uint32_t dst[], const uint32_t src[], int count) { |
142 SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemcpy32Proc, choice); | 148 SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemcpy32Proc, proc, choose_memcpy32); |
143 return choice.get(choose_memcpy32)(dst, src, count); | 149 proc.get()(dst, src, count); |
144 } | 150 } |
145 | 151 |
146 /////////////////////////////////////////////////////////////////////////////// | 152 /////////////////////////////////////////////////////////////////////////////// |
147 | 153 |
148 /* 0xxxxxxx 1 total | 154 /* 0xxxxxxx 1 total |
149 10xxxxxx // never a leading byte | 155 10xxxxxx // never a leading byte |
150 110xxxxx 2 total | 156 110xxxxx 2 total |
151 1110xxxx 3 total | 157 1110xxxx 3 total |
152 11110xxx 4 total | 158 11110xxx 4 total |
153 | 159 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 413 } |
408 } else { | 414 } else { |
409 char* start = utf8; | 415 char* start = utf8; |
410 while (utf16 < stop) { | 416 while (utf16 < stop) { |
411 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); | 417 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); |
412 } | 418 } |
413 size = utf8 - start; | 419 size = utf8 - start; |
414 } | 420 } |
415 return size; | 421 return size; |
416 } | 422 } |
OLD | NEW |