diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-13 18:46:45 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-13 18:46:45 +0000 |
commit | e47cbd27e8fefd50693f835675a7f1700a566821 (patch) | |
tree | e2c46bc605735b85b16eea241adc009786b55d8c /gpu | |
parent | 4b01fa36f20c749eae3ac13ac2665c2d0591568b (diff) | |
download | chromium_src-e47cbd27e8fefd50693f835675a7f1700a566821.zip chromium_src-e47cbd27e8fefd50693f835675a7f1700a566821.tar.gz chromium_src-e47cbd27e8fefd50693f835675a7f1700a566821.tar.bz2 |
Fix off by one error in glGetShaderiv for the size
of the shader source.
TEST=added webgl conformance test
BUG=66494
Review URL: http://codereview.chromium.org/5719003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69024 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation_unittest.cc | 49 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder.cc | 2 |
2 files changed, 50 insertions, 1 deletions
diff --git a/gpu/command_buffer/client/gles2_implementation_unittest.cc b/gpu/command_buffer/client/gles2_implementation_unittest.cc index 414183c..d431851 100644 --- a/gpu/command_buffer/client/gles2_implementation_unittest.cc +++ b/gpu/command_buffer/client/gles2_implementation_unittest.cc @@ -113,6 +113,10 @@ ACTION_P(SetMemory, obj) { memcpy(arg0, &obj, sizeof(obj)); } +ACTION_P2(SetMemoryAtOffset, offset, obj) { + memcpy(static_cast<char*>(arg0) + offset, &obj, sizeof(obj)); +} + // Used to help set the transfer buffer result to SizedResult of a single value. template <typename T> class SizedResultHelper { @@ -142,6 +146,13 @@ struct FourFloats { float w; }; +#pragma pack(push, 1) +// Struct that holds 7 characters. +struct Str7 { + char str[7]; +}; +#pragma pack(pop) + // Test fixture for CommandBufferHelper test. class GLES2ImplementationTest : public testing::Test { protected: @@ -260,6 +271,44 @@ TEST_F(GLES2ImplementationTest, ShaderSource) { EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); } +TEST_F(GLES2ImplementationTest, GetShaderSource) { + const uint32 kBucketId = 1; // This id is hardcoded into GLES2Implemenation + const GLuint kShaderId = 456; + const Str7 kString = {"foobar"}; + const char kBad = 0x12; + struct Cmds { + cmd::SetBucketSize set_bucket_size1; + GetShaderSource get_shader_source; + cmd::GetBucketSize get_bucket_size; + cmd::GetBucketData get_bucket_data; + cmd::SetToken set_token1; + cmd::SetBucketSize set_bucket_size2; + }; + int32 token = 1; + uint32 offset = GLES2Implementation::kStartingOffset; + Cmds expected; + expected.set_bucket_size1.Init(kBucketId, 0); + expected.get_shader_source.Init(kShaderId, kBucketId); + expected.get_bucket_size.Init(kBucketId, kTransferBufferId, 0); + expected.get_bucket_data.Init( + kBucketId, 0, sizeof(kString), kTransferBufferId, offset); + expected.set_token1.Init(token++); + expected.set_bucket_size2.Init(kBucketId, 0); + char buf[sizeof(kString) + 1]; + memset(buf, kBad, sizeof(buf)); + + EXPECT_CALL(*command_buffer_, OnFlush(_)) + .WillOnce(SetMemory(uint32(sizeof(kString)))) + .WillOnce(SetMemoryAtOffset(offset, kString)) + .RetiresOnSaturation(); + + GLsizei length = 0; + gl_->GetShaderSource(kShaderId, sizeof(buf), &length, buf); + EXPECT_EQ(sizeof(kString) - 1, static_cast<size_t>(length)); + EXPECT_STREQ(kString.str, buf); + EXPECT_EQ(buf[sizeof(kString)], kBad); +} + #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) TEST_F(GLES2ImplementationTest, DrawArraysClientSideBuffers) { diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 5d373fc..4d13583 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -4324,7 +4324,7 @@ void GLES2DecoderImpl::DoGetShaderiv( } switch (pname) { case GL_SHADER_SOURCE_LENGTH: - *params = info->source().size(); + *params = info->source().size() + 1; return; case GL_COMPILE_STATUS: *params = info->IsValid(); |