OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/gpu/gpu_channel_test_common.h" |
| 6 |
| 7 #include "base/test/test_simple_task_runner.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" |
| 11 #include "ipc/ipc_test_sink.h" |
| 12 #include "url/gurl.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 TestGpuChannelManagerDelegate::TestGpuChannelManagerDelegate() {} |
| 17 |
| 18 TestGpuChannelManagerDelegate::~TestGpuChannelManagerDelegate() {} |
| 19 |
| 20 void TestGpuChannelManagerDelegate::SetActiveURL(const GURL& url) {} |
| 21 |
| 22 void TestGpuChannelManagerDelegate::AddSubscription(int32_t client_id, |
| 23 unsigned int target) {} |
| 24 |
| 25 void TestGpuChannelManagerDelegate::DidCreateOffscreenContext( |
| 26 const GURL& active_url) {} |
| 27 |
| 28 void TestGpuChannelManagerDelegate::DidDestroyChannel(int client_id) {} |
| 29 |
| 30 void TestGpuChannelManagerDelegate::DidDestroyOffscreenContext( |
| 31 const GURL& active_url) {} |
| 32 |
| 33 void TestGpuChannelManagerDelegate::DidLoseContext( |
| 34 bool offscreen, |
| 35 gpu::error::ContextLostReason reason, |
| 36 const GURL& active_url) {} |
| 37 |
| 38 void TestGpuChannelManagerDelegate::GpuMemoryUmaStats( |
| 39 const gpu::GPUMemoryUmaStats& params) {} |
| 40 |
| 41 void TestGpuChannelManagerDelegate::RemoveSubscription(int32_t client_id, |
| 42 unsigned int target) {} |
| 43 |
| 44 void TestGpuChannelManagerDelegate::StoreShaderToDisk( |
| 45 int32_t client_id, |
| 46 const std::string& key, |
| 47 const std::string& shader) {} |
| 48 |
| 49 #if defined(OS_MACOSX) |
| 50 void TestGpuChannelManagerDelegate::SendAcceleratedSurfaceBuffersSwapped( |
| 51 int32_t surface_id, |
| 52 CAContextID ca_context_id, |
| 53 const gfx::ScopedRefCountedIOSurfaceMachPort& io_surface, |
| 54 const gfx::Size& size, |
| 55 float scale_factor, |
| 56 std::vector<ui::LatencyInfo> latency_info) {} |
| 57 #endif |
| 58 |
| 59 #if defined(OS_WIN) |
| 60 void TestGpuChannelManagerDelegate::SendAcceleratedSurfaceCreatedChildWindow( |
| 61 gpu::SurfaceHandle parent_window, |
| 62 gpu::SurfaceHandle child_window) {} |
| 63 #endif |
| 64 |
| 65 TestGpuChannelManager::TestGpuChannelManager( |
| 66 const gpu::GpuPreferences& gpu_preferences, |
| 67 GpuChannelManagerDelegate* delegate, |
| 68 base::SingleThreadTaskRunner* task_runner, |
| 69 base::SingleThreadTaskRunner* io_task_runner, |
| 70 gpu::SyncPointManager* sync_point_manager, |
| 71 GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
| 72 : GpuChannelManager(gpu_preferences, |
| 73 delegate, |
| 74 nullptr, |
| 75 task_runner, |
| 76 io_task_runner, |
| 77 nullptr, |
| 78 sync_point_manager, |
| 79 gpu_memory_buffer_factory) {} |
| 80 |
| 81 TestGpuChannelManager::~TestGpuChannelManager() { |
| 82 // Clear gpu channels here so that any IPC messages sent are handled using the |
| 83 // overridden Send method. |
| 84 gpu_channels_.clear(); |
| 85 } |
| 86 |
| 87 scoped_ptr<GpuChannel> TestGpuChannelManager::CreateGpuChannel( |
| 88 int client_id, |
| 89 uint64_t client_tracing_id, |
| 90 bool preempts, |
| 91 bool allow_view_command_buffers, |
| 92 bool allow_real_time_streams) { |
| 93 return make_scoped_ptr(new TestGpuChannel( |
| 94 this, sync_point_manager(), share_group(), mailbox_manager(), |
| 95 preempts ? preemption_flag() : nullptr, |
| 96 preempts ? nullptr : preemption_flag(), task_runner_.get(), |
| 97 io_task_runner_.get(), client_id, client_tracing_id, |
| 98 allow_view_command_buffers, allow_real_time_streams)); |
| 99 } |
| 100 |
| 101 TestGpuChannel::TestGpuChannel(GpuChannelManager* gpu_channel_manager, |
| 102 gpu::SyncPointManager* sync_point_manager, |
| 103 gfx::GLShareGroup* share_group, |
| 104 gpu::gles2::MailboxManager* mailbox_manager, |
| 105 gpu::PreemptionFlag* preempting_flag, |
| 106 gpu::PreemptionFlag* preempted_flag, |
| 107 base::SingleThreadTaskRunner* task_runner, |
| 108 base::SingleThreadTaskRunner* io_task_runner, |
| 109 int client_id, |
| 110 uint64_t client_tracing_id, |
| 111 bool allow_view_command_buffers, |
| 112 bool allow_real_time_streams) |
| 113 : GpuChannel(gpu_channel_manager, |
| 114 sync_point_manager, |
| 115 nullptr, |
| 116 share_group, |
| 117 mailbox_manager, |
| 118 preempting_flag, |
| 119 preempted_flag, |
| 120 task_runner, |
| 121 io_task_runner, |
| 122 client_id, |
| 123 client_tracing_id, |
| 124 allow_view_command_buffers, |
| 125 allow_real_time_streams) {} |
| 126 |
| 127 TestGpuChannel::~TestGpuChannel() { |
| 128 // Call stubs here so that any IPC messages sent are handled using the |
| 129 // overridden Send method. |
| 130 stubs_.clear(); |
| 131 } |
| 132 |
| 133 base::ProcessId TestGpuChannel::GetClientPID() const { |
| 134 return base::kNullProcessId; |
| 135 } |
| 136 |
| 137 IPC::ChannelHandle TestGpuChannel::Init(base::WaitableEvent* shutdown_event) { |
| 138 filter_->OnFilterAdded(&sink_); |
| 139 return IPC::ChannelHandle(channel_id()); |
| 140 } |
| 141 |
| 142 bool TestGpuChannel::Send(IPC::Message* msg) { |
| 143 DCHECK(!msg->is_sync()); |
| 144 return sink_.Send(msg); |
| 145 } |
| 146 |
| 147 // TODO(sunnyps): Use a mock memory buffer factory when necessary. |
| 148 GpuChannelTestCommon::GpuChannelTestCommon() |
| 149 : task_runner_(new base::TestSimpleTaskRunner), |
| 150 io_task_runner_(new base::TestSimpleTaskRunner), |
| 151 sync_point_manager_(new gpu::SyncPointManager(false)), |
| 152 channel_manager_delegate_(new TestGpuChannelManagerDelegate()), |
| 153 channel_manager_( |
| 154 new TestGpuChannelManager(gpu_preferences_, |
| 155 channel_manager_delegate_.get(), |
| 156 task_runner_.get(), |
| 157 io_task_runner_.get(), |
| 158 sync_point_manager_.get(), |
| 159 nullptr)) {} |
| 160 |
| 161 GpuChannelTestCommon::~GpuChannelTestCommon() { |
| 162 // Destroying channels causes tasks to run on the IO task runner. |
| 163 channel_manager_ = nullptr; |
| 164 // Clear pending tasks to avoid refptr cycles that get flagged by ASAN. |
| 165 task_runner_->ClearPendingTasks(); |
| 166 io_task_runner_->ClearPendingTasks(); |
| 167 } |
| 168 |
| 169 } // namespace content |
OLD | NEW |