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 2011 Google Inc. |
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 | |
michael@0 | 9 | #include "GrGLUtil.h" |
michael@0 | 10 | #include "SkMatrix.h" |
michael@0 | 11 | #include <stdio.h> |
michael@0 | 12 | |
michael@0 | 13 | void GrGLClearErr(const GrGLInterface* gl) { |
michael@0 | 14 | while (GR_GL_NO_ERROR != gl->fFunctions.fGetError()) {} |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | namespace { |
michael@0 | 18 | const char *get_error_string(uint32_t err) { |
michael@0 | 19 | switch (err) { |
michael@0 | 20 | case GR_GL_NO_ERROR: |
michael@0 | 21 | return ""; |
michael@0 | 22 | case GR_GL_INVALID_ENUM: |
michael@0 | 23 | return "Invalid Enum"; |
michael@0 | 24 | case GR_GL_INVALID_VALUE: |
michael@0 | 25 | return "Invalid Value"; |
michael@0 | 26 | case GR_GL_INVALID_OPERATION: |
michael@0 | 27 | return "Invalid Operation"; |
michael@0 | 28 | case GR_GL_OUT_OF_MEMORY: |
michael@0 | 29 | return "Out of Memory"; |
michael@0 | 30 | case GR_GL_CONTEXT_LOST: |
michael@0 | 31 | return "Context Lost"; |
michael@0 | 32 | } |
michael@0 | 33 | return "Unknown"; |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | void GrGLCheckErr(const GrGLInterface* gl, |
michael@0 | 38 | const char* location, |
michael@0 | 39 | const char* call) { |
michael@0 | 40 | uint32_t err = GR_GL_GET_ERROR(gl); |
michael@0 | 41 | if (GR_GL_NO_ERROR != err) { |
michael@0 | 42 | GrPrintf("---- glGetError 0x%x(%s)", err, get_error_string(err)); |
michael@0 | 43 | if (NULL != location) { |
michael@0 | 44 | GrPrintf(" at\n\t%s", location); |
michael@0 | 45 | } |
michael@0 | 46 | if (NULL != call) { |
michael@0 | 47 | GrPrintf("\n\t\t%s", call); |
michael@0 | 48 | } |
michael@0 | 49 | GrPrintf("\n"); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | namespace { |
michael@0 | 54 | // Mesa uses a non-standard version string of format: 1.4 Mesa <mesa_major>.<mesa_minor>. |
michael@0 | 55 | // The mapping of from mesa version to GL version came from here: http://www.mesa3d.org/intro.html |
michael@0 | 56 | bool get_gl_version_for_mesa(int mesaMajorVersion, int* major, int* minor) { |
michael@0 | 57 | switch (mesaMajorVersion) { |
michael@0 | 58 | case 2: |
michael@0 | 59 | case 3: |
michael@0 | 60 | case 4: |
michael@0 | 61 | case 5: |
michael@0 | 62 | case 6: |
michael@0 | 63 | *major = 1; |
michael@0 | 64 | *minor = mesaMajorVersion - 1; |
michael@0 | 65 | return true; |
michael@0 | 66 | case 7: |
michael@0 | 67 | *major = 2; |
michael@0 | 68 | *minor = 1; |
michael@0 | 69 | return true; |
michael@0 | 70 | case 8: |
michael@0 | 71 | *major = 3; |
michael@0 | 72 | *minor = 0; |
michael@0 | 73 | return true; |
michael@0 | 74 | case 9: |
michael@0 | 75 | *major = 3; |
michael@0 | 76 | *minor = 1; |
michael@0 | 77 | return true; |
michael@0 | 78 | case 10: |
michael@0 | 79 | *major = 3; |
michael@0 | 80 | *minor = 3; |
michael@0 | 81 | return true; |
michael@0 | 82 | default: |
michael@0 | 83 | return false; |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 89 | |
michael@0 | 90 | #if GR_GL_LOG_CALLS |
michael@0 | 91 | bool gLogCallsGL = !!(GR_GL_LOG_CALLS_START); |
michael@0 | 92 | #endif |
michael@0 | 93 | |
michael@0 | 94 | #if GR_GL_CHECK_ERROR |
michael@0 | 95 | bool gCheckErrorGL = !!(GR_GL_CHECK_ERROR_START); |
michael@0 | 96 | #endif |
michael@0 | 97 | |
michael@0 | 98 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 99 | |
michael@0 | 100 | GrGLStandard GrGLGetStandardInUseFromString(const char* versionString) { |
michael@0 | 101 | if (NULL == versionString) { |
michael@0 | 102 | SkDEBUGFAIL("NULL GL version string."); |
michael@0 | 103 | return kNone_GrGLStandard; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | int major, minor; |
michael@0 | 107 | |
michael@0 | 108 | // check for desktop |
michael@0 | 109 | int n = sscanf(versionString, "%d.%d", &major, &minor); |
michael@0 | 110 | if (2 == n) { |
michael@0 | 111 | return kGL_GrGLStandard; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | // check for ES 1 |
michael@0 | 115 | char profile[2]; |
michael@0 | 116 | n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1, &major, &minor); |
michael@0 | 117 | if (4 == n) { |
michael@0 | 118 | // we no longer support ES1. |
michael@0 | 119 | return kNone_GrGLStandard; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | // check for ES2 |
michael@0 | 123 | n = sscanf(versionString, "OpenGL ES %d.%d", &major, &minor); |
michael@0 | 124 | if (2 == n) { |
michael@0 | 125 | return kGLES_GrGLStandard; |
michael@0 | 126 | } |
michael@0 | 127 | return kNone_GrGLStandard; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | bool GrGLIsMesaFromVersionString(const char* versionString) { |
michael@0 | 131 | int major, minor, mesaMajor, mesaMinor; |
michael@0 | 132 | int n = sscanf(versionString, "%d.%d Mesa %d.%d", &major, &minor, &mesaMajor, &mesaMinor); |
michael@0 | 133 | return 4 == n; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | bool GrGLIsChromiumFromRendererString(const char* rendererString) { |
michael@0 | 137 | return 0 == strcmp(rendererString, "Chromium"); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | GrGLVersion GrGLGetVersionFromString(const char* versionString) { |
michael@0 | 141 | if (NULL == versionString) { |
michael@0 | 142 | SkDEBUGFAIL("NULL GL version string."); |
michael@0 | 143 | return 0; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | int major, minor; |
michael@0 | 147 | |
michael@0 | 148 | // check for mesa |
michael@0 | 149 | int mesaMajor, mesaMinor; |
michael@0 | 150 | int n = sscanf(versionString, "%d.%d Mesa %d.%d", &major, &minor, &mesaMajor, &mesaMinor); |
michael@0 | 151 | if (4 == n) { |
michael@0 | 152 | if (get_gl_version_for_mesa(mesaMajor, &major, &minor)) { |
michael@0 | 153 | return GR_GL_VER(major, minor); |
michael@0 | 154 | } else { |
michael@0 | 155 | return 0; |
michael@0 | 156 | } |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | n = sscanf(versionString, "%d.%d", &major, &minor); |
michael@0 | 160 | if (2 == n) { |
michael@0 | 161 | return GR_GL_VER(major, minor); |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | char profile[2]; |
michael@0 | 165 | n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1, |
michael@0 | 166 | &major, &minor); |
michael@0 | 167 | if (4 == n) { |
michael@0 | 168 | return GR_GL_VER(major, minor); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | n = sscanf(versionString, "OpenGL ES %d.%d", &major, &minor); |
michael@0 | 172 | if (2 == n) { |
michael@0 | 173 | return GR_GL_VER(major, minor); |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | return 0; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString) { |
michael@0 | 180 | if (NULL == versionString) { |
michael@0 | 181 | SkDEBUGFAIL("NULL GLSL version string."); |
michael@0 | 182 | return 0; |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | int major, minor; |
michael@0 | 186 | |
michael@0 | 187 | int n = sscanf(versionString, "%d.%d", &major, &minor); |
michael@0 | 188 | if (2 == n) { |
michael@0 | 189 | return GR_GLSL_VER(major, minor); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | n = sscanf(versionString, "OpenGL ES GLSL ES %d.%d", &major, &minor); |
michael@0 | 193 | if (2 == n) { |
michael@0 | 194 | return GR_GLSL_VER(major, minor); |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | #ifdef SK_BUILD_FOR_ANDROID |
michael@0 | 198 | // android hack until the gpu vender updates their drivers |
michael@0 | 199 | n = sscanf(versionString, "OpenGL ES GLSL %d.%d", &major, &minor); |
michael@0 | 200 | if (2 == n) { |
michael@0 | 201 | return GR_GLSL_VER(major, minor); |
michael@0 | 202 | } |
michael@0 | 203 | #endif |
michael@0 | 204 | |
michael@0 | 205 | return 0; |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | GrGLVendor GrGLGetVendorFromString(const char* vendorString) { |
michael@0 | 209 | if (NULL != vendorString) { |
michael@0 | 210 | if (0 == strcmp(vendorString, "ARM")) { |
michael@0 | 211 | return kARM_GrGLVendor; |
michael@0 | 212 | } |
michael@0 | 213 | if (0 == strcmp(vendorString, "Imagination Technologies")) { |
michael@0 | 214 | return kImagination_GrGLVendor; |
michael@0 | 215 | } |
michael@0 | 216 | if (0 == strncmp(vendorString, "Intel ", 6) || 0 == strcmp(vendorString, "Intel")) { |
michael@0 | 217 | return kIntel_GrGLVendor; |
michael@0 | 218 | } |
michael@0 | 219 | if (0 == strcmp(vendorString, "Qualcomm")) { |
michael@0 | 220 | return kQualcomm_GrGLVendor; |
michael@0 | 221 | } |
michael@0 | 222 | } |
michael@0 | 223 | return kOther_GrGLVendor; |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | GrGLRenderer GrGLGetRendererFromString(const char* rendererString) { |
michael@0 | 227 | if (NULL != rendererString) { |
michael@0 | 228 | if (0 == strcmp(rendererString, "NVIDIA Tegra 3")) { |
michael@0 | 229 | return kTegra3_GrGLRenderer; |
michael@0 | 230 | } else if (0 == strcmp(rendererString, "NVIDIA Tegra")) { |
michael@0 | 231 | return kTegra2_GrGLRenderer; |
michael@0 | 232 | } |
michael@0 | 233 | } |
michael@0 | 234 | return kOther_GrGLRenderer; |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | GrGLVersion GrGLGetVersion(const GrGLInterface* gl) { |
michael@0 | 238 | const GrGLubyte* v; |
michael@0 | 239 | GR_GL_CALL_RET(gl, v, GetString(GR_GL_VERSION)); |
michael@0 | 240 | return GrGLGetVersionFromString((const char*) v); |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface* gl) { |
michael@0 | 244 | const GrGLubyte* v; |
michael@0 | 245 | GR_GL_CALL_RET(gl, v, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
michael@0 | 246 | return GrGLGetGLSLVersionFromString((const char*) v); |
michael@0 | 247 | } |
michael@0 | 248 | |
michael@0 | 249 | GrGLVendor GrGLGetVendor(const GrGLInterface* gl) { |
michael@0 | 250 | const GrGLubyte* v; |
michael@0 | 251 | GR_GL_CALL_RET(gl, v, GetString(GR_GL_VENDOR)); |
michael@0 | 252 | return GrGLGetVendorFromString((const char*) v); |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | GrGLRenderer GrGLGetRenderer(const GrGLInterface* gl) { |
michael@0 | 256 | const GrGLubyte* v; |
michael@0 | 257 | GR_GL_CALL_RET(gl, v, GetString(GR_GL_RENDERER)); |
michael@0 | 258 | return GrGLGetRendererFromString((const char*) v); |
michael@0 | 259 | } |
michael@0 | 260 | |
michael@0 | 261 | template<> void GrGLGetMatrix<3>(GrGLfloat* dest, const SkMatrix& src) { |
michael@0 | 262 | // Col 0 |
michael@0 | 263 | dest[0] = SkScalarToFloat(src[SkMatrix::kMScaleX]); |
michael@0 | 264 | dest[1] = SkScalarToFloat(src[SkMatrix::kMSkewY]); |
michael@0 | 265 | dest[2] = SkScalarToFloat(src[SkMatrix::kMPersp0]); |
michael@0 | 266 | |
michael@0 | 267 | // Col 1 |
michael@0 | 268 | dest[3] = SkScalarToFloat(src[SkMatrix::kMSkewX]); |
michael@0 | 269 | dest[4] = SkScalarToFloat(src[SkMatrix::kMScaleY]); |
michael@0 | 270 | dest[5] = SkScalarToFloat(src[SkMatrix::kMPersp1]); |
michael@0 | 271 | |
michael@0 | 272 | // Col 2 |
michael@0 | 273 | dest[6] = SkScalarToFloat(src[SkMatrix::kMTransX]); |
michael@0 | 274 | dest[7] = SkScalarToFloat(src[SkMatrix::kMTransY]); |
michael@0 | 275 | dest[8] = SkScalarToFloat(src[SkMatrix::kMPersp2]); |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | template<> void GrGLGetMatrix<4>(GrGLfloat* dest, const SkMatrix& src) { |
michael@0 | 279 | // Col 0 |
michael@0 | 280 | dest[0] = SkScalarToFloat(src[SkMatrix::kMScaleX]); |
michael@0 | 281 | dest[1] = SkScalarToFloat(src[SkMatrix::kMSkewY]); |
michael@0 | 282 | dest[2] = 0; |
michael@0 | 283 | dest[3] = SkScalarToFloat(src[SkMatrix::kMPersp0]); |
michael@0 | 284 | |
michael@0 | 285 | // Col 1 |
michael@0 | 286 | dest[4] = SkScalarToFloat(src[SkMatrix::kMSkewX]); |
michael@0 | 287 | dest[5] = SkScalarToFloat(src[SkMatrix::kMScaleY]); |
michael@0 | 288 | dest[6] = 0; |
michael@0 | 289 | dest[7] = SkScalarToFloat(src[SkMatrix::kMPersp1]); |
michael@0 | 290 | |
michael@0 | 291 | // Col 2 |
michael@0 | 292 | dest[8] = 0; |
michael@0 | 293 | dest[9] = 0; |
michael@0 | 294 | dest[10] = 1; |
michael@0 | 295 | dest[11] = 0; |
michael@0 | 296 | |
michael@0 | 297 | // Col 3 |
michael@0 | 298 | dest[12] = SkScalarToFloat(src[SkMatrix::kMTransX]); |
michael@0 | 299 | dest[13] = SkScalarToFloat(src[SkMatrix::kMTransY]); |
michael@0 | 300 | dest[14] = 0; |
michael@0 | 301 | dest[15] = SkScalarToFloat(src[SkMatrix::kMPersp2]); |
michael@0 | 302 | } |