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 <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 size_t size = base::checked_cast<size_t>(proto.ByteSize()); | |
| 982 std::vector<uint8_t> serialized(size); | |
| 983 proto.SerializeToArray(serialized.data(), serialized.size()); | |
|
David Trainor- moved to gerrit
2015/11/17 00:58:34
Hmm I should probably make this use proto.ByteSize
palmer
2015/11/17 01:25:32
Yep, checked_cast will CHECK if there is a problem
David Trainor- moved to gerrit
2015/11/17 04:52:26
Ah okay thanks! I tweaked this a bit to just make
| |
| 984 widget_->ForwardCompositorProto(serialized); | |
| 985 } | |
| 986 | |
| 971 void RenderWidgetCompositor::RecordFrameTimingEvents( | 987 void RenderWidgetCompositor::RecordFrameTimingEvents( |
| 972 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, | 988 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, |
| 973 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 989 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
| 974 for (const auto& composite_event : *composite_events ) { | 990 for (const auto& composite_event : *composite_events ) { |
| 975 int64_t frameId = composite_event.first; | 991 int64_t frameId = composite_event.first; |
| 976 const std::vector<cc::FrameTimingTracker::CompositeTimingEvent>& events = | 992 const std::vector<cc::FrameTimingTracker::CompositeTimingEvent>& events = |
| 977 composite_event.second; | 993 composite_event.second; |
| 978 std::vector<blink::WebFrameTimingEvent> webEvents; | 994 std::vector<blink::WebFrameTimingEvent> webEvents; |
| 979 for (size_t i = 0; i < events.size(); ++i) { | 995 for (size_t i = 0; i < events.size(); ++i) { |
| 980 webEvents.push_back(blink::WebFrameTimingEvent( | 996 webEvents.push_back(blink::WebFrameTimingEvent( |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 998 widget_->webwidget()->recordFrameTimingEvent( | 1014 widget_->webwidget()->recordFrameTimingEvent( |
| 999 blink::WebWidget::RenderEvent, frameId, webEvents); | 1015 blink::WebWidget::RenderEvent, frameId, webEvents); |
| 1000 } | 1016 } |
| 1001 } | 1017 } |
| 1002 | 1018 |
| 1003 void RenderWidgetCompositor::SetSurfaceIdNamespace( | 1019 void RenderWidgetCompositor::SetSurfaceIdNamespace( |
| 1004 uint32_t surface_id_namespace) { | 1020 uint32_t surface_id_namespace) { |
| 1005 layer_tree_host_->set_surface_id_namespace(surface_id_namespace); | 1021 layer_tree_host_->set_surface_id_namespace(surface_id_namespace); |
| 1006 } | 1022 } |
| 1007 | 1023 |
| 1024 void RenderWidgetCompositor::OnHandleCompositorProto( | |
| 1025 const std::vector<uint8_t>& proto) { | |
| 1026 DCHECK(remote_proto_channel_receiver_); | |
| 1027 | |
| 1028 scoped_ptr<cc::proto::CompositorMessage> deserialized( | |
| 1029 new cc::proto::CompositorMessage); | |
| 1030 int size = base::checked_cast<int>(proto.size()); | |
| 1031 if (!deserialized->ParseFromArray(proto.data(), size)) { | |
| 1032 LOG(ERROR) << "Unable to parse compositor proto."; | |
| 1033 return; | |
| 1034 } | |
| 1035 | |
| 1036 remote_proto_channel_receiver_->OnProtoReceived(deserialized.Pass()); | |
| 1037 } | |
| 1038 | |
| 1008 cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy( | 1039 cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy( |
| 1009 const cc::ManagedMemoryPolicy& policy) { | 1040 const cc::ManagedMemoryPolicy& policy) { |
| 1010 cc::ManagedMemoryPolicy actual = policy; | 1041 cc::ManagedMemoryPolicy actual = policy; |
| 1011 actual.bytes_limit_when_visible = 0; | 1042 actual.bytes_limit_when_visible = 0; |
| 1012 | 1043 |
| 1013 // If the value was overridden on the command line, use the specified value. | 1044 // If the value was overridden on the command line, use the specified value. |
| 1014 static bool client_hard_limit_bytes_overridden = | 1045 static bool client_hard_limit_bytes_overridden = |
| 1015 base::CommandLine::ForCurrentProcess()->HasSwitch( | 1046 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1016 switches::kForceGpuMemAvailableMb); | 1047 switches::kForceGpuMemAvailableMb); |
| 1017 if (client_hard_limit_bytes_overridden) { | 1048 if (client_hard_limit_bytes_overridden) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1084 #endif | 1115 #endif |
| 1085 return actual; | 1116 return actual; |
| 1086 } | 1117 } |
| 1087 | 1118 |
| 1088 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( | 1119 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( |
| 1089 float device_scale) { | 1120 float device_scale) { |
| 1090 layer_tree_host_->SetPaintedDeviceScaleFactor(device_scale); | 1121 layer_tree_host_->SetPaintedDeviceScaleFactor(device_scale); |
| 1091 } | 1122 } |
| 1092 | 1123 |
| 1093 } // namespace content | 1124 } // namespace content |
| OLD | NEW |