blob: fe88647a8a3d2086d4f7a0eef829e9bbd72a866f (
plain)
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
|
// Copyright 2014 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 "ui/ozone/public/ozone_gpu_test_helper.h"
#include "base/thread_task_runner_handle.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_sender.h"
#include "ipc/message_filter.h"
#include "ui/ozone/public/gpu_platform_support.h"
#include "ui/ozone/public/gpu_platform_support_host.h"
#include "ui/ozone/public/ozone_platform.h"
namespace ui {
namespace {
const int kGpuProcessHostId = 1;
} // namespace
static void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) {
ui::OzonePlatform::GetInstance()
->GetGpuPlatformSupportHost()
->OnMessageReceived(*msg);
delete msg;
}
class FakeGpuProcess : public IPC::Sender {
public:
FakeGpuProcess(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
: ui_task_runner_(ui_task_runner) {}
~FakeGpuProcess() override {}
void Init() {
ui::OzonePlatform::GetInstance()
->GetGpuPlatformSupport()
->OnChannelEstablished(this);
}
void InitOnIO() {
ui::OzonePlatform::GetInstance()
->GetGpuPlatformSupport()
->GetMessageFilter()
->OnFilterAdded(this);
}
bool Send(IPC::Message* msg) override {
ui_task_runner_->PostTask(
FROM_HERE, base::Bind(&DispatchToGpuPlatformSupportHostTask, msg));
return true;
}
private:
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
};
static void DispatchToGpuPlatformSupportTask(IPC::Message* msg) {
ui::OzonePlatform::GetInstance()->GetGpuPlatformSupport()->OnMessageReceived(
*msg);
delete msg;
}
class FakeGpuProcessHost {
public:
FakeGpuProcessHost(
const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner)
: gpu_task_runner_(gpu_task_runner) {}
~FakeGpuProcessHost() {}
void Init() {
base::Callback<void(IPC::Message*)> sender =
base::Bind(&DispatchToGpuPlatformSupportTask);
ui::OzonePlatform::GetInstance()
->GetGpuPlatformSupportHost()
->OnChannelEstablished(kGpuProcessHostId, gpu_task_runner_, sender);
}
private:
scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
};
OzoneGpuTestHelper::OzoneGpuTestHelper() {
}
OzoneGpuTestHelper::~OzoneGpuTestHelper() {
}
bool OzoneGpuTestHelper::Initialize(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner) {
io_helper_thread_.reset(new base::Thread("IOHelperThread"));
if (!io_helper_thread_->StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
return false;
fake_gpu_process_.reset(new FakeGpuProcess(ui_task_runner));
io_helper_thread_->task_runner()->PostTask(
FROM_HERE, base::Bind(&FakeGpuProcess::InitOnIO,
base::Unretained(fake_gpu_process_.get())));
fake_gpu_process_->Init();
fake_gpu_process_host_.reset(new FakeGpuProcessHost(gpu_task_runner));
fake_gpu_process_host_->Init();
return true;
}
} // namespace ui
|