OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef Scheduler_h | 5 #ifndef Scheduler_h |
6 #define Scheduler_h | 6 #define Scheduler_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "platform/TraceLocation.h" | 9 #include "platform/TraceLocation.h" |
10 #include "wtf/DoubleBufferedDeque.h" | 10 #include "wtf/DoubleBufferedDeque.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 // Called to notify that a previously begun frame was committed. | 36 // Called to notify that a previously begun frame was committed. |
37 void didCommitFrameToCompositor(); | 37 void didCommitFrameToCompositor(); |
38 | 38 |
39 // The following entrypoints are used to schedule different types of tasks | 39 // The following entrypoints are used to schedule different types of tasks |
40 // to be run on the main thread. They can be called from any thread. | 40 // to be run on the main thread. They can be called from any thread. |
41 void postInputTask(const TraceLocation&, const Task&); | 41 void postInputTask(const TraceLocation&, const Task&); |
42 void postCompositorTask(const TraceLocation&, const Task&); | 42 void postCompositorTask(const TraceLocation&, const Task&); |
43 void postTask(const TraceLocation&, const Task&); // For generic (low priori ty) tasks. | 43 void postTask(const TraceLocation&, const Task&); // For generic (low priori ty) tasks. |
44 void postIdleTask(const TraceLocation&, const IdleTask&); // For non-critica l tasks which may be reordered relative to other task types. | 44 void postIdleTask(const TraceLocation&, const IdleTask&); // For non-critica l tasks which may be reordered relative to other task types. |
45 | 45 |
46 // Returns true if there is high priority work pending on the main thread | 46 // Returns true if we're in low latency mode and there is high priority work pending on the |
47 // and the caller should yield to let the scheduler service that work. | 47 // main thread and the caller should yield to let the scheduler service that work. |
48 // Can be called on any thread. | 48 // Can be called on any thread. |
49 bool shouldYieldForHighPriorityWork() const; | 49 bool shouldYieldForHighPriorityWork() const; |
50 | 50 |
51 // The shared timer can be used to schedule a periodic callback which may | 51 // The shared timer can be used to schedule a periodic callback which may |
52 // get preempted by higher priority work. | 52 // get preempted by higher priority work. |
53 void setSharedTimerFiredFunction(void (*function)()); | 53 void setSharedTimerFiredFunction(void (*function)()); |
54 void setSharedTimerFireInterval(double); | 54 void setSharedTimerFireInterval(double); |
55 void stopSharedTimer(); | 55 void stopSharedTimer(); |
56 | 56 |
57 private: | 57 private: |
58 class MainThreadPendingTaskRunner; | 58 class MainThreadPendingTaskRunner; |
59 class MainThreadPendingHighPriorityTaskRunner; | 59 class MainThreadPendingHighPriorityTaskRunner; |
60 friend class MainThreadPendingTaskRunner; | 60 friend class MainThreadPendingTaskRunner; |
61 friend class MainThreadPendingHighPriorityTaskRunner; | 61 friend class MainThreadPendingHighPriorityTaskRunner; |
62 | 62 |
63 enum LatencyMode { | |
64 Normal, | |
65 LowLatency, | |
eseidel
2014/09/10 16:09:01
What does LowLatency mode mean? Maybe just a comm
| |
66 }; | |
67 | |
63 class TracedTask { | 68 class TracedTask { |
64 public: | 69 public: |
65 TracedTask(const Task& task, const TraceLocation& location) | 70 TracedTask(const Task& task, const TraceLocation& location) |
66 : m_task(task) | 71 : m_task(task) |
67 , m_location(location) { } | 72 , m_location(location) { } |
68 | 73 |
69 void run(); | 74 void run(); |
70 | 75 |
71 private: | 76 private: |
72 Task m_task; | 77 Task m_task; |
73 TraceLocation m_location; | 78 TraceLocation m_location; |
74 }; | 79 }; |
75 | 80 |
76 Scheduler(); | 81 Scheduler(); |
77 ~Scheduler(); | 82 ~Scheduler(); |
78 | 83 |
79 void scheduleIdleTask(const TraceLocation&, const IdleTask&); | 84 void scheduleIdleTask(const TraceLocation&, const IdleTask&); |
80 | 85 |
81 static void sharedTimerAdapter(); | 86 static void sharedTimerAdapter(); |
82 void tickSharedTimer(); | 87 void tickSharedTimer(); |
83 | 88 |
84 bool hasPendingHighPriorityWork() const; | 89 bool hasPendingHighPriorityWork() const; |
90 | |
91 // Only does work in low latency mode. Returns true if any work was done. | |
92 bool runPendingHighPrioirtyTasksIfInLowLatencyMode(); | |
93 | |
94 // Returns true if any work was done. | |
85 bool swapQueuesAndRunPendingTasks(); | 95 bool swapQueuesAndRunPendingTasks(); |
86 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); | 96 void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting(); |
87 | 97 |
88 // Returns true if any work was done. | 98 // Returns true if any work was done. |
89 bool executeHighPriorityTasks(Deque<TracedTask>&); | 99 bool executeHighPriorityTasks(Deque<TracedTask>&); |
90 | 100 |
91 // Must be called while m_pendingTasksMutex is locked. | 101 // Must be called while m_pendingTasksMutex is locked. |
92 void maybePostMainThreadPendingHighPriorityTaskRunner(); | 102 void maybePostMainThreadPendingHighPriorityTaskRunner(); |
93 | 103 |
94 static Scheduler* s_sharedScheduler; | 104 static Scheduler* s_sharedScheduler; |
95 | 105 |
96 // Should only be accessed from the main thread. | 106 // Should only be accessed from the main thread. |
97 void (*m_sharedTimerFunction)(); | 107 void (*m_sharedTimerFunction)(); |
98 | 108 |
109 // Should only be accessed from the main thread. | |
110 LatencyMode latencyMode() const; | |
111 | |
112 // Can be called from any thread. | |
113 void setLatencyMode(LatencyMode); | |
114 | |
99 // These members can be accessed from any thread. | 115 // These members can be accessed from any thread. |
100 WebThread* m_mainThread; | 116 WebThread* m_mainThread; |
101 | 117 |
102 // This mutex protects calls to the pending task queue and m_highPriorityTas kRunnerPosted. | 118 // This mutex protects calls to the pending task queue and m_highPriorityTas kRunnerPosted. |
103 Mutex m_pendingTasksMutex; | 119 Mutex m_pendingTasksMutex; |
104 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; | 120 DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks; |
105 | 121 |
106 volatile int m_highPriorityTaskCount; | 122 volatile int m_highPriorityTaskCount; |
107 bool m_highPriorityTaskRunnerPosted; | 123 bool m_highPriorityTaskRunnerPosted; |
124 | |
125 volatile int m_latencyMode; | |
126 double m_lowLatencyModeEndTimeSeconds; | |
127 | |
128 // The time we should stay in low latency mode for after a touch event. | |
129 static double s_lowLatencyModeAfterTouchTimeSeconds; | |
108 }; | 130 }; |
109 | 131 |
110 } // namespace blink | 132 } // namespace blink |
111 | 133 |
112 #endif // Scheduler_h | 134 #endif // Scheduler_h |
OLD | NEW |