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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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  */
     8 #ifndef SkUtils_DEFINED
     9 #define SkUtils_DEFINED
    11 #include "SkTypes.h"
    13 ///////////////////////////////////////////////////////////////////////////////
    15 /** Similar to memset(), but it assigns a 16bit value into the buffer.
    16     @param buffer   The memory to have value copied into it
    17     @param value    The 16bit value to be copied into buffer
    18     @param count    The number of times value should be copied into the buffer.
    19 */
    20 void sk_memset16_portable(uint16_t dst[], uint16_t value, int count);
    21 typedef void (*SkMemset16Proc)(uint16_t dst[], uint16_t value, int count);
    22 SkMemset16Proc SkMemset16GetPlatformProc();
    24 /** Similar to memset(), but it assigns a 32bit value into the buffer.
    25     @param buffer   The memory to have value copied into it
    26     @param value    The 32bit value to be copied into buffer
    27     @param count    The number of times value should be copied into the buffer.
    28 */
    29 void sk_memset32_portable(uint32_t dst[], uint32_t value, int count);
    30 typedef void (*SkMemset32Proc)(uint32_t dst[], uint32_t value, int count);
    31 SkMemset32Proc SkMemset32GetPlatformProc();
    33 #ifndef sk_memset16
    34 extern SkMemset16Proc sk_memset16;
    35 #endif
    37 #ifndef sk_memset32
    38 extern SkMemset32Proc sk_memset32;
    39 #endif
    41 ///////////////////////////////////////////////////////////////////////////////
    43 #define kMaxBytesInUTF8Sequence     4
    45 #ifdef SK_DEBUG
    46     int SkUTF8_LeadByteToCount(unsigned c);
    47 #else
    48     #define SkUTF8_LeadByteToCount(c)   ((((0xE5 << 24) >> ((unsigned)c >> 4 << 1)) & 3) + 1)
    49 #endif
    51 inline int SkUTF8_CountUTF8Bytes(const char utf8[]) {
    52     SkASSERT(utf8);
    53     return SkUTF8_LeadByteToCount(*(const uint8_t*)utf8);
    54 }
    56 int         SkUTF8_CountUnichars(const char utf8[]);
    57 int         SkUTF8_CountUnichars(const char utf8[], size_t byteLength);
    58 SkUnichar   SkUTF8_ToUnichar(const char utf8[]);
    59 SkUnichar   SkUTF8_NextUnichar(const char**);
    60 SkUnichar   SkUTF8_PrevUnichar(const char**);
    62 /** Return the number of bytes need to convert a unichar
    63     into a utf8 sequence. Will be 1..kMaxBytesInUTF8Sequence,
    64     or 0 if uni is illegal.
    65 */
    66 size_t      SkUTF8_FromUnichar(SkUnichar uni, char utf8[] = NULL);
    68 ///////////////////////////////////////////////////////////////////////////////
    70 #define SkUTF16_IsHighSurrogate(c)  (((c) & 0xFC00) == 0xD800)
    71 #define SkUTF16_IsLowSurrogate(c)   (((c) & 0xFC00) == 0xDC00)
    73 int SkUTF16_CountUnichars(const uint16_t utf16[]);
    74 int SkUTF16_CountUnichars(const uint16_t utf16[], int numberOf16BitValues);
    75 // returns the current unichar and then moves past it (*p++)
    76 SkUnichar SkUTF16_NextUnichar(const uint16_t**);
    77 // this guy backs up to the previus unichar value, and returns it (*--p)
    78 SkUnichar SkUTF16_PrevUnichar(const uint16_t**);
    79 size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t utf16[] = NULL);
    81 size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues,
    82                       char utf8[] = NULL);
    84 inline bool SkUnichar_IsVariationSelector(SkUnichar uni) {
    85 /*  The 'true' ranges are:
    86  *      0x180B  <= uni <=  0x180D
    87  *      0xFE00  <= uni <=  0xFE0F
    88  *      0xE0100 <= uni <= 0xE01EF
    89  */
    90     if (uni < 0x180B || uni > 0xE01EF) {
    91         return false;
    92     }
    93     if ((uni > 0x180D && uni < 0xFE00) || (uni > 0xFE0F && uni < 0xE0100)) {
    94         return false;
    95     }
    96     return true;
    97 }
    99 ///////////////////////////////////////////////////////////////////////////////
   101 class SkAutoTrace {
   102 public:
   103     /** NOTE: label contents are not copied, just the ptr is
   104         retained, so DON'T DELETE IT.
   105     */
   106     SkAutoTrace(const char label[]) : fLabel(label) {
   107         SkDebugf("--- trace: %s Enter\n", fLabel);
   108     }
   109     ~SkAutoTrace() {
   110         SkDebugf("--- trace: %s Leave\n", fLabel);
   111     }
   112 private:
   113     const char* fLabel;
   114 };
   115 #define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace)
   117 #endif

mercurial