diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-05 00:24:58 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-05 00:24:58 +0000 |
commit | d7f0642692c2ac6de15cd1e713e0c88dd740b58e (patch) | |
tree | 43a5c7a0b91b538933f115a16a6618f6d411a693 /gpu/command_buffer | |
parent | 8ba903e43de0e0a0953aa16b878c6279931fffb9 (diff) | |
download | chromium_src-d7f0642692c2ac6de15cd1e713e0c88dd740b58e.zip chromium_src-d7f0642692c2ac6de15cd1e713e0c88dd740b58e.tar.gz chromium_src-d7f0642692c2ac6de15cd1e713e0c88dd740b58e.tar.bz2 |
Remove support for client side arrays from client side gpu
code used by Chromium and WebGL so that you can't use it
by accident. It's stil enabled for Pepper, the conformance
tests and the unit tests.
Note that bug 71717 was a bug in WebGL. The same call to
glDrawElements with the same parameters would have also
crashed real OpenGL. The reason it didn't with
--in-process-webgl is because some checks were used
with that flag that were not without. Mo is fixing that
side.
Also, I made it so the the GLES2Implementation class
is always the same. Otherwise code calling it needed
to have the same flags.
BUG=71717
TEST=none
Review URL: http://codereview.chromium.org/6410092
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73878 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu/command_buffer')
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation.cc | 59 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation.h | 74 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation_unittest.cc | 12 |
3 files changed, 51 insertions, 94 deletions
diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index 77dee21..0d5cd70 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -10,6 +10,10 @@ #include "../common/gles2_cmd_utils.h" #include "../common/id_allocator.h" +#if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) +#define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS +#endif + namespace gpu { namespace gles2 { @@ -18,12 +22,6 @@ static GLuint ToGLuint(const void* ptr) { return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); } -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) - -static GLsizei RoundUpToMultipleOf4(GLsizei size) { - return (size + 3) & ~3; -} - // An id handler for non-shared ids. class NonSharedIdHandler : public IdHandlerInterface { public: @@ -117,6 +115,10 @@ class SharedIdHandler : public IdHandlerInterface { id_namespaces::IdNamespaces id_namespace_; }; +static GLsizei RoundUpToMultipleOf4(GLsizei size) { + return (size + 3) & ~3; +} + // This class tracks VertexAttribPointers and helps emulate client side buffers. // // The way client side buffers work is we shadow all the Vertex Attribs so we @@ -413,9 +415,6 @@ class ClientSideBufferHelper { DISALLOW_COPY_AND_ASSIGN(ClientSideBufferHelper); }; -#endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) - - #if !defined(_MSC_VER) const size_t GLES2Implementation::kMaxSizeOfSimpleResult; #endif @@ -439,12 +438,10 @@ GLES2Implementation::GLES2Implementation( transfer_buffer_id_(transfer_buffer_id), pack_alignment_(4), unpack_alignment_(4), -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) bound_array_buffer_id_(0), bound_element_array_buffer_id_(0), client_side_array_id_(0), client_side_element_array_id_(0), -#endif error_bits_(0) { // Allocate space for simple GL results. result_buffer_ = transfer_buffer; @@ -471,7 +468,7 @@ GLES2Implementation::GLES2Implementation( texture_id_handler_.reset(new NonSharedIdHandler()); } -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) GLint max_vertex_attribs; GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs); @@ -486,7 +483,9 @@ GLES2Implementation::GLES2Implementation( } GLES2Implementation::~GLES2Implementation() { +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) DeleteBuffers(arraysize(reserved_ids_), &reserved_ids_[0]); +#endif } void GLES2Implementation::WaitForCmd() { @@ -622,7 +621,7 @@ void GLES2Implementation::DrawElements( if (count == 0) { return; } -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) bool have_client_side = client_side_buffer_helper_->HaveEnabledClientSideBuffers(); GLsizei num_elements = 0; @@ -744,12 +743,12 @@ void GLES2Implementation::BindAttribLocation( void GLES2Implementation::GetVertexAttribPointerv( GLuint index, GLenum pname, void** ptr) { -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) // If it's a client side buffer the client has the data. if (client_side_buffer_helper_->GetAttribPointer(index, pname, ptr)) { return; } -#endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) +#endif // defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) typedef gles2::GetVertexAttribPointerv::Result Result; Result* result = GetResultAs<Result*>(); @@ -831,7 +830,7 @@ void GLES2Implementation::PixelStorei(GLenum pname, GLint param) { void GLES2Implementation::VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr) { -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) // Record the info on the client side. client_side_buffer_helper_->SetAttribPointer( bound_array_buffer_id_, index, size, type, normalized, stride, ptr); @@ -840,10 +839,10 @@ void GLES2Implementation::VertexAttribPointer( helper_->VertexAttribPointer(index, size, type, normalized, stride, ToGLuint(ptr)); } -#else // !defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) +#else // !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) helper_->VertexAttribPointer(index, size, type, normalized, stride, ToGLuint(ptr)); -#endif // !defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) +#endif // !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) } void GLES2Implementation::ShaderSource( @@ -1359,7 +1358,7 @@ void GLES2Implementation::ReadPixels( } } -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) bool GLES2Implementation::IsBufferReservedId(GLuint id) { for (size_t ii = 0; ii < arraysize(reserved_ids_); ++ii) { if (id == reserved_ids_[ii]) { @@ -1374,14 +1373,13 @@ bool GLES2Implementation::IsBufferReservedId(GLuint) { // NOLINT } #endif -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) - void GLES2Implementation::BindBuffer(GLenum target, GLuint buffer) { if (IsBufferReservedId(buffer)) { SetGLError(GL_INVALID_OPERATION, "glBindBuffer: reserved buffer id"); return; } buffer_id_handler_->MarkAsUsedForBind(buffer); +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) switch (target) { case GL_ARRAY_BUFFER: bound_array_buffer_id_ = buffer; @@ -1392,6 +1390,7 @@ void GLES2Implementation::BindBuffer(GLenum target, GLuint buffer) { default: break; } +#endif helper_->BindBuffer(target, buffer); } @@ -1401,6 +1400,7 @@ void GLES2Implementation::DeleteBuffers(GLsizei n, const GLuint* buffers) { return; } buffer_id_handler_->FreeIds(n, buffers); +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) for (GLsizei ii = 0; ii < n; ++ii) { if (buffers[ii] == bound_array_buffer_id_) { bound_array_buffer_id_ = 0; @@ -1409,6 +1409,7 @@ void GLES2Implementation::DeleteBuffers(GLsizei n, const GLuint* buffers) { bound_element_array_buffer_id_ = 0; } } +#endif // TODO(gman): compute the number of buffers we can delete in 1 call // based on the size of command buffer and the limit of argument size // for comments then loop to delete all the buffers. The same needs to @@ -1417,12 +1418,16 @@ void GLES2Implementation::DeleteBuffers(GLsizei n, const GLuint* buffers) { } void GLES2Implementation::DisableVertexAttribArray(GLuint index) { +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) client_side_buffer_helper_->SetAttribEnable(index, false); +#endif helper_->DisableVertexAttribArray(index); } void GLES2Implementation::EnableVertexAttribArray(GLuint index) { +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) client_side_buffer_helper_->SetAttribEnable(index, true); +#endif helper_->EnableVertexAttribArray(index); } @@ -1431,19 +1436,24 @@ void GLES2Implementation::DrawArrays(GLenum mode, GLint first, GLsizei count) { SetGLError(GL_INVALID_VALUE, "glDrawArrays: count < 0"); return; } +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) bool have_client_side = client_side_buffer_helper_->HaveEnabledClientSideBuffers(); if (have_client_side) { client_side_buffer_helper_->SetupSimualtedClientSideBuffers( this, helper_, first + count); } +#endif helper_->DrawArrays(mode, first, count); +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) if (have_client_side) { // Restore the user's current binding. helper_->BindBuffer(GL_ARRAY_BUFFER, bound_array_buffer_id_); } +#endif } +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) bool GLES2Implementation::GetVertexAttribHelper( GLuint index, GLenum pname, uint32* param) { const ClientSideBufferHelper::VertexAttribInfo* info = @@ -1479,14 +1489,17 @@ bool GLES2Implementation::GetVertexAttribHelper( } return true; } +#endif // GLES2_SUPPORT_CLIENT_SIDE_ARRAYS void GLES2Implementation::GetVertexAttribfv( GLuint index, GLenum pname, GLfloat* params) { +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) uint32 value = 0; if (GetVertexAttribHelper(index, pname, &value)) { *params = static_cast<float>(value); return; } +#endif typedef GetVertexAttribfv::Result Result; Result* result = GetResultAs<Result*>(); result->SetNumResults(0); @@ -1498,11 +1511,13 @@ void GLES2Implementation::GetVertexAttribfv( void GLES2Implementation::GetVertexAttribiv( GLuint index, GLenum pname, GLint* params) { +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) uint32 value = 0; if (GetVertexAttribHelper(index, pname, &value)) { *params = value; return; } +#endif typedef GetVertexAttribiv::Result Result; Result* result = GetResultAs<Result*>(); result->SetNumResults(0); @@ -1525,8 +1540,6 @@ GLboolean GLES2Implementation::CommandBufferEnableCHROMIUM( return *result; } -#endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) - void* GLES2Implementation::MapBufferSubDataCHROMIUM( GLuint target, GLintptr offset, GLsizeiptr size, GLenum access) { // NOTE: target is NOT checked because the service will check it diff --git a/gpu/command_buffer/client/gles2_implementation.h b/gpu/command_buffer/client/gles2_implementation.h index f3f202e..1017ef1 100644 --- a/gpu/command_buffer/client/gles2_implementation.h +++ b/gpu/command_buffer/client/gles2_implementation.h @@ -18,8 +18,6 @@ #include "../client/gles2_cmd_helper.h" #include "../client/ring_buffer.h" -#define GLES2_SUPPORT_CLIENT_SIDE_BUFFERS 1 - // TODO(gman): replace with logging code expansion. #define GPU_CLIENT_LOG(args) @@ -94,67 +92,13 @@ class GLES2Implementation { // this file instead of having to edit some template or the code generator. #include "../client/gles2_implementation_autogen.h" - #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) - void BindBuffer(GLenum target, GLuint buffer); - void DeleteBuffers(GLsizei n, const GLuint* buffers); - void DisableVertexAttribArray(GLuint index); - void DrawArrays(GLenum mode, GLint first, GLsizei count); - void EnableVertexAttribArray(GLuint index); - void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params); - void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params); - #else - void BindBuffer(GLenum target, GLuint buffer) { - if (IsReservedId(buffer)) { - SetGLError(GL_INVALID_OPERATION, "glBindBuffer: reserved buffer id"); - return; - } - if (buffer != 0) { - id_allocator_.MarkAsUsed(buffer); - } - helper_->BindBuffer(target, buffer); - } - - void DeleteBuffers(GLsizei n, const GLuint* buffers) { - FreeIds(n, buffers); - helper_->DeleteBuffersImmediate(n, buffers); - } - - void DisableVertexAttribArray(GLuint index) { - helper_->DisableVertexAttribArray(index); - } - - void DrawArrays(GLenum mode, GLint first, GLsizei count) { - if (count < 0) { - SetGLError(GL_INVALID_VALUE, "glDrawArrays: count < 0"); - return; - } - helper_->DrawArrays(mode, first, count); - } - - void EnableVertexAttribArray(GLuint index) { - helper_->EnableVertexAttribArray(index); - } - - void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params) { - typedef GetVertexAttribfv::Result Result; - Result* result = GetResultAs<Result*>(); - result->SetNumResults(0); - helper_->GetVertexAttribfv( - index, pname, result_shm_id(), result_shm_offset()); - WaitForCmd(); - result->CopyResult(params); - } - - void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params) { - typedef GetVertexAttribiv::Result Result; - Result* result = GetResultAs<Result*>(); - result->SetNumResults(0); - helper_->GetVertexAttribiv( - index, pname, result_shm_id(), result_shm_offset()); - WaitForCmd(); - result->CopyResult(params); - } - #endif + void BindBuffer(GLenum target, GLuint buffer); + void DeleteBuffers(GLsizei n, const GLuint* buffers); + void DisableVertexAttribArray(GLuint index); + void DrawArrays(GLenum mode, GLint first, GLsizei count); + void EnableVertexAttribArray(GLuint index); + void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params); + void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params); GLuint MakeTextureId() { GLuint id; @@ -329,14 +273,12 @@ class GLES2Implementation { bool IsRenderbufferReservedId(GLuint id) { return false; } bool IsTextureReservedId(GLuint id) { return false; } -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) // Helper for GetVertexAttrib bool GetVertexAttribHelper(GLuint index, GLenum pname, uint32* param); // Asks the service for the max index in an element array buffer. GLsizei GetMaxIndexInElementArrayBuffer( GLuint buffer_id, GLsizei count, GLenum type, GLuint offset); -#endif GLES2Util util_; GLES2CmdHelper* helper_; @@ -359,7 +301,6 @@ class GLES2Implementation { // unpack alignment as last set by glPixelStorei GLint unpack_alignment_; -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) // The currently bound array buffer. GLuint bound_array_buffer_id_; @@ -375,7 +316,6 @@ class GLES2Implementation { scoped_ptr<ClientSideBufferHelper> client_side_buffer_helper_; GLuint reserved_ids_[2]; -#endif // Current GL error bits. uint32 error_bits_; diff --git a/gpu/command_buffer/client/gles2_implementation_unittest.cc b/gpu/command_buffer/client/gles2_implementation_unittest.cc index dabcba3..aa187e0 100644 --- a/gpu/command_buffer/client/gles2_implementation_unittest.cc +++ b/gpu/command_buffer/client/gles2_implementation_unittest.cc @@ -10,6 +10,10 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/gmock/include/gmock/gmock.h" +#if !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) +#define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS +#endif + namespace gpu { class GLES2MockCommandBufferHelper : public CommandBuffer { @@ -181,7 +185,7 @@ class GLES2ImplementationTest : public testing::Test { helper_.reset(new GLES2CmdHelper(command_buffer_.get())); helper_->Initialize(kCommandBufferSizeBytes); - #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) + #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) EXPECT_CALL(*command_buffer_, OnFlush(_)) .WillOnce(SetMemory(SizedResultHelper<GLint>(kMaxVertexAttribs))) .RetiresOnSaturation(); @@ -313,7 +317,7 @@ TEST_F(GLES2ImplementationTest, GetShaderSource) { EXPECT_EQ(buf[sizeof(kString)], kBad); } -#if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) +#if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) TEST_F(GLES2ImplementationTest, DrawArraysClientSideBuffers) { static const float verts[][4] = { @@ -685,8 +689,6 @@ TEST_F(GLES2ImplementationTest, GetVertexAttrib) { EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); } -#endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) - TEST_F(GLES2ImplementationTest, ReservedIds) { // Only the get error command should be issued. struct Cmds { @@ -711,6 +713,8 @@ TEST_F(GLES2ImplementationTest, ReservedIds) { EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); } +#endif // defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) + TEST_F(GLES2ImplementationTest, ReadPixels2Reads) { struct Cmds { ReadPixels read1; |