Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / common / gpu / gpu_channel_test_common.cc
blob5925a5492db1da276876820ff146a48dbfc6027b
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.
5 #include "content/common/gpu/gpu_channel_test_common.h"
7 #include "base/test/test_simple_task_runner.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "gpu/command_buffer/service/sync_point_manager.h"
10 #include "ipc/ipc_test_sink.h"
12 namespace content {
14 TestGpuChannelManager::TestGpuChannelManager(
15 IPC::TestSink* sink,
16 base::SingleThreadTaskRunner* task_runner,
17 base::SingleThreadTaskRunner* io_task_runner,
18 gpu::SyncPointManager* sync_point_manager,
19 GpuMemoryBufferFactory* gpu_memory_buffer_factory)
20 : GpuChannelManager(nullptr,
21 nullptr,
22 task_runner,
23 io_task_runner,
24 nullptr,
25 sync_point_manager,
26 gpu_memory_buffer_factory),
27 sink_(sink) {}
29 TestGpuChannelManager::~TestGpuChannelManager() {
30 // Clear gpu channels here so that any IPC messages sent are handled using the
31 // overridden Send method.
32 gpu_channels_.clear();
35 bool TestGpuChannelManager::Send(IPC::Message* msg) {
36 return sink_->Send(msg);
39 scoped_ptr<GpuChannel> TestGpuChannelManager::CreateGpuChannel(
40 gfx::GLShareGroup* share_group,
41 gpu::gles2::MailboxManager* mailbox_manager,
42 int client_id,
43 uint64_t client_tracing_id,
44 bool allow_future_sync_points,
45 bool allow_real_time_streams) {
46 return make_scoped_ptr(new TestGpuChannel(
47 sink_, this, share_group, mailbox_manager, task_runner_.get(),
48 io_task_runner_.get(), client_id, client_tracing_id,
49 allow_future_sync_points, allow_real_time_streams));
52 TestGpuChannel::TestGpuChannel(IPC::TestSink* sink,
53 GpuChannelManager* gpu_channel_manager,
54 gfx::GLShareGroup* share_group,
55 gpu::gles2::MailboxManager* mailbox_manager,
56 base::SingleThreadTaskRunner* task_runner,
57 base::SingleThreadTaskRunner* io_task_runner,
58 int client_id,
59 uint64_t client_tracing_id,
60 bool allow_future_sync_points,
61 bool allow_real_time_streams)
62 : GpuChannel(gpu_channel_manager,
63 nullptr,
64 share_group,
65 mailbox_manager,
66 task_runner,
67 io_task_runner,
68 client_id,
69 client_tracing_id,
70 false,
71 allow_future_sync_points,
72 allow_real_time_streams),
73 sink_(sink) {}
75 TestGpuChannel::~TestGpuChannel() {
76 // Call stubs here so that any IPC messages sent are handled using the
77 // overridden Send method.
78 stubs_.clear();
81 base::ProcessId TestGpuChannel::GetClientPID() const {
82 return base::kNullProcessId;
85 IPC::ChannelHandle TestGpuChannel::Init(base::WaitableEvent* shutdown_event) {
86 filter_->OnFilterAdded(sink_);
87 return IPC::ChannelHandle(channel_id());
90 bool TestGpuChannel::Send(IPC::Message* msg) {
91 DCHECK(!msg->is_sync());
92 return sink_->Send(msg);
95 // TODO(sunnyps): Use a mock memory buffer factory when necessary.
96 GpuChannelTestCommon::GpuChannelTestCommon()
97 : sink_(new IPC::TestSink),
98 task_runner_(new base::TestSimpleTaskRunner),
99 io_task_runner_(new base::TestSimpleTaskRunner),
100 sync_point_manager_(new gpu::SyncPointManager(false)),
101 channel_manager_(new TestGpuChannelManager(sink_.get(),
102 task_runner_.get(),
103 io_task_runner_.get(),
104 sync_point_manager_.get(),
105 nullptr)) {}
107 GpuChannelTestCommon::~GpuChannelTestCommon() {}
109 } // namespace content