thread_proxy.cc revision 3551c9c881056c480085172ff9840cab31610854
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2011 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/trees/thread_proxy.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <string> 87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/auto_reset.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/bind.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/debug/trace_event.h" 127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/metrics/histogram.h" 134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "cc/input/input_handler.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/output/context_provider.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/output/output_surface.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/quads/draw_quad.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/resources/prioritized_resource_manager.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/scheduler/delay_based_time_source.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/scheduler/frame_rate_controller.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/scheduler/scheduler.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/trees/layer_tree_host.h" 22424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "cc/trees/layer_tree_impl.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Measured in seconds. 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const double kContextRecreationTickRate = 0.03; 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Measured in seconds. 307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochconst double kSmoothnessTakesPriorityExpirationDelay = 0.25; 317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const size_t kDurationHistorySize = 60; 337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const double kCommitAndActivationDurationEstimationPercentile = 50.0; 347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const double kDrawDurationEstimationPercentile = 100.0; 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kDrawDurationEstimatePaddingInMicroseconds = 0; 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} // namespace 387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace cc { 407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)struct ThreadProxy::ReadbackRequest { 427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CompletionEvent completion; 437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool success; 447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void* pixels; 457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) gfx::Rect rect; 467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}; 477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)struct ThreadProxy::CommitPendingRequest { 497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CompletionEvent completion; 507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool commit_pending; 513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}; 527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)struct ThreadProxy::SchedulerStateRequest { 54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CompletionEvent completion; 55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<base::Value> state; 56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}; 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochscoped_ptr<Proxy> ThreadProxy::Create( 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LayerTreeHost* layer_tree_host, 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { 61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return make_scoped_ptr( 62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new ThreadProxy(layer_tree_host, impl_task_runner)).PassAs<Proxy>(); 63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ThreadProxy::ThreadProxy( 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LayerTreeHost* layer_tree_host, 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : Proxy(impl_task_runner), 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) animate_requested_(false), 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) commit_requested_(false), 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) commit_request_sent_to_impl_thread_(false), 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) created_offscreen_context_provider_(false), 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_(layer_tree_host), 74424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) started_(false), 75424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) textures_acquired_(true), 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) in_composite_and_readback_(false), 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) manage_tiles_pending_(false), 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) weak_factory_on_impl_thread_(this), 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) weak_factory_(this), 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) begin_frame_sent_to_main_thread_completion_event_on_impl_thread_(NULL), 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) readback_request_on_impl_thread_(NULL), 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) commit_completion_event_on_impl_thread_(NULL), 8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) completion_event_for_commit_held_on_tree_activation_(NULL), 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) texture_acquisition_completion_event_on_impl_thread_(NULL), 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) next_frame_is_newly_committed_frame_on_impl_thread_(false), 8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) throttle_frame_production_( 8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) layer_tree_host->settings().throttle_frame_production), 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) begin_frame_scheduling_enabled_( 89558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch layer_tree_host->settings().begin_frame_scheduling_enabled), 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) using_synchronous_renderer_compositor_( 91a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) layer_tree_host->settings().using_synchronous_renderer_compositor), 927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) inside_draw_(false), 937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch can_cancel_commit_(true), 941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) defer_commits_(false), 954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) input_throttled_until_commit_(false), 964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) renew_tree_priority_on_impl_thread_pending_(false), 974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) draw_duration_history_(kDurationHistorySize), 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) begin_frame_to_commit_duration_history_(kDurationHistorySize), 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) commit_to_activate_duration_history_(kDurationHistorySize) { 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsMainThread()); 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(layer_tree_host_); 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ThreadProxy::~ThreadProxy() { 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsMainThread()); 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!started_); 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool ThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::CompositeAndReadback"); 113ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch DCHECK(IsMainThread()); 114ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch DCHECK(layer_tree_host_); 115ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 116ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch if (defer_commits_) { 117ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch TRACE_EVENT0("cc", "CompositeAndReadback_DeferCommit"); 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) { 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized"); 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 12458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 12558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 12658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Perform a synchronous commit. 12758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) { 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked(this); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionEvent begin_frame_sent_to_main_thread_completion; 1301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 13158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) FROM_HERE, 13258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) base::Bind(&ThreadProxy::ForceCommitOnImplThread, 13358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) impl_thread_weak_ptr_, 13458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) &begin_frame_sent_to_main_thread_completion)); 1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) begin_frame_sent_to_main_thread_completion.Wait(); 13658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) in_composite_and_readback_ = true; 139558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch BeginFrameOnMainThread(scoped_ptr<BeginFrameAndCommitState>()); 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) in_composite_and_readback_ = false; 14158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Composite and readback requires a second commit to undo any changes 14358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // that it made. 14458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) can_cancel_commit_ = false; 1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Perform a synchronous readback. 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ReadbackRequest request; 148558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch request.rect = rect; 149558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch request.pixels = pixels; 150558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch { 151558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DebugScopedSetMainThreadBlocked main_thread_blocked(this); 15258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::RequestReadbackOnImplThread, 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_, 15658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) &request)); 1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) request.completion.Wait(); 15858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 15958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return request.success; 16090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::ForceCommitOnImplThread(CompletionEvent* completion) { 16358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::ForceCommitOnImplThread"); 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 1651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(!begin_frame_sent_to_main_thread_completion_event_on_impl_thread_); 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->SetNeedsForcedCommit(); 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (scheduler_on_impl_thread_->CommitPending()) { 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion->Signal(); 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 17258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 17358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ = completion; 17458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 1751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 17658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void ThreadProxy::RequestReadbackOnImplThread(ReadbackRequest* request) { 17758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(Proxy::IsImplThread()); 17858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(!readback_request_on_impl_thread_); 1791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!layer_tree_host_impl_) { 1801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) request->success = false; 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) request->completion.Signal(); 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) readback_request_on_impl_thread_ = request; 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->SetNeedsRedraw(); 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->SetNeedsForcedRedraw(); 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 190eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ThreadProxy::FinishAllRendering() { 191eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DCHECK(Proxy::IsMainThread()); 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!defer_commits_); 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Make sure all GL drawing is finished on the impl thread. 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked(this); 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionEvent completion; 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_, 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &completion)); 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion.Wait(); 203b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 204b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 205eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool ThreadProxy::IsStarted() const { 206eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DCHECK(Proxy::IsMainThread()); 207eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return started_; 208eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::SetLayerTreeHostClientReady() { 211b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady"); 212b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FROM_HERE, 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::SetLayerTreeHostClientReadyOnImplThread, 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_)); 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::SetLayerTreeHostClientReadyOnImplThread() { 219424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread"); 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->SetCanStart(); 221eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 222eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 223eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ThreadProxy::SetVisible(bool visible) { 224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TRACE_EVENT0("cc", "ThreadProxy::SetVisible"); 225eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DebugScopedSetMainThreadBlocked main_thread_blocked(this); 226eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CompletionEvent completion; 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::SetVisibleOnImplThread, 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_, 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &completion, 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) visible)); 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion.Wait(); 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 235424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::SetVisibleOnImplThread(CompletionEvent* completion, 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool visible) { 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::SetVisibleOnImplThread"); 239424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) layer_tree_host_impl_->SetVisible(visible); 240424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scheduler_on_impl_thread_->SetVisible(visible); 241424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 242424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) !scheduler_on_impl_thread_->WillDrawIfNeeded()); 243424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) completion->Signal(); 244424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 245c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 246c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ThreadProxy::DoCreateAndInitializeOutputSurface() { 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::DoCreateAndInitializeOutputSurface"); 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsMainThread()); 249c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<OutputSurface> output_surface = first_output_surface_.Pass(); 251c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!output_surface) 252c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) output_surface = layer_tree_host_->CreateOutputSurface(); 253c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 254c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RendererCapabilities capabilities; 255c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool success = !!output_surface; 256c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!success) { 257c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OnOutputSurfaceInitializeAttempted(false, capabilities); 258c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 259c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 260c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<ContextProvider> offscreen_context_provider; 2624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (created_offscreen_context_provider_) { 2634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) offscreen_context_provider = layer_tree_host_->client()-> 264868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) OffscreenContextProviderForCompositorThread(); 265c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) success = !!offscreen_context_provider.get(); 266c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!success) { 267c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OnOutputSurfaceInitializeAttempted(false, capabilities); 268c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 271c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 272c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) success = false; 273c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) { 274c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Make a blocking call to InitializeOutputSurfaceOnImplThread. The results 275c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // of that call are pushed into the success and capabilities local 276c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // variables. 277c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) CompletionEvent completion; 278c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked(this); 279eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 280eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Proxy::ImplThreadTaskRunner()->PostTask( 281c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FROM_HERE, 282c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread, 283c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) impl_thread_weak_ptr_, 284c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) &completion, 285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Passed(&output_surface), 286c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) offscreen_context_provider, 287c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) &success, 288c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) &capabilities)); 289c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) completion.Wait(); 2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OnOutputSurfaceInitializeAttempted(success, capabilities); 293c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 294c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ThreadProxy::OnOutputSurfaceInitializeAttempted( 296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool success, 297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const RendererCapabilities& capabilities) { 298c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(IsMainThread()); 299c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(layer_tree_host_); 300c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (success) { 302c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) renderer_capabilities_main_thread_copy_ = capabilities; 303c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 304c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 305c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) LayerTreeHost::CreateResult result = 306c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); 307c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (result == LayerTreeHost::CreateFailedButTryAgain) { 308eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!output_surface_creation_callback_.callback().is_null()) { 309eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Proxy::MainThreadTaskRunner()->PostTask( 310c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FROM_HERE, output_surface_creation_callback_.callback()); 311c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 312c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } else { 313c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) output_surface_creation_callback_.Cancel(); 3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 316558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 317558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochvoid ThreadProxy::SendCommitRequestToImplThreadIfNeeded() { 318558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DCHECK(IsMainThread()); 319558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch if (commit_request_sent_to_impl_thread_) 320558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch return; 321558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch commit_request_sent_to_impl_thread_ = true; 322558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch Proxy::ImplThreadTaskRunner()->PostTask( 323558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch FROM_HERE, 324558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, 325558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch impl_thread_weak_ptr_)); 326558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch} 3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 328c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { 329c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(IsMainThread()); 3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!layer_tree_host_->output_surface_lost()); 3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return renderer_capabilities_main_thread_copy_; 3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::SetNeedsAnimate() { 3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsMainThread()); 3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (animate_requested_) 3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimate"); 340558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch animate_requested_ = true; 341558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch can_cancel_commit_ = false; 342558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch SendCommitRequestToImplThreadIfNeeded(); 3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 344558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 345558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochvoid ThreadProxy::SetNeedsUpdateLayers() { 3461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(IsMainThread()); 3471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SendCommitRequestToImplThreadIfNeeded(); 3481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 3491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void ThreadProxy::SetNeedsCommit() { 351558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DCHECK(IsMainThread()); 3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Unconditionally set here to handle SetNeedsCommit calls during a commit. 3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) can_cancel_commit_ = false; 3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (commit_requested_) 356558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch return; 357558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommit"); 358558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch commit_requested_ = true; 3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendCommitRequestToImplThreadIfNeeded(); 3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::DidLoseOutputSurfaceOnImplThread() { 364558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DCHECK(IsImplThread()); 3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); 3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::CheckOutputSurfaceStatusOnImplThread, 3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_)); 37068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::CheckOutputSurfaceStatusOnImplThread() { 3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::CheckOutputSurfaceStatusOnImplThread"); 3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!layer_tree_host_impl_->IsContextLost()) 3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_ 378424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) ->resource_provider()->offscreen_context_provider()) 379424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) offscreen_contexts->VerifyContexts(); 3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->DidLoseOutputSurface(); 3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::OnSwapBuffersCompleteOnImplThread() { 3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread"); 3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::MainThreadTaskRunner()->PostTask( 387eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FROM_HERE, 388eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); 3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { 3928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DCHECK(IsImplThread()); 393c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", 3948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) "enable", enable); 3957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) layer_tree_host_impl_->SetNeedsBeginFrame(enable); 3961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 39768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 398c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ThreadProxy::BeginFrameOnImplThread(const BeginFrameArgs& args) { 399c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(IsImplThread()); 4001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread"); 401c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scheduler_on_impl_thread_->BeginFrame(args); 4021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 40368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 40468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { 40568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DCHECK(IsImplThread()); 40668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) TRACE_EVENT1( 40768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 4088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) scheduler_on_impl_thread_->SetCanDraw(can_draw); 40968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 41068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) !scheduler_on_impl_thread_->WillDrawIfNeeded()); 4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::OnHasPendingTreeStateChanged(bool has_pending_tree) { 4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT1("cc", "ThreadProxy::OnHasPendingTreeStateChanged", 416424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) "has_pending_tree", has_pending_tree); 4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->SetHasPendingTree(has_pending_tree); 4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 419424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 420424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void ThreadProxy::SetNeedsCommitOnImplThread() { 421424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(IsImplThread()); 4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); 4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->SetNeedsCommit(); 4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( 4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<AnimationEventsVector> events, 4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Time wall_clock_time) { 4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", 4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); 4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::MainThreadTaskRunner()->PostTask( 4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::SetAnimationEvents, 4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) main_thread_weak_ptr_, 436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::Passed(&events), 437eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wall_clock_time)); 438eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 439eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 440eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool ThreadProxy::ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, 441eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch int priority_cutoff) { 4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!layer_tree_host_->contents_texture_manager()) 4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool reduce_result = layer_tree_host_->contents_texture_manager()-> 4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ReduceMemoryOnImplThread(limit_bytes, 4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) priority_cutoff, 4504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) layer_tree_host_impl_->resource_provider()); 4514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (!reduce_result) 4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The texture upload queue may reference textures that were just purged, 4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // clear them from the queue. 4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (current_resource_update_controller_on_impl_thread_) { 4572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_resource_update_controller_on_impl_thread_-> 4582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DiscardUploadsToEvictedResources(); 4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return true; 4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::ReduceWastedContentsTextureMemoryOnImplThread() { 4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!layer_tree_host_->contents_texture_manager()) 4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->contents_texture_manager()->ReduceWastedMemoryOnImplThread( 4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->resource_provider()); 4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::SendManagedMemoryStats() { 4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!layer_tree_host_impl_) 4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!layer_tree_host_->contents_texture_manager()) 4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If we are using impl-side painting, then SendManagedMemoryStats is called 4812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // directly after the tile manager's manage function, and doesn't need to 4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // interact with main thread's layer tree. 4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_->settings().impl_side_painting) 4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->SendManagedMemoryStats( 4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->contents_texture_manager()->MemoryVisibleBytes(), 4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->contents_texture_manager()-> 4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MemoryVisibleAndNearbyBytes(), 4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->contents_texture_manager()->MemoryUseBytes()); 491c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool ThreadProxy::IsInsideDraw() { return inside_draw_; } 494eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 495eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) { 496eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DCHECK(IsMainThread()); 497eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedraw"); 498eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Proxy::ImplThreadTaskRunner()->PostTask( 4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::SetNeedsRedrawRectOnImplThread, 501424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) impl_thread_weak_ptr_, 502424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) damage_rect)); 503424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 504424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 505424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void ThreadProxy::SetDeferCommits(bool defer_commits) { 506424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(IsMainThread()); 5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK_NE(defer_commits_, defer_commits); 5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) defer_commits_ = defer_commits; 5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (defer_commits_) 5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this); 5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this); 5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!defer_commits_ && pending_deferred_commit_) 5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::MainThreadTaskRunner()->PostTask( 5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 518eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::Bind(&ThreadProxy::BeginFrameOnMainThread, 519eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch main_thread_weak_ptr_, 5201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::Passed(&pending_deferred_commit_))); 5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool ThreadProxy::CommitRequested() const { 5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsMainThread()); 5252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return commit_requested_; 5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::SetNeedsRedrawOnImplThread() { 5292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 5301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedrawOnImplThread"); 5311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scheduler_on_impl_thread_->SetNeedsRedraw(); 5321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 5331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void ThreadProxy::SetNeedsRedrawRectOnImplThread(gfx::Rect damage_rect) { 5352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->SetViewportDamage(damage_rect); 5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetNeedsRedrawOnImplThread(); 5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::DidSwapUseIncompleteTileOnImplThread() { 541d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) DCHECK(IsImplThread()); 542d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::DidSwapUseIncompleteTileOnImplThread"); 543d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) scheduler_on_impl_thread_->DidSwapUseIncompleteTile(); 544d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 545d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 546c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ThreadProxy::DidInitializeVisibleTileOnImplThread() { 547c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(IsImplThread()); 548c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::DidInitializeVisibleTileOnImplThread"); 549c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scheduler_on_impl_thread_->SetNeedsRedraw(); 550c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 551c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 55258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void ThreadProxy::MainThreadHasStoppedFlinging() { 55358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(IsMainThread()); 5542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 55558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) FROM_HERE, 55658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) base::Bind(&ThreadProxy::MainThreadHasStoppedFlingingOnImplThread, 55758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) impl_thread_weak_ptr_)); 55858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 55958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 56058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void ThreadProxy::MainThreadHasStoppedFlingingOnImplThread() { 56158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(IsImplThread()); 56258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) layer_tree_host_impl_->MainThreadHasStoppedFlinging(); 5632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::NotifyInputThrottledUntilCommit() { 5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsMainThread()); 5672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::SetInputThrottledUntilCommitOnImplThread, 5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_, 5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) true)); 572c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 573eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 574eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ThreadProxy::SetInputThrottledUntilCommitOnImplThread( 575c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool is_throttled) { 576c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(IsImplThread()); 577c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_throttled == input_throttled_until_commit_) 578c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 579c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) input_throttled_until_commit_ = is_throttled; 580c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenewTreePriority(); 58190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) { 584a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DCHECK(IsMainThread()); 585a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DCHECK(Proxy::HasImplThread()); 586a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DCHECK(first_output_surface); 587a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Create LayerTreeHostImpl. 588a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked(this); 589a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) CompletionEvent completion; 590a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 591a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) FROM_HERE, 592a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::Bind(&ThreadProxy::InitializeImplOnImplThread, 593a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::Unretained(this), 594a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) &completion)); 595a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) completion.Wait(); 596a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 597a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); 598a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) first_output_surface_ = first_output_surface.Pass(); 599a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 600a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) started_ = true; 601a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 602c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::Stop() { 604eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TRACE_EVENT0("cc", "ThreadProxy::Stop"); 605c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(IsMainThread()); 606424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(started_); 6072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Synchronously finishes pending GL operations and deletes the impl. 6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The two steps are done as separate post tasks, so that tasks posted 610eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // by the GL implementation due to the Finish can be executed by the 611eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // renderer before shutting it down. 6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked(this); 61490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionEvent completion; 6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 618c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Bind(&ThreadProxy::FinishGLOnImplThread, 6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_, 6202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &completion)); 6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion.Wait(); 6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked(this); 6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionEvent completion; 6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 628c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FROM_HERE, 629c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Bind(&ThreadProxy::LayerTreeHostClosedOnImplThread, 630c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) impl_thread_weak_ptr_, 631c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) &completion)); 632c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) completion.Wait(); 633c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 634c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 635c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) weak_factory_.InvalidateWeakPtrs(); 636eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 637eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DCHECK(!layer_tree_host_impl_.get()); // verify that the impl deleted. 638c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) layer_tree_host_ = NULL; 639c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) started_ = false; 640c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 641c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 642c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ThreadProxy::ForceSerializeOnSwapBuffers() { 6432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked(this); 6442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionEvent completion; 6452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 647eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::Bind(&ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread, 648eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch impl_thread_weak_ptr_, 6492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &completion)); 6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion.Wait(); 6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread( 6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionEvent* completion) { 6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_impl_->renderer()) 6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->renderer()->DoNoOp(); 6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion->Signal(); 6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::FinishAllRenderingOnImplThread(CompletionEvent* completion) { 6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); 6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->FinishAllRendering(); 6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion->Signal(); 665eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 666eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::ScheduledActionSendBeginFrameToMainThread() { 6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread"); 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<BeginFrameAndCommitState> begin_frame_state( 6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new BeginFrameAndCommitState); 6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) begin_frame_state->monotonic_frame_begin_time = 6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->CurrentPhysicalTimeTicks(); 6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) begin_frame_state->scroll_info = 6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->ProcessScrollDeltas(); 675c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!layer_tree_host_impl_->settings().impl_side_painting) { 6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); 6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) begin_frame_state->memory_allocation_limit_bytes = 6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->memory_allocation_limit_bytes(); 6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::MainThreadTaskRunner()->PostTask( 6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::BeginFrameOnMainThread, 6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) main_thread_weak_ptr_, 6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Passed(&begin_frame_state))); 6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) { 6888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal(); 6891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ = NULL; 6901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 6911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) begin_frame_sent_to_main_thread_time_ = base::TimeTicks::HighResNow(); 6927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 6931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 69490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void ThreadProxy::BeginFrameOnMainThread( 695eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<BeginFrameAndCommitState> begin_frame_state) { 696eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnMainThread"); 697eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DCHECK(IsMainThread()); 698eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 6991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!layer_tree_host_) 7002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 7011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 70268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (defer_commits_) { 7031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) pending_deferred_commit_ = begin_frame_state.Pass(); 70458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) layer_tree_host_->DidDeferCommit(); 705eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TRACE_EVENT0("cc", "EarlyOut_DeferCommits"); 706eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 7071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 70890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Do not notify the impl thread of commit requests that occur during 7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the apply/animate/layout part of the BeginFrameAndCommit process since 7111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // those commit requests will get painted immediately. Once we have done 7121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // the paint, commit_requested_ will be set to false to allow new commit 7131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // requests to be scheduled. 7142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) commit_requested_ = true; 7151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) commit_request_sent_to_impl_thread_ = true; 7162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // On the other hand, the AnimationRequested flag needs to be cleared 7181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // here so that any animation requests generated by the apply or animate 7191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // callbacks will trigger another frame. 7201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) animate_requested_ = false; 7212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!in_composite_and_readback_ && !layer_tree_host_->visible()) { 7232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) commit_requested_ = false; 7242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) commit_request_sent_to_impl_thread_ = false; 7252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "EarlyOut_NotVisible"); 7271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool did_handle = false; 7282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 7292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 7302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread, 7312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_, 7322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) did_handle)); 7332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 7341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 7352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (begin_frame_state) 7372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->ApplyScrollAndScale(*begin_frame_state->scroll_info); 7382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->WillBeginFrame(); 7402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (begin_frame_state) { 7422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->UpdateClientAnimations( 7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) begin_frame_state->monotonic_frame_begin_time); 7442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->AnimateLayers( 7452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) begin_frame_state->monotonic_frame_begin_time); 7462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Unlink any backings that the impl thread has evicted, so that we know to 7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // re-paint them in UpdateLayers. 7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_->contents_texture_manager()) { 751558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch layer_tree_host_->contents_texture_manager()-> 752eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UnlinkAndClearEvictedBackings(); 753eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 7541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 755558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch layer_tree_host_->Layout(); 756558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 7572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Clear the commit flag after updating animations and layout here --- objects 7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // that only layout when painted will trigger another SetNeedsCommit inside 7592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // UpdateLayers. 7601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) commit_requested_ = false; 7611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) commit_request_sent_to_impl_thread_ = false; 762558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch bool can_cancel_this_commit = 7631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) can_cancel_commit_ && !in_composite_and_readback_; 7642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) can_cancel_commit_ = true; 7651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 766b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) scoped_ptr<ResourceUpdateQueue> queue = 7671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) make_scoped_ptr(new ResourceUpdateQueue); 768b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool updated = layer_tree_host_->UpdateLayers( 7691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) queue.get(), 7702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) begin_frame_state ? begin_frame_state->memory_allocation_limit_bytes 7712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : 0u); 7722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Once single buffered layers are committed, they cannot be modified until 7742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // they are drawn by the impl thread. 7752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) textures_acquired_ = false; 7762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 77768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) layer_tree_host_->WillCommit(); 7781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 77968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (!updated && can_cancel_this_commit) { 7801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TRACE_EVENT0("cc", "EarlyOut_NoUpdates"); 78168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) bool did_handle = true; 7821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 78368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) FROM_HERE, 7842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread, 7852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_, 78658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) did_handle)); 78758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 7881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Although the commit is internally aborted, this is because it has been 7891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // detected to be a no-op. From the perspective of an embedder, this commit 7901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // went through, and input should no longer be throttled, etc. 79158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) layer_tree_host_->CommitComplete(); 79258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) layer_tree_host_->DidBeginFrame(); 79358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return; 7942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 7952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Before calling animate, we set animate_requested_ to false. If it is true 7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // now, it means SetNeedAnimate was called again, but during a state when 7982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // commit_request_sent_to_impl_thread_ = true. We need to force that call to 7992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // happen again now so that the commit request is sent to the impl thread. 8002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (animate_requested_) { 801558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // Forces SetNeedsAnimate to consider posting a commit task. 80258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) animate_requested_ = false; 80358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) SetNeedsAnimate(); 80458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 805558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 8062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<cc::ContextProvider> offscreen_context_provider; 8072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (renderer_capabilities_main_thread_copy_.using_offscreen_context3d && 8082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->needs_offscreen_context()) { 80968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) offscreen_context_provider = layer_tree_host_->client()-> 81068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) OffscreenContextProviderForCompositorThread(); 8112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (offscreen_context_provider.get()) 8122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) created_offscreen_context_provider_ = true; 8132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notify the impl thread that the main thread is ready to commit. This will 8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // begin the commit process, which is blocking from the main thread's 817558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // point of view, but asynchronously performed on the impl thread, 818558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // coordinated by the Scheduler. 819558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch { 820558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch TRACE_EVENT_BEGIN0("cc", "ThreadProxy::BeginFrameOnMainThread::commit"); 821558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 822558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DebugScopedSetMainThreadBlocked main_thread_blocked(this); 8231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 824558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch RenderingStatsInstrumentation* stats_instrumentation = 825558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch layer_tree_host_->rendering_stats_instrumentation(); 826558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch base::TimeTicks start_time = stats_instrumentation->StartRecording(); 827558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 828558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch CompletionEvent completion; 829558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch Proxy::ImplThreadTaskRunner()->PostTask( 830558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch FROM_HERE, 8311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::Bind(&ThreadProxy::StartCommitOnImplThread, 832558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch impl_thread_weak_ptr_, 833558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch &completion, 834558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch queue.release(), 835558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch offscreen_context_provider)); 836558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch completion.Wait(); 837558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 838558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); 8392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) stats_instrumentation->AddCommit(duration); 8402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT_END1("cc", "ThreadProxy::BeginFrameOnMainThread::commit", 8412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "data", stats_instrumentation-> 8422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetMainThreadRenderingStats().AsTraceableData()); 8432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) stats_instrumentation->AccumulateAndClearMainThreadStats(); 8442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->CommitComplete(); 8472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->DidBeginFrame(); 8484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 8494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 850868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ThreadProxy::StartCommitOnImplThread( 8512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionEvent* completion, 8522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ResourceUpdateQueue* raw_queue, 8532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<cc::ContextProvider> offscreen_context_provider) { 85490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<ResourceUpdateQueue> queue(raw_queue); 8552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); 8572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!commit_completion_event_on_impl_thread_); 8582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread() && IsMainThreadBlocked()); 8591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(scheduler_on_impl_thread_); 8602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(scheduler_on_impl_thread_->CommitPending()); 8612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!layer_tree_host_impl_) { 863424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); 864424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) completion->Signal(); 865424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return; 866424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 867424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 8682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (offscreen_context_provider.get()) 869eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch offscreen_context_provider->BindToCurrentThread(); 870eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch layer_tree_host_impl_->resource_provider()-> 87190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) set_offscreen_context_provider(offscreen_context_provider); 8722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_->contents_texture_manager()) { 8742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_->contents_texture_manager()-> 8752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LinkedEvictedBackingsExist()) { 8762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Clear any uploads we were making to textures linked to evicted 8772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // resources 8784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) queue->ClearUploadsToEvictedResources(); 8794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Some textures in the layer tree are invalid. Kick off another commit 8804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // to fill them again. 8814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) SetNeedsCommitOnImplThread(); 8823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->contents_texture_manager()-> 8852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PushTexturePrioritiesToBackings(); 8861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 8872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) commit_completion_event_on_impl_thread_ = completion; 88990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) current_resource_update_controller_on_impl_thread_ = 8902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ResourceUpdateController::Create( 8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) this, 8922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner(), 8932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) queue.Pass(), 8942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->resource_provider()); 89590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) current_resource_update_controller_on_impl_thread_->PerformMoreUpdates( 8962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->AnticipatedDrawTime()); 8972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 8982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread(bool did_handle) { 9002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread"); 9012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 9022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(scheduler_on_impl_thread_); 9032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(scheduler_on_impl_thread_->CommitPending()); 9042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!layer_tree_host_impl_->pending_tree()); 9052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If the begin frame data was handled, then scroll and scale set was applied 907868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // by the main thread, so the active tree needs to be updated as if these sent 9082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // values were applied and committed. 909424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (did_handle) { 910424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) layer_tree_host_impl_->active_tree() 9112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ->ApplySentScrollAndScaleDeltasFromAbortedCommit(); 912868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) layer_tree_host_impl_->active_tree()->ResetContentsTexturesPurged(); 913868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SetInputThrottledUntilCommitOnImplThread(false); 914868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 915868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scheduler_on_impl_thread_->BeginFrameAbortedByMainThread(did_handle); 916868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 917868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 918868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ThreadProxy::ScheduledActionCommit() { 919868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit"); 920868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DCHECK(IsImplThread()); 921868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DCHECK(commit_completion_event_on_impl_thread_); 9222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(current_resource_update_controller_on_impl_thread_); 923868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 924868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Complete all remaining texture updates. 925868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) current_resource_update_controller_on_impl_thread_->Finalize(); 9262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_resource_update_controller_on_impl_thread_.reset(); 9272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 928eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch layer_tree_host_impl_->BeginCommit(); 929eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); 930eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); 931eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch layer_tree_host_impl_->CommitComplete(); 932eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 933eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SetInputThrottledUntilCommitOnImplThread(false); 934eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 935eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 9362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) !scheduler_on_impl_thread_->WillDrawIfNeeded()); 9372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) next_frame_is_newly_committed_frame_on_impl_thread_ = true; 9391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 9402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_->settings().impl_side_painting && 9412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_->BlocksPendingCommit() && 9422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->pending_tree()) { 943558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // For some layer types in impl-side painting, the commit is held until 944558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // the pending tree is activated. It's also possible that the 945558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // pending tree has already activated if there was no work to be done. 946558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); 947558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch completion_event_for_commit_held_on_tree_activation_ = 948a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) commit_completion_event_on_impl_thread_; 9493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) commit_completion_event_on_impl_thread_ = NULL; 9503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } else { 9513240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch commit_completion_event_on_impl_thread_->Signal(); 952a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) commit_completion_event_on_impl_thread_ = NULL; 953a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) } 9548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 9552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) commit_complete_time_ = base::TimeTicks::HighResNow(); 9562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) begin_frame_to_commit_duration_history_.InsertSample( 9572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) commit_complete_time_ - begin_frame_sent_to_main_thread_time_); 9582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // SetVisible kicks off the next scheduler action, so this must be last. 9602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); 961eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 962eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 963eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ThreadProxy::ScheduledActionUpdateVisibleTiles() { 964eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DCHECK(IsImplThread()); 965eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionUpdateVisibleTiles"); 9662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->UpdateVisibleTiles(); 967424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 9682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() { 9702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 9712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded"); 972424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); 9732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 974a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 975a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { 976424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(IsImplThread()); 977c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation"); 9782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::MainThreadTaskRunner()->PostTask( 9792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 9802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, 981424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) main_thread_weak_ptr_)); 9822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 9847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)ScheduledActionDrawAndSwapResult 985c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { 9862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT1( 9872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "cc", "ThreadProxy::ScheduledActionDrawAndSwap", "forced", forced_draw); 9882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScheduledActionDrawAndSwapResult result; 9902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result.did_draw = false; 9912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result.did_swap = false; 9922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 9932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(layer_tree_host_impl_.get()); 994424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (!layer_tree_host_impl_) 995424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return result; 9967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 9971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(layer_tree_host_impl_->renderer()); 9981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!layer_tree_host_impl_->renderer()) 9997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return result; 10002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeTicks monotonic_time = 10022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->CurrentFrameTimeTicks(); 10032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime(); 1004ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 10052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(enne): This should probably happen post-animate. 1006ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch if (layer_tree_host_impl_->pending_tree()) { 1007ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); 10082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_impl_->pending_tree()) 10092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); 1010424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 10112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time); 1012424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false); 1013424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 10142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeTicks start_time = base::TimeTicks::HighResNow(); 10152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); 1016c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::AutoReset<bool> mark_inside(&inside_draw_, true); 10172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // This method is called on a forced draw, regardless of whether we are able 1019eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // to produce a frame, as the calling site on main thread is blocked until its 1020eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // request completes, and we signal completion here. If CanDraw() is false, we 1021c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // will indicate success=false to the caller, but we must still signal 1022c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // completion to avoid deadlock. 10232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // We guard PrepareToDraw() with CanDraw() because it always returns a valid 102558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // frame, so can only be used when such a frame is possible. Since 102658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on 102758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // CanDraw() as well. 102858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 102958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) bool drawing_for_readback = !!readback_request_on_impl_thread_; 10302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); 10312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 103258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) LayerTreeHostImpl::FrameData frame; 10332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool draw_frame = false; 10342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool start_ready_animations = true; 10352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_impl_->CanDraw() && 10372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (!drawing_for_readback || can_do_readback)) { 10382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If it is for a readback, make sure we draw the portion being read back. 10392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect readback_rect; 10402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (drawing_for_readback) 10412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) readback_rect = readback_request_on_impl_thread_->rect; 104268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 104368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Do not start animations if we skip drawing the frame to avoid 104468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // checkerboarding. 104568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) || 104668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) forced_draw) 1047c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) draw_frame = true; 1048c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) else 1049c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) start_ready_animations = false; 10504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 10514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 10524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (draw_frame) { 10534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) layer_tree_host_impl_->DrawLayers( 10542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &frame, 10557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scheduler_on_impl_thread_->LastBeginFrameOnImplThreadTime()); 10562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result.did_draw = true; 10572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1058c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) layer_tree_host_impl_->DidDrawAllLayers(frame); 10592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); 10612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1062c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Check for a pending CompositeAndReadback. 10632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (readback_request_on_impl_thread_) { 1064c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) readback_request_on_impl_thread_->success = false; 1065c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (draw_frame) { 1066c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) layer_tree_host_impl_->Readback(readback_request_on_impl_thread_->pixels, 106758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) readback_request_on_impl_thread_->rect); 106858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) readback_request_on_impl_thread_->success = 1069b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) !layer_tree_host_impl_->IsContextLost(); 10702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 10712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) readback_request_on_impl_thread_->completion.Signal(); 1072c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) readback_request_on_impl_thread_ = NULL; 1073c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } else if (draw_frame) { 1074b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) result.did_swap = layer_tree_host_impl_->SwapBuffers(frame); 1075b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1076b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) if (frame.contains_incomplete_tile) 1077b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) DidSwapUseIncompleteTileOnImplThread(); 1078b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) } 1079b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1080b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Tell the main thread that the the newly-commited frame was drawn. 1081c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (next_frame_is_newly_committed_frame_on_impl_thread_) { 1082c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) next_frame_is_newly_committed_frame_on_impl_thread_ = false; 1083c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Proxy::MainThreadTaskRunner()->PostTask( 1084c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FROM_HERE, 1085c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); 10862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 10872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (draw_frame) { 10898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckOutputSurfaceStatusOnImplThread(); 1090c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 10912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeDelta draw_duration = base::TimeTicks::HighResNow() - start_time; 10922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) draw_duration_history_.InsertSample(draw_duration); 109368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::TimeDelta draw_duration_overestimate; 109468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::TimeDelta draw_duration_underestimate; 1095c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (draw_duration > draw_duration_estimate) 1096c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) draw_duration_underestimate = draw_duration - draw_duration_estimate; 10972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 109858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) draw_duration_overestimate = draw_duration_estimate - draw_duration; 109958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", 110058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) draw_duration, 110158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) base::TimeDelta::FromMilliseconds(1), 11022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeDelta::FromMilliseconds(100), 11032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 50); 110458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", 11052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) draw_duration_underestimate, 110658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) base::TimeDelta::FromMilliseconds(1), 11072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeDelta::FromMilliseconds(100), 11082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 50); 11092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", 111058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) draw_duration_overestimate, 1111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::TimeDelta::FromMilliseconds(1), 11122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeDelta::FromMilliseconds(100), 111358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 50); 111458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 111558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 111658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Update the tile state after drawing. This prevents manage tiles from 111758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // being in the critical path for getting things on screen, but still 11182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // makes sure that tile state is updated on a semi-regular basis. 11192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_impl_->settings().impl_side_painting) 11202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->ManageTiles(); 11212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return result; 1123eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 1124eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 11252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::AcquireLayerTextures() { 11262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called when the main thread needs to modify a layer texture that is used 11272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // directly by the compositor. 11287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // This method will block until the next compositor draw if there is a 11292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // previously committed frame that is still undrawn. This is necessary to 11302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ensure that the main thread does not monopolize access to the textures. 11317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DCHECK(IsMainThread()); 11327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (textures_acquired_) 11347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return; 11357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::AcquireLayerTextures"); 11377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked(this); 11387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CompletionEvent completion; 11397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 11407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) FROM_HERE, 11417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::Bind(&ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread, 11427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) impl_thread_weak_ptr_, 11437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) &completion)); 11447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Block until it is safe to write to layer textures from the main thread. 11457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) completion.Wait(); 11467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) textures_acquired_ = true; 11487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) can_cancel_commit_ = false; 11497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 11507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread( 11527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CompletionEvent* completion) { 11537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DCHECK(IsImplThread()); 11547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DCHECK(!texture_acquisition_completion_event_on_impl_thread_); 11557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) texture_acquisition_completion_event_on_impl_thread_ = completion; 11572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->SetMainThreadNeedsLayerTextures(); 11582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::ScheduledActionAcquireLayerTexturesForMainThread() { 11612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(texture_acquisition_completion_event_on_impl_thread_); 11622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) texture_acquisition_completion_event_on_impl_thread_->Signal(); 11632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) texture_acquisition_completion_event_on_impl_thread_ = NULL; 11642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ScheduledActionDrawAndSwapResult 11672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { 11682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return ScheduledActionDrawAndSwapInternal(false); 11692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ScheduledActionDrawAndSwapResult 11722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ThreadProxy::ScheduledActionDrawAndSwapForced() { 1173eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return ScheduledActionDrawAndSwapInternal(true); 1174eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 11752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { 11772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (current_resource_update_controller_on_impl_thread_) 11782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_resource_update_controller_on_impl_thread_ 11792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ->PerformMoreUpdates(time); 11802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); 11812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1182558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 11832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)base::TimeDelta ThreadProxy::DrawDurationEstimate() { 11842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeDelta historical_estimate = 11852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); 11862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeDelta padding = base::TimeDelta::FromMicroseconds( 11872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) kDrawDurationEstimatePaddingInMicroseconds); 11882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return historical_estimate + padding; 11892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)base::TimeDelta ThreadProxy::BeginFrameToCommitDurationEstimate() { 11922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return begin_frame_to_commit_duration_history_.Percentile( 11932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) kCommitAndActivationDurationEstimationPercentile); 11942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() { 11972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return commit_to_activate_duration_history_.Percentile( 11982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) kCommitAndActivationDurationEstimationPercentile); 11992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1200d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 1201d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ThreadProxy::ReadyToFinalizeTextureUpdates() { 1202d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) DCHECK(IsImplThread()); 1203d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) scheduler_on_impl_thread_->FinishCommit(); 1204d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 1205d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 120658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void ThreadProxy::DidCommitAndDrawFrame() { 120758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(IsMainThread()); 120858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (!layer_tree_host_) 120958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return; 121058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) layer_tree_host_->DidCommitAndDrawFrame(); 121158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 121258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 121358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void ThreadProxy::DidCompleteSwapBuffers() { 121458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(IsMainThread()); 121558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (!layer_tree_host_) 121658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return; 121758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) layer_tree_host_->DidCompleteSwapBuffers(); 121858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 121958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 122058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events, 122158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) base::Time wall_clock_time) { 12222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); 12232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsMainThread()); 122458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (!layer_tree_host_) 122558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return; 122658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) layer_tree_host_->SetAnimationEvents(events.Pass(), wall_clock_time); 122758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 122858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 122958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void ThreadProxy::CreateAndInitializeOutputSurface() { 123058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::CreateAndInitializeOutputSurface"); 12312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsMainThread()); 12322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Check that output surface has not been recreated by CompositeAndReadback 12342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // after this task is posted but before it is run. 123568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) bool has_initialized_output_surface_on_impl_thread = true; 123668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) { 12372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionEvent completion; 12382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 12397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) FROM_HERE, 12407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::Bind(&ThreadProxy::HasInitializedOutputSurfaceOnImplThread, 12417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) impl_thread_weak_ptr_, 12427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) &completion, 12437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) &has_initialized_output_surface_on_impl_thread)); 12447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) completion.Wait(); 12457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 12467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (has_initialized_output_surface_on_impl_thread) 12478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return; 12481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 12497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch layer_tree_host_->DidLoseOutputSurface(); 12507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch output_surface_creation_callback_.Reset(base::Bind( 12517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch &ThreadProxy::DoCreateAndInitializeOutputSurface, 12527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch base::Unretained(this))); 12537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch output_surface_creation_callback_.callback().Run(); 12547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 12557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 12567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid ThreadProxy::HasInitializedOutputSurfaceOnImplThread( 12578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CompletionEvent* completion, 12588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) bool* has_initialized_output_surface) { 12591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(IsImplThread()); 126068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) *has_initialized_output_surface = 126168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) scheduler_on_impl_thread_->HasInitializedOutputSurface(); 126268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) completion->Signal(); 126368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 126468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 12658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { 12668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); 12678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DCHECK(IsImplThread()); 12688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); 12692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const LayerTreeSettings& settings = layer_tree_host_->settings(); 12702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SchedulerSettings scheduler_settings; 127190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scheduler_settings.impl_side_painting = settings.impl_side_painting; 12722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_settings.timeout_and_draw_when_animation_checkerboards = 12732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) settings.timeout_and_draw_when_animation_checkerboards; 12742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_settings.using_synchronous_renderer_compositor = 12752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) settings.using_synchronous_renderer_compositor; 12762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_settings.throttle_frame_production = 12772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) settings.throttle_frame_production; 12782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_ = Scheduler::Create(this, scheduler_settings); 12792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); 12802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr(); 12822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion->Signal(); 12832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 12842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::InitializeOutputSurfaceOnImplThread( 12862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionEvent* completion, 12872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<OutputSurface> output_surface, 12882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<ContextProvider> offscreen_context_provider, 12892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool* success, 12902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RendererCapabilities* capabilities) { 12912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread"); 12922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 12932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsMainThreadBlocked()); 12942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(success); 12952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(capabilities); 12962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) layer_tree_host_->DeleteContentsTexturesOnImplThread( 1298c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) layer_tree_host_impl_->resource_provider()); 12992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1300c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) *success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); 1301c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1302c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (*success) { 1303c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) *capabilities = layer_tree_host_impl_->GetRendererCapabilities(); 1304c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); 1305c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1306eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1307eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DidTryInitializeRendererOnImplThread(*success, offscreen_context_provider); 1308c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1309c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) completion->Signal(); 1310c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1311c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1312c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ThreadProxy::DidTryInitializeRendererOnImplThread( 1313c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool success, 1314c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_refptr<ContextProvider> offscreen_context_provider) { 1315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(IsImplThread()); 1316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(!inside_draw_); 13172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1318c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (offscreen_context_provider.get()) 1319c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) offscreen_context_provider->BindToCurrentThread(); 1320c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1321c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (success) { 13222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->resource_provider()-> 13232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) set_offscreen_context_provider(offscreen_context_provider); 1324c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } else if (offscreen_context_provider.get()) { 1325c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) offscreen_context_provider->VerifyContexts(); 1326c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1327c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1328c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1329c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ThreadProxy::FinishGLOnImplThread(CompletionEvent* completion) { 1330c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::FinishGLOnImplThread"); 13312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 13322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_impl_->resource_provider()) 133390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) layer_tree_host_impl_->resource_provider()->Finish(); 13342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion->Signal(); 13352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1337c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { 13382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); 133968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DCHECK(IsImplThread()); 134068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) layer_tree_host_->DeleteContentsTexturesOnImplThread( 1341c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) layer_tree_host_impl_->resource_provider()); 1342c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) layer_tree_host_impl_->SetNeedsBeginFrame(false); 1343c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scheduler_on_impl_thread_.reset(); 134458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) layer_tree_host_impl_.reset(); 134558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) weak_factory_on_impl_thread_.InvalidateWeakPtrs(); 13467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) completion->Signal(); 13477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 1348eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1349eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochsize_t ThreadProxy::MaxPartialTextureUpdates() const { 13507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return ResourceUpdateController::MaxPartialTextureUpdates(); 13512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState() 13542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : memory_allocation_limit_bytes(0) {} 13552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ThreadProxy::BeginFrameAndCommitState::~BeginFrameAndCommitState() {} 13572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)scoped_ptr<base::Value> ThreadProxy::AsValue() const { 1359c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 1360c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1361c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) CompletionEvent completion; 13622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 1363c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked( 13642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const_cast<ThreadProxy*>(this)); 1365c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 1366c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FROM_HERE, 1367c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Bind(&ThreadProxy::AsValueOnImplThread, 1368c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) impl_thread_weak_ptr_, 1369c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) &completion, 1370c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) state.get())); 1371c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) completion.Wait(); 1372c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1373c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return state.PassAs<base::Value>(); 1374c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 13752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1376c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ThreadProxy::AsValueOnImplThread(CompletionEvent* completion, 1377424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) base::DictionaryValue* state) const { 1378424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) state->Set("layer_tree_host_impl", 1379424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) layer_tree_host_impl_->AsValue().release()); 1380424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) completion->Signal(); 13812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1383424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)bool ThreadProxy::CommitPendingForTesting() { 1384424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(IsMainThread()); 1385868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CommitPendingRequest commit_pending_request; 13862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 13872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked(this); 13882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 1389c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FROM_HERE, 1390c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Bind(&ThreadProxy::CommitPendingOnImplThreadForTesting, 1391c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) impl_thread_weak_ptr_, 1392c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) &commit_pending_request)); 1393c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) commit_pending_request.completion.Wait(); 1394c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1395c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return commit_pending_request.commit_pending; 1396c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 13972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::CommitPendingOnImplThreadForTesting( 13992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CommitPendingRequest* request) { 14002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 14012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_impl_->output_surface()) 14024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) request->commit_pending = scheduler_on_impl_thread_->CommitPending(); 14031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) else 14042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) request->commit_pending = false; 1405a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) request->completion.Signal(); 14062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 14072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)scoped_ptr<base::Value> ThreadProxy::SchedulerStateAsValueForTesting() { 14092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (IsImplThread()) 14102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return scheduler_on_impl_thread_->StateAsValueForTesting().Pass(); 14112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SchedulerStateRequest scheduler_state_request; 14132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 14141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DebugScopedSetMainThreadBlocked main_thread_blocked(this); 141568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostTask( 141668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) FROM_HERE, 141768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::Bind(&ThreadProxy::SchedulerStateAsValueOnImplThreadForTesting, 14182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_, 14191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) &scheduler_state_request)); 14202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scheduler_state_request.completion.Wait(); 14212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 14222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return scheduler_state_request.state.Pass(); 14232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 14242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::SchedulerStateAsValueOnImplThreadForTesting( 14262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SchedulerStateRequest* request) { 14272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 1428eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch request->state = scheduler_on_impl_thread_->StateAsValueForTesting(); 1429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch request->completion.Signal(); 1430eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 1431eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1432eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ThreadProxy::RenewTreePriority() { 1433eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DCHECK(IsImplThread()); 14342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool smoothness_takes_priority = 14352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->pinch_gesture_active() || 14362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->CurrentlyScrollingLayer() || 14372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->page_scale_animation_active(); 14382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeTicks now = layer_tree_host_impl_->CurrentPhysicalTimeTicks(); 14402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Update expiration time if smoothness currently takes priority. 14422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (smoothness_takes_priority) { 14432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) smoothness_takes_priority_expiration_time_ = 14442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) now + base::TimeDelta::FromMilliseconds( 14452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) kSmoothnessTakesPriorityExpirationDelay * 1000); 14462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 14472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // We use the same priority for both trees by default. 14492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TreePriority priority = SAME_PRIORITY_FOR_BOTH_TREES; 14502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1451eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Smoothness takes priority if expiration time is in the future. 1452eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (smoothness_takes_priority_expiration_time_ > now) 14532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) priority = SMOOTHNESS_TAKES_PRIORITY; 14542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // New content always takes priority when the active tree has 14562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // evicted resources or there is an invalid viewport size. 14572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_impl_->active_tree()->ContentsTexturesPurged() || 14582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->active_tree()->ViewportSizeInvalid() || 14592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) input_throttled_until_commit_) 14602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) priority = NEW_CONTENT_TAKES_PRIORITY; 14612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->SetTreePriority(priority); 14632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notify the the client of this compositor via the output surface. 14652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(epenner): Route this to compositor-thread instead of output-surface 14662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // after GTFO refactor of compositor-thread (http://crbug/170828). 14672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (layer_tree_host_impl_->output_surface()) { 14682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->output_surface()-> 14692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateSmoothnessTakesPriority(priority == SMOOTHNESS_TAKES_PRIORITY); 14702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 14713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 14727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::TimeDelta delay = smoothness_takes_priority_expiration_time_ - now; 1473424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 14747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Need to make sure a delayed task is posted when we have smoothness 14757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // takes priority expiration time in the future. 14767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (delay <= base::TimeDelta()) 14777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return; 1478eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (renew_tree_priority_on_impl_thread_pending_) 1479eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 14803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 14817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostDelayedTask( 14827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) FROM_HERE, 14837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::Bind(&ThreadProxy::RenewTreePriorityOnImplThread, 14847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) weak_factory_on_impl_thread_.GetWeakPtr()), 14853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) delay); 14867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 14877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) renew_tree_priority_on_impl_thread_pending_ = true; 14883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 14897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 14907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void ThreadProxy::RenewTreePriorityOnImplThread() { 1491424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(renew_tree_priority_on_impl_thread_pending_); 14927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) renew_tree_priority_on_impl_thread_pending_ = false; 14937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 14947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) RenewTreePriority(); 14952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1496a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 14972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) { 14982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Proxy::ImplThreadTaskRunner()->PostDelayedTask( 14994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) FROM_HERE, 15002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&ThreadProxy::StartScrollbarAnimationOnImplThread, 15012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) impl_thread_weak_ptr_), 15027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) delay); 15037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 15042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::StartScrollbarAnimationOnImplThread() { 15062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer_tree_host_impl_->StartScrollbarAnimation(); 15077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 15087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 15092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ThreadProxy::DidActivatePendingTree() { 15102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(IsImplThread()); 15112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT0("cc", "ThreadProxy::DidActivatePendingTreeOnImplThread"); 15122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (completion_event_for_commit_held_on_tree_activation_ && 15142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) !layer_tree_host_impl_->pending_tree()) { 15157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", 15162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TRACE_EVENT_SCOPE_THREAD); 15172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(layer_tree_host_impl_->settings().impl_side_painting); 15182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion_event_for_commit_held_on_tree_activation_->Signal(); 15192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completion_event_for_commit_held_on_tree_activation_ = NULL; 15202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1521a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 152258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) commit_to_activate_duration_history_.InsertSample( 1523a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::TimeTicks::HighResNow() - commit_complete_time_); 15242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 15252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace cc 15271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)