| 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 |
| 45 class BufferTrackerTest : public testing::Test { | 50 class BufferTrackerTest : public testing::Test { |
| 46 protected: | 51 protected: |
| 47 static const int32 kNumCommandEntries = 400; | 52 static const int32 kNumCommandEntries = 400; |
| 48 static const int32 kCommandBufferSizeBytes = | 53 static const int32 kCommandBufferSizeBytes = |
| 49 kNumCommandEntries * sizeof(CommandBufferEntry); | 54 kNumCommandEntries * sizeof(CommandBufferEntry); |
| 50 | 55 |
| 51 virtual void SetUp() { | 56 virtual void SetUp() { |
| 52 command_buffer_.reset(new MockClientCommandBufferImpl()); | 57 command_buffer_.reset(new MockClientCommandBufferImpl()); |
| 53 helper_.reset(new GLES2CmdHelper(command_buffer_.get())); | 58 helper_.reset(new GLES2CmdHelper(command_buffer_.get())); |
| 54 helper_->Initialize(kCommandBufferSizeBytes); | 59 helper_->Initialize(kCommandBufferSizeBytes); |
| 55 mapped_memory_.reset(new MappedMemoryManager( | 60 mapped_memory_.reset(new MappedMemoryManager( |
| 56 helper_.get(), MappedMemoryManager::kNoLimit)); | 61 helper_.get(), base::Bind(&EmptyPoll), MappedMemoryManager::kNoLimit)); |
| 57 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); | 62 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); |
| 58 } | 63 } |
| 59 | 64 |
| 60 virtual void TearDown() { | 65 virtual void TearDown() { |
| 61 buffer_tracker_.reset(); | 66 buffer_tracker_.reset(); |
| 62 mapped_memory_.reset(); | 67 mapped_memory_.reset(); |
| 63 helper_.reset(); | 68 helper_.reset(); |
| 64 command_buffer_.reset(); | 69 command_buffer_.reset(); |
| 65 } | 70 } |
| 66 | 71 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // Check mapped memory address. | 125 // Check mapped memory address. |
| 121 EXPECT_EQ(64u, buffer->size()); | 126 EXPECT_EQ(64u, buffer->size()); |
| 122 // Check mapped memory address. | 127 // Check mapped memory address. |
| 123 EXPECT_TRUE(buffer->address() == NULL); | 128 EXPECT_TRUE(buffer->address() == NULL); |
| 124 // Check no shared memory was allocated. | 129 // Check no shared memory was allocated. |
| 125 EXPECT_EQ(0lu, mapped_memory_->num_chunks()); | 130 EXPECT_EQ(0lu, mapped_memory_->num_chunks()); |
| 126 // Check we can delete the buffer. | 131 // Check we can delete the buffer. |
| 127 buffer_tracker_->RemoveBuffer(kId); | 132 buffer_tracker_->RemoveBuffer(kId); |
| 128 } | 133 } |
| 129 | 134 |
| 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 |
| 130 } // namespace gles2 | 152 } // namespace gles2 |
| 131 } // namespace gpu | 153 } // namespace gpu |
| OLD | NEW |