gfx/skia/trunk/src/core/SkBuffer.cpp

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 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkBuffer.h"
michael@0 11
michael@0 12 ////////////////////////////////////////////////////////////////////////////////////////
michael@0 13
michael@0 14 void SkRBuffer::readNoSizeCheck(void* buffer, size_t size)
michael@0 15 {
michael@0 16 SkASSERT((fData != 0 && fStop == 0) || fPos + size <= fStop);
michael@0 17 if (buffer)
michael@0 18 memcpy(buffer, fPos, size);
michael@0 19 fPos += size;
michael@0 20 }
michael@0 21
michael@0 22 const void* SkRBuffer::skip(size_t size)
michael@0 23 {
michael@0 24 const void* result = fPos;
michael@0 25 readNoSizeCheck(NULL, size);
michael@0 26 return result;
michael@0 27 }
michael@0 28
michael@0 29 size_t SkRBuffer::skipToAlign4()
michael@0 30 {
michael@0 31 size_t pos = this->pos();
michael@0 32 size_t n = SkAlign4(pos) - pos;
michael@0 33 fPos += n;
michael@0 34 return n;
michael@0 35 }
michael@0 36
michael@0 37 bool SkRBufferWithSizeCheck::read(void* buffer, size_t size) {
michael@0 38 fError = fError || (fPos + size > fStop);
michael@0 39 if (!fError && (size > 0)) {
michael@0 40 readNoSizeCheck(buffer, size);
michael@0 41 }
michael@0 42 return !fError;
michael@0 43 }
michael@0 44
michael@0 45 void* SkWBuffer::skip(size_t size)
michael@0 46 {
michael@0 47 void* result = fPos;
michael@0 48 writeNoSizeCheck(NULL, size);
michael@0 49 return fData == NULL ? NULL : result;
michael@0 50 }
michael@0 51
michael@0 52 void SkWBuffer::writeNoSizeCheck(const void* buffer, size_t size)
michael@0 53 {
michael@0 54 SkASSERT(fData == 0 || fStop == 0 || fPos + size <= fStop);
michael@0 55 if (fData && buffer)
michael@0 56 memcpy(fPos, buffer, size);
michael@0 57 fPos += size;
michael@0 58 }
michael@0 59
michael@0 60 size_t SkWBuffer::padToAlign4()
michael@0 61 {
michael@0 62 size_t pos = this->pos();
michael@0 63 size_t n = SkAlign4(pos) - pos;
michael@0 64
michael@0 65 if (n && fData)
michael@0 66 {
michael@0 67 char* p = fPos;
michael@0 68 char* stop = p + n;
michael@0 69 do {
michael@0 70 *p++ = 0;
michael@0 71 } while (p < stop);
michael@0 72 }
michael@0 73 fPos += n;
michael@0 74 return n;
michael@0 75 }
michael@0 76
michael@0 77 #if 0
michael@0 78 #ifdef SK_DEBUG
michael@0 79 static void AssertBuffer32(const void* buffer)
michael@0 80 {
michael@0 81 SkASSERT(buffer);
michael@0 82 SkASSERT(((size_t)buffer & 3) == 0);
michael@0 83 }
michael@0 84 #else
michael@0 85 #define AssertBuffer32(buffer)
michael@0 86 #endif
michael@0 87
michael@0 88 void* sk_buffer_write_int32(void* buffer, int32_t value)
michael@0 89 {
michael@0 90 AssertBuffer32(buffer);
michael@0 91 *(int32_t*)buffer = value;
michael@0 92 return (char*)buffer + sizeof(int32_t);
michael@0 93 }
michael@0 94
michael@0 95 void* sk_buffer_write_int32(void* buffer, const int32_t values[], int count)
michael@0 96 {
michael@0 97 AssertBuffer32(buffer);
michael@0 98 SkASSERT(count >= 0);
michael@0 99
michael@0 100 memcpy((int32_t*)buffer, values, count * sizeof(int32_t));
michael@0 101 return (char*)buffer + count * sizeof(int32_t);
michael@0 102 }
michael@0 103
michael@0 104 const void* sk_buffer_read_int32(const void* buffer, int32_t* value)
michael@0 105 {
michael@0 106 AssertBuffer32(buffer);
michael@0 107 if (value)
michael@0 108 *value = *(const int32_t*)buffer;
michael@0 109 return (const char*)buffer + sizeof(int32_t);
michael@0 110 }
michael@0 111
michael@0 112 const void* sk_buffer_read_int32(const void* buffer, int32_t values[], int count)
michael@0 113 {
michael@0 114 AssertBuffer32(buffer);
michael@0 115 SkASSERT(count >= 0);
michael@0 116
michael@0 117 if (values)
michael@0 118 memcpy(values, (const int32_t*)buffer, count * sizeof(int32_t));
michael@0 119 return (const char*)buffer + count * sizeof(int32_t);
michael@0 120 }
michael@0 121
michael@0 122 void* sk_buffer_write_ptr(void* buffer, void* ptr)
michael@0 123 {
michael@0 124 AssertBuffer32(buffer);
michael@0 125 *(void**)buffer = ptr;
michael@0 126 return (char*)buffer + sizeof(void*);
michael@0 127 }
michael@0 128
michael@0 129 const void* sk_buffer_read_ptr(const void* buffer, void** ptr)
michael@0 130 {
michael@0 131 AssertBuffer32(buffer);
michael@0 132 if (ptr)
michael@0 133 *ptr = *(void**)buffer;
michael@0 134 return (const char*)buffer + sizeof(void*);
michael@0 135 }
michael@0 136
michael@0 137 #endif

mercurial