Commit c8d297a4 by Geoff Lang

Remove last uses of gl::error in the Buffer classes.

BUG=angle:520 Change-Id: Id18e93b440da64360a6845a42a2664ae531b06f9 Reviewed-on: https://chromium-review.googlesource.com/218769Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent f9004131
......@@ -12,6 +12,8 @@
#include "common/angleutils.h"
#include "libGLESv2/Buffer.h"
#include <cstdint>
namespace rx
{
......@@ -21,7 +23,7 @@ class BufferImpl
virtual ~BufferImpl() { }
virtual gl::Error setData(const void* data, size_t size, GLenum usage) = 0;
virtual void *getData() = 0;
virtual gl::Error getData(const uint8_t **outData) = 0;
virtual gl::Error setSubData(const void* data, size_t size, size_t offset) = 0;
virtual gl::Error copySubData(BufferImpl* source, GLintptr sourceOffset, GLintptr destOffset, GLsizeiptr size) = 0;
virtual gl::Error map(size_t offset, size_t length, GLbitfield access, GLvoid **mapPtr) = 0;
......
......@@ -97,7 +97,14 @@ gl::Error IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buf
ASSERT(typeInfo.bytes * static_cast<unsigned int>(count) + offset <= storage->getSize());
indices = static_cast<const GLubyte*>(storage->getData()) + offset;
const uint8_t *bufferData = NULL;
gl::Error error = storage->getData(&bufferData);
if (error.isError())
{
return error;
}
indices = bufferData + offset;
}
StaticIndexBufferInterface *staticBuffer = storage ? storage->getStaticIndexBuffer() : NULL;
......@@ -183,7 +190,16 @@ gl::Error IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buf
return error;
}
ConvertIndices(type, destinationIndexType, staticBuffer ? storage->getData() : indices, convertCount, output);
const uint8_t *dataPointer = reinterpret_cast<const uint8_t*>(indices);
if (staticBuffer)
{
error = storage->getData(&dataPointer);
if (error.isError())
{
return error;
}
}
ConvertIndices(type, destinationIndexType, dataPointer, convertCount, output);
error = indexBuffer->unmapBuffer();
if (error.isError())
......
......@@ -132,8 +132,13 @@ gl::Error TextureD3D::setImage(const gl::PixelUnpackState &unpack, GLenum type,
ptrdiff_t offset = reinterpret_cast<ptrdiff_t>(pixels);
// TODO: setImage/subImage is the only place outside of renderer that asks for a buffers raw data.
// This functionality should be moved into renderer and the getData method of BufferImpl removed.
const void *bufferData = pixelBuffer->getImplementation()->getData();
pixelData = static_cast<const uint8_t *>(bufferData) + offset;
const uint8_t *bufferData = NULL;
gl::Error error = pixelBuffer->getImplementation()->getData(&bufferData);
if (error.isError())
{
return error;
}
pixelData = bufferData + offset;
}
else
{
......@@ -176,8 +181,13 @@ gl::Error TextureD3D::subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsi
uintptr_t offset = reinterpret_cast<uintptr_t>(pixels);
// TODO: setImage/subImage is the only place outside of renderer that asks for a buffers raw data.
// This functionality should be moved into renderer and the getData method of BufferImpl removed.
const void *bufferData = pixelBuffer->getImplementation()->getData();
pixelData = static_cast<const uint8_t *>(bufferData)+offset;
const uint8_t *bufferData = NULL;
gl::Error error = pixelBuffer->getImplementation()->getData(&bufferData);
if (error.isError())
{
return error;
}
pixelData = bufferData + offset;
}
if (pixelData != NULL)
......
......@@ -86,7 +86,7 @@ class Buffer11::BufferStorage11
virtual bool copyFromStorage(BufferStorage11 *source, size_t sourceOffset,
size_t size, size_t destOffset) = 0;
virtual bool resize(size_t size, bool preserveData) = 0;
virtual gl::Error resize(size_t size, bool preserveData) = 0;
virtual void *map(size_t offset, size_t length, GLbitfield access) = 0;
virtual void unmap() = 0;
......@@ -112,12 +112,12 @@ class Buffer11::NativeBuffer11 : public Buffer11::BufferStorage11
virtual bool copyFromStorage(BufferStorage11 *source, size_t sourceOffset,
size_t size, size_t destOffset);
virtual bool resize(size_t size, bool preserveData);
virtual gl::Error resize(size_t size, bool preserveData);
virtual void *map(size_t offset, size_t length, GLbitfield access);
virtual void unmap();
bool setData(D3D11_MAP mapMode, const uint8_t *data, size_t size, size_t offset);
gl::Error setData(D3D11_MAP mapMode, const uint8_t *data, size_t size, size_t offset);
private:
ID3D11Buffer *mNativeBuffer;
......@@ -135,7 +135,7 @@ class Buffer11::PackStorage11 : public Buffer11::BufferStorage11
virtual bool copyFromStorage(BufferStorage11 *source, size_t sourceOffset,
size_t size, size_t destOffset);
virtual bool resize(size_t size, bool preserveData);
virtual gl::Error resize(size_t size, bool preserveData);
virtual void *map(size_t offset, size_t length, GLbitfield access);
virtual void unmap();
......@@ -195,14 +195,14 @@ gl::Error Buffer11::setData(const void *data, size_t size, GLenum usage)
return error;
}
void *Buffer11::getData()
gl::Error Buffer11::getData(const uint8_t **outData)
{
NativeBuffer11 *stagingBuffer = getStagingBuffer();
if (!stagingBuffer)
{
// Out-of-memory
return NULL;
return gl::Error(GL_OUT_OF_MEMORY, "Failed to get internal staging buffer.");
}
if (stagingBuffer->getDataRevision() > mResolvedDataRevision)
......@@ -211,7 +211,7 @@ void *Buffer11::getData()
{
if (!mResolvedData.resize(stagingBuffer->getSize()))
{
return gl::error(GL_OUT_OF_MEMORY, (void*)NULL);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to resize data resolve buffer.");
}
}
......@@ -221,7 +221,7 @@ void *Buffer11::getData()
HRESULT result = context->Map(stagingBuffer->getNativeBuffer(), 0, D3D11_MAP_READ, 0, &mappedResource);
if (FAILED(result))
{
return gl::error(GL_OUT_OF_MEMORY, (void*)NULL);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal buffer, result: 0x%X.", result);
}
memcpy(mResolvedData.data(), mappedResource.pData, stagingBuffer->getSize());
......@@ -238,13 +238,14 @@ void *Buffer11::getData()
{
if (!mResolvedData.resize(mSize))
{
return gl::error(GL_OUT_OF_MEMORY, (void*)NULL);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to resize data resolve buffer.");
}
}
ASSERT(mResolvedData.size() >= mSize);
return mResolvedData.data();
*outData = mResolvedData.data();
return gl::Error(GL_NO_ERROR);
}
gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset)
......@@ -265,15 +266,17 @@ gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset)
if (stagingBuffer->getSize() < requiredSize)
{
bool preserveData = (offset > 0);
if (!stagingBuffer->resize(requiredSize, preserveData))
gl::Error error = stagingBuffer->resize(requiredSize, preserveData);
if (error.isError())
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to resize internal staging buffer.");
return error;
}
}
if (!stagingBuffer->setData(D3D11_MAP_WRITE, reinterpret_cast<const uint8_t *>(data), size, offset))
gl::Error error = stagingBuffer->setData(D3D11_MAP_WRITE, reinterpret_cast<const uint8_t *>(data), size, offset);
if (error.isError())
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to set data on internal staging buffer.");
return error;
}
stagingBuffer->setDataRevision(stagingBuffer->getDataRevision() + 1);
......@@ -527,7 +530,7 @@ Buffer11::BufferStorage11 *Buffer11::getBufferStorage(BufferUsage usage)
// resize buffer
if (directBuffer->getSize() < mSize)
{
if (!directBuffer->resize(mSize, true))
if (directBuffer->resize(mSize, true).isError())
{
// Out of memory error
return NULL;
......@@ -692,7 +695,7 @@ bool Buffer11::NativeBuffer11::copyFromStorage(BufferStorage11 *source, size_t s
return createBuffer;
}
bool Buffer11::NativeBuffer11::resize(size_t size, bool preserveData)
gl::Error Buffer11::NativeBuffer11::resize(size_t size, bool preserveData)
{
ID3D11Device *device = mRenderer->getDevice();
ID3D11DeviceContext *context = mRenderer->getDeviceContext();
......@@ -705,7 +708,7 @@ bool Buffer11::NativeBuffer11::resize(size_t size, bool preserveData)
if (FAILED(result))
{
return gl::error(GL_OUT_OF_MEMORY, false);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer, result: 0x%X.", result);
}
if (mNativeBuffer && preserveData)
......@@ -730,7 +733,7 @@ bool Buffer11::NativeBuffer11::resize(size_t size, bool preserveData)
mBufferSize = bufferDesc.ByteWidth;
return true;
return gl::Error(GL_NO_ERROR);
}
void Buffer11::NativeBuffer11::fillBufferDesc(D3D11_BUFFER_DESC* bufferDesc, Renderer *renderer,
......@@ -798,7 +801,7 @@ void *Buffer11::NativeBuffer11::map(size_t offset, size_t length, GLbitfield acc
return static_cast<GLubyte*>(mappedResource.pData) + offset;
}
bool Buffer11::NativeBuffer11::setData(D3D11_MAP mapMode, const uint8_t *data, size_t size, size_t offset)
gl::Error Buffer11::NativeBuffer11::setData(D3D11_MAP mapMode, const uint8_t *data, size_t size, size_t offset)
{
ID3D11DeviceContext *context = mRenderer->getDeviceContext();
......@@ -806,7 +809,7 @@ bool Buffer11::NativeBuffer11::setData(D3D11_MAP mapMode, const uint8_t *data, s
HRESULT result = context->Map(mNativeBuffer, 0, mapMode, 0, &mappedResource);
if (FAILED(result))
{
return gl::error(GL_OUT_OF_MEMORY, false);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal buffer, result: 0x%X.", result);
}
uint8_t *offsetBufferPointer = reinterpret_cast<uint8_t *>(mappedResource.pData) + offset;
......@@ -814,7 +817,7 @@ bool Buffer11::NativeBuffer11::setData(D3D11_MAP mapMode, const uint8_t *data, s
context->Unmap(mNativeBuffer, 0);
return true;
return gl::Error(GL_NO_ERROR);
}
void Buffer11::NativeBuffer11::unmap()
......@@ -848,18 +851,18 @@ bool Buffer11::PackStorage11::copyFromStorage(BufferStorage11 *source, size_t so
return false;
}
bool Buffer11::PackStorage11::resize(size_t size, bool preserveData)
gl::Error Buffer11::PackStorage11::resize(size_t size, bool preserveData)
{
if (size != mBufferSize)
{
if (!mMemoryBuffer.resize(size))
{
return false;
return gl::Error(GL_OUT_OF_MEMORY, "Failed to resize internal buffer storage.");
}
mBufferSize = size;
}
return true;
return gl::Error(GL_NO_ERROR);
}
void *Buffer11::PackStorage11::map(size_t offset, size_t length, GLbitfield access)
......
......@@ -64,7 +64,7 @@ class Buffer11 : public BufferD3D
// BufferImpl implementation
virtual gl::Error setData(const void* data, size_t size, GLenum usage);
virtual void *getData();
virtual gl::Error getData(const uint8_t **outData);
virtual gl::Error setSubData(const void* data, size_t size, size_t offset);
virtual gl::Error copySubData(BufferImpl* source, GLintptr sourceOffset, GLintptr destOffset, GLsizeiptr size);
virtual gl::Error map(size_t offset, size_t length, GLbitfield access, GLvoid **mapPtr);
......
......@@ -1197,7 +1197,15 @@ gl::Error Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *ind
gl::Buffer *indexBuffer = elementArrayBuffer;
BufferImpl *storage = indexBuffer->getImplementation();
intptr_t offset = reinterpret_cast<intptr_t>(indices);
indices = static_cast<const GLubyte*>(storage->getData()) + offset;
const uint8_t *bufferData = NULL;
gl::Error error = storage->getData(&bufferData);
if (error.isError())
{
return error;
}
indices = bufferData + offset;
}
if (!mLineLoopIB)
......@@ -1301,7 +1309,15 @@ gl::Error Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *
gl::Buffer *indexBuffer = elementArrayBuffer;
BufferImpl *storage = indexBuffer->getImplementation();
intptr_t offset = reinterpret_cast<intptr_t>(indices);
indices = static_cast<const GLubyte*>(storage->getData()) + offset;
const uint8_t *bufferData = NULL;
gl::Error error = storage->getData(&bufferData);
if (error.isError())
{
return error;
}
indices = bufferData + offset;
}
if (!mTriangleFanIB)
......
......@@ -91,8 +91,13 @@ gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attri
{
if (buffer)
{
Buffer11 *storage = Buffer11::makeBuffer11(buffer->getImplementation());
input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
BufferImpl *storage = buffer->getImplementation();
gl::Error error = storage->getData(&input);
if (error.isError())
{
return error;
}
input += static_cast<int>(attrib.offset);
}
else
{
......
......@@ -56,9 +56,10 @@ gl::Error Buffer9::setData(const void* data, size_t size, GLenum usage)
return gl::Error(GL_NO_ERROR);
}
void *Buffer9::getData()
gl::Error Buffer9::getData(const uint8_t **outData)
{
return mMemory.data();
*outData = mMemory.data();
return gl::Error(GL_NO_ERROR);
}
gl::Error Buffer9::setSubData(const void* data, size_t size, size_t offset)
......
......@@ -32,7 +32,7 @@ class Buffer9 : public BufferD3D
// BufferImpl implementation
virtual gl::Error setData(const void* data, size_t size, GLenum usage);
virtual void *getData();
virtual gl::Error getData(const uint8_t **outData);
virtual gl::Error setSubData(const void* data, size_t size, size_t offset);
virtual gl::Error copySubData(BufferImpl* source, GLintptr sourceOffset, GLintptr destOffset, GLsizeiptr size);
virtual gl::Error map(size_t offset, size_t length, GLbitfield access, GLvoid **mapPtr);
......
......@@ -1415,7 +1415,13 @@ gl::Error Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indi
gl::Buffer *indexBuffer = elementArrayBuffer;
BufferImpl *storage = indexBuffer->getImplementation();
intptr_t offset = reinterpret_cast<intptr_t>(indices);
indices = static_cast<const GLubyte*>(storage->getData()) + offset;
const uint8_t *bufferData = NULL;
gl::Error error = storage->getData(&bufferData);
if (error.isError())
{
return error;
}
indices = bufferData + offset;
}
unsigned int startIndex = 0;
......@@ -1611,7 +1617,15 @@ gl::Error Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid
{
BufferImpl *storage = elementArrayBuffer->getImplementation();
intptr_t offset = reinterpret_cast<intptr_t>(indices);
indices = static_cast<const GLubyte*>(storage->getData()) + offset;
const uint8_t *bufferData = NULL;
gl::Error error = storage->getData(&bufferData);
if (error.isError())
{
return error;
}
indices = bufferData + offset;
}
switch (type)
......
......@@ -98,7 +98,12 @@ gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib
if (buffer)
{
BufferImpl *storage = buffer->getImplementation();
input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
gl::Error error = storage->getData(&input);
if (error.isError())
{
return error;
}
input += static_cast<int>(attrib.offset);
}
else
{
......
......@@ -1671,8 +1671,15 @@ bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum t
uintptr_t offset = reinterpret_cast<uintptr_t>(indices);
if (!elementArrayBuffer->getIndexRangeCache()->findRange(type, offset, count, indexRangeOut, NULL))
{
const void *dataPointer = elementArrayBuffer->getImplementation()->getData();
const uint8_t *offsetPointer = static_cast<const uint8_t *>(dataPointer) + offset;
const uint8_t *dataPointer = NULL;
Error error = elementArrayBuffer->getImplementation()->getData(&dataPointer);
if (error.isError())
{
context->recordError(error);
return false;
}
const uint8_t *offsetPointer = dataPointer + offset;
*indexRangeOut = rx::IndexRangeCache::ComputeRange(type, offsetPointer, count);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment