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
3 // found in the LICENSE file.
5 // Tests for GLES2Implementation.
7 #include "gpu/command_buffer/client/client_test_helper.h"
9 #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 using ::testing::Invoke
;
18 MockCommandBufferBase::~MockCommandBufferBase() {
21 bool MockCommandBufferBase::Initialize() {
25 CommandBuffer::State
MockCommandBufferBase::GetState() {
29 CommandBuffer::State
MockCommandBufferBase::GetLastState() {
33 int32
MockCommandBufferBase::GetLastToken() {
37 void MockCommandBufferBase::SetGetOffset(int32 get_offset
) {
38 state_
.get_offset
= get_offset
;
41 CommandBuffer::State
MockCommandBufferBase::FlushSync(
42 int32 put_offset
, int32 last_known_get
) {
43 state_
.put_offset
= put_offset
;
44 state_
.get_offset
= put_offset
;
49 void MockCommandBufferBase::SetGetBuffer(int transfer_buffer_id
) {
50 ring_buffer_buffer_
= GetTransferBuffer(transfer_buffer_id
);
51 ring_buffer_
= static_cast<CommandBufferEntry
*>(ring_buffer_buffer_
.ptr
);
52 state_
.num_entries
= ring_buffer_buffer_
.size
/ sizeof(ring_buffer_
[0]);
53 state_
.token
= 10000; // All token checks in the tests should pass.
56 // Get's the Id of the next transfer buffer that will be returned
57 // by CreateTransferBuffer. This is useful for testing expected ids.
58 int32
MockCommandBufferBase::GetNextFreeTransferBufferId() {
59 for (size_t ii
= 0; ii
< arraysize(transfer_buffers_
); ++ii
) {
60 if (!transfer_buffers_
[ii
].get()) {
61 return kTransferBufferBaseId
+ ii
;
67 Buffer
MockCommandBufferBase::CreateTransferBuffer(size_t size
, int32
* id
) {
68 *id
= GetNextFreeTransferBufferId();
70 int32 ndx
= *id
- kTransferBufferBaseId
;
71 transfer_buffers_
[ndx
].reset(new int8
[size
]);
72 transfer_buffer_buffers_
[ndx
].ptr
= transfer_buffers_
[ndx
].get();
73 transfer_buffer_buffers_
[ndx
].size
= size
;
75 return GetTransferBuffer(*id
);
78 void MockCommandBufferBase::DestroyTransferBufferHelper(int32 id
) {
79 GPU_DCHECK_GE(id
, kTransferBufferBaseId
);
80 GPU_DCHECK_LT(id
, kTransferBufferBaseId
+ kMaxTransferBuffers
);
81 id
-= kTransferBufferBaseId
;
82 transfer_buffers_
[id
].reset();
83 transfer_buffer_buffers_
[id
] = Buffer();
86 Buffer
MockCommandBufferBase::GetTransferBuffer(int32 id
) {
87 GPU_DCHECK_GE(id
, kTransferBufferBaseId
);
88 GPU_DCHECK_LT(id
, kTransferBufferBaseId
+ kMaxTransferBuffers
);
89 return transfer_buffer_buffers_
[id
- kTransferBufferBaseId
];
92 void MockCommandBufferBase::FlushHelper(int32 put_offset
) {
93 state_
.put_offset
= put_offset
;
96 void MockCommandBufferBase::SetToken(int32 token
) {
101 void MockCommandBufferBase::SetParseError(error::Error error
) {
103 state_
.error
= error
;
106 void MockCommandBufferBase::SetContextLostReason(
107 error::ContextLostReason reason
) {
109 state_
.context_lost_reason
= reason
;
112 uint32
MockCommandBufferBase::InsertSyncPoint() {
117 // GCC requires these declarations, but MSVC requires they not be present
119 const int32
MockCommandBufferBase::kTransferBufferBaseId
;
120 const int32
MockCommandBufferBase::kMaxTransferBuffers
;
123 MockClientCommandBuffer::MockClientCommandBuffer() {
127 MockClientCommandBuffer::~MockClientCommandBuffer() {
130 void MockClientCommandBuffer::Flush(int32 put_offset
) {
131 FlushHelper(put_offset
);
134 void MockClientCommandBuffer::DelegateToFake() {
135 ON_CALL(*this, DestroyTransferBuffer(_
))
136 .WillByDefault(Invoke(
137 this, &MockCommandBufferBase::DestroyTransferBufferHelper
));
140 MockClientCommandBufferMockFlush::MockClientCommandBufferMockFlush() {
144 MockClientCommandBufferMockFlush::~MockClientCommandBufferMockFlush() {
147 void MockClientCommandBufferMockFlush::DelegateToFake() {
148 MockClientCommandBuffer::DelegateToFake();
149 ON_CALL(*this, Flush(_
))
150 .WillByDefault(Invoke(
151 this, &MockCommandBufferBase::FlushHelper
));
154 MockClientGpuControl::MockClientGpuControl() {
157 MockClientGpuControl::~MockClientGpuControl() {