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 CONTENT_COMMON_GPU_GPU_CHANNEL_H_ | 5 #ifndef CONTENT_COMMON_GPU_GPU_CHANNEL_H_ |
6 #define CONTENT_COMMON_GPU_GPU_CHANNEL_H_ | 6 #define CONTENT_COMMON_GPU_GPU_CHANNEL_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/atomicops.h" | |
11 #include "base/containers/scoped_ptr_hash_map.h" | 12 #include "base/containers/scoped_ptr_hash_map.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "base/process/process.h" | 16 #include "base/process/process.h" |
17 #include "base/synchronization/lock.h" | |
18 #include "base/timer/timer.h" | |
16 #include "base/trace_event/memory_dump_provider.h" | 19 #include "base/trace_event/memory_dump_provider.h" |
17 #include "build/build_config.h" | 20 #include "build/build_config.h" |
18 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
19 #include "content/common/gpu/gpu_command_buffer_stub.h" | 22 #include "content/common/gpu/gpu_command_buffer_stub.h" |
20 #include "content/common/gpu/gpu_memory_manager.h" | 23 #include "content/common/gpu/gpu_memory_manager.h" |
21 #include "content/common/gpu/gpu_result_codes.h" | 24 #include "content/common/gpu/gpu_result_codes.h" |
22 #include "content/common/message_router.h" | 25 #include "content/common/message_router.h" |
23 #include "gpu/command_buffer/service/valuebuffer_manager.h" | 26 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
24 #include "ipc/ipc_sync_channel.h" | 27 #include "ipc/ipc_sync_channel.h" |
25 #include "ui/gfx/geometry/size.h" | 28 #include "ui/gfx/geometry/size.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 virtual base::ProcessId GetClientPID() const; | 91 virtual base::ProcessId GetClientPID() const; |
89 | 92 |
90 int client_id() const { return client_id_; } | 93 int client_id() const { return client_id_; } |
91 | 94 |
92 uint64_t client_tracing_id() const { return client_tracing_id_; } | 95 uint64_t client_tracing_id() const { return client_tracing_id_; } |
93 | 96 |
94 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() const { | 97 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() const { |
95 return io_task_runner_; | 98 return io_task_runner_; |
96 } | 99 } |
97 | 100 |
101 // Thread-safe channel message functions. | |
102 bool HasQueuedMessages(); | |
103 base::TimeTicks GetNextMessageTimeTick(); | |
104 void PushBackMessage(uint32_t order_number, const IPC::Message& message); | |
105 void PushFrontMessage(const IPC::Message& message); | |
106 | |
107 // TODO(dyen): Temporary sync point insertion hook. | |
108 void PushSyncPointMessage(uint32_t order_number, const IPC::Message& message, | |
109 bool retire_sync_point, uint32_t sync_point_num); | |
110 | |
111 // Process channel message from main thread. | |
112 void ProcessMessage(uint32_t order_number, const IPC::Message& message); | |
113 | |
98 // IPC::Listener implementation: | 114 // IPC::Listener implementation: |
99 bool OnMessageReceived(const IPC::Message& msg) override; | 115 bool OnMessageReceived(const IPC::Message& msg) override; |
100 void OnChannelError() override; | 116 void OnChannelError() override; |
101 | 117 |
102 // IPC::Sender implementation: | 118 // IPC::Sender implementation: |
103 bool Send(IPC::Message* msg) override; | 119 bool Send(IPC::Message* msg) override; |
104 | 120 |
105 // Requeue the message that is currently being processed to the beginning of | 121 // Requeue the message that is currently being processed to the beginning of |
106 // the queue. Used when the processing of a message gets aborted because of | 122 // the queue. Used when the processing of a message gets aborted because of |
107 // unscheduling conditions. | 123 // unscheduling conditions. |
(...skipping 30 matching lines...) Expand all Loading... | |
138 // Called to add a listener for a particular message routing ID. | 154 // Called to add a listener for a particular message routing ID. |
139 // Returns true if succeeded. | 155 // Returns true if succeeded. |
140 bool AddRoute(int32 route_id, IPC::Listener* listener); | 156 bool AddRoute(int32 route_id, IPC::Listener* listener); |
141 | 157 |
142 // Called to remove a listener for a particular message routing ID. | 158 // Called to remove a listener for a particular message routing ID. |
143 void RemoveRoute(int32 route_id); | 159 void RemoveRoute(int32 route_id); |
144 | 160 |
145 gpu::PreemptionFlag* GetPreemptionFlag(); | 161 gpu::PreemptionFlag* GetPreemptionFlag(); |
146 | 162 |
147 bool handle_messages_scheduled() const { return handle_messages_scheduled_; } | 163 bool handle_messages_scheduled() const { return handle_messages_scheduled_; } |
148 uint64 messages_processed() const { return messages_processed_; } | |
149 | 164 |
150 // If |preemption_flag->IsSet()|, any stub on this channel | 165 // If |preemption_flag->IsSet()|, any stub on this channel |
151 // should stop issuing GL commands. Setting this to NULL stops deferral. | 166 // should stop issuing GL commands. Setting this to NULL stops deferral. |
152 void SetPreemptByFlag( | 167 void SetPreemptByFlag( |
153 scoped_refptr<gpu::PreemptionFlag> preemption_flag); | 168 scoped_refptr<gpu::PreemptionFlag> preemption_flag); |
154 | 169 |
155 void CacheShader(const std::string& key, const std::string& shader); | 170 void CacheShader(const std::string& key, const std::string& shader); |
156 | 171 |
157 virtual void AddFilter(IPC::MessageFilter* filter); | 172 virtual void AddFilter(IPC::MessageFilter* filter); |
158 virtual void RemoveFilter(IPC::MessageFilter* filter); | 173 virtual void RemoveFilter(IPC::MessageFilter* filter); |
159 | 174 |
160 uint64 GetMemoryUsage(); | 175 uint64 GetMemoryUsage(); |
161 | 176 |
162 scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( | 177 scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( |
163 const gfx::GpuMemoryBufferHandle& handle, | 178 const gfx::GpuMemoryBufferHandle& handle, |
164 const gfx::Size& size, | 179 const gfx::Size& size, |
165 gfx::BufferFormat format, | 180 gfx::BufferFormat format, |
166 uint32 internalformat); | 181 uint32 internalformat); |
167 | 182 |
168 bool allow_future_sync_points() const { return allow_future_sync_points_; } | 183 bool allow_future_sync_points() const { return allow_future_sync_points_; } |
169 | 184 |
170 void HandleUpdateValueState(unsigned int target, | 185 void HandleUpdateValueState(unsigned int target, |
171 const gpu::ValueState& state); | 186 const gpu::ValueState& state); |
172 | 187 |
173 // Visible for testing. | 188 // Visible for testing. |
174 const gpu::ValueStateMap* pending_valuebuffer_state() const { | 189 const gpu::ValueStateMap* pending_valuebuffer_state() const { |
175 return pending_valuebuffer_state_.get(); | 190 return pending_valuebuffer_state_.get(); |
176 } | 191 } |
177 | 192 |
193 uint32_t GetCurrentOrderNum() const { return current_order_num_; } | |
194 uint32_t GetProcessedOrderNum() const { return processed_order_num_; } | |
195 uint32_t GetUnprocessedOrderNum() const { | |
196 return base::subtle::Acquire_Load(&unprocessed_order_num_); | |
197 } | |
198 | |
178 protected: | 199 protected: |
179 // The message filter on the io thread. | 200 // The message filter on the io thread. |
180 scoped_refptr<GpuChannelMessageFilter> filter_; | 201 scoped_refptr<GpuChannelMessageFilter> filter_; |
181 | 202 |
182 // Map of routing id to command buffer stub. | 203 // Map of routing id to command buffer stub. |
183 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; | 204 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; |
184 | 205 |
185 private: | 206 private: |
186 friend class GpuChannelMessageFilter; | 207 friend class GpuChannelMessageFilter; |
187 | 208 |
188 void OnDestroy(); | 209 void OnDestroy(); |
189 | 210 |
190 bool OnControlMessageReceived(const IPC::Message& msg); | 211 bool OnControlMessageReceived(const IPC::Message& msg); |
191 | 212 |
192 void HandleMessage(); | 213 void HandleMessage(); |
193 | 214 |
194 // Message handlers. | 215 // Message handlers. |
195 void OnCreateOffscreenCommandBuffer( | 216 void OnCreateOffscreenCommandBuffer( |
196 const gfx::Size& size, | 217 const gfx::Size& size, |
197 const GPUCreateCommandBufferConfig& init_params, | 218 const GPUCreateCommandBufferConfig& init_params, |
198 int32 route_id, | 219 int32 route_id, |
199 bool* succeeded); | 220 bool* succeeded); |
200 void OnDestroyCommandBuffer(int32 route_id); | 221 void OnDestroyCommandBuffer(int32 route_id); |
201 void OnCreateJpegDecoder(int32 route_id, IPC::Message* reply_msg); | 222 void OnCreateJpegDecoder(int32 route_id, IPC::Message* reply_msg); |
202 | 223 |
203 // Decrement the count of unhandled IPC messages and defer preemption. | 224 void PushUnfinishedMessage(uint32_t order_number, |
204 void MessageProcessed(); | 225 const IPC::Message& message); |
226 void ScheduleHandleMessage(); | |
227 void ScheduleHandleMessageLocked(); | |
228 | |
229 // Update processed order number and defer preemption. | |
230 void MessageProcessed(uint32_t order_number); | |
205 | 231 |
206 // The lifetime of objects of this class is managed by a GpuChannelManager. | 232 // The lifetime of objects of this class is managed by a GpuChannelManager. |
207 // The GpuChannelManager destroy all the GpuChannels that they own when they | 233 // The GpuChannelManager destroy all the GpuChannels that they own when they |
208 // are destroyed. So a raw pointer is safe. | 234 // are destroyed. So a raw pointer is safe. |
209 GpuChannelManager* gpu_channel_manager_; | 235 GpuChannelManager* gpu_channel_manager_; |
210 | 236 |
211 scoped_ptr<IPC::SyncChannel> channel_; | 237 scoped_ptr<IPC::SyncChannel> channel_; |
212 | 238 |
213 // Uniquely identifies the channel within this GPU process. | 239 // Uniquely identifies the channel within this GPU process. |
214 std::string channel_id_; | 240 std::string channel_id_; |
215 | 241 |
216 // Used to implement message routing functionality to CommandBuffer objects | 242 // Used to implement message routing functionality to CommandBuffer objects |
217 MessageRouter router_; | 243 MessageRouter router_; |
218 | 244 |
219 uint64 messages_processed_; | |
220 | |
221 // Whether the processing of IPCs on this channel is stalled and we should | 245 // Whether the processing of IPCs on this channel is stalled and we should |
222 // preempt other GpuChannels. | 246 // preempt other GpuChannels. |
223 scoped_refptr<gpu::PreemptionFlag> preempting_flag_; | 247 scoped_refptr<gpu::PreemptionFlag> preempting_flag_; |
224 | 248 |
225 // If non-NULL, all stubs on this channel should stop processing GL | 249 // If non-NULL, all stubs on this channel should stop processing GL |
226 // commands (via their GpuScheduler) when preempted_flag_->IsSet() | 250 // commands (via their GpuScheduler) when preempted_flag_->IsSet() |
227 scoped_refptr<gpu::PreemptionFlag> preempted_flag_; | 251 scoped_refptr<gpu::PreemptionFlag> preempted_flag_; |
228 | 252 |
229 std::deque<IPC::Message*> deferred_messages_; | 253 struct ChannelMessage { |
254 uint32_t order_number; | |
255 base::TimeTicks time_received; | |
256 IPC::Message message; | |
257 | |
258 // TODO(dyen): Temporary sync point data, remove once new sync point lands. | |
259 bool retire_sync_point; | |
260 uint32 sync_point_number; | |
261 | |
262 ChannelMessage(uint32_t order_num, const IPC::Message& msg) | |
263 : order_number(order_num), | |
264 time_received(base::TimeTicks::Now()), | |
265 message(msg), | |
266 retire_sync_point(false), | |
267 sync_point_number(0) {} | |
268 }; | |
piman
2015/08/31 23:15:04
nit: move to before OnDestroy (within each visibli
David Yen
2015/09/01 02:01:52
Done.
| |
269 bool handle_messages_scheduled_; | |
270 std::deque<ChannelMessage*> channel_messages_; | |
271 | |
272 // This lock protects both handle_messages_scheduled_ and channel_messages_. | |
273 base::Lock channel_messages_lock_; | |
274 | |
230 | 275 |
231 // The id of the client who is on the other side of the channel. | 276 // The id of the client who is on the other side of the channel. |
232 int client_id_; | 277 int client_id_; |
233 | 278 |
234 // The tracing ID used for memory allocations associated with this client. | 279 // The tracing ID used for memory allocations associated with this client. |
235 uint64_t client_tracing_id_; | 280 uint64_t client_tracing_id_; |
236 | 281 |
237 // The task runners for the main thread and the io thread. | 282 // The task runners for the main thread and the io thread. |
238 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 283 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
239 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 284 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
240 | 285 |
241 // The share group that all contexts associated with a particular renderer | 286 // The share group that all contexts associated with a particular renderer |
242 // process use. | 287 // process use. |
243 scoped_refptr<gfx::GLShareGroup> share_group_; | 288 scoped_refptr<gfx::GLShareGroup> share_group_; |
244 | 289 |
245 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; | 290 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
246 | 291 |
247 scoped_refptr<gpu::gles2::SubscriptionRefSet> subscription_ref_set_; | 292 scoped_refptr<gpu::gles2::SubscriptionRefSet> subscription_ref_set_; |
248 | 293 |
249 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; | 294 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; |
250 | 295 |
251 scoped_ptr<GpuJpegDecodeAccelerator> jpeg_decoder_; | 296 scoped_ptr<GpuJpegDecodeAccelerator> jpeg_decoder_; |
252 | 297 |
253 gpu::gles2::DisallowedFeatures disallowed_features_; | 298 gpu::gles2::DisallowedFeatures disallowed_features_; |
254 GpuWatchdog* watchdog_; | 299 GpuWatchdog* watchdog_; |
255 bool software_; | 300 bool software_; |
256 bool handle_messages_scheduled_; | 301 ChannelMessage* currently_processing_message_; |
257 IPC::Message* currently_processing_message_; | 302 |
303 // Current IPC order number being processed. | |
304 uint32_t current_order_num_; | |
305 | |
306 // Last finished IPC order number. | |
307 uint32_t processed_order_num_; | |
308 | |
309 // Highest IPC order number seen, set when queued on the IO thread. | |
310 base::subtle::Atomic32 unprocessed_order_num_; | |
piman
2015/08/31 23:15:04
As far as I can tell, this is only used in a DCHEC
David Yen
2015/09/01 02:01:52
This is going to be used later in the actual sync
| |
258 | 311 |
259 size_t num_stubs_descheduled_; | 312 size_t num_stubs_descheduled_; |
260 | |
261 bool allow_future_sync_points_; | 313 bool allow_future_sync_points_; |
262 | 314 |
263 // Member variables should appear before the WeakPtrFactory, to ensure | 315 // Member variables should appear before the WeakPtrFactory, to ensure |
264 // that any WeakPtrs to Controller are invalidated before its members | 316 // that any WeakPtrs to Controller are invalidated before its members |
265 // variable's destructors are executed, rendering them invalid. | 317 // variable's destructors are executed, rendering them invalid. |
266 base::WeakPtrFactory<GpuChannel> weak_factory_; | 318 base::WeakPtrFactory<GpuChannel> weak_factory_; |
267 | 319 |
268 DISALLOW_COPY_AND_ASSIGN(GpuChannel); | 320 DISALLOW_COPY_AND_ASSIGN(GpuChannel); |
269 }; | 321 }; |
270 | 322 |
271 } // namespace content | 323 } // namespace content |
272 | 324 |
273 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ | 325 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ |
OLD | NEW |