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, | 90 preempts ? preemption_flag() : nullptr, |
48 preempts ? nullptr : preemption_flag(), task_runner_.get(), | 91 preempts ? nullptr : preemption_flag(), task_runner_.get(), |
49 io_task_runner_.get(), client_id, client_tracing_id, | 92 io_task_runner_.get(), client_id, client_tracing_id, |
50 allow_view_command_buffers, allow_real_time_streams)); | 93 allow_view_command_buffers, allow_real_time_streams)); |
51 } | 94 } |
52 | 95 |
53 TestGpuChannel::TestGpuChannel(IPC::TestSink* sink, | 96 TestGpuChannel::TestGpuChannel(GpuChannelManager* gpu_channel_manager, |
54 GpuChannelManager* gpu_channel_manager, | |
55 gpu::SyncPointManager* sync_point_manager, | 97 gpu::SyncPointManager* sync_point_manager, |
56 gfx::GLShareGroup* share_group, | 98 gfx::GLShareGroup* share_group, |
57 gpu::gles2::MailboxManager* mailbox_manager, | 99 gpu::gles2::MailboxManager* mailbox_manager, |
58 gpu::PreemptionFlag* preempting_flag, | 100 gpu::PreemptionFlag* preempting_flag, |
59 gpu::PreemptionFlag* preempted_flag, | 101 gpu::PreemptionFlag* preempted_flag, |
60 base::SingleThreadTaskRunner* task_runner, | 102 base::SingleThreadTaskRunner* task_runner, |
61 base::SingleThreadTaskRunner* io_task_runner, | 103 base::SingleThreadTaskRunner* io_task_runner, |
62 int client_id, | 104 int client_id, |
63 uint64_t client_tracing_id, | 105 uint64_t client_tracing_id, |
64 bool allow_view_command_buffers, | 106 bool allow_view_command_buffers, |
65 bool allow_real_time_streams) | 107 bool allow_real_time_streams) |
66 : GpuChannel(gpu_channel_manager, | 108 : GpuChannel(gpu_channel_manager, |
67 sync_point_manager, | 109 sync_point_manager, |
68 nullptr, | 110 nullptr, |
69 share_group, | 111 share_group, |
70 mailbox_manager, | 112 mailbox_manager, |
71 preempting_flag, | 113 preempting_flag, |
72 preempted_flag, | 114 preempted_flag, |
73 task_runner, | 115 task_runner, |
74 io_task_runner, | 116 io_task_runner, |
75 client_id, | 117 client_id, |
76 client_tracing_id, | 118 client_tracing_id, |
77 allow_view_command_buffers, | 119 allow_view_command_buffers, |
78 allow_real_time_streams), | 120 allow_real_time_streams) {} |
79 sink_(sink) {} | |
80 | 121 |
81 TestGpuChannel::~TestGpuChannel() { | 122 TestGpuChannel::~TestGpuChannel() { |
82 // Call stubs here so that any IPC messages sent are handled using the | 123 // Call stubs here so that any IPC messages sent are handled using the |
83 // overridden Send method. | 124 // overridden Send method. |
84 stubs_.clear(); | 125 stubs_.clear(); |
85 } | 126 } |
86 | 127 |
87 base::ProcessId TestGpuChannel::GetClientPID() const { | 128 base::ProcessId TestGpuChannel::GetClientPID() const { |
88 return base::kNullProcessId; | 129 return base::kNullProcessId; |
89 } | 130 } |
90 | 131 |
91 IPC::ChannelHandle TestGpuChannel::Init(base::WaitableEvent* shutdown_event) { | 132 IPC::ChannelHandle TestGpuChannel::Init(base::WaitableEvent* shutdown_event) { |
92 filter_->OnFilterAdded(sink_); | 133 filter_->OnFilterAdded(&sink_); |
93 return IPC::ChannelHandle(channel_id()); | 134 return IPC::ChannelHandle(channel_id()); |
94 } | 135 } |
95 | 136 |
96 bool TestGpuChannel::Send(IPC::Message* msg) { | 137 bool TestGpuChannel::Send(IPC::Message* msg) { |
97 DCHECK(!msg->is_sync()); | 138 DCHECK(!msg->is_sync()); |
98 return sink_->Send(msg); | 139 return sink_.Send(msg); |
99 } | 140 } |
100 | 141 |
101 // TODO(sunnyps): Use a mock memory buffer factory when necessary. | 142 // TODO(sunnyps): Use a mock memory buffer factory when necessary. |
102 GpuChannelTestCommon::GpuChannelTestCommon() | 143 GpuChannelTestCommon::GpuChannelTestCommon() |
103 : sink_(new IPC::TestSink), | 144 : task_runner_(new base::TestSimpleTaskRunner), |
104 task_runner_(new base::TestSimpleTaskRunner), | |
105 io_task_runner_(new base::TestSimpleTaskRunner), | 145 io_task_runner_(new base::TestSimpleTaskRunner), |
106 sync_point_manager_(new gpu::SyncPointManager(false)), | 146 sync_point_manager_(new gpu::SyncPointManager(false)), |
107 channel_manager_(new TestGpuChannelManager(sink_.get(), | 147 channel_manager_delegate_(new TestGpuChannelManagerDelegate()), |
108 task_runner_.get(), | 148 channel_manager_( |
109 io_task_runner_.get(), | 149 new TestGpuChannelManager(channel_manager_delegate_.get(), |
110 sync_point_manager_.get(), | 150 task_runner_.get(), |
111 nullptr)) {} | 151 io_task_runner_.get(), |
| 152 sync_point_manager_.get(), |
| 153 nullptr)) {} |
112 | 154 |
113 GpuChannelTestCommon::~GpuChannelTestCommon() { | 155 GpuChannelTestCommon::~GpuChannelTestCommon() { |
114 // Destroying channels causes tasks to run on the IO task runner. | 156 // Destroying channels causes tasks to run on the IO task runner. |
115 channel_manager_ = nullptr; | 157 channel_manager_ = nullptr; |
116 // Clear pending tasks to avoid refptr cycles that get flagged by ASAN. | 158 // Clear pending tasks to avoid refptr cycles that get flagged by ASAN. |
117 task_runner_->ClearPendingTasks(); | 159 task_runner_->ClearPendingTasks(); |
118 io_task_runner_->ClearPendingTasks(); | 160 io_task_runner_->ClearPendingTasks(); |
119 } | 161 } |
120 | 162 |
121 } // namespace content | 163 } // namespace content |
OLD | NEW |