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 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 9 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
10 #include "gpu/command_buffer/service/mocks.h" | 10 #include "gpu/command_buffer/service/mocks.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 helper_->Initialize(kBufferSize); | 65 helper_->Initialize(kBufferSize); |
66 } | 66 } |
67 | 67 |
68 int32 GetToken() { | 68 int32 GetToken() { |
69 return command_buffer_->GetState().token; | 69 return command_buffer_->GetState().token; |
70 } | 70 } |
71 | 71 |
72 #if defined(OS_MACOSX) | 72 #if defined(OS_MACOSX) |
73 base::mac::ScopedNSAutoreleasePool autorelease_pool_; | 73 base::mac::ScopedNSAutoreleasePool autorelease_pool_; |
74 #endif | 74 #endif |
75 MessageLoop message_loop_; | 75 base::MessageLoop message_loop_; |
76 scoped_ptr<AsyncAPIMock> api_mock_; | 76 scoped_ptr<AsyncAPIMock> api_mock_; |
77 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 77 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
78 scoped_ptr<CommandBufferService> command_buffer_; | 78 scoped_ptr<CommandBufferService> command_buffer_; |
79 scoped_ptr<GpuScheduler> gpu_scheduler_; | 79 scoped_ptr<GpuScheduler> gpu_scheduler_; |
80 scoped_ptr<CommandBufferHelper> helper_; | 80 scoped_ptr<CommandBufferHelper> helper_; |
81 }; | 81 }; |
82 | 82 |
83 #ifndef _MSC_VER | 83 #ifndef _MSC_VER |
84 const unsigned int MappedMemoryTestBase::kBufferSize; | 84 const unsigned int MappedMemoryTestBase::kBufferSize; |
85 #endif | 85 #endif |
86 | 86 |
87 // Test fixture for MemoryChunk test - Creates a MemoryChunk, using a | 87 // Test fixture for MemoryChunk test - Creates a MemoryChunk, using a |
88 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling | 88 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling |
89 // it directly, not through the RPC mechanism), making sure Noops are ignored | 89 // it directly, not through the RPC mechanism), making sure Noops are ignored |
90 // and SetToken are properly forwarded to the engine. | 90 // and SetToken are properly forwarded to the engine. |
91 class MemoryChunkTest : public MappedMemoryTestBase { | 91 class MemoryChunkTest : public MappedMemoryTestBase { |
92 protected: | 92 protected: |
93 static const int32 kShmId = 123; | 93 static const int32 kShmId = 123; |
94 virtual void SetUp() { | 94 virtual void SetUp() { |
95 MappedMemoryTestBase::SetUp(); | 95 MappedMemoryTestBase::SetUp(); |
96 buffer_.reset(new uint8[kBufferSize]); | 96 buffer_.reset(new uint8[kBufferSize]); |
97 gpu::Buffer buf; | 97 gpu::Buffer buf; |
98 buf.size = kBufferSize; | 98 buf.size = kBufferSize; |
99 buf.ptr = buffer_.get(); | 99 buf.ptr = buffer_.get(); |
100 chunk_.reset(new MemoryChunk(kShmId, buf, helper_.get())); | 100 chunk_.reset(new MemoryChunk(kShmId, buf, helper_.get())); |
101 } | 101 } |
102 | 102 |
103 virtual void TearDown() { | 103 virtual void TearDown() { |
104 // If the GpuScheduler posts any tasks, this forces them to run. | 104 // If the GpuScheduler posts any tasks, this forces them to run. |
105 MessageLoop::current()->RunUntilIdle(); | 105 base::MessageLoop::current()->RunUntilIdle(); |
106 | 106 |
107 MappedMemoryTestBase::TearDown(); | 107 MappedMemoryTestBase::TearDown(); |
108 } | 108 } |
109 | 109 |
110 scoped_ptr<MemoryChunk> chunk_; | 110 scoped_ptr<MemoryChunk> chunk_; |
111 scoped_ptr<uint8[]> buffer_; | 111 scoped_ptr<uint8[]> buffer_; |
112 }; | 112 }; |
113 | 113 |
114 #ifndef _MSC_VER | 114 #ifndef _MSC_VER |
115 const int32 MemoryChunkTest::kShmId; | 115 const int32 MemoryChunkTest::kShmId; |
(...skipping 30 matching lines...) Expand all Loading... |
146 | 146 |
147 class MappedMemoryManagerTest : public MappedMemoryTestBase { | 147 class MappedMemoryManagerTest : public MappedMemoryTestBase { |
148 protected: | 148 protected: |
149 virtual void SetUp() { | 149 virtual void SetUp() { |
150 MappedMemoryTestBase::SetUp(); | 150 MappedMemoryTestBase::SetUp(); |
151 manager_.reset(new MappedMemoryManager(helper_.get())); | 151 manager_.reset(new MappedMemoryManager(helper_.get())); |
152 } | 152 } |
153 | 153 |
154 virtual void TearDown() { | 154 virtual void TearDown() { |
155 // If the GpuScheduler posts any tasks, this forces them to run. | 155 // If the GpuScheduler posts any tasks, this forces them to run. |
156 MessageLoop::current()->RunUntilIdle(); | 156 base::MessageLoop::current()->RunUntilIdle(); |
157 manager_.reset(); | 157 manager_.reset(); |
158 MappedMemoryTestBase::TearDown(); | 158 MappedMemoryTestBase::TearDown(); |
159 } | 159 } |
160 | 160 |
161 scoped_ptr<MappedMemoryManager> manager_; | 161 scoped_ptr<MappedMemoryManager> manager_; |
162 }; | 162 }; |
163 | 163 |
164 TEST_F(MappedMemoryManagerTest, Basic) { | 164 TEST_F(MappedMemoryManagerTest, Basic) { |
165 const unsigned int kSize = 1024; | 165 const unsigned int kSize = 1024; |
166 // Check we can alloc. | 166 // Check we can alloc. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 ASSERT_TRUE(mem3); | 299 ASSERT_TRUE(mem3); |
300 EXPECT_NE(-1, id1); | 300 EXPECT_NE(-1, id1); |
301 EXPECT_EQ(id1, id2); | 301 EXPECT_EQ(id1, id2); |
302 EXPECT_NE(id2, id3); | 302 EXPECT_NE(id2, id3); |
303 EXPECT_EQ(0u, offset1); | 303 EXPECT_EQ(0u, offset1); |
304 EXPECT_EQ(kSize, offset2); | 304 EXPECT_EQ(kSize, offset2); |
305 EXPECT_EQ(0u, offset3); | 305 EXPECT_EQ(0u, offset3); |
306 } | 306 } |
307 | 307 |
308 } // namespace gpu | 308 } // namespace gpu |
OLD | NEW |