gfx/skia/trunk/include/core/SkUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +/*
     1.5 + * Copyright 2006 The Android Open Source Project
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkUtils_DEFINED
    1.12 +#define SkUtils_DEFINED
    1.13 +
    1.14 +#include "SkTypes.h"
    1.15 +
    1.16 +///////////////////////////////////////////////////////////////////////////////
    1.17 +
    1.18 +/** Similar to memset(), but it assigns a 16bit value into the buffer.
    1.19 +    @param buffer   The memory to have value copied into it
    1.20 +    @param value    The 16bit value to be copied into buffer
    1.21 +    @param count    The number of times value should be copied into the buffer.
    1.22 +*/
    1.23 +void sk_memset16_portable(uint16_t dst[], uint16_t value, int count);
    1.24 +typedef void (*SkMemset16Proc)(uint16_t dst[], uint16_t value, int count);
    1.25 +SkMemset16Proc SkMemset16GetPlatformProc();
    1.26 +
    1.27 +/** Similar to memset(), but it assigns a 32bit value into the buffer.
    1.28 +    @param buffer   The memory to have value copied into it
    1.29 +    @param value    The 32bit value to be copied into buffer
    1.30 +    @param count    The number of times value should be copied into the buffer.
    1.31 +*/
    1.32 +void sk_memset32_portable(uint32_t dst[], uint32_t value, int count);
    1.33 +typedef void (*SkMemset32Proc)(uint32_t dst[], uint32_t value, int count);
    1.34 +SkMemset32Proc SkMemset32GetPlatformProc();
    1.35 +
    1.36 +#ifndef sk_memset16
    1.37 +extern SkMemset16Proc sk_memset16;
    1.38 +#endif
    1.39 +
    1.40 +#ifndef sk_memset32
    1.41 +extern SkMemset32Proc sk_memset32;
    1.42 +#endif
    1.43 +
    1.44 +///////////////////////////////////////////////////////////////////////////////
    1.45 +
    1.46 +#define kMaxBytesInUTF8Sequence     4
    1.47 +
    1.48 +#ifdef SK_DEBUG
    1.49 +    int SkUTF8_LeadByteToCount(unsigned c);
    1.50 +#else
    1.51 +    #define SkUTF8_LeadByteToCount(c)   ((((0xE5 << 24) >> ((unsigned)c >> 4 << 1)) & 3) + 1)
    1.52 +#endif
    1.53 +
    1.54 +inline int SkUTF8_CountUTF8Bytes(const char utf8[]) {
    1.55 +    SkASSERT(utf8);
    1.56 +    return SkUTF8_LeadByteToCount(*(const uint8_t*)utf8);
    1.57 +}
    1.58 +
    1.59 +int         SkUTF8_CountUnichars(const char utf8[]);
    1.60 +int         SkUTF8_CountUnichars(const char utf8[], size_t byteLength);
    1.61 +SkUnichar   SkUTF8_ToUnichar(const char utf8[]);
    1.62 +SkUnichar   SkUTF8_NextUnichar(const char**);
    1.63 +SkUnichar   SkUTF8_PrevUnichar(const char**);
    1.64 +
    1.65 +/** Return the number of bytes need to convert a unichar
    1.66 +    into a utf8 sequence. Will be 1..kMaxBytesInUTF8Sequence,
    1.67 +    or 0 if uni is illegal.
    1.68 +*/
    1.69 +size_t      SkUTF8_FromUnichar(SkUnichar uni, char utf8[] = NULL);
    1.70 +
    1.71 +///////////////////////////////////////////////////////////////////////////////
    1.72 +
    1.73 +#define SkUTF16_IsHighSurrogate(c)  (((c) & 0xFC00) == 0xD800)
    1.74 +#define SkUTF16_IsLowSurrogate(c)   (((c) & 0xFC00) == 0xDC00)
    1.75 +
    1.76 +int SkUTF16_CountUnichars(const uint16_t utf16[]);
    1.77 +int SkUTF16_CountUnichars(const uint16_t utf16[], int numberOf16BitValues);
    1.78 +// returns the current unichar and then moves past it (*p++)
    1.79 +SkUnichar SkUTF16_NextUnichar(const uint16_t**);
    1.80 +// this guy backs up to the previus unichar value, and returns it (*--p)
    1.81 +SkUnichar SkUTF16_PrevUnichar(const uint16_t**);
    1.82 +size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t utf16[] = NULL);
    1.83 +
    1.84 +size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues,
    1.85 +                      char utf8[] = NULL);
    1.86 +
    1.87 +inline bool SkUnichar_IsVariationSelector(SkUnichar uni) {
    1.88 +/*  The 'true' ranges are:
    1.89 + *      0x180B  <= uni <=  0x180D
    1.90 + *      0xFE00  <= uni <=  0xFE0F
    1.91 + *      0xE0100 <= uni <= 0xE01EF
    1.92 + */
    1.93 +    if (uni < 0x180B || uni > 0xE01EF) {
    1.94 +        return false;
    1.95 +    }
    1.96 +    if ((uni > 0x180D && uni < 0xFE00) || (uni > 0xFE0F && uni < 0xE0100)) {
    1.97 +        return false;
    1.98 +    }
    1.99 +    return true;
   1.100 +}
   1.101 +
   1.102 +///////////////////////////////////////////////////////////////////////////////
   1.103 +
   1.104 +class SkAutoTrace {
   1.105 +public:
   1.106 +    /** NOTE: label contents are not copied, just the ptr is
   1.107 +        retained, so DON'T DELETE IT.
   1.108 +    */
   1.109 +    SkAutoTrace(const char label[]) : fLabel(label) {
   1.110 +        SkDebugf("--- trace: %s Enter\n", fLabel);
   1.111 +    }
   1.112 +    ~SkAutoTrace() {
   1.113 +        SkDebugf("--- trace: %s Leave\n", fLabel);
   1.114 +    }
   1.115 +private:
   1.116 +    const char* fLabel;
   1.117 +};
   1.118 +#define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace)
   1.119 +
   1.120 +#endif

mercurial