michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkUtils_DEFINED michael@0: #define SkUtils_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: /** Similar to memset(), but it assigns a 16bit value into the buffer. michael@0: @param buffer The memory to have value copied into it michael@0: @param value The 16bit value to be copied into buffer michael@0: @param count The number of times value should be copied into the buffer. michael@0: */ michael@0: void sk_memset16_portable(uint16_t dst[], uint16_t value, int count); michael@0: typedef void (*SkMemset16Proc)(uint16_t dst[], uint16_t value, int count); michael@0: SkMemset16Proc SkMemset16GetPlatformProc(); michael@0: michael@0: /** Similar to memset(), but it assigns a 32bit value into the buffer. michael@0: @param buffer The memory to have value copied into it michael@0: @param value The 32bit value to be copied into buffer michael@0: @param count The number of times value should be copied into the buffer. michael@0: */ michael@0: void sk_memset32_portable(uint32_t dst[], uint32_t value, int count); michael@0: typedef void (*SkMemset32Proc)(uint32_t dst[], uint32_t value, int count); michael@0: SkMemset32Proc SkMemset32GetPlatformProc(); michael@0: michael@0: #ifndef sk_memset16 michael@0: extern SkMemset16Proc sk_memset16; michael@0: #endif michael@0: michael@0: #ifndef sk_memset32 michael@0: extern SkMemset32Proc sk_memset32; michael@0: #endif michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #define kMaxBytesInUTF8Sequence 4 michael@0: michael@0: #ifdef SK_DEBUG michael@0: int SkUTF8_LeadByteToCount(unsigned c); michael@0: #else michael@0: #define SkUTF8_LeadByteToCount(c) ((((0xE5 << 24) >> ((unsigned)c >> 4 << 1)) & 3) + 1) michael@0: #endif michael@0: michael@0: inline int SkUTF8_CountUTF8Bytes(const char utf8[]) { michael@0: SkASSERT(utf8); michael@0: return SkUTF8_LeadByteToCount(*(const uint8_t*)utf8); michael@0: } michael@0: michael@0: int SkUTF8_CountUnichars(const char utf8[]); michael@0: int SkUTF8_CountUnichars(const char utf8[], size_t byteLength); michael@0: SkUnichar SkUTF8_ToUnichar(const char utf8[]); michael@0: SkUnichar SkUTF8_NextUnichar(const char**); michael@0: SkUnichar SkUTF8_PrevUnichar(const char**); michael@0: michael@0: /** Return the number of bytes need to convert a unichar michael@0: into a utf8 sequence. Will be 1..kMaxBytesInUTF8Sequence, michael@0: or 0 if uni is illegal. michael@0: */ michael@0: size_t SkUTF8_FromUnichar(SkUnichar uni, char utf8[] = NULL); michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #define SkUTF16_IsHighSurrogate(c) (((c) & 0xFC00) == 0xD800) michael@0: #define SkUTF16_IsLowSurrogate(c) (((c) & 0xFC00) == 0xDC00) michael@0: michael@0: int SkUTF16_CountUnichars(const uint16_t utf16[]); michael@0: int SkUTF16_CountUnichars(const uint16_t utf16[], int numberOf16BitValues); michael@0: // returns the current unichar and then moves past it (*p++) michael@0: SkUnichar SkUTF16_NextUnichar(const uint16_t**); michael@0: // this guy backs up to the previus unichar value, and returns it (*--p) michael@0: SkUnichar SkUTF16_PrevUnichar(const uint16_t**); michael@0: size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t utf16[] = NULL); michael@0: michael@0: size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues, michael@0: char utf8[] = NULL); michael@0: michael@0: inline bool SkUnichar_IsVariationSelector(SkUnichar uni) { michael@0: /* The 'true' ranges are: michael@0: * 0x180B <= uni <= 0x180D michael@0: * 0xFE00 <= uni <= 0xFE0F michael@0: * 0xE0100 <= uni <= 0xE01EF michael@0: */ michael@0: if (uni < 0x180B || uni > 0xE01EF) { michael@0: return false; michael@0: } michael@0: if ((uni > 0x180D && uni < 0xFE00) || (uni > 0xFE0F && uni < 0xE0100)) { michael@0: return false; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: class SkAutoTrace { michael@0: public: michael@0: /** NOTE: label contents are not copied, just the ptr is michael@0: retained, so DON'T DELETE IT. michael@0: */ michael@0: SkAutoTrace(const char label[]) : fLabel(label) { michael@0: SkDebugf("--- trace: %s Enter\n", fLabel); michael@0: } michael@0: ~SkAutoTrace() { michael@0: SkDebugf("--- trace: %s Leave\n", fLabel); michael@0: } michael@0: private: michael@0: const char* fLabel; michael@0: }; michael@0: #define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace) michael@0: michael@0: #endif