OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CC_SCHEDULER_BEGIN_FRAME_TRACKER_H_ |
| 6 #define CC_SCHEDULER_BEGIN_FRAME_TRACKER_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 |
| 11 #include "base/debug/trace_event.h" |
| 12 #include "base/location.h" |
| 13 #include "cc/output/begin_frame_args.h" |
| 14 |
| 15 #define BEGINFRAMETRACKER_FROM_HERE FROM_HERE_WITH_EXPLICIT_FUNCTION("") |
| 16 |
| 17 namespace cc { |
| 18 |
| 19 // Microclass to trace and check properties for correct BeginFrameArgs (BFA) |
| 20 // usage and provide a few helper methods. |
| 21 // |
| 22 // With DCHECKs enable, this class checks the following "invariants"; |
| 23 // * BFA are monotonically increasing. |
| 24 // * BFA is valid. |
| 25 // * The BFA is only used inside a given period ( |
| 26 // * A new BFA isn't used before the last BFA is finished with. |
| 27 // |
| 28 // With the tracing category "cc.debug.scheduler.frames" enabled the tracker |
| 29 // will output the following trace information; |
| 30 // * Time period for which the BFA is in usage. |
| 31 // * The flow of BFA as they are passed between tracking objects. |
| 32 // |
| 33 // TODO(mithro): Record stats about the BeginFrameArgs |
| 34 class CC_EXPORT BeginFrameTracker { |
| 35 public: |
| 36 explicit BeginFrameTracker(const tracked_objects::Location& location); |
| 37 ~BeginFrameTracker(); |
| 38 |
| 39 // The Start and Finish methods manage the period that a BFA should be |
| 40 // accessed for. This allows tight control over the BFA and prevents |
| 41 // accidental usage in the wrong period when code is split across multiple |
| 42 // locations. |
| 43 |
| 44 // Start using a new BFA value and check invariant properties. |
| 45 // **Must** only be called after finishing with any previous BFA. |
| 46 void Start(BeginFrameArgs new_args); |
| 47 // Finish using the current BFA. |
| 48 // **Must** only be called while still using a BFA. |
| 49 void Finish(); |
| 50 |
| 51 // The two accessors methods allow access to the BFA stored inside the |
| 52 // tracker. They are mutually exclusive, at any time it is only valid to call |
| 53 // one or the other. This makes sure you understand exactly which BFA you are |
| 54 // intending to use and verifies that is the case. |
| 55 |
| 56 // Get the current BFA object. |
| 57 // **Must** only be called between the start and finish methods calls. |
| 58 const BeginFrameArgs& Get() const; |
| 59 // Get the last used BFA. |
| 60 // **Must** only be called when **not** between the start and finish method |
| 61 // calls. |
| 62 const BeginFrameArgs& Last() const; |
| 63 |
| 64 // Return if currently not between the start/end period. This method should |
| 65 // be used extremely sparingly and normal indicates incorrect management of |
| 66 // the BFA object. Can be called at any time. |
| 67 // TODO(mithro): Make this method protected/private. |
| 68 bool HasFinished() const { return !current_finished_at_.is_null(); } |
| 69 |
| 70 // Helper method to try and return a valid interval property. Defaults to |
| 71 // BFA::DefaultInterval() is no other interval can be found. Can be called at |
| 72 // any time. |
| 73 base::TimeDelta Interval() const; |
| 74 |
| 75 private: |
| 76 const tracked_objects::Location location_; |
| 77 const std::string location_string_; |
| 78 |
| 79 base::TimeTicks current_updated_at_; |
| 80 BeginFrameArgs current_args_; |
| 81 base::TimeTicks current_finished_at_; |
| 82 }; |
| 83 |
| 84 } // namespace cc |
| 85 |
| 86 #endif // CC_SCHEDULER_BEGIN_FRAME_TRACKER_H_ |
OLD | NEW |