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

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

Issue 17125004: Revert 206020 "cc: Emulate BeginFrame in OutputSurfaces that don..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | Annotate | Revision Log
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 <string>
8
9 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
10 #include "base/bind.h" 8 #include "base/bind.h"
11 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
12 #include "cc/base/thread.h" 10 #include "cc/base/thread.h"
13 #include "cc/input/input_handler.h" 11 #include "cc/input/input_handler.h"
14 #include "cc/output/context_provider.h" 12 #include "cc/output/context_provider.h"
15 #include "cc/output/output_surface.h" 13 #include "cc/output/output_surface.h"
16 #include "cc/quads/draw_quad.h" 14 #include "cc/quads/draw_quad.h"
17 #include "cc/resources/prioritized_resource_manager.h" 15 #include "cc/resources/prioritized_resource_manager.h"
18 #include "cc/scheduler/delay_based_time_source.h" 16 #include "cc/scheduler/delay_based_time_source.h"
19 #include "cc/scheduler/frame_rate_controller.h" 17 #include "cc/scheduler/frame_rate_controller.h"
20 #include "cc/scheduler/scheduler.h" 18 #include "cc/scheduler/scheduler.h"
19 #include "cc/scheduler/vsync_time_source.h"
21 #include "cc/trees/layer_tree_host.h" 20 #include "cc/trees/layer_tree_host.h"
22 #include "cc/trees/layer_tree_impl.h" 21 #include "cc/trees/layer_tree_impl.h"
23 22
24 namespace { 23 namespace {
25 24
26 // Measured in seconds. 25 // Measured in seconds.
27 const double kContextRecreationTickRate = 0.03; 26 const double kContextRecreationTickRate = 0.03;
28 27
29 // Measured in seconds. 28 // Measured in seconds.
30 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; 29 const double kSmoothnessTakesPriorityExpirationDelay = 0.25;
31 30
32 } // namespace 31 } // namespace
33 32
34 namespace cc { 33 namespace cc {
35 34
36 struct ThreadProxy::ReadbackRequest {
37 CompletionEvent completion;
38 bool success;
39 void* pixels;
40 gfx::Rect rect;
41 };
42
43 struct ThreadProxy::CommitPendingRequest {
44 CompletionEvent completion;
45 bool commit_pending;
46 };
47
48 struct ThreadProxy::SchedulerStateRequest {
49 CompletionEvent completion;
50 std::string state;
51 };
52
53 scoped_ptr<Proxy> ThreadProxy::Create(LayerTreeHost* layer_tree_host, 35 scoped_ptr<Proxy> ThreadProxy::Create(LayerTreeHost* layer_tree_host,
54 scoped_ptr<Thread> impl_thread) { 36 scoped_ptr<Thread> impl_thread) {
55 return make_scoped_ptr( 37 return make_scoped_ptr(
56 new ThreadProxy(layer_tree_host, impl_thread.Pass())).PassAs<Proxy>(); 38 new ThreadProxy(layer_tree_host, impl_thread.Pass())).PassAs<Proxy>();
57 } 39 }
58 40
59 ThreadProxy::ThreadProxy(LayerTreeHost* layer_tree_host, 41 ThreadProxy::ThreadProxy(LayerTreeHost* layer_tree_host,
60 scoped_ptr<Thread> impl_thread) 42 scoped_ptr<Thread> impl_thread)
61 : Proxy(impl_thread.Pass()), 43 : Proxy(impl_thread.Pass()),
62 animate_requested_(false), 44 animate_requested_(false),
(...skipping 12 matching lines...) Expand all
75 commit_completion_event_on_impl_thread_(NULL), 57 commit_completion_event_on_impl_thread_(NULL),
76 completion_event_for_commit_held_on_tree_activation_(NULL), 58 completion_event_for_commit_held_on_tree_activation_(NULL),
77 texture_acquisition_completion_event_on_impl_thread_(NULL), 59 texture_acquisition_completion_event_on_impl_thread_(NULL),
78 next_frame_is_newly_committed_frame_on_impl_thread_(false), 60 next_frame_is_newly_committed_frame_on_impl_thread_(false),
79 throttle_frame_production_( 61 throttle_frame_production_(
80 layer_tree_host->settings().throttle_frame_production), 62 layer_tree_host->settings().throttle_frame_production),
81 begin_frame_scheduling_enabled_( 63 begin_frame_scheduling_enabled_(
82 layer_tree_host->settings().begin_frame_scheduling_enabled), 64 layer_tree_host->settings().begin_frame_scheduling_enabled),
83 using_synchronous_renderer_compositor_( 65 using_synchronous_renderer_compositor_(
84 layer_tree_host->settings().using_synchronous_renderer_compositor), 66 layer_tree_host->settings().using_synchronous_renderer_compositor),
67 vsync_client_(NULL),
85 inside_draw_(false), 68 inside_draw_(false),
86 defer_commits_(false), 69 defer_commits_(false),
87 renew_tree_priority_on_impl_thread_pending_(false) { 70 renew_tree_priority_on_impl_thread_pending_(false) {
88 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); 71 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy");
89 DCHECK(IsMainThread()); 72 DCHECK(IsMainThread());
90 DCHECK(layer_tree_host_); 73 DCHECK(layer_tree_host_);
91 } 74 }
92 75
93 ThreadProxy::~ThreadProxy() { 76 ThreadProxy::~ThreadProxy() {
94 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); 77 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy");
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 offscreen_context_provider() : NULL; 321 offscreen_context_provider() : NULL;
339 322
340 if (offscreen_contexts) 323 if (offscreen_contexts)
341 offscreen_contexts->VerifyContexts(); 324 offscreen_contexts->VerifyContexts();
342 scheduler_on_impl_thread_->DidLoseOutputSurface(); 325 scheduler_on_impl_thread_->DidLoseOutputSurface();
343 } 326 }
344 327
345 void ThreadProxy::OnSwapBuffersCompleteOnImplThread() { 328 void ThreadProxy::OnSwapBuffersCompleteOnImplThread() {
346 DCHECK(IsImplThread()); 329 DCHECK(IsImplThread());
347 TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread"); 330 TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread");
331 scheduler_on_impl_thread_->DidSwapBuffersComplete();
348 Proxy::MainThread()->PostTask( 332 Proxy::MainThread()->PostTask(
349 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); 333 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_));
350 } 334 }
351 335
352 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { 336 void ThreadProxy::OnVSyncParametersChanged(base::TimeTicks timebase,
337 base::TimeDelta interval) {
353 DCHECK(IsImplThread()); 338 DCHECK(IsImplThread());
354 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", 339 TRACE_EVENT2("cc",
355 "enable", enable); 340 "ThreadProxy::OnVSyncParametersChanged",
356 layer_tree_host_impl_->SetNeedsBeginFrame(enable); 341 "timebase",
342 (timebase - base::TimeTicks()).InMilliseconds(),
343 "interval",
344 interval.InMilliseconds());
345 scheduler_on_impl_thread_->SetTimebaseAndInterval(timebase, interval);
357 } 346 }
358 347
359 void ThreadProxy::BeginFrameOnImplThread(base::TimeTicks frame_time) { 348 void ThreadProxy::BeginFrameOnImplThread(base::TimeTicks frame_time) {
360 DCHECK(IsImplThread()); 349 DCHECK(IsImplThread());
361 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread"); 350 TRACE_EVENT0("cc", "ThreadProxy::OnBeginFrameOnImplThread");
362 scheduler_on_impl_thread_->BeginFrame(frame_time); 351 if (vsync_client_)
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);
363 } 361 }
364 362
365 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { 363 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) {
366 DCHECK(IsImplThread()); 364 DCHECK(IsImplThread());
367 TRACE_EVENT1( 365 TRACE_EVENT1(
368 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 366 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
369 scheduler_on_impl_thread_->SetCanDraw(can_draw); 367 scheduler_on_impl_thread_->SetCanDraw(can_draw);
370 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 368 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
371 !scheduler_on_impl_thread_->WillDrawIfNeeded()); 369 !scheduler_on_impl_thread_->WillDrawIfNeeded());
372 } 370 }
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 DCHECK(IsImplThread()); 1104 DCHECK(IsImplThread());
1107 *has_initialized_output_surface = 1105 *has_initialized_output_surface =
1108 scheduler_on_impl_thread_->HasInitializedOutputSurface(); 1106 scheduler_on_impl_thread_->HasInitializedOutputSurface();
1109 completion->Signal(); 1107 completion->Signal();
1110 } 1108 }
1111 1109
1112 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { 1110 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) {
1113 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); 1111 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread");
1114 DCHECK(IsImplThread()); 1112 DCHECK(IsImplThread());
1115 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); 1113 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
1114 const base::TimeDelta display_refresh_interval =
1115 base::TimeDelta::FromMicroseconds(
1116 base::Time::kMicrosecondsPerSecond /
1117 layer_tree_host_->settings().refresh_rate);
1118 scoped_ptr<FrameRateController> frame_rate_controller;
1119 if (throttle_frame_production_) {
1120 if (begin_frame_scheduling_enabled_) {
1121 frame_rate_controller.reset(
1122 new FrameRateController(VSyncTimeSource::Create(
1123 this,
1124 using_synchronous_renderer_compositor_ ?
1125 VSyncTimeSource::DISABLE_SYNCHRONOUSLY :
1126 VSyncTimeSource::DISABLE_ON_NEXT_TICK)));
1127 } else {
1128 frame_rate_controller.reset(
1129 new FrameRateController(DelayBasedTimeSource::Create(
1130 display_refresh_interval, Proxy::ImplThread())));
1131 }
1132 } else {
1133 frame_rate_controller.reset(new FrameRateController(Proxy::ImplThread()));
1134 }
1116 const LayerTreeSettings& settings = layer_tree_host_->settings(); 1135 const LayerTreeSettings& settings = layer_tree_host_->settings();
1117 SchedulerSettings scheduler_settings; 1136 SchedulerSettings scheduler_settings;
1118 scheduler_settings.impl_side_painting = settings.impl_side_painting; 1137 scheduler_settings.impl_side_painting = settings.impl_side_painting;
1119 scheduler_settings.timeout_and_draw_when_animation_checkerboards = 1138 scheduler_settings.timeout_and_draw_when_animation_checkerboards =
1120 settings.timeout_and_draw_when_animation_checkerboards; 1139 settings.timeout_and_draw_when_animation_checkerboards;
1121 scheduler_settings.using_synchronous_renderer_compositor = 1140 scheduler_on_impl_thread_ = Scheduler::Create(this,
1122 settings.using_synchronous_renderer_compositor; 1141 frame_rate_controller.Pass(),
1123 scheduler_on_impl_thread_ = Scheduler::Create(this, scheduler_settings); 1142 scheduler_settings);
1124 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); 1143 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
1125 1144
1126 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr(); 1145 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr();
1127 completion->Signal(); 1146 completion->Signal();
1128 } 1147 }
1129 1148
1130 void ThreadProxy::InitializeOutputSurfaceOnImplThread( 1149 void ThreadProxy::InitializeOutputSurfaceOnImplThread(
1131 CompletionEvent* completion, 1150 CompletionEvent* completion,
1132 scoped_ptr<OutputSurface> output_surface, 1151 scoped_ptr<OutputSurface> output_surface,
1133 scoped_refptr<ContextProvider> offscreen_context_provider, 1152 scoped_refptr<ContextProvider> offscreen_context_provider,
1134 bool* success, 1153 bool* success,
1135 RendererCapabilities* capabilities) { 1154 RendererCapabilities* capabilities) {
1136 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread"); 1155 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread");
1137 DCHECK(IsImplThread()); 1156 DCHECK(IsImplThread());
1138 DCHECK(IsMainThreadBlocked()); 1157 DCHECK(IsMainThreadBlocked());
1139 DCHECK(success); 1158 DCHECK(success);
1140 DCHECK(capabilities); 1159 DCHECK(capabilities);
1141 1160
1142 layer_tree_host_->DeleteContentsTexturesOnImplThread( 1161 layer_tree_host_->DeleteContentsTexturesOnImplThread(
1143 layer_tree_host_impl_->resource_provider()); 1162 layer_tree_host_impl_->resource_provider());
1144 1163
1145 *success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); 1164 *success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
1146 1165
1147 if (*success) { 1166 if (*success) {
1148 *capabilities = layer_tree_host_impl_->GetRendererCapabilities(); 1167 *capabilities = layer_tree_host_impl_->GetRendererCapabilities();
1168
1169 OutputSurface* output_surface_ptr = layer_tree_host_impl_->output_surface();
1170 DCHECK(output_surface_ptr);
1171 int max_frames_pending =
1172 output_surface_ptr->capabilities().max_frames_pending;
1173 if (max_frames_pending <= 0)
1174 max_frames_pending = FrameRateController::DEFAULT_MAX_FRAMES_PENDING;
1175
1176 scheduler_on_impl_thread_->SetMaxFramesPending(max_frames_pending);
1177
1149 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); 1178 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface();
1150 } 1179 }
1151 1180
1152 DidTryInitializeRendererOnImplThread(*success, offscreen_context_provider); 1181 DidTryInitializeRendererOnImplThread(*success, offscreen_context_provider);
1153 1182
1154 completion->Signal(); 1183 completion->Signal();
1155 } 1184 }
1156 1185
1157 void ThreadProxy::DidTryInitializeRendererOnImplThread( 1186 void ThreadProxy::DidTryInitializeRendererOnImplThread(
1158 bool success, 1187 bool success,
(...skipping 24 matching lines...) Expand all
1183 1212
1184 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { 1213 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) {
1185 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); 1214 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread");
1186 DCHECK(IsImplThread()); 1215 DCHECK(IsImplThread());
1187 layer_tree_host_->DeleteContentsTexturesOnImplThread( 1216 layer_tree_host_->DeleteContentsTexturesOnImplThread(
1188 layer_tree_host_impl_->resource_provider()); 1217 layer_tree_host_impl_->resource_provider());
1189 layer_tree_host_impl_->SetNeedsBeginFrame(false); 1218 layer_tree_host_impl_->SetNeedsBeginFrame(false);
1190 scheduler_on_impl_thread_.reset(); 1219 scheduler_on_impl_thread_.reset();
1191 layer_tree_host_impl_.reset(); 1220 layer_tree_host_impl_.reset();
1192 weak_factory_on_impl_thread_.InvalidateWeakPtrs(); 1221 weak_factory_on_impl_thread_.InvalidateWeakPtrs();
1222 vsync_client_ = NULL;
1193 completion->Signal(); 1223 completion->Signal();
1194 } 1224 }
1195 1225
1196 size_t ThreadProxy::MaxPartialTextureUpdates() const { 1226 size_t ThreadProxy::MaxPartialTextureUpdates() const {
1197 return ResourceUpdateController::MaxPartialTextureUpdates(); 1227 return ResourceUpdateController::MaxPartialTextureUpdates();
1198 } 1228 }
1199 1229
1200 ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState() 1230 ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState()
1201 : memory_allocation_limit_bytes(0) {} 1231 : memory_allocation_limit_bytes(0) {}
1202 1232
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 void ThreadProxy::CommitPendingOnImplThreadForTesting( 1272 void ThreadProxy::CommitPendingOnImplThreadForTesting(
1243 CommitPendingRequest* request) { 1273 CommitPendingRequest* request) {
1244 DCHECK(IsImplThread()); 1274 DCHECK(IsImplThread());
1245 if (layer_tree_host_impl_->output_surface()) 1275 if (layer_tree_host_impl_->output_surface())
1246 request->commit_pending = scheduler_on_impl_thread_->CommitPending(); 1276 request->commit_pending = scheduler_on_impl_thread_->CommitPending();
1247 else 1277 else
1248 request->commit_pending = false; 1278 request->commit_pending = false;
1249 request->completion.Signal(); 1279 request->completion.Signal();
1250 } 1280 }
1251 1281
1252 std::string ThreadProxy::SchedulerStateAsStringForTesting() {
1253 if (IsImplThread())
1254 return scheduler_on_impl_thread_->StateAsStringForTesting();
1255
1256 SchedulerStateRequest scheduler_state_request;
1257 {
1258 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
1259 Proxy::ImplThread()->PostTask(
1260 base::Bind(&ThreadProxy::SchedulerStateAsStringOnImplThreadForTesting,
1261 impl_thread_weak_ptr_,
1262 &scheduler_state_request));
1263 scheduler_state_request.completion.Wait();
1264 }
1265 return scheduler_state_request.state;
1266 }
1267
1268 void ThreadProxy::SchedulerStateAsStringOnImplThreadForTesting(
1269 SchedulerStateRequest* request) {
1270 DCHECK(IsImplThread());
1271 request->state = scheduler_on_impl_thread_->StateAsStringForTesting();
1272 request->completion.Signal();
1273 }
1274
1275 skia::RefPtr<SkPicture> ThreadProxy::CapturePicture() { 1282 skia::RefPtr<SkPicture> ThreadProxy::CapturePicture() {
1276 DCHECK(IsMainThread()); 1283 DCHECK(IsMainThread());
1277 CompletionEvent completion; 1284 CompletionEvent completion;
1278 skia::RefPtr<SkPicture> picture; 1285 skia::RefPtr<SkPicture> picture;
1279 { 1286 {
1280 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 1287 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
1281 Proxy::ImplThread()->PostTask( 1288 Proxy::ImplThread()->PostTask(
1282 base::Bind(&ThreadProxy::CapturePictureOnImplThread, 1289 base::Bind(&ThreadProxy::CapturePictureOnImplThread,
1283 impl_thread_weak_ptr_, 1290 impl_thread_weak_ptr_,
1284 &completion, 1291 &completion,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 !layer_tree_host_impl_->pending_tree()) { 1383 !layer_tree_host_impl_->pending_tree()) {
1377 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", 1384 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation",
1378 TRACE_EVENT_SCOPE_THREAD); 1385 TRACE_EVENT_SCOPE_THREAD);
1379 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); 1386 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
1380 completion_event_for_commit_held_on_tree_activation_->Signal(); 1387 completion_event_for_commit_held_on_tree_activation_->Signal();
1381 completion_event_for_commit_held_on_tree_activation_ = NULL; 1388 completion_event_for_commit_held_on_tree_activation_ = NULL;
1382 } 1389 }
1383 } 1390 }
1384 1391
1385 } // namespace cc 1392 } // namespace cc
OLDNEW
« no previous file with comments | « trunk/src/cc/trees/thread_proxy.h ('k') | trunk/src/chrome/test/perf/rendering/latency_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698