1 // Copyright 2013 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. 4 5 #include "cc/output/begin_frame_args.h" 6 #include "ui/gfx/frame_time.h" 7 8 namespace cc { 9 10 BeginFrameArgs::BeginFrameArgs() 11 : frame_time(base::TimeTicks()), 12 deadline(base::TimeTicks()), 13 interval(base::TimeDelta::FromMicroseconds(-1)) { 14 } 15 16 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time, 17 base::TimeTicks deadline, 18 base::TimeDelta interval) 19 : frame_time(frame_time), 20 deadline(deadline), 21 interval(interval) 22 {} 23 24 BeginFrameArgs BeginFrameArgs::Create(base::TimeTicks frame_time, 25 base::TimeTicks deadline, 26 base::TimeDelta interval) { 27 return BeginFrameArgs(frame_time, deadline, interval); 28 } 29 30 BeginFrameArgs BeginFrameArgs::CreateForSynchronousCompositor() { 31 // For WebView/SynchronousCompositor, we always want to draw immediately, 32 // so we set the deadline to 0 and guess that the interval is 16 milliseconds. 33 return BeginFrameArgs(gfx::FrameTime::Now(), 34 base::TimeTicks(), 35 DefaultInterval()); 36 } 37 38 BeginFrameArgs BeginFrameArgs::CreateForTesting() { 39 base::TimeTicks now = gfx::FrameTime::Now(); 40 return BeginFrameArgs(now, 41 now + (DefaultInterval() / 2), 42 DefaultInterval()); 43 } 44 45 BeginFrameArgs BeginFrameArgs::CreateExpiredForTesting() { 46 base::TimeTicks now = gfx::FrameTime::Now(); 47 return BeginFrameArgs(now, 48 now - DefaultInterval(), 49 DefaultInterval()); 50 } 51 52 // This is a hard-coded deadline adjustment that assumes 60Hz, to be used in 53 // cases where a good estimated draw time is not known. Using 1/3 of the vsync 54 // as the default adjustment gives the Browser the last 1/3 of a frame to 55 // produce output, the Renderer Impl thread the middle 1/3 of a frame to produce 56 // ouput, and the Renderer Main thread the first 1/3 of a frame to produce 57 // output. 58 base::TimeDelta BeginFrameArgs::DefaultDeadlineAdjustment() { 59 return base::TimeDelta::FromMicroseconds(-16666 / 3); 60 } 61 62 base::TimeDelta BeginFrameArgs::DefaultInterval() { 63 return base::TimeDelta::FromMicroseconds(16666); 64 } 65 66 base::TimeDelta BeginFrameArgs::DefaultRetroactiveBeginFramePeriod() { 67 return base::TimeDelta::FromMicroseconds(4444); 68 } 69 70 } // namespace cc 71