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.
5 #ifndef CC_OUTPUT_BEGIN_FRAME_ARGS_H_
6 #define CC_OUTPUT_BEGIN_FRAME_ARGS_H_
8 #include "base/location.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/time/time.h"
11 #include "base/values.h"
12 #include "cc/base/cc_export.h"
15 namespace trace_event
{
16 class ConvertableToTraceFormat
;
22 * In debug builds we trace the creation origin of BeginFrameArgs objects. We
23 * reuse the tracked_objects::Location system to do that.
25 * However, in release builds we don't want this as it doubles the size of the
26 * BeginFrameArgs object. As well it adds a number of largish strings to the
27 * binary. Despite the argument being unused, most compilers are unable to
28 * optimise it away even when unused. Instead we use the BEGINFRAME_FROM_HERE
29 * macro to prevent the data even getting referenced.
32 #define BEGINFRAME_FROM_HERE nullptr
34 #define BEGINFRAME_FROM_HERE FROM_HERE
39 struct CC_EXPORT BeginFrameArgs
{
40 enum BeginFrameArgsType
{
44 // Not a real type, but used by the IPC system. Should always remain the
45 // *last* value in this enum.
46 BEGIN_FRAME_ARGS_TYPE_MAX
,
48 static const char* TypeToString(BeginFrameArgsType type
);
50 // Creates an invalid set of values.
54 typedef const void* CreationLocation
;
56 typedef const tracked_objects::Location
& CreationLocation
;
57 tracked_objects::Location created_from
;
60 // You should be able to find all instances where a BeginFrame has been
61 // created by searching for "BeginFrameArgs::Create".
62 // The location argument should **always** be BEGINFRAME_FROM_HERE macro.
63 static BeginFrameArgs
Create(CreationLocation location
,
64 base::TimeTicks frame_time
,
65 base::TimeTicks deadline
,
66 base::TimeDelta interval
,
67 BeginFrameArgsType type
);
69 // This is the default delta that will be used to adjust the deadline when
70 // proper draw-time estimations are not yet available.
71 static base::TimeDelta
DefaultEstimatedParentDrawTime();
73 // This is the default interval to use to avoid sprinkling the code with
75 static base::TimeDelta
DefaultInterval();
77 bool IsValid() const { return interval
>= base::TimeDelta(); }
79 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> AsValue() const;
80 void AsValueInto(base::trace_event::TracedValue
* dict
) const;
82 base::TimeTicks frame_time
;
83 base::TimeTicks deadline
;
84 base::TimeDelta interval
;
85 BeginFrameArgsType type
;
86 bool on_critical_path
;
89 BeginFrameArgs(base::TimeTicks frame_time
,
90 base::TimeTicks deadline
,
91 base::TimeDelta interval
,
92 BeginFrameArgsType type
);
97 #endif // CC_OUTPUT_BEGIN_FRAME_ARGS_H_