Remove last uses of gl::error in the Buffer classes.
BUG=angle:520
Change-Id: Id18e93b440da64360a6845a42a2664ae531b06f9
Reviewed-on: https://chromium-review.googlesource.com/218769
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2/renderer/BufferImpl.h b/src/libGLESv2/renderer/BufferImpl.h
index f0b5f02..790e033 100644
--- a/src/libGLESv2/renderer/BufferImpl.h
+++ b/src/libGLESv2/renderer/BufferImpl.h
@@ -12,6 +12,8 @@
#include "common/angleutils.h"
#include "libGLESv2/Buffer.h"
+#include <cstdint>
+
namespace rx
{
@@ -21,7 +23,7 @@
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;
diff --git a/src/libGLESv2/renderer/d3d/IndexDataManager.cpp b/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
index 8d455b4..206ef39 100644
--- a/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
+++ b/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
@@ -97,7 +97,14 @@
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 @@
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())
diff --git a/src/libGLESv2/renderer/d3d/TextureD3D.cpp b/src/libGLESv2/renderer/d3d/TextureD3D.cpp
index bbe1261..42fea65 100644
--- a/src/libGLESv2/renderer/d3d/TextureD3D.cpp
+++ b/src/libGLESv2/renderer/d3d/TextureD3D.cpp
@@ -132,8 +132,13 @@
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 @@
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)
diff --git a/src/libGLESv2/renderer/d3d/d3d11/Buffer11.cpp b/src/libGLESv2/renderer/d3d/d3d11/Buffer11.cpp
index 877b303..4ec0f49 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/Buffer11.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/Buffer11.cpp
@@ -86,7 +86,7 @@
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 @@
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 @@
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 @@
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 @@
{
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 @@
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 @@
{
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 @@
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 @@
// 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
context->Unmap(mNativeBuffer, 0);
- return true;
+ return gl::Error(GL_NO_ERROR);
}
void Buffer11::NativeBuffer11::unmap()
@@ -848,18 +851,18 @@
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)
diff --git a/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h b/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h
index 5f24fb4..c723b11 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h
+++ b/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h
@@ -64,7 +64,7 @@
// 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);
diff --git a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
index b60c478..f985d02 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
@@ -1197,7 +1197,15 @@
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::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)
diff --git a/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp b/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp
index 9bc5b1d..312c2be 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp
@@ -91,8 +91,13 @@
{
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
{
diff --git a/src/libGLESv2/renderer/d3d/d3d9/Buffer9.cpp b/src/libGLESv2/renderer/d3d/d3d9/Buffer9.cpp
index ff79a8a..6c8ad2b 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/Buffer9.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/Buffer9.cpp
@@ -56,9 +56,10 @@
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)
diff --git a/src/libGLESv2/renderer/d3d/d3d9/Buffer9.h b/src/libGLESv2/renderer/d3d/d3d9/Buffer9.h
index e78182f..a9344ae 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/Buffer9.h
+++ b/src/libGLESv2/renderer/d3d/d3d9/Buffer9.h
@@ -32,7 +32,7 @@
// 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);
diff --git a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
index 62d64de..3c48fcf 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
@@ -1415,7 +1415,13 @@
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 @@
{
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)
diff --git a/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp b/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp
index 4cf7779..994b386 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp
@@ -98,7 +98,12 @@
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
{
diff --git a/src/libGLESv2/validationES.cpp b/src/libGLESv2/validationES.cpp
index 59c18a2..d0b2331 100644
--- a/src/libGLESv2/validationES.cpp
+++ b/src/libGLESv2/validationES.cpp
@@ -1671,8 +1671,15 @@
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);
}
}