OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 #include "content/common/gpu/gpu_channel_test_common.h" | 5 #include "content/common/gpu/gpu_channel_test_common.h" |
6 | 6 |
7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "content/common/gpu/gpu_channel_manager_delegate.h" |
9 #include "gpu/command_buffer/service/sync_point_manager.h" | 10 #include "gpu/command_buffer/service/sync_point_manager.h" |
10 #include "ipc/ipc_test_sink.h" | 11 #include "ipc/ipc_test_sink.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
| 15 TestGpuChannelManagerDelegate::TestGpuChannelManagerDelegate() {} |
| 16 |
| 17 TestGpuChannelManagerDelegate::~TestGpuChannelManagerDelegate() {} |
| 18 |
| 19 void TestGpuChannelManagerDelegate::AddSubscription(int32_t client_id, |
| 20 unsigned int target) {} |
| 21 |
| 22 void TestGpuChannelManagerDelegate::ChannelEstablished( |
| 23 const IPC::ChannelHandle& channel_handle) { |
| 24 last_established_channel_handle_ = channel_handle; |
| 25 } |
| 26 |
| 27 void TestGpuChannelManagerDelegate::DidCreateOffscreenContext( |
| 28 const GURL& active_url) {} |
| 29 |
| 30 void TestGpuChannelManagerDelegate::DidDestroyChannel(int client_id) {} |
| 31 |
| 32 void TestGpuChannelManagerDelegate::DidDestroyOffscreenContext( |
| 33 const GURL& active_url) {} |
| 34 |
| 35 void TestGpuChannelManagerDelegate::DidLoseContext( |
| 36 bool offscreen, |
| 37 gpu::error::ContextLostReason reason, |
| 38 const GURL& active_url) {} |
| 39 |
| 40 void TestGpuChannelManagerDelegate::GpuMemoryUmaStats( |
| 41 const GPUMemoryUmaStats& params) {} |
| 42 |
| 43 void TestGpuChannelManagerDelegate::RemoveSubscription(int32_t client_id, |
| 44 unsigned int target) {} |
| 45 |
| 46 void TestGpuChannelManagerDelegate::StoreShaderToDisk( |
| 47 int32_t client_id, |
| 48 const std::string& key, |
| 49 const std::string& shader) {} |
| 50 |
| 51 #if defined(OS_MACOSX) |
| 52 void TestGpuChannelManagerDelegate::SendAcceleratedSurfaceBuffersSwapped( |
| 53 const AcceleratedSurfaceBuffersSwappedParams& params) {} |
| 54 #endif |
| 55 |
| 56 #if defined(OS_WIN) |
| 57 void TestGpuChannelManagerDelegate::SendAcceleratedSurfaceCreatedChildWindow( |
| 58 const gfx::PluginWindowHandle& parent_window, |
| 59 const gfx::PluginWindowHandle& child_window) {} |
| 60 #endif |
| 61 |
14 TestGpuChannelManager::TestGpuChannelManager( | 62 TestGpuChannelManager::TestGpuChannelManager( |
15 IPC::TestSink* sink, | 63 GpuChannelManagerDelegate* delegate, |
16 base::SingleThreadTaskRunner* task_runner, | 64 base::SingleThreadTaskRunner* task_runner, |
17 base::SingleThreadTaskRunner* io_task_runner, | 65 base::SingleThreadTaskRunner* io_task_runner, |
18 gpu::SyncPointManager* sync_point_manager, | 66 gpu::SyncPointManager* sync_point_manager, |
19 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 67 GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
20 : GpuChannelManager(nullptr, | 68 : GpuChannelManager(delegate, |
21 nullptr, | 69 nullptr, |
22 task_runner, | 70 task_runner, |
23 io_task_runner, | 71 io_task_runner, |
24 nullptr, | 72 nullptr, |
25 sync_point_manager, | 73 sync_point_manager, |
26 gpu_memory_buffer_factory), | 74 gpu_memory_buffer_factory) {} |
27 sink_(sink) {} | |
28 | 75 |
29 TestGpuChannelManager::~TestGpuChannelManager() { | 76 TestGpuChannelManager::~TestGpuChannelManager() { |
30 // Clear gpu channels here so that any IPC messages sent are handled using the | 77 // Clear gpu channels here so that any IPC messages sent are handled using the |
31 // overridden Send method. | 78 // overridden Send method. |
32 gpu_channels_.clear(); | 79 gpu_channels_.clear(); |
33 } | 80 } |
34 | 81 |
35 bool TestGpuChannelManager::Send(IPC::Message* msg) { | |
36 return sink_->Send(msg); | |
37 } | |
38 | |
39 scoped_ptr<GpuChannel> TestGpuChannelManager::CreateGpuChannel( | 82 scoped_ptr<GpuChannel> TestGpuChannelManager::CreateGpuChannel( |
40 int client_id, | 83 int client_id, |
41 uint64_t client_tracing_id, | 84 uint64_t client_tracing_id, |
42 bool preempts, | 85 bool preempts, |
43 bool allow_view_command_buffers, | 86 bool allow_view_command_buffers, |
44 bool allow_real_time_streams) { | 87 bool allow_real_time_streams) { |
45 return make_scoped_ptr(new TestGpuChannel( | 88 return make_scoped_ptr(new TestGpuChannel( |
46 sink_, this, sync_point_manager(), share_group(), mailbox_manager(), | 89 this, sync_point_manager(), share_group(), mailbox_manager(), |
47 preempts ? preemption_flag() : nullptr, task_runner_.get(), | 90 preempts ? preemption_flag() : nullptr, task_runner_.get(), |
48 io_task_runner_.get(), client_id, client_tracing_id, | 91 io_task_runner_.get(), client_id, client_tracing_id, |
49 allow_view_command_buffers, allow_real_time_streams)); | 92 allow_view_command_buffers, allow_real_time_streams)); |
50 } | 93 } |
51 | 94 |
52 TestGpuChannel::TestGpuChannel(IPC::TestSink* sink, | 95 TestGpuChannel::TestGpuChannel(GpuChannelManager* gpu_channel_manager, |
53 GpuChannelManager* gpu_channel_manager, | |
54 gpu::SyncPointManager* sync_point_manager, | 96 gpu::SyncPointManager* sync_point_manager, |
55 gfx::GLShareGroup* share_group, | 97 gfx::GLShareGroup* share_group, |
56 gpu::gles2::MailboxManager* mailbox_manager, | 98 gpu::gles2::MailboxManager* mailbox_manager, |
57 gpu::PreemptionFlag* preempting_flag, | 99 gpu::PreemptionFlag* preempting_flag, |
58 base::SingleThreadTaskRunner* task_runner, | 100 base::SingleThreadTaskRunner* task_runner, |
59 base::SingleThreadTaskRunner* io_task_runner, | 101 base::SingleThreadTaskRunner* io_task_runner, |
60 int client_id, | 102 int client_id, |
61 uint64_t client_tracing_id, | 103 uint64_t client_tracing_id, |
62 bool allow_view_command_buffers, | 104 bool allow_view_command_buffers, |
63 bool allow_real_time_streams) | 105 bool allow_real_time_streams) |
64 : GpuChannel(gpu_channel_manager, | 106 : GpuChannel(gpu_channel_manager, |
65 sync_point_manager, | 107 sync_point_manager, |
66 nullptr, | 108 nullptr, |
67 share_group, | 109 share_group, |
68 mailbox_manager, | 110 mailbox_manager, |
69 preempting_flag, | 111 preempting_flag, |
70 task_runner, | 112 task_runner, |
71 io_task_runner, | 113 io_task_runner, |
72 client_id, | 114 client_id, |
73 client_tracing_id, | 115 client_tracing_id, |
74 allow_view_command_buffers, | 116 allow_view_command_buffers, |
75 allow_real_time_streams), | 117 allow_real_time_streams) {} |
76 sink_(sink) {} | |
77 | 118 |
78 TestGpuChannel::~TestGpuChannel() { | 119 TestGpuChannel::~TestGpuChannel() { |
79 // Call stubs here so that any IPC messages sent are handled using the | 120 // Call stubs here so that any IPC messages sent are handled using the |
80 // overridden Send method. | 121 // overridden Send method. |
81 stubs_.clear(); | 122 stubs_.clear(); |
82 } | 123 } |
83 | 124 |
84 base::ProcessId TestGpuChannel::GetClientPID() const { | 125 base::ProcessId TestGpuChannel::GetClientPID() const { |
85 return base::kNullProcessId; | 126 return base::kNullProcessId; |
86 } | 127 } |
87 | 128 |
88 IPC::ChannelHandle TestGpuChannel::Init(base::WaitableEvent* shutdown_event) { | 129 IPC::ChannelHandle TestGpuChannel::Init(base::WaitableEvent* shutdown_event) { |
89 filter_->OnFilterAdded(sink_); | 130 filter_->OnFilterAdded(&sink_); |
90 return IPC::ChannelHandle(channel_id()); | 131 return IPC::ChannelHandle(channel_id()); |
91 } | 132 } |
92 | 133 |
93 bool TestGpuChannel::Send(IPC::Message* msg) { | 134 bool TestGpuChannel::Send(IPC::Message* msg) { |
94 DCHECK(!msg->is_sync()); | 135 DCHECK(!msg->is_sync()); |
95 return sink_->Send(msg); | 136 return sink_.Send(msg); |
96 } | 137 } |
97 | 138 |
98 // TODO(sunnyps): Use a mock memory buffer factory when necessary. | 139 // TODO(sunnyps): Use a mock memory buffer factory when necessary. |
99 GpuChannelTestCommon::GpuChannelTestCommon() | 140 GpuChannelTestCommon::GpuChannelTestCommon() |
100 : sink_(new IPC::TestSink), | 141 : task_runner_(new base::TestSimpleTaskRunner), |
101 task_runner_(new base::TestSimpleTaskRunner), | |
102 io_task_runner_(new base::TestSimpleTaskRunner), | 142 io_task_runner_(new base::TestSimpleTaskRunner), |
103 sync_point_manager_(new gpu::SyncPointManager(false)), | 143 sync_point_manager_(new gpu::SyncPointManager(false)), |
104 channel_manager_(new TestGpuChannelManager(sink_.get(), | 144 channel_manager_delegate_(new TestGpuChannelManagerDelegate()), |
105 task_runner_.get(), | 145 channel_manager_( |
106 io_task_runner_.get(), | 146 new TestGpuChannelManager(channel_manager_delegate_.get(), |
107 sync_point_manager_.get(), | 147 task_runner_.get(), |
108 nullptr)) {} | 148 io_task_runner_.get(), |
| 149 sync_point_manager_.get(), |
| 150 nullptr)) {} |
109 | 151 |
110 GpuChannelTestCommon::~GpuChannelTestCommon() {} | 152 GpuChannelTestCommon::~GpuChannelTestCommon() {} |
111 | 153 |
112 } // namespace content | 154 } // namespace content |
OLD | NEW |