| 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/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/profiler/scoped_tracker.h" | 15 #include "base/profiler/scoped_tracker.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/simple_thread.h" | 17 #include "base/threading/simple_thread.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "cc/base/histograms.h" | 21 #include "cc/base/histograms.h" |
| 22 #include "cc/base/switches.h" |
| 22 #include "cc/output/texture_mailbox_deleter.h" | 23 #include "cc/output/texture_mailbox_deleter.h" |
| 23 #include "cc/output/vulkan_in_process_context_provider.h" | 24 #include "cc/output/vulkan_in_process_context_provider.h" |
| 24 #include "cc/raster/single_thread_task_graph_runner.h" | 25 #include "cc/raster/single_thread_task_graph_runner.h" |
| 25 #include "cc/raster/task_graph_runner.h" | 26 #include "cc/raster/task_graph_runner.h" |
| 26 #include "cc/scheduler/begin_frame_source.h" | 27 #include "cc/scheduler/begin_frame_source.h" |
| 27 #include "cc/scheduler/delay_based_time_source.h" | 28 #include "cc/scheduler/delay_based_time_source.h" |
| 28 #include "cc/surfaces/direct_compositor_frame_sink.h" | 29 #include "cc/surfaces/direct_compositor_frame_sink.h" |
| 29 #include "cc/surfaces/display.h" | 30 #include "cc/surfaces/display.h" |
| 30 #include "cc/surfaces/display_scheduler.h" | 31 #include "cc/surfaces/display_scheduler.h" |
| 31 #include "cc/surfaces/surface_manager.h" | 32 #include "cc/surfaces/surface_manager.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 #include "gpu/ipc/client/gpu_channel_host.h" | 51 #include "gpu/ipc/client/gpu_channel_host.h" |
| 51 #include "gpu/ipc/host/gpu_memory_buffer_support.h" | 52 #include "gpu/ipc/host/gpu_memory_buffer_support.h" |
| 52 #include "gpu/vulkan/features.h" | 53 #include "gpu/vulkan/features.h" |
| 53 #include "services/service_manager/runner/common/client_util.h" | 54 #include "services/service_manager/runner/common/client_util.h" |
| 54 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" | 55 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
| 55 #include "third_party/khronos/GLES2/gl2.h" | 56 #include "third_party/khronos/GLES2/gl2.h" |
| 56 #include "ui/compositor/compositor.h" | 57 #include "ui/compositor/compositor.h" |
| 57 #include "ui/compositor/compositor_constants.h" | 58 #include "ui/compositor/compositor_constants.h" |
| 58 #include "ui/compositor/compositor_switches.h" | 59 #include "ui/compositor/compositor_switches.h" |
| 59 #include "ui/compositor/layer.h" | 60 #include "ui/compositor/layer.h" |
| 61 #include "ui/display/display_switches.h" |
| 60 #include "ui/display/types/display_snapshot.h" | 62 #include "ui/display/types/display_snapshot.h" |
| 61 #include "ui/gfx/geometry/size.h" | 63 #include "ui/gfx/geometry/size.h" |
| 62 #include "ui/gfx/switches.h" | 64 #include "ui/gfx/switches.h" |
| 63 #include "ui/gl/gl_switches.h" | 65 #include "ui/gl/gl_switches.h" |
| 64 | 66 |
| 65 #if defined(USE_AURA) | 67 #if defined(USE_AURA) |
| 66 #include "content/public/common/service_manager_connection.h" | 68 #include "content/public/common/service_manager_connection.h" |
| 67 #include "ui/aura/window_tree_host.h" | 69 #include "ui/aura/window_tree_host.h" |
| 68 #endif | 70 #endif |
| 69 | 71 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 std::string display_vsync_string = | 206 std::string display_vsync_string = |
| 205 command_line->GetSwitchValueASCII(switches::kDisableGpuVsync); | 207 command_line->GetSwitchValueASCII(switches::kDisableGpuVsync); |
| 206 // See comments in gl_switches about this flag. The browser compositor | 208 // See comments in gl_switches about this flag. The browser compositor |
| 207 // is only unthrottled when "gpu" or no switch value is passed, as it | 209 // is only unthrottled when "gpu" or no switch value is passed, as it |
| 208 // is driven directly by the display compositor. | 210 // is driven directly by the display compositor. |
| 209 if (display_vsync_string != "beginframe") { | 211 if (display_vsync_string != "beginframe") { |
| 210 disable_display_vsync_ = true; | 212 disable_display_vsync_ = true; |
| 211 } | 213 } |
| 212 } | 214 } |
| 213 | 215 |
| 216 renderer_settings_.partial_swap_enabled = |
| 217 !command_line->HasSwitch(switches::kUIDisablePartialSwap); |
| 218 #if defined(OS_WIN) |
| 219 renderer_settings_.finish_rendering_on_resize = true; |
| 220 #elif defined(OS_MACOSX) |
| 221 renderer_settings_.release_overlay_resources_after_gpu_query = true; |
| 222 #endif |
| 223 renderer_settings_.gl_composited_texture_quad_border = |
| 224 command_line->HasSwitch(cc::switches::kGlCompositedTextureQuadBorder); |
| 225 renderer_settings_.show_overdraw_feedback = |
| 226 command_line->HasSwitch(cc::switches::kShowOverdrawFeedback); |
| 227 if (command_line->HasSwitch(switches::kUIEnableRGBA4444Textures)) |
| 228 renderer_settings_.preferred_tile_format = cc::RGBA_4444; |
| 229 renderer_settings_.enable_color_correct_rendering = |
| 230 command_line->HasSwitch(switches::kEnableColorCorrectRendering) || |
| 231 command_line->HasSwitch(switches::kEnableHDR); |
| 232 // Populate buffer_to_texture_target_map for all buffer usage/formats. |
| 233 for (int usage_idx = 0; usage_idx <= static_cast<int>(gfx::BufferUsage::LAST); |
| 234 ++usage_idx) { |
| 235 gfx::BufferUsage usage = static_cast<gfx::BufferUsage>(usage_idx); |
| 236 for (int format_idx = 0; |
| 237 format_idx <= static_cast<int>(gfx::BufferFormat::LAST); |
| 238 ++format_idx) { |
| 239 gfx::BufferFormat format = static_cast<gfx::BufferFormat>(format_idx); |
| 240 uint32_t target = gpu::GetImageTextureTarget(format, usage); |
| 241 renderer_settings_ |
| 242 .buffer_to_texture_target_map[std::make_pair(usage, format)] = target; |
| 243 } |
| 244 } |
| 245 renderer_settings_.disallow_non_exact_resource_reuse = |
| 246 command_line->HasSwitch(cc::switches::kDisallowNonExactResourceReuse); |
| 247 |
| 214 task_graph_runner_->Start("CompositorTileWorker1", | 248 task_graph_runner_->Start("CompositorTileWorker1", |
| 215 base::SimpleThread::Options()); | 249 base::SimpleThread::Options()); |
| 216 #if defined(OS_WIN) | 250 #if defined(OS_WIN) |
| 217 software_backing_.reset(new OutputDeviceBacking); | 251 software_backing_.reset(new OutputDeviceBacking); |
| 218 #endif | 252 #endif |
| 219 } | 253 } |
| 220 | 254 |
| 221 GpuProcessTransportFactory::~GpuProcessTransportFactory() { | 255 GpuProcessTransportFactory::~GpuProcessTransportFactory() { |
| 222 DCHECK(per_compositor_data_.empty()); | 256 DCHECK(per_compositor_data_.empty()); |
| 223 | 257 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 compositor->widget()); | 623 compositor->widget()); |
| 590 #endif | 624 #endif |
| 591 | 625 |
| 592 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( | 626 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 593 compositor->task_runner().get(), | 627 compositor->task_runner().get(), |
| 594 display_output_surface->capabilities().max_frames_pending)); | 628 display_output_surface->capabilities().max_frames_pending)); |
| 595 | 629 |
| 596 // The Display owns and uses the |display_output_surface| created above. | 630 // The Display owns and uses the |display_output_surface| created above. |
| 597 data->display = base::MakeUnique<cc::Display>( | 631 data->display = base::MakeUnique<cc::Display>( |
| 598 display_compositor::HostSharedBitmapManager::current(), | 632 display_compositor::HostSharedBitmapManager::current(), |
| 599 GetGpuMemoryBufferManager(), compositor->GetRendererSettings(), | 633 GetGpuMemoryBufferManager(), renderer_settings_, |
| 600 compositor->frame_sink_id(), begin_frame_source, | 634 compositor->frame_sink_id(), begin_frame_source, |
| 601 std::move(display_output_surface), std::move(scheduler), | 635 std::move(display_output_surface), std::move(scheduler), |
| 602 base::MakeUnique<cc::TextureMailboxDeleter>( | 636 base::MakeUnique<cc::TextureMailboxDeleter>( |
| 603 compositor->task_runner().get())); | 637 compositor->task_runner().get())); |
| 604 // Note that we are careful not to destroy prior BeginFrameSource objects | 638 // Note that we are careful not to destroy prior BeginFrameSource objects |
| 605 // until we have reset |data->display|. | 639 // until we have reset |data->display|. |
| 606 data->synthetic_begin_frame_source = std::move(synthetic_begin_frame_source); | 640 data->synthetic_begin_frame_source = std::move(synthetic_begin_frame_source); |
| 607 data->gpu_vsync_begin_frame_source = std::move(gpu_vsync_begin_frame_source); | 641 data->gpu_vsync_begin_frame_source = std::move(gpu_vsync_begin_frame_source); |
| 608 | 642 |
| 609 // The |delegated_output_surface| is given back to the compositor, it | 643 // The |delegated_output_surface| is given back to the compositor, it |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 #if defined(OS_WIN) | 717 #if defined(OS_WIN) |
| 684 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( | 718 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( |
| 685 compositor->widget()); | 719 compositor->widget()); |
| 686 #endif | 720 #endif |
| 687 } | 721 } |
| 688 | 722 |
| 689 double GpuProcessTransportFactory::GetRefreshRate() const { | 723 double GpuProcessTransportFactory::GetRefreshRate() const { |
| 690 return 60.0; | 724 return 60.0; |
| 691 } | 725 } |
| 692 | 726 |
| 693 uint32_t GpuProcessTransportFactory::GetImageTextureTarget( | |
| 694 gfx::BufferFormat format, | |
| 695 gfx::BufferUsage usage) { | |
| 696 return gpu::GetImageTextureTarget(format, usage); | |
| 697 } | |
| 698 | |
| 699 gpu::GpuMemoryBufferManager* | 727 gpu::GpuMemoryBufferManager* |
| 700 GpuProcessTransportFactory::GetGpuMemoryBufferManager() { | 728 GpuProcessTransportFactory::GetGpuMemoryBufferManager() { |
| 701 return gpu_channel_factory_->GetGpuMemoryBufferManager(); | 729 return gpu_channel_factory_->GetGpuMemoryBufferManager(); |
| 702 } | 730 } |
| 703 | 731 |
| 704 cc::TaskGraphRunner* GpuProcessTransportFactory::GetTaskGraphRunner() { | 732 cc::TaskGraphRunner* GpuProcessTransportFactory::GetTaskGraphRunner() { |
| 705 return task_graph_runner_.get(); | 733 return task_graph_runner_.get(); |
| 706 } | 734 } |
| 707 | 735 |
| 708 ui::ContextFactory* GpuProcessTransportFactory::GetContextFactory() { | 736 ui::ContextFactory* GpuProcessTransportFactory::GetContextFactory() { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 819 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 792 if (it == per_compositor_data_.end()) | 820 if (it == per_compositor_data_.end()) |
| 793 return; | 821 return; |
| 794 PerCompositorData* data = it->second.get(); | 822 PerCompositorData* data = it->second.get(); |
| 795 DCHECK(data); | 823 DCHECK(data); |
| 796 data->output_is_secure = secure; | 824 data->output_is_secure = secure; |
| 797 if (data->display) | 825 if (data->display) |
| 798 data->display->SetOutputIsSecure(secure); | 826 data->display->SetOutputIsSecure(secure); |
| 799 } | 827 } |
| 800 | 828 |
| 829 const cc::RendererSettings& GpuProcessTransportFactory::GetRendererSettings() |
| 830 const { |
| 831 return renderer_settings_; |
| 832 } |
| 833 |
| 801 void GpuProcessTransportFactory::AddObserver( | 834 void GpuProcessTransportFactory::AddObserver( |
| 802 ui::ContextFactoryObserver* observer) { | 835 ui::ContextFactoryObserver* observer) { |
| 803 observer_list_.AddObserver(observer); | 836 observer_list_.AddObserver(observer); |
| 804 } | 837 } |
| 805 | 838 |
| 806 void GpuProcessTransportFactory::RemoveObserver( | 839 void GpuProcessTransportFactory::RemoveObserver( |
| 807 ui::ContextFactoryObserver* observer) { | 840 ui::ContextFactoryObserver* observer) { |
| 808 observer_list_.RemoveObserver(observer); | 841 observer_list_.RemoveObserver(observer); |
| 809 } | 842 } |
| 810 | 843 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 shared_vulkan_context_provider_ = | 978 shared_vulkan_context_provider_ = |
| 946 cc::VulkanInProcessContextProvider::Create(); | 979 cc::VulkanInProcessContextProvider::Create(); |
| 947 } | 980 } |
| 948 | 981 |
| 949 shared_vulkan_context_provider_initialized_ = true; | 982 shared_vulkan_context_provider_initialized_ = true; |
| 950 } | 983 } |
| 951 return shared_vulkan_context_provider_; | 984 return shared_vulkan_context_provider_; |
| 952 } | 985 } |
| 953 | 986 |
| 954 } // namespace content | 987 } // namespace content |
| OLD | NEW |