Skip to content

Commit

Permalink
Make ui::InProcessContextFactory::refresh_rate_ effective.
Browse files Browse the repository at this point in the history
This change also adds the flag --disable-vsync-for-tests to disable vsync
for test, so the tests will not wait for vsync signal and run as fast as
possible.

Bug: None
Change-Id: I599566dac7381be753ca5dc285caf39cf17cc117
Reviewed-on: https://chromium-review.googlesource.com/661322
Reviewed-by: Antoine Labour <piman@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501124}
  • Loading branch information
phuangg authored and Commit Bot committed Sep 12, 2017
1 parent 3be4b41 commit 308c566
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ui/compositor/compositor_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const char kUISlowAnimations[] = "ui-slow-animations";
// to be done via corner points. See https://goo.gl/Dqig5s
const char kEnablePixelCanvasRecording[] = "enable-pixel-canvas-recording";

const char kDisableVsyncForTests[] = "disable-vsync-for-tests";

} // namespace switches

namespace ui {
Expand Down
1 change: 1 addition & 0 deletions ui/compositor/compositor_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ COMPOSITOR_EXPORT extern const char kUIDisableZeroCopy[];
COMPOSITOR_EXPORT extern const char kUIShowPaintRects[];
COMPOSITOR_EXPORT extern const char kUISlowAnimations[];
COMPOSITOR_EXPORT extern const char kEnablePixelCanvasRecording[];
COMPOSITOR_EXPORT extern const char kDisableVsyncForTests[];

} // namespace switches

Expand Down
21 changes: 17 additions & 4 deletions ui/compositor/test/in_process_context_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ InProcessContextFactory::InProcessContextFactory(
viz::FrameSinkManagerImpl* frame_sink_manager)
: frame_sink_id_allocator_(kDefaultClientId),
use_test_surface_(true),
disable_vsync_(base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableVsyncForTests)),
host_frame_sink_manager_(host_frame_sink_manager),
frame_sink_manager_(frame_sink_manager) {
DCHECK(host_frame_sink_manager);
Expand Down Expand Up @@ -236,10 +238,21 @@ void InProcessContextFactory::CreateLayerTreeFrameSink(
base::MakeUnique<DirectOutputSurface>(context_provider);
}

std::unique_ptr<viz::DelayBasedBeginFrameSource> begin_frame_source(
new viz::DelayBasedBeginFrameSource(
base::MakeUnique<viz::DelayBasedTimeSource>(
compositor->task_runner().get())));
std::unique_ptr<viz::BeginFrameSource> begin_frame_source;
if (disable_vsync_) {
begin_frame_source = base::MakeUnique<viz::BackToBackBeginFrameSource>(
base::MakeUnique<viz::DelayBasedTimeSource>(
compositor->task_runner().get()));
} else {
auto time_source = base::MakeUnique<viz::DelayBasedTimeSource>(
compositor->task_runner().get());
time_source->SetTimebaseAndInterval(
base::TimeTicks(),
base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond /
refresh_rate_));
begin_frame_source = base::MakeUnique<viz::DelayBasedBeginFrameSource>(
std::move(time_source));
}
auto scheduler = base::MakeUnique<viz::DisplayScheduler>(
begin_frame_source.get(), compositor->task_runner().get(),
display_output_surface->capabilities().max_frames_pending);
Expand Down
5 changes: 3 additions & 2 deletions ui/compositor/test/in_process_context_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class InProcessContextFactory : public ContextFactory,
// using the SharedMainThreadContextProvider.
void SendOnLostResources();

// Set refresh rate to 200 to spend less time waiting for BeginFrame when
// used for tests.
// Set refresh rate will be set to 200 to spend less time waiting for
// BeginFrame when used for tests.
void SetUseFastRefreshRateForTests();

// ContextFactory implementation.
Expand Down Expand Up @@ -104,6 +104,7 @@ class InProcessContextFactory : public ContextFactory,
cc::TestTaskGraphRunner task_graph_runner_;
viz::FrameSinkIdAllocator frame_sink_id_allocator_;
bool use_test_surface_;
bool disable_vsync_ = false;
double refresh_rate_ = 60.0;
viz::HostFrameSinkManager* const host_frame_sink_manager_;
viz::FrameSinkManagerImpl* const frame_sink_manager_;
Expand Down

0 comments on commit 308c566

Please sign in to comment.