Chromium Code Reviews| 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(int32 image_id) { | |
| 184 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | |
| 185 if (!host) { | |
| 186 return; | |
| 187 } | |
| 188 | |
| 189 host->DeleteImage(gpu_client_id_, image_id); | |
| 190 } | |
| 191 | |
| 192 void BrowserGpuChannelHostFactory::DeleteImage(int32 image_id) { | |
| 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 194 GetIOLoopProxy()->PostTask(FROM_HERE, base::Bind( | |
| 195 &BrowserGpuChannelHostFactory::DeleteImageOnIO, | |
| 196 base::Unretained(this), | |
| 197 image_id)); | |
|
piman
2012/10/12 22:05:11
Note: there's still a race on destruction. Take th
reveman
2012/10/13 05:25:53
I've added a sync point to DeleteImage. I liked th
| |
| 198 } | |
| 199 | |
| 137 void BrowserGpuChannelHostFactory::EstablishGpuChannelOnIO( | 200 void BrowserGpuChannelHostFactory::EstablishGpuChannelOnIO( |
| 138 EstablishRequest* request) { | 201 EstablishRequest* request) { |
| 139 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | 202 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 140 if (!host) { | 203 if (!host) { |
| 141 host = GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | 204 host = GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| 142 request->cause_for_gpu_launch); | 205 request->cause_for_gpu_launch); |
| 143 if (!host) { | 206 if (!host) { |
| 144 request->event.Signal(); | 207 request->event.Signal(); |
| 145 return; | 208 return; |
| 146 } | 209 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 gpu_channel_->set_gpu_info(request.gpu_info); | 281 gpu_channel_->set_gpu_info(request.gpu_info); |
| 219 content::GetContentClient()->SetGpuInfo(request.gpu_info); | 282 content::GetContentClient()->SetGpuInfo(request.gpu_info); |
| 220 | 283 |
| 221 // Connect to the GPU process if a channel name was received. | 284 // Connect to the GPU process if a channel name was received. |
| 222 gpu_channel_->Connect(request.channel_handle); | 285 gpu_channel_->Connect(request.channel_handle); |
| 223 | 286 |
| 224 return gpu_channel_.get(); | 287 return gpu_channel_.get(); |
| 225 } | 288 } |
| 226 | 289 |
| 227 } // namespace content | 290 } // namespace content |
| OLD | NEW |