00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SkUtils_DEFINED
00018 #define SkUtils_DEFINED
00019
00020 #include "SkTypes.h"
00021
00023
00029 void sk_memset16_portable(uint16_t dst[], uint16_t value, int count);
00030
00036 void sk_memset32_portable(uint32_t dst[], uint32_t value, int count);
00037
00038 #ifdef ANDROID
00039 #include "cutils/memory.h"
00040
00041 #define sk_memset16(dst, value, count) android_memset16(dst, value, (count) << 1)
00042 #define sk_memset32(dst, value, count) android_memset32(dst, value, (count) << 2)
00043 #endif
00044
00045 #ifndef sk_memset16
00046 #define sk_memset16(dst, value, count) sk_memset16_portable(dst, value, count)
00047 #endif
00048
00049 #ifndef sk_memset32
00050 #define sk_memset32(dst, value, count) sk_memset32_portable(dst, value, count)
00051 #endif
00052
00053
00055
00056 #define kMaxBytesInUTF8Sequence 4
00057
00058 #ifdef SK_DEBUG
00059 int SkUTF8_LeadByteToCount(unsigned c);
00060 #else
00061 #define SkUTF8_LeadByteToCount(c) ((((0xE5 << 24) >> ((unsigned)c >> 4 << 1)) & 3) + 1)
00062 #endif
00063
00064 inline int SkUTF8_CountUTF8Bytes(const char utf8[])
00065 {
00066 SkASSERT(utf8);
00067 return SkUTF8_LeadByteToCount(*(const uint8_t*)utf8);
00068 }
00069
00070 int SkUTF8_CountUnichars(const char utf8[]);
00071 int SkUTF8_CountUnichars(const char utf8[], size_t byteLength);
00072 SkUnichar SkUTF8_ToUnichar(const char utf8[]);
00073 SkUnichar SkUTF8_NextUnichar(const char**);
00074 SkUnichar SkUTF8_PrevUnichar(const char**);
00075
00080 size_t SkUTF8_FromUnichar(SkUnichar uni, char utf8[] = NULL);
00081
00083
00084 #define SkUTF16_IsHighSurrogate(c) (((c) & 0xFC00) == 0xD800)
00085 #define SkUTF16_IsLowSurrogate(c) (((c) & 0xFC00) == 0xDC00)
00086
00087 int SkUTF16_CountUnichars(const uint16_t utf16[]);
00088 int SkUTF16_CountUnichars(const uint16_t utf16[],
00089 int numberOf16BitValues);
00090
00091 SkUnichar SkUTF16_NextUnichar(const uint16_t**);
00092
00093 SkUnichar SkUTF16_PrevUnichar(const uint16_t**);
00094 size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t utf16[] = NULL);
00095
00096 size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues,
00097 char utf8[] = NULL);
00098
00100
00101 class SkAutoTrace {
00102 public:
00106 SkAutoTrace(const char label[]) : fLabel(label) {
00107 SkDebugf("--- trace: %s Enter\n", fLabel);
00108 }
00109 ~SkAutoTrace() {
00110 SkDebugf("--- trace: %s Leave\n", fLabel);
00111 }
00112 private:
00113 const char* fLabel;
00114 };
00115
00117
00118 class SkAutoMemoryUsageProbe {
00119 public:
00125 SkAutoMemoryUsageProbe(const char label[]);
00126 ~SkAutoMemoryUsageProbe();
00127 private:
00128 const char* fLabel;
00129 size_t fBytesAllocated;
00130 };
00131
00132 #endif
00133