Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/gpu/render_widget_compositor.h" | 5 #include "content/renderer/gpu/render_widget_compositor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "base/task_scheduler/post_task.h" | 23 #include "base/task_scheduler/post_task.h" |
| 24 #include "base/task_scheduler/task_scheduler.h" | 24 #include "base/task_scheduler/task_scheduler.h" |
| 25 #include "base/task_scheduler/task_traits.h" | 25 #include "base/task_scheduler/task_traits.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 28 #include "base/values.h" | 28 #include "base/values.h" |
| 29 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 30 #include "cc/animation/animation_host.h" | 30 #include "cc/animation/animation_host.h" |
| 31 #include "cc/animation/animation_timeline.h" | 31 #include "cc/animation/animation_timeline.h" |
| 32 #include "cc/base/switches.h" | 32 #include "cc/base/switches.h" |
| 33 #include "cc/blimp/engine_picture_cache.h" | |
| 34 #include "cc/blimp/image_serialization_processor.h" | |
| 35 #include "cc/blimp/layer_tree_host_remote.h" | |
| 36 #include "cc/blimp/remote_compositor_bridge.h" | |
| 37 #include "cc/blink/web_layer_impl.h" | 33 #include "cc/blink/web_layer_impl.h" |
| 38 #include "cc/debug/layer_tree_debug_state.h" | 34 #include "cc/debug/layer_tree_debug_state.h" |
| 39 #include "cc/debug/micro_benchmark.h" | 35 #include "cc/debug/micro_benchmark.h" |
| 40 #include "cc/input/layer_selection_bound.h" | 36 #include "cc/input/layer_selection_bound.h" |
| 41 #include "cc/layers/layer.h" | 37 #include "cc/layers/layer.h" |
| 42 #include "cc/output/begin_frame_args.h" | 38 #include "cc/output/begin_frame_args.h" |
| 43 #include "cc/output/copy_output_request.h" | 39 #include "cc/output/copy_output_request.h" |
| 44 #include "cc/output/copy_output_result.h" | 40 #include "cc/output/copy_output_result.h" |
| 45 #include "cc/output/latency_info_swap_promise.h" | 41 #include "cc/output/latency_info_swap_promise.h" |
| 46 #include "cc/output/swap_promise.h" | 42 #include "cc/output/swap_promise.h" |
| 47 #include "cc/proto/compositor_message.pb.h" | |
| 48 #include "cc/resources/single_release_callback.h" | 43 #include "cc/resources/single_release_callback.h" |
| 49 #include "cc/scheduler/begin_frame_source.h" | 44 #include "cc/scheduler/begin_frame_source.h" |
| 50 #include "cc/trees/latency_info_swap_promise_monitor.h" | 45 #include "cc/trees/latency_info_swap_promise_monitor.h" |
| 51 #include "cc/trees/layer_tree_host_in_process.h" | 46 #include "cc/trees/layer_tree_host_in_process.h" |
| 52 #include "cc/trees/layer_tree_mutator.h" | 47 #include "cc/trees/layer_tree_mutator.h" |
| 53 #include "content/common/content_switches_internal.h" | 48 #include "content/common/content_switches_internal.h" |
| 54 #include "content/common/layer_tree_settings_factory.h" | 49 #include "content/common/layer_tree_settings_factory.h" |
| 55 #include "content/public/common/content_client.h" | 50 #include "content/public/common/content_client.h" |
| 56 #include "content/public/common/content_switches.h" | 51 #include "content/public/common/content_switches.h" |
| 57 #include "content/public/common/screen_info.h" | 52 #include "content/public/common/screen_info.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 | 201 |
| 207 RenderWidgetCompositor::RenderWidgetCompositor( | 202 RenderWidgetCompositor::RenderWidgetCompositor( |
| 208 RenderWidgetCompositorDelegate* delegate, | 203 RenderWidgetCompositorDelegate* delegate, |
| 209 CompositorDependencies* compositor_deps) | 204 CompositorDependencies* compositor_deps) |
| 210 : num_failed_recreate_attempts_(0), | 205 : num_failed_recreate_attempts_(0), |
| 211 delegate_(delegate), | 206 delegate_(delegate), |
| 212 compositor_deps_(compositor_deps), | 207 compositor_deps_(compositor_deps), |
| 213 threaded_(!!compositor_deps_->GetCompositorImplThreadTaskRunner()), | 208 threaded_(!!compositor_deps_->GetCompositorImplThreadTaskRunner()), |
| 214 never_visible_(false), | 209 never_visible_(false), |
| 215 layout_and_paint_async_callback_(nullptr), | 210 layout_and_paint_async_callback_(nullptr), |
| 216 remote_proto_channel_receiver_(nullptr), | |
| 217 weak_factory_(this) {} | 211 weak_factory_(this) {} |
| 218 | 212 |
| 219 void RenderWidgetCompositor::Initialize(float device_scale_factor, | 213 void RenderWidgetCompositor::Initialize(float device_scale_factor, |
| 220 const ScreenInfo& screen_info) { | 214 const ScreenInfo& screen_info) { |
| 221 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | 215 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 222 cc::LayerTreeSettings settings = GenerateLayerTreeSettings( | 216 cc::LayerTreeSettings settings = GenerateLayerTreeSettings( |
| 223 *cmd, compositor_deps_, device_scale_factor, screen_info); | 217 *cmd, compositor_deps_, device_scale_factor, screen_info); |
| 224 | 218 |
| 225 animation_host_ = cc::AnimationHost::CreateMainInstance(); | 219 animation_host_ = cc::AnimationHost::CreateMainInstance(); |
| 226 | |
| 227 if (cmd->HasSwitch(switches::kUseRemoteCompositing)) { | |
| 228 DCHECK(!threaded_); | |
| 229 | |
| 230 cc::LayerTreeHostRemote::InitParams params; | |
| 231 params.client = this; | |
| 232 params.main_task_runner = | |
| 233 compositor_deps_->GetCompositorMainThreadTaskRunner(); | |
| 234 params.mutator_host = animation_host_.get(); | |
| 235 params.remote_compositor_bridge = | |
| 236 GetContentClient()->renderer()->CreateRemoteCompositorBridge( | |
| 237 this, params.main_task_runner); | |
| 238 params.engine_picture_cache = | |
| 239 compositor_deps_->GetImageSerializationProcessor() | |
| 240 ->CreateEnginePictureCache(); | |
| 241 params.settings = &settings; | |
| 242 layer_tree_host_ = base::MakeUnique<cc::LayerTreeHostRemote>(¶ms); | |
| 243 } else { | |
| 244 cc::LayerTreeHostInProcess::InitParams params; | 220 cc::LayerTreeHostInProcess::InitParams params; |
|
Charlie Reis
2017/01/19 23:37:33
Style nit: Fix indent on this block.
(Might be wo
Khushal
2017/01/19 23:47:17
Woops. Done.
| |
| 245 params.client = this; | 221 params.client = this; |
| 246 params.settings = &settings; | 222 params.settings = &settings; |
| 247 params.task_graph_runner = compositor_deps_->GetTaskGraphRunner(); | 223 params.task_graph_runner = compositor_deps_->GetTaskGraphRunner(); |
| 248 params.main_task_runner = | 224 params.main_task_runner = |
| 249 compositor_deps_->GetCompositorMainThreadTaskRunner(); | 225 compositor_deps_->GetCompositorMainThreadTaskRunner(); |
| 250 params.mutator_host = animation_host_.get(); | 226 params.mutator_host = animation_host_.get(); |
| 251 if (base::TaskScheduler::GetInstance()) { | 227 if (base::TaskScheduler::GetInstance()) { |
| 252 params.image_worker_task_runner = | 228 params.image_worker_task_runner = |
| 253 base::CreateSequencedTaskRunnerWithTraits( | 229 base::CreateSequencedTaskRunnerWithTraits( |
| 254 base::TaskTraits() | 230 base::TaskTraits() |
| 255 .WithPriority(base::TaskPriority::BACKGROUND) | 231 .WithPriority(base::TaskPriority::BACKGROUND) |
| 256 .WithShutdownBehavior( | 232 .WithShutdownBehavior( |
| 257 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)); | 233 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)); |
| 258 } | 234 } |
| 259 if (!threaded_) { | 235 if (!threaded_) { |
| 260 // Single-threaded layout tests. | 236 // Single-threaded layout tests. |
| 261 layer_tree_host_ = | 237 layer_tree_host_ = |
| 262 cc::LayerTreeHostInProcess::CreateSingleThreaded(this, ¶ms); | 238 cc::LayerTreeHostInProcess::CreateSingleThreaded(this, ¶ms); |
| 263 } else { | 239 } else { |
| 264 layer_tree_host_ = cc::LayerTreeHostInProcess::CreateThreaded( | 240 layer_tree_host_ = cc::LayerTreeHostInProcess::CreateThreaded( |
| 265 compositor_deps_->GetCompositorImplThreadTaskRunner(), ¶ms); | 241 compositor_deps_->GetCompositorImplThreadTaskRunner(), ¶ms); |
| 266 } | 242 } |
| 267 } | |
| 268 | |
| 269 DCHECK(layer_tree_host_); | 243 DCHECK(layer_tree_host_); |
| 270 } | 244 } |
| 271 | 245 |
| 272 RenderWidgetCompositor::~RenderWidgetCompositor() = default; | 246 RenderWidgetCompositor::~RenderWidgetCompositor() = default; |
| 273 | 247 |
| 274 // static | 248 // static |
| 275 cc::LayerTreeSettings RenderWidgetCompositor::GenerateLayerTreeSettings( | 249 cc::LayerTreeSettings RenderWidgetCompositor::GenerateLayerTreeSettings( |
| 276 const base::CommandLine& cmd, | 250 const base::CommandLine& cmd, |
| 277 CompositorDependencies* compositor_deps, | 251 CompositorDependencies* compositor_deps, |
| 278 float device_scale_factor, | 252 float device_scale_factor, |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1092 delegate_->RequestScheduleAnimation(); | 1066 delegate_->RequestScheduleAnimation(); |
| 1093 } | 1067 } |
| 1094 | 1068 |
| 1095 void RenderWidgetCompositor::DidSubmitCompositorFrame() {} | 1069 void RenderWidgetCompositor::DidSubmitCompositorFrame() {} |
| 1096 | 1070 |
| 1097 void RenderWidgetCompositor::DidLoseCompositorFrameSink() { | 1071 void RenderWidgetCompositor::DidLoseCompositorFrameSink() { |
| 1098 // The CompositorFrameSink is not lost in layout tests (single thread mode). | 1072 // The CompositorFrameSink is not lost in layout tests (single thread mode). |
| 1099 NOTREACHED(); | 1073 NOTREACHED(); |
| 1100 } | 1074 } |
| 1101 | 1075 |
| 1102 void RenderWidgetCompositor::SetProtoReceiver(ProtoReceiver* receiver) { | |
| 1103 remote_proto_channel_receiver_ = receiver; | |
| 1104 } | |
| 1105 | |
| 1106 void RenderWidgetCompositor::SendCompositorProto( | |
| 1107 const cc::proto::CompositorMessage& proto) { | |
| 1108 int signed_size = proto.ByteSize(); | |
| 1109 size_t unsigned_size = base::checked_cast<size_t>(signed_size); | |
| 1110 std::vector<uint8_t> serialized(unsigned_size); | |
| 1111 proto.SerializeToArray(serialized.data(), signed_size); | |
| 1112 delegate_->ForwardCompositorProto(serialized); | |
| 1113 } | |
| 1114 | |
| 1115 void RenderWidgetCompositor::SetFrameSinkId( | 1076 void RenderWidgetCompositor::SetFrameSinkId( |
| 1116 const cc::FrameSinkId& frame_sink_id) { | 1077 const cc::FrameSinkId& frame_sink_id) { |
| 1117 frame_sink_id_ = frame_sink_id; | 1078 frame_sink_id_ = frame_sink_id; |
| 1118 layer_tree_host_->SetFrameSinkId(frame_sink_id); | 1079 layer_tree_host_->SetFrameSinkId(frame_sink_id); |
| 1119 } | 1080 } |
| 1120 | 1081 |
| 1121 void RenderWidgetCompositor::OnHandleCompositorProto( | |
| 1122 const std::vector<uint8_t>& proto) { | |
| 1123 DCHECK(remote_proto_channel_receiver_); | |
| 1124 | |
| 1125 std::unique_ptr<cc::proto::CompositorMessage> deserialized( | |
| 1126 new cc::proto::CompositorMessage); | |
| 1127 int signed_size = base::checked_cast<int>(proto.size()); | |
| 1128 if (!deserialized->ParseFromArray(proto.data(), signed_size)) { | |
| 1129 LOG(ERROR) << "Unable to parse compositor proto."; | |
| 1130 return; | |
| 1131 } | |
| 1132 | |
| 1133 remote_proto_channel_receiver_->OnProtoReceived(std::move(deserialized)); | |
| 1134 } | |
| 1135 | |
| 1136 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( | 1082 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( |
| 1137 float device_scale) { | 1083 float device_scale) { |
| 1138 layer_tree_host_->GetLayerTree()->SetPaintedDeviceScaleFactor(device_scale); | 1084 layer_tree_host_->GetLayerTree()->SetPaintedDeviceScaleFactor(device_scale); |
| 1139 } | 1085 } |
| 1140 | 1086 |
| 1141 void RenderWidgetCompositor::SetDeviceColorSpace( | 1087 void RenderWidgetCompositor::SetDeviceColorSpace( |
| 1142 const gfx::ColorSpace& color_space) { | 1088 const gfx::ColorSpace& color_space) { |
| 1143 layer_tree_host_->GetLayerTree()->SetDeviceColorSpace(color_space); | 1089 layer_tree_host_->GetLayerTree()->SetDeviceColorSpace(color_space); |
| 1144 } | 1090 } |
| 1145 | 1091 |
| 1146 } // namespace content | 1092 } // namespace content |
| OLD | NEW |