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 <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/numerics/safe_conversions.h" |
13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
16 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
17 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "cc/animation/animation_host.h" | 21 #include "cc/animation/animation_host.h" |
21 #include "cc/animation/animation_timeline.h" | 22 #include "cc/animation/animation_timeline.h" |
22 #include "cc/base/switches.h" | 23 #include "cc/base/switches.h" |
23 #include "cc/blink/web_compositor_animation_timeline_impl.h" | 24 #include "cc/blink/web_compositor_animation_timeline_impl.h" |
24 #include "cc/blink/web_layer_impl.h" | 25 #include "cc/blink/web_layer_impl.h" |
25 #include "cc/debug/layer_tree_debug_state.h" | 26 #include "cc/debug/layer_tree_debug_state.h" |
26 #include "cc/debug/micro_benchmark.h" | 27 #include "cc/debug/micro_benchmark.h" |
27 #include "cc/input/layer_selection_bound.h" | 28 #include "cc/input/layer_selection_bound.h" |
28 #include "cc/layers/layer.h" | 29 #include "cc/layers/layer.h" |
29 #include "cc/output/begin_frame_args.h" | 30 #include "cc/output/begin_frame_args.h" |
30 #include "cc/output/copy_output_request.h" | 31 #include "cc/output/copy_output_request.h" |
31 #include "cc/output/copy_output_result.h" | 32 #include "cc/output/copy_output_result.h" |
32 #include "cc/output/latency_info_swap_promise.h" | 33 #include "cc/output/latency_info_swap_promise.h" |
33 #include "cc/output/swap_promise.h" | 34 #include "cc/output/swap_promise.h" |
| 35 #include "cc/proto/compositor_message.pb.h" |
34 #include "cc/resources/single_release_callback.h" | 36 #include "cc/resources/single_release_callback.h" |
35 #include "cc/scheduler/begin_frame_source.h" | 37 #include "cc/scheduler/begin_frame_source.h" |
36 #include "cc/trees/latency_info_swap_promise_monitor.h" | 38 #include "cc/trees/latency_info_swap_promise_monitor.h" |
37 #include "cc/trees/layer_tree_host.h" | 39 #include "cc/trees/layer_tree_host.h" |
| 40 #include "cc/trees/remote_proto_channel.h" |
38 #include "components/scheduler/renderer/renderer_scheduler.h" | 41 #include "components/scheduler/renderer/renderer_scheduler.h" |
39 #include "content/common/content_switches_internal.h" | 42 #include "content/common/content_switches_internal.h" |
40 #include "content/common/gpu/client/context_provider_command_buffer.h" | 43 #include "content/common/gpu/client/context_provider_command_buffer.h" |
41 #include "content/public/common/content_switches.h" | 44 #include "content/public/common/content_switches.h" |
42 #include "content/renderer/input/input_handler_manager.h" | 45 #include "content/renderer/input/input_handler_manager.h" |
43 #include "gpu/command_buffer/client/gles2_interface.h" | 46 #include "gpu/command_buffer/client/gles2_interface.h" |
44 #include "gpu/command_buffer/service/gpu_switches.h" | 47 #include "gpu/command_buffer/service/gpu_switches.h" |
45 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" | 48 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" |
46 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" | 49 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" |
47 #include "third_party/WebKit/public/platform/WebSize.h" | 50 #include "third_party/WebKit/public/platform/WebSize.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 211 } |
209 | 212 |
210 RenderWidgetCompositor::RenderWidgetCompositor( | 213 RenderWidgetCompositor::RenderWidgetCompositor( |
211 RenderWidget* widget, | 214 RenderWidget* widget, |
212 CompositorDependencies* compositor_deps) | 215 CompositorDependencies* compositor_deps) |
213 : num_failed_recreate_attempts_(0), | 216 : num_failed_recreate_attempts_(0), |
214 widget_(widget), | 217 widget_(widget), |
215 compositor_deps_(compositor_deps), | 218 compositor_deps_(compositor_deps), |
216 never_visible_(false), | 219 never_visible_(false), |
217 layout_and_paint_async_callback_(nullptr), | 220 layout_and_paint_async_callback_(nullptr), |
| 221 remote_proto_channel_receiver_(nullptr), |
218 weak_factory_(this) { | 222 weak_factory_(this) { |
219 } | 223 } |
220 | 224 |
221 void RenderWidgetCompositor::Initialize() { | 225 void RenderWidgetCompositor::Initialize() { |
222 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | 226 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
223 | 227 |
224 cc::LayerTreeSettings settings; | 228 cc::LayerTreeSettings settings; |
225 | 229 |
226 // For web contents, layer transforms should scale up the contents of layers | 230 // For web contents, layer transforms should scale up the contents of layers |
227 // to keep content always crisp when possible. | 231 // to keep content always crisp when possible. |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 } | 965 } |
962 | 966 |
963 void RenderWidgetCompositor::DidPostSwapBuffers() { | 967 void RenderWidgetCompositor::DidPostSwapBuffers() { |
964 widget_->OnSwapBuffersPosted(); | 968 widget_->OnSwapBuffersPosted(); |
965 } | 969 } |
966 | 970 |
967 void RenderWidgetCompositor::DidAbortSwapBuffers() { | 971 void RenderWidgetCompositor::DidAbortSwapBuffers() { |
968 widget_->OnSwapBuffersAborted(); | 972 widget_->OnSwapBuffersAborted(); |
969 } | 973 } |
970 | 974 |
| 975 void RenderWidgetCompositor::SetProtoReceiver(ProtoReceiver* receiver) { |
| 976 remote_proto_channel_receiver_ = receiver; |
| 977 } |
| 978 |
| 979 void RenderWidgetCompositor::SendCompositorProto( |
| 980 const cc::proto::CompositorMessage& proto) { |
| 981 int signed_size = proto.ByteSize(); |
| 982 size_t unsigned_size = base::checked_cast<size_t>(signed_size); |
| 983 std::vector<uint8_t> serialized(unsigned_size); |
| 984 proto.SerializeToArray(serialized.data(), signed_size); |
| 985 widget_->ForwardCompositorProto(serialized); |
| 986 } |
| 987 |
971 void RenderWidgetCompositor::RecordFrameTimingEvents( | 988 void RenderWidgetCompositor::RecordFrameTimingEvents( |
972 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, | 989 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, |
973 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 990 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
974 for (const auto& composite_event : *composite_events ) { | 991 for (const auto& composite_event : *composite_events ) { |
975 int64_t frameId = composite_event.first; | 992 int64_t frameId = composite_event.first; |
976 const std::vector<cc::FrameTimingTracker::CompositeTimingEvent>& events = | 993 const std::vector<cc::FrameTimingTracker::CompositeTimingEvent>& events = |
977 composite_event.second; | 994 composite_event.second; |
978 std::vector<blink::WebFrameTimingEvent> webEvents; | 995 std::vector<blink::WebFrameTimingEvent> webEvents; |
979 for (size_t i = 0; i < events.size(); ++i) { | 996 for (size_t i = 0; i < events.size(); ++i) { |
980 webEvents.push_back(blink::WebFrameTimingEvent( | 997 webEvents.push_back(blink::WebFrameTimingEvent( |
(...skipping 17 matching lines...) Expand all Loading... |
998 widget_->webwidget()->recordFrameTimingEvent( | 1015 widget_->webwidget()->recordFrameTimingEvent( |
999 blink::WebWidget::RenderEvent, frameId, webEvents); | 1016 blink::WebWidget::RenderEvent, frameId, webEvents); |
1000 } | 1017 } |
1001 } | 1018 } |
1002 | 1019 |
1003 void RenderWidgetCompositor::SetSurfaceIdNamespace( | 1020 void RenderWidgetCompositor::SetSurfaceIdNamespace( |
1004 uint32_t surface_id_namespace) { | 1021 uint32_t surface_id_namespace) { |
1005 layer_tree_host_->set_surface_id_namespace(surface_id_namespace); | 1022 layer_tree_host_->set_surface_id_namespace(surface_id_namespace); |
1006 } | 1023 } |
1007 | 1024 |
| 1025 void RenderWidgetCompositor::OnHandleCompositorProto( |
| 1026 const std::vector<uint8_t>& proto) { |
| 1027 DCHECK(remote_proto_channel_receiver_); |
| 1028 |
| 1029 scoped_ptr<cc::proto::CompositorMessage> deserialized( |
| 1030 new cc::proto::CompositorMessage); |
| 1031 int signed_size = base::checked_cast<int>(proto.size()); |
| 1032 if (!deserialized->ParseFromArray(proto.data(), signed_size)) { |
| 1033 LOG(ERROR) << "Unable to parse compositor proto."; |
| 1034 return; |
| 1035 } |
| 1036 |
| 1037 remote_proto_channel_receiver_->OnProtoReceived(deserialized.Pass()); |
| 1038 } |
| 1039 |
1008 cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy( | 1040 cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy( |
1009 const cc::ManagedMemoryPolicy& policy) { | 1041 const cc::ManagedMemoryPolicy& policy) { |
1010 cc::ManagedMemoryPolicy actual = policy; | 1042 cc::ManagedMemoryPolicy actual = policy; |
1011 actual.bytes_limit_when_visible = 0; | 1043 actual.bytes_limit_when_visible = 0; |
1012 | 1044 |
1013 // If the value was overridden on the command line, use the specified value. | 1045 // If the value was overridden on the command line, use the specified value. |
1014 static bool client_hard_limit_bytes_overridden = | 1046 static bool client_hard_limit_bytes_overridden = |
1015 base::CommandLine::ForCurrentProcess()->HasSwitch( | 1047 base::CommandLine::ForCurrentProcess()->HasSwitch( |
1016 switches::kForceGpuMemAvailableMb); | 1048 switches::kForceGpuMemAvailableMb); |
1017 if (client_hard_limit_bytes_overridden) { | 1049 if (client_hard_limit_bytes_overridden) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 #endif | 1116 #endif |
1085 return actual; | 1117 return actual; |
1086 } | 1118 } |
1087 | 1119 |
1088 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( | 1120 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( |
1089 float device_scale) { | 1121 float device_scale) { |
1090 layer_tree_host_->SetPaintedDeviceScaleFactor(device_scale); | 1122 layer_tree_host_->SetPaintedDeviceScaleFactor(device_scale); |
1091 } | 1123 } |
1092 | 1124 |
1093 } // namespace content | 1125 } // namespace content |
OLD | NEW |