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) 2012 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 | // VertexDeclarationCache.cpp: Implements a helper class to construct and cache vertex declarations. |
michael@0 | 9 | |
michael@0 | 10 | #include "libGLESv2/ProgramBinary.h" |
michael@0 | 11 | #include "libGLESv2/Context.h" |
michael@0 | 12 | #include "libGLESv2/renderer/VertexBuffer9.h" |
michael@0 | 13 | #include "libGLESv2/renderer/VertexDeclarationCache.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace rx |
michael@0 | 16 | { |
michael@0 | 17 | |
michael@0 | 18 | VertexDeclarationCache::VertexDeclarationCache() : mMaxLru(0) |
michael@0 | 19 | { |
michael@0 | 20 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
michael@0 | 21 | { |
michael@0 | 22 | mVertexDeclCache[i].vertexDeclaration = NULL; |
michael@0 | 23 | mVertexDeclCache[i].lruCount = 0; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
michael@0 | 27 | { |
michael@0 | 28 | mAppliedVBs[i].serial = 0; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | mLastSetVDecl = NULL; |
michael@0 | 32 | mInstancingEnabled = true; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | VertexDeclarationCache::~VertexDeclarationCache() |
michael@0 | 36 | { |
michael@0 | 37 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
michael@0 | 38 | { |
michael@0 | 39 | if (mVertexDeclCache[i].vertexDeclaration) |
michael@0 | 40 | { |
michael@0 | 41 | mVertexDeclCache[i].vertexDeclaration->Release(); |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], gl::ProgramBinary *programBinary, GLsizei instances, GLsizei *repeatDraw) |
michael@0 | 47 | { |
michael@0 | 48 | *repeatDraw = 1; |
michael@0 | 49 | |
michael@0 | 50 | int indexedAttribute = gl::MAX_VERTEX_ATTRIBS; |
michael@0 | 51 | int instancedAttribute = gl::MAX_VERTEX_ATTRIBS; |
michael@0 | 52 | |
michael@0 | 53 | if (instances > 0) |
michael@0 | 54 | { |
michael@0 | 55 | // Find an indexed attribute to be mapped to D3D stream 0 |
michael@0 | 56 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
michael@0 | 57 | { |
michael@0 | 58 | if (attributes[i].active) |
michael@0 | 59 | { |
michael@0 | 60 | if (indexedAttribute == gl::MAX_VERTEX_ATTRIBS && attributes[i].divisor == 0) |
michael@0 | 61 | { |
michael@0 | 62 | indexedAttribute = i; |
michael@0 | 63 | } |
michael@0 | 64 | else if (instancedAttribute == gl::MAX_VERTEX_ATTRIBS && attributes[i].divisor != 0) |
michael@0 | 65 | { |
michael@0 | 66 | instancedAttribute = i; |
michael@0 | 67 | } |
michael@0 | 68 | if (indexedAttribute != gl::MAX_VERTEX_ATTRIBS && instancedAttribute != gl::MAX_VERTEX_ATTRIBS) |
michael@0 | 69 | break; // Found both an indexed and instanced attribute |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | if (indexedAttribute == gl::MAX_VERTEX_ATTRIBS) |
michael@0 | 74 | { |
michael@0 | 75 | return GL_INVALID_OPERATION; |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | D3DVERTEXELEMENT9 elements[gl::MAX_VERTEX_ATTRIBS + 1]; |
michael@0 | 80 | D3DVERTEXELEMENT9 *element = &elements[0]; |
michael@0 | 81 | |
michael@0 | 82 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
michael@0 | 83 | { |
michael@0 | 84 | if (attributes[i].active) |
michael@0 | 85 | { |
michael@0 | 86 | // Directly binding the storage buffer is not supported for d3d9 |
michael@0 | 87 | ASSERT(attributes[i].storage == NULL); |
michael@0 | 88 | |
michael@0 | 89 | int stream = i; |
michael@0 | 90 | |
michael@0 | 91 | if (instances > 0) |
michael@0 | 92 | { |
michael@0 | 93 | // Due to a bug on ATI cards we can't enable instancing when none of the attributes are instanced. |
michael@0 | 94 | if (instancedAttribute == gl::MAX_VERTEX_ATTRIBS) |
michael@0 | 95 | { |
michael@0 | 96 | *repeatDraw = instances; |
michael@0 | 97 | } |
michael@0 | 98 | else |
michael@0 | 99 | { |
michael@0 | 100 | if (i == indexedAttribute) |
michael@0 | 101 | { |
michael@0 | 102 | stream = 0; |
michael@0 | 103 | } |
michael@0 | 104 | else if (i == 0) |
michael@0 | 105 | { |
michael@0 | 106 | stream = indexedAttribute; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | UINT frequency = 1; |
michael@0 | 110 | |
michael@0 | 111 | if (attributes[i].divisor == 0) |
michael@0 | 112 | { |
michael@0 | 113 | frequency = D3DSTREAMSOURCE_INDEXEDDATA | instances; |
michael@0 | 114 | } |
michael@0 | 115 | else |
michael@0 | 116 | { |
michael@0 | 117 | frequency = D3DSTREAMSOURCE_INSTANCEDATA | attributes[i].divisor; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | device->SetStreamSourceFreq(stream, frequency); |
michael@0 | 121 | mInstancingEnabled = true; |
michael@0 | 122 | } |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | VertexBuffer9 *vertexBuffer = VertexBuffer9::makeVertexBuffer9(attributes[i].vertexBuffer); |
michael@0 | 126 | |
michael@0 | 127 | if (mAppliedVBs[stream].serial != attributes[i].serial || |
michael@0 | 128 | mAppliedVBs[stream].stride != attributes[i].stride || |
michael@0 | 129 | mAppliedVBs[stream].offset != attributes[i].offset) |
michael@0 | 130 | { |
michael@0 | 131 | device->SetStreamSource(stream, vertexBuffer->getBuffer(), attributes[i].offset, attributes[i].stride); |
michael@0 | 132 | mAppliedVBs[stream].serial = attributes[i].serial; |
michael@0 | 133 | mAppliedVBs[stream].stride = attributes[i].stride; |
michael@0 | 134 | mAppliedVBs[stream].offset = attributes[i].offset; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | element->Stream = stream; |
michael@0 | 138 | element->Offset = 0; |
michael@0 | 139 | element->Type = attributes[i].attribute->mArrayEnabled ? vertexBuffer->getDeclType(*attributes[i].attribute) : D3DDECLTYPE_FLOAT4; |
michael@0 | 140 | element->Method = D3DDECLMETHOD_DEFAULT; |
michael@0 | 141 | element->Usage = D3DDECLUSAGE_TEXCOORD; |
michael@0 | 142 | element->UsageIndex = programBinary->getSemanticIndex(i); |
michael@0 | 143 | element++; |
michael@0 | 144 | } |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | if (instances == 0 || instancedAttribute == gl::MAX_VERTEX_ATTRIBS) |
michael@0 | 148 | { |
michael@0 | 149 | if (mInstancingEnabled) |
michael@0 | 150 | { |
michael@0 | 151 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
michael@0 | 152 | { |
michael@0 | 153 | device->SetStreamSourceFreq(i, 1); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | mInstancingEnabled = false; |
michael@0 | 157 | } |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | static const D3DVERTEXELEMENT9 end = D3DDECL_END(); |
michael@0 | 161 | *(element++) = end; |
michael@0 | 162 | |
michael@0 | 163 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
michael@0 | 164 | { |
michael@0 | 165 | VertexDeclCacheEntry *entry = &mVertexDeclCache[i]; |
michael@0 | 166 | if (memcmp(entry->cachedElements, elements, (element - elements) * sizeof(D3DVERTEXELEMENT9)) == 0 && entry->vertexDeclaration) |
michael@0 | 167 | { |
michael@0 | 168 | entry->lruCount = ++mMaxLru; |
michael@0 | 169 | if(entry->vertexDeclaration != mLastSetVDecl) |
michael@0 | 170 | { |
michael@0 | 171 | device->SetVertexDeclaration(entry->vertexDeclaration); |
michael@0 | 172 | mLastSetVDecl = entry->vertexDeclaration; |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | return GL_NO_ERROR; |
michael@0 | 176 | } |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | VertexDeclCacheEntry *lastCache = mVertexDeclCache; |
michael@0 | 180 | |
michael@0 | 181 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
michael@0 | 182 | { |
michael@0 | 183 | if (mVertexDeclCache[i].lruCount < lastCache->lruCount) |
michael@0 | 184 | { |
michael@0 | 185 | lastCache = &mVertexDeclCache[i]; |
michael@0 | 186 | } |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | if (lastCache->vertexDeclaration != NULL) |
michael@0 | 190 | { |
michael@0 | 191 | lastCache->vertexDeclaration->Release(); |
michael@0 | 192 | lastCache->vertexDeclaration = NULL; |
michael@0 | 193 | // mLastSetVDecl is set to the replacement, so we don't have to worry |
michael@0 | 194 | // about it. |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | memcpy(lastCache->cachedElements, elements, (element - elements) * sizeof(D3DVERTEXELEMENT9)); |
michael@0 | 198 | device->CreateVertexDeclaration(elements, &lastCache->vertexDeclaration); |
michael@0 | 199 | device->SetVertexDeclaration(lastCache->vertexDeclaration); |
michael@0 | 200 | mLastSetVDecl = lastCache->vertexDeclaration; |
michael@0 | 201 | lastCache->lruCount = ++mMaxLru; |
michael@0 | 202 | |
michael@0 | 203 | return GL_NO_ERROR; |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | void VertexDeclarationCache::markStateDirty() |
michael@0 | 207 | { |
michael@0 | 208 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
michael@0 | 209 | { |
michael@0 | 210 | mAppliedVBs[i].serial = 0; |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | mLastSetVDecl = NULL; |
michael@0 | 214 | mInstancingEnabled = true; // Forces it to be disabled when not used |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | } |