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

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

Issue 936703002: Fix UiThreadGpu initialization for video accelerator tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename Created 5 years, 10 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 | « ui/ozone/public/ozone_gpu_test_helper.h ('k') | ui/ozone/public/ui_thread_gpu.h » ('j') | 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/ui_thread_gpu.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 class FakeGpuProcess : public IPC::Sender { 24 class FakeGpuProcess : public IPC::Sender {
25 public: 25 public:
26 FakeGpuProcess() : weak_factory_(this) {} 26 FakeGpuProcess(
27 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
28 : ui_task_runner_(ui_task_runner), weak_factory_(this) {}
27 ~FakeGpuProcess() override {} 29 ~FakeGpuProcess() override {}
28 30
29 void Init() { 31 void Init() {
30 task_runner_ = base::ThreadTaskRunnerHandle::Get();
31
32 ui::OzonePlatform::GetInstance() 32 ui::OzonePlatform::GetInstance()
33 ->GetGpuPlatformSupport() 33 ->GetGpuPlatformSupport()
34 ->OnChannelEstablished(this); 34 ->OnChannelEstablished(this);
35 } 35 }
36 36
37 void InitOnIO() { 37 void InitOnIO() {
38 ui::OzonePlatform::GetInstance() 38 ui::OzonePlatform::GetInstance()
39 ->GetGpuPlatformSupport() 39 ->GetGpuPlatformSupport()
40 ->GetMessageFilter() 40 ->GetMessageFilter()
41 ->OnFilterAdded(this); 41 ->OnFilterAdded(this);
42 } 42 }
43 43
44 bool Send(IPC::Message* msg) override { 44 bool Send(IPC::Message* msg) override {
45 DCHECK(task_runner_->BelongsToCurrentThread()); 45 ui_task_runner_->PostTask(
46 base::MessageLoop::current()->PostTask(
47 FROM_HERE, 46 FROM_HERE,
48 base::Bind(&FakeGpuProcess::DispatchToGpuPlatformSupportHostTask, 47 base::Bind(&FakeGpuProcess::DispatchToGpuPlatformSupportHostTask,
49 weak_factory_.GetWeakPtr(), msg)); 48 weak_factory_.GetWeakPtr(), msg));
50 return true; 49 return true;
51 } 50 }
52 51
53 private: 52 private:
54 void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) { 53 void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) {
55 ui::OzonePlatform::GetInstance() 54 ui::OzonePlatform::GetInstance()
56 ->GetGpuPlatformSupportHost() 55 ->GetGpuPlatformSupportHost()
57 ->OnMessageReceived(*msg); 56 ->OnMessageReceived(*msg);
58 delete msg; 57 delete msg;
59 } 58 }
60 59
61 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 60 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
62 base::WeakPtrFactory<FakeGpuProcess> weak_factory_; 61 base::WeakPtrFactory<FakeGpuProcess> weak_factory_;
63 }; 62 };
64 63
65 class FakeGpuProcessHost { 64 class FakeGpuProcessHost {
66 public: 65 public:
67 FakeGpuProcessHost() : weak_factory_(this) {} 66 FakeGpuProcessHost(
67 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner)
68 : gpu_task_runner_(gpu_task_runner), weak_factory_(this) {}
68 ~FakeGpuProcessHost() {} 69 ~FakeGpuProcessHost() {}
69 70
70 void Init() { 71 void Init() {
71 task_runner_ = base::ThreadTaskRunnerHandle::Get();
72
73 base::Callback<void(IPC::Message*)> sender = 72 base::Callback<void(IPC::Message*)> sender =
74 base::Bind(&FakeGpuProcessHost::DispatchToGpuPlatformSupportTask, 73 base::Bind(&FakeGpuProcessHost::DispatchToGpuPlatformSupportTask,
75 weak_factory_.GetWeakPtr()); 74 weak_factory_.GetWeakPtr());
76 75
77 ui::OzonePlatform::GetInstance() 76 ui::OzonePlatform::GetInstance()
78 ->GetGpuPlatformSupportHost() 77 ->GetGpuPlatformSupportHost()
79 ->OnChannelEstablished(kGpuProcessHostId, task_runner_, sender); 78 ->OnChannelEstablished(kGpuProcessHostId, gpu_task_runner_, sender);
80 } 79 }
81 80
82 private: 81 private:
83 void DispatchToGpuPlatformSupportTask(IPC::Message* msg) { 82 void DispatchToGpuPlatformSupportTask(IPC::Message* msg) {
84 DCHECK(task_runner_->BelongsToCurrentThread());
85 ui::OzonePlatform::GetInstance() 83 ui::OzonePlatform::GetInstance()
86 ->GetGpuPlatformSupport() 84 ->GetGpuPlatformSupport()
87 ->OnMessageReceived(*msg); 85 ->OnMessageReceived(*msg);
88 delete msg; 86 delete msg;
89 } 87 }
90 88
91 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 89 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
92 base::WeakPtrFactory<FakeGpuProcessHost> weak_factory_; 90 base::WeakPtrFactory<FakeGpuProcessHost> weak_factory_;
93 }; 91 };
94 92
95 UiThreadGpu::UiThreadGpu() { 93 OzoneGpuTestHelper::OzoneGpuTestHelper() {
96 } 94 }
97 95
98 UiThreadGpu::~UiThreadGpu() { 96 OzoneGpuTestHelper::~OzoneGpuTestHelper() {
99 } 97 }
100 98
101 bool UiThreadGpu::Initialize() { 99 bool OzoneGpuTestHelper::Initialize(
100 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
101 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner) {
102 io_helper_thread_.reset(new base::Thread("IOHelperThread")); 102 io_helper_thread_.reset(new base::Thread("IOHelperThread"));
103 if (!io_helper_thread_->StartWithOptions( 103 if (!io_helper_thread_->StartWithOptions(
104 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) 104 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
105 return false; 105 return false;
106 106
107 fake_gpu_process_.reset(new FakeGpuProcess); 107 fake_gpu_process_.reset(new FakeGpuProcess(ui_task_runner));
108 io_helper_thread_->task_runner()->PostTask( 108 io_helper_thread_->task_runner()->PostTask(
109 FROM_HERE, base::Bind(&FakeGpuProcess::InitOnIO, 109 FROM_HERE, base::Bind(&FakeGpuProcess::InitOnIO,
110 base::Unretained(fake_gpu_process_.get()))); 110 base::Unretained(fake_gpu_process_.get())));
111 fake_gpu_process_->Init(); 111 fake_gpu_process_->Init();
112 112
113 fake_gpu_process_host_.reset(new FakeGpuProcessHost); 113 fake_gpu_process_host_.reset(new FakeGpuProcessHost(gpu_task_runner));
114 fake_gpu_process_host_->Init(); 114 fake_gpu_process_host_->Init();
115 115
116 return true; 116 return true;
117 } 117 }
118 118
119 } // namespace ui 119 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/public/ozone_gpu_test_helper.h ('k') | ui/ozone/public/ui_thread_gpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698