• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkUtils_DEFINED
9 #define SkUtils_DEFINED
10 
11 #include "SkOpts.h"
12 #include "SkTypeface.h"
13 #include "../utils/SkUTF.h"
14 
15 /** Similar to memset(), but it assigns a 16, 32, or 64-bit value into the buffer.
16     @param buffer   The memory to have value copied into it
17     @param value    The value to be copied into buffer
18     @param count    The number of times value should be copied into the buffer.
19 */
sk_memset16(uint16_t buffer[],uint16_t value,int count)20 static inline void sk_memset16(uint16_t buffer[], uint16_t value, int count) {
21     SkOpts::memset16(buffer, value, count);
22 }
sk_memset32(uint32_t buffer[],uint32_t value,int count)23 static inline void sk_memset32(uint32_t buffer[], uint32_t value, int count) {
24     SkOpts::memset32(buffer, value, count);
25 }
sk_memset64(uint64_t buffer[],uint64_t value,int count)26 static inline void sk_memset64(uint64_t buffer[], uint64_t value, int count) {
27     SkOpts::memset64(buffer, value, count);
28 }
29 
30 ///////////////////////////////////////////////////////////////////////////////
31 
32 // Unlike the functions in SkUTF.h, these two functions do not take an array
33 // length parameter.  When possible, use SkUTF::NextUTF{8,16} instead.
34 SkUnichar SkUTF8_NextUnichar(const char**);
35 SkUnichar SkUTF16_NextUnichar(const uint16_t**);
36 
37 ///////////////////////////////////////////////////////////////////////////////
38 
SkUTF16_IsLeadingSurrogate(uint16_t c)39 static inline bool SkUTF16_IsLeadingSurrogate(uint16_t c) { return ((c) & 0xFC00) == 0xD800; }
40 
SkUTF16_IsTrailingSurrogate(uint16_t c)41 static inline bool SkUTF16_IsTrailingSurrogate (uint16_t c) { return ((c) & 0xFC00) == 0xDC00; }
42 
43 ///////////////////////////////////////////////////////////////////////////////
44 
SkUTFN_CountUnichars(SkTypeface::Encoding enc,const void * utfN,size_t bytes)45 static inline int SkUTFN_CountUnichars(SkTypeface::Encoding enc, const void* utfN, size_t bytes) {
46     switch (enc) {
47         case SkTypeface::kUTF8_Encoding:  return SkUTF::CountUTF8((const char*)utfN, bytes);
48         case SkTypeface::kUTF16_Encoding: return SkUTF::CountUTF16((const uint16_t*)utfN, bytes);
49         case SkTypeface::kUTF32_Encoding: return SkUTF::CountUTF32((const int32_t*)utfN, bytes);
50         default: SkDEBUGFAIL("unknown text encoding"); return -1;
51     }
52 }
53 
SkUTFN_Next(SkTypeface::Encoding enc,const void ** ptr,const void * stop)54 static inline SkUnichar SkUTFN_Next(SkTypeface::Encoding enc,
55                                     const void** ptr, const void* stop) {
56     switch (enc) {
57         case SkTypeface::kUTF8_Encoding:
58             return SkUTF::NextUTF8((const char**)ptr, (const char*)stop);
59         case SkTypeface::kUTF16_Encoding:
60             return SkUTF::NextUTF16((const uint16_t**)ptr, (const uint16_t*)stop);
61         case SkTypeface::kUTF32_Encoding:
62             return SkUTF::NextUTF32((const int32_t**)ptr, (const int32_t*)stop);
63         default: SkDEBUGFAIL("unknown text encoding"); return -1;
64     }
65 }
66 
67 ///////////////////////////////////////////////////////////////////////////////
68 
69 namespace SkHexadecimalDigits {
70     extern const char gUpper[16];  // 0-9A-F
71     extern const char gLower[16];  // 0-9a-f
72 }
73 
74 #endif
75