OLD | NEW |
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/base/thread.h" | 9 #include "cc/base/thread.h" |
10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); | 47 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
48 DCHECK(Proxy::IsMainThread()); | 48 DCHECK(Proxy::IsMainThread()); |
49 DCHECK(!layer_tree_host_impl_.get() && | 49 DCHECK(!layer_tree_host_impl_.get() && |
50 !layer_tree_host_); // make sure Stop() got called. | 50 !layer_tree_host_); // make sure Stop() got called. |
51 } | 51 } |
52 | 52 |
53 bool SingleThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { | 53 bool SingleThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { |
54 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeAndReadback"); | 54 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeAndReadback"); |
55 DCHECK(Proxy::IsMainThread()); | 55 DCHECK(Proxy::IsMainThread()); |
56 | 56 |
57 if (!CommitAndComposite(base::TimeTicks::Now())) | 57 gfx::Rect device_viewport_damage_rect = rect; |
| 58 |
| 59 LayerTreeHostImpl::FrameData frame; |
| 60 if (!CommitAndComposite(base::TimeTicks::Now(), |
| 61 device_viewport_damage_rect, |
| 62 &frame)) |
58 return false; | 63 return false; |
59 | 64 |
60 { | 65 { |
61 DebugScopedSetImplThread impl(this); | 66 DebugScopedSetImplThread impl(this); |
62 layer_tree_host_impl_->Readback(pixels, rect); | 67 layer_tree_host_impl_->Readback(pixels, rect); |
63 | 68 |
64 if (layer_tree_host_impl_->IsContextLost()) | 69 if (layer_tree_host_impl_->IsContextLost()) |
65 return false; | 70 return false; |
66 | 71 |
67 layer_tree_host_impl_->SwapBuffers(); | 72 layer_tree_host_impl_->SwapBuffers(frame); |
68 } | 73 } |
69 DidSwapFrame(); | 74 DidSwapFrame(); |
70 | 75 |
71 return true; | 76 return true; |
72 } | 77 } |
73 | 78 |
74 void SingleThreadProxy::FinishAllRendering() { | 79 void SingleThreadProxy::FinishAllRendering() { |
75 DCHECK(Proxy::IsMainThread()); | 80 DCHECK(Proxy::IsMainThread()); |
76 { | 81 { |
77 DebugScopedSetImplThread impl(this); | 82 DebugScopedSetImplThread impl(this); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } | 328 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
324 | 329 |
325 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { | 330 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
326 // Cause a commit so we can notice the lost context. | 331 // Cause a commit so we can notice the lost context. |
327 SetNeedsCommitOnImplThread(); | 332 SetNeedsCommitOnImplThread(); |
328 } | 333 } |
329 | 334 |
330 // Called by the legacy scheduling path (e.g. where render_widget does the | 335 // Called by the legacy scheduling path (e.g. where render_widget does the |
331 // scheduling) | 336 // scheduling) |
332 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { | 337 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
333 if (CommitAndComposite(frame_begin_time)) { | 338 gfx::Rect device_viewport_damage_rect; |
334 layer_tree_host_impl_->SwapBuffers(); | 339 |
| 340 LayerTreeHostImpl::FrameData frame; |
| 341 if (CommitAndComposite(frame_begin_time, |
| 342 device_viewport_damage_rect, |
| 343 &frame)) { |
| 344 layer_tree_host_impl_->SwapBuffers(frame); |
335 DidSwapFrame(); | 345 DidSwapFrame(); |
336 } | 346 } |
337 } | 347 } |
338 | 348 |
339 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { | 349 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { |
340 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 350 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
341 { | 351 { |
342 // The following line casts away const modifiers because it is just | 352 // The following line casts away const modifiers because it is just |
343 // setting debug state. We still want the AsValue() function and its | 353 // setting debug state. We still want the AsValue() function and its |
344 // call chain to be const throughout. | 354 // call chain to be const throughout. |
345 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); | 355 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
346 | 356 |
347 state->Set("layer_tree_host_impl", | 357 state->Set("layer_tree_host_impl", |
348 layer_tree_host_impl_->AsValue().release()); | 358 layer_tree_host_impl_->AsValue().release()); |
349 } | 359 } |
350 return state.PassAs<base::Value>(); | 360 return state.PassAs<base::Value>(); |
351 } | 361 } |
352 | 362 |
353 void SingleThreadProxy::ForceSerializeOnSwapBuffers() { | 363 void SingleThreadProxy::ForceSerializeOnSwapBuffers() { |
354 { | 364 { |
355 DebugScopedSetImplThread impl(this); | 365 DebugScopedSetImplThread impl(this); |
356 if (renderer_initialized_) | 366 if (renderer_initialized_) |
357 layer_tree_host_impl_->renderer()->DoNoOp(); | 367 layer_tree_host_impl_->renderer()->DoNoOp(); |
358 } | 368 } |
359 } | 369 } |
360 | 370 |
361 void SingleThreadProxy::OnSwapBuffersCompleteOnImplThread() { NOTREACHED(); } | 371 void SingleThreadProxy::OnSwapBuffersCompleteOnImplThread() { NOTREACHED(); } |
362 | 372 |
363 bool SingleThreadProxy::CommitAndComposite(base::TimeTicks frame_begin_time) { | 373 bool SingleThreadProxy::CommitAndComposite( |
| 374 base::TimeTicks frame_begin_time, |
| 375 gfx::Rect device_viewport_damage_rect, |
| 376 LayerTreeHostImpl::FrameData* frame) { |
364 DCHECK(Proxy::IsMainThread()); | 377 DCHECK(Proxy::IsMainThread()); |
365 | 378 |
366 if (!layer_tree_host_->InitializeRendererIfNeeded()) | 379 if (!layer_tree_host_->InitializeRendererIfNeeded()) |
367 return false; | 380 return false; |
368 | 381 |
369 scoped_refptr<cc::ContextProvider> offscreen_context_provider; | 382 scoped_refptr<cc::ContextProvider> offscreen_context_provider; |
370 if (renderer_capabilities_for_main_thread_.using_offscreen_context3d && | 383 if (renderer_capabilities_for_main_thread_.using_offscreen_context3d && |
371 layer_tree_host_->needs_offscreen_context()) { | 384 layer_tree_host_->needs_offscreen_context()) { |
372 offscreen_context_provider = | 385 offscreen_context_provider = |
373 layer_tree_host_->client()->OffscreenContextProviderForMainThread(); | 386 layer_tree_host_->client()->OffscreenContextProviderForMainThread(); |
374 if (offscreen_context_provider) | 387 if (offscreen_context_provider) |
375 created_offscreen_context_provider_ = true; | 388 created_offscreen_context_provider_ = true; |
376 } | 389 } |
377 | 390 |
378 layer_tree_host_->contents_texture_manager()->UnlinkAndClearEvictedBackings(); | 391 layer_tree_host_->contents_texture_manager()->UnlinkAndClearEvictedBackings(); |
379 | 392 |
380 scoped_ptr<ResourceUpdateQueue> queue = | 393 scoped_ptr<ResourceUpdateQueue> queue = |
381 make_scoped_ptr(new ResourceUpdateQueue); | 394 make_scoped_ptr(new ResourceUpdateQueue); |
382 layer_tree_host_->UpdateLayers( | 395 layer_tree_host_->UpdateLayers( |
383 queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes()); | 396 queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes()); |
384 | 397 |
385 layer_tree_host_->WillCommit(); | 398 layer_tree_host_->WillCommit(); |
386 DoCommit(queue.Pass()); | 399 DoCommit(queue.Pass()); |
387 bool result = DoComposite(offscreen_context_provider, frame_begin_time); | 400 bool result = DoComposite(offscreen_context_provider, |
| 401 frame_begin_time, |
| 402 device_viewport_damage_rect, |
| 403 frame); |
388 layer_tree_host_->DidBeginFrame(); | 404 layer_tree_host_->DidBeginFrame(); |
389 return result; | 405 return result; |
390 } | 406 } |
391 | 407 |
392 bool SingleThreadProxy::ShouldComposite() const { | 408 bool SingleThreadProxy::ShouldComposite() const { |
393 DCHECK(Proxy::IsImplThread()); | 409 DCHECK(Proxy::IsImplThread()); |
394 return layer_tree_host_impl_->visible() && | 410 return layer_tree_host_impl_->visible() && |
395 layer_tree_host_impl_->CanDraw(); | 411 layer_tree_host_impl_->CanDraw(); |
396 } | 412 } |
397 | 413 |
398 bool SingleThreadProxy::DoComposite( | 414 bool SingleThreadProxy::DoComposite( |
399 scoped_refptr<cc::ContextProvider> offscreen_context_provider, | 415 scoped_refptr<cc::ContextProvider> offscreen_context_provider, |
400 base::TimeTicks frame_begin_time) { | 416 base::TimeTicks frame_begin_time, |
| 417 gfx::Rect device_viewport_damage_rect, |
| 418 LayerTreeHostImpl::FrameData* frame) { |
401 DCHECK(!output_surface_lost_); | 419 DCHECK(!output_surface_lost_); |
402 { | 420 { |
403 DebugScopedSetImplThread impl(this); | 421 DebugScopedSetImplThread impl(this); |
404 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 422 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
405 | 423 |
406 layer_tree_host_impl_->resource_provider()-> | 424 layer_tree_host_impl_->resource_provider()-> |
407 set_offscreen_context_provider(offscreen_context_provider); | 425 set_offscreen_context_provider(offscreen_context_provider); |
408 | 426 |
409 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 427 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
410 // frame, so can only be used when such a frame is possible. Since | 428 // frame, so can only be used when such a frame is possible. Since |
411 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 429 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
412 // CanDraw() as well. | 430 // CanDraw() as well. |
413 if (!ShouldComposite()) { | 431 if (!ShouldComposite()) { |
414 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); | 432 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); |
415 return false; | 433 return false; |
416 } | 434 } |
417 | 435 |
418 layer_tree_host_impl_->Animate(base::TimeTicks::Now(), base::Time::Now()); | 436 layer_tree_host_impl_->Animate(base::TimeTicks::Now(), base::Time::Now()); |
419 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false); | 437 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false); |
420 | 438 |
421 LayerTreeHostImpl::FrameData frame; | 439 layer_tree_host_impl_->PrepareToDraw(frame, device_viewport_damage_rect); |
422 layer_tree_host_impl_->PrepareToDraw(&frame); | 440 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
423 layer_tree_host_impl_->DrawLayers(&frame, frame_begin_time); | 441 layer_tree_host_impl_->DidDrawAllLayers(*frame); |
424 layer_tree_host_impl_->DidDrawAllLayers(frame); | |
425 output_surface_lost_ = layer_tree_host_impl_->IsContextLost(); | 442 output_surface_lost_ = layer_tree_host_impl_->IsContextLost(); |
426 | 443 |
427 bool start_ready_animations = true; | 444 bool start_ready_animations = true; |
428 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 445 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
429 | 446 |
430 layer_tree_host_impl_->BeginNextFrame(); | 447 layer_tree_host_impl_->BeginNextFrame(); |
431 } | 448 } |
432 | 449 |
433 if (output_surface_lost_) { | 450 if (output_surface_lost_) { |
434 cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_-> | 451 cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_-> |
(...skipping 16 matching lines...) Expand all Loading... |
451 | 468 |
452 bool SingleThreadProxy::CommitPendingForTesting() { return false; } | 469 bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
453 | 470 |
454 skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() { | 471 skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() { |
455 // Impl-side painting only. | 472 // Impl-side painting only. |
456 NOTREACHED(); | 473 NOTREACHED(); |
457 return skia::RefPtr<SkPicture>(); | 474 return skia::RefPtr<SkPicture>(); |
458 } | 475 } |
459 | 476 |
460 } // namespace cc | 477 } // namespace cc |
OLD | NEW |