| 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/gl2.h> | 9 #include <GLES2/gl2.h> |
| 10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
| 11 #include <stddef.h> |
| 12 #include <stdint.h> |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "gpu/command_buffer/client/client_test_helper.h" | 14 #include "gpu/command_buffer/client/client_test_helper.h" |
| 13 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 15 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 14 #include "gpu/command_buffer/client/mapped_memory.h" | 16 #include "gpu/command_buffer/client/mapped_memory.h" |
| 15 #include "gpu/command_buffer/common/command_buffer.h" | 17 #include "gpu/command_buffer/common/command_buffer.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 20 |
| 19 namespace gpu { | 21 namespace gpu { |
| 20 namespace gles2 { | 22 namespace gles2 { |
| 21 | 23 |
| 22 class MockClientCommandBufferImpl : public MockClientCommandBuffer { | 24 class MockClientCommandBufferImpl : public MockClientCommandBuffer { |
| 23 public: | 25 public: |
| 24 MockClientCommandBufferImpl() | 26 MockClientCommandBufferImpl() |
| 25 : MockClientCommandBuffer(), | 27 : MockClientCommandBuffer(), |
| 26 context_lost_(false) {} | 28 context_lost_(false) {} |
| 27 ~MockClientCommandBufferImpl() override {} | 29 ~MockClientCommandBufferImpl() override {} |
| 28 | 30 |
| 29 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, | 31 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, |
| 30 int32* id) override { | 32 int32_t* id) override { |
| 31 if (context_lost_) { | 33 if (context_lost_) { |
| 32 *id = -1; | 34 *id = -1; |
| 33 return NULL; | 35 return NULL; |
| 34 } | 36 } |
| 35 return MockClientCommandBuffer::CreateTransferBuffer(size, id); | 37 return MockClientCommandBuffer::CreateTransferBuffer(size, id); |
| 36 } | 38 } |
| 37 | 39 |
| 38 void set_context_lost(bool context_lost) { | 40 void set_context_lost(bool context_lost) { |
| 39 context_lost_ = context_lost; | 41 context_lost_ = context_lost; |
| 40 } | 42 } |
| 41 | 43 |
| 42 private: | 44 private: |
| 43 bool context_lost_; | 45 bool context_lost_; |
| 44 }; | 46 }; |
| 45 | 47 |
| 46 class BufferTrackerTest : public testing::Test { | 48 class BufferTrackerTest : public testing::Test { |
| 47 protected: | 49 protected: |
| 48 static const int32 kNumCommandEntries = 400; | 50 static const int32_t kNumCommandEntries = 400; |
| 49 static const int32 kCommandBufferSizeBytes = | 51 static const int32_t kCommandBufferSizeBytes = |
| 50 kNumCommandEntries * sizeof(CommandBufferEntry); | 52 kNumCommandEntries * sizeof(CommandBufferEntry); |
| 51 | 53 |
| 52 void SetUp() override { | 54 void SetUp() override { |
| 53 command_buffer_.reset(new MockClientCommandBufferImpl()); | 55 command_buffer_.reset(new MockClientCommandBufferImpl()); |
| 54 helper_.reset(new GLES2CmdHelper(command_buffer_.get())); | 56 helper_.reset(new GLES2CmdHelper(command_buffer_.get())); |
| 55 helper_->Initialize(kCommandBufferSizeBytes); | 57 helper_->Initialize(kCommandBufferSizeBytes); |
| 56 mapped_memory_.reset( | 58 mapped_memory_.reset( |
| 57 new MappedMemoryManager(helper_.get(), MappedMemoryManager::kNoLimit)); | 59 new MappedMemoryManager(helper_.get(), MappedMemoryManager::kNoLimit)); |
| 58 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); | 60 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); |
| 59 } | 61 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 buffer_tracker_->Unmanage(buffer); | 142 buffer_tracker_->Unmanage(buffer); |
| 141 buffer_tracker_->RemoveBuffer(kId); | 143 buffer_tracker_->RemoveBuffer(kId); |
| 142 EXPECT_EQ(mapped_memory_->bytes_in_use(), static_cast<size_t>(size)); | 144 EXPECT_EQ(mapped_memory_->bytes_in_use(), static_cast<size_t>(size)); |
| 143 | 145 |
| 144 mapped_memory_->Free(mem); | 146 mapped_memory_->Free(mem); |
| 145 EXPECT_EQ(mapped_memory_->bytes_in_use(), static_cast<size_t>(0)); | 147 EXPECT_EQ(mapped_memory_->bytes_in_use(), static_cast<size_t>(0)); |
| 146 } | 148 } |
| 147 | 149 |
| 148 } // namespace gles2 | 150 } // namespace gles2 |
| 149 } // namespace gpu | 151 } // namespace gpu |
| OLD | NEW |