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" | |
14 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
15 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
16 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
17 #include "base/threading/simple_thread.h" | 16 #include "base/threading/simple_thread.h" |
18 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
19 #include "build/build_config.h" | 18 #include "build/build_config.h" |
20 #include "cc/base/histograms.h" | 19 #include "cc/base/histograms.h" |
21 #include "cc/output/compositor_frame.h" | 20 #include "cc/output/compositor_frame.h" |
22 #include "cc/output/output_surface.h" | 21 #include "cc/output/output_surface.h" |
23 #include "cc/raster/single_thread_task_graph_runner.h" | 22 #include "cc/raster/single_thread_task_graph_runner.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 callback_factory_.GetWeakPtr(), compositor, | 321 callback_factory_.GetWeakPtr(), compositor, |
323 create_gpu_output_surface, num_attempts + 1)); | 322 create_gpu_output_surface, num_attempts + 1)); |
324 return; | 323 return; |
325 } | 324 } |
326 } | 325 } |
327 | 326 |
328 std::unique_ptr<BrowserCompositorOutputSurface> surface; | 327 std::unique_ptr<BrowserCompositorOutputSurface> surface; |
329 if (!create_gpu_output_surface) { | 328 if (!create_gpu_output_surface) { |
330 surface = base::WrapUnique(new SoftwareBrowserCompositorOutputSurface( | 329 surface = base::WrapUnique(new SoftwareBrowserCompositorOutputSurface( |
331 CreateSoftwareOutputDevice(compositor.get()), | 330 CreateSoftwareOutputDevice(compositor.get()), |
332 compositor->vsync_manager())); | 331 compositor->vsync_manager(), compositor->task_runner().get())); |
333 } else { | 332 } else { |
334 DCHECK(context_provider); | 333 DCHECK(context_provider); |
335 ContextProvider::Capabilities capabilities = | 334 ContextProvider::Capabilities capabilities = |
336 context_provider->ContextCapabilities(); | 335 context_provider->ContextCapabilities(); |
337 if (!data->surface_id) { | 336 if (!data->surface_id) { |
338 surface = base::WrapUnique(new OffscreenBrowserCompositorOutputSurface( | 337 surface = base::WrapUnique(new OffscreenBrowserCompositorOutputSurface( |
339 context_provider, shared_worker_context_provider_, | 338 context_provider, shared_worker_context_provider_, |
340 compositor->vsync_manager(), | 339 compositor->vsync_manager(), compositor->task_runner().get(), |
341 std::unique_ptr<BrowserCompositorOverlayCandidateValidator>())); | 340 std::unique_ptr<BrowserCompositorOverlayCandidateValidator>())); |
342 } else if (capabilities.gpu.surfaceless) { | 341 } else if (capabilities.gpu.surfaceless) { |
343 GLenum target = GL_TEXTURE_2D; | 342 GLenum target = GL_TEXTURE_2D; |
344 GLenum format = GL_RGB; | 343 GLenum format = GL_RGB; |
345 #if defined(OS_MACOSX) | 344 #if defined(OS_MACOSX) |
346 target = GL_TEXTURE_RECTANGLE_ARB; | 345 target = GL_TEXTURE_RECTANGLE_ARB; |
347 format = GL_RGBA; | 346 format = GL_RGBA; |
348 #endif | 347 #endif |
349 surface = | 348 surface = |
350 base::WrapUnique(new GpuSurfacelessBrowserCompositorOutputSurface( | 349 base::WrapUnique(new GpuSurfacelessBrowserCompositorOutputSurface( |
351 context_provider, shared_worker_context_provider_, | 350 context_provider, shared_worker_context_provider_, |
352 data->surface_id, compositor->vsync_manager(), | 351 data->surface_id, compositor->vsync_manager(), |
| 352 compositor->task_runner().get(), |
353 CreateOverlayCandidateValidator(compositor->widget()), target, | 353 CreateOverlayCandidateValidator(compositor->widget()), target, |
354 format, BrowserGpuMemoryBufferManager::current())); | 354 format, BrowserGpuMemoryBufferManager::current())); |
355 } else { | 355 } else { |
356 std::unique_ptr<BrowserCompositorOverlayCandidateValidator> validator; | 356 std::unique_ptr<BrowserCompositorOverlayCandidateValidator> validator; |
357 #if !defined(OS_MACOSX) | 357 #if !defined(OS_MACOSX) |
358 // Overlays are only supported on surfaceless output surfaces on Mac. | 358 // Overlays are only supported on surfaceless output surfaces on Mac. |
359 validator = CreateOverlayCandidateValidator(compositor->widget()); | 359 validator = CreateOverlayCandidateValidator(compositor->widget()); |
360 #endif | 360 #endif |
361 surface = base::WrapUnique(new GpuBrowserCompositorOutputSurface( | 361 surface = base::WrapUnique(new GpuBrowserCompositorOutputSurface( |
362 context_provider, shared_worker_context_provider_, | 362 context_provider, shared_worker_context_provider_, |
363 compositor->vsync_manager(), std::move(validator))); | 363 compositor->vsync_manager(), compositor->task_runner().get(), |
| 364 std::move(validator))); |
364 } | 365 } |
365 } | 366 } |
366 | 367 |
367 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an | 368 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an |
368 // output_surface_map_ here. | 369 // output_surface_map_ here. |
369 output_surface_map_.AddWithID(surface.get(), data->surface_id); | 370 output_surface_map_.AddWithID(surface.get(), data->surface_id); |
370 data->surface = surface.get(); | 371 data->surface = surface.get(); |
371 if (data->reflector) | 372 if (data->reflector) |
372 data->reflector->OnSourceSurfaceReady(data->surface); | 373 data->reflector->OnSourceSurfaceReady(data->surface); |
373 | 374 |
374 #if defined(OS_WIN) | 375 #if defined(OS_WIN) |
375 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( | 376 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( |
376 compositor->widget()); | 377 compositor->widget()); |
377 #endif | 378 #endif |
378 | 379 |
379 // This gets a bit confusing. Here we have a ContextProvider in the |surface| | 380 // This gets a bit confusing. Here we have a ContextProvider in the |surface| |
380 // configured to render directly to this widget. We need to make an | 381 // configured to render directly to this widget. We need to make an |
381 // OnscreenDisplayClient associated with that context, then return a | 382 // OnscreenDisplayClient associated with that context, then return a |
382 // SurfaceDisplayOutputSurface set up to draw to the display's surface. | 383 // SurfaceDisplayOutputSurface set up to draw to the display's surface. |
383 cc::SurfaceManager* manager = surface_manager_.get(); | 384 cc::SurfaceManager* manager = surface_manager_.get(); |
384 std::unique_ptr<cc::OnscreenDisplayClient> display_client( | 385 std::unique_ptr<cc::OnscreenDisplayClient> display_client( |
385 new cc::OnscreenDisplayClient( | 386 new cc::OnscreenDisplayClient( |
386 std::move(surface), manager, HostSharedBitmapManager::current(), | 387 std::move(surface), manager, HostSharedBitmapManager::current(), |
387 BrowserGpuMemoryBufferManager::current(), | 388 BrowserGpuMemoryBufferManager::current(), |
388 compositor->GetRendererSettings(), compositor->task_runner())); | 389 compositor->GetRendererSettings(), compositor->task_runner(), |
| 390 compositor->surface_id_allocator()->id_namespace())); |
389 | 391 |
390 std::unique_ptr<cc::SurfaceDisplayOutputSurface> output_surface( | 392 std::unique_ptr<cc::SurfaceDisplayOutputSurface> output_surface( |
391 new cc::SurfaceDisplayOutputSurface( | 393 new cc::SurfaceDisplayOutputSurface( |
392 manager, compositor->surface_id_allocator(), context_provider, | 394 manager, compositor->surface_id_allocator(), context_provider, |
393 shared_worker_context_provider_)); | 395 shared_worker_context_provider_)); |
394 display_client->set_surface_output_surface(output_surface.get()); | 396 display_client->set_surface_output_surface(output_surface.get()); |
395 output_surface->set_display_client(display_client.get()); | 397 output_surface->set_display_client(display_client.get()); |
396 display_client->display()->Resize(compositor->size()); | 398 display_client->display()->Resize(compositor->size()); |
397 data->display_client = std::move(display_client); | 399 data->display_client = std::move(display_client); |
398 compositor->SetOutputSurface(std::move(output_surface)); | 400 compositor->SetOutputSurface(std::move(output_surface)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 output_surface_map_.Remove(data->surface_id); | 435 output_surface_map_.Remove(data->surface_id); |
434 if (data->surface_id) | 436 if (data->surface_id) |
435 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); | 437 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); |
436 delete data; | 438 delete data; |
437 per_compositor_data_.erase(it); | 439 per_compositor_data_.erase(it); |
438 if (per_compositor_data_.empty()) { | 440 if (per_compositor_data_.empty()) { |
439 // Destroying the GLHelper may cause some async actions to be cancelled, | 441 // Destroying the GLHelper may cause some async actions to be cancelled, |
440 // causing things to request a new GLHelper. Due to crbug.com/176091 the | 442 // causing things to request a new GLHelper. Due to crbug.com/176091 the |
441 // GLHelper created in this case would be lost/leaked if we just reset() | 443 // GLHelper created in this case would be lost/leaked if we just reset() |
442 // on the |gl_helper_| variable directly. So instead we call reset() on a | 444 // on the |gl_helper_| variable directly. So instead we call reset() on a |
443 // local scoped_ptr. | 445 // local std::unique_ptr. |
444 std::unique_ptr<GLHelper> helper = std::move(gl_helper_); | 446 std::unique_ptr<GLHelper> helper = std::move(gl_helper_); |
445 | 447 |
446 // If there are any observer left at this point, make sure they clean up | 448 // If there are any observer left at this point, make sure they clean up |
447 // before we destroy the GLHelper. | 449 // before we destroy the GLHelper. |
448 FOR_EACH_OBSERVER( | 450 FOR_EACH_OBSERVER( |
449 ImageTransportFactoryObserver, observer_list_, OnLostResources()); | 451 ImageTransportFactoryObserver, observer_list_, OnLostResources()); |
450 | 452 |
451 helper.reset(); | 453 helper.reset(); |
452 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " | 454 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " |
453 "GLHelper to be created."; | 455 "GLHelper to be created."; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 677 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
676 observer_list_, | 678 observer_list_, |
677 OnLostResources()); | 679 OnLostResources()); |
678 | 680 |
679 // Kill things that use the shared context before killing the shared context. | 681 // Kill things that use the shared context before killing the shared context. |
680 lost_gl_helper.reset(); | 682 lost_gl_helper.reset(); |
681 lost_shared_main_thread_contexts = NULL; | 683 lost_shared_main_thread_contexts = NULL; |
682 } | 684 } |
683 | 685 |
684 } // namespace content | 686 } // namespace content |
OLD | NEW |