gfx/angle/src/libGLESv2/renderer/IndexBuffer11.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 // IndexBuffer11.cpp: Defines the D3D11 IndexBuffer implementation.
michael@0 9
michael@0 10 #include "libGLESv2/renderer/IndexBuffer11.h"
michael@0 11 #include "libGLESv2/renderer/Renderer11.h"
michael@0 12
michael@0 13 namespace rx
michael@0 14 {
michael@0 15
michael@0 16 IndexBuffer11::IndexBuffer11(Renderer11 *const renderer) : mRenderer(renderer)
michael@0 17 {
michael@0 18 mBuffer = NULL;
michael@0 19 mBufferSize = 0;
michael@0 20 mDynamicUsage = false;
michael@0 21 }
michael@0 22
michael@0 23 IndexBuffer11::~IndexBuffer11()
michael@0 24 {
michael@0 25 if (mBuffer)
michael@0 26 {
michael@0 27 mBuffer->Release();
michael@0 28 mBuffer = NULL;
michael@0 29 }
michael@0 30 }
michael@0 31
michael@0 32 bool IndexBuffer11::initialize(unsigned int bufferSize, GLenum indexType, bool dynamic)
michael@0 33 {
michael@0 34 if (mBuffer)
michael@0 35 {
michael@0 36 mBuffer->Release();
michael@0 37 mBuffer = NULL;
michael@0 38 }
michael@0 39
michael@0 40 updateSerial();
michael@0 41
michael@0 42 if (bufferSize > 0)
michael@0 43 {
michael@0 44 ID3D11Device* dxDevice = mRenderer->getDevice();
michael@0 45
michael@0 46 D3D11_BUFFER_DESC bufferDesc;
michael@0 47 bufferDesc.ByteWidth = bufferSize;
michael@0 48 bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
michael@0 49 bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
michael@0 50 bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
michael@0 51 bufferDesc.MiscFlags = 0;
michael@0 52 bufferDesc.StructureByteStride = 0;
michael@0 53
michael@0 54 HRESULT result = dxDevice->CreateBuffer(&bufferDesc, NULL, &mBuffer);
michael@0 55 if (FAILED(result))
michael@0 56 {
michael@0 57 return false;
michael@0 58 }
michael@0 59 }
michael@0 60
michael@0 61 mBufferSize = bufferSize;
michael@0 62 mIndexType = indexType;
michael@0 63 mDynamicUsage = dynamic;
michael@0 64
michael@0 65 return true;
michael@0 66 }
michael@0 67
michael@0 68 IndexBuffer11 *IndexBuffer11::makeIndexBuffer11(IndexBuffer *indexBuffer)
michael@0 69 {
michael@0 70 ASSERT(HAS_DYNAMIC_TYPE(IndexBuffer11*, indexBuffer));
michael@0 71 return static_cast<IndexBuffer11*>(indexBuffer);
michael@0 72 }
michael@0 73
michael@0 74 bool IndexBuffer11::mapBuffer(unsigned int offset, unsigned int size, void** outMappedMemory)
michael@0 75 {
michael@0 76 if (mBuffer)
michael@0 77 {
michael@0 78 // Check for integer overflows and out-out-bounds map requests
michael@0 79 if (offset + size < offset || offset + size > mBufferSize)
michael@0 80 {
michael@0 81 ERR("Index buffer map range is not inside the buffer.");
michael@0 82 return false;
michael@0 83 }
michael@0 84
michael@0 85 ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
michael@0 86
michael@0 87 D3D11_MAPPED_SUBRESOURCE mappedResource;
michael@0 88 HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource);
michael@0 89 if (FAILED(result))
michael@0 90 {
michael@0 91 ERR("Index buffer map failed with error 0x%08x", result);
michael@0 92 return false;
michael@0 93 }
michael@0 94
michael@0 95 *outMappedMemory = reinterpret_cast<char*>(mappedResource.pData) + offset;
michael@0 96 return true;
michael@0 97 }
michael@0 98 else
michael@0 99 {
michael@0 100 ERR("Index buffer not initialized.");
michael@0 101 return false;
michael@0 102 }
michael@0 103 }
michael@0 104
michael@0 105 bool IndexBuffer11::unmapBuffer()
michael@0 106 {
michael@0 107 if (mBuffer)
michael@0 108 {
michael@0 109 ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
michael@0 110 dxContext->Unmap(mBuffer, 0);
michael@0 111 return true;
michael@0 112 }
michael@0 113 else
michael@0 114 {
michael@0 115 ERR("Index buffer not initialized.");
michael@0 116 return false;
michael@0 117 }
michael@0 118 }
michael@0 119
michael@0 120 GLenum IndexBuffer11::getIndexType() const
michael@0 121 {
michael@0 122 return mIndexType;
michael@0 123 }
michael@0 124
michael@0 125 unsigned int IndexBuffer11::getBufferSize() const
michael@0 126 {
michael@0 127 return mBufferSize;
michael@0 128 }
michael@0 129
michael@0 130 bool IndexBuffer11::setSize(unsigned int bufferSize, GLenum indexType)
michael@0 131 {
michael@0 132 if (bufferSize > mBufferSize || indexType != mIndexType)
michael@0 133 {
michael@0 134 return initialize(bufferSize, indexType, mDynamicUsage);
michael@0 135 }
michael@0 136 else
michael@0 137 {
michael@0 138 return true;
michael@0 139 }
michael@0 140 }
michael@0 141
michael@0 142 bool IndexBuffer11::discard()
michael@0 143 {
michael@0 144 if (mBuffer)
michael@0 145 {
michael@0 146 ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
michael@0 147
michael@0 148 D3D11_MAPPED_SUBRESOURCE mappedResource;
michael@0 149 HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
michael@0 150 if (FAILED(result))
michael@0 151 {
michael@0 152 ERR("Index buffer map failed with error 0x%08x", result);
michael@0 153 return false;
michael@0 154 }
michael@0 155
michael@0 156 dxContext->Unmap(mBuffer, 0);
michael@0 157
michael@0 158 return true;
michael@0 159 }
michael@0 160 else
michael@0 161 {
michael@0 162 ERR("Index buffer not initialized.");
michael@0 163 return false;
michael@0 164 }
michael@0 165 }
michael@0 166
michael@0 167 DXGI_FORMAT IndexBuffer11::getIndexFormat() const
michael@0 168 {
michael@0 169 switch (mIndexType)
michael@0 170 {
michael@0 171 case GL_UNSIGNED_BYTE: return DXGI_FORMAT_R16_UINT;
michael@0 172 case GL_UNSIGNED_SHORT: return DXGI_FORMAT_R16_UINT;
michael@0 173 case GL_UNSIGNED_INT: return DXGI_FORMAT_R32_UINT;
michael@0 174 default: UNREACHABLE(); return DXGI_FORMAT_UNKNOWN;
michael@0 175 }
michael@0 176 }
michael@0 177
michael@0 178 ID3D11Buffer *IndexBuffer11::getBuffer() const
michael@0 179 {
michael@0 180 return mBuffer;
michael@0 181 }
michael@0 182
michael@0 183 }

mercurial