OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "ui/ozone/public/ui_thread_gpu.h" | |
6 | |
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" | |
15 | |
16 namespace ui { | |
17 | |
18 namespace { | |
19 | |
20 const int kGpuProcessHostId = 1; | |
21 | |
22 } // namespace | |
23 | |
24 class FakeGpuProcess : public IPC::Sender { | |
25 public: | |
26 FakeGpuProcess() : weak_factory_(this) {} | |
27 ~FakeGpuProcess() override {} | |
28 | |
29 void Init() { | |
30 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | |
31 | |
32 ui::OzonePlatform::GetInstance() | |
33 ->GetGpuPlatformSupport() | |
34 ->OnChannelEstablished(this); | |
35 } | |
36 | |
37 void InitOnIO() { | |
38 ui::OzonePlatform::GetInstance() | |
39 ->GetGpuPlatformSupport() | |
40 ->GetMessageFilter() | |
41 ->OnFilterAdded(this); | |
42 } | |
43 | |
44 bool Send(IPC::Message* msg) override { | |
45 DCHECK(task_runner_->BelongsToCurrentThread()); | |
46 base::MessageLoop::current()->PostTask( | |
47 FROM_HERE, | |
48 base::Bind(&FakeGpuProcess::DispatchToGpuPlatformSupportHostTask, | |
49 weak_factory_.GetWeakPtr(), msg)); | |
50 return true; | |
51 } | |
52 | |
53 private: | |
54 void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) { | |
55 ui::OzonePlatform::GetInstance() | |
56 ->GetGpuPlatformSupportHost() | |
57 ->OnMessageReceived(*msg); | |
58 delete msg; | |
59 } | |
60 | |
61 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
62 base::WeakPtrFactory<FakeGpuProcess> weak_factory_; | |
63 }; | |
64 | |
65 class FakeGpuProcessHost { | |
66 public: | |
67 FakeGpuProcessHost() : weak_factory_(this) {} | |
68 ~FakeGpuProcessHost() {} | |
69 | |
70 void Init() { | |
71 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | |
72 | |
73 base::Callback<void(IPC::Message*)> sender = | |
74 base::Bind(&FakeGpuProcessHost::DispatchToGpuPlatformSupportTask, | |
75 weak_factory_.GetWeakPtr()); | |
76 | |
77 ui::OzonePlatform::GetInstance() | |
78 ->GetGpuPlatformSupportHost() | |
79 ->OnChannelEstablished(kGpuProcessHostId, task_runner_, sender); | |
80 } | |
81 | |
82 private: | |
83 void DispatchToGpuPlatformSupportTask(IPC::Message* msg) { | |
84 DCHECK(task_runner_->BelongsToCurrentThread()); | |
85 ui::OzonePlatform::GetInstance() | |
86 ->GetGpuPlatformSupport() | |
87 ->OnMessageReceived(*msg); | |
88 delete msg; | |
89 } | |
90 | |
91 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
92 base::WeakPtrFactory<FakeGpuProcessHost> weak_factory_; | |
93 }; | |
94 | |
95 UiThreadGpu::UiThreadGpu() { | |
96 } | |
97 | |
98 UiThreadGpu::~UiThreadGpu() { | |
99 } | |
100 | |
101 bool UiThreadGpu::Initialize() { | |
102 io_helper_thread_.reset(new base::Thread("IOHelperThread")); | |
103 if (!io_helper_thread_->StartWithOptions( | |
104 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) | |
105 return false; | |
106 | |
107 fake_gpu_process_.reset(new FakeGpuProcess); | |
108 io_helper_thread_->task_runner()->PostTask( | |
109 FROM_HERE, base::Bind(&FakeGpuProcess::InitOnIO, | |
110 base::Unretained(fake_gpu_process_.get()))); | |
111 fake_gpu_process_->Init(); | |
112 | |
113 fake_gpu_process_host_.reset(new FakeGpuProcessHost); | |
114 fake_gpu_process_host_->Init(); | |
115 | |
116 return true; | |
117 } | |
118 | |
119 } // namespace ui | |
OLD | NEW |