| 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 "SkOnce.h" |
| 11 | 12 |
| 12 #if 0 | 13 #if 0 |
| 13 #define assign_16_longs(dst, value) \ | 14 #define assign_16_longs(dst, value) \ |
| 14 do { \ | 15 do { \ |
| 15 (dst)[0] = value; (dst)[1] = value; \ | 16 (dst)[0] = value; (dst)[1] = value; \ |
| 16 (dst)[2] = value; (dst)[3] = value; \ | 17 (dst)[2] = value; (dst)[3] = value; \ |
| 17 (dst)[4] = value; (dst)[5] = value; \ | 18 (dst)[4] = value; (dst)[5] = value; \ |
| 18 (dst)[6] = value; (dst)[7] = value; \ | 19 (dst)[6] = value; (dst)[7] = value; \ |
| 19 (dst)[8] = value; (dst)[9] = value; \ | 20 (dst)[8] = value; (dst)[9] = value; \ |
| 20 (dst)[10] = value; (dst)[11] = value; \ | 21 (dst)[10] = value; (dst)[11] = value; \ |
| 21 (dst)[12] = value; (dst)[13] = value; \ | 22 (dst)[12] = value; (dst)[13] = value; \ |
| 22 (dst)[14] = value; (dst)[15] = value; \ | 23 (dst)[14] = value; (dst)[15] = value; \ |
| 23 } while (0) | 24 } while (0) |
| 24 #else | 25 #else |
| 25 #define assign_16_longs(dst, value) \ | 26 #define assign_16_longs(dst, value) \ |
| 26 do { \ | 27 do { \ |
| 27 *(dst)++ = value; *(dst)++ = value; \ | 28 *(dst)++ = value; *(dst)++ = value; \ |
| 28 *(dst)++ = value; *(dst)++ = value; \ | 29 *(dst)++ = value; *(dst)++ = value; \ |
| 29 *(dst)++ = value; *(dst)++ = value; \ | 30 *(dst)++ = value; *(dst)++ = value; \ |
| 30 *(dst)++ = value; *(dst)++ = value; \ | 31 *(dst)++ = value; *(dst)++ = value; \ |
| 31 *(dst)++ = value; *(dst)++ = value; \ | 32 *(dst)++ = value; *(dst)++ = value; \ |
| 32 *(dst)++ = value; *(dst)++ = value; \ | 33 *(dst)++ = value; *(dst)++ = value; \ |
| 33 *(dst)++ = value; *(dst)++ = value; \ | 34 *(dst)++ = value; *(dst)++ = value; \ |
| 34 *(dst)++ = value; *(dst)++ = value; \ | 35 *(dst)++ = value; *(dst)++ = value; \ |
| 35 } while (0) | 36 } while (0) |
| 36 #endif | 37 #endif |
| 37 | 38 |
| 38 /////////////////////////////////////////////////////////////////////////////// | 39 /////////////////////////////////////////////////////////////////////////////// |
| 39 | 40 |
| 40 void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) { | 41 static void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) { |
| 41 SkASSERT(dst != NULL && count >= 0); | 42 SkASSERT(dst != NULL && count >= 0); |
| 42 | 43 |
| 43 if (count <= 0) { | 44 if (count <= 0) { |
| 44 return; | 45 return; |
| 45 } | 46 } |
| 46 | 47 |
| 47 // not sure if this helps to short-circuit on small values of count | 48 // not sure if this helps to short-circuit on small values of count |
| 48 if (count < 8) { | 49 if (count < 8) { |
| 49 do { | 50 do { |
| 50 *dst++ = (uint16_t)value; | 51 *dst++ = (uint16_t)value; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } while (--longs != 0); | 84 } while (--longs != 0); |
| 84 } | 85 } |
| 85 } | 86 } |
| 86 | 87 |
| 87 // cleanup a possible trailing short | 88 // cleanup a possible trailing short |
| 88 if (count & 1) { | 89 if (count & 1) { |
| 89 *dst = (uint16_t)value; | 90 *dst = (uint16_t)value; |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| 93 void sk_memset32_portable(uint32_t dst[], uint32_t value, int count) { | 94 static void sk_memset32_portable(uint32_t dst[], uint32_t value, int count) { |
| 94 SkASSERT(dst != NULL && count >= 0); | 95 SkASSERT(dst != NULL && count >= 0); |
| 95 | 96 |
| 96 int sixteenlongs = count >> 4; | 97 int sixteenlongs = count >> 4; |
| 97 if (sixteenlongs) { | 98 if (sixteenlongs) { |
| 98 do { | 99 do { |
| 99 assign_16_longs(dst, value); | 100 assign_16_longs(dst, value); |
| 100 } while (--sixteenlongs != 0); | 101 } while (--sixteenlongs != 0); |
| 101 count &= 15; | 102 count &= 15; |
| 102 } | 103 } |
| 103 | 104 |
| 104 if (count) { | 105 if (count) { |
| 105 do { | 106 do { |
| 106 *dst++ = value; | 107 *dst++ = value; |
| 107 } while (--count != 0); | 108 } while (--count != 0); |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 | 111 |
| 111 static void sk_memset16_stub(uint16_t dst[], uint16_t value, int count) { | 112 static void choose_memset16(SkMemset16Proc* proc) { |
| 112 SkMemset16Proc proc = SkMemset16GetPlatformProc(); | 113 *proc = SkMemset16GetPlatformProc(); |
| 113 sk_memset16 = proc ? proc : sk_memset16_portable; | 114 if (NULL == *proc) { |
| 114 sk_memset16(dst, value, count); | 115 *proc = &sk_memset16_portable; |
| 116 } |
| 115 } | 117 } |
| 116 | 118 |
| 117 SkMemset16Proc sk_memset16 = sk_memset16_stub; | 119 void sk_memset16(uint16_t dst[], uint16_t value, int count) { |
| 120 SK_DECLARE_STATIC_ONCE(once); |
| 121 static SkMemset16Proc proc = NULL; |
| 122 SkOnce(&once, choose_memset16, &proc); |
| 123 SkASSERT(proc != NULL); |
| 118 | 124 |
| 119 static void sk_memset32_stub(uint32_t dst[], uint32_t value, int count) { | 125 return proc(dst, value, count); |
| 120 SkMemset32Proc proc = SkMemset32GetPlatformProc(); | |
| 121 sk_memset32 = proc ? proc : sk_memset32_portable; | |
| 122 sk_memset32(dst, value, count); | |
| 123 } | 126 } |
| 124 | 127 |
| 125 SkMemset32Proc sk_memset32 = sk_memset32_stub; | 128 static void choose_memset32(SkMemset32Proc* proc) { |
| 129 *proc = SkMemset32GetPlatformProc(); |
| 130 if (NULL == *proc) { |
| 131 *proc = &sk_memset32_portable; |
| 132 } |
| 133 } |
| 134 |
| 135 void sk_memset32(uint32_t dst[], uint32_t value, int count) { |
| 136 SK_DECLARE_STATIC_ONCE(once); |
| 137 static SkMemset32Proc proc = NULL; |
| 138 SkOnce(&once, choose_memset32, &proc); |
| 139 SkASSERT(proc != NULL); |
| 140 |
| 141 return proc(dst, value, count); |
| 142 } |
| 126 | 143 |
| 127 /////////////////////////////////////////////////////////////////////////////// | 144 /////////////////////////////////////////////////////////////////////////////// |
| 128 | 145 |
| 129 /* 0xxxxxxx 1 total | 146 /* 0xxxxxxx 1 total |
| 130 10xxxxxx // never a leading byte | 147 10xxxxxx // never a leading byte |
| 131 110xxxxx 2 total | 148 110xxxxx 2 total |
| 132 1110xxxx 3 total | 149 1110xxxx 3 total |
| 133 11110xxx 4 total | 150 11110xxx 4 total |
| 134 | 151 |
| 135 11 10 01 01 xx xx xx xx 0... | 152 11 10 01 01 xx xx xx xx 0... |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 405 } |
| 389 } else { | 406 } else { |
| 390 char* start = utf8; | 407 char* start = utf8; |
| 391 while (utf16 < stop) { | 408 while (utf16 < stop) { |
| 392 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); | 409 utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); |
| 393 } | 410 } |
| 394 size = utf8 - start; | 411 size = utf8 - start; |
| 395 } | 412 } |
| 396 return size; | 413 return size; |
| 397 } | 414 } |
| OLD | NEW |