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.

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

mercurial