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 | #include "precompiled.h" |
michael@0 | 2 | // |
michael@0 | 3 | // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
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 | // ResourceManager.cpp: Implements the gl::ResourceManager class, which tracks and |
michael@0 | 9 | // retrieves objects which may be shared by multiple Contexts. |
michael@0 | 10 | |
michael@0 | 11 | #include "libGLESv2/ResourceManager.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "libGLESv2/Buffer.h" |
michael@0 | 14 | #include "libGLESv2/Program.h" |
michael@0 | 15 | #include "libGLESv2/Renderbuffer.h" |
michael@0 | 16 | #include "libGLESv2/Shader.h" |
michael@0 | 17 | #include "libGLESv2/Texture.h" |
michael@0 | 18 | |
michael@0 | 19 | namespace gl |
michael@0 | 20 | { |
michael@0 | 21 | ResourceManager::ResourceManager(rx::Renderer *renderer) |
michael@0 | 22 | { |
michael@0 | 23 | mRefCount = 1; |
michael@0 | 24 | mRenderer = renderer; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | ResourceManager::~ResourceManager() |
michael@0 | 28 | { |
michael@0 | 29 | while (!mBufferMap.empty()) |
michael@0 | 30 | { |
michael@0 | 31 | deleteBuffer(mBufferMap.begin()->first); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | while (!mProgramMap.empty()) |
michael@0 | 35 | { |
michael@0 | 36 | deleteProgram(mProgramMap.begin()->first); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | while (!mShaderMap.empty()) |
michael@0 | 40 | { |
michael@0 | 41 | deleteShader(mShaderMap.begin()->first); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | while (!mRenderbufferMap.empty()) |
michael@0 | 45 | { |
michael@0 | 46 | deleteRenderbuffer(mRenderbufferMap.begin()->first); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | while (!mTextureMap.empty()) |
michael@0 | 50 | { |
michael@0 | 51 | deleteTexture(mTextureMap.begin()->first); |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void ResourceManager::addRef() |
michael@0 | 56 | { |
michael@0 | 57 | mRefCount++; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | void ResourceManager::release() |
michael@0 | 61 | { |
michael@0 | 62 | if (--mRefCount == 0) |
michael@0 | 63 | { |
michael@0 | 64 | delete this; |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | // Returns an unused buffer name |
michael@0 | 69 | GLuint ResourceManager::createBuffer() |
michael@0 | 70 | { |
michael@0 | 71 | GLuint handle = mBufferHandleAllocator.allocate(); |
michael@0 | 72 | |
michael@0 | 73 | mBufferMap[handle] = NULL; |
michael@0 | 74 | |
michael@0 | 75 | return handle; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | // Returns an unused shader/program name |
michael@0 | 79 | GLuint ResourceManager::createShader(GLenum type) |
michael@0 | 80 | { |
michael@0 | 81 | GLuint handle = mProgramShaderHandleAllocator.allocate(); |
michael@0 | 82 | |
michael@0 | 83 | if (type == GL_VERTEX_SHADER) |
michael@0 | 84 | { |
michael@0 | 85 | mShaderMap[handle] = new VertexShader(this, mRenderer, handle); |
michael@0 | 86 | } |
michael@0 | 87 | else if (type == GL_FRAGMENT_SHADER) |
michael@0 | 88 | { |
michael@0 | 89 | mShaderMap[handle] = new FragmentShader(this, mRenderer, handle); |
michael@0 | 90 | } |
michael@0 | 91 | else UNREACHABLE(); |
michael@0 | 92 | |
michael@0 | 93 | return handle; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | // Returns an unused program/shader name |
michael@0 | 97 | GLuint ResourceManager::createProgram() |
michael@0 | 98 | { |
michael@0 | 99 | GLuint handle = mProgramShaderHandleAllocator.allocate(); |
michael@0 | 100 | |
michael@0 | 101 | mProgramMap[handle] = new Program(mRenderer, this, handle); |
michael@0 | 102 | |
michael@0 | 103 | return handle; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | // Returns an unused texture name |
michael@0 | 107 | GLuint ResourceManager::createTexture() |
michael@0 | 108 | { |
michael@0 | 109 | GLuint handle = mTextureHandleAllocator.allocate(); |
michael@0 | 110 | |
michael@0 | 111 | mTextureMap[handle] = NULL; |
michael@0 | 112 | |
michael@0 | 113 | return handle; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | // Returns an unused renderbuffer name |
michael@0 | 117 | GLuint ResourceManager::createRenderbuffer() |
michael@0 | 118 | { |
michael@0 | 119 | GLuint handle = mRenderbufferHandleAllocator.allocate(); |
michael@0 | 120 | |
michael@0 | 121 | mRenderbufferMap[handle] = NULL; |
michael@0 | 122 | |
michael@0 | 123 | return handle; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | void ResourceManager::deleteBuffer(GLuint buffer) |
michael@0 | 127 | { |
michael@0 | 128 | BufferMap::iterator bufferObject = mBufferMap.find(buffer); |
michael@0 | 129 | |
michael@0 | 130 | if (bufferObject != mBufferMap.end()) |
michael@0 | 131 | { |
michael@0 | 132 | mBufferHandleAllocator.release(bufferObject->first); |
michael@0 | 133 | if (bufferObject->second) bufferObject->second->release(); |
michael@0 | 134 | mBufferMap.erase(bufferObject); |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | void ResourceManager::deleteShader(GLuint shader) |
michael@0 | 139 | { |
michael@0 | 140 | ShaderMap::iterator shaderObject = mShaderMap.find(shader); |
michael@0 | 141 | |
michael@0 | 142 | if (shaderObject != mShaderMap.end()) |
michael@0 | 143 | { |
michael@0 | 144 | if (shaderObject->second->getRefCount() == 0) |
michael@0 | 145 | { |
michael@0 | 146 | mProgramShaderHandleAllocator.release(shaderObject->first); |
michael@0 | 147 | delete shaderObject->second; |
michael@0 | 148 | mShaderMap.erase(shaderObject); |
michael@0 | 149 | } |
michael@0 | 150 | else |
michael@0 | 151 | { |
michael@0 | 152 | shaderObject->second->flagForDeletion(); |
michael@0 | 153 | } |
michael@0 | 154 | } |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | void ResourceManager::deleteProgram(GLuint program) |
michael@0 | 158 | { |
michael@0 | 159 | ProgramMap::iterator programObject = mProgramMap.find(program); |
michael@0 | 160 | |
michael@0 | 161 | if (programObject != mProgramMap.end()) |
michael@0 | 162 | { |
michael@0 | 163 | if (programObject->second->getRefCount() == 0) |
michael@0 | 164 | { |
michael@0 | 165 | mProgramShaderHandleAllocator.release(programObject->first); |
michael@0 | 166 | delete programObject->second; |
michael@0 | 167 | mProgramMap.erase(programObject); |
michael@0 | 168 | } |
michael@0 | 169 | else |
michael@0 | 170 | { |
michael@0 | 171 | programObject->second->flagForDeletion(); |
michael@0 | 172 | } |
michael@0 | 173 | } |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | void ResourceManager::deleteTexture(GLuint texture) |
michael@0 | 177 | { |
michael@0 | 178 | TextureMap::iterator textureObject = mTextureMap.find(texture); |
michael@0 | 179 | |
michael@0 | 180 | if (textureObject != mTextureMap.end()) |
michael@0 | 181 | { |
michael@0 | 182 | mTextureHandleAllocator.release(textureObject->first); |
michael@0 | 183 | if (textureObject->second) textureObject->second->release(); |
michael@0 | 184 | mTextureMap.erase(textureObject); |
michael@0 | 185 | } |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | void ResourceManager::deleteRenderbuffer(GLuint renderbuffer) |
michael@0 | 189 | { |
michael@0 | 190 | RenderbufferMap::iterator renderbufferObject = mRenderbufferMap.find(renderbuffer); |
michael@0 | 191 | |
michael@0 | 192 | if (renderbufferObject != mRenderbufferMap.end()) |
michael@0 | 193 | { |
michael@0 | 194 | mRenderbufferHandleAllocator.release(renderbufferObject->first); |
michael@0 | 195 | if (renderbufferObject->second) renderbufferObject->second->release(); |
michael@0 | 196 | mRenderbufferMap.erase(renderbufferObject); |
michael@0 | 197 | } |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | Buffer *ResourceManager::getBuffer(unsigned int handle) |
michael@0 | 201 | { |
michael@0 | 202 | BufferMap::iterator buffer = mBufferMap.find(handle); |
michael@0 | 203 | |
michael@0 | 204 | if (buffer == mBufferMap.end()) |
michael@0 | 205 | { |
michael@0 | 206 | return NULL; |
michael@0 | 207 | } |
michael@0 | 208 | else |
michael@0 | 209 | { |
michael@0 | 210 | return buffer->second; |
michael@0 | 211 | } |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | Shader *ResourceManager::getShader(unsigned int handle) |
michael@0 | 215 | { |
michael@0 | 216 | ShaderMap::iterator shader = mShaderMap.find(handle); |
michael@0 | 217 | |
michael@0 | 218 | if (shader == mShaderMap.end()) |
michael@0 | 219 | { |
michael@0 | 220 | return NULL; |
michael@0 | 221 | } |
michael@0 | 222 | else |
michael@0 | 223 | { |
michael@0 | 224 | return shader->second; |
michael@0 | 225 | } |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | Texture *ResourceManager::getTexture(unsigned int handle) |
michael@0 | 229 | { |
michael@0 | 230 | if (handle == 0) return NULL; |
michael@0 | 231 | |
michael@0 | 232 | TextureMap::iterator texture = mTextureMap.find(handle); |
michael@0 | 233 | |
michael@0 | 234 | if (texture == mTextureMap.end()) |
michael@0 | 235 | { |
michael@0 | 236 | return NULL; |
michael@0 | 237 | } |
michael@0 | 238 | else |
michael@0 | 239 | { |
michael@0 | 240 | return texture->second; |
michael@0 | 241 | } |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | Program *ResourceManager::getProgram(unsigned int handle) |
michael@0 | 245 | { |
michael@0 | 246 | ProgramMap::iterator program = mProgramMap.find(handle); |
michael@0 | 247 | |
michael@0 | 248 | if (program == mProgramMap.end()) |
michael@0 | 249 | { |
michael@0 | 250 | return NULL; |
michael@0 | 251 | } |
michael@0 | 252 | else |
michael@0 | 253 | { |
michael@0 | 254 | return program->second; |
michael@0 | 255 | } |
michael@0 | 256 | } |
michael@0 | 257 | |
michael@0 | 258 | Renderbuffer *ResourceManager::getRenderbuffer(unsigned int handle) |
michael@0 | 259 | { |
michael@0 | 260 | RenderbufferMap::iterator renderbuffer = mRenderbufferMap.find(handle); |
michael@0 | 261 | |
michael@0 | 262 | if (renderbuffer == mRenderbufferMap.end()) |
michael@0 | 263 | { |
michael@0 | 264 | return NULL; |
michael@0 | 265 | } |
michael@0 | 266 | else |
michael@0 | 267 | { |
michael@0 | 268 | return renderbuffer->second; |
michael@0 | 269 | } |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | void ResourceManager::setRenderbuffer(GLuint handle, Renderbuffer *buffer) |
michael@0 | 273 | { |
michael@0 | 274 | mRenderbufferMap[handle] = buffer; |
michael@0 | 275 | } |
michael@0 | 276 | |
michael@0 | 277 | void ResourceManager::checkBufferAllocation(unsigned int buffer) |
michael@0 | 278 | { |
michael@0 | 279 | if (buffer != 0 && !getBuffer(buffer)) |
michael@0 | 280 | { |
michael@0 | 281 | Buffer *bufferObject = new Buffer(mRenderer, buffer); |
michael@0 | 282 | mBufferMap[buffer] = bufferObject; |
michael@0 | 283 | bufferObject->addRef(); |
michael@0 | 284 | } |
michael@0 | 285 | } |
michael@0 | 286 | |
michael@0 | 287 | void ResourceManager::checkTextureAllocation(GLuint texture, TextureType type) |
michael@0 | 288 | { |
michael@0 | 289 | if (!getTexture(texture) && texture != 0) |
michael@0 | 290 | { |
michael@0 | 291 | Texture *textureObject; |
michael@0 | 292 | |
michael@0 | 293 | if (type == TEXTURE_2D) |
michael@0 | 294 | { |
michael@0 | 295 | textureObject = new Texture2D(mRenderer, texture); |
michael@0 | 296 | } |
michael@0 | 297 | else if (type == TEXTURE_CUBE) |
michael@0 | 298 | { |
michael@0 | 299 | textureObject = new TextureCubeMap(mRenderer, texture); |
michael@0 | 300 | } |
michael@0 | 301 | else |
michael@0 | 302 | { |
michael@0 | 303 | UNREACHABLE(); |
michael@0 | 304 | return; |
michael@0 | 305 | } |
michael@0 | 306 | |
michael@0 | 307 | mTextureMap[texture] = textureObject; |
michael@0 | 308 | textureObject->addRef(); |
michael@0 | 309 | } |
michael@0 | 310 | } |
michael@0 | 311 | |
michael@0 | 312 | void ResourceManager::checkRenderbufferAllocation(GLuint renderbuffer) |
michael@0 | 313 | { |
michael@0 | 314 | if (renderbuffer != 0 && !getRenderbuffer(renderbuffer)) |
michael@0 | 315 | { |
michael@0 | 316 | Renderbuffer *renderbufferObject = new Renderbuffer(mRenderer, renderbuffer, new Colorbuffer(mRenderer, 0, 0, GL_RGBA4, 0)); |
michael@0 | 317 | mRenderbufferMap[renderbuffer] = renderbufferObject; |
michael@0 | 318 | renderbufferObject->addRef(); |
michael@0 | 319 | } |
michael@0 | 320 | } |
michael@0 | 321 | |
michael@0 | 322 | } |