1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/test/fake_external_begin_frame_source.h"
7 #include "base/location.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/time/time.h"
10 #include "cc/test/begin_frame_args_test.h"
14 FakeExternalBeginFrameSource::FakeExternalBeginFrameSource(double refresh_rate
)
15 : milliseconds_per_frame_(1000.0 / refresh_rate
),
17 weak_ptr_factory_(this) {
21 FakeExternalBeginFrameSource::~FakeExternalBeginFrameSource() {
22 DCHECK(CalledOnValidThread());
25 void FakeExternalBeginFrameSource::SetClientReady() {
26 DCHECK(CalledOnValidThread());
30 void FakeExternalBeginFrameSource::OnNeedsBeginFramesChange(
31 bool needs_begin_frames
) {
32 DCHECK(CalledOnValidThread());
33 if (needs_begin_frames
) {
34 PostTestOnBeginFrame();
38 void FakeExternalBeginFrameSource::TestOnBeginFrame() {
39 DCHECK(CalledOnValidThread());
40 CallOnBeginFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
));
42 if (NeedsBeginFrames()) {
43 PostTestOnBeginFrame();
47 void FakeExternalBeginFrameSource::PostTestOnBeginFrame() {
48 base::MessageLoop::current()->PostDelayedTask(
49 FROM_HERE
, base::Bind(&FakeExternalBeginFrameSource::TestOnBeginFrame
,
50 weak_ptr_factory_
.GetWeakPtr()),
51 base::TimeDelta::FromMilliseconds(milliseconds_per_frame_
));