Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Unified Diff: gpu/command_buffer/client/cmd_buffer_helper_test.cc

Issue 8953006: Free the command buffer when tabs are switched (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/client/cmd_buffer_helper.cc ('k') | gpu/command_buffer/client/fenced_allocator_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/client/cmd_buffer_helper_test.cc
diff --git a/gpu/command_buffer/client/cmd_buffer_helper_test.cc b/gpu/command_buffer/client/cmd_buffer_helper_test.cc
index 216bb608802121d3f2bcd73de6912dff5ee9ac56..2fa1fee0bc76b9a5a35df163fad9a175f5a8df11 100644
--- a/gpu/command_buffer/client/cmd_buffer_helper_test.cc
+++ b/gpu/command_buffer/client/cmd_buffer_helper_test.cc
@@ -41,8 +41,8 @@ class CommandBufferHelperTest : public testing::Test {
// Helper so mock can handle the Jump command.
class DoJumpCommand {
public:
- explicit DoJumpCommand(CommandParser* parser)
- : parser_(parser) {
+ explicit DoJumpCommand(GpuScheduler* gpu_scheduler)
+ : gpu_scheduler_(gpu_scheduler) {
}
error::Error DoCommand(
@@ -50,12 +50,12 @@ class CommandBufferHelperTest : public testing::Test {
unsigned int arg_count,
const void* cmd_data) {
const cmd::Jump* jump_cmd = static_cast<const cmd::Jump*>(cmd_data);
- parser_->set_get(jump_cmd->offset);
+ gpu_scheduler_->parser()->set_get(jump_cmd->offset);
return error::kNoError;
};
private:
- CommandParser* parser_;
+ GpuScheduler* gpu_scheduler_;
};
virtual void SetUp() {
@@ -68,28 +68,23 @@ class CommandBufferHelperTest : public testing::Test {
command_buffer_.reset(new CommandBufferService);
command_buffer_->Initialize();
- parser_ = new CommandParser(api_mock_.get());
+ gpu_scheduler_.reset(new GpuScheduler(
+ command_buffer_.get(), api_mock_.get(), NULL));
+ command_buffer_->SetPutOffsetChangeCallback(base::Bind(
+ &GpuScheduler::PutChanged, base::Unretained(gpu_scheduler_.get())));
+ command_buffer_->SetGetBufferChangeCallback(base::Bind(
+ &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get())));
- do_jump_command_.reset(new DoJumpCommand(parser_));
+ do_jump_command_.reset(new DoJumpCommand(gpu_scheduler_.get()));
EXPECT_CALL(*api_mock_, DoCommand(cmd::kJump, _, _))
.WillRepeatedly(
Invoke(do_jump_command_.get(), &DoJumpCommand::DoCommand));
- gpu_scheduler_.reset(new GpuScheduler(
- command_buffer_.get(), NULL, parser_));
- command_buffer_->SetPutOffsetChangeCallback(base::Bind(
- &GpuScheduler::PutChanged, base::Unretained(gpu_scheduler_.get())));
api_mock_->set_engine(gpu_scheduler_.get());
helper_.reset(new CommandBufferHelper(command_buffer_.get()));
helper_->Initialize(kCommandBufferSizeBytes);
-
- // Note: parser->SetBuffer would normally be called through
- // helper_->Initialize but currently it needs a GpuCommandBufferStub as the
- // CommandBuffer instead of the CommandBufferService for that to happen.
- Buffer ring_buffer = helper_->get_ring_buffer();
- parser_->SetBuffer(ring_buffer.ptr, ring_buffer.size, 0, ring_buffer.size);
}
virtual void TearDown() {
@@ -97,6 +92,10 @@ class CommandBufferHelperTest : public testing::Test {
MessageLoop::current()->RunAllPending();
}
+ const CommandParser* GetParser() const {
+ return gpu_scheduler_->parser();
+ }
+
// Adds a command to the buffer through the helper, while adding it as an
// expected call on the API mock.
void AddCommandWithExpect(error::Error _return,
@@ -121,8 +120,8 @@ class CommandBufferHelperTest : public testing::Test {
// Checks that the buffer from put to put+size is free in the parser.
void CheckFreeSpace(CommandBufferOffset put, unsigned int size) {
- CommandBufferOffset parser_put = parser_->put();
- CommandBufferOffset parser_get = parser_->get();
+ CommandBufferOffset parser_put = GetParser()->put();
+ CommandBufferOffset parser_get = GetParser()->get();
CommandBufferOffset limit = put + size;
if (parser_get > parser_put) {
// "busy" buffer wraps, so "free" buffer is between put (inclusive) and
@@ -163,7 +162,6 @@ class CommandBufferHelperTest : public testing::Test {
scoped_ptr<AsyncAPIMock> api_mock_;
scoped_ptr<CommandBufferService> command_buffer_;
scoped_ptr<GpuScheduler> gpu_scheduler_;
- CommandParser* parser_;
scoped_ptr<CommandBufferHelper> helper_;
Sequence sequence_;
scoped_ptr<DoJumpCommand> do_jump_command_;
@@ -174,7 +172,7 @@ class CommandBufferHelperTest : public testing::Test {
TEST_F(CommandBufferHelperTest, TestCommandProcessing) {
// Check initial state of the engine - it should have been configured by the
// helper.
- EXPECT_TRUE(parser_ != NULL);
+ EXPECT_TRUE(GetParser() != NULL);
EXPECT_EQ(error::kNoError, GetError());
EXPECT_EQ(0, GetGetOffset());
@@ -194,7 +192,7 @@ TEST_F(CommandBufferHelperTest, TestCommandProcessing) {
// Wait until it's done.
helper_->Finish();
// Check that the engine has no more work to do.
- EXPECT_TRUE(parser_->IsEmpty());
+ EXPECT_TRUE(GetParser()->IsEmpty());
// Check that the commands did happen.
Mock::VerifyAndClearExpectations(api_mock_.get());
@@ -309,4 +307,32 @@ TEST_F(CommandBufferHelperTest, TestToken) {
EXPECT_EQ(error::kNoError, GetError());
}
+TEST_F(CommandBufferHelperTest, FreeRingBuffer) {
+ EXPECT_TRUE(helper_->HaveRingBuffer());
+
+ // Test freeing ring buffer.
+ helper_->FreeRingBuffer();
+ EXPECT_FALSE(helper_->HaveRingBuffer());
+
+ // Test that InsertToken allocates a new one
+ int32 token = helper_->InsertToken();
+ EXPECT_TRUE(helper_->HaveRingBuffer());
+ EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _))
+ .WillOnce(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken),
+ Return(error::kNoError)));
+ helper_->WaitForToken(token);
+ helper_->FreeRingBuffer();
+ EXPECT_FALSE(helper_->HaveRingBuffer());
+
+ // Test that WaitForAvailableEntries allocates a new one
+ AddCommandWithExpect(error::kNoError, kUnusedCommandId, 0, NULL);
+ EXPECT_TRUE(helper_->HaveRingBuffer());
+ helper_->Finish();
+ helper_->FreeRingBuffer();
+ EXPECT_FALSE(helper_->HaveRingBuffer());
+
+ // Check that the commands did happen.
+ Mock::VerifyAndClearExpectations(api_mock_.get());
+}
+
} // namespace gpu
« no previous file with comments | « gpu/command_buffer/client/cmd_buffer_helper.cc ('k') | gpu/command_buffer/client/fenced_allocator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698