| OLD | NEW |
| 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 "content/browser/compositor/gpu_process_transport_factory.h" | 5 #include "content/browser/compositor/gpu_process_transport_factory.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 #endif | 152 #endif |
| 153 | 153 |
| 154 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 154 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
| 155 | 155 |
| 156 if (!create_software_renderer) { | 156 if (!create_software_renderer) { |
| 157 context_provider = ContextProviderCommandBuffer::Create( | 157 context_provider = ContextProviderCommandBuffer::Create( |
| 158 GpuProcessTransportFactory::CreateContextCommon(data->surface_id), | 158 GpuProcessTransportFactory::CreateContextCommon(data->surface_id), |
| 159 "Compositor"); | 159 "Compositor"); |
| 160 } | 160 } |
| 161 | 161 |
| 162 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", !!context_provider); | 162 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", |
| 163 !!context_provider.get()); |
| 163 | 164 |
| 164 if (context_provider) { | 165 if (context_provider.get()) { |
| 165 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = | 166 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = |
| 166 GetCompositorMessageLoop(); | 167 GetCompositorMessageLoop(); |
| 167 if (!compositor_thread_task_runner.get()) | 168 if (!compositor_thread_task_runner.get()) |
| 168 compositor_thread_task_runner = base::MessageLoopProxy::current(); | 169 compositor_thread_task_runner = base::MessageLoopProxy::current(); |
| 169 | 170 |
| 170 // Here we know the GpuProcessHost has been set up, because we created a | 171 // Here we know the GpuProcessHost has been set up, because we created a |
| 171 // context. | 172 // context. |
| 172 output_surface_proxy_->ConnectToGpuProcessHost( | 173 output_surface_proxy_->ConnectToGpuProcessHost( |
| 173 compositor_thread_task_runner.get()); | 174 compositor_thread_task_runner.get()); |
| 174 } | 175 } |
| 175 | 176 |
| 176 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 177 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 177 switches::kUseSurfaces)) { | 178 switches::kUseSurfaces)) { |
| 178 // This gets a bit confusing. Here we have a ContextProvider configured to | 179 // This gets a bit confusing. Here we have a ContextProvider configured to |
| 179 // render directly to this widget. We need to make an OnscreenDisplayClient | 180 // render directly to this widget. We need to make an OnscreenDisplayClient |
| 180 // associated with this context, then return a SurfaceDisplayOutputSurface | 181 // associated with this context, then return a SurfaceDisplayOutputSurface |
| 181 // set up to draw to the display's surface. | 182 // set up to draw to the display's surface. |
| 182 cc::SurfaceManager* manager = surface_manager_.get(); | 183 cc::SurfaceManager* manager = surface_manager_.get(); |
| 183 scoped_ptr<cc::OutputSurface> software_surface; | 184 scoped_ptr<cc::OutputSurface> software_surface; |
| 184 if (!context_provider) { | 185 if (!context_provider.get()) { |
| 185 software_surface = | 186 software_surface = |
| 186 make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface( | 187 make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface( |
| 187 output_surface_proxy_, | 188 output_surface_proxy_, |
| 188 CreateSoftwareOutputDevice(compositor), | 189 CreateSoftwareOutputDevice(compositor), |
| 189 per_compositor_data_[compositor]->surface_id, | 190 per_compositor_data_[compositor]->surface_id, |
| 190 &output_surface_map_, | 191 &output_surface_map_, |
| 191 compositor->vsync_manager())); | 192 compositor->vsync_manager())); |
| 192 } | 193 } |
| 193 scoped_ptr<OnscreenDisplayClient> display_client( | 194 scoped_ptr<OnscreenDisplayClient> display_client( |
| 194 new OnscreenDisplayClient(context_provider, | 195 new OnscreenDisplayClient(context_provider, |
| 195 software_surface.Pass(), | 196 software_surface.Pass(), |
| 196 manager, | 197 manager, |
| 197 compositor->task_runner())); | 198 compositor->task_runner())); |
| 198 // TODO(jamesr): Need to set up filtering for the | 199 // TODO(jamesr): Need to set up filtering for the |
| 199 // GpuHostMsg_UpdateVSyncParameters message. | 200 // GpuHostMsg_UpdateVSyncParameters message. |
| 200 | 201 |
| 201 scoped_refptr<cc::ContextProvider> offscreen_context_provider; | 202 scoped_refptr<cc::ContextProvider> offscreen_context_provider; |
| 202 if (context_provider) { | 203 if (context_provider.get()) { |
| 203 offscreen_context_provider = ContextProviderCommandBuffer::Create( | 204 offscreen_context_provider = ContextProviderCommandBuffer::Create( |
| 204 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext(), | 205 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext(), |
| 205 "Offscreen-Compositor"); | 206 "Offscreen-Compositor"); |
| 206 } | 207 } |
| 207 scoped_ptr<SurfaceDisplayOutputSurface> output_surface( | 208 scoped_ptr<SurfaceDisplayOutputSurface> output_surface( |
| 208 new SurfaceDisplayOutputSurface(manager, | 209 new SurfaceDisplayOutputSurface(manager, |
| 209 next_surface_id_namespace_++, | 210 next_surface_id_namespace_++, |
| 210 offscreen_context_provider)); | 211 offscreen_context_provider)); |
| 211 output_surface->set_display(display_client->display()); | 212 output_surface->set_display(display_client->display()); |
| 212 data->display_client = display_client.Pass(); | 213 data->display_client = display_client.Pass(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 return HostSharedBitmapManager::current(); | 302 return HostSharedBitmapManager::current(); |
| 302 } | 303 } |
| 303 | 304 |
| 304 ui::ContextFactory* GpuProcessTransportFactory::GetContextFactory() { | 305 ui::ContextFactory* GpuProcessTransportFactory::GetContextFactory() { |
| 305 return this; | 306 return this; |
| 306 } | 307 } |
| 307 | 308 |
| 308 base::MessageLoopProxy* GpuProcessTransportFactory::GetCompositorMessageLoop() { | 309 base::MessageLoopProxy* GpuProcessTransportFactory::GetCompositorMessageLoop() { |
| 309 if (!compositor_thread_) | 310 if (!compositor_thread_) |
| 310 return NULL; | 311 return NULL; |
| 311 return compositor_thread_->message_loop_proxy(); | 312 return compositor_thread_->message_loop_proxy().get(); |
| 312 } | 313 } |
| 313 | 314 |
| 314 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() { | 315 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() { |
| 315 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 316 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
| 316 gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT); | 317 gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT); |
| 317 handle.parent_client_id = | 318 handle.parent_client_id = |
| 318 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); | 319 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); |
| 319 return handle; | 320 return handle; |
| 320 } | 321 } |
| 321 | 322 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 return shared_main_thread_contexts_; | 366 return shared_main_thread_contexts_; |
| 366 | 367 |
| 367 // In threaded compositing mode, we have to create our own context for the | 368 // In threaded compositing mode, we have to create our own context for the |
| 368 // main thread since the compositor's context will be bound to the | 369 // main thread since the compositor's context will be bound to the |
| 369 // compositor thread. When not in threaded mode, we still need a separate | 370 // compositor thread. When not in threaded mode, we still need a separate |
| 370 // context so that skia and gl_helper don't step on each other. | 371 // context so that skia and gl_helper don't step on each other. |
| 371 shared_main_thread_contexts_ = ContextProviderCommandBuffer::Create( | 372 shared_main_thread_contexts_ = ContextProviderCommandBuffer::Create( |
| 372 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext(), | 373 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext(), |
| 373 "Offscreen-MainThread"); | 374 "Offscreen-MainThread"); |
| 374 | 375 |
| 375 if (shared_main_thread_contexts_) { | 376 if (shared_main_thread_contexts_.get()) { |
| 376 shared_main_thread_contexts_->SetLostContextCallback( | 377 shared_main_thread_contexts_->SetLostContextCallback( |
| 377 base::Bind(&GpuProcessTransportFactory:: | 378 base::Bind(&GpuProcessTransportFactory:: |
| 378 OnLostMainThreadSharedContextInsideCallback, | 379 OnLostMainThreadSharedContextInsideCallback, |
| 379 callback_factory_.GetWeakPtr())); | 380 callback_factory_.GetWeakPtr())); |
| 380 if (!shared_main_thread_contexts_->BindToCurrentThread()) | 381 if (!shared_main_thread_contexts_->BindToCurrentThread()) |
| 381 shared_main_thread_contexts_ = NULL; | 382 shared_main_thread_contexts_ = NULL; |
| 382 } | 383 } |
| 383 return shared_main_thread_contexts_; | 384 return shared_main_thread_contexts_; |
| 384 } | 385 } |
| 385 | 386 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 410 attrs.shareResources = true; | 411 attrs.shareResources = true; |
| 411 attrs.depth = false; | 412 attrs.depth = false; |
| 412 attrs.stencil = false; | 413 attrs.stencil = false; |
| 413 attrs.antialias = false; | 414 attrs.antialias = false; |
| 414 attrs.noAutomaticFlushes = true; | 415 attrs.noAutomaticFlushes = true; |
| 415 bool lose_context_when_out_of_memory = true; | 416 bool lose_context_when_out_of_memory = true; |
| 416 CauseForGpuLaunch cause = | 417 CauseForGpuLaunch cause = |
| 417 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 418 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 418 scoped_refptr<GpuChannelHost> gpu_channel_host( | 419 scoped_refptr<GpuChannelHost> gpu_channel_host( |
| 419 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause)); | 420 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause)); |
| 420 if (!gpu_channel_host) { | 421 if (!gpu_channel_host.get()) { |
| 421 LOG(ERROR) << "Failed to establish GPU channel."; | 422 LOG(ERROR) << "Failed to establish GPU channel."; |
| 422 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | 423 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
| 423 } | 424 } |
| 424 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); | 425 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); |
| 425 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 426 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
| 426 new WebGraphicsContext3DCommandBufferImpl( | 427 new WebGraphicsContext3DCommandBufferImpl( |
| 427 surface_id, | 428 surface_id, |
| 428 url, | 429 url, |
| 429 gpu_channel_host.get(), | 430 gpu_channel_host.get(), |
| 430 attrs, | 431 attrs, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 457 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 458 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
| 458 observer_list_, | 459 observer_list_, |
| 459 OnLostResources()); | 460 OnLostResources()); |
| 460 | 461 |
| 461 // Kill things that use the shared context before killing the shared context. | 462 // Kill things that use the shared context before killing the shared context. |
| 462 lost_gl_helper.reset(); | 463 lost_gl_helper.reset(); |
| 463 lost_shared_main_thread_contexts = NULL; | 464 lost_shared_main_thread_contexts = NULL; |
| 464 } | 465 } |
| 465 | 466 |
| 466 } // namespace content | 467 } // namespace content |
| OLD | NEW |