| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/threading/simple_thread.h" | 17 #include "base/threading/simple_thread.h" |
| 17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "cc/base/histograms.h" | 20 #include "cc/base/histograms.h" |
| 20 #include "cc/output/compositor_frame.h" | 21 #include "cc/output/compositor_frame.h" |
| 21 #include "cc/output/output_surface.h" | 22 #include "cc/output/output_surface.h" |
| 22 #include "cc/raster/single_thread_task_graph_runner.h" | 23 #include "cc/raster/single_thread_task_graph_runner.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 using gpu::gles2::GLES2Interface; | 83 using gpu::gles2::GLES2Interface; |
| 83 | 84 |
| 84 static const int kNumRetriesBeforeSoftwareFallback = 4; | 85 static const int kNumRetriesBeforeSoftwareFallback = 4; |
| 85 | 86 |
| 86 namespace content { | 87 namespace content { |
| 87 | 88 |
| 88 struct GpuProcessTransportFactory::PerCompositorData { | 89 struct GpuProcessTransportFactory::PerCompositorData { |
| 89 int surface_id; | 90 int surface_id; |
| 90 BrowserCompositorOutputSurface* surface; | 91 BrowserCompositorOutputSurface* surface; |
| 91 ReflectorImpl* reflector; | 92 ReflectorImpl* reflector; |
| 92 scoped_ptr<cc::OnscreenDisplayClient> display_client; | 93 std::unique_ptr<cc::OnscreenDisplayClient> display_client; |
| 93 | 94 |
| 94 PerCompositorData() : surface_id(0), surface(nullptr), reflector(nullptr) {} | 95 PerCompositorData() : surface_id(0), surface(nullptr), reflector(nullptr) {} |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 GpuProcessTransportFactory::GpuProcessTransportFactory() | 98 GpuProcessTransportFactory::GpuProcessTransportFactory() |
| 98 : next_surface_id_namespace_(1u), | 99 : next_surface_id_namespace_(1u), |
| 99 task_graph_runner_(new cc::SingleThreadTaskGraphRunner), | 100 task_graph_runner_(new cc::SingleThreadTaskGraphRunner), |
| 100 callback_factory_(this) { | 101 callback_factory_(this) { |
| 101 cc::SetClientNameForMetrics("Browser"); | 102 cc::SetClientNameForMetrics("Browser"); |
| 102 | 103 |
| 103 surface_manager_ = make_scoped_ptr(new cc::SurfaceManager); | 104 surface_manager_ = base::WrapUnique(new cc::SurfaceManager); |
| 104 | 105 |
| 105 task_graph_runner_->Start("CompositorTileWorker1", | 106 task_graph_runner_->Start("CompositorTileWorker1", |
| 106 base::SimpleThread::Options()); | 107 base::SimpleThread::Options()); |
| 107 #if defined(OS_WIN) | 108 #if defined(OS_WIN) |
| 108 software_backing_.reset(new OutputDeviceBacking); | 109 software_backing_.reset(new OutputDeviceBacking); |
| 109 #endif | 110 #endif |
| 110 } | 111 } |
| 111 | 112 |
| 112 GpuProcessTransportFactory::~GpuProcessTransportFactory() { | 113 GpuProcessTransportFactory::~GpuProcessTransportFactory() { |
| 113 DCHECK(per_compositor_data_.empty()); | 114 DCHECK(per_compositor_data_.empty()); |
| 114 | 115 |
| 115 // Make sure the lost context callback doesn't try to run during destruction. | 116 // Make sure the lost context callback doesn't try to run during destruction. |
| 116 callback_factory_.InvalidateWeakPtrs(); | 117 callback_factory_.InvalidateWeakPtrs(); |
| 117 | 118 |
| 118 task_graph_runner_->Shutdown(); | 119 task_graph_runner_->Shutdown(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 122 std::unique_ptr<WebGraphicsContext3DCommandBufferImpl> |
| 122 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext() { | 123 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext() { |
| 123 CauseForGpuLaunch cause = | 124 CauseForGpuLaunch cause = |
| 124 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 125 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 125 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( | 126 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
| 126 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause)); | 127 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause)); |
| 127 return CreateContextCommon(gpu_channel_host, gpu::kNullSurfaceHandle); | 128 return CreateContextCommon(gpu_channel_host, gpu::kNullSurfaceHandle); |
| 128 } | 129 } |
| 129 | 130 |
| 130 scoped_ptr<cc::SoftwareOutputDevice> | 131 std::unique_ptr<cc::SoftwareOutputDevice> |
| 131 GpuProcessTransportFactory::CreateSoftwareOutputDevice( | 132 GpuProcessTransportFactory::CreateSoftwareOutputDevice( |
| 132 ui::Compositor* compositor) { | 133 ui::Compositor* compositor) { |
| 133 #if defined(MOJO_RUNNER_CLIENT) | 134 #if defined(MOJO_RUNNER_CLIENT) |
| 134 if (IsRunningInMojoShell()) { | 135 if (IsRunningInMojoShell()) { |
| 135 return scoped_ptr<cc::SoftwareOutputDevice>( | 136 return std::unique_ptr<cc::SoftwareOutputDevice>( |
| 136 new SoftwareOutputDeviceMus(compositor)); | 137 new SoftwareOutputDeviceMus(compositor)); |
| 137 } | 138 } |
| 138 #endif | 139 #endif |
| 139 | 140 |
| 140 #if defined(OS_WIN) | 141 #if defined(OS_WIN) |
| 141 return scoped_ptr<cc::SoftwareOutputDevice>( | 142 return std::unique_ptr<cc::SoftwareOutputDevice>( |
| 142 new SoftwareOutputDeviceWin(software_backing_.get(), compositor)); | 143 new SoftwareOutputDeviceWin(software_backing_.get(), compositor)); |
| 143 #elif defined(USE_OZONE) | 144 #elif defined(USE_OZONE) |
| 144 return SoftwareOutputDeviceOzone::Create(compositor); | 145 return SoftwareOutputDeviceOzone::Create(compositor); |
| 145 #elif defined(USE_X11) | 146 #elif defined(USE_X11) |
| 146 return scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareOutputDeviceX11( | 147 return std::unique_ptr<cc::SoftwareOutputDevice>( |
| 147 compositor)); | 148 new SoftwareOutputDeviceX11(compositor)); |
| 148 #elif defined(OS_MACOSX) | 149 #elif defined(OS_MACOSX) |
| 149 return scoped_ptr<cc::SoftwareOutputDevice>( | 150 return std::unique_ptr<cc::SoftwareOutputDevice>( |
| 150 new SoftwareOutputDeviceMac(compositor)); | 151 new SoftwareOutputDeviceMac(compositor)); |
| 151 #else | 152 #else |
| 152 NOTREACHED(); | 153 NOTREACHED(); |
| 153 return scoped_ptr<cc::SoftwareOutputDevice>(); | 154 return std::unique_ptr<cc::SoftwareOutputDevice>(); |
| 154 #endif | 155 #endif |
| 155 } | 156 } |
| 156 | 157 |
| 157 scoped_ptr<BrowserCompositorOverlayCandidateValidator> | 158 std::unique_ptr<BrowserCompositorOverlayCandidateValidator> |
| 158 CreateOverlayCandidateValidator(gfx::AcceleratedWidget widget) { | 159 CreateOverlayCandidateValidator(gfx::AcceleratedWidget widget) { |
| 159 scoped_ptr<BrowserCompositorOverlayCandidateValidator> validator; | 160 std::unique_ptr<BrowserCompositorOverlayCandidateValidator> validator; |
| 160 #if defined(USE_OZONE) | 161 #if defined(USE_OZONE) |
| 161 scoped_ptr<ui::OverlayCandidatesOzone> overlay_candidates = | 162 std::unique_ptr<ui::OverlayCandidatesOzone> overlay_candidates = |
| 162 ui::OzonePlatform::GetInstance() | 163 ui::OzonePlatform::GetInstance() |
| 163 ->GetOverlayManager() | 164 ->GetOverlayManager() |
| 164 ->CreateOverlayCandidates(widget); | 165 ->CreateOverlayCandidates(widget); |
| 165 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 166 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 166 if (overlay_candidates && | 167 if (overlay_candidates && |
| 167 (command_line->HasSwitch(switches::kEnableHardwareOverlays) || | 168 (command_line->HasSwitch(switches::kEnableHardwareOverlays) || |
| 168 command_line->HasSwitch(switches::kOzoneTestSingleOverlaySupport))) { | 169 command_line->HasSwitch(switches::kOzoneTestSingleOverlaySupport))) { |
| 169 validator.reset(new BrowserCompositorOverlayCandidateValidatorOzone( | 170 validator.reset(new BrowserCompositorOverlayCandidateValidatorOzone( |
| 170 widget, std::move(overlay_candidates))); | 171 widget, std::move(overlay_candidates))); |
| 171 } | 172 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 CauseForGpuLaunch cause = | 318 CauseForGpuLaunch cause = |
| 318 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 319 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 319 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( | 320 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( |
| 320 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, | 321 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, |
| 321 callback_factory_.GetWeakPtr(), compositor, | 322 callback_factory_.GetWeakPtr(), compositor, |
| 322 create_gpu_output_surface, num_attempts + 1)); | 323 create_gpu_output_surface, num_attempts + 1)); |
| 323 return; | 324 return; |
| 324 } | 325 } |
| 325 } | 326 } |
| 326 | 327 |
| 327 scoped_ptr<BrowserCompositorOutputSurface> surface; | 328 std::unique_ptr<BrowserCompositorOutputSurface> surface; |
| 328 if (!create_gpu_output_surface) { | 329 if (!create_gpu_output_surface) { |
| 329 surface = make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface( | 330 surface = base::WrapUnique(new SoftwareBrowserCompositorOutputSurface( |
| 330 CreateSoftwareOutputDevice(compositor.get()), | 331 CreateSoftwareOutputDevice(compositor.get()), |
| 331 compositor->vsync_manager())); | 332 compositor->vsync_manager())); |
| 332 } else { | 333 } else { |
| 333 DCHECK(context_provider); | 334 DCHECK(context_provider); |
| 334 ContextProvider::Capabilities capabilities = | 335 ContextProvider::Capabilities capabilities = |
| 335 context_provider->ContextCapabilities(); | 336 context_provider->ContextCapabilities(); |
| 336 if (!data->surface_id) { | 337 if (!data->surface_id) { |
| 337 surface = make_scoped_ptr(new OffscreenBrowserCompositorOutputSurface( | 338 surface = base::WrapUnique(new OffscreenBrowserCompositorOutputSurface( |
| 338 context_provider, shared_worker_context_provider_, | 339 context_provider, shared_worker_context_provider_, |
| 339 compositor->vsync_manager(), | 340 compositor->vsync_manager(), |
| 340 scoped_ptr<BrowserCompositorOverlayCandidateValidator>())); | 341 std::unique_ptr<BrowserCompositorOverlayCandidateValidator>())); |
| 341 } else if (capabilities.gpu.surfaceless) { | 342 } else if (capabilities.gpu.surfaceless) { |
| 342 GLenum target = GL_TEXTURE_2D; | 343 GLenum target = GL_TEXTURE_2D; |
| 343 GLenum format = GL_RGB; | 344 GLenum format = GL_RGB; |
| 344 #if defined(OS_MACOSX) | 345 #if defined(OS_MACOSX) |
| 345 target = GL_TEXTURE_RECTANGLE_ARB; | 346 target = GL_TEXTURE_RECTANGLE_ARB; |
| 346 format = GL_RGBA; | 347 format = GL_RGBA; |
| 347 #endif | 348 #endif |
| 348 surface = | 349 surface = |
| 349 make_scoped_ptr(new GpuSurfacelessBrowserCompositorOutputSurface( | 350 base::WrapUnique(new GpuSurfacelessBrowserCompositorOutputSurface( |
| 350 context_provider, shared_worker_context_provider_, | 351 context_provider, shared_worker_context_provider_, |
| 351 data->surface_id, compositor->vsync_manager(), | 352 data->surface_id, compositor->vsync_manager(), |
| 352 CreateOverlayCandidateValidator(compositor->widget()), target, | 353 CreateOverlayCandidateValidator(compositor->widget()), target, |
| 353 format, BrowserGpuMemoryBufferManager::current())); | 354 format, BrowserGpuMemoryBufferManager::current())); |
| 354 } else { | 355 } else { |
| 355 scoped_ptr<BrowserCompositorOverlayCandidateValidator> validator; | 356 std::unique_ptr<BrowserCompositorOverlayCandidateValidator> validator; |
| 356 #if !defined(OS_MACOSX) | 357 #if !defined(OS_MACOSX) |
| 357 // Overlays are only supported on surfaceless output surfaces on Mac. | 358 // Overlays are only supported on surfaceless output surfaces on Mac. |
| 358 validator = CreateOverlayCandidateValidator(compositor->widget()); | 359 validator = CreateOverlayCandidateValidator(compositor->widget()); |
| 359 #endif | 360 #endif |
| 360 surface = make_scoped_ptr(new GpuBrowserCompositorOutputSurface( | 361 surface = base::WrapUnique(new GpuBrowserCompositorOutputSurface( |
| 361 context_provider, shared_worker_context_provider_, | 362 context_provider, shared_worker_context_provider_, |
| 362 compositor->vsync_manager(), std::move(validator))); | 363 compositor->vsync_manager(), std::move(validator))); |
| 363 } | 364 } |
| 364 } | 365 } |
| 365 | 366 |
| 366 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an | 367 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an |
| 367 // output_surface_map_ here. | 368 // output_surface_map_ here. |
| 368 output_surface_map_.AddWithID(surface.get(), data->surface_id); | 369 output_surface_map_.AddWithID(surface.get(), data->surface_id); |
| 369 data->surface = surface.get(); | 370 data->surface = surface.get(); |
| 370 if (data->reflector) | 371 if (data->reflector) |
| 371 data->reflector->OnSourceSurfaceReady(data->surface); | 372 data->reflector->OnSourceSurfaceReady(data->surface); |
| 372 | 373 |
| 373 #if defined(OS_WIN) | 374 #if defined(OS_WIN) |
| 374 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( | 375 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( |
| 375 compositor->widget()); | 376 compositor->widget()); |
| 376 #endif | 377 #endif |
| 377 | 378 |
| 378 // This gets a bit confusing. Here we have a ContextProvider in the |surface| | 379 // This gets a bit confusing. Here we have a ContextProvider in the |surface| |
| 379 // configured to render directly to this widget. We need to make an | 380 // configured to render directly to this widget. We need to make an |
| 380 // OnscreenDisplayClient associated with that context, then return a | 381 // OnscreenDisplayClient associated with that context, then return a |
| 381 // SurfaceDisplayOutputSurface set up to draw to the display's surface. | 382 // SurfaceDisplayOutputSurface set up to draw to the display's surface. |
| 382 cc::SurfaceManager* manager = surface_manager_.get(); | 383 cc::SurfaceManager* manager = surface_manager_.get(); |
| 383 scoped_ptr<cc::OnscreenDisplayClient> display_client( | 384 std::unique_ptr<cc::OnscreenDisplayClient> display_client( |
| 384 new cc::OnscreenDisplayClient( | 385 new cc::OnscreenDisplayClient( |
| 385 std::move(surface), manager, HostSharedBitmapManager::current(), | 386 std::move(surface), manager, HostSharedBitmapManager::current(), |
| 386 BrowserGpuMemoryBufferManager::current(), | 387 BrowserGpuMemoryBufferManager::current(), |
| 387 compositor->GetRendererSettings(), compositor->task_runner())); | 388 compositor->GetRendererSettings(), compositor->task_runner())); |
| 388 | 389 |
| 389 scoped_ptr<cc::SurfaceDisplayOutputSurface> output_surface( | 390 std::unique_ptr<cc::SurfaceDisplayOutputSurface> output_surface( |
| 390 new cc::SurfaceDisplayOutputSurface( | 391 new cc::SurfaceDisplayOutputSurface( |
| 391 manager, compositor->surface_id_allocator(), context_provider, | 392 manager, compositor->surface_id_allocator(), context_provider, |
| 392 shared_worker_context_provider_)); | 393 shared_worker_context_provider_)); |
| 393 display_client->set_surface_output_surface(output_surface.get()); | 394 display_client->set_surface_output_surface(output_surface.get()); |
| 394 output_surface->set_display_client(display_client.get()); | 395 output_surface->set_display_client(display_client.get()); |
| 395 display_client->display()->Resize(compositor->size()); | 396 display_client->display()->Resize(compositor->size()); |
| 396 data->display_client = std::move(display_client); | 397 data->display_client = std::move(display_client); |
| 397 compositor->SetOutputSurface(std::move(output_surface)); | 398 compositor->SetOutputSurface(std::move(output_surface)); |
| 398 } | 399 } |
| 399 | 400 |
| 400 scoped_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( | 401 std::unique_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( |
| 401 ui::Compositor* source_compositor, | 402 ui::Compositor* source_compositor, |
| 402 ui::Layer* target_layer) { | 403 ui::Layer* target_layer) { |
| 403 PerCompositorData* source_data = per_compositor_data_[source_compositor]; | 404 PerCompositorData* source_data = per_compositor_data_[source_compositor]; |
| 404 DCHECK(source_data); | 405 DCHECK(source_data); |
| 405 | 406 |
| 406 scoped_ptr<ReflectorImpl> reflector( | 407 std::unique_ptr<ReflectorImpl> reflector( |
| 407 new ReflectorImpl(source_compositor, target_layer)); | 408 new ReflectorImpl(source_compositor, target_layer)); |
| 408 source_data->reflector = reflector.get(); | 409 source_data->reflector = reflector.get(); |
| 409 if (BrowserCompositorOutputSurface* source_surface = source_data->surface) | 410 if (BrowserCompositorOutputSurface* source_surface = source_data->surface) |
| 410 reflector->OnSourceSurfaceReady(source_surface); | 411 reflector->OnSourceSurfaceReady(source_surface); |
| 411 return std::move(reflector); | 412 return std::move(reflector); |
| 412 } | 413 } |
| 413 | 414 |
| 414 void GpuProcessTransportFactory::RemoveReflector(ui::Reflector* reflector) { | 415 void GpuProcessTransportFactory::RemoveReflector(ui::Reflector* reflector) { |
| 415 ReflectorImpl* reflector_impl = static_cast<ReflectorImpl*>(reflector); | 416 ReflectorImpl* reflector_impl = static_cast<ReflectorImpl*>(reflector); |
| 416 PerCompositorData* data = | 417 PerCompositorData* data = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 433 if (data->surface_id) | 434 if (data->surface_id) |
| 434 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); | 435 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); |
| 435 delete data; | 436 delete data; |
| 436 per_compositor_data_.erase(it); | 437 per_compositor_data_.erase(it); |
| 437 if (per_compositor_data_.empty()) { | 438 if (per_compositor_data_.empty()) { |
| 438 // Destroying the GLHelper may cause some async actions to be cancelled, | 439 // Destroying the GLHelper may cause some async actions to be cancelled, |
| 439 // causing things to request a new GLHelper. Due to crbug.com/176091 the | 440 // causing things to request a new GLHelper. Due to crbug.com/176091 the |
| 440 // GLHelper created in this case would be lost/leaked if we just reset() | 441 // GLHelper created in this case would be lost/leaked if we just reset() |
| 441 // on the |gl_helper_| variable directly. So instead we call reset() on a | 442 // on the |gl_helper_| variable directly. So instead we call reset() on a |
| 442 // local scoped_ptr. | 443 // local scoped_ptr. |
| 443 scoped_ptr<GLHelper> helper = std::move(gl_helper_); | 444 std::unique_ptr<GLHelper> helper = std::move(gl_helper_); |
| 444 | 445 |
| 445 // If there are any observer left at this point, make sure they clean up | 446 // If there are any observer left at this point, make sure they clean up |
| 446 // before we destroy the GLHelper. | 447 // before we destroy the GLHelper. |
| 447 FOR_EACH_OBSERVER( | 448 FOR_EACH_OBSERVER( |
| 448 ImageTransportFactoryObserver, observer_list_, OnLostResources()); | 449 ImageTransportFactoryObserver, observer_list_, OnLostResources()); |
| 449 | 450 |
| 450 helper.reset(); | 451 helper.reset(); |
| 451 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " | 452 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " |
| 452 "GLHelper to be created."; | 453 "GLHelper to be created."; |
| 453 } | 454 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 475 } | 476 } |
| 476 | 477 |
| 477 cc::TaskGraphRunner* GpuProcessTransportFactory::GetTaskGraphRunner() { | 478 cc::TaskGraphRunner* GpuProcessTransportFactory::GetTaskGraphRunner() { |
| 478 return task_graph_runner_.get(); | 479 return task_graph_runner_.get(); |
| 479 } | 480 } |
| 480 | 481 |
| 481 ui::ContextFactory* GpuProcessTransportFactory::GetContextFactory() { | 482 ui::ContextFactory* GpuProcessTransportFactory::GetContextFactory() { |
| 482 return this; | 483 return this; |
| 483 } | 484 } |
| 484 | 485 |
| 485 scoped_ptr<cc::SurfaceIdAllocator> | 486 std::unique_ptr<cc::SurfaceIdAllocator> |
| 486 GpuProcessTransportFactory::CreateSurfaceIdAllocator() { | 487 GpuProcessTransportFactory::CreateSurfaceIdAllocator() { |
| 487 scoped_ptr<cc::SurfaceIdAllocator> allocator = | 488 std::unique_ptr<cc::SurfaceIdAllocator> allocator = base::WrapUnique( |
| 488 make_scoped_ptr(new cc::SurfaceIdAllocator(next_surface_id_namespace_++)); | 489 new cc::SurfaceIdAllocator(next_surface_id_namespace_++)); |
| 489 if (GetSurfaceManager()) | 490 if (GetSurfaceManager()) |
| 490 allocator->RegisterSurfaceIdNamespace(GetSurfaceManager()); | 491 allocator->RegisterSurfaceIdNamespace(GetSurfaceManager()); |
| 491 return allocator; | 492 return allocator; |
| 492 } | 493 } |
| 493 | 494 |
| 494 void GpuProcessTransportFactory::ResizeDisplay(ui::Compositor* compositor, | 495 void GpuProcessTransportFactory::ResizeDisplay(ui::Compositor* compositor, |
| 495 const gfx::Size& size) { | 496 const gfx::Size& size) { |
| 496 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 497 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 497 if (it == per_compositor_data_.end()) | 498 if (it == per_compositor_data_.end()) |
| 498 return; | 499 return; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 } else { | 600 } else { |
| 600 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 601 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
| 601 data->surface_id = tracker->AddSurfaceForNativeWidget(widget); | 602 data->surface_id = tracker->AddSurfaceForNativeWidget(widget); |
| 602 } | 603 } |
| 603 | 604 |
| 604 per_compositor_data_[compositor] = data; | 605 per_compositor_data_[compositor] = data; |
| 605 | 606 |
| 606 return data; | 607 return data; |
| 607 } | 608 } |
| 608 | 609 |
| 609 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 610 std::unique_ptr<WebGraphicsContext3DCommandBufferImpl> |
| 610 GpuProcessTransportFactory::CreateContextCommon( | 611 GpuProcessTransportFactory::CreateContextCommon( |
| 611 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 612 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| 612 gpu::SurfaceHandle surface_handle) { | 613 gpu::SurfaceHandle surface_handle) { |
| 613 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) | 614 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) |
| 614 return nullptr; | 615 return nullptr; |
| 615 if (!gpu_channel_host) { | 616 if (!gpu_channel_host) { |
| 616 LOG(ERROR) << "Failed to establish GPU channel."; | 617 LOG(ERROR) << "Failed to establish GPU channel."; |
| 617 return nullptr; | 618 return nullptr; |
| 618 } | 619 } |
| 619 | 620 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 635 attributes.stencil_size = 0; | 636 attributes.stencil_size = 0; |
| 636 attributes.samples = 0; | 637 attributes.samples = 0; |
| 637 attributes.sample_buffers = 0; | 638 attributes.sample_buffers = 0; |
| 638 attributes.bind_generates_resource = false; | 639 attributes.bind_generates_resource = false; |
| 639 attributes.lose_context_when_out_of_memory = true; | 640 attributes.lose_context_when_out_of_memory = true; |
| 640 | 641 |
| 641 bool share_resources = true; | 642 bool share_resources = true; |
| 642 bool automatic_flushes = false; | 643 bool automatic_flushes = false; |
| 643 | 644 |
| 644 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); | 645 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); |
| 645 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 646 std::unique_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
| 646 new WebGraphicsContext3DCommandBufferImpl( | 647 new WebGraphicsContext3DCommandBufferImpl( |
| 647 surface_handle, url, gpu_channel_host.get(), attributes, | 648 surface_handle, url, gpu_channel_host.get(), attributes, |
| 648 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, | 649 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, |
| 649 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(), | 650 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(), |
| 650 nullptr)); | 651 nullptr)); |
| 651 return context; | 652 return context; |
| 652 } | 653 } |
| 653 | 654 |
| 654 void GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback() { | 655 void GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback() { |
| 655 base::ThreadTaskRunnerHandle::Get()->PostTask( | 656 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 656 FROM_HERE, | 657 FROM_HERE, |
| 657 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, | 658 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, |
| 658 callback_factory_.GetWeakPtr())); | 659 callback_factory_.GetWeakPtr())); |
| 659 } | 660 } |
| 660 | 661 |
| 661 void GpuProcessTransportFactory::OnLostMainThreadSharedContext() { | 662 void GpuProcessTransportFactory::OnLostMainThreadSharedContext() { |
| 662 LOG(ERROR) << "Lost UI shared context."; | 663 LOG(ERROR) << "Lost UI shared context."; |
| 663 | 664 |
| 664 // Keep old resources around while we call the observers, but ensure that | 665 // Keep old resources around while we call the observers, but ensure that |
| 665 // new resources are created if needed. | 666 // new resources are created if needed. |
| 666 // Kill shared contexts for both threads in tandem so they are always in | 667 // Kill shared contexts for both threads in tandem so they are always in |
| 667 // the same share group. | 668 // the same share group. |
| 668 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts = | 669 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts = |
| 669 shared_main_thread_contexts_; | 670 shared_main_thread_contexts_; |
| 670 shared_main_thread_contexts_ = NULL; | 671 shared_main_thread_contexts_ = NULL; |
| 671 | 672 |
| 672 scoped_ptr<GLHelper> lost_gl_helper = std::move(gl_helper_); | 673 std::unique_ptr<GLHelper> lost_gl_helper = std::move(gl_helper_); |
| 673 | 674 |
| 674 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 675 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
| 675 observer_list_, | 676 observer_list_, |
| 676 OnLostResources()); | 677 OnLostResources()); |
| 677 | 678 |
| 678 // Kill things that use the shared context before killing the shared context. | 679 // Kill things that use the shared context before killing the shared context. |
| 679 lost_gl_helper.reset(); | 680 lost_gl_helper.reset(); |
| 680 lost_shared_main_thread_contexts = NULL; | 681 lost_shared_main_thread_contexts = NULL; |
| 681 } | 682 } |
| 682 | 683 |
| 683 } // namespace content | 684 } // namespace content |
| OLD | NEW |