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 "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
9 #include "content/browser/gpu/gpu_data_manager_impl.h" | 9 #include "content/browser/gpu/gpu_data_manager_impl.h" |
10 #include "content/browser/gpu/gpu_process_host.h" | 10 #include "content/browser/gpu/gpu_process_host.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 init_params)); | 127 init_params)); |
128 // We're blocking the UI thread, which is generally undesirable. | 128 // We're blocking the UI thread, which is generally undesirable. |
129 // In this case we need to wait for this before we can show any UI /anyway/, | 129 // In this case we need to wait for this before we can show any UI /anyway/, |
130 // so it won't cause additional jank. | 130 // so it won't cause additional jank. |
131 // TODO(piman): Make this asynchronous (http://crbug.com/125248). | 131 // TODO(piman): Make this asynchronous (http://crbug.com/125248). |
132 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 132 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
133 request.event.Wait(); | 133 request.event.Wait(); |
134 return request.route_id; | 134 return request.route_id; |
135 } | 135 } |
136 | 136 |
| 137 void BrowserGpuChannelHostFactory::CreateImageOnIO( |
| 138 gfx::PluginWindowHandle window, |
| 139 int32 image_id, |
| 140 const CreateImageCallback& callback) { |
| 141 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 142 if (!host) { |
| 143 ImageCreatedOnIO(callback, gfx::Size()); |
| 144 return; |
| 145 } |
| 146 |
| 147 host->CreateImage( |
| 148 window, |
| 149 gpu_client_id_, |
| 150 image_id, |
| 151 base::Bind(&BrowserGpuChannelHostFactory::ImageCreatedOnIO, callback)); |
| 152 } |
| 153 |
| 154 // static |
| 155 void BrowserGpuChannelHostFactory::ImageCreatedOnIO( |
| 156 const CreateImageCallback& callback, const gfx::Size size) { |
| 157 BrowserThread::PostTask( |
| 158 BrowserThread::UI, |
| 159 FROM_HERE, |
| 160 base::Bind(&BrowserGpuChannelHostFactory::OnImageCreated, |
| 161 callback, size)); |
| 162 } |
| 163 |
| 164 // static |
| 165 void BrowserGpuChannelHostFactory::OnImageCreated( |
| 166 const CreateImageCallback& callback, const gfx::Size size) { |
| 167 callback.Run(size); |
| 168 } |
| 169 |
| 170 void BrowserGpuChannelHostFactory::CreateImage( |
| 171 gfx::PluginWindowHandle window, |
| 172 int32 image_id, |
| 173 const CreateImageCallback& callback) { |
| 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 175 GetIOLoopProxy()->PostTask(FROM_HERE, base::Bind( |
| 176 &BrowserGpuChannelHostFactory::CreateImageOnIO, |
| 177 base::Unretained(this), |
| 178 window, |
| 179 image_id, |
| 180 callback)); |
| 181 } |
| 182 |
| 183 void BrowserGpuChannelHostFactory::DeleteImageOnIO( |
| 184 int32 image_id, int32 sync_point) { |
| 185 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 186 if (!host) { |
| 187 return; |
| 188 } |
| 189 |
| 190 host->DeleteImage(gpu_client_id_, image_id, sync_point); |
| 191 } |
| 192 |
| 193 void BrowserGpuChannelHostFactory::DeleteImage( |
| 194 int32 image_id, int32 sync_point) { |
| 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 196 GetIOLoopProxy()->PostTask(FROM_HERE, base::Bind( |
| 197 &BrowserGpuChannelHostFactory::DeleteImageOnIO, |
| 198 base::Unretained(this), |
| 199 image_id, |
| 200 sync_point)); |
| 201 } |
| 202 |
137 void BrowserGpuChannelHostFactory::EstablishGpuChannelOnIO( | 203 void BrowserGpuChannelHostFactory::EstablishGpuChannelOnIO( |
138 EstablishRequest* request) { | 204 EstablishRequest* request) { |
139 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | 205 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
140 if (!host) { | 206 if (!host) { |
141 host = GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | 207 host = GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
142 request->cause_for_gpu_launch); | 208 request->cause_for_gpu_launch); |
143 if (!host) { | 209 if (!host) { |
144 request->event.Signal(); | 210 request->event.Signal(); |
145 return; | 211 return; |
146 } | 212 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 gpu_channel_->set_gpu_info(request.gpu_info); | 284 gpu_channel_->set_gpu_info(request.gpu_info); |
219 content::GetContentClient()->SetGpuInfo(request.gpu_info); | 285 content::GetContentClient()->SetGpuInfo(request.gpu_info); |
220 | 286 |
221 // Connect to the GPU process if a channel name was received. | 287 // Connect to the GPU process if a channel name was received. |
222 gpu_channel_->Connect(request.channel_handle); | 288 gpu_channel_->Connect(request.channel_handle); |
223 | 289 |
224 return gpu_channel_.get(); | 290 return gpu_channel_.get(); |
225 } | 291 } |
226 | 292 |
227 } // namespace content | 293 } // namespace content |
OLD | NEW |