1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/common/gpu/gpu_channel_test_common.h"
#include "base/test/test_simple_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "ipc/ipc_test_sink.h"
namespace content {
TestGpuChannelManager::TestGpuChannelManager(
IPC::TestSink* sink,
base::SingleThreadTaskRunner* task_runner,
base::SingleThreadTaskRunner* io_task_runner,
gpu::SyncPointManager* sync_point_manager,
GpuMemoryBufferFactory* gpu_memory_buffer_factory)
: GpuChannelManager(nullptr,
nullptr,
task_runner,
io_task_runner,
nullptr,
sync_point_manager,
gpu_memory_buffer_factory),
sink_(sink) {}
TestGpuChannelManager::~TestGpuChannelManager() {
// Clear gpu channels here so that any IPC messages sent are handled using the
// overridden Send method.
gpu_channels_.clear();
}
bool TestGpuChannelManager::Send(IPC::Message* msg) {
return sink_->Send(msg);
}
scoped_ptr<GpuChannel> TestGpuChannelManager::CreateGpuChannel(
int client_id,
uint64_t client_tracing_id,
bool preempts,
bool allow_view_command_buffers,
bool allow_real_time_streams) {
return make_scoped_ptr(new TestGpuChannel(
sink_, this, sync_point_manager(), share_group(), mailbox_manager(),
preempts ? preemption_flag() : nullptr,
preempts ? nullptr : preemption_flag(), task_runner_.get(),
io_task_runner_.get(), client_id, client_tracing_id,
allow_view_command_buffers, allow_real_time_streams));
}
TestGpuChannel::TestGpuChannel(IPC::TestSink* sink,
GpuChannelManager* gpu_channel_manager,
gpu::SyncPointManager* sync_point_manager,
gfx::GLShareGroup* share_group,
gpu::gles2::MailboxManager* mailbox_manager,
gpu::PreemptionFlag* preempting_flag,
gpu::PreemptionFlag* preempted_flag,
base::SingleThreadTaskRunner* task_runner,
base::SingleThreadTaskRunner* io_task_runner,
int client_id,
uint64_t client_tracing_id,
bool allow_view_command_buffers,
bool allow_real_time_streams)
: GpuChannel(gpu_channel_manager,
sync_point_manager,
nullptr,
share_group,
mailbox_manager,
preempting_flag,
preempted_flag,
task_runner,
io_task_runner,
client_id,
client_tracing_id,
allow_view_command_buffers,
allow_real_time_streams),
sink_(sink) {}
TestGpuChannel::~TestGpuChannel() {
// Call stubs here so that any IPC messages sent are handled using the
// overridden Send method.
stubs_.clear();
}
base::ProcessId TestGpuChannel::GetClientPID() const {
return base::kNullProcessId;
}
IPC::ChannelHandle TestGpuChannel::Init(base::WaitableEvent* shutdown_event) {
filter_->OnFilterAdded(sink_);
return IPC::ChannelHandle(channel_id());
}
bool TestGpuChannel::Send(IPC::Message* msg) {
DCHECK(!msg->is_sync());
return sink_->Send(msg);
}
// TODO(sunnyps): Use a mock memory buffer factory when necessary.
GpuChannelTestCommon::GpuChannelTestCommon()
: sink_(new IPC::TestSink),
task_runner_(new base::TestSimpleTaskRunner),
io_task_runner_(new base::TestSimpleTaskRunner),
sync_point_manager_(new gpu::SyncPointManager(false)),
channel_manager_(new TestGpuChannelManager(sink_.get(),
task_runner_.get(),
io_task_runner_.get(),
sync_point_manager_.get(),
nullptr)) {}
GpuChannelTestCommon::~GpuChannelTestCommon() {
// Destroying channels causes tasks to run on the IO task runner.
channel_manager_ = nullptr;
// Clear pending tasks to avoid refptr cycles that get flagged by ASAN.
task_runner_->ClearPendingTasks();
io_task_runner_->ClearPendingTasks();
}
} // namespace content
|