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) 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 | // ShaderCache: Defines rx::ShaderCache, a cache of Direct3D shader objects |
michael@0 | 8 | // keyed by their byte code. |
michael@0 | 9 | |
michael@0 | 10 | #ifndef LIBGLESV2_RENDERER_SHADER_CACHE_H_ |
michael@0 | 11 | #define LIBGLESV2_RENDERER_SHADER_CACHE_H_ |
michael@0 | 12 | |
michael@0 | 13 | #include "common/debug.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace rx |
michael@0 | 16 | { |
michael@0 | 17 | template <typename ShaderObject> |
michael@0 | 18 | class ShaderCache |
michael@0 | 19 | { |
michael@0 | 20 | public: |
michael@0 | 21 | ShaderCache() : mDevice(NULL) |
michael@0 | 22 | { |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | ~ShaderCache() |
michael@0 | 26 | { |
michael@0 | 27 | // Call clear while the device is still valid. |
michael@0 | 28 | ASSERT(mMap.empty()); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | void initialize(IDirect3DDevice9* device) |
michael@0 | 32 | { |
michael@0 | 33 | mDevice = device; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | ShaderObject *create(const DWORD *function, size_t length) |
michael@0 | 37 | { |
michael@0 | 38 | std::string key(reinterpret_cast<const char*>(function), length); |
michael@0 | 39 | typename Map::iterator it = mMap.find(key); |
michael@0 | 40 | if (it != mMap.end()) |
michael@0 | 41 | { |
michael@0 | 42 | it->second->AddRef(); |
michael@0 | 43 | return it->second; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | ShaderObject *shader; |
michael@0 | 47 | HRESULT result = createShader(function, &shader); |
michael@0 | 48 | if (FAILED(result)) |
michael@0 | 49 | { |
michael@0 | 50 | return NULL; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | // Random eviction policy. |
michael@0 | 54 | if (mMap.size() >= kMaxMapSize) |
michael@0 | 55 | { |
michael@0 | 56 | mMap.begin()->second->Release(); |
michael@0 | 57 | mMap.erase(mMap.begin()); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | shader->AddRef(); |
michael@0 | 61 | mMap[key] = shader; |
michael@0 | 62 | |
michael@0 | 63 | return shader; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | void clear() |
michael@0 | 67 | { |
michael@0 | 68 | for (typename Map::iterator it = mMap.begin(); it != mMap.end(); ++it) |
michael@0 | 69 | { |
michael@0 | 70 | it->second->Release(); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | mMap.clear(); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | private: |
michael@0 | 77 | DISALLOW_COPY_AND_ASSIGN(ShaderCache); |
michael@0 | 78 | |
michael@0 | 79 | const static size_t kMaxMapSize = 100; |
michael@0 | 80 | |
michael@0 | 81 | HRESULT createShader(const DWORD *function, IDirect3DVertexShader9 **shader) |
michael@0 | 82 | { |
michael@0 | 83 | return mDevice->CreateVertexShader(function, shader); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | HRESULT createShader(const DWORD *function, IDirect3DPixelShader9 **shader) |
michael@0 | 87 | { |
michael@0 | 88 | return mDevice->CreatePixelShader(function, shader); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | #ifndef HASH_MAP |
michael@0 | 92 | # ifdef _MSC_VER |
michael@0 | 93 | # define HASH_MAP stdext::hash_map |
michael@0 | 94 | # else |
michael@0 | 95 | # define HASH_MAP std::unordered_map |
michael@0 | 96 | # endif |
michael@0 | 97 | #endif |
michael@0 | 98 | |
michael@0 | 99 | typedef HASH_MAP<std::string, ShaderObject*> Map; |
michael@0 | 100 | Map mMap; |
michael@0 | 101 | |
michael@0 | 102 | IDirect3DDevice9 *mDevice; |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | typedef ShaderCache<IDirect3DVertexShader9> VertexShaderCache; |
michael@0 | 106 | typedef ShaderCache<IDirect3DPixelShader9> PixelShaderCache; |
michael@0 | 107 | |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | #endif // LIBGLESV2_RENDERER_SHADER_CACHE_H_ |