| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 using blink::WebFloatPoint; | 81 using blink::WebFloatPoint; |
| 82 using blink::WebRect; | 82 using blink::WebRect; |
| 83 using blink::WebSelection; | 83 using blink::WebSelection; |
| 84 using blink::WebSize; | 84 using blink::WebSize; |
| 85 using blink::WebBrowserControlsState; | 85 using blink::WebBrowserControlsState; |
| 86 | 86 |
| 87 namespace content { | 87 namespace content { |
| 88 namespace { | 88 namespace { |
| 89 | 89 |
| 90 using ReportTimeCallback = base::Callback<void(bool, double)>; |
| 91 |
| 92 double MonotonicallyIncreasingTime() { |
| 93 return static_cast<double>(base::TimeTicks::Now().ToInternalValue()) / |
| 94 base::Time::kMicrosecondsPerSecond; |
| 95 } |
| 96 |
| 97 class ReportTimeSwapPromise : public cc::SwapPromise { |
| 98 public: |
| 99 ReportTimeSwapPromise( |
| 100 ReportTimeCallback callback, |
| 101 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| 102 ~ReportTimeSwapPromise() override; |
| 103 |
| 104 void DidActivate() override {} |
| 105 void WillSwap(cc::CompositorFrameMetadata* metadata) override {} |
| 106 void DidSwap() override; |
| 107 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override; |
| 108 |
| 109 int64_t TraceId() const override; |
| 110 |
| 111 private: |
| 112 ReportTimeCallback callback_; |
| 113 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(ReportTimeSwapPromise); |
| 116 }; |
| 117 |
| 118 ReportTimeSwapPromise::ReportTimeSwapPromise( |
| 119 ReportTimeCallback callback, |
| 120 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
| 121 : callback_(callback), task_runner_(task_runner) {} |
| 122 |
| 123 ReportTimeSwapPromise::~ReportTimeSwapPromise() {} |
| 124 |
| 125 void ReportTimeSwapPromise::DidSwap() { |
| 126 task_runner_->PostTask( |
| 127 FROM_HERE, |
| 128 base::BindOnce(callback_, true, MonotonicallyIncreasingTime())); |
| 129 } |
| 130 |
| 131 cc::SwapPromise::DidNotSwapAction ReportTimeSwapPromise::DidNotSwap( |
| 132 cc::SwapPromise::DidNotSwapReason reason) { |
| 133 task_runner_->PostTask(FROM_HERE, base::BindOnce(callback_, false, 0)); |
| 134 return cc::SwapPromise::DidNotSwapAction::BREAK_PROMISE; |
| 135 } |
| 136 |
| 137 int64_t ReportTimeSwapPromise::TraceId() const { |
| 138 return 0; |
| 139 } |
| 140 |
| 90 bool GetSwitchValueAsInt(const base::CommandLine& command_line, | 141 bool GetSwitchValueAsInt(const base::CommandLine& command_line, |
| 91 const std::string& switch_string, | 142 const std::string& switch_string, |
| 92 int min_value, | 143 int min_value, |
| 93 int max_value, | 144 int max_value, |
| 94 int* result) { | 145 int* result) { |
| 95 std::string string_value = command_line.GetSwitchValueASCII(switch_string); | 146 std::string string_value = command_line.GetSwitchValueASCII(switch_string); |
| 96 int int_value; | 147 int int_value; |
| 97 if (base::StringToInt(string_value, &int_value) && int_value >= min_value && | 148 if (base::StringToInt(string_value, &int_value) && int_value >= min_value && |
| 98 int_value <= max_value) { | 149 int_value <= max_value) { |
| 99 *result = int_value; | 150 *result = int_value; |
| (...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 | 1199 |
| 1149 void RenderWidgetCompositor::SetContentSourceId(uint32_t id) { | 1200 void RenderWidgetCompositor::SetContentSourceId(uint32_t id) { |
| 1150 layer_tree_host_->SetContentSourceId(id); | 1201 layer_tree_host_->SetContentSourceId(id); |
| 1151 } | 1202 } |
| 1152 | 1203 |
| 1153 void RenderWidgetCompositor::SetLocalSurfaceId( | 1204 void RenderWidgetCompositor::SetLocalSurfaceId( |
| 1154 const cc::LocalSurfaceId& local_surface_id) { | 1205 const cc::LocalSurfaceId& local_surface_id) { |
| 1155 layer_tree_host_->SetLocalSurfaceId(local_surface_id); | 1206 layer_tree_host_->SetLocalSurfaceId(local_surface_id); |
| 1156 } | 1207 } |
| 1157 | 1208 |
| 1209 void RenderWidgetCompositor::NotifySwapTime(ReportTimeCallback callback) { |
| 1210 QueueSwapPromise(base::MakeUnique<ReportTimeSwapPromise>( |
| 1211 std::move(callback), base::ThreadTaskRunnerHandle::Get())); |
| 1212 } |
| 1213 |
| 1158 } // namespace content | 1214 } // namespace content |
| OLD | NEW |