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

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

Issue 17204002: 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 "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
13 #include "cc/base/thread.h" 11 #include "cc/base/thread.h"
14 #include "cc/input/input_handler.h" 12 #include "cc/input/input_handler.h"
15 #include "cc/output/context_provider.h" 13 #include "cc/output/context_provider.h"
16 #include "cc/output/output_surface.h" 14 #include "cc/output/output_surface.h"
17 #include "cc/quads/draw_quad.h" 15 #include "cc/quads/draw_quad.h"
18 #include "cc/resources/prioritized_resource_manager.h" 16 #include "cc/resources/prioritized_resource_manager.h"
19 #include "cc/scheduler/delay_based_time_source.h" 17 #include "cc/scheduler/delay_based_time_source.h"
20 #include "cc/scheduler/frame_rate_controller.h" 18 #include "cc/scheduler/frame_rate_controller.h"
21 #include "cc/scheduler/scheduler.h" 19 #include "cc/scheduler/scheduler.h"
20 #include "cc/scheduler/vsync_time_source.h"
22 #include "cc/trees/layer_tree_host.h" 21 #include "cc/trees/layer_tree_host.h"
23 #include "cc/trees/layer_tree_impl.h" 22 #include "cc/trees/layer_tree_impl.h"
24 23
25 namespace { 24 namespace {
26 25
27 // Measured in seconds. 26 // Measured in seconds.
28 const double kContextRecreationTickRate = 0.03; 27 const double kContextRecreationTickRate = 0.03;
29 28
30 // Measured in seconds. 29 // Measured in seconds.
31 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; 30 const double kSmoothnessTakesPriorityExpirationDelay = 0.25;
32 31
33 const size_t kDrawDurationHistorySize = 60; 32 const size_t kDrawDurationHistorySize = 60;
34 const double kDrawDurationEstimationPercentile = 100.0; 33 const double kDrawDurationEstimationPercentile = 100.0;
35 const int kDrawDurationEstimatePaddingInMicroseconds = 0; 34 const int kDrawDurationEstimatePaddingInMicroseconds = 0;
36 35
37 } // namespace 36 } // namespace
38 37
39 namespace cc { 38 namespace cc {
40 39
41 struct ThreadProxy::ReadbackRequest {
42 CompletionEvent completion;
43 bool success;
44 void* pixels;
45 gfx::Rect rect;
46 };
47
48 struct ThreadProxy::CommitPendingRequest {
49 CompletionEvent completion;
50 bool commit_pending;
51 };
52
53 struct ThreadProxy::SchedulerStateRequest {
54 CompletionEvent completion;
55 std::string state;
56 };
57
58 scoped_ptr<Proxy> ThreadProxy::Create(LayerTreeHost* layer_tree_host, 40 scoped_ptr<Proxy> ThreadProxy::Create(LayerTreeHost* layer_tree_host,
59 scoped_ptr<Thread> impl_thread) { 41 scoped_ptr<Thread> impl_thread) {
60 return make_scoped_ptr( 42 return make_scoped_ptr(
61 new ThreadProxy(layer_tree_host, impl_thread.Pass())).PassAs<Proxy>(); 43 new ThreadProxy(layer_tree_host, impl_thread.Pass())).PassAs<Proxy>();
62 } 44 }
63 45
64 ThreadProxy::ThreadProxy(LayerTreeHost* layer_tree_host, 46 ThreadProxy::ThreadProxy(LayerTreeHost* layer_tree_host,
65 scoped_ptr<Thread> impl_thread) 47 scoped_ptr<Thread> impl_thread)
66 : Proxy(impl_thread.Pass()), 48 : Proxy(impl_thread.Pass()),
67 animate_requested_(false), 49 animate_requested_(false),
(...skipping 12 matching lines...) Expand all
80 commit_completion_event_on_impl_thread_(NULL), 62 commit_completion_event_on_impl_thread_(NULL),
81 completion_event_for_commit_held_on_tree_activation_(NULL), 63 completion_event_for_commit_held_on_tree_activation_(NULL),
82 texture_acquisition_completion_event_on_impl_thread_(NULL), 64 texture_acquisition_completion_event_on_impl_thread_(NULL),
83 next_frame_is_newly_committed_frame_on_impl_thread_(false), 65 next_frame_is_newly_committed_frame_on_impl_thread_(false),
84 throttle_frame_production_( 66 throttle_frame_production_(
85 layer_tree_host->settings().throttle_frame_production), 67 layer_tree_host->settings().throttle_frame_production),
86 begin_frame_scheduling_enabled_( 68 begin_frame_scheduling_enabled_(
87 layer_tree_host->settings().begin_frame_scheduling_enabled), 69 layer_tree_host->settings().begin_frame_scheduling_enabled),
88 using_synchronous_renderer_compositor_( 70 using_synchronous_renderer_compositor_(
89 layer_tree_host->settings().using_synchronous_renderer_compositor), 71 layer_tree_host->settings().using_synchronous_renderer_compositor),
72 vsync_client_(NULL),
90 inside_draw_(false), 73 inside_draw_(false),
91 defer_commits_(false), 74 defer_commits_(false),
92 renew_tree_priority_on_impl_thread_pending_(false), 75 renew_tree_priority_on_impl_thread_pending_(false),
93 draw_duration_history_(kDrawDurationHistorySize) { 76 draw_duration_history_(kDrawDurationHistorySize) {
94 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); 77 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy");
95 DCHECK(IsMainThread()); 78 DCHECK(IsMainThread());
96 DCHECK(layer_tree_host_); 79 DCHECK(layer_tree_host_);
97 } 80 }
98 81
99 ThreadProxy::~ThreadProxy() { 82 ThreadProxy::~ThreadProxy() {
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 offscreen_context_provider() : NULL; 327 offscreen_context_provider() : NULL;
345 328
346 if (offscreen_contexts) 329 if (offscreen_contexts)
347 offscreen_contexts->VerifyContexts(); 330 offscreen_contexts->VerifyContexts();
348 scheduler_on_impl_thread_->DidLoseOutputSurface(); 331 scheduler_on_impl_thread_->DidLoseOutputSurface();
349 } 332 }
350 333
351 void ThreadProxy::OnSwapBuffersCompleteOnImplThread() { 334 void ThreadProxy::OnSwapBuffersCompleteOnImplThread() {
352 DCHECK(IsImplThread()); 335 DCHECK(IsImplThread());
353 TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread"); 336 TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread");
337 scheduler_on_impl_thread_->DidSwapBuffersComplete();
354 Proxy::MainThread()->PostTask( 338 Proxy::MainThread()->PostTask(
355 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); 339 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_));
356 } 340 }
357 341
358 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { 342 void ThreadProxy::OnVSyncParametersChanged(base::TimeTicks timebase,
343 base::TimeDelta interval) {
359 DCHECK(IsImplThread()); 344 DCHECK(IsImplThread());
360 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", 345 TRACE_EVENT2("cc",
361 "enable", enable); 346 "ThreadProxy::OnVSyncParametersChanged",
362 layer_tree_host_impl_->SetNeedsBeginFrame(enable); 347 "timebase",
348 (timebase - base::TimeTicks()).InMilliseconds(),
349 "interval",
350 interval.InMilliseconds());
351 scheduler_on_impl_thread_->SetTimebaseAndInterval(timebase, interval);
363 } 352 }
364 353
365 void ThreadProxy::BeginFrameOnImplThread(base::TimeTicks frame_time) { 354 void ThreadProxy::BeginFrameOnImplThread(base::TimeTicks frame_time) {
366 DCHECK(IsImplThread()); 355 DCHECK(IsImplThread());
367 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread"); 356 TRACE_EVENT0("cc", "ThreadProxy::OnBeginFrameOnImplThread");
368 scheduler_on_impl_thread_->BeginFrame(frame_time); 357 if (vsync_client_)
358 vsync_client_->DidVSync(frame_time);
359 }
360
361 void ThreadProxy::RequestVSyncNotification(VSyncClient* client) {
362 DCHECK(IsImplThread());
363 TRACE_EVENT1(
364 "cc", "ThreadProxy::RequestVSyncNotification", "enable", !!client);
365 vsync_client_ = client;
366 layer_tree_host_impl_->SetNeedsBeginFrame(!!client);
369 } 367 }
370 368
371 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { 369 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) {
372 DCHECK(IsImplThread()); 370 DCHECK(IsImplThread());
373 TRACE_EVENT1( 371 TRACE_EVENT1(
374 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 372 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
375 scheduler_on_impl_thread_->SetCanDraw(can_draw); 373 scheduler_on_impl_thread_->SetCanDraw(can_draw);
376 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 374 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
377 !scheduler_on_impl_thread_->WillDrawIfNeeded()); 375 !scheduler_on_impl_thread_->WillDrawIfNeeded());
378 } 376 }
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 DCHECK(IsImplThread()); 1145 DCHECK(IsImplThread());
1148 *has_initialized_output_surface = 1146 *has_initialized_output_surface =
1149 scheduler_on_impl_thread_->HasInitializedOutputSurface(); 1147 scheduler_on_impl_thread_->HasInitializedOutputSurface();
1150 completion->Signal(); 1148 completion->Signal();
1151 } 1149 }
1152 1150
1153 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { 1151 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) {
1154 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); 1152 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread");
1155 DCHECK(IsImplThread()); 1153 DCHECK(IsImplThread());
1156 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); 1154 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
1155 const base::TimeDelta display_refresh_interval =
1156 base::TimeDelta::FromMicroseconds(
1157 base::Time::kMicrosecondsPerSecond /
1158 layer_tree_host_->settings().refresh_rate);
1159 scoped_ptr<FrameRateController> frame_rate_controller;
1160 if (throttle_frame_production_) {
1161 if (begin_frame_scheduling_enabled_) {
1162 frame_rate_controller.reset(
1163 new FrameRateController(VSyncTimeSource::Create(
1164 this,
1165 using_synchronous_renderer_compositor_ ?
1166 VSyncTimeSource::DISABLE_SYNCHRONOUSLY :
1167 VSyncTimeSource::DISABLE_ON_NEXT_TICK)));
1168 } else {
1169 frame_rate_controller.reset(
1170 new FrameRateController(DelayBasedTimeSource::Create(
1171 display_refresh_interval, Proxy::ImplThread())));
1172 }
1173 } else {
1174 frame_rate_controller.reset(new FrameRateController(Proxy::ImplThread()));
1175 }
1157 const LayerTreeSettings& settings = layer_tree_host_->settings(); 1176 const LayerTreeSettings& settings = layer_tree_host_->settings();
1158 SchedulerSettings scheduler_settings; 1177 SchedulerSettings scheduler_settings;
1159 scheduler_settings.impl_side_painting = settings.impl_side_painting; 1178 scheduler_settings.impl_side_painting = settings.impl_side_painting;
1160 scheduler_settings.timeout_and_draw_when_animation_checkerboards = 1179 scheduler_settings.timeout_and_draw_when_animation_checkerboards =
1161 settings.timeout_and_draw_when_animation_checkerboards; 1180 settings.timeout_and_draw_when_animation_checkerboards;
1162 scheduler_settings.using_synchronous_renderer_compositor = 1181 scheduler_on_impl_thread_ = Scheduler::Create(this,
1163 settings.using_synchronous_renderer_compositor; 1182 frame_rate_controller.Pass(),
1164 scheduler_on_impl_thread_ = Scheduler::Create(this, scheduler_settings); 1183 scheduler_settings);
1165 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); 1184 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
1166 1185
1167 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr(); 1186 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr();
1168 completion->Signal(); 1187 completion->Signal();
1169 } 1188 }
1170 1189
1171 void ThreadProxy::InitializeOutputSurfaceOnImplThread( 1190 void ThreadProxy::InitializeOutputSurfaceOnImplThread(
1172 CompletionEvent* completion, 1191 CompletionEvent* completion,
1173 scoped_ptr<OutputSurface> output_surface, 1192 scoped_ptr<OutputSurface> output_surface,
1174 scoped_refptr<ContextProvider> offscreen_context_provider, 1193 scoped_refptr<ContextProvider> offscreen_context_provider,
1175 bool* success, 1194 bool* success,
1176 RendererCapabilities* capabilities) { 1195 RendererCapabilities* capabilities) {
1177 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread"); 1196 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread");
1178 DCHECK(IsImplThread()); 1197 DCHECK(IsImplThread());
1179 DCHECK(IsMainThreadBlocked()); 1198 DCHECK(IsMainThreadBlocked());
1180 DCHECK(success); 1199 DCHECK(success);
1181 DCHECK(capabilities); 1200 DCHECK(capabilities);
1182 1201
1183 layer_tree_host_->DeleteContentsTexturesOnImplThread( 1202 layer_tree_host_->DeleteContentsTexturesOnImplThread(
1184 layer_tree_host_impl_->resource_provider()); 1203 layer_tree_host_impl_->resource_provider());
1185 1204
1186 *success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); 1205 *success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass());
1187 1206
1188 if (*success) { 1207 if (*success) {
1189 *capabilities = layer_tree_host_impl_->GetRendererCapabilities(); 1208 *capabilities = layer_tree_host_impl_->GetRendererCapabilities();
1209
1210 OutputSurface* output_surface_ptr = layer_tree_host_impl_->output_surface();
1211 DCHECK(output_surface_ptr);
1212 int max_frames_pending =
1213 output_surface_ptr->capabilities().max_frames_pending;
1214 if (max_frames_pending <= 0)
1215 max_frames_pending = FrameRateController::DEFAULT_MAX_FRAMES_PENDING;
1216
1217 scheduler_on_impl_thread_->SetMaxFramesPending(max_frames_pending);
1218
1190 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); 1219 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface();
1191 } 1220 }
1192 1221
1193 DidTryInitializeRendererOnImplThread(*success, offscreen_context_provider); 1222 DidTryInitializeRendererOnImplThread(*success, offscreen_context_provider);
1194 1223
1195 completion->Signal(); 1224 completion->Signal();
1196 } 1225 }
1197 1226
1198 void ThreadProxy::DidTryInitializeRendererOnImplThread( 1227 void ThreadProxy::DidTryInitializeRendererOnImplThread(
1199 bool success, 1228 bool success,
(...skipping 24 matching lines...) Expand all
1224 1253
1225 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { 1254 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) {
1226 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); 1255 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread");
1227 DCHECK(IsImplThread()); 1256 DCHECK(IsImplThread());
1228 layer_tree_host_->DeleteContentsTexturesOnImplThread( 1257 layer_tree_host_->DeleteContentsTexturesOnImplThread(
1229 layer_tree_host_impl_->resource_provider()); 1258 layer_tree_host_impl_->resource_provider());
1230 layer_tree_host_impl_->SetNeedsBeginFrame(false); 1259 layer_tree_host_impl_->SetNeedsBeginFrame(false);
1231 scheduler_on_impl_thread_.reset(); 1260 scheduler_on_impl_thread_.reset();
1232 layer_tree_host_impl_.reset(); 1261 layer_tree_host_impl_.reset();
1233 weak_factory_on_impl_thread_.InvalidateWeakPtrs(); 1262 weak_factory_on_impl_thread_.InvalidateWeakPtrs();
1263 vsync_client_ = NULL;
1234 completion->Signal(); 1264 completion->Signal();
1235 } 1265 }
1236 1266
1237 size_t ThreadProxy::MaxPartialTextureUpdates() const { 1267 size_t ThreadProxy::MaxPartialTextureUpdates() const {
1238 return ResourceUpdateController::MaxPartialTextureUpdates(); 1268 return ResourceUpdateController::MaxPartialTextureUpdates();
1239 } 1269 }
1240 1270
1241 ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState() 1271 ThreadProxy::BeginFrameAndCommitState::BeginFrameAndCommitState()
1242 : memory_allocation_limit_bytes(0) {} 1272 : memory_allocation_limit_bytes(0) {}
1243 1273
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 void ThreadProxy::CommitPendingOnImplThreadForTesting( 1313 void ThreadProxy::CommitPendingOnImplThreadForTesting(
1284 CommitPendingRequest* request) { 1314 CommitPendingRequest* request) {
1285 DCHECK(IsImplThread()); 1315 DCHECK(IsImplThread());
1286 if (layer_tree_host_impl_->output_surface()) 1316 if (layer_tree_host_impl_->output_surface())
1287 request->commit_pending = scheduler_on_impl_thread_->CommitPending(); 1317 request->commit_pending = scheduler_on_impl_thread_->CommitPending();
1288 else 1318 else
1289 request->commit_pending = false; 1319 request->commit_pending = false;
1290 request->completion.Signal(); 1320 request->completion.Signal();
1291 } 1321 }
1292 1322
1293 std::string ThreadProxy::SchedulerStateAsStringForTesting() {
1294 if (IsImplThread())
1295 return scheduler_on_impl_thread_->StateAsStringForTesting();
1296
1297 SchedulerStateRequest scheduler_state_request;
1298 {
1299 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
1300 Proxy::ImplThread()->PostTask(
1301 base::Bind(&ThreadProxy::SchedulerStateAsStringOnImplThreadForTesting,
1302 impl_thread_weak_ptr_,
1303 &scheduler_state_request));
1304 scheduler_state_request.completion.Wait();
1305 }
1306 return scheduler_state_request.state;
1307 }
1308
1309 void ThreadProxy::SchedulerStateAsStringOnImplThreadForTesting(
1310 SchedulerStateRequest* request) {
1311 DCHECK(IsImplThread());
1312 request->state = scheduler_on_impl_thread_->StateAsStringForTesting();
1313 request->completion.Signal();
1314 }
1315
1316 skia::RefPtr<SkPicture> ThreadProxy::CapturePicture() { 1323 skia::RefPtr<SkPicture> ThreadProxy::CapturePicture() {
1317 DCHECK(IsMainThread()); 1324 DCHECK(IsMainThread());
1318 CompletionEvent completion; 1325 CompletionEvent completion;
1319 skia::RefPtr<SkPicture> picture; 1326 skia::RefPtr<SkPicture> picture;
1320 { 1327 {
1321 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 1328 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
1322 Proxy::ImplThread()->PostTask( 1329 Proxy::ImplThread()->PostTask(
1323 base::Bind(&ThreadProxy::CapturePictureOnImplThread, 1330 base::Bind(&ThreadProxy::CapturePictureOnImplThread,
1324 impl_thread_weak_ptr_, 1331 impl_thread_weak_ptr_,
1325 &completion, 1332 &completion,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 !layer_tree_host_impl_->pending_tree()) { 1424 !layer_tree_host_impl_->pending_tree()) {
1418 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", 1425 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation",
1419 TRACE_EVENT_SCOPE_THREAD); 1426 TRACE_EVENT_SCOPE_THREAD);
1420 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); 1427 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
1421 completion_event_for_commit_held_on_tree_activation_->Signal(); 1428 completion_event_for_commit_held_on_tree_activation_->Signal();
1422 completion_event_for_commit_held_on_tree_activation_ = NULL; 1429 completion_event_for_commit_held_on_tree_activation_ = NULL;
1423 } 1430 }
1424 } 1431 }
1425 1432
1426 } // namespace cc 1433 } // 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