| 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 <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 if (cmd->HasSwitch(switches::kDisableLowResTiling)) | 402 if (cmd->HasSwitch(switches::kDisableLowResTiling)) |
| 403 settings.create_low_res_tiling = false; | 403 settings.create_low_res_tiling = false; |
| 404 | 404 |
| 405 compositor->Initialize(settings); | 405 compositor->Initialize(settings); |
| 406 | 406 |
| 407 return compositor.Pass(); | 407 return compositor.Pass(); |
| 408 } | 408 } |
| 409 | 409 |
| 410 RenderWidgetCompositor::RenderWidgetCompositor(RenderWidget* widget, | 410 RenderWidgetCompositor::RenderWidgetCompositor(RenderWidget* widget, |
| 411 bool threaded) | 411 bool threaded) |
| 412 : threaded_(threaded), | 412 : num_failed_recreate_attempts_(0), |
| 413 threaded_(threaded), |
| 413 widget_(widget), | 414 widget_(widget), |
| 414 send_v8_idle_notification_after_commit_(true) { | 415 send_v8_idle_notification_after_commit_(true), |
| 416 weak_factory_(this) { |
| 415 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 417 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 416 | 418 |
| 417 if (cmd->HasSwitch(switches::kEnableV8IdleNotificationAfterCommit)) | 419 if (cmd->HasSwitch(switches::kEnableV8IdleNotificationAfterCommit)) |
| 418 send_v8_idle_notification_after_commit_ = true; | 420 send_v8_idle_notification_after_commit_ = true; |
| 419 if (cmd->HasSwitch(switches::kDisableV8IdleNotificationAfterCommit)) | 421 if (cmd->HasSwitch(switches::kDisableV8IdleNotificationAfterCommit)) |
| 420 send_v8_idle_notification_after_commit_ = false; | 422 send_v8_idle_notification_after_commit_ = false; |
| 421 } | 423 } |
| 422 | 424 |
| 423 RenderWidgetCompositor::~RenderWidgetCompositor() {} | 425 RenderWidgetCompositor::~RenderWidgetCompositor() {} |
| 424 | 426 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 const base::Callback<void(scoped_ptr<base::Value>)>& callback) { | 508 const base::Callback<void(scoped_ptr<base::Value>)>& callback) { |
| 507 return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback); | 509 return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback); |
| 508 } | 510 } |
| 509 | 511 |
| 510 bool RenderWidgetCompositor::SendMessageToMicroBenchmark( | 512 bool RenderWidgetCompositor::SendMessageToMicroBenchmark( |
| 511 int id, | 513 int id, |
| 512 scoped_ptr<base::Value> value) { | 514 scoped_ptr<base::Value> value) { |
| 513 return layer_tree_host_->SendMessageToMicroBenchmark(id, value.Pass()); | 515 return layer_tree_host_->SendMessageToMicroBenchmark(id, value.Pass()); |
| 514 } | 516 } |
| 515 | 517 |
| 516 void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) { | 518 void RenderWidgetCompositor::Initialize(const cc::LayerTreeSettings& settings) { |
| 517 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy; | 519 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy; |
| 518 scoped_refptr<base::SingleThreadTaskRunner> | 520 scoped_refptr<base::SingleThreadTaskRunner> |
| 519 main_thread_compositor_task_runner(base::MessageLoopProxy::current()); | 521 main_thread_compositor_task_runner(base::MessageLoopProxy::current()); |
| 520 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 522 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 521 cc::SharedBitmapManager* shared_bitmap_manager = NULL; | 523 cc::SharedBitmapManager* shared_bitmap_manager = NULL; |
| 522 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = NULL; | 524 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = NULL; |
| 523 // render_thread may be NULL in tests. | 525 // render_thread may be NULL in tests. |
| 524 if (render_thread) { | 526 if (render_thread) { |
| 525 compositor_message_loop_proxy = | 527 compositor_message_loop_proxy = |
| 526 render_thread->compositor_message_loop_proxy(); | 528 render_thread->compositor_message_loop_proxy(); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 void RenderWidgetCompositor::ApplyViewportDeltas( | 838 void RenderWidgetCompositor::ApplyViewportDeltas( |
| 837 const gfx::Vector2d& scroll_delta, | 839 const gfx::Vector2d& scroll_delta, |
| 838 float page_scale, | 840 float page_scale, |
| 839 float top_controls_delta) { | 841 float top_controls_delta) { |
| 840 widget_->webwidget()->applyViewportDeltas( | 842 widget_->webwidget()->applyViewportDeltas( |
| 841 scroll_delta, | 843 scroll_delta, |
| 842 page_scale, | 844 page_scale, |
| 843 top_controls_delta); | 845 top_controls_delta); |
| 844 } | 846 } |
| 845 | 847 |
| 846 void RenderWidgetCompositor::RequestNewOutputSurface(bool fallback) { | 848 void RenderWidgetCompositor::RequestNewOutputSurface() { |
| 847 // If the host is closing, then no more compositing is possible. This | 849 // If the host is closing, then no more compositing is possible. This |
| 848 // prevents shutdown races between handling the close message and | 850 // prevents shutdown races between handling the close message and |
| 849 // the CreateOutputSurface task. | 851 // the CreateOutputSurface task. |
| 850 if (widget_->host_closing()) | 852 if (widget_->host_closing()) |
| 851 return; | 853 return; |
| 852 layer_tree_host_->SetOutputSurface(widget_->CreateOutputSurface(fallback)); | 854 |
| 855 bool fallback = |
| 856 num_failed_recreate_attempts_ >= OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK; |
| 857 scoped_ptr<cc::OutputSurface> surface(widget_->CreateOutputSurface(fallback)); |
| 858 |
| 859 if (!surface) { |
| 860 DidFailToInitializeOutputSurface(); |
| 861 return; |
| 862 } |
| 863 |
| 864 layer_tree_host_->SetOutputSurface(surface.Pass()); |
| 853 } | 865 } |
| 854 | 866 |
| 855 void RenderWidgetCompositor::DidInitializeOutputSurface() { | 867 void RenderWidgetCompositor::DidInitializeOutputSurface() { |
| 868 num_failed_recreate_attempts_ = 0; |
| 869 } |
| 870 |
| 871 void RenderWidgetCompositor::DidFailToInitializeOutputSurface() { |
| 872 ++num_failed_recreate_attempts_; |
| 873 // Tolerate a certain number of recreation failures to work around races |
| 874 // in the output-surface-lost machinery. |
| 875 LOG_IF(FATAL, (num_failed_recreate_attempts_ >= MAX_OUTPUT_SURFACE_RETRIES)) |
| 876 << "Failed to create a fallback OutputSurface."; |
| 877 |
| 878 base::MessageLoop::current()->PostTask( |
| 879 FROM_HERE, base::Bind(&RenderWidgetCompositor::RequestNewOutputSurface, |
| 880 weak_factory_.GetWeakPtr())); |
| 856 } | 881 } |
| 857 | 882 |
| 858 void RenderWidgetCompositor::WillCommit() { | 883 void RenderWidgetCompositor::WillCommit() { |
| 859 widget_->InstrumentWillComposite(); | 884 widget_->InstrumentWillComposite(); |
| 860 } | 885 } |
| 861 | 886 |
| 862 void RenderWidgetCompositor::DidCommit() { | 887 void RenderWidgetCompositor::DidCommit() { |
| 863 DCHECK(!temporary_copy_output_request_); | 888 DCHECK(!temporary_copy_output_request_); |
| 864 if (send_v8_idle_notification_after_commit_) { | 889 if (send_v8_idle_notification_after_commit_) { |
| 865 base::TimeDelta idle_time = begin_main_frame_time_ + | 890 base::TimeDelta idle_time = begin_main_frame_time_ + |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 widget_->OnSwapBuffersAborted(); | 928 widget_->OnSwapBuffersAborted(); |
| 904 } | 929 } |
| 905 | 930 |
| 906 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() { | 931 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() { |
| 907 cc::ContextProvider* provider = | 932 cc::ContextProvider* provider = |
| 908 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); | 933 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); |
| 909 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM(); | 934 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM(); |
| 910 } | 935 } |
| 911 | 936 |
| 912 } // namespace content | 937 } // namespace content |
| OLD | NEW |