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 | // RenderTarget11.cpp: Implements a DX11-specific wrapper for ID3D11View pointers |
michael@0 | 9 | // retained by Renderbuffers. |
michael@0 | 10 | |
michael@0 | 11 | #include "libGLESv2/renderer/RenderTarget11.h" |
michael@0 | 12 | #include "libGLESv2/renderer/Renderer11.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "libGLESv2/renderer/renderer11_utils.h" |
michael@0 | 15 | #include "libGLESv2/main.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace rx |
michael@0 | 18 | { |
michael@0 | 19 | |
michael@0 | 20 | static unsigned int getRTVSubresourceIndex(ID3D11Texture2D *texture, ID3D11RenderTargetView *view) |
michael@0 | 21 | { |
michael@0 | 22 | D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; |
michael@0 | 23 | view->GetDesc(&rtvDesc); |
michael@0 | 24 | |
michael@0 | 25 | D3D11_TEXTURE2D_DESC texDesc; |
michael@0 | 26 | texture->GetDesc(&texDesc); |
michael@0 | 27 | |
michael@0 | 28 | unsigned int mipSlice = 0; |
michael@0 | 29 | unsigned int arraySlice = 0; |
michael@0 | 30 | unsigned int mipLevels = texDesc.MipLevels; |
michael@0 | 31 | |
michael@0 | 32 | switch (rtvDesc.ViewDimension) |
michael@0 | 33 | { |
michael@0 | 34 | case D3D11_RTV_DIMENSION_TEXTURE1D: |
michael@0 | 35 | mipSlice = rtvDesc.Texture1D.MipSlice; |
michael@0 | 36 | arraySlice = 0; |
michael@0 | 37 | break; |
michael@0 | 38 | |
michael@0 | 39 | case D3D11_RTV_DIMENSION_TEXTURE1DARRAY: |
michael@0 | 40 | mipSlice = rtvDesc.Texture1DArray.MipSlice; |
michael@0 | 41 | arraySlice = rtvDesc.Texture1DArray.FirstArraySlice; |
michael@0 | 42 | break; |
michael@0 | 43 | |
michael@0 | 44 | case D3D11_RTV_DIMENSION_TEXTURE2D: |
michael@0 | 45 | mipSlice = rtvDesc.Texture2D.MipSlice; |
michael@0 | 46 | arraySlice = 0; |
michael@0 | 47 | break; |
michael@0 | 48 | |
michael@0 | 49 | case D3D11_RTV_DIMENSION_TEXTURE2DARRAY: |
michael@0 | 50 | mipSlice = rtvDesc.Texture2DArray.MipSlice; |
michael@0 | 51 | arraySlice = rtvDesc.Texture2DArray.FirstArraySlice; |
michael@0 | 52 | break; |
michael@0 | 53 | |
michael@0 | 54 | case D3D11_RTV_DIMENSION_TEXTURE2DMS: |
michael@0 | 55 | mipSlice = 0; |
michael@0 | 56 | arraySlice = 0; |
michael@0 | 57 | break; |
michael@0 | 58 | |
michael@0 | 59 | case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY: |
michael@0 | 60 | mipSlice = 0; |
michael@0 | 61 | arraySlice = rtvDesc.Texture2DMSArray.FirstArraySlice; |
michael@0 | 62 | break; |
michael@0 | 63 | |
michael@0 | 64 | case D3D11_RTV_DIMENSION_TEXTURE3D: |
michael@0 | 65 | mipSlice = rtvDesc.Texture3D.MipSlice; |
michael@0 | 66 | arraySlice = 0; |
michael@0 | 67 | break; |
michael@0 | 68 | |
michael@0 | 69 | case D3D11_RTV_DIMENSION_UNKNOWN: |
michael@0 | 70 | case D3D11_RTV_DIMENSION_BUFFER: |
michael@0 | 71 | UNIMPLEMENTED(); |
michael@0 | 72 | break; |
michael@0 | 73 | |
michael@0 | 74 | default: |
michael@0 | 75 | UNREACHABLE(); |
michael@0 | 76 | break; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | return D3D11CalcSubresource(mipSlice, arraySlice, mipLevels); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | static unsigned int getDSVSubresourceIndex(ID3D11Texture2D *texture, ID3D11DepthStencilView *view) |
michael@0 | 83 | { |
michael@0 | 84 | D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; |
michael@0 | 85 | view->GetDesc(&dsvDesc); |
michael@0 | 86 | |
michael@0 | 87 | D3D11_TEXTURE2D_DESC texDesc; |
michael@0 | 88 | texture->GetDesc(&texDesc); |
michael@0 | 89 | |
michael@0 | 90 | unsigned int mipSlice = 0; |
michael@0 | 91 | unsigned int arraySlice = 0; |
michael@0 | 92 | unsigned int mipLevels = texDesc.MipLevels; |
michael@0 | 93 | |
michael@0 | 94 | switch (dsvDesc.ViewDimension) |
michael@0 | 95 | { |
michael@0 | 96 | case D3D11_DSV_DIMENSION_TEXTURE1D: |
michael@0 | 97 | mipSlice = dsvDesc.Texture1D.MipSlice; |
michael@0 | 98 | arraySlice = 0; |
michael@0 | 99 | break; |
michael@0 | 100 | |
michael@0 | 101 | case D3D11_DSV_DIMENSION_TEXTURE1DARRAY: |
michael@0 | 102 | mipSlice = dsvDesc.Texture1DArray.MipSlice; |
michael@0 | 103 | arraySlice = dsvDesc.Texture1DArray.FirstArraySlice; |
michael@0 | 104 | break; |
michael@0 | 105 | |
michael@0 | 106 | case D3D11_DSV_DIMENSION_TEXTURE2D: |
michael@0 | 107 | mipSlice = dsvDesc.Texture2D.MipSlice; |
michael@0 | 108 | arraySlice = 0; |
michael@0 | 109 | break; |
michael@0 | 110 | |
michael@0 | 111 | case D3D11_DSV_DIMENSION_TEXTURE2DARRAY: |
michael@0 | 112 | mipSlice = dsvDesc.Texture2DArray.MipSlice; |
michael@0 | 113 | arraySlice = dsvDesc.Texture2DArray.FirstArraySlice; |
michael@0 | 114 | break; |
michael@0 | 115 | |
michael@0 | 116 | case D3D11_DSV_DIMENSION_TEXTURE2DMS: |
michael@0 | 117 | mipSlice = 0; |
michael@0 | 118 | arraySlice = 0; |
michael@0 | 119 | break; |
michael@0 | 120 | |
michael@0 | 121 | case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY: |
michael@0 | 122 | mipSlice = 0; |
michael@0 | 123 | arraySlice = dsvDesc.Texture2DMSArray.FirstArraySlice; |
michael@0 | 124 | break; |
michael@0 | 125 | |
michael@0 | 126 | case D3D11_RTV_DIMENSION_UNKNOWN: |
michael@0 | 127 | UNIMPLEMENTED(); |
michael@0 | 128 | break; |
michael@0 | 129 | |
michael@0 | 130 | default: |
michael@0 | 131 | UNREACHABLE(); |
michael@0 | 132 | break; |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | return D3D11CalcSubresource(mipSlice, arraySlice, mipLevels); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | RenderTarget11::RenderTarget11(Renderer *renderer, ID3D11RenderTargetView *rtv, ID3D11Texture2D *tex, ID3D11ShaderResourceView *srv, GLsizei width, GLsizei height) |
michael@0 | 139 | { |
michael@0 | 140 | mRenderer = Renderer11::makeRenderer11(renderer); |
michael@0 | 141 | mTexture = tex; |
michael@0 | 142 | mRenderTarget = rtv; |
michael@0 | 143 | mDepthStencil = NULL; |
michael@0 | 144 | mShaderResource = srv; |
michael@0 | 145 | mSubresourceIndex = 0; |
michael@0 | 146 | |
michael@0 | 147 | if (mRenderTarget && mTexture) |
michael@0 | 148 | { |
michael@0 | 149 | D3D11_RENDER_TARGET_VIEW_DESC desc; |
michael@0 | 150 | mRenderTarget->GetDesc(&desc); |
michael@0 | 151 | |
michael@0 | 152 | D3D11_TEXTURE2D_DESC texDesc; |
michael@0 | 153 | mTexture->GetDesc(&texDesc); |
michael@0 | 154 | |
michael@0 | 155 | mSubresourceIndex = getRTVSubresourceIndex(mTexture, mRenderTarget); |
michael@0 | 156 | mWidth = width; |
michael@0 | 157 | mHeight = height; |
michael@0 | 158 | mSamples = (texDesc.SampleDesc.Count > 1) ? texDesc.SampleDesc.Count : 0; |
michael@0 | 159 | |
michael@0 | 160 | mInternalFormat = d3d11_gl::ConvertTextureInternalFormat(desc.Format); |
michael@0 | 161 | mActualFormat = d3d11_gl::ConvertTextureInternalFormat(desc.Format); |
michael@0 | 162 | } |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | RenderTarget11::RenderTarget11(Renderer *renderer, ID3D11DepthStencilView *dsv, ID3D11Texture2D *tex, ID3D11ShaderResourceView *srv, GLsizei width, GLsizei height) |
michael@0 | 166 | { |
michael@0 | 167 | mRenderer = Renderer11::makeRenderer11(renderer); |
michael@0 | 168 | mTexture = tex; |
michael@0 | 169 | mRenderTarget = NULL; |
michael@0 | 170 | mDepthStencil = dsv; |
michael@0 | 171 | mShaderResource = srv; |
michael@0 | 172 | mSubresourceIndex = 0; |
michael@0 | 173 | |
michael@0 | 174 | if (mDepthStencil && mTexture) |
michael@0 | 175 | { |
michael@0 | 176 | D3D11_DEPTH_STENCIL_VIEW_DESC desc; |
michael@0 | 177 | mDepthStencil->GetDesc(&desc); |
michael@0 | 178 | |
michael@0 | 179 | D3D11_TEXTURE2D_DESC texDesc; |
michael@0 | 180 | mTexture->GetDesc(&texDesc); |
michael@0 | 181 | |
michael@0 | 182 | mSubresourceIndex = getDSVSubresourceIndex(mTexture, mDepthStencil); |
michael@0 | 183 | mWidth = width; |
michael@0 | 184 | mHeight = height; |
michael@0 | 185 | mSamples = (texDesc.SampleDesc.Count > 1) ? texDesc.SampleDesc.Count : 0; |
michael@0 | 186 | |
michael@0 | 187 | mInternalFormat = d3d11_gl::ConvertTextureInternalFormat(desc.Format); |
michael@0 | 188 | mActualFormat = d3d11_gl::ConvertTextureInternalFormat(desc.Format); |
michael@0 | 189 | } |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height, GLenum format, GLsizei samples, bool depth) |
michael@0 | 193 | { |
michael@0 | 194 | mRenderer = Renderer11::makeRenderer11(renderer); |
michael@0 | 195 | mTexture = NULL; |
michael@0 | 196 | mRenderTarget = NULL; |
michael@0 | 197 | mDepthStencil = NULL; |
michael@0 | 198 | mShaderResource = NULL; |
michael@0 | 199 | |
michael@0 | 200 | DXGI_FORMAT requestedFormat = gl_d3d11::ConvertRenderbufferFormat(format); |
michael@0 | 201 | |
michael@0 | 202 | int supportedSamples = mRenderer->getNearestSupportedSamples(requestedFormat, samples); |
michael@0 | 203 | if (supportedSamples < 0) |
michael@0 | 204 | { |
michael@0 | 205 | gl::error(GL_OUT_OF_MEMORY); |
michael@0 | 206 | return; |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | if (width > 0 && height > 0) |
michael@0 | 210 | { |
michael@0 | 211 | // Create texture resource |
michael@0 | 212 | D3D11_TEXTURE2D_DESC desc; |
michael@0 | 213 | desc.Width = width; |
michael@0 | 214 | desc.Height = height; |
michael@0 | 215 | desc.MipLevels = 1; |
michael@0 | 216 | desc.ArraySize = 1; |
michael@0 | 217 | desc.Format = requestedFormat; |
michael@0 | 218 | desc.SampleDesc.Count = (supportedSamples == 0) ? 1 : supportedSamples; |
michael@0 | 219 | desc.SampleDesc.Quality = 0; |
michael@0 | 220 | desc.Usage = D3D11_USAGE_DEFAULT; |
michael@0 | 221 | desc.CPUAccessFlags = 0; |
michael@0 | 222 | desc.MiscFlags = 0; |
michael@0 | 223 | desc.BindFlags = (depth ? D3D11_BIND_DEPTH_STENCIL : (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE)); |
michael@0 | 224 | |
michael@0 | 225 | ID3D11Device *device = mRenderer->getDevice(); |
michael@0 | 226 | HRESULT result = device->CreateTexture2D(&desc, NULL, &mTexture); |
michael@0 | 227 | |
michael@0 | 228 | if (result == E_OUTOFMEMORY) |
michael@0 | 229 | { |
michael@0 | 230 | gl::error(GL_OUT_OF_MEMORY); |
michael@0 | 231 | return; |
michael@0 | 232 | } |
michael@0 | 233 | ASSERT(SUCCEEDED(result)); |
michael@0 | 234 | |
michael@0 | 235 | if (depth) |
michael@0 | 236 | { |
michael@0 | 237 | D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; |
michael@0 | 238 | dsvDesc.Format = requestedFormat; |
michael@0 | 239 | dsvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS; |
michael@0 | 240 | dsvDesc.Texture2D.MipSlice = 0; |
michael@0 | 241 | dsvDesc.Flags = 0; |
michael@0 | 242 | result = device->CreateDepthStencilView(mTexture, &dsvDesc, &mDepthStencil); |
michael@0 | 243 | |
michael@0 | 244 | if (result == E_OUTOFMEMORY) |
michael@0 | 245 | { |
michael@0 | 246 | mTexture->Release(); |
michael@0 | 247 | mTexture = NULL; |
michael@0 | 248 | gl::error(GL_OUT_OF_MEMORY); |
michael@0 | 249 | } |
michael@0 | 250 | ASSERT(SUCCEEDED(result)); |
michael@0 | 251 | } |
michael@0 | 252 | else |
michael@0 | 253 | { |
michael@0 | 254 | D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; |
michael@0 | 255 | rtvDesc.Format = requestedFormat; |
michael@0 | 256 | rtvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS; |
michael@0 | 257 | rtvDesc.Texture2D.MipSlice = 0; |
michael@0 | 258 | result = device->CreateRenderTargetView(mTexture, &rtvDesc, &mRenderTarget); |
michael@0 | 259 | |
michael@0 | 260 | if (result == E_OUTOFMEMORY) |
michael@0 | 261 | { |
michael@0 | 262 | mTexture->Release(); |
michael@0 | 263 | mTexture = NULL; |
michael@0 | 264 | gl::error(GL_OUT_OF_MEMORY); |
michael@0 | 265 | return; |
michael@0 | 266 | } |
michael@0 | 267 | ASSERT(SUCCEEDED(result)); |
michael@0 | 268 | |
michael@0 | 269 | D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; |
michael@0 | 270 | srvDesc.Format = requestedFormat; |
michael@0 | 271 | srvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS; |
michael@0 | 272 | srvDesc.Texture2D.MostDetailedMip = 0; |
michael@0 | 273 | srvDesc.Texture2D.MipLevels = 1; |
michael@0 | 274 | result = device->CreateShaderResourceView(mTexture, &srvDesc, &mShaderResource); |
michael@0 | 275 | |
michael@0 | 276 | if (result == E_OUTOFMEMORY) |
michael@0 | 277 | { |
michael@0 | 278 | mTexture->Release(); |
michael@0 | 279 | mTexture = NULL; |
michael@0 | 280 | mRenderTarget->Release(); |
michael@0 | 281 | mRenderTarget = NULL; |
michael@0 | 282 | gl::error(GL_OUT_OF_MEMORY); |
michael@0 | 283 | return; |
michael@0 | 284 | } |
michael@0 | 285 | ASSERT(SUCCEEDED(result)); |
michael@0 | 286 | } |
michael@0 | 287 | } |
michael@0 | 288 | |
michael@0 | 289 | mWidth = width; |
michael@0 | 290 | mHeight = height; |
michael@0 | 291 | mInternalFormat = format; |
michael@0 | 292 | mSamples = supportedSamples; |
michael@0 | 293 | mActualFormat = d3d11_gl::ConvertTextureInternalFormat(requestedFormat); |
michael@0 | 294 | mSubresourceIndex = D3D11CalcSubresource(0, 0, 1); |
michael@0 | 295 | } |
michael@0 | 296 | |
michael@0 | 297 | RenderTarget11::~RenderTarget11() |
michael@0 | 298 | { |
michael@0 | 299 | if (mTexture) |
michael@0 | 300 | { |
michael@0 | 301 | mTexture->Release(); |
michael@0 | 302 | mTexture = NULL; |
michael@0 | 303 | } |
michael@0 | 304 | |
michael@0 | 305 | if (mRenderTarget) |
michael@0 | 306 | { |
michael@0 | 307 | mRenderTarget->Release(); |
michael@0 | 308 | mRenderTarget = NULL; |
michael@0 | 309 | } |
michael@0 | 310 | |
michael@0 | 311 | if (mDepthStencil) |
michael@0 | 312 | { |
michael@0 | 313 | mDepthStencil->Release(); |
michael@0 | 314 | mDepthStencil = NULL; |
michael@0 | 315 | } |
michael@0 | 316 | |
michael@0 | 317 | if (mShaderResource) |
michael@0 | 318 | { |
michael@0 | 319 | mShaderResource->Release(); |
michael@0 | 320 | mShaderResource = NULL; |
michael@0 | 321 | } |
michael@0 | 322 | } |
michael@0 | 323 | |
michael@0 | 324 | RenderTarget11 *RenderTarget11::makeRenderTarget11(RenderTarget *target) |
michael@0 | 325 | { |
michael@0 | 326 | ASSERT(HAS_DYNAMIC_TYPE(rx::RenderTarget11*, target)); |
michael@0 | 327 | return static_cast<rx::RenderTarget11*>(target); |
michael@0 | 328 | } |
michael@0 | 329 | |
michael@0 | 330 | ID3D11Texture2D *RenderTarget11::getTexture() const |
michael@0 | 331 | { |
michael@0 | 332 | return mTexture; |
michael@0 | 333 | } |
michael@0 | 334 | |
michael@0 | 335 | ID3D11RenderTargetView *RenderTarget11::getRenderTargetView() const |
michael@0 | 336 | { |
michael@0 | 337 | return mRenderTarget; |
michael@0 | 338 | } |
michael@0 | 339 | |
michael@0 | 340 | ID3D11DepthStencilView *RenderTarget11::getDepthStencilView() const |
michael@0 | 341 | { |
michael@0 | 342 | return mDepthStencil; |
michael@0 | 343 | } |
michael@0 | 344 | |
michael@0 | 345 | ID3D11ShaderResourceView *RenderTarget11::getShaderResourceView() const |
michael@0 | 346 | { |
michael@0 | 347 | return mShaderResource; |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | unsigned int RenderTarget11::getSubresourceIndex() const |
michael@0 | 351 | { |
michael@0 | 352 | return mSubresourceIndex; |
michael@0 | 353 | } |
michael@0 | 354 | |
michael@0 | 355 | } |