Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/ozone/public/ui_thread_gpu.h" | 5 #include "ui/ozone/public/ui_thread_gpu.h" |
| 6 | 6 |
| 7 #include "base/thread_task_runner_handle.h" | |
| 7 #include "ipc/ipc_listener.h" | 8 #include "ipc/ipc_listener.h" |
| 8 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
| 9 #include "ipc/ipc_sender.h" | 10 #include "ipc/ipc_sender.h" |
| 10 #include "ui/ozone/public/gpu_platform_support.h" | 11 #include "ui/ozone/public/gpu_platform_support.h" |
| 11 #include "ui/ozone/public/gpu_platform_support_host.h" | 12 #include "ui/ozone/public/gpu_platform_support_host.h" |
| 12 #include "ui/ozone/public/ozone_platform.h" | 13 #include "ui/ozone/public/ozone_platform.h" |
| 13 | 14 |
| 14 namespace ui { | 15 namespace ui { |
| 15 | 16 |
| 16 class UiThreadGpuForwardingSender : public IPC::Sender { | 17 namespace { |
| 18 | |
| 19 const int kGpuProcessHostId = 1; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 class FakeGpuProcess : public IPC::Sender { | |
| 17 public: | 24 public: |
| 18 explicit UiThreadGpuForwardingSender(IPC::Listener* listener) | 25 FakeGpuProcess() : weak_factory_(this) {} |
| 19 : listener_(listener) {} | 26 ~FakeGpuProcess() {} |
| 20 ~UiThreadGpuForwardingSender() override {} | |
| 21 | 27 |
| 22 // IPC::Sender: | 28 void Init() { |
| 29 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | |
| 30 ui::OzonePlatform::GetInstance() | |
| 31 ->GetGpuPlatformSupport() | |
| 32 ->OnChannelEstablished(this); | |
| 33 } | |
| 34 | |
| 23 bool Send(IPC::Message* msg) override { | 35 bool Send(IPC::Message* msg) override { |
| 24 listener_->OnMessageReceived(*msg); | 36 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 25 delete msg; | 37 base::MessageLoop::current()->PostTask( |
| 38 FROM_HERE, | |
| 39 base::Bind(&FakeGpuProcess::DispatchToGpuPlatformSupportHostTask, | |
| 40 weak_factory_.GetWeakPtr(), msg)); | |
| 26 return true; | 41 return true; |
| 27 } | 42 } |
| 28 | 43 |
| 29 private: | 44 private: |
| 30 IPC::Listener* listener_; | 45 void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) { |
| 46 ui::OzonePlatform::GetInstance() | |
| 47 ->GetGpuPlatformSupportHost() | |
| 48 ->OnMessageReceived(*msg); | |
| 49 delete msg; | |
| 50 } | |
| 51 | |
| 52 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 53 base::WeakPtrFactory<FakeGpuProcess> weak_factory_; | |
| 54 }; | |
| 55 | |
| 56 class FakeGpuProcessHost { | |
| 57 public: | |
| 58 FakeGpuProcessHost() : weak_factory_(this) {} | |
| 59 ~FakeGpuProcessHost() {} | |
| 60 | |
| 61 void Init() { | |
| 62 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | |
| 63 | |
| 64 base::Callback<void(IPC::Message*)> sender = | |
| 65 base::Bind(&FakeGpuProcessHost::DispatchToGpuPlatformSupportTask, | |
| 66 weak_factory_.GetWeakPtr()); | |
| 67 | |
| 68 ui::OzonePlatform::GetInstance() | |
| 69 ->GetGpuPlatformSupportHost() | |
| 70 ->OnChannelEstablished(kGpuProcessHostId, task_runner_, sender); | |
|
alexst (slow to review)
2015/01/09 21:53:08
You call them send_runner and send_callback in oth
| |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 void DispatchToGpuPlatformSupportTask(IPC::Message* msg) { | |
| 75 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 76 ui::OzonePlatform::GetInstance() | |
| 77 ->GetGpuPlatformSupport() | |
| 78 ->OnMessageReceived(*msg); | |
| 79 delete msg; | |
| 80 } | |
| 81 | |
| 82 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 83 base::WeakPtrFactory<FakeGpuProcessHost> weak_factory_; | |
| 31 }; | 84 }; |
| 32 | 85 |
| 33 UiThreadGpu::UiThreadGpu() { | 86 UiThreadGpu::UiThreadGpu() { |
| 34 } | 87 } |
| 35 | 88 |
| 36 UiThreadGpu::~UiThreadGpu() { | 89 UiThreadGpu::~UiThreadGpu() { |
| 37 } | 90 } |
| 38 | 91 |
| 39 bool UiThreadGpu::Initialize() { | 92 bool UiThreadGpu::Initialize() { |
| 40 OzonePlatform* platform = ui::OzonePlatform::GetInstance(); | 93 fake_gpu_process_.reset(new FakeGpuProcess); |
| 94 fake_gpu_process_->Init(); | |
| 41 | 95 |
| 42 ui_sender_.reset( | 96 fake_gpu_process_host_.reset(new FakeGpuProcessHost); |
| 43 new UiThreadGpuForwardingSender(platform->GetGpuPlatformSupportHost())); | 97 fake_gpu_process_host_->Init(); |
| 44 gpu_sender_.reset( | |
| 45 new UiThreadGpuForwardingSender(platform->GetGpuPlatformSupport())); | |
| 46 | |
| 47 const int kHostId = 1; | |
| 48 platform->GetGpuPlatformSupportHost()->OnChannelEstablished( | |
| 49 kHostId, gpu_sender_.get()); | |
| 50 platform->GetGpuPlatformSupport()->OnChannelEstablished(ui_sender_.get()); | |
| 51 | 98 |
| 52 return true; | 99 return true; |
| 53 } | 100 } |
| 54 | 101 |
| 55 } // namespace ui | 102 } // namespace ui |
| OLD | NEW |