| 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 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 bool RenderWidgetCompositor::CompositeIsSynchronous() const { | 888 bool RenderWidgetCompositor::CompositeIsSynchronous() const { |
| 889 if (!threaded_) { | 889 if (!threaded_) { |
| 890 DCHECK(!layer_tree_host_->settings().single_thread_proxy_scheduler); | 890 DCHECK(!layer_tree_host_->settings().single_thread_proxy_scheduler); |
| 891 return true; | 891 return true; |
| 892 } | 892 } |
| 893 return false; | 893 return false; |
| 894 } | 894 } |
| 895 | 895 |
| 896 void RenderWidgetCompositor::layoutAndPaintAsync( | 896 void RenderWidgetCompositor::layoutAndPaintAsync( |
| 897 blink::WebLayoutAndPaintAsyncCallback* callback) { | 897 blink::WebLayoutAndPaintAsyncCallback* callback) { |
| 898 DCHECK(!temporary_copy_output_request_ && !layout_and_paint_async_callback_); | 898 DCHECK(!layout_and_paint_async_callback_); |
| 899 layout_and_paint_async_callback_ = callback; | 899 layout_and_paint_async_callback_ = callback; |
| 900 | 900 |
| 901 if (CompositeIsSynchronous()) { | 901 if (CompositeIsSynchronous()) { |
| 902 base::ThreadTaskRunnerHandle::Get()->PostTask( | 902 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 903 FROM_HERE, base::Bind(&RenderWidgetCompositor::LayoutAndUpdateLayers, | 903 FROM_HERE, base::Bind(&RenderWidgetCompositor::LayoutAndUpdateLayers, |
| 904 weak_factory_.GetWeakPtr())); | 904 weak_factory_.GetWeakPtr())); |
| 905 } else { | 905 } else { |
| 906 layer_tree_host_->SetNeedsCommit(); | 906 layer_tree_host_->SetNeedsCommit(); |
| 907 } | 907 } |
| 908 } | 908 } |
| 909 | 909 |
| 910 void RenderWidgetCompositor::LayoutAndUpdateLayers() { | 910 void RenderWidgetCompositor::LayoutAndUpdateLayers() { |
| 911 DCHECK(CompositeIsSynchronous()); | 911 DCHECK(CompositeIsSynchronous()); |
| 912 layer_tree_host_->LayoutAndUpdateLayers(); | 912 layer_tree_host_->LayoutAndUpdateLayers(); |
| 913 InvokeLayoutAndPaintCallback(); | 913 InvokeLayoutAndPaintCallback(); |
| 914 } | 914 } |
| 915 | 915 |
| 916 void RenderWidgetCompositor::InvokeLayoutAndPaintCallback() { | 916 void RenderWidgetCompositor::InvokeLayoutAndPaintCallback() { |
| 917 if (!layout_and_paint_async_callback_) | 917 if (!layout_and_paint_async_callback_) |
| 918 return; | 918 return; |
| 919 layout_and_paint_async_callback_->didLayoutAndPaint(); | 919 layout_and_paint_async_callback_->didLayoutAndPaint(); |
| 920 layout_and_paint_async_callback_ = nullptr; | 920 layout_and_paint_async_callback_ = nullptr; |
| 921 } | 921 } |
| 922 | 922 |
| 923 void RenderWidgetCompositor::compositeAndReadbackAsync( | 923 void RenderWidgetCompositor::compositeAndReadbackAsync( |
| 924 blink::WebCompositeAndReadbackAsyncCallback* callback) { | 924 blink::WebCompositeAndReadbackAsyncCallback* callback) { |
| 925 DCHECK(!temporary_copy_output_request_ && !layout_and_paint_async_callback_); | 925 DCHECK(!layout_and_paint_async_callback_); |
| 926 temporary_copy_output_request_ = | 926 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner = |
| 927 cc::CopyOutputRequest::CreateBitmapRequest( | 927 layer_tree_host_->task_runner_provider()->MainThreadTaskRunner(); |
| 928 base::Bind(&CompositeAndReadbackAsyncCallback, callback)); | 928 std::unique_ptr<cc::CopyOutputRequest> request = |
| 929 cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
| 930 [](blink::WebCompositeAndReadbackAsyncCallback* callback, |
| 931 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 932 std::unique_ptr<cc::CopyOutputResult> result) { |
| 933 task_runner->PostTask(FROM_HERE, |
| 934 base::Bind(&CompositeAndReadbackAsyncCallback, |
| 935 callback, base::Passed(&result))); |
| 936 }, |
| 937 callback, base::Passed(&main_thread_task_runner))); |
| 938 layer_tree_host_->QueueSwapPromise( |
| 939 delegate_->RequestCopyOfOutputForLayoutTest(std::move(request))); |
| 929 | 940 |
| 930 // Force a commit to happen. The temporary copy output request will | 941 // Force a commit to happen. The temporary copy output request will |
| 931 // be installed after layout which will happen as a part of the commit, for | 942 // be installed after layout which will happen as a part of the commit, for |
| 932 // widgets that delay the creation of their output surface. | 943 // widgets that delay the creation of their output surface. |
| 933 if (CompositeIsSynchronous()) { | 944 if (CompositeIsSynchronous()) { |
| 934 base::ThreadTaskRunnerHandle::Get()->PostTask( | 945 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 935 FROM_HERE, base::Bind(&RenderWidgetCompositor::SynchronouslyComposite, | 946 FROM_HERE, base::Bind(&RenderWidgetCompositor::SynchronouslyComposite, |
| 936 weak_factory_.GetWeakPtr())); | 947 weak_factory_.GetWeakPtr())); |
| 937 } else { | 948 } else { |
| 938 layer_tree_host_->SetNeedsCommit(); | 949 layer_tree_host_->SetNeedsCommit(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 double frame_time_sec = (args.frame_time - base::TimeTicks()).InSecondsF(); | 1018 double frame_time_sec = (args.frame_time - base::TimeTicks()).InSecondsF(); |
| 1008 delegate_->BeginMainFrame(frame_time_sec); | 1019 delegate_->BeginMainFrame(frame_time_sec); |
| 1009 } | 1020 } |
| 1010 | 1021 |
| 1011 void RenderWidgetCompositor::BeginMainFrameNotExpectedSoon() { | 1022 void RenderWidgetCompositor::BeginMainFrameNotExpectedSoon() { |
| 1012 compositor_deps_->GetRendererScheduler()->BeginFrameNotExpectedSoon(); | 1023 compositor_deps_->GetRendererScheduler()->BeginFrameNotExpectedSoon(); |
| 1013 } | 1024 } |
| 1014 | 1025 |
| 1015 void RenderWidgetCompositor::UpdateLayerTreeHost() { | 1026 void RenderWidgetCompositor::UpdateLayerTreeHost() { |
| 1016 delegate_->UpdateVisualState(); | 1027 delegate_->UpdateVisualState(); |
| 1017 if (temporary_copy_output_request_) { | |
| 1018 // For WebViewImpl, this will always have a root layer. For other widgets, | |
| 1019 // the widget may be closed before servicing this request, so ignore it. | |
| 1020 if (cc::Layer* root_layer = layer_tree_host_->root_layer()) { | |
| 1021 root_layer->RequestCopyOfOutput( | |
| 1022 std::move(temporary_copy_output_request_)); | |
| 1023 } else { | |
| 1024 temporary_copy_output_request_->SendEmptyResult(); | |
| 1025 temporary_copy_output_request_ = nullptr; | |
| 1026 } | |
| 1027 } | |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 void RenderWidgetCompositor::ApplyViewportDeltas( | 1030 void RenderWidgetCompositor::ApplyViewportDeltas( |
| 1031 const gfx::Vector2dF& inner_delta, | 1031 const gfx::Vector2dF& inner_delta, |
| 1032 const gfx::Vector2dF& outer_delta, | 1032 const gfx::Vector2dF& outer_delta, |
| 1033 const gfx::Vector2dF& elastic_overscroll_delta, | 1033 const gfx::Vector2dF& elastic_overscroll_delta, |
| 1034 float page_scale, | 1034 float page_scale, |
| 1035 float top_controls_delta) { | 1035 float top_controls_delta) { |
| 1036 delegate_->ApplyViewportDeltas(inner_delta, outer_delta, | 1036 delegate_->ApplyViewportDeltas(inner_delta, outer_delta, |
| 1037 elastic_overscroll_delta, page_scale, | 1037 elastic_overscroll_delta, page_scale, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1074 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1075 FROM_HERE, base::Bind(&RenderWidgetCompositor::RequestNewOutputSurface, | 1075 FROM_HERE, base::Bind(&RenderWidgetCompositor::RequestNewOutputSurface, |
| 1076 weak_factory_.GetWeakPtr())); | 1076 weak_factory_.GetWeakPtr())); |
| 1077 } | 1077 } |
| 1078 | 1078 |
| 1079 void RenderWidgetCompositor::WillCommit() { | 1079 void RenderWidgetCompositor::WillCommit() { |
| 1080 InvokeLayoutAndPaintCallback(); | 1080 InvokeLayoutAndPaintCallback(); |
| 1081 } | 1081 } |
| 1082 | 1082 |
| 1083 void RenderWidgetCompositor::DidCommit() { | 1083 void RenderWidgetCompositor::DidCommit() { |
| 1084 DCHECK(!temporary_copy_output_request_); | |
| 1085 delegate_->DidCommitCompositorFrame(); | 1084 delegate_->DidCommitCompositorFrame(); |
| 1086 compositor_deps_->GetRendererScheduler()->DidCommitFrameToCompositor(); | 1085 compositor_deps_->GetRendererScheduler()->DidCommitFrameToCompositor(); |
| 1087 } | 1086 } |
| 1088 | 1087 |
| 1089 void RenderWidgetCompositor::DidCommitAndDrawFrame() { | 1088 void RenderWidgetCompositor::DidCommitAndDrawFrame() { |
| 1090 delegate_->DidCommitAndDrawCompositorFrame(); | 1089 delegate_->DidCommitAndDrawCompositorFrame(); |
| 1091 } | 1090 } |
| 1092 | 1091 |
| 1093 void RenderWidgetCompositor::DidCompleteSwapBuffers() { | 1092 void RenderWidgetCompositor::DidCompleteSwapBuffers() { |
| 1094 delegate_->DidCompleteSwapBuffers(); | 1093 delegate_->DidCompleteSwapBuffers(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 | 1142 |
| 1144 remote_proto_channel_receiver_->OnProtoReceived(std::move(deserialized)); | 1143 remote_proto_channel_receiver_->OnProtoReceived(std::move(deserialized)); |
| 1145 } | 1144 } |
| 1146 | 1145 |
| 1147 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( | 1146 void RenderWidgetCompositor::SetPaintedDeviceScaleFactor( |
| 1148 float device_scale) { | 1147 float device_scale) { |
| 1149 layer_tree_host_->SetPaintedDeviceScaleFactor(device_scale); | 1148 layer_tree_host_->SetPaintedDeviceScaleFactor(device_scale); |
| 1150 } | 1149 } |
| 1151 | 1150 |
| 1152 } // namespace content | 1151 } // namespace content |
| OLD | NEW |