1 // Copyright 2014 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 "ui/ozone/public/ozone_gpu_test_helper.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "ipc/ipc_listener.h"
9 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_sender.h"
11 #include "ipc/message_filter.h"
12 #include "ui/ozone/public/gpu_platform_support.h"
13 #include "ui/ozone/public/gpu_platform_support_host.h"
14 #include "ui/ozone/public/ozone_platform.h"
20 const int kGpuProcessHostId
= 1;
24 static void DispatchToGpuPlatformSupportHostTask(IPC::Message
* msg
) {
25 ui::OzonePlatform::GetInstance()
26 ->GetGpuPlatformSupportHost()
27 ->OnMessageReceived(*msg
);
31 class FakeGpuProcess
: public IPC::Sender
{
34 const scoped_refptr
<base::SingleThreadTaskRunner
>& ui_task_runner
)
35 : ui_task_runner_(ui_task_runner
) {}
36 ~FakeGpuProcess() override
{}
39 ui::OzonePlatform::GetInstance()
40 ->GetGpuPlatformSupport()
41 ->OnChannelEstablished(this);
45 ui::OzonePlatform::GetInstance()
46 ->GetGpuPlatformSupport()
48 ->OnFilterAdded(this);
51 bool Send(IPC::Message
* msg
) override
{
52 ui_task_runner_
->PostTask(
53 FROM_HERE
, base::Bind(&DispatchToGpuPlatformSupportHostTask
, msg
));
58 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner_
;
61 static void DispatchToGpuPlatformSupportTask(IPC::Message
* msg
) {
62 ui::OzonePlatform::GetInstance()->GetGpuPlatformSupport()->OnMessageReceived(
67 class FakeGpuProcessHost
{
70 const scoped_refptr
<base::SingleThreadTaskRunner
>& gpu_task_runner
)
71 : gpu_task_runner_(gpu_task_runner
) {}
72 ~FakeGpuProcessHost() {}
75 base::Callback
<void(IPC::Message
*)> sender
=
76 base::Bind(&DispatchToGpuPlatformSupportTask
);
78 ui::OzonePlatform::GetInstance()
79 ->GetGpuPlatformSupportHost()
80 ->OnChannelEstablished(kGpuProcessHostId
, gpu_task_runner_
, sender
);
84 scoped_refptr
<base::SingleThreadTaskRunner
> gpu_task_runner_
;
87 OzoneGpuTestHelper::OzoneGpuTestHelper() {
90 OzoneGpuTestHelper::~OzoneGpuTestHelper() {
93 bool OzoneGpuTestHelper::Initialize(
94 const scoped_refptr
<base::SingleThreadTaskRunner
>& ui_task_runner
,
95 const scoped_refptr
<base::SingleThreadTaskRunner
>& gpu_task_runner
) {
96 io_helper_thread_
.reset(new base::Thread("IOHelperThread"));
97 if (!io_helper_thread_
->StartWithOptions(
98 base::Thread::Options(base::MessageLoop::TYPE_IO
, 0)))
101 fake_gpu_process_
.reset(new FakeGpuProcess(ui_task_runner
));
102 io_helper_thread_
->task_runner()->PostTask(
103 FROM_HERE
, base::Bind(&FakeGpuProcess::InitOnIO
,
104 base::Unretained(fake_gpu_process_
.get())));
105 fake_gpu_process_
->Init();
107 fake_gpu_process_host_
.reset(new FakeGpuProcessHost(gpu_task_runner
));
108 fake_gpu_process_host_
->Init();