Sat, 03 Jan 2015 20:18:00 +0100
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 (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
michael@0 | 3 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | // found in the LICENSE file. |
michael@0 | 5 | // |
michael@0 | 6 | |
michael@0 | 7 | // generatemip.h: Defines the GenerateMip function, templated on the format |
michael@0 | 8 | // type of the image for which mip levels are being generated. |
michael@0 | 9 | |
michael@0 | 10 | #ifndef LIBGLESV2_RENDERER_GENERATEMIP_H_ |
michael@0 | 11 | #define LIBGLESV2_RENDERER_GENERATEMIP_H_ |
michael@0 | 12 | |
michael@0 | 13 | #include "libGLESv2/mathutil.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace rx |
michael@0 | 16 | { |
michael@0 | 17 | struct L8 |
michael@0 | 18 | { |
michael@0 | 19 | unsigned char L; |
michael@0 | 20 | |
michael@0 | 21 | static void average(L8 *dst, const L8 *src1, const L8 *src2) |
michael@0 | 22 | { |
michael@0 | 23 | dst->L = ((src1->L ^ src2->L) >> 1) + (src1->L & src2->L); |
michael@0 | 24 | } |
michael@0 | 25 | }; |
michael@0 | 26 | |
michael@0 | 27 | typedef L8 R8; // R8 type is functionally equivalent for mip purposes |
michael@0 | 28 | typedef L8 A8; // A8 type is functionally equivalent for mip purposes |
michael@0 | 29 | |
michael@0 | 30 | struct A8L8 |
michael@0 | 31 | { |
michael@0 | 32 | unsigned char L; |
michael@0 | 33 | unsigned char A; |
michael@0 | 34 | |
michael@0 | 35 | static void average(A8L8 *dst, const A8L8 *src1, const A8L8 *src2) |
michael@0 | 36 | { |
michael@0 | 37 | *(unsigned short*)dst = (((*(unsigned short*)src1 ^ *(unsigned short*)src2) & 0xFEFE) >> 1) + (*(unsigned short*)src1 & *(unsigned short*)src2); |
michael@0 | 38 | } |
michael@0 | 39 | }; |
michael@0 | 40 | |
michael@0 | 41 | typedef A8L8 R8G8; // R8G8 type is functionally equivalent for mip purposes |
michael@0 | 42 | |
michael@0 | 43 | struct A8R8G8B8 |
michael@0 | 44 | { |
michael@0 | 45 | unsigned char B; |
michael@0 | 46 | unsigned char G; |
michael@0 | 47 | unsigned char R; |
michael@0 | 48 | unsigned char A; |
michael@0 | 49 | |
michael@0 | 50 | static void average(A8R8G8B8 *dst, const A8R8G8B8 *src1, const A8R8G8B8 *src2) |
michael@0 | 51 | { |
michael@0 | 52 | *(unsigned int*)dst = (((*(unsigned int*)src1 ^ *(unsigned int*)src2) & 0xFEFEFEFE) >> 1) + (*(unsigned int*)src1 & *(unsigned int*)src2); |
michael@0 | 53 | } |
michael@0 | 54 | }; |
michael@0 | 55 | |
michael@0 | 56 | typedef A8R8G8B8 R8G8B8A8; // R8G8B8A8 type is functionally equivalent for mip purposes |
michael@0 | 57 | |
michael@0 | 58 | struct A16B16G16R16F |
michael@0 | 59 | { |
michael@0 | 60 | unsigned short R; |
michael@0 | 61 | unsigned short G; |
michael@0 | 62 | unsigned short B; |
michael@0 | 63 | unsigned short A; |
michael@0 | 64 | |
michael@0 | 65 | static void average(A16B16G16R16F *dst, const A16B16G16R16F *src1, const A16B16G16R16F *src2) |
michael@0 | 66 | { |
michael@0 | 67 | dst->R = gl::float32ToFloat16((gl::float16ToFloat32(src1->R) + gl::float16ToFloat32(src2->R)) * 0.5f); |
michael@0 | 68 | dst->G = gl::float32ToFloat16((gl::float16ToFloat32(src1->G) + gl::float16ToFloat32(src2->G)) * 0.5f); |
michael@0 | 69 | dst->B = gl::float32ToFloat16((gl::float16ToFloat32(src1->B) + gl::float16ToFloat32(src2->B)) * 0.5f); |
michael@0 | 70 | dst->A = gl::float32ToFloat16((gl::float16ToFloat32(src1->A) + gl::float16ToFloat32(src2->A)) * 0.5f); |
michael@0 | 71 | } |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | struct R16F |
michael@0 | 75 | { |
michael@0 | 76 | unsigned short R; |
michael@0 | 77 | |
michael@0 | 78 | static void average(R16F *dst, const R16F *src1, const R16F *src2) |
michael@0 | 79 | { |
michael@0 | 80 | dst->R = gl::float32ToFloat16((gl::float16ToFloat32(src1->R) + gl::float16ToFloat32(src2->R)) * 0.5f); |
michael@0 | 81 | } |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | struct R16G16F |
michael@0 | 85 | { |
michael@0 | 86 | unsigned short R; |
michael@0 | 87 | unsigned short G; |
michael@0 | 88 | |
michael@0 | 89 | static void average(R16G16F *dst, const R16G16F *src1, const R16G16F *src2) |
michael@0 | 90 | { |
michael@0 | 91 | dst->R = gl::float32ToFloat16((gl::float16ToFloat32(src1->R) + gl::float16ToFloat32(src2->R)) * 0.5f); |
michael@0 | 92 | dst->G = gl::float32ToFloat16((gl::float16ToFloat32(src1->G) + gl::float16ToFloat32(src2->G)) * 0.5f); |
michael@0 | 93 | } |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | struct A32B32G32R32F |
michael@0 | 97 | { |
michael@0 | 98 | float R; |
michael@0 | 99 | float G; |
michael@0 | 100 | float B; |
michael@0 | 101 | float A; |
michael@0 | 102 | |
michael@0 | 103 | static void average(A32B32G32R32F *dst, const A32B32G32R32F *src1, const A32B32G32R32F *src2) |
michael@0 | 104 | { |
michael@0 | 105 | dst->R = (src1->R + src2->R) * 0.5f; |
michael@0 | 106 | dst->G = (src1->G + src2->G) * 0.5f; |
michael@0 | 107 | dst->B = (src1->B + src2->B) * 0.5f; |
michael@0 | 108 | dst->A = (src1->A + src2->A) * 0.5f; |
michael@0 | 109 | } |
michael@0 | 110 | }; |
michael@0 | 111 | |
michael@0 | 112 | struct R32F |
michael@0 | 113 | { |
michael@0 | 114 | float R; |
michael@0 | 115 | |
michael@0 | 116 | static void average(R32F *dst, const R32F *src1, const R32F *src2) |
michael@0 | 117 | { |
michael@0 | 118 | dst->R = (src1->R + src2->R) * 0.5f; |
michael@0 | 119 | } |
michael@0 | 120 | }; |
michael@0 | 121 | |
michael@0 | 122 | struct R32G32F |
michael@0 | 123 | { |
michael@0 | 124 | float R; |
michael@0 | 125 | float G; |
michael@0 | 126 | |
michael@0 | 127 | static void average(R32G32F *dst, const R32G32F *src1, const R32G32F *src2) |
michael@0 | 128 | { |
michael@0 | 129 | dst->R = (src1->R + src2->R) * 0.5f; |
michael@0 | 130 | dst->G = (src1->G + src2->G) * 0.5f; |
michael@0 | 131 | } |
michael@0 | 132 | }; |
michael@0 | 133 | |
michael@0 | 134 | struct R32G32B32F |
michael@0 | 135 | { |
michael@0 | 136 | float R; |
michael@0 | 137 | float G; |
michael@0 | 138 | float B; |
michael@0 | 139 | |
michael@0 | 140 | static void average(R32G32B32F *dst, const R32G32B32F *src1, const R32G32B32F *src2) |
michael@0 | 141 | { |
michael@0 | 142 | dst->R = (src1->R + src2->R) * 0.5f; |
michael@0 | 143 | dst->G = (src1->G + src2->G) * 0.5f; |
michael@0 | 144 | dst->B = (src1->B + src2->B) * 0.5f; |
michael@0 | 145 | } |
michael@0 | 146 | }; |
michael@0 | 147 | |
michael@0 | 148 | template <typename T> |
michael@0 | 149 | static void GenerateMip(unsigned int sourceWidth, unsigned int sourceHeight, |
michael@0 | 150 | const unsigned char *sourceData, int sourcePitch, |
michael@0 | 151 | unsigned char *destData, int destPitch) |
michael@0 | 152 | { |
michael@0 | 153 | unsigned int mipWidth = std::max(1U, sourceWidth >> 1); |
michael@0 | 154 | unsigned int mipHeight = std::max(1U, sourceHeight >> 1); |
michael@0 | 155 | |
michael@0 | 156 | if (sourceHeight == 1) |
michael@0 | 157 | { |
michael@0 | 158 | ASSERT(sourceWidth != 1); |
michael@0 | 159 | |
michael@0 | 160 | const T *src = (const T*)sourceData; |
michael@0 | 161 | T *dst = (T*)destData; |
michael@0 | 162 | |
michael@0 | 163 | for (unsigned int x = 0; x < mipWidth; x++) |
michael@0 | 164 | { |
michael@0 | 165 | T::average(&dst[x], &src[x * 2], &src[x * 2 + 1]); |
michael@0 | 166 | } |
michael@0 | 167 | } |
michael@0 | 168 | else if (sourceWidth == 1) |
michael@0 | 169 | { |
michael@0 | 170 | ASSERT(sourceHeight != 1); |
michael@0 | 171 | |
michael@0 | 172 | for (unsigned int y = 0; y < mipHeight; y++) |
michael@0 | 173 | { |
michael@0 | 174 | const T *src0 = (const T*)(sourceData + y * 2 * sourcePitch); |
michael@0 | 175 | const T *src1 = (const T*)(sourceData + y * 2 * sourcePitch + sourcePitch); |
michael@0 | 176 | T *dst = (T*)(destData + y * destPitch); |
michael@0 | 177 | |
michael@0 | 178 | T::average(dst, src0, src1); |
michael@0 | 179 | } |
michael@0 | 180 | } |
michael@0 | 181 | else |
michael@0 | 182 | { |
michael@0 | 183 | for (unsigned int y = 0; y < mipHeight; y++) |
michael@0 | 184 | { |
michael@0 | 185 | const T *src0 = (const T*)(sourceData + y * 2 * sourcePitch); |
michael@0 | 186 | const T *src1 = (const T*)(sourceData + y * 2 * sourcePitch + sourcePitch); |
michael@0 | 187 | T *dst = (T*)(destData + y * destPitch); |
michael@0 | 188 | |
michael@0 | 189 | for (unsigned int x = 0; x < mipWidth; x++) |
michael@0 | 190 | { |
michael@0 | 191 | T tmp0; |
michael@0 | 192 | T tmp1; |
michael@0 | 193 | |
michael@0 | 194 | T::average(&tmp0, &src0[x * 2], &src0[x * 2 + 1]); |
michael@0 | 195 | T::average(&tmp1, &src1[x * 2], &src1[x * 2 + 1]); |
michael@0 | 196 | T::average(&dst[x], &tmp0, &tmp1); |
michael@0 | 197 | } |
michael@0 | 198 | } |
michael@0 | 199 | } |
michael@0 | 200 | } |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | #endif // LIBGLESV2_RENDERER_GENERATEMIP_H_ |