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

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

Issue 15836005: cc: Emulate BeginFrame in OutputSurfaces that don't support it natively (Closed) Base URL: http://git.chromium.org/chromium/src.git@nofrc
Patch Set: Fix checkerboard; Track pending swaps; Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/thread_proxy.h" 5 #include "cc/trees/thread_proxy.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "cc/base/thread.h" 10 #include "cc/base/thread.h"
11 #include "cc/input/input_handler.h" 11 #include "cc/input/input_handler.h"
12 #include "cc/output/context_provider.h" 12 #include "cc/output/context_provider.h"
13 #include "cc/output/output_surface.h" 13 #include "cc/output/output_surface.h"
14 #include "cc/quads/draw_quad.h" 14 #include "cc/quads/draw_quad.h"
15 #include "cc/resources/prioritized_resource_manager.h" 15 #include "cc/resources/prioritized_resource_manager.h"
16 #include "cc/scheduler/delay_based_time_source.h" 16 #include "cc/scheduler/delay_based_time_source.h"
17 #include "cc/scheduler/frame_rate_controller.h" 17 #include "cc/scheduler/frame_rate_controller.h"
18 #include "cc/scheduler/scheduler.h" 18 #include "cc/scheduler/scheduler.h"
19 #include "cc/scheduler/vsync_time_source.h"
20 #include "cc/trees/layer_tree_host.h" 19 #include "cc/trees/layer_tree_host.h"
21 #include "cc/trees/layer_tree_impl.h" 20 #include "cc/trees/layer_tree_impl.h"
22 21
23 namespace { 22 namespace {
24 23
25 // Measured in seconds. 24 // Measured in seconds.
26 const double kContextRecreationTickRate = 0.03; 25 const double kContextRecreationTickRate = 0.03;
27 26
28 // Measured in seconds. 27 // Measured in seconds.
29 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; 28 const double kSmoothnessTakesPriorityExpirationDelay = 0.25;
(...skipping 27 matching lines...) Expand all
57 commit_completion_event_on_impl_thread_(NULL), 56 commit_completion_event_on_impl_thread_(NULL),
58 completion_event_for_commit_held_on_tree_activation_(NULL), 57 completion_event_for_commit_held_on_tree_activation_(NULL),
59 texture_acquisition_completion_event_on_impl_thread_(NULL), 58 texture_acquisition_completion_event_on_impl_thread_(NULL),
60 next_frame_is_newly_committed_frame_on_impl_thread_(false), 59 next_frame_is_newly_committed_frame_on_impl_thread_(false),
61 throttle_frame_production_( 60 throttle_frame_production_(
62 layer_tree_host->settings().throttle_frame_production), 61 layer_tree_host->settings().throttle_frame_production),
63 begin_frame_scheduling_enabled_( 62 begin_frame_scheduling_enabled_(
64 layer_tree_host->settings().begin_frame_scheduling_enabled), 63 layer_tree_host->settings().begin_frame_scheduling_enabled),
65 using_synchronous_renderer_compositor_( 64 using_synchronous_renderer_compositor_(
66 layer_tree_host->settings().using_synchronous_renderer_compositor), 65 layer_tree_host->settings().using_synchronous_renderer_compositor),
67 vsync_client_(NULL),
68 inside_draw_(false), 66 inside_draw_(false),
69 defer_commits_(false), 67 defer_commits_(false),
70 renew_tree_priority_on_impl_thread_pending_(false) { 68 renew_tree_priority_on_impl_thread_pending_(false) {
71 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); 69 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy");
72 DCHECK(IsMainThread()); 70 DCHECK(IsMainThread());
73 DCHECK(layer_tree_host_); 71 DCHECK(layer_tree_host_);
74 } 72 }
75 73
76 ThreadProxy::~ThreadProxy() { 74 ThreadProxy::~ThreadProxy() {
77 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); 75 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy");
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 offscreen_context_provider() : NULL; 319 offscreen_context_provider() : NULL;
322 320
323 if (offscreen_contexts) 321 if (offscreen_contexts)
324 offscreen_contexts->VerifyContexts(); 322 offscreen_contexts->VerifyContexts();
325 scheduler_on_impl_thread_->DidLoseOutputSurface(); 323 scheduler_on_impl_thread_->DidLoseOutputSurface();
326 } 324 }
327 325
328 void ThreadProxy::OnSwapBuffersCompleteOnImplThread() { 326 void ThreadProxy::OnSwapBuffersCompleteOnImplThread() {
329 DCHECK(IsImplThread()); 327 DCHECK(IsImplThread());
330 TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread"); 328 TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread");
331 scheduler_on_impl_thread_->DidSwapBuffersComplete();
332 Proxy::MainThread()->PostTask( 329 Proxy::MainThread()->PostTask(
333 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); 330 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_));
334 } 331 }
335 332
336 void ThreadProxy::OnVSyncParametersChanged(base::TimeTicks timebase, 333 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) {
337 base::TimeDelta interval) {
338 DCHECK(IsImplThread()); 334 DCHECK(IsImplThread());
339 TRACE_EVENT2("cc", 335 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread",
340 "ThreadProxy::OnVSyncParametersChanged", 336 "enable", enable);
341 "timebase", 337 layer_tree_host_impl_->SetNeedsBeginFrame(enable);
342 (timebase - base::TimeTicks()).InMilliseconds(),
343 "interval",
344 interval.InMilliseconds());
345 scheduler_on_impl_thread_->SetTimebaseAndInterval(timebase, interval);
346 } 338 }
347 339
348 void ThreadProxy::BeginFrameOnImplThread(base::TimeTicks frame_time) { 340 void ThreadProxy::BeginFrameOnImplThread(base::TimeTicks frame_time) {
349 DCHECK(IsImplThread()); 341 DCHECK(IsImplThread());
350 TRACE_EVENT0("cc", "ThreadProxy::OnBeginFrameOnImplThread"); 342 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread");
351 if (vsync_client_) 343 scheduler_on_impl_thread_->BeginFrame(frame_time);
352 vsync_client_->DidVSync(frame_time);
353 }
354
355 void ThreadProxy::RequestVSyncNotification(VSyncClient* client) {
356 DCHECK(IsImplThread());
357 TRACE_EVENT1(
358 "cc", "ThreadProxy::RequestVSyncNotification", "enable", !!client);
359 vsync_client_ = client;
360 layer_tree_host_impl_->SetNeedsBeginFrame(!!client);
361 } 344 }
362 345
363 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { 346 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) {
364 DCHECK(IsImplThread()); 347 DCHECK(IsImplThread());
365 TRACE_EVENT1( 348 TRACE_EVENT1(
366 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 349 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
367 scheduler_on_impl_thread_->SetCanDraw(can_draw); 350 scheduler_on_impl_thread_->SetCanDraw(can_draw);
368 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 351 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
369 !scheduler_on_impl_thread_->WillDrawIfNeeded()); 352 !scheduler_on_impl_thread_->WillDrawIfNeeded());
370 } 353 }
(...skipping 16 matching lines...) Expand all
387 void ThreadProxy::SetNeedsManageTilesOnImplThread() { 370 void ThreadProxy::SetNeedsManageTilesOnImplThread() {
388 if (manage_tiles_pending_) 371 if (manage_tiles_pending_)
389 return; 372 return;
390 Proxy::ImplThread()->PostTask( 373 Proxy::ImplThread()->PostTask(
391 base::Bind(&ThreadProxy::ManageTilesOnImplThread, impl_thread_weak_ptr_)); 374 base::Bind(&ThreadProxy::ManageTilesOnImplThread, impl_thread_weak_ptr_));
392 manage_tiles_pending_ = true; 375 manage_tiles_pending_ = true;
393 } 376 }
394 377
395 void ThreadProxy::ManageTilesOnImplThread() { 378 void ThreadProxy::ManageTilesOnImplThread() {
396 // TODO(nduca): If needed, move this into CCSchedulerStateMachine. 379 // TODO(nduca): If needed, move this into CCSchedulerStateMachine.
380 if (!manage_tiles_pending_)
381 return;
397 manage_tiles_pending_ = false; 382 manage_tiles_pending_ = false;
398 if (layer_tree_host_impl_) 383 if (layer_tree_host_impl_)
399 layer_tree_host_impl_->ManageTiles(); 384 layer_tree_host_impl_->ManageTiles();
400 } 385 }
401 386
402 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( 387 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
403 scoped_ptr<AnimationEventsVector> events, 388 scoped_ptr<AnimationEventsVector> events,
404 base::Time wall_clock_time) { 389 base::Time wall_clock_time) {
405 DCHECK(IsImplThread()); 390 DCHECK(IsImplThread());
406 TRACE_EVENT0("cc", 391 TRACE_EVENT0("cc",
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 void ThreadProxy::ScheduledActionCheckForCompletedTileUploads() { 856 void ThreadProxy::ScheduledActionCheckForCompletedTileUploads() {
872 DCHECK(IsImplThread()); 857 DCHECK(IsImplThread());
873 TRACE_EVENT0("cc", 858 TRACE_EVENT0("cc",
874 "ThreadProxy::ScheduledActionCheckForCompletedTileUploads"); 859 "ThreadProxy::ScheduledActionCheckForCompletedTileUploads");
875 layer_tree_host_impl_->CheckForCompletedTileUploads(); 860 layer_tree_host_impl_->CheckForCompletedTileUploads();
876 } 861 }
877 862
878 void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() { 863 void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() {
879 DCHECK(IsImplThread()); 864 DCHECK(IsImplThread());
880 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded"); 865 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded");
866 // TODO(brianderson): Add ScheduledActionManageTiles.
867 ManageTilesOnImplThread();
enne (OOO) 2013/06/04 03:23:10 I don't know that ManageTiles should always be pai
881 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); 868 layer_tree_host_impl_->ActivatePendingTreeIfNeeded();
882 } 869 }
883 870
884 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { 871 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
885 DCHECK(IsImplThread()); 872 DCHECK(IsImplThread());
886 Proxy::MainThread()->PostTask( 873 Proxy::MainThread()->PostTask(
887 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, 874 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface,
888 main_thread_weak_ptr_)); 875 main_thread_weak_ptr_));
889 } 876 }
890 877
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 DCHECK(IsImplThread()); 1092 DCHECK(IsImplThread());
1106 *has_initialized_output_surface = 1093 *has_initialized_output_surface =
1107 scheduler_on_impl_thread_->HasInitializedOutputSurface(); 1094 scheduler_on_impl_thread_->HasInitializedOutputSurface();
1108 completion->Signal(); 1095 completion->Signal();
1109 } 1096 }
1110 1097
1111 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { 1098 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) {
1112 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); 1099 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread");
1113 DCHECK(IsImplThread()); 1100 DCHECK(IsImplThread());
1114 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); 1101 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
1115 const base::TimeDelta display_refresh_interval =
1116 base::TimeDelta::FromMicroseconds(
1117 base::Time::kMicrosecondsPerSecond /
1118 layer_tree_host_->settings().refresh_rate);
1119 scoped_ptr<FrameRateController> frame_rate_controller;
1120 if (throttle_frame_production_) {
1121 if (begin_frame_scheduling_enabled_) {
1122 frame_rate_controller.reset(
1123 new FrameRateController(VSyncTimeSource::Create(
1124 this,
1125 using_synchronous_renderer_compositor_ ?
1126 VSyncTimeSource::DISABLE_SYNCHRONOUSLY :
1127 VSyncTimeSource::DISABLE_ON_NEXT_TICK)));
1128 } else {
1129 frame_rate_controller.reset(
1130 new FrameRateController(DelayBasedTimeSource::Create(
1131 display_refresh_interval, Proxy::ImplThread())));
1132 }
1133 } else {
1134 frame_rate_controller.reset(new FrameRateController(Proxy::ImplThread()));
1135 }
1136 const LayerTreeSettings& settings = layer_tree_host_->settings(); 1102 const LayerTreeSettings& settings = layer_tree_host_->settings();
1137 SchedulerSettings scheduler_settings; 1103 SchedulerSettings scheduler_settings;
1138 scheduler_settings.impl_side_painting = settings.impl_side_painting; 1104 scheduler_settings.impl_side_painting = settings.impl_side_painting;
1139 scheduler_settings.timeout_and_draw_when_animation_checkerboards = 1105 scheduler_settings.timeout_and_draw_when_animation_checkerboards =
1140 settings.timeout_and_draw_when_animation_checkerboards; 1106 settings.timeout_and_draw_when_animation_checkerboards;
1141 scheduler_on_impl_thread_ = Scheduler::Create(this, 1107 scheduler_settings.using_synchronous_renderer_compositor =
1142 frame_rate_controller.Pass(), 1108 settings.using_synchronous_renderer_compositor;
1143 scheduler_settings); 1109 scheduler_on_impl_thread_ =
1110 Scheduler::Create(this, scheduler_settings, Proxy::ImplThread());
1144 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); 1111 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
1145 1112
1146 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr(); 1113 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr();
1147 completion->Signal(); 1114 completion->Signal();
1148 } 1115 }
1149 1116
1150 void ThreadProxy::InitializeOutputSurfaceOnImplThread( 1117 void ThreadProxy::InitializeOutputSurfaceOnImplThread(
1151 CompletionEvent* completion, 1118 CompletionEvent* completion,
1152 scoped_ptr<OutputSurface> output_surface, 1119 scoped_ptr<OutputSurface> output_surface,
1153 scoped_refptr<ContextProvider> offscreen_context_provider, 1120 scoped_refptr<ContextProvider> offscreen_context_provider,
1154 bool* success, 1121 bool* success,
1155 RendererCapabilities* capabilities) { 1122 RendererCapabilities* capabilities) {
1156 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread"); 1123 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread");
1157 DCHECK(IsImplThread()); 1124 DCHECK(IsImplThread());
1158 DCHECK(IsMainThreadBlocked()); 1125 DCHECK(IsMainThreadBlocked());
1159 DCHECK(success); 1126 DCHECK(success);
1160 DCHECK(capabilities); 1127 DCHECK(capabilities);
1161 1128
1162 layer_tree_host_->DeleteContentsTexturesOnImplThread( 1129 layer_tree_host_->DeleteContentsTexturesOnImplThread(
1163 layer_tree_host_impl_->resource_provider()); 1130 layer_tree_host_impl_->resource_provider());
1164 1131
1165 *success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); 1132 *success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
1166 1133
1167 if (offscreen_context_provider.get()) 1134 if (offscreen_context_provider.get())
1168 offscreen_context_provider->BindToCurrentThread(); 1135 offscreen_context_provider->BindToCurrentThread();
1169 1136
1170 if (*success) { 1137 if (*success) {
1171 *capabilities = layer_tree_host_impl_->GetRendererCapabilities(); 1138 *capabilities = layer_tree_host_impl_->GetRendererCapabilities();
1172 scheduler_on_impl_thread_->SetSwapBuffersCompleteSupported(
1173 capabilities->using_swap_complete_callback);
1174
1175 OutputSurface* output_surface_ptr = layer_tree_host_impl_->output_surface();
1176 DCHECK(output_surface_ptr);
1177 int max_frames_pending =
1178 output_surface_ptr->capabilities().max_frames_pending;
1179 if (max_frames_pending <= 0)
1180 max_frames_pending = FrameRateController::DEFAULT_MAX_FRAMES_PENDING;
1181 if (output_surface_ptr->capabilities().has_parent_compositor)
1182 max_frames_pending = 1;
1183
1184 scheduler_on_impl_thread_->SetMaxFramesPending(max_frames_pending);
1185 1139
1186 if (layer_tree_host_impl_->resource_provider()) 1140 if (layer_tree_host_impl_->resource_provider())
1187 layer_tree_host_impl_->resource_provider()-> 1141 layer_tree_host_impl_->resource_provider()->
1188 set_offscreen_context_provider(offscreen_context_provider); 1142 set_offscreen_context_provider(offscreen_context_provider);
1189 1143
1190 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); 1144 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface();
1191 } else if (offscreen_context_provider.get()) { 1145 } else if (offscreen_context_provider.get()) {
1192 offscreen_context_provider->VerifyContexts(); 1146 offscreen_context_provider->VerifyContexts();
1193 } 1147 }
1194 1148
(...skipping 10 matching lines...) Expand all
1205 1159
1206 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { 1160 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) {
1207 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); 1161 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread");
1208 DCHECK(IsImplThread()); 1162 DCHECK(IsImplThread());
1209 layer_tree_host_->DeleteContentsTexturesOnImplThread( 1163 layer_tree_host_->DeleteContentsTexturesOnImplThread(
1210 layer_tree_host_impl_->resource_provider()); 1164 layer_tree_host_impl_->resource_provider());
1211 layer_tree_host_impl_->SetNeedsBeginFrame(false); 1165 layer_tree_host_impl_->SetNeedsBeginFrame(false);
1212 scheduler_on_impl_thread_.reset(); 1166 scheduler_on_impl_thread_.reset();
1213 layer_tree_host_impl_.reset(); 1167 layer_tree_host_impl_.reset();
1214 weak_factory_on_impl_thread_.InvalidateWeakPtrs(); 1168 weak_factory_on_impl_thread_.InvalidateWeakPtrs();
1215 vsync_client_ = NULL;
1216 completion->Signal(); 1169 completion->Signal();
1217 } 1170 }
1218 1171
1219 size_t ThreadProxy::MaxPartialTextureUpdates() const { 1172 size_t ThreadProxy::MaxPartialTextureUpdates() const {
1220 return ResourceUpdateController::MaxPartialTextureUpdates(); 1173 return ResourceUpdateController::MaxPartialTextureUpdates();
1221 } 1174 }
1222 1175
1223 ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState() 1176 ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState()
1224 : memory_allocation_limit_bytes(0) {} 1177 : memory_allocation_limit_bytes(0) {}
1225 1178
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 !layer_tree_host_impl_->pending_tree()) { 1339 !layer_tree_host_impl_->pending_tree()) {
1387 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", 1340 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation",
1388 TRACE_EVENT_SCOPE_THREAD); 1341 TRACE_EVENT_SCOPE_THREAD);
1389 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); 1342 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
1390 completion_event_for_commit_held_on_tree_activation_->Signal(); 1343 completion_event_for_commit_held_on_tree_activation_->Signal();
1391 completion_event_for_commit_held_on_tree_activation_ = NULL; 1344 completion_event_for_commit_held_on_tree_activation_ = NULL;
1392 } 1345 }
1393 } 1346 }
1394 1347
1395 } // namespace cc 1348 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698