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-2010 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 | // Config.cpp: Implements the egl::Config class, describing the format, type |
michael@0 | 8 | // and size for an egl::Surface. Implements EGLConfig and related functionality. |
michael@0 | 9 | // [EGL 1.4] section 3.4 page 15. |
michael@0 | 10 | |
michael@0 | 11 | #include "libEGL/Config.h" |
michael@0 | 12 | |
michael@0 | 13 | #include <algorithm> |
michael@0 | 14 | #include <vector> |
michael@0 | 15 | |
michael@0 | 16 | #include <GLES2/gl2.h> |
michael@0 | 17 | #include <GLES2/gl2ext.h> |
michael@0 | 18 | |
michael@0 | 19 | #include "common/debug.h" |
michael@0 | 20 | |
michael@0 | 21 | using namespace std; |
michael@0 | 22 | |
michael@0 | 23 | namespace egl |
michael@0 | 24 | { |
michael@0 | 25 | Config::Config(rx::ConfigDesc desc, EGLint minInterval, EGLint maxInterval, EGLint texWidth, EGLint texHeight) |
michael@0 | 26 | : mRenderTargetFormat(desc.renderTargetFormat), mDepthStencilFormat(desc.depthStencilFormat), mMultiSample(desc.multiSample) |
michael@0 | 27 | { |
michael@0 | 28 | mBindToTextureRGB = EGL_FALSE; |
michael@0 | 29 | mBindToTextureRGBA = EGL_FALSE; |
michael@0 | 30 | switch (desc.renderTargetFormat) |
michael@0 | 31 | { |
michael@0 | 32 | case GL_RGB5_A1: |
michael@0 | 33 | mBufferSize = 16; |
michael@0 | 34 | mRedSize = 5; |
michael@0 | 35 | mGreenSize = 5; |
michael@0 | 36 | mBlueSize = 5; |
michael@0 | 37 | mAlphaSize = 1; |
michael@0 | 38 | break; |
michael@0 | 39 | case GL_RGBA8_OES: |
michael@0 | 40 | mBufferSize = 32; |
michael@0 | 41 | mRedSize = 8; |
michael@0 | 42 | mGreenSize = 8; |
michael@0 | 43 | mBlueSize = 8; |
michael@0 | 44 | mAlphaSize = 8; |
michael@0 | 45 | mBindToTextureRGBA = true; |
michael@0 | 46 | break; |
michael@0 | 47 | case GL_RGB565: |
michael@0 | 48 | mBufferSize = 16; |
michael@0 | 49 | mRedSize = 5; |
michael@0 | 50 | mGreenSize = 6; |
michael@0 | 51 | mBlueSize = 5; |
michael@0 | 52 | mAlphaSize = 0; |
michael@0 | 53 | break; |
michael@0 | 54 | case GL_RGB8_OES: |
michael@0 | 55 | mBufferSize = 32; |
michael@0 | 56 | mRedSize = 8; |
michael@0 | 57 | mGreenSize = 8; |
michael@0 | 58 | mBlueSize = 8; |
michael@0 | 59 | mAlphaSize = 0; |
michael@0 | 60 | mBindToTextureRGB = true; |
michael@0 | 61 | break; |
michael@0 | 62 | case GL_BGRA8_EXT: |
michael@0 | 63 | mBufferSize = 32; |
michael@0 | 64 | mRedSize = 8; |
michael@0 | 65 | mGreenSize = 8; |
michael@0 | 66 | mBlueSize = 8; |
michael@0 | 67 | mAlphaSize = 8; |
michael@0 | 68 | mBindToTextureRGBA = true; |
michael@0 | 69 | break; |
michael@0 | 70 | default: |
michael@0 | 71 | UNREACHABLE(); // Other formats should not be valid |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | mLuminanceSize = 0; |
michael@0 | 75 | mAlphaMaskSize = 0; |
michael@0 | 76 | mColorBufferType = EGL_RGB_BUFFER; |
michael@0 | 77 | mConfigCaveat = (desc.fastConfig) ? EGL_NONE : EGL_SLOW_CONFIG; |
michael@0 | 78 | mConfigID = 0; |
michael@0 | 79 | mConformant = EGL_OPENGL_ES2_BIT; |
michael@0 | 80 | |
michael@0 | 81 | switch (desc.depthStencilFormat) |
michael@0 | 82 | { |
michael@0 | 83 | case GL_NONE: |
michael@0 | 84 | mDepthSize = 0; |
michael@0 | 85 | mStencilSize = 0; |
michael@0 | 86 | break; |
michael@0 | 87 | case GL_DEPTH_COMPONENT32_OES: |
michael@0 | 88 | mDepthSize = 32; |
michael@0 | 89 | mStencilSize = 0; |
michael@0 | 90 | break; |
michael@0 | 91 | case GL_DEPTH24_STENCIL8_OES: |
michael@0 | 92 | mDepthSize = 24; |
michael@0 | 93 | mStencilSize = 8; |
michael@0 | 94 | break; |
michael@0 | 95 | case GL_DEPTH_COMPONENT24_OES: |
michael@0 | 96 | mDepthSize = 24; |
michael@0 | 97 | mStencilSize = 0; |
michael@0 | 98 | break; |
michael@0 | 99 | case GL_DEPTH_COMPONENT16: |
michael@0 | 100 | mDepthSize = 16; |
michael@0 | 101 | mStencilSize = 0; |
michael@0 | 102 | break; |
michael@0 | 103 | default: |
michael@0 | 104 | UNREACHABLE(); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | mLevel = 0; |
michael@0 | 108 | mMatchNativePixmap = EGL_NONE; |
michael@0 | 109 | mMaxPBufferWidth = texWidth; |
michael@0 | 110 | mMaxPBufferHeight = texHeight; |
michael@0 | 111 | mMaxPBufferPixels = texWidth*texHeight; |
michael@0 | 112 | mMaxSwapInterval = maxInterval; |
michael@0 | 113 | mMinSwapInterval = minInterval; |
michael@0 | 114 | mNativeRenderable = EGL_FALSE; |
michael@0 | 115 | mNativeVisualID = 0; |
michael@0 | 116 | mNativeVisualType = 0; |
michael@0 | 117 | mRenderableType = EGL_OPENGL_ES2_BIT; |
michael@0 | 118 | mSampleBuffers = desc.multiSample ? 1 : 0; |
michael@0 | 119 | mSamples = desc.multiSample; |
michael@0 | 120 | mSurfaceType = EGL_PBUFFER_BIT | EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT; |
michael@0 | 121 | mTransparentType = EGL_NONE; |
michael@0 | 122 | mTransparentRedValue = 0; |
michael@0 | 123 | mTransparentGreenValue = 0; |
michael@0 | 124 | mTransparentBlueValue = 0; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | EGLConfig Config::getHandle() const |
michael@0 | 128 | { |
michael@0 | 129 | return (EGLConfig)(size_t)mConfigID; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | SortConfig::SortConfig(const EGLint *attribList) |
michael@0 | 133 | : mWantRed(false), mWantGreen(false), mWantBlue(false), mWantAlpha(false), mWantLuminance(false) |
michael@0 | 134 | { |
michael@0 | 135 | scanForWantedComponents(attribList); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | void SortConfig::scanForWantedComponents(const EGLint *attribList) |
michael@0 | 139 | { |
michael@0 | 140 | // [EGL] section 3.4.1 page 24 |
michael@0 | 141 | // Sorting rule #3: by larger total number of color bits, not considering |
michael@0 | 142 | // components that are 0 or don't-care. |
michael@0 | 143 | for (const EGLint *attr = attribList; attr[0] != EGL_NONE; attr += 2) |
michael@0 | 144 | { |
michael@0 | 145 | if (attr[1] != 0 && attr[1] != EGL_DONT_CARE) |
michael@0 | 146 | { |
michael@0 | 147 | switch (attr[0]) |
michael@0 | 148 | { |
michael@0 | 149 | case EGL_RED_SIZE: mWantRed = true; break; |
michael@0 | 150 | case EGL_GREEN_SIZE: mWantGreen = true; break; |
michael@0 | 151 | case EGL_BLUE_SIZE: mWantBlue = true; break; |
michael@0 | 152 | case EGL_ALPHA_SIZE: mWantAlpha = true; break; |
michael@0 | 153 | case EGL_LUMINANCE_SIZE: mWantLuminance = true; break; |
michael@0 | 154 | } |
michael@0 | 155 | } |
michael@0 | 156 | } |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | EGLint SortConfig::wantedComponentsSize(const Config &config) const |
michael@0 | 160 | { |
michael@0 | 161 | EGLint total = 0; |
michael@0 | 162 | |
michael@0 | 163 | if (mWantRed) total += config.mRedSize; |
michael@0 | 164 | if (mWantGreen) total += config.mGreenSize; |
michael@0 | 165 | if (mWantBlue) total += config.mBlueSize; |
michael@0 | 166 | if (mWantAlpha) total += config.mAlphaSize; |
michael@0 | 167 | if (mWantLuminance) total += config.mLuminanceSize; |
michael@0 | 168 | |
michael@0 | 169 | return total; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | bool SortConfig::operator()(const Config *x, const Config *y) const |
michael@0 | 173 | { |
michael@0 | 174 | return (*this)(*x, *y); |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | bool SortConfig::operator()(const Config &x, const Config &y) const |
michael@0 | 178 | { |
michael@0 | 179 | #define SORT(attribute) \ |
michael@0 | 180 | if (x.attribute != y.attribute) \ |
michael@0 | 181 | { \ |
michael@0 | 182 | return x.attribute < y.attribute; \ |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | META_ASSERT(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG); |
michael@0 | 186 | SORT(mConfigCaveat); |
michael@0 | 187 | |
michael@0 | 188 | META_ASSERT(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER); |
michael@0 | 189 | SORT(mColorBufferType); |
michael@0 | 190 | |
michael@0 | 191 | // By larger total number of color bits, only considering those that are requested to be > 0. |
michael@0 | 192 | EGLint xComponentsSize = wantedComponentsSize(x); |
michael@0 | 193 | EGLint yComponentsSize = wantedComponentsSize(y); |
michael@0 | 194 | if (xComponentsSize != yComponentsSize) |
michael@0 | 195 | { |
michael@0 | 196 | return xComponentsSize > yComponentsSize; |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | SORT(mBufferSize); |
michael@0 | 200 | SORT(mSampleBuffers); |
michael@0 | 201 | SORT(mSamples); |
michael@0 | 202 | SORT(mDepthSize); |
michael@0 | 203 | SORT(mStencilSize); |
michael@0 | 204 | SORT(mAlphaMaskSize); |
michael@0 | 205 | SORT(mNativeVisualType); |
michael@0 | 206 | SORT(mConfigID); |
michael@0 | 207 | |
michael@0 | 208 | #undef SORT |
michael@0 | 209 | |
michael@0 | 210 | return false; |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | // We'd like to use SortConfig to also eliminate duplicate configs. |
michael@0 | 214 | // This works as long as we never have two configs with different per-RGB-component layouts, |
michael@0 | 215 | // but the same total. |
michael@0 | 216 | // 5551 and 565 are different because R+G+B is different. |
michael@0 | 217 | // 5551 and 555 are different because bufferSize is different. |
michael@0 | 218 | const EGLint ConfigSet::mSortAttribs[] = |
michael@0 | 219 | { |
michael@0 | 220 | EGL_RED_SIZE, 1, |
michael@0 | 221 | EGL_GREEN_SIZE, 1, |
michael@0 | 222 | EGL_BLUE_SIZE, 1, |
michael@0 | 223 | EGL_LUMINANCE_SIZE, 1, |
michael@0 | 224 | // BUT NOT ALPHA |
michael@0 | 225 | EGL_NONE |
michael@0 | 226 | }; |
michael@0 | 227 | |
michael@0 | 228 | ConfigSet::ConfigSet() |
michael@0 | 229 | : mSet(SortConfig(mSortAttribs)) |
michael@0 | 230 | { |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | void ConfigSet::add(rx::ConfigDesc desc, EGLint minSwapInterval, EGLint maxSwapInterval, EGLint texWidth, EGLint texHeight) |
michael@0 | 234 | { |
michael@0 | 235 | Config config(desc, minSwapInterval, maxSwapInterval, texWidth, texHeight); |
michael@0 | 236 | mSet.insert(config); |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | size_t ConfigSet::size() const |
michael@0 | 240 | { |
michael@0 | 241 | return mSet.size(); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | bool ConfigSet::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig) |
michael@0 | 245 | { |
michael@0 | 246 | vector<const Config*> passed; |
michael@0 | 247 | passed.reserve(mSet.size()); |
michael@0 | 248 | |
michael@0 | 249 | for (Iterator config = mSet.begin(); config != mSet.end(); config++) |
michael@0 | 250 | { |
michael@0 | 251 | bool match = true; |
michael@0 | 252 | const EGLint *attribute = attribList; |
michael@0 | 253 | |
michael@0 | 254 | while (attribute[0] != EGL_NONE) |
michael@0 | 255 | { |
michael@0 | 256 | switch (attribute[0]) |
michael@0 | 257 | { |
michael@0 | 258 | case EGL_BUFFER_SIZE: match = config->mBufferSize >= attribute[1]; break; |
michael@0 | 259 | case EGL_ALPHA_SIZE: match = config->mAlphaSize >= attribute[1]; break; |
michael@0 | 260 | case EGL_BLUE_SIZE: match = config->mBlueSize >= attribute[1]; break; |
michael@0 | 261 | case EGL_GREEN_SIZE: match = config->mGreenSize >= attribute[1]; break; |
michael@0 | 262 | case EGL_RED_SIZE: match = config->mRedSize >= attribute[1]; break; |
michael@0 | 263 | case EGL_DEPTH_SIZE: match = config->mDepthSize >= attribute[1]; break; |
michael@0 | 264 | case EGL_STENCIL_SIZE: match = config->mStencilSize >= attribute[1]; break; |
michael@0 | 265 | case EGL_CONFIG_CAVEAT: match = config->mConfigCaveat == (EGLenum) attribute[1]; break; |
michael@0 | 266 | case EGL_CONFIG_ID: match = config->mConfigID == attribute[1]; break; |
michael@0 | 267 | case EGL_LEVEL: match = config->mLevel >= attribute[1]; break; |
michael@0 | 268 | case EGL_NATIVE_RENDERABLE: match = config->mNativeRenderable == (EGLBoolean) attribute[1]; break; |
michael@0 | 269 | case EGL_NATIVE_VISUAL_TYPE: match = config->mNativeVisualType == attribute[1]; break; |
michael@0 | 270 | case EGL_SAMPLES: match = config->mSamples >= attribute[1]; break; |
michael@0 | 271 | case EGL_SAMPLE_BUFFERS: match = config->mSampleBuffers >= attribute[1]; break; |
michael@0 | 272 | case EGL_SURFACE_TYPE: match = (config->mSurfaceType & attribute[1]) == attribute[1]; break; |
michael@0 | 273 | case EGL_TRANSPARENT_TYPE: match = config->mTransparentType == (EGLenum) attribute[1]; break; |
michael@0 | 274 | case EGL_TRANSPARENT_BLUE_VALUE: match = config->mTransparentBlueValue == attribute[1]; break; |
michael@0 | 275 | case EGL_TRANSPARENT_GREEN_VALUE: match = config->mTransparentGreenValue == attribute[1]; break; |
michael@0 | 276 | case EGL_TRANSPARENT_RED_VALUE: match = config->mTransparentRedValue == attribute[1]; break; |
michael@0 | 277 | case EGL_BIND_TO_TEXTURE_RGB: match = config->mBindToTextureRGB == (EGLBoolean) attribute[1]; break; |
michael@0 | 278 | case EGL_BIND_TO_TEXTURE_RGBA: match = config->mBindToTextureRGBA == (EGLBoolean) attribute[1]; break; |
michael@0 | 279 | case EGL_MIN_SWAP_INTERVAL: match = config->mMinSwapInterval == attribute[1]; break; |
michael@0 | 280 | case EGL_MAX_SWAP_INTERVAL: match = config->mMaxSwapInterval == attribute[1]; break; |
michael@0 | 281 | case EGL_LUMINANCE_SIZE: match = config->mLuminanceSize >= attribute[1]; break; |
michael@0 | 282 | case EGL_ALPHA_MASK_SIZE: match = config->mAlphaMaskSize >= attribute[1]; break; |
michael@0 | 283 | case EGL_COLOR_BUFFER_TYPE: match = config->mColorBufferType == (EGLenum) attribute[1]; break; |
michael@0 | 284 | case EGL_RENDERABLE_TYPE: match = (config->mRenderableType & attribute[1]) == attribute[1]; break; |
michael@0 | 285 | case EGL_MATCH_NATIVE_PIXMAP: match = false; UNIMPLEMENTED(); break; |
michael@0 | 286 | case EGL_CONFORMANT: match = (config->mConformant & attribute[1]) == attribute[1]; break; |
michael@0 | 287 | case EGL_MAX_PBUFFER_WIDTH: match = config->mMaxPBufferWidth >= attribute[1]; break; |
michael@0 | 288 | case EGL_MAX_PBUFFER_HEIGHT: match = config->mMaxPBufferHeight >= attribute[1]; break; |
michael@0 | 289 | case EGL_MAX_PBUFFER_PIXELS: match = config->mMaxPBufferPixels >= attribute[1]; break; |
michael@0 | 290 | default: |
michael@0 | 291 | return false; |
michael@0 | 292 | } |
michael@0 | 293 | |
michael@0 | 294 | if (!match) |
michael@0 | 295 | { |
michael@0 | 296 | break; |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | attribute += 2; |
michael@0 | 300 | } |
michael@0 | 301 | |
michael@0 | 302 | if (match) |
michael@0 | 303 | { |
michael@0 | 304 | passed.push_back(&*config); |
michael@0 | 305 | } |
michael@0 | 306 | } |
michael@0 | 307 | |
michael@0 | 308 | if (configs) |
michael@0 | 309 | { |
michael@0 | 310 | sort(passed.begin(), passed.end(), SortConfig(attribList)); |
michael@0 | 311 | |
michael@0 | 312 | EGLint index; |
michael@0 | 313 | for (index = 0; index < configSize && index < static_cast<EGLint>(passed.size()); index++) |
michael@0 | 314 | { |
michael@0 | 315 | configs[index] = passed[index]->getHandle(); |
michael@0 | 316 | } |
michael@0 | 317 | |
michael@0 | 318 | *numConfig = index; |
michael@0 | 319 | } |
michael@0 | 320 | else |
michael@0 | 321 | { |
michael@0 | 322 | *numConfig = passed.size(); |
michael@0 | 323 | } |
michael@0 | 324 | |
michael@0 | 325 | return true; |
michael@0 | 326 | } |
michael@0 | 327 | |
michael@0 | 328 | const egl::Config *ConfigSet::get(EGLConfig configHandle) |
michael@0 | 329 | { |
michael@0 | 330 | for (Iterator config = mSet.begin(); config != mSet.end(); config++) |
michael@0 | 331 | { |
michael@0 | 332 | if (config->getHandle() == configHandle) |
michael@0 | 333 | { |
michael@0 | 334 | return &(*config); |
michael@0 | 335 | } |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | return NULL; |
michael@0 | 339 | } |
michael@0 | 340 | } |