| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Tests for the Command Buffer Helper. | 5 // Tests for the Command Buffer Helper. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 | 8 |
| 9 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
| 10 #include "gpu/command_buffer/common/command_buffer.h" | 10 #include "gpu/command_buffer/common/command_buffer.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 state_.get_offset = get_offset; | 66 state_.get_offset = get_offset; |
| 67 } | 67 } |
| 68 | 68 |
| 69 virtual int32 CreateTransferBuffer(size_t size, int32 id_request) { | 69 virtual int32 CreateTransferBuffer(size_t size, int32 id_request) { |
| 70 transfer_buffer_.reset(new int8[size]); | 70 transfer_buffer_.reset(new int8[size]); |
| 71 transfer_buffer_buffer_.ptr = transfer_buffer_.get(); | 71 transfer_buffer_buffer_.ptr = transfer_buffer_.get(); |
| 72 transfer_buffer_buffer_.size = size; | 72 transfer_buffer_buffer_.size = size; |
| 73 return kTransferBufferId; | 73 return kTransferBufferId; |
| 74 } | 74 } |
| 75 | 75 |
| 76 virtual void DestroyTransferBuffer(int32) { // NOLINT | 76 virtual void DestroyTransferBuffer(int32 /* id */) { |
| 77 GPU_NOTREACHED(); | 77 GPU_NOTREACHED(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 virtual Buffer GetTransferBuffer(int32 id) { | 80 virtual Buffer GetTransferBuffer(int32 id) { |
| 81 GPU_DCHECK_EQ(id, kTransferBufferId); | 81 GPU_DCHECK_EQ(id, kTransferBufferId); |
| 82 return transfer_buffer_buffer_; | 82 return transfer_buffer_buffer_; |
| 83 } | 83 } |
| 84 | 84 |
| 85 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, | 85 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, |
| 86 size_t size, | 86 size_t size, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 114 State state_; | 114 State state_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 class MockGLES2CommandBuffer : public GLES2MockCommandBufferHelper { | 117 class MockGLES2CommandBuffer : public GLES2MockCommandBufferHelper { |
| 118 public: | 118 public: |
| 119 virtual ~MockGLES2CommandBuffer() { | 119 virtual ~MockGLES2CommandBuffer() { |
| 120 } | 120 } |
| 121 | 121 |
| 122 // This is so we can use all the gmock functions when Flush is called. | 122 // This is so we can use all the gmock functions when Flush is called. |
| 123 MOCK_METHOD1(OnFlush, void(void* result)); | 123 MOCK_METHOD1(OnFlush, void(void* result)); |
| 124 MOCK_METHOD1(DestroyTransferBuffer, void(int32 id)); |
| 124 }; | 125 }; |
| 125 | 126 |
| 126 // GCC requires these declarations, but MSVC requires they not be present | 127 // GCC requires these declarations, but MSVC requires they not be present |
| 127 #ifndef _MSC_VER | 128 #ifndef _MSC_VER |
| 128 const int32 GLES2MockCommandBufferHelper::kTransferBufferId; | 129 const int32 GLES2MockCommandBufferHelper::kTransferBufferId; |
| 129 #endif | 130 #endif |
| 130 | 131 |
| 131 namespace gles2 { | 132 namespace gles2 { |
| 132 | 133 |
| 133 using testing::_; | 134 using testing::_; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 virtual void SetUp() { | 377 virtual void SetUp() { |
| 377 Initialize(true, false); | 378 Initialize(true, false); |
| 378 } | 379 } |
| 379 }; | 380 }; |
| 380 | 381 |
| 381 // GCC requires these declarations, but MSVC requires they not be present | 382 // GCC requires these declarations, but MSVC requires they not be present |
| 382 #ifndef _MSC_VER | 383 #ifndef _MSC_VER |
| 383 const int32 GLES2ImplementationTest::kTransferBufferId; | 384 const int32 GLES2ImplementationTest::kTransferBufferId; |
| 384 #endif | 385 #endif |
| 385 | 386 |
| 386 | |
| 387 TEST_F(GLES2ImplementationTest, ShaderSource) { | 387 TEST_F(GLES2ImplementationTest, ShaderSource) { |
| 388 const uint32 kBucketId = 1; // This id is hardcoded into GLES2Implemenation | 388 const uint32 kBucketId = 1; // This id is hardcoded into GLES2Implemenation |
| 389 const GLuint kShaderId = 456; | 389 const GLuint kShaderId = 456; |
| 390 const char* kString1 = "foobar"; | 390 const char* kString1 = "foobar"; |
| 391 const char* kString2 = "barfoo"; | 391 const char* kString2 = "barfoo"; |
| 392 const size_t kString1Size = strlen(kString1); | 392 const size_t kString1Size = strlen(kString1); |
| 393 const size_t kString2Size = strlen(kString2); | 393 const size_t kString2Size = strlen(kString2); |
| 394 const size_t kString3Size = 1; // Want the NULL; | 394 const size_t kString3Size = 1; // Want the NULL; |
| 395 const size_t kSourceSize = kString1Size + kString2Size + kString3Size; | 395 const size_t kSourceSize = kString1Size + kString2Size + kString3Size; |
| 396 const size_t kPaddedString1Size = RoundToAlignment(kString1Size); | 396 const size_t kPaddedString1Size = RoundToAlignment(kString1Size); |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 expected.set_token.Init(GetNextToken()); | 924 expected.set_token.Init(GetNextToken()); |
| 925 scoped_array<int8> buffer(new int8[kWidth * kHeight * kBytesPerPixel]); | 925 scoped_array<int8> buffer(new int8[kWidth * kHeight * kBytesPerPixel]); |
| 926 | 926 |
| 927 EXPECT_CALL(*command_buffer_, OnFlush(_)) | 927 EXPECT_CALL(*command_buffer_, OnFlush(_)) |
| 928 .Times(1) | 928 .Times(1) |
| 929 .RetiresOnSaturation(); | 929 .RetiresOnSaturation(); |
| 930 | 930 |
| 931 gl_->ReadPixels(0, 0, kWidth, kHeight, kFormat, kType, buffer.get()); | 931 gl_->ReadPixels(0, 0, kWidth, kHeight, kFormat, kType, buffer.get()); |
| 932 } | 932 } |
| 933 | 933 |
| 934 TEST_F(GLES2ImplementationTest, FreeUnusedSharedMemory) { |
| 935 struct Cmds { |
| 936 BufferSubData buf; |
| 937 cmd::SetToken set_token; |
| 938 }; |
| 939 const GLenum kTarget = GL_ELEMENT_ARRAY_BUFFER; |
| 940 const GLintptr kOffset = 15; |
| 941 const GLsizeiptr kSize = 16; |
| 942 |
| 943 uint32 offset = 0; |
| 944 Cmds expected; |
| 945 expected.buf.Init( |
| 946 kTarget, kOffset, kSize, kTransferBufferId, offset); |
| 947 expected.set_token.Init(GetNextToken()); |
| 948 |
| 949 void* mem = gl_->MapBufferSubDataCHROMIUM( |
| 950 kTarget, kOffset, kSize, GL_WRITE_ONLY); |
| 951 ASSERT_TRUE(mem != NULL); |
| 952 gl_->UnmapBufferSubDataCHROMIUM(mem); |
| 953 EXPECT_CALL(*command_buffer_, DestroyTransferBuffer(_))\ |
| 954 .Times(1) |
| 955 .RetiresOnSaturation(); |
| 956 gl_->FreeUnusedSharedMemory(); |
| 957 } |
| 958 |
| 934 TEST_F(GLES2ImplementationTest, MapUnmapBufferSubDataCHROMIUM) { | 959 TEST_F(GLES2ImplementationTest, MapUnmapBufferSubDataCHROMIUM) { |
| 935 struct Cmds { | 960 struct Cmds { |
| 936 BufferSubData buf; | 961 BufferSubData buf; |
| 937 cmd::SetToken set_token; | 962 cmd::SetToken set_token; |
| 938 }; | 963 }; |
| 939 const GLenum kTarget = GL_ELEMENT_ARRAY_BUFFER; | 964 const GLenum kTarget = GL_ELEMENT_ARRAY_BUFFER; |
| 940 const GLintptr kOffset = 15; | 965 const GLintptr kOffset = 15; |
| 941 const GLsizeiptr kSize = 16; | 966 const GLsizeiptr kSize = 16; |
| 942 | 967 |
| 943 uint32 offset = 0; | 968 uint32 offset = 0; |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 expected.destroy_stream.Init(kTextureHandle); | 1861 expected.destroy_stream.Init(kTextureHandle); |
| 1837 | 1862 |
| 1838 gl_->DestroyStreamTextureCHROMIUM(kTextureHandle); | 1863 gl_->DestroyStreamTextureCHROMIUM(kTextureHandle); |
| 1839 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); | 1864 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); |
| 1840 } | 1865 } |
| 1841 | 1866 |
| 1842 } // namespace gles2 | 1867 } // namespace gles2 |
| 1843 } // namespace gpu | 1868 } // namespace gpu |
| 1844 | 1869 |
| 1845 | 1870 |
| OLD | NEW |