Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: ui/ozone/public/ozone_gpu_test_helper.cc

Issue 1017673003: Simplify FakeGpuProcess* video accelerator tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DispatchToGpuPlatformSupportTask & DispatchToGpuPlatformSupportHostTask static Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ozone_gpu_test_helper.h" 5 #include "ui/ozone/public/ozone_gpu_test_helper.h"
6 6
7 #include "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "ipc/ipc_listener.h" 8 #include "ipc/ipc_listener.h"
9 #include "ipc/ipc_message.h" 9 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_sender.h" 10 #include "ipc/ipc_sender.h"
11 #include "ipc/message_filter.h" 11 #include "ipc/message_filter.h"
12 #include "ui/ozone/public/gpu_platform_support.h" 12 #include "ui/ozone/public/gpu_platform_support.h"
13 #include "ui/ozone/public/gpu_platform_support_host.h" 13 #include "ui/ozone/public/gpu_platform_support_host.h"
14 #include "ui/ozone/public/ozone_platform.h" 14 #include "ui/ozone/public/ozone_platform.h"
15 15
16 namespace ui { 16 namespace ui {
17 17
18 namespace { 18 namespace {
19 19
20 const int kGpuProcessHostId = 1; 20 const int kGpuProcessHostId = 1;
21 21
22 } // namespace 22 } // namespace
23 23
24 static void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) {
25 ui::OzonePlatform::GetInstance()
26 ->GetGpuPlatformSupportHost()
27 ->OnMessageReceived(*msg);
28 delete msg;
29 }
30
24 class FakeGpuProcess : public IPC::Sender { 31 class FakeGpuProcess : public IPC::Sender {
25 public: 32 public:
26 FakeGpuProcess( 33 FakeGpuProcess(
27 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) 34 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
28 : ui_task_runner_(ui_task_runner), weak_factory_(this) {} 35 : ui_task_runner_(ui_task_runner) {}
29 ~FakeGpuProcess() override {} 36 ~FakeGpuProcess() override {}
30 37
31 void Init() { 38 void Init() {
32 ui::OzonePlatform::GetInstance() 39 ui::OzonePlatform::GetInstance()
33 ->GetGpuPlatformSupport() 40 ->GetGpuPlatformSupport()
34 ->OnChannelEstablished(this); 41 ->OnChannelEstablished(this);
35 } 42 }
36 43
37 void InitOnIO() { 44 void InitOnIO() {
38 ui::OzonePlatform::GetInstance() 45 ui::OzonePlatform::GetInstance()
39 ->GetGpuPlatformSupport() 46 ->GetGpuPlatformSupport()
40 ->GetMessageFilter() 47 ->GetMessageFilter()
41 ->OnFilterAdded(this); 48 ->OnFilterAdded(this);
42 } 49 }
43 50
44 bool Send(IPC::Message* msg) override { 51 bool Send(IPC::Message* msg) override {
45 ui_task_runner_->PostTask( 52 ui_task_runner_->PostTask(
46 FROM_HERE, 53 FROM_HERE, base::Bind(&DispatchToGpuPlatformSupportHostTask, msg));
47 base::Bind(&FakeGpuProcess::DispatchToGpuPlatformSupportHostTask,
48 weak_factory_.GetWeakPtr(), msg));
49 return true; 54 return true;
50 } 55 }
51 56
52 private: 57 private:
53 void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) { 58 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
54 ui::OzonePlatform::GetInstance() 59 };
55 ->GetGpuPlatformSupportHost()
56 ->OnMessageReceived(*msg);
57 delete msg;
58 }
59 60
60 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 61 static void DispatchToGpuPlatformSupportTask(IPC::Message* msg) {
61 base::WeakPtrFactory<FakeGpuProcess> weak_factory_; 62 ui::OzonePlatform::GetInstance()->GetGpuPlatformSupport()->OnMessageReceived(
62 }; 63 *msg);
64 delete msg;
65 }
63 66
64 class FakeGpuProcessHost { 67 class FakeGpuProcessHost {
65 public: 68 public:
66 FakeGpuProcessHost( 69 FakeGpuProcessHost(
67 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner) 70 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner)
68 : gpu_task_runner_(gpu_task_runner), weak_factory_(this) {} 71 : gpu_task_runner_(gpu_task_runner) {}
69 ~FakeGpuProcessHost() {} 72 ~FakeGpuProcessHost() {}
70 73
71 void Init() { 74 void Init() {
72 base::Callback<void(IPC::Message*)> sender = 75 base::Callback<void(IPC::Message*)> sender =
73 base::Bind(&FakeGpuProcessHost::DispatchToGpuPlatformSupportTask, 76 base::Bind(&DispatchToGpuPlatformSupportTask);
74 weak_factory_.GetWeakPtr());
75 77
76 ui::OzonePlatform::GetInstance() 78 ui::OzonePlatform::GetInstance()
77 ->GetGpuPlatformSupportHost() 79 ->GetGpuPlatformSupportHost()
78 ->OnChannelEstablished(kGpuProcessHostId, gpu_task_runner_, sender); 80 ->OnChannelEstablished(kGpuProcessHostId, gpu_task_runner_, sender);
79 } 81 }
80 82
81 private: 83 private:
82 void DispatchToGpuPlatformSupportTask(IPC::Message* msg) {
83 ui::OzonePlatform::GetInstance()
84 ->GetGpuPlatformSupport()
85 ->OnMessageReceived(*msg);
86 delete msg;
87 }
88
89 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; 84 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
90 base::WeakPtrFactory<FakeGpuProcessHost> weak_factory_;
91 }; 85 };
92 86
93 OzoneGpuTestHelper::OzoneGpuTestHelper() { 87 OzoneGpuTestHelper::OzoneGpuTestHelper() {
94 } 88 }
95 89
96 OzoneGpuTestHelper::~OzoneGpuTestHelper() { 90 OzoneGpuTestHelper::~OzoneGpuTestHelper() {
97 } 91 }
98 92
99 bool OzoneGpuTestHelper::Initialize( 93 bool OzoneGpuTestHelper::Initialize(
100 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, 94 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
101 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner) { 95 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner) {
102 io_helper_thread_.reset(new base::Thread("IOHelperThread")); 96 io_helper_thread_.reset(new base::Thread("IOHelperThread"));
103 if (!io_helper_thread_->StartWithOptions( 97 if (!io_helper_thread_->StartWithOptions(
104 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) 98 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
105 return false; 99 return false;
106 100
107 fake_gpu_process_.reset(new FakeGpuProcess(ui_task_runner)); 101 fake_gpu_process_.reset(new FakeGpuProcess(ui_task_runner));
108 io_helper_thread_->task_runner()->PostTask( 102 io_helper_thread_->task_runner()->PostTask(
109 FROM_HERE, base::Bind(&FakeGpuProcess::InitOnIO, 103 FROM_HERE, base::Bind(&FakeGpuProcess::InitOnIO,
110 base::Unretained(fake_gpu_process_.get()))); 104 base::Unretained(fake_gpu_process_.get())));
111 fake_gpu_process_->Init(); 105 fake_gpu_process_->Init();
112 106
113 fake_gpu_process_host_.reset(new FakeGpuProcessHost(gpu_task_runner)); 107 fake_gpu_process_host_.reset(new FakeGpuProcessHost(gpu_task_runner));
114 fake_gpu_process_host_->Init(); 108 fake_gpu_process_host_->Init();
115 109
116 return true; 110 return true;
117 } 111 }
118 112
119 } // namespace ui 113 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698