| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 if (!create_gpu_output_surface) { | 267 if (!create_gpu_output_surface) { |
| 268 surface = make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface( | 268 surface = make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface( |
| 269 CreateSoftwareOutputDevice(compositor.get()), | 269 CreateSoftwareOutputDevice(compositor.get()), |
| 270 compositor->vsync_manager())); | 270 compositor->vsync_manager())); |
| 271 } else { | 271 } else { |
| 272 DCHECK(context_provider); | 272 DCHECK(context_provider); |
| 273 ContextProvider::Capabilities capabilities = | 273 ContextProvider::Capabilities capabilities = |
| 274 context_provider->ContextCapabilities(); | 274 context_provider->ContextCapabilities(); |
| 275 if (!data->surface_id) { | 275 if (!data->surface_id) { |
| 276 surface = make_scoped_ptr(new OffscreenBrowserCompositorOutputSurface( | 276 surface = make_scoped_ptr(new OffscreenBrowserCompositorOutputSurface( |
| 277 context_provider, compositor->vsync_manager(), | 277 context_provider, SharedWorkerContextProvider(), |
| 278 compositor->vsync_manager(), |
| 278 scoped_ptr<BrowserCompositorOverlayCandidateValidator>())); | 279 scoped_ptr<BrowserCompositorOverlayCandidateValidator>())); |
| 279 } else if (capabilities.gpu.surfaceless) { | 280 } else if (capabilities.gpu.surfaceless) { |
| 280 GLenum target = GL_TEXTURE_2D; | 281 GLenum target = GL_TEXTURE_2D; |
| 281 GLenum format = GL_RGB; | 282 GLenum format = GL_RGB; |
| 282 #if defined(OS_MACOSX) | 283 #if defined(OS_MACOSX) |
| 283 target = GL_TEXTURE_RECTANGLE_ARB; | 284 target = GL_TEXTURE_RECTANGLE_ARB; |
| 284 format = GL_BGRA_EXT; | 285 format = GL_BGRA_EXT; |
| 285 #endif | 286 #endif |
| 286 surface = | 287 surface = |
| 287 make_scoped_ptr(new GpuSurfacelessBrowserCompositorOutputSurface( | 288 make_scoped_ptr(new GpuSurfacelessBrowserCompositorOutputSurface( |
| 288 context_provider, data->surface_id, compositor->vsync_manager(), | 289 context_provider, SharedWorkerContextProvider(), data->surface_id, |
| 290 compositor->vsync_manager(), |
| 289 CreateOverlayCandidateValidator(compositor->widget()), target, | 291 CreateOverlayCandidateValidator(compositor->widget()), target, |
| 290 format, BrowserGpuMemoryBufferManager::current())); | 292 format, BrowserGpuMemoryBufferManager::current())); |
| 291 } else { | 293 } else { |
| 292 if (!surface) { | 294 if (!surface) { |
| 293 surface = make_scoped_ptr(new GpuBrowserCompositorOutputSurface( | 295 surface = make_scoped_ptr(new GpuBrowserCompositorOutputSurface( |
| 294 context_provider, compositor->vsync_manager(), | 296 context_provider, SharedWorkerContextProvider(), |
| 297 compositor->vsync_manager(), |
| 295 CreateOverlayCandidateValidator(compositor->widget()))); | 298 CreateOverlayCandidateValidator(compositor->widget()))); |
| 296 } | 299 } |
| 297 } | 300 } |
| 298 } | 301 } |
| 299 | 302 |
| 300 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an | 303 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an |
| 301 // output_surface_map_ here. | 304 // output_surface_map_ here. |
| 302 output_surface_map_.AddWithID(surface.get(), data->surface_id); | 305 output_surface_map_.AddWithID(surface.get(), data->surface_id); |
| 303 data->surface = surface.get(); | 306 data->surface = surface.get(); |
| 304 if (data->reflector) | 307 if (data->reflector) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 315 // SurfaceDisplayOutputSurface set up to draw to the display's surface. | 318 // SurfaceDisplayOutputSurface set up to draw to the display's surface. |
| 316 cc::SurfaceManager* manager = surface_manager_.get(); | 319 cc::SurfaceManager* manager = surface_manager_.get(); |
| 317 scoped_ptr<cc::OnscreenDisplayClient> display_client( | 320 scoped_ptr<cc::OnscreenDisplayClient> display_client( |
| 318 new cc::OnscreenDisplayClient( | 321 new cc::OnscreenDisplayClient( |
| 319 surface.Pass(), manager, HostSharedBitmapManager::current(), | 322 surface.Pass(), manager, HostSharedBitmapManager::current(), |
| 320 BrowserGpuMemoryBufferManager::current(), | 323 BrowserGpuMemoryBufferManager::current(), |
| 321 compositor->GetRendererSettings(), compositor->task_runner())); | 324 compositor->GetRendererSettings(), compositor->task_runner())); |
| 322 | 325 |
| 323 scoped_ptr<cc::SurfaceDisplayOutputSurface> output_surface( | 326 scoped_ptr<cc::SurfaceDisplayOutputSurface> output_surface( |
| 324 new cc::SurfaceDisplayOutputSurface( | 327 new cc::SurfaceDisplayOutputSurface( |
| 325 manager, compositor->surface_id_allocator(), context_provider)); | 328 manager, compositor->surface_id_allocator(), context_provider, |
| 329 SharedWorkerContextProvider())); |
| 326 display_client->set_surface_output_surface(output_surface.get()); | 330 display_client->set_surface_output_surface(output_surface.get()); |
| 327 output_surface->set_display_client(display_client.get()); | 331 output_surface->set_display_client(display_client.get()); |
| 328 display_client->display()->Resize(compositor->size()); | 332 display_client->display()->Resize(compositor->size()); |
| 329 data->display_client = display_client.Pass(); | 333 data->display_client = display_client.Pass(); |
| 330 compositor->SetOutputSurface(output_surface.Pass()); | 334 compositor->SetOutputSurface(output_surface.Pass()); |
| 331 } | 335 } |
| 332 | 336 |
| 333 scoped_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( | 337 scoped_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( |
| 334 ui::Compositor* source_compositor, | 338 ui::Compositor* source_compositor, |
| 335 ui::Layer* target_layer) { | 339 ui::Layer* target_layer) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 shared_main_thread_contexts_->SetLostContextCallback( | 517 shared_main_thread_contexts_->SetLostContextCallback( |
| 514 base::Bind(&GpuProcessTransportFactory:: | 518 base::Bind(&GpuProcessTransportFactory:: |
| 515 OnLostMainThreadSharedContextInsideCallback, | 519 OnLostMainThreadSharedContextInsideCallback, |
| 516 callback_factory_.GetWeakPtr())); | 520 callback_factory_.GetWeakPtr())); |
| 517 if (!shared_main_thread_contexts_->BindToCurrentThread()) | 521 if (!shared_main_thread_contexts_->BindToCurrentThread()) |
| 518 shared_main_thread_contexts_ = NULL; | 522 shared_main_thread_contexts_ = NULL; |
| 519 } | 523 } |
| 520 return shared_main_thread_contexts_; | 524 return shared_main_thread_contexts_; |
| 521 } | 525 } |
| 522 | 526 |
| 527 scoped_refptr<ContextProviderCommandBuffer> |
| 528 GpuProcessTransportFactory::SharedWorkerContextProvider() { |
| 529 if (shared_worker_context_provider_.get()) |
| 530 return shared_worker_context_provider_; |
| 531 |
| 532 shared_worker_context_provider_ = ContextProviderCommandBuffer::Create( |
| 533 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext(), |
| 534 BROWSER_WORKER_CONTEXT); |
| 535 |
| 536 if (shared_worker_context_provider_.get()) { |
| 537 shared_worker_context_provider_->SetLostContextCallback( |
| 538 base::Bind(&GpuProcessTransportFactory::OnLostWorkerSharedContext, |
| 539 callback_factory_.GetWeakPtr())); |
| 540 if (!shared_worker_context_provider_->BindToCurrentThread()) |
| 541 shared_worker_context_provider_ = nullptr; |
| 542 } |
| 543 return shared_worker_context_provider_; |
| 544 } |
| 545 |
| 523 GpuProcessTransportFactory::PerCompositorData* | 546 GpuProcessTransportFactory::PerCompositorData* |
| 524 GpuProcessTransportFactory::CreatePerCompositorData( | 547 GpuProcessTransportFactory::CreatePerCompositorData( |
| 525 ui::Compositor* compositor) { | 548 ui::Compositor* compositor) { |
| 526 DCHECK(!per_compositor_data_[compositor]); | 549 DCHECK(!per_compositor_data_[compositor]); |
| 527 | 550 |
| 528 gfx::AcceleratedWidget widget = compositor->widget(); | 551 gfx::AcceleratedWidget widget = compositor->widget(); |
| 529 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 552 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
| 530 | 553 |
| 531 PerCompositorData* data = new PerCompositorData; | 554 PerCompositorData* data = new PerCompositorData; |
| 532 if (compositor->widget() == gfx::kNullAcceleratedWidget) { | 555 if (compositor->widget() == gfx::kNullAcceleratedWidget) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 | 617 |
| 595 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 618 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
| 596 observer_list_, | 619 observer_list_, |
| 597 OnLostResources()); | 620 OnLostResources()); |
| 598 | 621 |
| 599 // Kill things that use the shared context before killing the shared context. | 622 // Kill things that use the shared context before killing the shared context. |
| 600 lost_gl_helper.reset(); | 623 lost_gl_helper.reset(); |
| 601 lost_shared_main_thread_contexts = NULL; | 624 lost_shared_main_thread_contexts = NULL; |
| 602 } | 625 } |
| 603 | 626 |
| 627 void GpuProcessTransportFactory::OnLostWorkerSharedContext() { |
| 628 LOG(ERROR) << "Lost UI shared worker context."; |
| 629 |
| 630 shared_worker_context_provider_ = nullptr; |
| 631 } |
| 632 |
| 604 } // namespace content | 633 } // namespace content |
| OLD | NEW |