Remove getData from BufferImpl.
We only ever call this method inside the D3D Renderer, so we can
downcast to BufferD3D and call getData on the D3D-specific type.
Leave a FIXME for handling index range validation, which will
need a CPU-side data cache.
Change-Id: Iaf71bc8055869a8561777b6b36f67e376a1d0b81
Reviewed-on: https://chromium-review.googlesource.com/224654
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2/renderer/BufferImpl.h b/src/libGLESv2/renderer/BufferImpl.h
index 790e033..c031eff 100644
--- a/src/libGLESv2/renderer/BufferImpl.h
+++ b/src/libGLESv2/renderer/BufferImpl.h
@@ -23,7 +23,6 @@
virtual ~BufferImpl() { }
virtual gl::Error setData(const void* data, size_t size, GLenum usage) = 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/BufferD3D.cpp b/src/libGLESv2/renderer/d3d/BufferD3D.cpp
index a34ef03..44a41b8 100644
--- a/src/libGLESv2/renderer/d3d/BufferD3D.cpp
+++ b/src/libGLESv2/renderer/d3d/BufferD3D.cpp
@@ -37,6 +37,13 @@
return static_cast<BufferD3D*>(buffer);
}
+BufferD3D *BufferD3D::makeFromBuffer(gl::Buffer *buffer)
+{
+ BufferImpl *impl = buffer->getImplementation();
+ ASSERT(impl);
+ return makeBufferD3D(impl);
+}
+
void BufferD3D::updateSerial()
{
mSerial = mNextSerial++;
diff --git a/src/libGLESv2/renderer/d3d/BufferD3D.h b/src/libGLESv2/renderer/d3d/BufferD3D.h
index 44f14ce..8c03d72 100644
--- a/src/libGLESv2/renderer/d3d/BufferD3D.h
+++ b/src/libGLESv2/renderer/d3d/BufferD3D.h
@@ -12,6 +12,8 @@
#include "libGLESv2/renderer/BufferImpl.h"
#include "libGLESv2/angletypes.h"
+#include <cstdint>
+
namespace rx
{
@@ -26,9 +28,11 @@
virtual ~BufferD3D();
static BufferD3D *makeBufferD3D(BufferImpl *buffer);
+ static BufferD3D *makeFromBuffer(gl::Buffer *buffer);
unsigned int getSerial() const { return mSerial; }
+ virtual gl::Error getData(const uint8_t **outData) = 0;
virtual size_t getSize() const = 0;
virtual bool supportsDirectBinding() const = 0;
virtual Renderer* getRenderer() = 0;
diff --git a/src/libGLESv2/renderer/d3d/TextureD3D.cpp b/src/libGLESv2/renderer/d3d/TextureD3D.cpp
index 51593b3..1028b1b 100644
--- a/src/libGLESv2/renderer/d3d/TextureD3D.cpp
+++ b/src/libGLESv2/renderer/d3d/TextureD3D.cpp
@@ -9,7 +9,7 @@
#include "libGLESv2/renderer/d3d/TextureD3D.h"
#include "libGLESv2/renderer/d3d/TextureStorage.h"
#include "libGLESv2/renderer/d3d/ImageD3D.h"
-#include "libGLESv2/Buffer.h"
+#include "libGLESv2/renderer/d3d/BufferD3D.h"
#include "libGLESv2/Framebuffer.h"
#include "libGLESv2/Texture.h"
#include "libGLESv2/main.h"
@@ -39,8 +39,10 @@
// TODO: this 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.
+ BufferD3D *bufferD3D = BufferD3D::makeBufferD3D(pixelBuffer->getImplementation());
+ ASSERT(bufferD3D);
const uint8_t *bufferData = NULL;
- gl::Error error = pixelBuffer->getImplementation()->getData(&bufferData);
+ gl::Error error = bufferD3D->getData(&bufferData);
if (error.isError())
{
return error;
diff --git a/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h b/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h
index c723b11..25705a7 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 gl::Error getData(const uint8_t **outData);
+ gl::Error getData(const uint8_t **outData) override;
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 a3a78a7..d632429 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
@@ -1163,8 +1163,7 @@
// Get the raw indices for an indexed draw
if (type != GL_NONE && elementArrayBuffer)
{
- gl::Buffer *indexBuffer = elementArrayBuffer;
- BufferImpl *storage = indexBuffer->getImplementation();
+ BufferD3D *storage = BufferD3D::makeFromBuffer(elementArrayBuffer);
intptr_t offset = reinterpret_cast<intptr_t>(indices);
const uint8_t *bufferData = NULL;
@@ -1275,8 +1274,7 @@
// Get the raw indices for an indexed draw
if (type != GL_NONE && elementArrayBuffer)
{
- gl::Buffer *indexBuffer = elementArrayBuffer;
- BufferImpl *storage = indexBuffer->getImplementation();
+ BufferD3D *storage = BufferD3D::makeFromBuffer(elementArrayBuffer);
intptr_t offset = reinterpret_cast<intptr_t>(indices);
const uint8_t *bufferData = NULL;
diff --git a/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp b/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp
index 312c2be..2104bca 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp
@@ -91,7 +91,7 @@
{
if (buffer)
{
- BufferImpl *storage = buffer->getImplementation();
+ BufferD3D *storage = BufferD3D::makeFromBuffer(buffer);
gl::Error error = storage->getData(&input);
if (error.isError())
{
diff --git a/src/libGLESv2/renderer/d3d/d3d9/Buffer9.h b/src/libGLESv2/renderer/d3d/d3d9/Buffer9.h
index a9344ae..2b28a07 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 gl::Error getData(const uint8_t **outData);
+ gl::Error getData(const uint8_t **outData) override;
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 4d22b21..eacfd81 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
@@ -1417,8 +1417,7 @@
// Get the raw indices for an indexed draw
if (type != GL_NONE && elementArrayBuffer)
{
- gl::Buffer *indexBuffer = elementArrayBuffer;
- BufferImpl *storage = indexBuffer->getImplementation();
+ BufferD3D *storage = BufferD3D::makeFromBuffer(elementArrayBuffer);
intptr_t offset = reinterpret_cast<intptr_t>(indices);
const uint8_t *bufferData = NULL;
gl::Error error = storage->getData(&bufferData);
@@ -1620,7 +1619,7 @@
if (elementArrayBuffer)
{
- BufferImpl *storage = elementArrayBuffer->getImplementation();
+ BufferD3D *storage = BufferD3D::makeFromBuffer(elementArrayBuffer);
intptr_t offset = reinterpret_cast<intptr_t>(indices);
const uint8_t *bufferData = NULL;
diff --git a/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp b/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp
index 994b386..3eb0ff8 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp
@@ -10,7 +10,7 @@
#include "libGLESv2/renderer/d3d/d3d9/Renderer9.h"
#include "libGLESv2/renderer/d3d/d3d9/formatutils9.h"
#include "libGLESv2/renderer/vertexconversion.h"
-#include "libGLESv2/renderer/BufferImpl.h"
+#include "libGLESv2/renderer/d3d/BufferD3D.h"
#include "libGLESv2/VertexAttribute.h"
#include "libGLESv2/Buffer.h"
@@ -97,7 +97,8 @@
{
if (buffer)
{
- BufferImpl *storage = buffer->getImplementation();
+ BufferD3D *storage = BufferD3D::makeFromBuffer(buffer);
+ ASSERT(storage);
gl::Error error = storage->getData(&input);
if (error.isError())
{