| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file contains the tests for the RingBuffer class. | 5 // This file contains the tests for the RingBuffer class. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/ring_buffer.h" | 7 #include "gpu/command_buffer/client/ring_buffer.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 using testing::Invoke; | 29 using testing::Invoke; |
| 30 using testing::_; | 30 using testing::_; |
| 31 | 31 |
| 32 class BaseRingBufferTest : public testing::Test { | 32 class BaseRingBufferTest : public testing::Test { |
| 33 protected: | 33 protected: |
| 34 static const unsigned int kBaseOffset = 128; | 34 static const unsigned int kBaseOffset = 128; |
| 35 static const unsigned int kBufferSize = 1024; | 35 static const unsigned int kBufferSize = 1024; |
| 36 | 36 |
| 37 class DoJumpCommand { | 37 class DoJumpCommand { |
| 38 public: | 38 public: |
| 39 explicit DoJumpCommand(CommandParser* parser) | 39 explicit DoJumpCommand(GpuScheduler* gpu_scheduler) |
| 40 : parser_(parser) { | 40 : gpu_scheduler_(gpu_scheduler) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 error::Error DoCommand( | 43 error::Error DoCommand( |
| 44 unsigned int command, | 44 unsigned int command, |
| 45 unsigned int arg_count, | 45 unsigned int arg_count, |
| 46 const void* cmd_data) { | 46 const void* cmd_data) { |
| 47 const cmd::Jump* jump_cmd = static_cast<const cmd::Jump*>(cmd_data); | 47 const cmd::Jump* jump_cmd = static_cast<const cmd::Jump*>(cmd_data); |
| 48 parser_->set_get(jump_cmd->offset); | 48 gpu_scheduler_->parser()->set_get(jump_cmd->offset); |
| 49 return error::kNoError; | 49 return error::kNoError; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 CommandParser* parser_; | 53 GpuScheduler* gpu_scheduler_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 virtual void SetUp() { | 56 virtual void SetUp() { |
| 57 api_mock_.reset(new AsyncAPIMock); | 57 api_mock_.reset(new AsyncAPIMock); |
| 58 // ignore noops in the mock - we don't want to inspect the internals of the | 58 // ignore noops in the mock - we don't want to inspect the internals of the |
| 59 // helper. | 59 // helper. |
| 60 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, 0, _)) | 60 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, 0, _)) |
| 61 .WillRepeatedly(Return(error::kNoError)); | 61 .WillRepeatedly(Return(error::kNoError)); |
| 62 // Forward the SetToken calls to the engine | 62 // Forward the SetToken calls to the engine |
| 63 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) | 63 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) |
| 64 .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), | 64 .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), |
| 65 Return(error::kNoError))); | 65 Return(error::kNoError))); |
| 66 | 66 |
| 67 command_buffer_.reset(new CommandBufferService); | 67 command_buffer_.reset(new CommandBufferService); |
| 68 command_buffer_->Initialize(); | 68 command_buffer_->Initialize(); |
| 69 | 69 |
| 70 parser_ = new CommandParser(api_mock_.get()); | |
| 71 | |
| 72 gpu_scheduler_.reset(new GpuScheduler( | 70 gpu_scheduler_.reset(new GpuScheduler( |
| 73 command_buffer_.get(), NULL, parser_)); | 71 command_buffer_.get(), api_mock_.get(), NULL)); |
| 74 command_buffer_->SetPutOffsetChangeCallback(base::Bind( | 72 command_buffer_->SetPutOffsetChangeCallback(base::Bind( |
| 75 &GpuScheduler::PutChanged, base::Unretained(gpu_scheduler_.get()))); | 73 &GpuScheduler::PutChanged, base::Unretained(gpu_scheduler_.get()))); |
| 74 command_buffer_->SetGetBufferChangeCallback(base::Bind( |
| 75 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get()))); |
| 76 | 76 |
| 77 api_mock_->set_engine(gpu_scheduler_.get()); | 77 api_mock_->set_engine(gpu_scheduler_.get()); |
| 78 do_jump_command_.reset(new DoJumpCommand(parser_)); | 78 do_jump_command_.reset(new DoJumpCommand(gpu_scheduler_.get())); |
| 79 EXPECT_CALL(*api_mock_, DoCommand(cmd::kJump, _, _)) | 79 EXPECT_CALL(*api_mock_, DoCommand(cmd::kJump, _, _)) |
| 80 .WillRepeatedly( | 80 .WillRepeatedly( |
| 81 Invoke(do_jump_command_.get(), &DoJumpCommand::DoCommand)); | 81 Invoke(do_jump_command_.get(), &DoJumpCommand::DoCommand)); |
| 82 | 82 |
| 83 helper_.reset(new CommandBufferHelper(command_buffer_.get())); | 83 helper_.reset(new CommandBufferHelper(command_buffer_.get())); |
| 84 helper_->Initialize(kBufferSize); | 84 helper_->Initialize(kBufferSize); |
| 85 | |
| 86 // Note: parser->SetBuffer would normally be called through | |
| 87 // helper_->Initialize but currently it needs a GpuCommandBufferStub as the | |
| 88 // CommandBuffer instead of the CommandBufferService for that to happen. | |
| 89 Buffer ring_buffer = helper_->get_ring_buffer(); | |
| 90 parser_->SetBuffer(ring_buffer.ptr, ring_buffer.size, 0, ring_buffer.size); | |
| 91 } | 85 } |
| 92 | 86 |
| 93 int32 GetToken() { | 87 int32 GetToken() { |
| 94 return command_buffer_->GetState().token; | 88 return command_buffer_->GetState().token; |
| 95 } | 89 } |
| 96 | 90 |
| 97 #if defined(OS_MACOSX) | 91 #if defined(OS_MACOSX) |
| 98 base::mac::ScopedNSAutoreleasePool autorelease_pool_; | 92 base::mac::ScopedNSAutoreleasePool autorelease_pool_; |
| 99 #endif | 93 #endif |
| 100 MessageLoop message_loop_; | 94 MessageLoop message_loop_; |
| 101 scoped_ptr<AsyncAPIMock> api_mock_; | 95 scoped_ptr<AsyncAPIMock> api_mock_; |
| 102 scoped_ptr<CommandBufferService> command_buffer_; | 96 scoped_ptr<CommandBufferService> command_buffer_; |
| 103 scoped_ptr<GpuScheduler> gpu_scheduler_; | 97 scoped_ptr<GpuScheduler> gpu_scheduler_; |
| 104 CommandParser* parser_; | |
| 105 scoped_ptr<CommandBufferHelper> helper_; | 98 scoped_ptr<CommandBufferHelper> helper_; |
| 106 scoped_ptr<DoJumpCommand> do_jump_command_; | 99 scoped_ptr<DoJumpCommand> do_jump_command_; |
| 107 }; | 100 }; |
| 108 | 101 |
| 109 #ifndef _MSC_VER | 102 #ifndef _MSC_VER |
| 110 const unsigned int BaseRingBufferTest::kBaseOffset; | 103 const unsigned int BaseRingBufferTest::kBaseOffset; |
| 111 const unsigned int BaseRingBufferTest::kBufferSize; | 104 const unsigned int BaseRingBufferTest::kBufferSize; |
| 112 #endif | 105 #endif |
| 113 | 106 |
| 114 // Test fixture for RingBuffer test - Creates a RingBuffer, using a | 107 // Test fixture for RingBuffer test - Creates a RingBuffer, using a |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 EXPECT_EQ(buffer_start_, static_cast<int8*>(pointer1)); | 276 EXPECT_EQ(buffer_start_, static_cast<int8*>(pointer1)); |
| 284 | 277 |
| 285 // Check that the token has indeed passed. | 278 // Check that the token has indeed passed. |
| 286 EXPECT_LE(tokens[0], GetToken()); | 279 EXPECT_LE(tokens[0], GetToken()); |
| 287 | 280 |
| 288 allocator_->FreePendingToken(pointer1, helper_->InsertToken()); | 281 allocator_->FreePendingToken(pointer1, helper_->InsertToken()); |
| 289 EXPECT_LE(command_buffer_->GetState().token, helper_->InsertToken()); | 282 EXPECT_LE(command_buffer_->GetState().token, helper_->InsertToken()); |
| 290 } | 283 } |
| 291 | 284 |
| 292 } // namespace gpu | 285 } // namespace gpu |
| OLD | NEW |