gfx/angle/src/libGLESv2/renderer/IndexBuffer9.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) 2002-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 // Indexffer9.cpp: Defines the D3D9 IndexBuffer implementation.
michael@0 9
michael@0 10 #include "libGLESv2/renderer/IndexBuffer9.h"
michael@0 11 #include "libGLESv2/renderer/Renderer9.h"
michael@0 12
michael@0 13 namespace rx
michael@0 14 {
michael@0 15
michael@0 16 IndexBuffer9::IndexBuffer9(Renderer9 *const renderer) : mRenderer(renderer)
michael@0 17 {
michael@0 18 mIndexBuffer = NULL;
michael@0 19 mBufferSize = 0;
michael@0 20 mIndexType = 0;
michael@0 21 mDynamic = false;
michael@0 22 }
michael@0 23
michael@0 24 IndexBuffer9::~IndexBuffer9()
michael@0 25 {
michael@0 26 if (mIndexBuffer)
michael@0 27 {
michael@0 28 mIndexBuffer->Release();
michael@0 29 mIndexBuffer = NULL;
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33 bool IndexBuffer9::initialize(unsigned int bufferSize, GLenum indexType, bool dynamic)
michael@0 34 {
michael@0 35 if (mIndexBuffer)
michael@0 36 {
michael@0 37 mIndexBuffer->Release();
michael@0 38 mIndexBuffer = NULL;
michael@0 39 }
michael@0 40
michael@0 41 updateSerial();
michael@0 42
michael@0 43 if (bufferSize > 0)
michael@0 44 {
michael@0 45 D3DFORMAT format;
michael@0 46 if (indexType == GL_UNSIGNED_SHORT || indexType == GL_UNSIGNED_BYTE)
michael@0 47 {
michael@0 48 format = D3DFMT_INDEX16;
michael@0 49 }
michael@0 50 else if (indexType == GL_UNSIGNED_INT)
michael@0 51 {
michael@0 52 if (mRenderer->get32BitIndexSupport())
michael@0 53 {
michael@0 54 format = D3DFMT_INDEX32;
michael@0 55 }
michael@0 56 else
michael@0 57 {
michael@0 58 ERR("Attempted to create a 32-bit index buffer but renderer does not support 32-bit indices.");
michael@0 59 return false;
michael@0 60 }
michael@0 61 }
michael@0 62 else
michael@0 63 {
michael@0 64 ERR("Invalid index type %u.", indexType);
michael@0 65 return false;
michael@0 66 }
michael@0 67
michael@0 68 DWORD usageFlags = D3DUSAGE_WRITEONLY;
michael@0 69 if (dynamic)
michael@0 70 {
michael@0 71 usageFlags |= D3DUSAGE_DYNAMIC;
michael@0 72 }
michael@0 73
michael@0 74 HRESULT result = mRenderer->createIndexBuffer(bufferSize, usageFlags, format, &mIndexBuffer);
michael@0 75 if (FAILED(result))
michael@0 76 {
michael@0 77 ERR("Failed to create an index buffer of size %u, result: 0x%08x.", mBufferSize, result);
michael@0 78 return false;
michael@0 79 }
michael@0 80 }
michael@0 81
michael@0 82 mBufferSize = bufferSize;
michael@0 83 mIndexType = indexType;
michael@0 84 mDynamic = dynamic;
michael@0 85
michael@0 86 return true;
michael@0 87 }
michael@0 88
michael@0 89 IndexBuffer9 *IndexBuffer9::makeIndexBuffer9(IndexBuffer *indexBuffer)
michael@0 90 {
michael@0 91 ASSERT(HAS_DYNAMIC_TYPE(IndexBuffer9*, indexBuffer));
michael@0 92 return static_cast<IndexBuffer9*>(indexBuffer);
michael@0 93 }
michael@0 94
michael@0 95 bool IndexBuffer9::mapBuffer(unsigned int offset, unsigned int size, void** outMappedMemory)
michael@0 96 {
michael@0 97 if (mIndexBuffer)
michael@0 98 {
michael@0 99 DWORD lockFlags = mDynamic ? D3DLOCK_NOOVERWRITE : 0;
michael@0 100
michael@0 101 void *mapPtr = NULL;
michael@0 102 HRESULT result = mIndexBuffer->Lock(offset, size, &mapPtr, lockFlags);
michael@0 103 if (FAILED(result))
michael@0 104 {
michael@0 105 ERR("Index buffer lock failed with error 0x%08x", result);
michael@0 106 return false;
michael@0 107 }
michael@0 108
michael@0 109 *outMappedMemory = mapPtr;
michael@0 110 return true;
michael@0 111 }
michael@0 112 else
michael@0 113 {
michael@0 114 ERR("Index buffer not initialized.");
michael@0 115 return false;
michael@0 116 }
michael@0 117 }
michael@0 118
michael@0 119 bool IndexBuffer9::unmapBuffer()
michael@0 120 {
michael@0 121 if (mIndexBuffer)
michael@0 122 {
michael@0 123 HRESULT result = mIndexBuffer->Unlock();
michael@0 124 if (FAILED(result))
michael@0 125 {
michael@0 126 ERR("Index buffer unlock failed with error 0x%08x", result);
michael@0 127 return false;
michael@0 128 }
michael@0 129
michael@0 130 return true;
michael@0 131 }
michael@0 132 else
michael@0 133 {
michael@0 134 ERR("Index buffer not initialized.");
michael@0 135 return false;
michael@0 136 }
michael@0 137 }
michael@0 138
michael@0 139 GLenum IndexBuffer9::getIndexType() const
michael@0 140 {
michael@0 141 return mIndexType;
michael@0 142 }
michael@0 143
michael@0 144 unsigned int IndexBuffer9::getBufferSize() const
michael@0 145 {
michael@0 146 return mBufferSize;
michael@0 147 }
michael@0 148
michael@0 149 bool IndexBuffer9::setSize(unsigned int bufferSize, GLenum indexType)
michael@0 150 {
michael@0 151 if (bufferSize > mBufferSize || indexType != mIndexType)
michael@0 152 {
michael@0 153 return initialize(bufferSize, indexType, mDynamic);
michael@0 154 }
michael@0 155 else
michael@0 156 {
michael@0 157 return true;
michael@0 158 }
michael@0 159 }
michael@0 160
michael@0 161 bool IndexBuffer9::discard()
michael@0 162 {
michael@0 163 if (mIndexBuffer)
michael@0 164 {
michael@0 165 void *dummy;
michael@0 166 HRESULT result;
michael@0 167
michael@0 168 result = mIndexBuffer->Lock(0, 1, &dummy, D3DLOCK_DISCARD);
michael@0 169 if (FAILED(result))
michael@0 170 {
michael@0 171 ERR("Discard lock failed with error 0x%08x", result);
michael@0 172 return false;
michael@0 173 }
michael@0 174
michael@0 175 result = mIndexBuffer->Unlock();
michael@0 176 if (FAILED(result))
michael@0 177 {
michael@0 178 ERR("Discard unlock failed with error 0x%08x", result);
michael@0 179 return false;
michael@0 180 }
michael@0 181
michael@0 182 return true;
michael@0 183 }
michael@0 184 else
michael@0 185 {
michael@0 186 ERR("Index buffer not initialized.");
michael@0 187 return false;
michael@0 188 }
michael@0 189 }
michael@0 190
michael@0 191 D3DFORMAT IndexBuffer9::getIndexFormat() const
michael@0 192 {
michael@0 193 switch (mIndexType)
michael@0 194 {
michael@0 195 case GL_UNSIGNED_BYTE: return D3DFMT_INDEX16;
michael@0 196 case GL_UNSIGNED_SHORT: return D3DFMT_INDEX16;
michael@0 197 case GL_UNSIGNED_INT: return D3DFMT_INDEX32;
michael@0 198 default: UNREACHABLE(); return D3DFMT_UNKNOWN;
michael@0 199 }
michael@0 200 }
michael@0 201
michael@0 202 IDirect3DIndexBuffer9 * IndexBuffer9::getBuffer() const
michael@0 203 {
michael@0 204 return mIndexBuffer;
michael@0 205 }
michael@0 206
michael@0 207 }

mercurial