OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "base/at_exit.h" | 35 #include "base/at_exit.h" |
36 #include "base/message_loop.h" | 36 #include "base/message_loop.h" |
37 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 37 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
38 #include "gpu/command_buffer/client/fenced_allocator.h" | 38 #include "gpu/command_buffer/client/fenced_allocator.h" |
39 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 39 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
40 #include "gpu/command_buffer/service/mocks.h" | 40 #include "gpu/command_buffer/service/mocks.h" |
41 #include "gpu/command_buffer/service/command_buffer_service.h" | 41 #include "gpu/command_buffer/service/command_buffer_service.h" |
42 #include "gpu/command_buffer/service/gpu_processor.h" | 42 #include "gpu/command_buffer/service/gpu_processor.h" |
43 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
44 | 44 |
45 namespace command_buffer { | 45 namespace gpu { |
46 | 46 |
47 using command_buffer::CommandBufferService; | 47 using gpu::CommandBufferService; |
48 using command_buffer::GPUProcessor; | 48 using gpu::GPUProcessor; |
49 using testing::Return; | 49 using testing::Return; |
50 using testing::Mock; | 50 using testing::Mock; |
51 using testing::Truly; | 51 using testing::Truly; |
52 using testing::Sequence; | 52 using testing::Sequence; |
53 using testing::DoAll; | 53 using testing::DoAll; |
54 using testing::Invoke; | 54 using testing::Invoke; |
55 using testing::_; | 55 using testing::_; |
56 | 56 |
57 class BaseFencedAllocatorTest : public testing::Test { | 57 class BaseFencedAllocatorTest : public testing::Test { |
58 protected: | 58 protected: |
59 static const unsigned int kBufferSize = 1024; | 59 static const unsigned int kBufferSize = 1024; |
60 | 60 |
61 virtual void SetUp() { | 61 virtual void SetUp() { |
62 api_mock_.reset(new AsyncAPIMock); | 62 api_mock_.reset(new AsyncAPIMock); |
63 // ignore noops in the mock - we don't want to inspect the internals of the | 63 // ignore noops in the mock - we don't want to inspect the internals of the |
64 // helper. | 64 // helper. |
65 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, 0, _)) | 65 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, 0, _)) |
66 .WillRepeatedly(Return(parse_error::kParseNoError)); | 66 .WillRepeatedly(Return(parse_error::kParseNoError)); |
67 // Forward the SetToken calls to the engine | 67 // Forward the SetToken calls to the engine |
68 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) | 68 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) |
69 .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), | 69 .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), |
70 Return(parse_error::kParseNoError))); | 70 Return(parse_error::kParseNoError))); |
71 | 71 |
72 base::SharedMemory* ring_buffer = new base::SharedMemory; | 72 command_buffer_.reset(new CommandBufferService); |
73 ring_buffer->Create(std::wstring(), false, false, 1024); | 73 base::SharedMemory* ring_buffer = command_buffer_->Initialize( |
74 ring_buffer->Map(1024); | 74 kBufferSize / sizeof(CommandBufferEntry)); |
75 | 75 |
76 command_buffer_.reset(new CommandBufferService); | 76 parser_ = new gpu::CommandParser(ring_buffer->memory(), |
77 command_buffer_->Initialize(ring_buffer); | |
78 | |
79 parser_ = new command_buffer::CommandParser(ring_buffer->memory(), | |
80 kBufferSize, | 77 kBufferSize, |
81 0, | 78 0, |
82 kBufferSize, | 79 kBufferSize, |
83 0, | 80 0, |
84 api_mock_.get()); | 81 api_mock_.get()); |
85 | 82 |
86 scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor( | 83 scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor( |
87 command_buffer_.get(), NULL, parser_, INT_MAX)); | 84 command_buffer_.get(), NULL, parser_, INT_MAX)); |
88 command_buffer_->SetPutOffsetChangeCallback(NewCallback( | 85 command_buffer_->SetPutOffsetChangeCallback(NewCallback( |
89 gpu_processor.get(), &GPUProcessor::ProcessCommands)); | 86 gpu_processor.get(), &GPUProcessor::ProcessCommands)); |
90 | 87 |
91 api_mock_->set_engine(gpu_processor.get()); | 88 api_mock_->set_engine(gpu_processor.get()); |
92 | 89 |
93 helper_.reset(new CommandBufferHelper(command_buffer_.get())); | 90 helper_.reset(new CommandBufferHelper(command_buffer_.get())); |
94 helper_->Initialize(); | 91 helper_->Initialize(); |
95 } | 92 } |
96 | 93 |
97 virtual void TearDown() { | 94 virtual void TearDown() { |
98 helper_.release(); | 95 helper_.release(); |
99 } | 96 } |
100 | 97 |
101 base::AtExitManager at_exit_manager_; | 98 base::AtExitManager at_exit_manager_; |
102 MessageLoop message_loop_; | 99 MessageLoop message_loop_; |
103 scoped_ptr<AsyncAPIMock> api_mock_; | 100 scoped_ptr<AsyncAPIMock> api_mock_; |
104 scoped_ptr<CommandBufferService> command_buffer_; | 101 scoped_ptr<CommandBufferService> command_buffer_; |
105 command_buffer::CommandParser* parser_; | 102 gpu::CommandParser* parser_; |
106 scoped_ptr<CommandBufferHelper> helper_; | 103 scoped_ptr<CommandBufferHelper> helper_; |
107 }; | 104 }; |
108 | 105 |
109 #ifndef COMPILER_MSVC | 106 #ifndef COMPILER_MSVC |
110 const unsigned int BaseFencedAllocatorTest::kBufferSize; | 107 const unsigned int BaseFencedAllocatorTest::kBufferSize; |
111 #endif | 108 #endif |
112 | 109 |
113 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a | 110 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a |
114 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling | 111 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling |
115 // it directly, not through the RPC mechanism), making sure Noops are ignored | 112 // it directly, not through the RPC mechanism), making sure Noops are ignored |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // Check that the token has indeed passed. | 483 // Check that the token has indeed passed. |
487 EXPECT_LE(token, command_buffer_->GetToken()); | 484 EXPECT_LE(token, command_buffer_->GetToken()); |
488 | 485 |
489 // Free up everything. | 486 // Free up everything. |
490 for (unsigned int i = 0; i < kAllocCount; ++i) { | 487 for (unsigned int i = 0; i < kAllocCount; ++i) { |
491 allocator_->Free(pointers[i]); | 488 allocator_->Free(pointers[i]); |
492 EXPECT_TRUE(allocator_->CheckConsistency()); | 489 EXPECT_TRUE(allocator_->CheckConsistency()); |
493 } | 490 } |
494 } | 491 } |
495 | 492 |
496 } // namespace command_buffer | 493 } // namespace gpu |
OLD | NEW |