forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make transferbuffer increase in size dynamically
TEST=unit tests BUG=101431 Review URL: http://codereview.chromium.org/9113069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119430 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
gman@chromium.org
committed
Jan 27, 2012
1 parent
52fe647
commit d5c7696
Showing
25 changed files
with
2,232 additions
and
1,396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Tests for GLES2Implementation. | ||
|
||
#include "gpu/command_buffer/client/client_test_helper.h" | ||
|
||
#include "gpu/command_buffer/common/command_buffer.h" | ||
#include "gpu/command_buffer/client/cmd_buffer_helper.h" | ||
#include "testing/gmock/include/gmock/gmock.h" | ||
|
||
using ::testing::_; | ||
using ::testing::Invoke; | ||
|
||
namespace gpu { | ||
|
||
MockCommandBufferBase::~MockCommandBufferBase() { | ||
} | ||
|
||
bool MockCommandBufferBase::Initialize() { | ||
return true; | ||
} | ||
|
||
CommandBuffer::State MockCommandBufferBase::GetState() { | ||
return state_; | ||
} | ||
|
||
CommandBuffer::State MockCommandBufferBase::GetLastState() { | ||
return state_; | ||
} | ||
|
||
void MockCommandBufferBase::Flush(int32 put_offset) { | ||
state_.put_offset = put_offset; | ||
} | ||
|
||
void MockCommandBufferBase::SetGetOffset(int32 get_offset) { | ||
state_.get_offset = get_offset; | ||
} | ||
|
||
CommandBuffer::State MockCommandBufferBase::FlushSync( | ||
int32 put_offset, int32 last_known_get) { | ||
state_.put_offset = put_offset; | ||
state_.get_offset = put_offset; | ||
OnFlush(); | ||
return state_; | ||
} | ||
|
||
void MockCommandBufferBase::SetGetBuffer(int transfer_buffer_id) { | ||
ring_buffer_buffer_ = GetTransferBuffer(transfer_buffer_id); | ||
ring_buffer_ = static_cast<CommandBufferEntry*>(ring_buffer_buffer_.ptr); | ||
state_.num_entries = ring_buffer_buffer_.size / sizeof(ring_buffer_[0]); | ||
state_.token = 10000; // All token checks in the tests should pass. | ||
} | ||
|
||
// Get's the Id of the next transfer buffer that will be returned | ||
// by CreateTransferBuffer. This is useful for testing expected ids. | ||
int32 MockCommandBufferBase::GetNextFreeTransferBufferId() { | ||
for (size_t ii = 0; ii < arraysize(transfer_buffers_); ++ii) { | ||
if (!transfer_buffers_[ii].get()) { | ||
return kTransferBufferBaseId + ii; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
int32 MockCommandBufferBase::CreateTransferBuffer( | ||
size_t size, int32 id_request) { | ||
int32 id = GetNextFreeTransferBufferId(); | ||
if (id >= 0) { | ||
int32 ndx = id - kTransferBufferBaseId; | ||
transfer_buffers_[ndx].reset(new int8[size]); | ||
transfer_buffer_buffers_[ndx].ptr = transfer_buffers_[ndx].get(); | ||
transfer_buffer_buffers_[ndx].size = size; | ||
} | ||
return id; | ||
} | ||
|
||
void MockCommandBufferBase::DestroyTransferBufferHelper(int32 id) { | ||
GPU_DCHECK_GE(id, kTransferBufferBaseId); | ||
GPU_DCHECK_LT(id, kTransferBufferBaseId + kMaxTransferBuffers); | ||
id -= kTransferBufferBaseId; | ||
transfer_buffers_[id].reset(); | ||
transfer_buffer_buffers_[id] = Buffer(); | ||
} | ||
|
||
Buffer MockCommandBufferBase::GetTransferBuffer(int32 id) { | ||
GPU_DCHECK_GE(id, kTransferBufferBaseId); | ||
GPU_DCHECK_LT(id, kTransferBufferBaseId + kMaxTransferBuffers); | ||
return transfer_buffer_buffers_[id - kTransferBufferBaseId]; | ||
} | ||
|
||
int32 MockCommandBufferBase::RegisterTransferBuffer( | ||
base::SharedMemory* shared_memory, | ||
size_t size, | ||
int32 id_request) { | ||
GPU_NOTREACHED(); | ||
return -1; | ||
} | ||
|
||
void MockCommandBufferBase::SetToken(int32 token) { | ||
GPU_NOTREACHED(); | ||
state_.token = token; | ||
} | ||
|
||
void MockCommandBufferBase::SetParseError(error::Error error) { | ||
GPU_NOTREACHED(); | ||
state_.error = error; | ||
} | ||
|
||
void MockCommandBufferBase::SetContextLostReason( | ||
error::ContextLostReason reason) { | ||
GPU_NOTREACHED(); | ||
state_.context_lost_reason = reason; | ||
} | ||
|
||
// GCC requires these declarations, but MSVC requires they not be present | ||
#ifndef _MSC_VER | ||
const int32 MockCommandBufferBase::kTransferBufferBaseId; | ||
const int32 MockCommandBufferBase::kMaxTransferBuffers; | ||
#endif | ||
|
||
MockClientCommandBuffer::MockClientCommandBuffer() { | ||
DelegateToFake(); | ||
} | ||
|
||
MockClientCommandBuffer::~MockClientCommandBuffer() { | ||
} | ||
|
||
void MockClientCommandBuffer::DelegateToFake() { | ||
ON_CALL(*this, DestroyTransferBuffer(_)) | ||
.WillByDefault(Invoke( | ||
this, &MockCommandBufferBase::DestroyTransferBufferHelper)); | ||
} | ||
|
||
} // namespace gpu | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Helper classes for implementing gpu client side unit tests. | ||
|
||
#ifndef GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_ | ||
#define GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_ | ||
|
||
#include "gpu/command_buffer/common/cmd_buffer_common.h" | ||
#include "gpu/command_buffer/common/command_buffer.h" | ||
#include "gpu/command_buffer/common/compiler_specific.h" | ||
#include "gpu/command_buffer/common/scoped_ptr.h" | ||
#include "testing/gmock/include/gmock/gmock.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace gpu { | ||
|
||
class CommandBufferHelper; | ||
|
||
class MockCommandBufferBase : public CommandBuffer { | ||
public: | ||
static const int32 kTransferBufferBaseId = 0x123; | ||
static const int32 kMaxTransferBuffers = 6; | ||
|
||
MockCommandBufferBase() { } | ||
virtual ~MockCommandBufferBase(); | ||
|
||
virtual bool Initialize() OVERRIDE; | ||
virtual State GetState() OVERRIDE; | ||
virtual State GetLastState() OVERRIDE; | ||
virtual void Flush(int32 put_offset) OVERRIDE; | ||
virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; | ||
virtual void SetGetBuffer(int transfer_buffer_id) OVERRIDE; | ||
virtual void SetGetOffset(int32 get_offset) OVERRIDE; | ||
virtual int32 CreateTransferBuffer(size_t size, int32 id_request) OVERRIDE; | ||
virtual Buffer GetTransferBuffer(int32 id) OVERRIDE; | ||
virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, | ||
size_t size, | ||
int32 id_request) OVERRIDE; | ||
virtual void SetToken(int32 token) OVERRIDE; | ||
virtual void SetParseError(error::Error error) OVERRIDE; | ||
virtual void SetContextLostReason(error::ContextLostReason reason) OVERRIDE; | ||
|
||
// Get's the Id of the next transfer buffer that will be returned | ||
// by CreateTransferBuffer. This is useful for testing expected ids. | ||
int32 GetNextFreeTransferBufferId(); | ||
|
||
void DestroyTransferBufferHelper(int32 id); | ||
|
||
virtual void OnFlush() = 0; | ||
|
||
private: | ||
scoped_array<int8> transfer_buffers_[kMaxTransferBuffers]; | ||
Buffer transfer_buffer_buffers_[kMaxTransferBuffers]; | ||
CommandBufferEntry* ring_buffer_; | ||
Buffer ring_buffer_buffer_; | ||
State state_; | ||
}; | ||
|
||
class MockClientCommandBuffer : public MockCommandBufferBase { | ||
public: | ||
MockClientCommandBuffer(); | ||
virtual ~MockClientCommandBuffer(); | ||
|
||
// This is so we can use all the gmock functions when Flush is called. | ||
MOCK_METHOD0(OnFlush, void()); | ||
MOCK_METHOD1(DestroyTransferBuffer, void(int32 id)); | ||
|
||
void DelegateToFake(); | ||
}; | ||
|
||
} // namespace gpu | ||
|
||
#endif // GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_ | ||
|
Oops, something went wrong.