| 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/single_thread_proxy.h" | 5 #include "cc/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/context_provider.h" | 9 #include "cc/context_provider.h" |
| 10 #include "cc/draw_quad.h" | 10 #include "cc/draw_quad.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); | 48 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
| 49 DCHECK(Proxy::IsMainThread()); | 49 DCHECK(Proxy::IsMainThread()); |
| 50 DCHECK(!layer_tree_host_impl_.get() && | 50 DCHECK(!layer_tree_host_impl_.get() && |
| 51 !layer_tree_host_); // make sure Stop() got called. | 51 !layer_tree_host_); // make sure Stop() got called. |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool SingleThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { | 54 bool SingleThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { |
| 55 TRACE_EVENT0("cc", "SingleThreadProxy::compositeAndReadback"); | 55 TRACE_EVENT0("cc", "SingleThreadProxy::compositeAndReadback"); |
| 56 DCHECK(Proxy::IsMainThread()); | 56 DCHECK(Proxy::IsMainThread()); |
| 57 | 57 |
| 58 if (!CommitAndComposite()) | 58 if (!CommitAndComposite(base::TimeTicks::Now())) |
| 59 return false; | 59 return false; |
| 60 | 60 |
| 61 { | 61 { |
| 62 DebugScopedSetImplThread impl(this); | 62 DebugScopedSetImplThread impl(this); |
| 63 layer_tree_host_impl_->readback(pixels, rect); | 63 layer_tree_host_impl_->readback(pixels, rect); |
| 64 | 64 |
| 65 if (layer_tree_host_impl_->isContextLost()) | 65 if (layer_tree_host_impl_->isContextLost()) |
| 66 return false; | 66 return false; |
| 67 | 67 |
| 68 layer_tree_host_impl_->swapBuffers(); | 68 layer_tree_host_impl_->swapBuffers(); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 328 |
| 329 bool SingleThreadProxy::isInsideDraw() { return inside_draw_; } | 329 bool SingleThreadProxy::isInsideDraw() { return inside_draw_; } |
| 330 | 330 |
| 331 void SingleThreadProxy::didLoseOutputSurfaceOnImplThread() { | 331 void SingleThreadProxy::didLoseOutputSurfaceOnImplThread() { |
| 332 // Cause a commit so we can notice the lost context. | 332 // Cause a commit so we can notice the lost context. |
| 333 setNeedsCommitOnImplThread(); | 333 setNeedsCommitOnImplThread(); |
| 334 } | 334 } |
| 335 | 335 |
| 336 // Called by the legacy scheduling path (e.g. where render_widget does the | 336 // Called by the legacy scheduling path (e.g. where render_widget does the |
| 337 // scheduling) | 337 // scheduling) |
| 338 void SingleThreadProxy::CompositeImmediately() { | 338 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
| 339 if (CommitAndComposite()) { | 339 if (CommitAndComposite(frame_begin_time)) { |
| 340 layer_tree_host_impl_->swapBuffers(); | 340 layer_tree_host_impl_->swapBuffers(); |
| 341 DidSwapFrame(); | 341 DidSwapFrame(); |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| 345 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { | 345 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { |
| 346 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 346 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 347 { | 347 { |
| 348 // The following line casts away const modifiers because it is just | 348 // The following line casts away const modifiers because it is just |
| 349 // setting debug state. We still want the AsValue() function and its | 349 // setting debug state. We still want the AsValue() function and its |
| 350 // call chain to be const throughout. | 350 // call chain to be const throughout. |
| 351 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); | 351 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
| 352 | 352 |
| 353 state->Set("layer_tree_host_impl", | 353 state->Set("layer_tree_host_impl", |
| 354 layer_tree_host_impl_->asValue().release()); | 354 layer_tree_host_impl_->asValue().release()); |
| 355 } | 355 } |
| 356 return state.PassAs<base::Value>(); | 356 return state.PassAs<base::Value>(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 void SingleThreadProxy::ForceSerializeOnSwapBuffers() { | 359 void SingleThreadProxy::ForceSerializeOnSwapBuffers() { |
| 360 { | 360 { |
| 361 DebugScopedSetImplThread impl(this); | 361 DebugScopedSetImplThread impl(this); |
| 362 if (renderer_initialized_) | 362 if (renderer_initialized_) |
| 363 layer_tree_host_impl_->renderer()->DoNoOp(); | 363 layer_tree_host_impl_->renderer()->DoNoOp(); |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 void SingleThreadProxy::onSwapBuffersCompleteOnImplThread() { NOTREACHED(); } | 367 void SingleThreadProxy::onSwapBuffersCompleteOnImplThread() { NOTREACHED(); } |
| 368 | 368 |
| 369 bool SingleThreadProxy::CommitAndComposite() { | 369 bool SingleThreadProxy::CommitAndComposite(base::TimeTicks frame_begin_time) { |
| 370 DCHECK(Proxy::IsMainThread()); | 370 DCHECK(Proxy::IsMainThread()); |
| 371 | 371 |
| 372 if (!layer_tree_host_->initializeRendererIfNeeded()) | 372 if (!layer_tree_host_->initializeRendererIfNeeded()) |
| 373 return false; | 373 return false; |
| 374 | 374 |
| 375 scoped_refptr<cc::ContextProvider> offscreen_context_provider; | 375 scoped_refptr<cc::ContextProvider> offscreen_context_provider; |
| 376 if (renderer_capabilities_for_main_thread_.usingOffscreenContext3d && | 376 if (renderer_capabilities_for_main_thread_.usingOffscreenContext3d && |
| 377 layer_tree_host_->needsOffscreenContext()) { | 377 layer_tree_host_->needsOffscreenContext()) { |
| 378 offscreen_context_provider = | 378 offscreen_context_provider = |
| 379 layer_tree_host_->client()->OffscreenContextProviderForMainThread(); | 379 layer_tree_host_->client()->OffscreenContextProviderForMainThread(); |
| 380 if (offscreen_context_provider->InitializeOnMainThread()) | 380 if (offscreen_context_provider->InitializeOnMainThread()) |
| 381 created_offscreen_context_provider = true; | 381 created_offscreen_context_provider = true; |
| 382 else | 382 else |
| 383 offscreen_context_provider = NULL; | 383 offscreen_context_provider = NULL; |
| 384 } | 384 } |
| 385 | 385 |
| 386 layer_tree_host_->contentsTextureManager()->unlinkAndClearEvictedBackings(); | 386 layer_tree_host_->contentsTextureManager()->unlinkAndClearEvictedBackings(); |
| 387 | 387 |
| 388 scoped_ptr<ResourceUpdateQueue> queue = | 388 scoped_ptr<ResourceUpdateQueue> queue = |
| 389 make_scoped_ptr(new ResourceUpdateQueue); | 389 make_scoped_ptr(new ResourceUpdateQueue); |
| 390 layer_tree_host_->updateLayers( | 390 layer_tree_host_->updateLayers( |
| 391 *(queue.get()), layer_tree_host_impl_->memoryAllocationLimitBytes()); | 391 *(queue.get()), layer_tree_host_impl_->memoryAllocationLimitBytes()); |
| 392 | 392 |
| 393 layer_tree_host_->willCommit(); | 393 layer_tree_host_->willCommit(); |
| 394 DoCommit(queue.Pass()); | 394 DoCommit(queue.Pass()); |
| 395 bool result = DoComposite(offscreen_context_provider); | 395 bool result = DoComposite(offscreen_context_provider, frame_begin_time); |
| 396 layer_tree_host_->didBeginFrame(); | 396 layer_tree_host_->didBeginFrame(); |
| 397 return result; | 397 return result; |
| 398 } | 398 } |
| 399 | 399 |
| 400 bool SingleThreadProxy::DoComposite( | 400 bool SingleThreadProxy::DoComposite( |
| 401 scoped_refptr<cc::ContextProvider> offscreen_context_provider) { | 401 scoped_refptr<cc::ContextProvider> offscreen_context_provider, |
| 402 base::TimeTicks frame_begin_time) { |
| 402 DCHECK(!output_surface_lost_); | 403 DCHECK(!output_surface_lost_); |
| 403 { | 404 { |
| 404 DebugScopedSetImplThread impl(this); | 405 DebugScopedSetImplThread impl(this); |
| 405 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 406 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 406 | 407 |
| 407 layer_tree_host_impl_->resourceProvider()-> | 408 layer_tree_host_impl_->resourceProvider()-> |
| 408 SetOffscreenContextProvider(offscreen_context_provider); | 409 SetOffscreenContextProvider(offscreen_context_provider); |
| 409 | 410 |
| 410 if (!layer_tree_host_impl_->visible()) | 411 if (!layer_tree_host_impl_->visible()) |
| 411 return false; | 412 return false; |
| 412 | 413 |
| 413 layer_tree_host_impl_->animate(base::TimeTicks::Now(), base::Time::Now()); | 414 layer_tree_host_impl_->animate(base::TimeTicks::Now(), base::Time::Now()); |
| 414 | 415 |
| 415 // We guard prepareToDraw() with canDraw() because it always returns a valid | 416 // We guard prepareToDraw() with canDraw() because it always returns a valid |
| 416 // frame, so can only be used when such a frame is possible. Since | 417 // frame, so can only be used when such a frame is possible. Since |
| 417 // drawLayers() depends on the result of prepareToDraw(), it is guarded on | 418 // drawLayers() depends on the result of prepareToDraw(), it is guarded on |
| 418 // canDraw() as well. | 419 // canDraw() as well. |
| 419 if (!layer_tree_host_impl_->canDraw()) | 420 if (!layer_tree_host_impl_->canDraw()) |
| 420 return false; | 421 return false; |
| 421 | 422 |
| 422 LayerTreeHostImpl::FrameData frame; | 423 LayerTreeHostImpl::FrameData frame; |
| 423 layer_tree_host_impl_->prepareToDraw(frame); | 424 layer_tree_host_impl_->prepareToDraw(frame); |
| 424 layer_tree_host_impl_->drawLayers(frame); | 425 layer_tree_host_impl_->drawLayers(frame, frame_begin_time); |
| 425 layer_tree_host_impl_->didDrawAllLayers(frame); | 426 layer_tree_host_impl_->didDrawAllLayers(frame); |
| 426 output_surface_lost_ = layer_tree_host_impl_->isContextLost(); | 427 output_surface_lost_ = layer_tree_host_impl_->isContextLost(); |
| 427 | 428 |
| 428 layer_tree_host_impl_->beginNextFrame(); | 429 layer_tree_host_impl_->beginNextFrame(); |
| 429 } | 430 } |
| 430 | 431 |
| 431 if (output_surface_lost_) { | 432 if (output_surface_lost_) { |
| 432 cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_-> | 433 cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_-> |
| 433 resourceProvider()->offscreen_context_provider(); | 434 resourceProvider()->offscreen_context_provider(); |
| 434 if (offscreen_contexts) | 435 if (offscreen_contexts) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 449 | 450 |
| 450 bool SingleThreadProxy::CommitPendingForTesting() { return false; } | 451 bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
| 451 | 452 |
| 452 skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() { | 453 skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() { |
| 453 // Impl-side painting only. | 454 // Impl-side painting only. |
| 454 NOTREACHED(); | 455 NOTREACHED(); |
| 455 return skia::RefPtr<SkPicture>(); | 456 return skia::RefPtr<SkPicture>(); |
| 456 } | 457 } |
| 457 | 458 |
| 458 } // namespace cc | 459 } // namespace cc |
| OLD | NEW |