| 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 GLES2Implementation. | 5 // Tests for GLES2Implementation. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/client_test_helper.h" | 7 #include "gpu/command_buffer/client/client_test_helper.h" |
| 8 | 8 |
| 9 #include <stddef.h> |
| 10 #include <stdint.h> |
| 11 |
| 12 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| 9 #include "gpu/command_buffer/common/command_buffer.h" | 13 #include "gpu/command_buffer/common/command_buffer.h" |
| 10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 12 | 15 |
| 13 using ::testing::_; | 16 using ::testing::_; |
| 14 using ::testing::Invoke; | 17 using ::testing::Invoke; |
| 15 | 18 |
| 16 namespace gpu { | 19 namespace gpu { |
| 17 | 20 |
| 18 MockCommandBufferBase::MockCommandBufferBase() : put_offset_(0) { | 21 MockCommandBufferBase::MockCommandBufferBase() : put_offset_(0) { |
| 19 } | 22 } |
| 20 | 23 |
| 21 MockCommandBufferBase::~MockCommandBufferBase() { | 24 MockCommandBufferBase::~MockCommandBufferBase() { |
| 22 } | 25 } |
| 23 | 26 |
| 24 bool MockCommandBufferBase::Initialize() { | 27 bool MockCommandBufferBase::Initialize() { |
| 25 return true; | 28 return true; |
| 26 } | 29 } |
| 27 | 30 |
| 28 CommandBuffer::State MockCommandBufferBase::GetLastState() { | 31 CommandBuffer::State MockCommandBufferBase::GetLastState() { |
| 29 return state_; | 32 return state_; |
| 30 } | 33 } |
| 31 | 34 |
| 32 int32 MockCommandBufferBase::GetLastToken() { | 35 int32_t MockCommandBufferBase::GetLastToken() { |
| 33 return state_.token; | 36 return state_.token; |
| 34 } | 37 } |
| 35 | 38 |
| 36 void MockCommandBufferBase::SetGetOffset(int32 get_offset) { | 39 void MockCommandBufferBase::SetGetOffset(int32_t get_offset) { |
| 37 state_.get_offset = get_offset; | 40 state_.get_offset = get_offset; |
| 38 } | 41 } |
| 39 | 42 |
| 40 void MockCommandBufferBase::WaitForTokenInRange(int32 start, int32 end) {} | 43 void MockCommandBufferBase::WaitForTokenInRange(int32_t start, int32_t end) {} |
| 41 | 44 |
| 42 void MockCommandBufferBase::WaitForGetOffsetInRange(int32 start, int32 end) { | 45 void MockCommandBufferBase::WaitForGetOffsetInRange(int32_t start, |
| 46 int32_t end) { |
| 43 state_.get_offset = put_offset_; | 47 state_.get_offset = put_offset_; |
| 44 OnFlush(); | 48 OnFlush(); |
| 45 } | 49 } |
| 46 | 50 |
| 47 void MockCommandBufferBase::SetGetBuffer(int transfer_buffer_id) { | 51 void MockCommandBufferBase::SetGetBuffer(int transfer_buffer_id) { |
| 48 ring_buffer_buffer_ = GetTransferBuffer(transfer_buffer_id); | 52 ring_buffer_buffer_ = GetTransferBuffer(transfer_buffer_id); |
| 49 ring_buffer_ = | 53 ring_buffer_ = |
| 50 static_cast<CommandBufferEntry*>(ring_buffer_buffer_->memory()); | 54 static_cast<CommandBufferEntry*>(ring_buffer_buffer_->memory()); |
| 51 state_.token = 10000; // All token checks in the tests should pass. | 55 state_.token = 10000; // All token checks in the tests should pass. |
| 52 } | 56 } |
| 53 | 57 |
| 54 // Get's the Id of the next transfer buffer that will be returned | 58 // Get's the Id of the next transfer buffer that will be returned |
| 55 // by CreateTransferBuffer. This is useful for testing expected ids. | 59 // by CreateTransferBuffer. This is useful for testing expected ids. |
| 56 int32 MockCommandBufferBase::GetNextFreeTransferBufferId() { | 60 int32_t MockCommandBufferBase::GetNextFreeTransferBufferId() { |
| 57 for (size_t ii = 0; ii < arraysize(transfer_buffer_buffers_); ++ii) { | 61 for (size_t ii = 0; ii < arraysize(transfer_buffer_buffers_); ++ii) { |
| 58 if (!transfer_buffer_buffers_[ii].get()) { | 62 if (!transfer_buffer_buffers_[ii].get()) { |
| 59 return kTransferBufferBaseId + ii; | 63 return kTransferBufferBaseId + ii; |
| 60 } | 64 } |
| 61 } | 65 } |
| 62 return -1; | 66 return -1; |
| 63 } | 67 } |
| 64 | 68 |
| 65 scoped_refptr<gpu::Buffer> MockCommandBufferBase::CreateTransferBuffer( | 69 scoped_refptr<gpu::Buffer> MockCommandBufferBase::CreateTransferBuffer( |
| 66 size_t size, | 70 size_t size, |
| 67 int32* id) { | 71 int32_t* id) { |
| 68 *id = GetNextFreeTransferBufferId(); | 72 *id = GetNextFreeTransferBufferId(); |
| 69 if (*id >= 0) { | 73 if (*id >= 0) { |
| 70 int32 ndx = *id - kTransferBufferBaseId; | 74 int32_t ndx = *id - kTransferBufferBaseId; |
| 71 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 75 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
| 72 shared_memory->CreateAndMapAnonymous(size); | 76 shared_memory->CreateAndMapAnonymous(size); |
| 73 transfer_buffer_buffers_[ndx] = | 77 transfer_buffer_buffers_[ndx] = |
| 74 MakeBufferFromSharedMemory(std::move(shared_memory), size); | 78 MakeBufferFromSharedMemory(std::move(shared_memory), size); |
| 75 } | 79 } |
| 76 return GetTransferBuffer(*id); | 80 return GetTransferBuffer(*id); |
| 77 } | 81 } |
| 78 | 82 |
| 79 void MockCommandBufferBase::DestroyTransferBufferHelper(int32 id) { | 83 void MockCommandBufferBase::DestroyTransferBufferHelper(int32_t id) { |
| 80 DCHECK_GE(id, kTransferBufferBaseId); | 84 DCHECK_GE(id, kTransferBufferBaseId); |
| 81 DCHECK_LT(id, kTransferBufferBaseId + kMaxTransferBuffers); | 85 DCHECK_LT(id, kTransferBufferBaseId + kMaxTransferBuffers); |
| 82 id -= kTransferBufferBaseId; | 86 id -= kTransferBufferBaseId; |
| 83 transfer_buffer_buffers_[id] = NULL; | 87 transfer_buffer_buffers_[id] = NULL; |
| 84 } | 88 } |
| 85 | 89 |
| 86 scoped_refptr<Buffer> MockCommandBufferBase::GetTransferBuffer(int32 id) { | 90 scoped_refptr<Buffer> MockCommandBufferBase::GetTransferBuffer(int32_t id) { |
| 87 DCHECK_GE(id, kTransferBufferBaseId); | 91 DCHECK_GE(id, kTransferBufferBaseId); |
| 88 DCHECK_LT(id, kTransferBufferBaseId + kMaxTransferBuffers); | 92 DCHECK_LT(id, kTransferBufferBaseId + kMaxTransferBuffers); |
| 89 return transfer_buffer_buffers_[id - kTransferBufferBaseId]; | 93 return transfer_buffer_buffers_[id - kTransferBufferBaseId]; |
| 90 } | 94 } |
| 91 | 95 |
| 92 void MockCommandBufferBase::FlushHelper(int32 put_offset) { | 96 void MockCommandBufferBase::FlushHelper(int32_t put_offset) { |
| 93 put_offset_ = put_offset; | 97 put_offset_ = put_offset; |
| 94 } | 98 } |
| 95 | 99 |
| 96 void MockCommandBufferBase::SetToken(int32 token) { | 100 void MockCommandBufferBase::SetToken(int32_t token) { |
| 97 NOTREACHED(); | 101 NOTREACHED(); |
| 98 state_.token = token; | 102 state_.token = token; |
| 99 } | 103 } |
| 100 | 104 |
| 101 void MockCommandBufferBase::SetParseError(error::Error error) { | 105 void MockCommandBufferBase::SetParseError(error::Error error) { |
| 102 NOTREACHED(); | 106 NOTREACHED(); |
| 103 state_.error = error; | 107 state_.error = error; |
| 104 } | 108 } |
| 105 | 109 |
| 106 void MockCommandBufferBase::SetContextLostReason( | 110 void MockCommandBufferBase::SetContextLostReason( |
| 107 error::ContextLostReason reason) { | 111 error::ContextLostReason reason) { |
| 108 NOTREACHED(); | 112 NOTREACHED(); |
| 109 state_.context_lost_reason = reason; | 113 state_.context_lost_reason = reason; |
| 110 } | 114 } |
| 111 | 115 |
| 112 int32 MockCommandBufferBase::GetPutOffset() { | 116 int32_t MockCommandBufferBase::GetPutOffset() { |
| 113 return put_offset_; | 117 return put_offset_; |
| 114 } | 118 } |
| 115 | 119 |
| 116 // GCC requires these declarations, but MSVC requires they not be present | 120 // GCC requires these declarations, but MSVC requires they not be present |
| 117 #ifndef _MSC_VER | 121 #ifndef _MSC_VER |
| 118 const int32 MockCommandBufferBase::kTransferBufferBaseId; | 122 const int32_t MockCommandBufferBase::kTransferBufferBaseId; |
| 119 const int32 MockCommandBufferBase::kMaxTransferBuffers; | 123 const int32_t MockCommandBufferBase::kMaxTransferBuffers; |
| 120 #endif | 124 #endif |
| 121 | 125 |
| 122 MockClientCommandBuffer::MockClientCommandBuffer() { | 126 MockClientCommandBuffer::MockClientCommandBuffer() { |
| 123 DelegateToFake(); | 127 DelegateToFake(); |
| 124 } | 128 } |
| 125 | 129 |
| 126 MockClientCommandBuffer::~MockClientCommandBuffer() { | 130 MockClientCommandBuffer::~MockClientCommandBuffer() { |
| 127 } | 131 } |
| 128 | 132 |
| 129 void MockClientCommandBuffer::Flush(int32 put_offset) { | 133 void MockClientCommandBuffer::Flush(int32_t put_offset) { |
| 130 FlushHelper(put_offset); | 134 FlushHelper(put_offset); |
| 131 } | 135 } |
| 132 | 136 |
| 133 void MockClientCommandBuffer::OrderingBarrier(int32 put_offset) { | 137 void MockClientCommandBuffer::OrderingBarrier(int32_t put_offset) { |
| 134 FlushHelper(put_offset); | 138 FlushHelper(put_offset); |
| 135 } | 139 } |
| 136 | 140 |
| 137 void MockClientCommandBuffer::DelegateToFake() { | 141 void MockClientCommandBuffer::DelegateToFake() { |
| 138 ON_CALL(*this, DestroyTransferBuffer(_)) | 142 ON_CALL(*this, DestroyTransferBuffer(_)) |
| 139 .WillByDefault(Invoke( | 143 .WillByDefault(Invoke( |
| 140 this, &MockCommandBufferBase::DestroyTransferBufferHelper)); | 144 this, &MockCommandBufferBase::DestroyTransferBufferHelper)); |
| 141 } | 145 } |
| 142 | 146 |
| 143 MockClientCommandBufferMockFlush::MockClientCommandBufferMockFlush() { | 147 MockClientCommandBufferMockFlush::MockClientCommandBufferMockFlush() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 | 160 |
| 157 MockClientGpuControl::MockClientGpuControl() { | 161 MockClientGpuControl::MockClientGpuControl() { |
| 158 } | 162 } |
| 159 | 163 |
| 160 MockClientGpuControl::~MockClientGpuControl() { | 164 MockClientGpuControl::~MockClientGpuControl() { |
| 161 } | 165 } |
| 162 | 166 |
| 163 } // namespace gpu | 167 } // namespace gpu |
| 164 | 168 |
| 165 | 169 |
| OLD | NEW |