 Chromium Code Reviews
 Chromium Code Reviews Issue 1449953002:
  compositor-worker: Refactor CompositorWorkerManager  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1449953002:
  compositor-worker: Refactor CompositorWorkerManager  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <limits> | 8 #include <limits> | 
| 9 #include <map> | 9 #include <map> | 
| 10 #include <vector> | 10 #include <vector> | 
| 11 | 11 | 
| 12 #include "base/allocator/allocator_extension.h" | 12 #include "base/allocator/allocator_extension.h" | 
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" | 
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" | 
| 15 #include "base/location.h" | 15 #include "base/location.h" | 
| 16 #include "base/logging.h" | 16 #include "base/logging.h" | 
| 17 #include "base/memory/discardable_memory_allocator.h" | 17 #include "base/memory/discardable_memory_allocator.h" | 
| 18 #include "base/memory/shared_memory.h" | 18 #include "base/memory/shared_memory.h" | 
| 19 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" | 
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" | 
| 21 #include "base/path_service.h" | 21 #include "base/path_service.h" | 
| 22 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" | 
| 23 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" | 
| 24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" | 
| 25 #include "base/strings/string_split.h" | 25 #include "base/strings/string_split.h" | 
| 26 #include "base/strings/string_tokenizer.h" | 26 #include "base/strings/string_tokenizer.h" | 
| 27 #include "base/strings/sys_string_conversions.h" | 27 #include "base/strings/sys_string_conversions.h" | 
| 28 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" | 
| 29 #include "base/synchronization/waitable_event.h" | |
| 29 #include "base/thread_task_runner_handle.h" | 30 #include "base/thread_task_runner_handle.h" | 
| 30 #include "base/threading/simple_thread.h" | 31 #include "base/threading/simple_thread.h" | 
| 31 #include "base/threading/thread_local.h" | 32 #include "base/threading/thread_local.h" | 
| 32 #include "base/threading/thread_restrictions.h" | 33 #include "base/threading/thread_restrictions.h" | 
| 33 #include "base/trace_event/memory_dump_manager.h" | 34 #include "base/trace_event/memory_dump_manager.h" | 
| 34 #include "base/trace_event/trace_event.h" | 35 #include "base/trace_event/trace_event.h" | 
| 35 #include "base/values.h" | 36 #include "base/values.h" | 
| 36 #include "cc/base/histograms.h" | 37 #include "cc/base/histograms.h" | 
| 37 #include "cc/base/switches.h" | 38 #include "cc/base/switches.h" | 
| 38 #include "cc/blink/web_external_bitmap_impl.h" | 39 #include "cc/blink/web_external_bitmap_impl.h" | 
| 39 #include "cc/blink/web_layer_impl.h" | 40 #include "cc/blink/web_layer_impl.h" | 
| 40 #include "cc/layers/layer_settings.h" | 41 #include "cc/layers/layer_settings.h" | 
| 41 #include "cc/raster/task_graph_runner.h" | 42 #include "cc/raster/task_graph_runner.h" | 
| 43 #include "cc/trees/layer_tree_host_common.h" | |
| 42 #include "cc/trees/layer_tree_settings.h" | 44 #include "cc/trees/layer_tree_settings.h" | 
| 45 #include "components/scheduler/child/webthread_base.h" | |
| 43 #include "components/scheduler/renderer/renderer_scheduler.h" | 46 #include "components/scheduler/renderer/renderer_scheduler.h" | 
| 44 #include "content/child/appcache/appcache_dispatcher.h" | 47 #include "content/child/appcache/appcache_dispatcher.h" | 
| 45 #include "content/child/appcache/appcache_frontend_impl.h" | 48 #include "content/child/appcache/appcache_frontend_impl.h" | 
| 46 #include "content/child/child_discardable_shared_memory_manager.h" | 49 #include "content/child/child_discardable_shared_memory_manager.h" | 
| 47 #include "content/child/child_gpu_memory_buffer_manager.h" | 50 #include "content/child/child_gpu_memory_buffer_manager.h" | 
| 48 #include "content/child/child_histogram_message_filter.h" | 51 #include "content/child/child_histogram_message_filter.h" | 
| 49 #include "content/child/child_resource_message_filter.h" | 52 #include "content/child/child_resource_message_filter.h" | 
| 50 #include "content/child/child_shared_bitmap_manager.h" | 53 #include "content/child/child_shared_bitmap_manager.h" | 
| 51 #include "content/child/content_child_helpers.h" | 54 #include "content/child/content_child_helpers.h" | 
| 52 #include "content/child/db_message_filter.h" | 55 #include "content/child/db_message_filter.h" | 
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 #if defined(OS_ANDROID) | 842 #if defined(OS_ANDROID) | 
| 840 if (sync_compositor_message_filter_) { | 843 if (sync_compositor_message_filter_) { | 
| 841 RemoveFilter(sync_compositor_message_filter_.get()); | 844 RemoveFilter(sync_compositor_message_filter_.get()); | 
| 842 sync_compositor_message_filter_ = nullptr; | 845 sync_compositor_message_filter_ = nullptr; | 
| 843 } | 846 } | 
| 844 stream_texture_factory_ = nullptr; | 847 stream_texture_factory_ = nullptr; | 
| 845 #endif | 848 #endif | 
| 846 | 849 | 
| 847 media_thread_.reset(); | 850 media_thread_.reset(); | 
| 848 | 851 | 
| 852 blink_platform_impl_->set_compositor_thread(nullptr); | |
| 853 | |
| 849 compositor_thread_.reset(); | 854 compositor_thread_.reset(); | 
| 850 | 855 | 
| 851 // AudioMessageFilter may be accessed on |media_thread_|, so shutdown after. | 856 // AudioMessageFilter may be accessed on |media_thread_|, so shutdown after. | 
| 852 RemoveFilter(audio_message_filter_.get()); | 857 RemoveFilter(audio_message_filter_.get()); | 
| 853 audio_message_filter_ = NULL; | 858 audio_message_filter_ = NULL; | 
| 854 | 859 | 
| 855 raster_worker_pool_->Shutdown(); | 860 raster_worker_pool_->Shutdown(); | 
| 856 | 861 | 
| 857 main_input_callback_.Cancel(); | 862 main_input_callback_.Cancel(); | 
| 858 input_handler_manager_.reset(); | 863 input_handler_manager_.reset(); | 
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1045 new ResourceSchedulingFilter(resource_task_queue, resource_dispatcher())); | 1050 new ResourceSchedulingFilter(resource_task_queue, resource_dispatcher())); | 
| 1046 channel()->AddFilter(filter.get()); | 1051 channel()->AddFilter(filter.get()); | 
| 1047 resource_dispatcher()->SetResourceSchedulingFilter(filter); | 1052 resource_dispatcher()->SetResourceSchedulingFilter(filter); | 
| 1048 | 1053 | 
| 1049 // The ChildResourceMessageFilter and the ResourceDispatcher need to use the | 1054 // The ChildResourceMessageFilter and the ResourceDispatcher need to use the | 
| 1050 // same queue to ensure tasks are executed in the expected order. | 1055 // same queue to ensure tasks are executed in the expected order. | 
| 1051 child_resource_message_filter()->SetMainThreadTaskRunner(resource_task_queue); | 1056 child_resource_message_filter()->SetMainThreadTaskRunner(resource_task_queue); | 
| 1052 resource_dispatcher()->SetMainThreadTaskRunner(resource_task_queue); | 1057 resource_dispatcher()->SetMainThreadTaskRunner(resource_task_queue); | 
| 1053 } | 1058 } | 
| 1054 | 1059 | 
| 1060 void RenderThreadImpl::InitializeCompositorThread() { | |
| 1061 #if defined(OS_ANDROID) | |
| 1062 SynchronousCompositorFactory* sync_compositor_factory = | |
| 1063 SynchronousCompositorFactory::GetInstance(); | |
| 1064 bool using_ipc_sync_compositing = | |
| 1065 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1066 switches::kIPCSyncCompositing); | |
| 1067 DCHECK(!sync_compositor_factory || !using_ipc_sync_compositing); | |
| 1068 | |
| 1069 if (sync_compositor_factory) { | |
| 1070 compositor_task_runner_ = | |
| 1071 sync_compositor_factory->GetCompositorTaskRunner(); | |
| 1072 } | |
| 1073 #endif | |
| 1074 if (!compositor_task_runner_.get()) { | |
| 1075 base::Thread::Options options; | |
| 1076 #if defined(OS_ANDROID) | |
| 1077 options.priority = base::ThreadPriority::DISPLAY; | |
| 1078 #endif | |
| 1079 compositor_thread_.reset(static_cast<scheduler::WebThreadBase*>( | |
| 1080 blink_platform_impl_->createThreadWithOptions("Compositor", options))); | |
| 1081 compositor_task_runner_ = compositor_thread_->TaskRunner(); | |
| 1082 compositor_task_runner_->PostTask( | |
| 1083 FROM_HERE, | |
| 1084 base::Bind(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed), | |
| 1085 false)); | |
| 1086 // Need to ensure that we finish initializing the compositor thread before | |
| 1087 // setting it on |blink_platform_impl_|. This prevents the unfortunate | |
| 1088 // situation where the platform is torn down before initialization (which | |
| 1089 // depends on the platform) is done. | |
| 1090 base::WaitableEvent event(false, false); | |
| 1091 compositor_task_runner_->PostTask( | |
| 1092 FROM_HERE, | |
| 1093 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | |
| 1094 event.Wait(); | |
| 
piman
2015/12/01 23:44:41
Really sorry to be a pain, but can we move this lo
 
Ian Vollick
2015/12/02 00:26:40
Good point. Done.
 | |
| 1095 | |
| 1096 blink_platform_impl_->set_compositor_thread(compositor_thread_.get()); | |
| 1097 } | |
| 1098 | |
| 1099 InputHandlerManagerClient* input_handler_manager_client = NULL; | |
| 1100 #if defined(OS_ANDROID) | |
| 1101 if (using_ipc_sync_compositing) { | |
| 1102 sync_compositor_message_filter_ = | |
| 1103 new SynchronousCompositorFilter(compositor_task_runner_); | |
| 1104 AddFilter(sync_compositor_message_filter_.get()); | |
| 1105 input_handler_manager_client = sync_compositor_message_filter_.get(); | |
| 1106 } else if (sync_compositor_factory) { | |
| 1107 input_handler_manager_client = | |
| 1108 sync_compositor_factory->GetInputHandlerManagerClient(); | |
| 1109 } | |
| 1110 #endif | |
| 1111 if (!input_handler_manager_client) { | |
| 1112 scoped_refptr<InputEventFilter> compositor_input_event_filter( | |
| 1113 new InputEventFilter(main_input_callback_.callback(), | |
| 1114 main_thread_compositor_task_runner_, | |
| 1115 compositor_task_runner_)); | |
| 1116 input_handler_manager_client = compositor_input_event_filter.get(); | |
| 1117 input_event_filter_ = compositor_input_event_filter; | |
| 1118 } | |
| 1119 input_handler_manager_.reset(new InputHandlerManager( | |
| 1120 compositor_task_runner_, input_handler_manager_client, | |
| 1121 renderer_scheduler_.get())); | |
| 1122 } | |
| 1123 | |
| 1055 void RenderThreadImpl::EnsureWebKitInitialized() { | 1124 void RenderThreadImpl::EnsureWebKitInitialized() { | 
| 1056 if (blink_platform_impl_) | 1125 if (blink_platform_impl_) | 
| 1057 return; | 1126 return; | 
| 1058 | 1127 | 
| 1059 const base::CommandLine& command_line = | 1128 const base::CommandLine& command_line = | 
| 1060 *base::CommandLine::ForCurrentProcess(); | 1129 *base::CommandLine::ForCurrentProcess(); | 
| 1061 | 1130 | 
| 1062 #ifdef ENABLE_VTUNE_JIT_INTERFACE | 1131 #ifdef ENABLE_VTUNE_JIT_INTERFACE | 
| 1063 if (command_line.HasSwitch(switches::kEnableVtune)) | 1132 if (command_line.HasSwitch(switches::kEnableVtune)) | 
| 1064 gin::Debug::SetJitCodeEventHandler(vTune::GetVtuneCodeEventHandler()); | 1133 gin::Debug::SetJitCodeEventHandler(vTune::GetVtuneCodeEventHandler()); | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1075 isolate->SetAddHistogramSampleFunction(AddHistogramSample); | 1144 isolate->SetAddHistogramSampleFunction(AddHistogramSample); | 
| 1076 | 1145 | 
| 1077 main_thread_compositor_task_runner_ = | 1146 main_thread_compositor_task_runner_ = | 
| 1078 renderer_scheduler_->CompositorTaskRunner(); | 1147 renderer_scheduler_->CompositorTaskRunner(); | 
| 1079 | 1148 | 
| 1080 main_input_callback_.Reset( | 1149 main_input_callback_.Reset( | 
| 1081 base::Bind(base::IgnoreResult(&RenderThreadImpl::OnMessageReceived), | 1150 base::Bind(base::IgnoreResult(&RenderThreadImpl::OnMessageReceived), | 
| 1082 base::Unretained(this))); | 1151 base::Unretained(this))); | 
| 1083 | 1152 | 
| 1084 SetResourceDispatchTaskQueue(renderer_scheduler_->LoadingTaskRunner()); | 1153 SetResourceDispatchTaskQueue(renderer_scheduler_->LoadingTaskRunner()); | 
| 1085 | 1154 if (!command_line.HasSwitch(switches::kDisableThreadedCompositing)) | 
| 1086 bool enable = !command_line.HasSwitch(switches::kDisableThreadedCompositing); | 1155 InitializeCompositorThread(); | 
| 1087 if (enable) { | |
| 1088 #if defined(OS_ANDROID) | |
| 1089 SynchronousCompositorFactory* sync_compositor_factory = | |
| 1090 SynchronousCompositorFactory::GetInstance(); | |
| 1091 bool using_ipc_sync_compositing = | |
| 1092 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1093 switches::kIPCSyncCompositing); | |
| 1094 DCHECK(!sync_compositor_factory || !using_ipc_sync_compositing); | |
| 1095 | |
| 1096 if (sync_compositor_factory) { | |
| 1097 compositor_task_runner_ = | |
| 1098 sync_compositor_factory->GetCompositorTaskRunner(); | |
| 1099 } | |
| 1100 #endif | |
| 1101 if (!compositor_task_runner_) { | |
| 1102 compositor_thread_.reset(new base::Thread("Compositor")); | |
| 1103 base::Thread::Options compositor_thread_options; | |
| 1104 #if defined(OS_ANDROID) | |
| 1105 compositor_thread_options.priority = base::ThreadPriority::DISPLAY; | |
| 1106 #endif | |
| 1107 compositor_thread_->StartWithOptions(compositor_thread_options); | |
| 1108 compositor_task_runner_ = compositor_thread_->task_runner(); | |
| 1109 compositor_task_runner_->PostTask( | |
| 1110 FROM_HERE, | |
| 1111 base::Bind(base::IgnoreResult(&ThreadRestrictions::SetIOAllowed), | |
| 1112 false)); | |
| 1113 } | |
| 1114 | |
| 1115 InputHandlerManagerClient* input_handler_manager_client = NULL; | |
| 1116 #if defined(OS_ANDROID) | |
| 1117 if (using_ipc_sync_compositing) { | |
| 1118 sync_compositor_message_filter_ = | |
| 1119 new SynchronousCompositorFilter(compositor_task_runner_); | |
| 1120 AddFilter(sync_compositor_message_filter_.get()); | |
| 1121 input_handler_manager_client = sync_compositor_message_filter_.get(); | |
| 1122 } else if (sync_compositor_factory) { | |
| 1123 input_handler_manager_client = | |
| 1124 sync_compositor_factory->GetInputHandlerManagerClient(); | |
| 1125 } | |
| 1126 #endif | |
| 1127 if (!input_handler_manager_client) { | |
| 1128 scoped_refptr<InputEventFilter> compositor_input_event_filter( | |
| 1129 new InputEventFilter(main_input_callback_.callback(), | |
| 1130 main_thread_compositor_task_runner_, | |
| 1131 compositor_task_runner_)); | |
| 1132 input_handler_manager_client = compositor_input_event_filter.get(); | |
| 1133 input_event_filter_ = compositor_input_event_filter; | |
| 1134 } | |
| 1135 input_handler_manager_.reset(new InputHandlerManager( | |
| 1136 compositor_task_runner_, input_handler_manager_client, | |
| 1137 renderer_scheduler_.get())); | |
| 1138 } | |
| 1139 | 1156 | 
| 1140 if (!input_event_filter_.get()) { | 1157 if (!input_event_filter_.get()) { | 
| 1141 // Always provide an input event filter implementation to ensure consistent | 1158 // Always provide an input event filter implementation to ensure consistent | 
| 1142 // input event scheduling and prioritization. | 1159 // input event scheduling and prioritization. | 
| 1143 // TODO(jdduke): Merge InputEventFilter, InputHandlerManager and | 1160 // TODO(jdduke): Merge InputEventFilter, InputHandlerManager and | 
| 1144 // MainThreadInputEventFilter, crbug.com/436057. | 1161 // MainThreadInputEventFilter, crbug.com/436057. | 
| 1145 input_event_filter_ = new MainThreadInputEventFilter( | 1162 input_event_filter_ = new MainThreadInputEventFilter( | 
| 1146 main_input_callback_.callback(), main_thread_compositor_task_runner_); | 1163 main_input_callback_.callback(), main_thread_compositor_task_runner_); | 
| 1147 } | 1164 } | 
| 1148 AddFilter(input_event_filter_.get()); | 1165 AddFilter(input_event_filter_.get()); | 
| 1149 | 1166 | 
| 1150 scoped_refptr<base::SingleThreadTaskRunner> compositor_impl_side_task_runner; | 1167 scoped_refptr<base::SingleThreadTaskRunner> compositor_impl_side_task_runner; | 
| 1151 if (enable) | 1168 if (compositor_task_runner_) | 
| 1152 compositor_impl_side_task_runner = compositor_task_runner_; | 1169 compositor_impl_side_task_runner = compositor_task_runner_; | 
| 1153 else | 1170 else | 
| 1154 compositor_impl_side_task_runner = base::ThreadTaskRunnerHandle::Get(); | 1171 compositor_impl_side_task_runner = base::ThreadTaskRunnerHandle::Get(); | 
| 1155 | 1172 | 
| 1156 compositor_message_filter_ = new CompositorForwardingMessageFilter( | 1173 compositor_message_filter_ = new CompositorForwardingMessageFilter( | 
| 1157 compositor_impl_side_task_runner.get()); | 1174 compositor_impl_side_task_runner.get()); | 
| 1158 AddFilter(compositor_message_filter_.get()); | 1175 AddFilter(compositor_message_filter_.get()); | 
| 1159 | 1176 | 
| 1160 RenderThreadImpl::RegisterSchemes(); | 1177 RenderThreadImpl::RegisterSchemes(); | 
| 1161 | 1178 | 
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1985 | 2002 | 
| 1986 void RenderThreadImpl::ReleaseFreeMemory() { | 2003 void RenderThreadImpl::ReleaseFreeMemory() { | 
| 1987 base::allocator::ReleaseFreeMemory(); | 2004 base::allocator::ReleaseFreeMemory(); | 
| 1988 discardable_shared_memory_manager()->ReleaseFreeMemory(); | 2005 discardable_shared_memory_manager()->ReleaseFreeMemory(); | 
| 1989 | 2006 | 
| 1990 if (blink_platform_impl_) | 2007 if (blink_platform_impl_) | 
| 1991 blink::decommitFreeableMemory(); | 2008 blink::decommitFreeableMemory(); | 
| 1992 } | 2009 } | 
| 1993 | 2010 | 
| 1994 } // namespace content | 2011 } // namespace content | 
| OLD | NEW |