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