OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/atomic_ref_count.h" | 10 #include "base/atomic_ref_count.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 ~GpuScheduler() override; | 59 ~GpuScheduler() override; |
60 | 60 |
61 void PutChanged(); | 61 void PutChanged(); |
62 | 62 |
63 void SetPreemptByFlag(scoped_refptr<PreemptionFlag> flag) { | 63 void SetPreemptByFlag(scoped_refptr<PreemptionFlag> flag) { |
64 preemption_flag_ = flag; | 64 preemption_flag_ = flag; |
65 } | 65 } |
66 | 66 |
67 // Sets whether commands should be processed by this scheduler. Setting to | 67 // Sets whether commands should be processed by this scheduler. Setting to |
68 // false unschedules. Setting to true reschedules. Whether or not the | 68 // false unschedules. Setting to true reschedules. |
69 // scheduler is currently scheduled is "reference counted". Every call with | 69 void SetScheduled(bool scheduled); |
70 // false must eventually be paired by a call with true. | |
71 void SetScheduled(bool is_scheduled); | |
72 | 70 |
73 // Returns whether the scheduler is currently able to process more commands. | 71 bool scheduled() const { return scheduled_; } |
74 bool IsScheduled(); | |
75 | 72 |
76 // Returns whether the scheduler needs to be polled again in the future to | 73 // Returns whether the scheduler needs to be polled again in the future to |
77 // process pending queries. | 74 // process pending queries. |
78 bool HasPendingQueries() const; | 75 bool HasPendingQueries() const; |
79 | 76 |
80 // Process pending queries and return. HasPendingQueries() can be used to | 77 // Process pending queries and return. HasPendingQueries() can be used to |
81 // determine if there's more pending queries after this has been called. | 78 // determine if there's more pending queries after this has been called. |
82 void ProcessPendingQueries(); | 79 void ProcessPendingQueries(); |
83 | 80 |
84 typedef base::Callback<void(bool /* scheduled */)> SchedulingChangedCallback; | 81 typedef base::Callback<void(bool /* scheduled */)> SchedulingChangedCallback; |
(...skipping 17 matching lines...) Expand all Loading... |
102 | 99 |
103 // Perform some idle work and return. HasMoreIdleWork() can be used to | 100 // Perform some idle work and return. HasMoreIdleWork() can be used to |
104 // determine if there's more idle work do be done after this has been called. | 101 // determine if there's more idle work do be done after this has been called. |
105 void PerformIdleWork(); | 102 void PerformIdleWork(); |
106 | 103 |
107 CommandParser* parser() const { | 104 CommandParser* parser() const { |
108 return parser_.get(); | 105 return parser_.get(); |
109 } | 106 } |
110 | 107 |
111 private: | 108 private: |
112 // Artificially reschedule if the scheduler is still unscheduled after a | |
113 // timeout. | |
114 void RescheduleTimeOut(); | |
115 | |
116 bool IsPreempted(); | 109 bool IsPreempted(); |
117 | 110 |
118 // The GpuScheduler holds a weak reference to the CommandBuffer. The | 111 // The GpuScheduler holds a weak reference to the CommandBuffer. The |
119 // CommandBuffer owns the GpuScheduler and holds a strong reference to it | 112 // CommandBuffer owns the GpuScheduler and holds a strong reference to it |
120 // through the ProcessCommands callback. | 113 // through the ProcessCommands callback. |
121 CommandBufferServiceBase* command_buffer_; | 114 CommandBufferServiceBase* command_buffer_; |
122 | 115 |
123 // The parser uses this to execute commands. | 116 // The parser uses this to execute commands. |
124 AsyncAPIInterface* handler_; | 117 AsyncAPIInterface* handler_; |
125 | 118 |
126 // Does not own decoder. TODO(apatrick): The GpuScheduler shouldn't need a | 119 // Does not own decoder. TODO(apatrick): The GpuScheduler shouldn't need a |
127 // pointer to the decoder, it is only used to initialize the CommandParser, | 120 // pointer to the decoder, it is only used to initialize the CommandParser, |
128 // which could be an argument to the constructor, and to determine the | 121 // which could be an argument to the constructor, and to determine the |
129 // reason for context lost. | 122 // reason for context lost. |
130 gles2::GLES2Decoder* decoder_; | 123 gles2::GLES2Decoder* decoder_; |
131 | 124 |
132 // TODO(apatrick): The GpuScheduler currently creates and owns the parser. | 125 // TODO(apatrick): The GpuScheduler currently creates and owns the parser. |
133 // This should be an argument to the constructor. | 126 // This should be an argument to the constructor. |
134 scoped_ptr<CommandParser> parser_; | 127 scoped_ptr<CommandParser> parser_; |
135 | 128 |
136 // Greater than zero if this is waiting to be rescheduled before continuing. | 129 // Whether the scheduler is currently able to process more commands. |
137 int unscheduled_count_; | 130 bool scheduled_; |
138 | |
139 // The number of times this scheduler has been artificially rescheduled on | |
140 // account of a timeout. | |
141 int rescheduled_count_; | |
142 | 131 |
143 SchedulingChangedCallback scheduling_changed_callback_; | 132 SchedulingChangedCallback scheduling_changed_callback_; |
144 base::Closure descheduled_callback_; | 133 base::Closure descheduled_callback_; |
145 base::Closure command_processed_callback_; | 134 base::Closure command_processed_callback_; |
146 | 135 |
147 // If non-NULL and |preemption_flag_->IsSet()|, exit PutChanged early. | 136 // If non-NULL and |preemption_flag_->IsSet()|, exit PutChanged early. |
148 scoped_refptr<PreemptionFlag> preemption_flag_; | 137 scoped_refptr<PreemptionFlag> preemption_flag_; |
149 bool was_preempted_; | 138 bool was_preempted_; |
150 | 139 |
151 // A factory for outstanding rescheduling tasks that is invalidated whenever | |
152 // the scheduler is rescheduled. | |
153 base::WeakPtrFactory<GpuScheduler> reschedule_task_factory_; | |
154 | |
155 DISALLOW_COPY_AND_ASSIGN(GpuScheduler); | 140 DISALLOW_COPY_AND_ASSIGN(GpuScheduler); |
156 }; | 141 }; |
157 | 142 |
158 } // namespace gpu | 143 } // namespace gpu |
159 | 144 |
160 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ | 145 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ |
OLD | NEW |