OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/gpu/browser_gpu_channel_host_factory.h" | 5 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/browser/gpu/gpu_data_manager_impl.h" | 8 #include "content/browser/gpu/gpu_data_manager_impl.h" |
9 #include "content/browser/gpu/gpu_process_host.h" | 9 #include "content/browser/gpu/gpu_process_host.h" |
10 #include "content/browser/gpu/gpu_surface_tracker.h" | 10 #include "content/browser/gpu/gpu_surface_tracker.h" |
11 #include "content/common/gpu/gpu_messages.h" | 11 #include "content/common/gpu/gpu_messages.h" |
12 #include "content/common/child_process_host_impl.h" | 12 #include "content/common/child_process_host_impl.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; | 18 BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = NULL; |
19 | 19 |
20 BrowserGpuChannelHostFactory::CreateRequest::CreateRequest() | 20 BrowserGpuChannelHostFactory::CreateRequest::CreateRequest() |
21 : event(false, false), | 21 : event(false, false), |
22 route_id(MSG_ROUTING_NONE) { | 22 route_id(MSG_ROUTING_NONE) { |
23 } | 23 } |
24 | 24 |
25 BrowserGpuChannelHostFactory::CreateRequest::~CreateRequest() { | 25 BrowserGpuChannelHostFactory::CreateRequest::~CreateRequest() { |
26 } | 26 } |
27 | 27 |
28 BrowserGpuChannelHostFactory::EstablishRequest::EstablishRequest() | 28 BrowserGpuChannelHostFactory::EstablishRequest::EstablishRequest() |
29 : event(false, false), | 29 : event(false, false) { |
30 gpu_process_handle(base::kNullProcessHandle) { | |
31 } | 30 } |
32 | 31 |
33 BrowserGpuChannelHostFactory::EstablishRequest::~EstablishRequest() { | 32 BrowserGpuChannelHostFactory::EstablishRequest::~EstablishRequest() { |
34 } | 33 } |
35 | 34 |
36 void BrowserGpuChannelHostFactory::Initialize() { | 35 void BrowserGpuChannelHostFactory::Initialize() { |
37 instance_ = new BrowserGpuChannelHostFactory(); | 36 instance_ = new BrowserGpuChannelHostFactory(); |
38 } | 37 } |
39 | 38 |
40 void BrowserGpuChannelHostFactory::Terminate() { | 39 void BrowserGpuChannelHostFactory::Terminate() { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 gpu_client_id_, | 145 gpu_client_id_, |
147 true, | 146 true, |
148 base::Bind(&BrowserGpuChannelHostFactory::GpuChannelEstablishedOnIO, | 147 base::Bind(&BrowserGpuChannelHostFactory::GpuChannelEstablishedOnIO, |
149 request)); | 148 request)); |
150 } | 149 } |
151 | 150 |
152 // static | 151 // static |
153 void BrowserGpuChannelHostFactory::GpuChannelEstablishedOnIO( | 152 void BrowserGpuChannelHostFactory::GpuChannelEstablishedOnIO( |
154 EstablishRequest* request, | 153 EstablishRequest* request, |
155 const IPC::ChannelHandle& channel_handle, | 154 const IPC::ChannelHandle& channel_handle, |
156 base::ProcessHandle gpu_process_handle, | |
157 const GPUInfo& gpu_info) { | 155 const GPUInfo& gpu_info) { |
158 request->channel_handle = channel_handle; | 156 request->channel_handle = channel_handle; |
159 request->gpu_process_handle = gpu_process_handle; | |
160 request->gpu_info = gpu_info; | 157 request->gpu_info = gpu_info; |
161 request->event.Signal(); | 158 request->event.Signal(); |
162 } | 159 } |
163 | 160 |
164 GpuChannelHost* BrowserGpuChannelHostFactory::EstablishGpuChannelSync( | 161 GpuChannelHost* BrowserGpuChannelHostFactory::EstablishGpuChannelSync( |
165 CauseForGpuLaunch cause_for_gpu_launch) { | 162 CauseForGpuLaunch cause_for_gpu_launch) { |
166 if (gpu_channel_.get()) { | 163 if (gpu_channel_.get()) { |
167 // Recreate the channel if it has been lost. | 164 // Recreate the channel if it has been lost. |
168 if (gpu_channel_->state() == GpuChannelHost::kLost) | 165 if (gpu_channel_->state() == GpuChannelHost::kLost) |
169 gpu_channel_ = NULL; | 166 gpu_channel_ = NULL; |
(...skipping 10 matching lines...) Expand all Loading... |
180 &BrowserGpuChannelHostFactory::EstablishGpuChannelOnIO, | 177 &BrowserGpuChannelHostFactory::EstablishGpuChannelOnIO, |
181 base::Unretained(this), | 178 base::Unretained(this), |
182 &request, | 179 &request, |
183 cause_for_gpu_launch)); | 180 cause_for_gpu_launch)); |
184 // We're blocking the UI thread, which is generally undesirable. | 181 // We're blocking the UI thread, which is generally undesirable. |
185 // In this case we need to wait for this before we can show any UI /anyway/, | 182 // In this case we need to wait for this before we can show any UI /anyway/, |
186 // so it won't cause additional jank. | 183 // so it won't cause additional jank. |
187 // TODO(piman): Make this asynchronous. | 184 // TODO(piman): Make this asynchronous. |
188 request.event.Wait(); | 185 request.event.Wait(); |
189 | 186 |
190 if (request.channel_handle.name.empty() || | 187 if (request.channel_handle.name.empty()) |
191 request.gpu_process_handle == base::kNullProcessHandle) | |
192 return NULL; | 188 return NULL; |
193 | 189 |
194 base::ProcessHandle browser_process_for_gpu; | |
195 #if defined(OS_WIN) | |
196 // Create a process handle that the GPU process can use to access our handles. | |
197 DuplicateHandle(base::GetCurrentProcessHandle(), | |
198 base::GetCurrentProcessHandle(), | |
199 request.gpu_process_handle, | |
200 &browser_process_for_gpu, | |
201 PROCESS_DUP_HANDLE, | |
202 FALSE, | |
203 0); | |
204 #else | |
205 browser_process_for_gpu = base::GetCurrentProcessHandle(); | |
206 #endif | |
207 | |
208 gpu_channel_ = new GpuChannelHost(this, gpu_host_id_, gpu_client_id_); | 190 gpu_channel_ = new GpuChannelHost(this, gpu_host_id_, gpu_client_id_); |
209 gpu_channel_->set_gpu_info(request.gpu_info); | 191 gpu_channel_->set_gpu_info(request.gpu_info); |
210 content::GetContentClient()->SetGpuInfo(request.gpu_info); | 192 content::GetContentClient()->SetGpuInfo(request.gpu_info); |
211 | 193 |
212 // Connect to the GPU process if a channel name was received. | 194 // Connect to the GPU process if a channel name was received. |
213 gpu_channel_->Connect(request.channel_handle, browser_process_for_gpu); | 195 gpu_channel_->Connect(request.channel_handle); |
214 | 196 |
215 return gpu_channel_.get(); | 197 return gpu_channel_.get(); |
216 } | 198 } |
217 | 199 |
218 } // namespace content | 200 } // namespace content |
OLD | NEW |