| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "gpu/command_buffer/client/mapped_memory.h" | 5 #include "gpu/command_buffer/client/mapped_memory.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <memory> |
| 12 |
| 11 #include "base/bind.h" | 13 #include "base/bind.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 15 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| 15 #include "gpu/command_buffer/service/command_buffer_service.h" | 16 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 16 #include "gpu/command_buffer/service/command_executor.h" | 17 #include "gpu/command_buffer/service/command_executor.h" |
| 17 #include "gpu/command_buffer/service/mocks.h" | 18 #include "gpu/command_buffer/service/mocks.h" |
| 18 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 19 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace gpu { | 22 namespace gpu { |
| 22 | 23 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 &CommandExecutor::SetGetBuffer, base::Unretained(executor_.get()))); | 62 &CommandExecutor::SetGetBuffer, base::Unretained(executor_.get()))); |
| 62 | 63 |
| 63 api_mock_->set_engine(executor_.get()); | 64 api_mock_->set_engine(executor_.get()); |
| 64 | 65 |
| 65 helper_.reset(new CommandBufferHelper(command_buffer_.get())); | 66 helper_.reset(new CommandBufferHelper(command_buffer_.get())); |
| 66 helper_->Initialize(kBufferSize); | 67 helper_->Initialize(kBufferSize); |
| 67 } | 68 } |
| 68 | 69 |
| 69 int32_t GetToken() { return command_buffer_->GetLastState().token; } | 70 int32_t GetToken() { return command_buffer_->GetLastState().token; } |
| 70 | 71 |
| 71 scoped_ptr<AsyncAPIMock> api_mock_; | 72 std::unique_ptr<AsyncAPIMock> api_mock_; |
| 72 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 73 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 73 scoped_ptr<CommandBufferService> command_buffer_; | 74 std::unique_ptr<CommandBufferService> command_buffer_; |
| 74 scoped_ptr<CommandExecutor> executor_; | 75 std::unique_ptr<CommandExecutor> executor_; |
| 75 scoped_ptr<CommandBufferHelper> helper_; | 76 std::unique_ptr<CommandBufferHelper> helper_; |
| 76 base::MessageLoop message_loop_; | 77 base::MessageLoop message_loop_; |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 #ifndef _MSC_VER | 80 #ifndef _MSC_VER |
| 80 const unsigned int MappedMemoryTestBase::kBufferSize; | 81 const unsigned int MappedMemoryTestBase::kBufferSize; |
| 81 #endif | 82 #endif |
| 82 | 83 |
| 83 // Test fixture for MemoryChunk test - Creates a MemoryChunk, using a | 84 // Test fixture for MemoryChunk test - Creates a MemoryChunk, using a |
| 84 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling | 85 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling |
| 85 // it directly, not through the RPC mechanism), making sure Noops are ignored | 86 // it directly, not through the RPC mechanism), making sure Noops are ignored |
| 86 // and SetToken are properly forwarded to the engine. | 87 // and SetToken are properly forwarded to the engine. |
| 87 class MemoryChunkTest : public MappedMemoryTestBase { | 88 class MemoryChunkTest : public MappedMemoryTestBase { |
| 88 protected: | 89 protected: |
| 89 static const int32_t kShmId = 123; | 90 static const int32_t kShmId = 123; |
| 90 void SetUp() override { | 91 void SetUp() override { |
| 91 MappedMemoryTestBase::SetUp(); | 92 MappedMemoryTestBase::SetUp(); |
| 92 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 93 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
| 93 shared_memory->CreateAndMapAnonymous(kBufferSize); | 94 shared_memory->CreateAndMapAnonymous(kBufferSize); |
| 94 buffer_ = MakeBufferFromSharedMemory(std::move(shared_memory), kBufferSize); | 95 buffer_ = MakeBufferFromSharedMemory(std::move(shared_memory), kBufferSize); |
| 95 chunk_.reset(new MemoryChunk(kShmId, buffer_, helper_.get())); | 96 chunk_.reset(new MemoryChunk(kShmId, buffer_, helper_.get())); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void TearDown() override { | 99 void TearDown() override { |
| 99 // If the CommandExecutor posts any tasks, this forces them to run. | 100 // If the CommandExecutor posts any tasks, this forces them to run. |
| 100 base::MessageLoop::current()->RunUntilIdle(); | 101 base::MessageLoop::current()->RunUntilIdle(); |
| 101 | 102 |
| 102 MappedMemoryTestBase::TearDown(); | 103 MappedMemoryTestBase::TearDown(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 uint8_t* buffer_memory() { return static_cast<uint8_t*>(buffer_->memory()); } | 106 uint8_t* buffer_memory() { return static_cast<uint8_t*>(buffer_->memory()); } |
| 106 | 107 |
| 107 scoped_ptr<MemoryChunk> chunk_; | 108 std::unique_ptr<MemoryChunk> chunk_; |
| 108 scoped_refptr<gpu::Buffer> buffer_; | 109 scoped_refptr<gpu::Buffer> buffer_; |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 #ifndef _MSC_VER | 112 #ifndef _MSC_VER |
| 112 const int32_t MemoryChunkTest::kShmId; | 113 const int32_t MemoryChunkTest::kShmId; |
| 113 #endif | 114 #endif |
| 114 | 115 |
| 115 TEST_F(MemoryChunkTest, Basic) { | 116 TEST_F(MemoryChunkTest, Basic) { |
| 116 const unsigned int kSize = 16; | 117 const unsigned int kSize = 16; |
| 117 EXPECT_EQ(kShmId, chunk_->shm_id()); | 118 EXPECT_EQ(kShmId, chunk_->shm_id()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 new MappedMemoryManager(helper_.get(), MappedMemoryManager::kNoLimit)); | 156 new MappedMemoryManager(helper_.get(), MappedMemoryManager::kNoLimit)); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void TearDown() override { | 159 void TearDown() override { |
| 159 // If the CommandExecutor posts any tasks, this forces them to run. | 160 // If the CommandExecutor posts any tasks, this forces them to run. |
| 160 base::MessageLoop::current()->RunUntilIdle(); | 161 base::MessageLoop::current()->RunUntilIdle(); |
| 161 manager_.reset(); | 162 manager_.reset(); |
| 162 MappedMemoryTestBase::TearDown(); | 163 MappedMemoryTestBase::TearDown(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 scoped_ptr<MappedMemoryManager> manager_; | 166 std::unique_ptr<MappedMemoryManager> manager_; |
| 166 }; | 167 }; |
| 167 | 168 |
| 168 TEST_F(MappedMemoryManagerTest, Basic) { | 169 TEST_F(MappedMemoryManagerTest, Basic) { |
| 169 const unsigned int kSize = 1024; | 170 const unsigned int kSize = 1024; |
| 170 // Check we can alloc. | 171 // Check we can alloc. |
| 171 int32_t id1 = -1; | 172 int32_t id1 = -1; |
| 172 unsigned int offset1 = 0xFFFFFFFFU; | 173 unsigned int offset1 = 0xFFFFFFFFU; |
| 173 void* mem1 = manager_->Alloc(kSize, &id1, &offset1); | 174 void* mem1 = manager_->Alloc(kSize, &id1, &offset1); |
| 174 ASSERT_TRUE(mem1); | 175 ASSERT_TRUE(mem1); |
| 175 EXPECT_NE(-1, id1); | 176 EXPECT_NE(-1, id1); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 void* mem4 = manager_->Alloc(kLimit, &id4, &offset4); | 428 void* mem4 = manager_->Alloc(kLimit, &id4, &offset4); |
| 428 ASSERT_TRUE(mem4); | 429 ASSERT_TRUE(mem4); |
| 429 EXPECT_EQ(id2, id4); | 430 EXPECT_EQ(id2, id4); |
| 430 EXPECT_EQ(offset2, offset4); | 431 EXPECT_EQ(offset2, offset4); |
| 431 | 432 |
| 432 manager_->Free(mem1); | 433 manager_->Free(mem1); |
| 433 manager_->Free(mem4); | 434 manager_->Free(mem4); |
| 434 } | 435 } |
| 435 | 436 |
| 436 } // namespace gpu | 437 } // namespace gpu |
| OLD | NEW |