Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: cc/trees/single_thread_proxy.cc

Issue 447133002: Revert of Make SingleThreadProxy a SchedulerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/trees/single_thread_proxy.h ('k') | cc/trees/thread_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/trees/single_thread_proxy.h" 5 #include "cc/trees/single_thread_proxy.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "cc/debug/benchmark_instrumentation.h" 9 #include "cc/debug/benchmark_instrumentation.h"
10 #include "cc/output/context_provider.h" 10 #include "cc/output/context_provider.h"
(...skipping 18 matching lines...) Expand all
29 .PassAs<Proxy>(); 29 .PassAs<Proxy>();
30 } 30 }
31 31
32 SingleThreadProxy::SingleThreadProxy( 32 SingleThreadProxy::SingleThreadProxy(
33 LayerTreeHost* layer_tree_host, 33 LayerTreeHost* layer_tree_host,
34 LayerTreeHostSingleThreadClient* client, 34 LayerTreeHostSingleThreadClient* client,
35 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) 35 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner)
36 : Proxy(main_task_runner, NULL), 36 : Proxy(main_task_runner, NULL),
37 layer_tree_host_(layer_tree_host), 37 layer_tree_host_(layer_tree_host),
38 client_(client), 38 client_(client),
39 timing_history_(layer_tree_host->rendering_stats_instrumentation()),
40 next_frame_is_newly_committed_frame_(false), 39 next_frame_is_newly_committed_frame_(false),
41 inside_draw_(false), 40 inside_draw_(false) {
42 defer_commits_(false),
43 commit_was_deferred_(false),
44 commit_requested_(false),
45 weak_factory_(this) {
46 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); 41 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
47 DCHECK(Proxy::IsMainThread()); 42 DCHECK(Proxy::IsMainThread());
48 DCHECK(layer_tree_host); 43 DCHECK(layer_tree_host);
49 44
50 // Impl-side painting not supported without threaded compositing. 45 // Impl-side painting not supported without threaded compositing.
51 CHECK(!layer_tree_host->settings().impl_side_painting) 46 CHECK(!layer_tree_host->settings().impl_side_painting)
52 << "Threaded compositing must be enabled to use impl-side painting."; 47 << "Threaded compositing must be enabled to use impl-side painting.";
53 } 48 }
54 49
55 void SingleThreadProxy::Start() { 50 void SingleThreadProxy::Start() {
(...skipping 19 matching lines...) Expand all
75 70
76 bool SingleThreadProxy::IsStarted() const { 71 bool SingleThreadProxy::IsStarted() const {
77 DCHECK(Proxy::IsMainThread()); 72 DCHECK(Proxy::IsMainThread());
78 return layer_tree_host_impl_; 73 return layer_tree_host_impl_;
79 } 74 }
80 75
81 void SingleThreadProxy::SetLayerTreeHostClientReady() { 76 void SingleThreadProxy::SetLayerTreeHostClientReady() {
82 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); 77 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady");
83 // Scheduling is controlled by the embedder in the single thread case, so 78 // Scheduling is controlled by the embedder in the single thread case, so
84 // nothing to do. 79 // nothing to do.
85 DCHECK(Proxy::IsMainThread());
86 DebugScopedSetImplThread impl(this);
87 if (layer_tree_host_->settings().single_thread_proxy_scheduler &&
88 !scheduler_on_impl_thread_) {
89 SchedulerSettings scheduler_settings(layer_tree_host_->settings());
90 scheduler_on_impl_thread_ = Scheduler::Create(this,
91 scheduler_settings,
92 layer_tree_host_->id(),
93 MainThreadTaskRunner());
94 scheduler_on_impl_thread_->SetCanStart();
95 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
96 }
97 } 80 }
98 81
99 void SingleThreadProxy::SetVisible(bool visible) { 82 void SingleThreadProxy::SetVisible(bool visible) {
100 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); 83 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible");
101 DebugScopedSetImplThread impl(this); 84 DebugScopedSetImplThread impl(this);
102 layer_tree_host_impl_->SetVisible(visible); 85 layer_tree_host_impl_->SetVisible(visible);
103 if (scheduler_on_impl_thread_) 86
104 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
105 // Changing visibility could change ShouldComposite(). 87 // Changing visibility could change ShouldComposite().
106 UpdateBackgroundAnimateTicking(); 88 UpdateBackgroundAnimateTicking();
107 } 89 }
108 90
109 void SingleThreadProxy::CreateAndInitializeOutputSurface() { 91 void SingleThreadProxy::CreateAndInitializeOutputSurface() {
110 TRACE_EVENT0( 92 TRACE_EVENT0(
111 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); 93 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface");
112 DCHECK(Proxy::IsMainThread()); 94 DCHECK(Proxy::IsMainThread());
113 DCHECK(layer_tree_host_->output_surface_lost()); 95 DCHECK(layer_tree_host_->output_surface_lost());
114 96
115 scoped_ptr<OutputSurface> output_surface = 97 scoped_ptr<OutputSurface> output_surface =
116 layer_tree_host_->CreateOutputSurface(); 98 layer_tree_host_->CreateOutputSurface();
117 99
118 renderer_capabilities_for_main_thread_ = RendererCapabilities(); 100 renderer_capabilities_for_main_thread_ = RendererCapabilities();
119 101
120 bool success = !!output_surface; 102 bool success = !!output_surface;
121 if (success) { 103 if (success) {
122 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 104 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
123 DebugScopedSetImplThread impl(this); 105 DebugScopedSetImplThread impl(this);
124 layer_tree_host_->DeleteContentsTexturesOnImplThread( 106 layer_tree_host_->DeleteContentsTexturesOnImplThread(
125 layer_tree_host_impl_->resource_provider()); 107 layer_tree_host_impl_->resource_provider());
126 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); 108 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
127 } 109 }
128 110
129 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); 111 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success);
130 112
131 if (success) { 113 if (!success) {
132 if (scheduler_on_impl_thread_) 114 // Force another recreation attempt to happen by requesting another commit.
133 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); 115 SetNeedsCommit();
134 } else if (Proxy::MainThreadTaskRunner()) {
135 MainThreadTaskRunner()->PostTask(
136 FROM_HERE,
137 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface,
138 weak_factory_.GetWeakPtr()));
139 } 116 }
140 } 117 }
141 118
142 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { 119 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const {
143 DCHECK(Proxy::IsMainThread()); 120 DCHECK(Proxy::IsMainThread());
144 DCHECK(!layer_tree_host_->output_surface_lost()); 121 DCHECK(!layer_tree_host_->output_surface_lost());
145 return renderer_capabilities_for_main_thread_; 122 return renderer_capabilities_for_main_thread_;
146 } 123 }
147 124
148 void SingleThreadProxy::SetNeedsAnimate() { 125 void SingleThreadProxy::SetNeedsAnimate() {
149 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); 126 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate");
150 DCHECK(Proxy::IsMainThread()); 127 DCHECK(Proxy::IsMainThread());
151 client_->ScheduleAnimation(); 128 client_->ScheduleAnimation();
152 SetNeedsCommit();
153 } 129 }
154 130
155 void SingleThreadProxy::SetNeedsUpdateLayers() { 131 void SingleThreadProxy::SetNeedsUpdateLayers() {
156 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); 132 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers");
157 DCHECK(Proxy::IsMainThread()); 133 DCHECK(Proxy::IsMainThread());
158 SetNeedsCommit(); 134 client_->ScheduleComposite();
159 } 135 }
160 136
161 void SingleThreadProxy::DoCommit(base::TimeTicks frame_begin_time) { 137 void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
162 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); 138 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit");
163 DCHECK(Proxy::IsMainThread()); 139 DCHECK(Proxy::IsMainThread());
164 layer_tree_host_->WillBeginMainFrame();
165 layer_tree_host_->UpdateClientAnimations(frame_begin_time);
166 layer_tree_host_->AnimateLayers(frame_begin_time);
167 layer_tree_host_->Layout();
168 commit_requested_ = false;
169
170 if (PrioritizedResourceManager* contents_texture_manager =
171 layer_tree_host_->contents_texture_manager()) {
172 contents_texture_manager->UnlinkAndClearEvictedBackings();
173 contents_texture_manager->SetMaxMemoryLimitBytes(
174 layer_tree_host_impl_->memory_allocation_limit_bytes());
175 contents_texture_manager->SetExternalPriorityCutoff(
176 layer_tree_host_impl_->memory_allocation_priority_cutoff());
177 }
178
179 scoped_ptr<ResourceUpdateQueue> queue =
180 make_scoped_ptr(new ResourceUpdateQueue);
181
182 layer_tree_host_->UpdateLayers(queue.get());
183
184 layer_tree_host_->WillCommit();
185
186 // Commit immediately. 140 // Commit immediately.
187 { 141 {
188 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 142 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
189 DebugScopedSetImplThread impl(this); 143 DebugScopedSetImplThread impl(this);
190 144
191 // This CapturePostTasks should be destroyed before CommitComplete() is 145 // This CapturePostTasks should be destroyed before CommitComplete() is
192 // called since that goes out to the embedder, and we want the embedder 146 // called since that goes out to the embedder, and we want the embedder
193 // to receive its callbacks before that. 147 // to receive its callbacks before that.
194 BlockingTaskRunner::CapturePostTasks blocked; 148 BlockingTaskRunner::CapturePostTasks blocked;
195 149
196 layer_tree_host_impl_->BeginCommit(); 150 layer_tree_host_impl_->BeginCommit();
197 151
198 if (PrioritizedResourceManager* contents_texture_manager = 152 if (PrioritizedResourceManager* contents_texture_manager =
199 layer_tree_host_->contents_texture_manager()) { 153 layer_tree_host_->contents_texture_manager()) {
200 contents_texture_manager->PushTexturePrioritiesToBackings(); 154 contents_texture_manager->PushTexturePrioritiesToBackings();
201 } 155 }
202 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); 156 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
203 157
204 scoped_ptr<ResourceUpdateController> update_controller = 158 scoped_ptr<ResourceUpdateController> update_controller =
205 ResourceUpdateController::Create( 159 ResourceUpdateController::Create(
206 NULL, 160 NULL,
207 MainThreadTaskRunner(), 161 Proxy::MainThreadTaskRunner(),
208 queue.Pass(), 162 queue.Pass(),
209 layer_tree_host_impl_->resource_provider()); 163 layer_tree_host_impl_->resource_provider());
210 update_controller->Finalize(); 164 update_controller->Finalize();
211 165
212 if (layer_tree_host_impl_->EvictedUIResourcesExist()) 166 if (layer_tree_host_impl_->EvictedUIResourcesExist())
213 layer_tree_host_->RecreateUIResources(); 167 layer_tree_host_->RecreateUIResources();
214 168
215 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); 169 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
216 170
217 layer_tree_host_impl_->CommitComplete(); 171 layer_tree_host_impl_->CommitComplete();
218 172
219 UpdateBackgroundAnimateTicking();
220
221 #if DCHECK_IS_ON 173 #if DCHECK_IS_ON
222 // In the single-threaded case, the scale and scroll deltas should never be 174 // In the single-threaded case, the scale and scroll deltas should never be
223 // touched on the impl layer tree. 175 // touched on the impl layer tree.
224 scoped_ptr<ScrollAndScaleSet> scroll_info = 176 scoped_ptr<ScrollAndScaleSet> scroll_info =
225 layer_tree_host_impl_->ProcessScrollDeltas(); 177 layer_tree_host_impl_->ProcessScrollDeltas();
226 DCHECK(!scroll_info->scrolls.size()); 178 DCHECK(!scroll_info->scrolls.size());
227 DCHECK_EQ(1.f, scroll_info->page_scale_delta); 179 DCHECK_EQ(1.f, scroll_info->page_scale_delta);
228 #endif 180 #endif
229 181
230 RenderingStatsInstrumentation* stats_instrumentation = 182 RenderingStatsInstrumentation* stats_instrumentation =
231 layer_tree_host_->rendering_stats_instrumentation(); 183 layer_tree_host_->rendering_stats_instrumentation();
232 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent( 184 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent(
233 stats_instrumentation->main_thread_rendering_stats()); 185 stats_instrumentation->main_thread_rendering_stats());
234 stats_instrumentation->AccumulateAndClearMainThreadStats(); 186 stats_instrumentation->AccumulateAndClearMainThreadStats();
235 } 187 }
236 layer_tree_host_->CommitComplete(); 188 layer_tree_host_->CommitComplete();
237 layer_tree_host_->DidBeginMainFrame();
238 timing_history_.DidCommit();
239
240 next_frame_is_newly_committed_frame_ = true; 189 next_frame_is_newly_committed_frame_ = true;
241 } 190 }
242 191
243 void SingleThreadProxy::SetNeedsCommit() { 192 void SingleThreadProxy::SetNeedsCommit() {
244 DCHECK(Proxy::IsMainThread()); 193 DCHECK(Proxy::IsMainThread());
245 DebugScopedSetImplThread impl(this);
246 client_->ScheduleComposite(); 194 client_->ScheduleComposite();
247 if (scheduler_on_impl_thread_)
248 scheduler_on_impl_thread_->SetNeedsCommit();
249 commit_requested_ = true;
250 } 195 }
251 196
252 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { 197 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
253 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); 198 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw");
254 DCHECK(Proxy::IsMainThread()); 199 SetNeedsRedrawRectOnImplThread(damage_rect);
255 DebugScopedSetImplThread impl(this);
256 client_->ScheduleComposite(); 200 client_->ScheduleComposite();
257 SetNeedsRedrawRectOnImplThread(damage_rect);
258 } 201 }
259 202
260 void SingleThreadProxy::SetNextCommitWaitsForActivation() { 203 void SingleThreadProxy::SetNextCommitWaitsForActivation() {
261 // There is no activation here other than commit. So do nothing. 204 // There is no activation here other than commit. So do nothing.
262 DCHECK(Proxy::IsMainThread());
263 } 205 }
264 206
265 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { 207 void SingleThreadProxy::SetDeferCommits(bool defer_commits) {
266 DCHECK(Proxy::IsMainThread());
267 // Deferring commits only makes sense if there's a scheduler.
268 if (!scheduler_on_impl_thread_)
269 return;
270 if (defer_commits_ == defer_commits)
271 return;
272
273 if (defer_commits)
274 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this);
275 else
276 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this);
277
278 defer_commits_ = defer_commits;
279 if (!defer_commits_ && commit_was_deferred_) {
280 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted();
281 scheduler_on_impl_thread_->NotifyReadyToCommit();
282 commit_was_deferred_ = false;
283 }
284 } 208 }
285 209
286 bool SingleThreadProxy::CommitRequested() const { 210 bool SingleThreadProxy::CommitRequested() const { return false; }
287 DCHECK(Proxy::IsMainThread());
288 return commit_requested_;
289 }
290 211
291 bool SingleThreadProxy::BeginMainFrameRequested() const { 212 bool SingleThreadProxy::BeginMainFrameRequested() const { return false; }
292 DCHECK(Proxy::IsMainThread());
293 return commit_requested_;
294 }
295 213
296 size_t SingleThreadProxy::MaxPartialTextureUpdates() const { 214 size_t SingleThreadProxy::MaxPartialTextureUpdates() const {
297 return std::numeric_limits<size_t>::max(); 215 return std::numeric_limits<size_t>::max();
298 } 216 }
299 217
300 void SingleThreadProxy::Stop() { 218 void SingleThreadProxy::Stop() {
301 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); 219 TRACE_EVENT0("cc", "SingleThreadProxy::stop");
302 DCHECK(Proxy::IsMainThread()); 220 DCHECK(Proxy::IsMainThread());
303 { 221 {
304 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 222 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
305 DebugScopedSetImplThread impl(this); 223 DebugScopedSetImplThread impl(this);
306 224
307 BlockingTaskRunner::CapturePostTasks blocked; 225 BlockingTaskRunner::CapturePostTasks blocked;
308 layer_tree_host_->DeleteContentsTexturesOnImplThread( 226 layer_tree_host_->DeleteContentsTexturesOnImplThread(
309 layer_tree_host_impl_->resource_provider()); 227 layer_tree_host_impl_->resource_provider());
310 scheduler_on_impl_thread_.reset();
311 layer_tree_host_impl_.reset(); 228 layer_tree_host_impl_.reset();
312 } 229 }
313 layer_tree_host_ = NULL; 230 layer_tree_host_ = NULL;
314 } 231 }
315 232
316 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { 233 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
317 TRACE_EVENT1( 234 TRACE_EVENT1(
318 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 235 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
319 DCHECK(Proxy::IsImplThread()); 236 DCHECK(Proxy::IsImplThread());
320 UpdateBackgroundAnimateTicking(); 237 UpdateBackgroundAnimateTicking();
321 if (scheduler_on_impl_thread_)
322 scheduler_on_impl_thread_->SetCanDraw(can_draw);
323 } 238 }
324 239
325 void SingleThreadProxy::NotifyReadyToActivate() { 240 void SingleThreadProxy::NotifyReadyToActivate() {
326 // Impl-side painting only. 241 // Thread-only feature.
327 NOTREACHED(); 242 NOTREACHED();
328 } 243 }
329 244
330 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { 245 void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
331 client_->ScheduleComposite(); 246 client_->ScheduleComposite();
332 if (scheduler_on_impl_thread_)
333 scheduler_on_impl_thread_->SetNeedsRedraw();
334 } 247 }
335 248
336 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { 249 void SingleThreadProxy::SetNeedsAnimateOnImplThread() {
337 SetNeedsRedrawOnImplThread(); 250 SetNeedsRedrawOnImplThread();
338 } 251 }
339 252
340 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { 253 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() {
341 // Impl-side painting only. 254 // Thread-only/Impl-side-painting-only feature.
342 NOTREACHED(); 255 NOTREACHED();
343 } 256 }
344 257
345 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( 258 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread(
346 const gfx::Rect& damage_rect) { 259 const gfx::Rect& damage_rect) {
260 // TODO(brianderson): Once we move render_widget scheduling into this class,
261 // we can treat redraw requests more efficiently than CommitAndRedraw
262 // requests.
347 layer_tree_host_impl_->SetViewportDamage(damage_rect); 263 layer_tree_host_impl_->SetViewportDamage(damage_rect);
348 SetNeedsRedrawOnImplThread(); 264 SetNeedsCommit();
349 } 265 }
350 266
351 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { 267 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() {
352 // Impl-side painting only. 268 // Impl-side painting only.
353 NOTREACHED(); 269 NOTREACHED();
354 } 270 }
355 271
356 void SingleThreadProxy::SetNeedsCommitOnImplThread() { 272 void SingleThreadProxy::SetNeedsCommitOnImplThread() {
357 client_->ScheduleComposite(); 273 client_->ScheduleComposite();
358 if (scheduler_on_impl_thread_)
359 scheduler_on_impl_thread_->SetNeedsCommit();
360 } 274 }
361 275
362 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( 276 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
363 scoped_ptr<AnimationEventsVector> events) { 277 scoped_ptr<AnimationEventsVector> events) {
364 TRACE_EVENT0( 278 TRACE_EVENT0(
365 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); 279 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
366 DCHECK(Proxy::IsImplThread()); 280 DCHECK(Proxy::IsImplThread());
367 DebugScopedSetMainThread main(this); 281 DebugScopedSetMainThread main(this);
368 layer_tree_host_->SetAnimationEvents(events.Pass()); 282 layer_tree_host_->SetAnimationEvents(events.Pass());
369 } 283 }
(...skipping 16 matching lines...) Expand all
386 } 300 }
387 301
388 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } 302 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; }
389 303
390 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { 304 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
391 DCHECK(IsImplThread()); 305 DCHECK(IsImplThread());
392 renderer_capabilities_for_main_thread_ = 306 renderer_capabilities_for_main_thread_ =
393 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); 307 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities();
394 } 308 }
395 309
396 void SingleThreadProxy::DidManageTiles() {
397 // Impl-side painting only.
398 NOTREACHED();
399 }
400
401 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { 310 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() {
402 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); 311 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread");
403 { 312 // Cause a commit so we can notice the lost context.
404 DebugScopedSetMainThread main(this); 313 SetNeedsCommitOnImplThread();
405 // This must happen before we notify the scheduler as it may try to recreate
406 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE.
407 layer_tree_host_->DidLoseOutputSurface();
408 }
409 client_->DidAbortSwapBuffers(); 314 client_->DidAbortSwapBuffers();
410 if (scheduler_on_impl_thread_)
411 scheduler_on_impl_thread_->DidLoseOutputSurface();
412 } 315 }
413 316
414 void SingleThreadProxy::DidSwapBuffersOnImplThread() { 317 void SingleThreadProxy::DidSwapBuffersOnImplThread() {
415 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread");
416 if (scheduler_on_impl_thread_)
417 scheduler_on_impl_thread_->DidSwapBuffers();
418 client_->DidPostSwapBuffers(); 318 client_->DidPostSwapBuffers();
419 } 319 }
420 320
421 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { 321 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() {
422 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); 322 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread");
423 if (scheduler_on_impl_thread_) 323 client_->DidCompleteSwapBuffers();
424 scheduler_on_impl_thread_->DidSwapBuffersComplete();
425 layer_tree_host_->DidCompleteSwapBuffers();
426 } 324 }
427 325
428 void SingleThreadProxy::BeginFrame(const BeginFrameArgs& args) { 326 // Called by the legacy scheduling path (e.g. where render_widget does the
429 TRACE_EVENT0("cc", "SingleThreadProxy::BeginFrame"); 327 // scheduling)
430 if (scheduler_on_impl_thread_)
431 scheduler_on_impl_thread_->BeginImplFrame(args);
432 }
433
434 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { 328 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
435 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); 329 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately");
436 DCHECK(Proxy::IsMainThread()); 330 DCHECK(Proxy::IsMainThread());
437 DCHECK(!layer_tree_host_->output_surface_lost()); 331 DCHECK(!layer_tree_host_->output_surface_lost());
438 332
439 DoCommit(frame_begin_time); 333 layer_tree_host_->AnimateLayers(frame_begin_time);
334
335 if (PrioritizedResourceManager* contents_texture_manager =
336 layer_tree_host_->contents_texture_manager()) {
337 contents_texture_manager->UnlinkAndClearEvictedBackings();
338 contents_texture_manager->SetMaxMemoryLimitBytes(
339 layer_tree_host_impl_->memory_allocation_limit_bytes());
340 contents_texture_manager->SetExternalPriorityCutoff(
341 layer_tree_host_impl_->memory_allocation_priority_cutoff());
342 }
343
344 scoped_ptr<ResourceUpdateQueue> queue =
345 make_scoped_ptr(new ResourceUpdateQueue);
346 layer_tree_host_->UpdateLayers(queue.get());
347 layer_tree_host_->WillCommit();
348 DoCommit(queue.Pass());
349 layer_tree_host_->DidBeginMainFrame();
440 350
441 LayerTreeHostImpl::FrameData frame; 351 LayerTreeHostImpl::FrameData frame;
442 DoComposite(frame_begin_time, &frame); 352 if (DoComposite(frame_begin_time, &frame)) {
353 {
354 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
355 DebugScopedSetImplThread impl(this);
356
357 // This CapturePostTasks should be destroyed before
358 // DidCommitAndDrawFrame() is called since that goes out to the embedder,
359 // and we want the embedder to receive its callbacks before that.
360 // NOTE: This maintains consistent ordering with the ThreadProxy since
361 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
362 // there as the main thread is not blocked, so any posted tasks inside
363 // the swap buffers will execute first.
364 BlockingTaskRunner::CapturePostTasks blocked;
365
366 layer_tree_host_impl_->SwapBuffers(frame);
367 }
368 DidSwapFrame();
369 }
443 } 370 }
444 371
445 void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const { 372 void SingleThreadProxy::AsValueInto(base::debug::TracedValue* state) const {
446 // The following line casts away const modifiers because it is just 373 // The following line casts away const modifiers because it is just
447 // setting debug state. We still want the AsValue() function and its 374 // setting debug state. We still want the AsValue() function and its
448 // call chain to be const throughout. 375 // call chain to be const throughout.
449 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); 376 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
450 377
451 state->BeginDictionary("layer_tree_host_impl"); 378 state->BeginDictionary("layer_tree_host_impl");
452 layer_tree_host_impl_->AsValueInto(state); 379 layer_tree_host_impl_->AsValueInto(state);
(...skipping 19 matching lines...) Expand all
472 return layer_tree_host_impl_->visible() && 399 return layer_tree_host_impl_->visible() &&
473 layer_tree_host_impl_->CanDraw(); 400 layer_tree_host_impl_->CanDraw();
474 } 401 }
475 402
476 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { 403 void SingleThreadProxy::UpdateBackgroundAnimateTicking() {
477 DCHECK(Proxy::IsImplThread()); 404 DCHECK(Proxy::IsImplThread());
478 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 405 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
479 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); 406 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer());
480 } 407 }
481 408
482 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, 409 bool SingleThreadProxy::DoComposite(
483 LayerTreeHostImpl::FrameData* frame) { 410 base::TimeTicks frame_begin_time,
411 LayerTreeHostImpl::FrameData* frame) {
484 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); 412 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite");
485 DCHECK(!layer_tree_host_->output_surface_lost()); 413 DCHECK(!layer_tree_host_->output_surface_lost());
486 414
415 bool lost_output_surface = false;
487 { 416 {
488 DebugScopedSetImplThread impl(this); 417 DebugScopedSetImplThread impl(this);
489 base::AutoReset<bool> mark_inside(&inside_draw_, true); 418 base::AutoReset<bool> mark_inside(&inside_draw_, true);
490 419
491 // We guard PrepareToDraw() with CanDraw() because it always returns a valid 420 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
492 // frame, so can only be used when such a frame is possible. Since 421 // frame, so can only be used when such a frame is possible. Since
493 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on 422 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
494 // CanDraw() as well. 423 // CanDraw() as well.
495 if (!ShouldComposite()) { 424 if (!ShouldComposite()) {
496 UpdateBackgroundAnimateTicking(); 425 UpdateBackgroundAnimateTicking();
497 return DRAW_ABORTED_CANT_DRAW; 426 return false;
498 } 427 }
499 428
500 timing_history_.DidStartDrawing();
501
502 layer_tree_host_impl_->Animate( 429 layer_tree_host_impl_->Animate(
503 layer_tree_host_impl_->CurrentFrameTimeTicks()); 430 layer_tree_host_impl_->CurrentFrameTimeTicks());
504 UpdateBackgroundAnimateTicking(); 431 UpdateBackgroundAnimateTicking();
505 432
506 if (!layer_tree_host_impl_->IsContextLost()) { 433 if (!layer_tree_host_impl_->IsContextLost()) {
507 layer_tree_host_impl_->PrepareToDraw(frame); 434 layer_tree_host_impl_->PrepareToDraw(frame);
508 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); 435 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time);
509 layer_tree_host_impl_->DidDrawAllLayers(*frame); 436 layer_tree_host_impl_->DidDrawAllLayers(*frame);
510 } 437 }
438 lost_output_surface = layer_tree_host_impl_->IsContextLost();
511 439
512 bool start_ready_animations = true; 440 bool start_ready_animations = true;
513 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); 441 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
514 442
515 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); 443 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
516
517 timing_history_.DidFinishDrawing();
518 } 444 }
519 445
520 { 446 if (lost_output_surface) {
521 DebugScopedSetImplThread impl(this); 447 layer_tree_host_->DidLoseOutputSurface();
448 return false;
449 }
522 450
523 if (layer_tree_host_impl_->IsContextLost()) { 451 return true;
524 DidLoseOutputSurfaceOnImplThread();
525 } else {
526 // This CapturePostTasks should be destroyed before
527 // DidCommitAndDrawFrame() is called since that goes out to the
528 // embedder,
529 // and we want the embedder to receive its callbacks before that.
530 // NOTE: This maintains consistent ordering with the ThreadProxy since
531 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread
532 // there as the main thread is not blocked, so any posted tasks inside
533 // the swap buffers will execute first.
534 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
535
536 BlockingTaskRunner::CapturePostTasks blocked;
537 layer_tree_host_impl_->SwapBuffers(*frame);
538 }
539 }
540 DidCommitAndDrawFrame();
541
542 return DRAW_SUCCESS;
543 } 452 }
544 453
545 void SingleThreadProxy::DidCommitAndDrawFrame() { 454 void SingleThreadProxy::DidSwapFrame() {
546 if (next_frame_is_newly_committed_frame_) { 455 if (next_frame_is_newly_committed_frame_) {
547 DebugScopedSetMainThread main(this);
548 next_frame_is_newly_committed_frame_ = false; 456 next_frame_is_newly_committed_frame_ = false;
549 layer_tree_host_->DidCommitAndDrawFrame(); 457 layer_tree_host_->DidCommitAndDrawFrame();
550 } 458 }
551 } 459 }
552 460
553 bool SingleThreadProxy::CommitPendingForTesting() { return false; } 461 bool SingleThreadProxy::CommitPendingForTesting() { return false; }
554 462
555 void SingleThreadProxy::SetNeedsBeginFrame(bool enable) {
556 layer_tree_host_impl_->SetNeedsBeginFrame(enable);
557 }
558
559 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
560 layer_tree_host_impl_->WillBeginImplFrame(args);
561 }
562
563 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() {
564 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
565 // Although this proxy is single-threaded, it's problematic to synchronously
566 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
567 // could cause a commit to occur in between a series of SetNeedsCommit calls
568 // (i.e. property modifications) causing some to fall on one frame and some to
569 // fall on the next. Doing it asynchronously instead matches the semantics of
570 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
571 // synchronous commit.
572 MainThreadTaskRunner()->PostTask(
573 FROM_HERE,
574 base::Bind(&SingleThreadProxy::BeginMainFrame,
575 weak_factory_.GetWeakPtr()));
576 }
577
578 void SingleThreadProxy::BeginMainFrame() {
579 if (defer_commits_) {
580 DCHECK(!commit_was_deferred_);
581 commit_was_deferred_ = true;
582 layer_tree_host_->DidDeferCommit();
583 return;
584 }
585 timing_history_.DidBeginMainFrame();
586
587 DCHECK(scheduler_on_impl_thread_);
588 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted();
589 scheduler_on_impl_thread_->NotifyReadyToCommit();
590 }
591
592 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
593 DebugScopedSetImplThread impl(this);
594 if (layer_tree_host_impl_->IsContextLost()) {
595 DidCommitAndDrawFrame();
596 return DRAW_SUCCESS;
597 }
598
599 LayerTreeHostImpl::FrameData frame;
600 return DoComposite(layer_tree_host_impl_->CurrentFrameTimeTicks(), &frame);
601 }
602
603 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() {
604 NOTREACHED();
605 return INVALID_RESULT;
606 }
607
608 void SingleThreadProxy::ScheduledActionCommit() {
609 DebugScopedSetMainThread main(this);
610 DoCommit(layer_tree_host_impl_->CurrentFrameTimeTicks());
611 }
612
613 void SingleThreadProxy::ScheduledActionAnimate() {
614 TRACE_EVENT0("cc", "ScheduledActionAnimate");
615 layer_tree_host_impl_->Animate(
616 layer_tree_host_impl_->CurrentFrameTimeTicks());
617 }
618
619 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() {
620 // Impl-side painting only.
621 NOTREACHED();
622 }
623
624 void SingleThreadProxy::ScheduledActionActivateSyncTree() {
625 }
626
627 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
628 DebugScopedSetMainThread main(this);
629 DCHECK(scheduler_on_impl_thread_);
630 // If possible, create the output surface in a post task. Synchronously
631 // creating the output surface makes tests more awkward since this differs
632 // from the ThreadProxy behavior. However, sometimes there is no
633 // task runner.
634 if (Proxy::MainThreadTaskRunner()) {
635 MainThreadTaskRunner()->PostTask(
636 FROM_HERE,
637 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface,
638 weak_factory_.GetWeakPtr()));
639 } else {
640 CreateAndInitializeOutputSurface();
641 }
642 }
643
644 void SingleThreadProxy::ScheduledActionManageTiles() {
645 // Impl-side painting only.
646 NOTREACHED();
647 }
648
649 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) {
650 }
651
652 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() {
653 return timing_history_.DrawDurationEstimate();
654 }
655
656 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() {
657 return timing_history_.BeginMainFrameToCommitDurationEstimate();
658 }
659
660 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() {
661 return timing_history_.CommitToActivateDurationEstimate();
662 }
663
664 void SingleThreadProxy::DidBeginImplFrameDeadline() {
665 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
666 }
667
668 } // namespace cc 463 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/single_thread_proxy.h ('k') | cc/trees/thread_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698