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