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 // Tests for the BufferTracker. | 5 // Tests for the BufferTracker. |
6 | 6 |
7 #include "gpu/command_buffer/client/buffer_tracker.h" | 7 #include "gpu/command_buffer/client/buffer_tracker.h" |
8 | 8 |
9 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 void set_context_lost(bool context_lost) { | 37 void set_context_lost(bool context_lost) { |
38 context_lost_ = context_lost; | 38 context_lost_ = context_lost; |
39 } | 39 } |
40 | 40 |
41 private: | 41 private: |
42 bool context_lost_; | 42 bool context_lost_; |
43 }; | 43 }; |
44 | 44 |
45 namespace { | |
46 void EmptyPoll() { | |
47 } | |
48 } | |
49 | |
50 class BufferTrackerTest : public testing::Test { | 45 class BufferTrackerTest : public testing::Test { |
51 protected: | 46 protected: |
52 static const int32 kNumCommandEntries = 400; | 47 static const int32 kNumCommandEntries = 400; |
53 static const int32 kCommandBufferSizeBytes = | 48 static const int32 kCommandBufferSizeBytes = |
54 kNumCommandEntries * sizeof(CommandBufferEntry); | 49 kNumCommandEntries * sizeof(CommandBufferEntry); |
55 | 50 |
56 virtual void SetUp() { | 51 virtual void SetUp() { |
57 command_buffer_.reset(new MockClientCommandBufferImpl()); | 52 command_buffer_.reset(new MockClientCommandBufferImpl()); |
58 helper_.reset(new GLES2CmdHelper(command_buffer_.get())); | 53 helper_.reset(new GLES2CmdHelper(command_buffer_.get())); |
59 helper_->Initialize(kCommandBufferSizeBytes); | 54 helper_->Initialize(kCommandBufferSizeBytes); |
60 mapped_memory_.reset(new MappedMemoryManager( | 55 mapped_memory_.reset(new MappedMemoryManager( |
61 helper_.get(), base::Bind(&EmptyPoll), MappedMemoryManager::kNoLimit)); | 56 helper_.get(), MappedMemoryManager::kNoLimit)); |
62 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); | 57 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); |
63 } | 58 } |
64 | 59 |
65 virtual void TearDown() { | 60 virtual void TearDown() { |
66 buffer_tracker_.reset(); | 61 buffer_tracker_.reset(); |
67 mapped_memory_.reset(); | 62 mapped_memory_.reset(); |
68 helper_.reset(); | 63 helper_.reset(); |
69 command_buffer_.reset(); | 64 command_buffer_.reset(); |
70 } | 65 } |
71 | 66 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // Check mapped memory address. | 120 // Check mapped memory address. |
126 EXPECT_EQ(64u, buffer->size()); | 121 EXPECT_EQ(64u, buffer->size()); |
127 // Check mapped memory address. | 122 // Check mapped memory address. |
128 EXPECT_TRUE(buffer->address() == NULL); | 123 EXPECT_TRUE(buffer->address() == NULL); |
129 // Check no shared memory was allocated. | 124 // Check no shared memory was allocated. |
130 EXPECT_EQ(0lu, mapped_memory_->num_chunks()); | 125 EXPECT_EQ(0lu, mapped_memory_->num_chunks()); |
131 // Check we can delete the buffer. | 126 // Check we can delete the buffer. |
132 buffer_tracker_->RemoveBuffer(kId); | 127 buffer_tracker_->RemoveBuffer(kId); |
133 } | 128 } |
134 | 129 |
135 TEST_F(BufferTrackerTest, Unmanage) { | |
136 const GLuint kId = 123; | |
137 const GLsizeiptr size = 64; | |
138 | |
139 BufferTracker::Buffer* buffer = buffer_tracker_->CreateBuffer(kId, size); | |
140 ASSERT_TRUE(buffer != NULL); | |
141 EXPECT_EQ(mapped_memory_->bytes_in_use(), static_cast<size_t>(size)); | |
142 | |
143 void* mem = buffer->address(); | |
144 buffer_tracker_->Unmanage(buffer); | |
145 buffer_tracker_->RemoveBuffer(kId); | |
146 EXPECT_EQ(mapped_memory_->bytes_in_use(), static_cast<size_t>(size)); | |
147 | |
148 mapped_memory_->Free(mem); | |
149 EXPECT_EQ(mapped_memory_->bytes_in_use(), static_cast<size_t>(0)); | |
150 } | |
151 | |
152 } // namespace gles2 | 130 } // namespace gles2 |
153 } // namespace gpu | 131 } // namespace gpu |
OLD | NEW |