Fix OOP <webview> resize and autosize.
[chromium-blink-merge.git] / ui / ozone / public / ozone_gpu_test_helper.cc
blob8490a322c2f638e931060326296115412ef864c6
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"
16 namespace ui {
18 namespace {
20 const int kGpuProcessHostId = 1;
22 } // namespace
24 static void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) {
25 ui::OzonePlatform::GetInstance()
26 ->GetGpuPlatformSupportHost()
27 ->OnMessageReceived(*msg);
28 delete msg;
31 class FakeGpuProcess : public IPC::Sender {
32 public:
33 FakeGpuProcess(
34 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
35 : ui_task_runner_(ui_task_runner) {}
36 ~FakeGpuProcess() override {}
38 void Init() {
39 ui::OzonePlatform::GetInstance()
40 ->GetGpuPlatformSupport()
41 ->OnChannelEstablished(this);
44 void InitOnIO() {
45 IPC::MessageFilter* filter = ui::OzonePlatform::GetInstance()
46 ->GetGpuPlatformSupport()
47 ->GetMessageFilter();
49 if (filter)
50 filter->OnFilterAdded(this);
53 bool Send(IPC::Message* msg) override {
54 ui_task_runner_->PostTask(
55 FROM_HERE, base::Bind(&DispatchToGpuPlatformSupportHostTask, msg));
56 return true;
59 private:
60 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
63 static void DispatchToGpuPlatformSupportTask(IPC::Message* msg) {
64 ui::OzonePlatform::GetInstance()->GetGpuPlatformSupport()->OnMessageReceived(
65 *msg);
66 delete msg;
69 class FakeGpuProcessHost {
70 public:
71 FakeGpuProcessHost(
72 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner)
73 : gpu_task_runner_(gpu_task_runner) {}
74 ~FakeGpuProcessHost() {}
76 void Init() {
77 base::Callback<void(IPC::Message*)> sender =
78 base::Bind(&DispatchToGpuPlatformSupportTask);
80 ui::OzonePlatform::GetInstance()
81 ->GetGpuPlatformSupportHost()
82 ->OnChannelEstablished(kGpuProcessHostId, gpu_task_runner_, sender);
85 private:
86 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
89 OzoneGpuTestHelper::OzoneGpuTestHelper() {
92 OzoneGpuTestHelper::~OzoneGpuTestHelper() {
95 bool OzoneGpuTestHelper::Initialize(
96 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
97 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner) {
98 io_helper_thread_.reset(new base::Thread("IOHelperThread"));
99 if (!io_helper_thread_->StartWithOptions(
100 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
101 return false;
103 fake_gpu_process_.reset(new FakeGpuProcess(ui_task_runner));
104 io_helper_thread_->task_runner()->PostTask(
105 FROM_HERE, base::Bind(&FakeGpuProcess::InitOnIO,
106 base::Unretained(fake_gpu_process_.get())));
107 fake_gpu_process_->Init();
109 fake_gpu_process_host_.reset(new FakeGpuProcessHost(gpu_task_runner));
110 fake_gpu_process_host_->Init();
112 return true;
115 } // namespace ui