Chromium Code Reviews| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 return io_task_runner_; | 99 return io_task_runner_; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // IPC::Listener implementation: | 102 // IPC::Listener implementation: |
| 103 bool OnMessageReceived(const IPC::Message& msg) override; | 103 bool OnMessageReceived(const IPC::Message& msg) override; |
| 104 void OnChannelError() override; | 104 void OnChannelError() override; |
| 105 | 105 |
| 106 // IPC::Sender implementation: | 106 // IPC::Sender implementation: |
| 107 bool Send(IPC::Message* msg) override; | 107 bool Send(IPC::Message* msg) override; |
| 108 | 108 |
| 109 // Requeue the message that is currently being processed to the beginning of | |
| 110 // the queue. Used when the processing of a message gets aborted because of | |
| 111 // unscheduling conditions. | |
| 112 void RequeueMessage(); | |
| 113 | |
| 114 // SubscriptionRefSet::Observer implementation | 109 // SubscriptionRefSet::Observer implementation |
| 115 void OnAddSubscription(unsigned int target) override; | 110 void OnAddSubscription(unsigned int target) override; |
| 116 void OnRemoveSubscription(unsigned int target) override; | 111 void OnRemoveSubscription(unsigned int target) override; |
| 117 | 112 |
| 118 // This is called when a command buffer transitions from the unscheduled | 113 // This is called when a command buffer transitions from the unscheduled |
| 119 // state to the scheduled state, which potentially means the channel | 114 // state to the scheduled state, which potentially means the channel |
| 120 // transitions from the unscheduled to the scheduled state. When this occurs | 115 // transitions from the unscheduled to the scheduled state. When this occurs |
| 121 // deferred IPC messaged are handled. | 116 // deferred IPC messaged are handled. |
| 122 void OnScheduled(); | 117 void OnScheduled(); |
| 123 | 118 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 const gpu::ValueState& state); | 167 const gpu::ValueState& state); |
| 173 | 168 |
| 174 // Visible for testing. | 169 // Visible for testing. |
| 175 const gpu::ValueStateMap* pending_valuebuffer_state() const { | 170 const gpu::ValueStateMap* pending_valuebuffer_state() const { |
| 176 return pending_valuebuffer_state_.get(); | 171 return pending_valuebuffer_state_.get(); |
| 177 } | 172 } |
| 178 | 173 |
| 179 // Visible for testing. | 174 // Visible for testing. |
| 180 GpuChannelMessageFilter* filter() const { return filter_.get(); } | 175 GpuChannelMessageFilter* filter() const { return filter_.get(); } |
| 181 | 176 |
| 182 uint32_t GetCurrentOrderNum() const { return current_order_num_; } | 177 // Returns the global order number for the last processed IPC message. |
| 183 uint32_t GetProcessedOrderNum() const { return processed_order_num_; } | 178 uint32_t GetProcessedOrderNum() const; |
| 179 | |
| 180 // Returns the global order number for the last unprocessed IPC message. | |
| 184 uint32_t GetUnprocessedOrderNum() const; | 181 uint32_t GetUnprocessedOrderNum() const; |
| 185 | 182 |
| 183 void HandleMessage(); | |
| 184 | |
| 186 protected: | 185 protected: |
| 187 // The message filter on the io thread. | 186 // The message filter on the io thread. |
| 188 scoped_refptr<GpuChannelMessageFilter> filter_; | 187 scoped_refptr<GpuChannelMessageFilter> filter_; |
| 189 | 188 |
| 190 // Map of routing id to command buffer stub. | 189 // Map of routing id to command buffer stub. |
| 191 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; | 190 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; |
| 192 | 191 |
| 193 private: | 192 private: |
| 194 class StreamState { | 193 class StreamState { |
| 195 public: | 194 public: |
| 196 StreamState(int32 id, GpuStreamPriority priority); | 195 StreamState(int32 id, GpuStreamPriority priority); |
| 197 ~StreamState(); | 196 ~StreamState(); |
| 198 | 197 |
| 199 int32 id() const { return id_; } | 198 int32 id() const { return id_; } |
| 200 GpuStreamPriority priority() const { return priority_; } | 199 GpuStreamPriority priority() const { return priority_; } |
| 201 | 200 |
| 202 void AddRoute(int32 route_id); | 201 void AddRoute(int32 route_id); |
| 203 void RemoveRoute(int32 route_id); | 202 void RemoveRoute(int32 route_id); |
| 204 bool HasRoute(int32 route_id) const; | 203 bool HasRoute(int32 route_id) const; |
| 205 bool HasRoutes() const; | 204 bool HasRoutes() const; |
| 206 | 205 |
| 207 private: | 206 private: |
| 208 int32 id_; | 207 int32 id_; |
| 209 GpuStreamPriority priority_; | 208 GpuStreamPriority priority_; |
| 210 base::hash_set<int32> routes_; | 209 base::hash_set<int32> routes_; |
| 211 }; | 210 }; |
| 212 | 211 |
| 213 friend class GpuChannelMessageFilter; | |
| 214 friend class GpuChannelMessageQueue; | |
| 215 | |
| 216 void OnDestroy(); | 212 void OnDestroy(); |
| 217 | 213 |
| 218 bool OnControlMessageReceived(const IPC::Message& msg); | 214 bool OnControlMessageReceived(const IPC::Message& msg); |
| 219 | 215 |
| 220 void HandleMessage(); | 216 void ScheduleHandleMessage(); |
| 221 | 217 |
| 222 // Message handlers. | 218 // Message handlers. |
| 223 void OnCreateOffscreenCommandBuffer( | 219 void OnCreateOffscreenCommandBuffer( |
| 224 const gfx::Size& size, | 220 const gfx::Size& size, |
| 225 const GPUCreateCommandBufferConfig& init_params, | 221 const GPUCreateCommandBufferConfig& init_params, |
| 226 int32 route_id, | 222 int32 route_id, |
| 227 bool* succeeded); | 223 bool* succeeded); |
| 228 void OnDestroyCommandBuffer(int32 route_id); | 224 void OnDestroyCommandBuffer(int32 route_id); |
| 229 void OnCreateJpegDecoder(int32 route_id, IPC::Message* reply_msg); | 225 void OnCreateJpegDecoder(int32 route_id, IPC::Message* reply_msg); |
| 230 | 226 |
| 231 // Update processed order number and defer preemption. | |
| 232 void MessageProcessed(uint32_t order_number); | |
| 233 | |
| 234 // The lifetime of objects of this class is managed by a GpuChannelManager. | 227 // The lifetime of objects of this class is managed by a GpuChannelManager. |
| 235 // The GpuChannelManager destroy all the GpuChannels that they own when they | 228 // The GpuChannelManager destroy all the GpuChannels that they own when they |
| 236 // are destroyed. So a raw pointer is safe. | 229 // are destroyed. So a raw pointer is safe. |
| 237 GpuChannelManager* gpu_channel_manager_; | 230 GpuChannelManager* gpu_channel_manager_; |
| 238 | 231 |
| 239 scoped_ptr<IPC::SyncChannel> channel_; | 232 scoped_ptr<IPC::SyncChannel> channel_; |
| 240 | 233 |
| 241 // Uniquely identifies the channel within this GPU process. | 234 // Uniquely identifies the channel within this GPU process. |
| 242 std::string channel_id_; | 235 std::string channel_id_; |
| 243 | 236 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 273 scoped_refptr<gpu::gles2::SubscriptionRefSet> subscription_ref_set_; | 266 scoped_refptr<gpu::gles2::SubscriptionRefSet> subscription_ref_set_; |
| 274 | 267 |
| 275 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; | 268 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; |
| 276 | 269 |
| 277 scoped_ptr<GpuJpegDecodeAccelerator> jpeg_decoder_; | 270 scoped_ptr<GpuJpegDecodeAccelerator> jpeg_decoder_; |
| 278 | 271 |
| 279 gpu::gles2::DisallowedFeatures disallowed_features_; | 272 gpu::gles2::DisallowedFeatures disallowed_features_; |
| 280 GpuWatchdog* watchdog_; | 273 GpuWatchdog* watchdog_; |
| 281 bool software_; | 274 bool software_; |
| 282 | 275 |
| 283 // Current IPC order number being processed. | |
| 284 uint32_t current_order_num_; | |
| 285 | |
| 286 // Last finished IPC order number. | |
| 287 uint32_t processed_order_num_; | |
| 288 | |
| 289 size_t num_stubs_descheduled_; | 276 size_t num_stubs_descheduled_; |
| 290 | 277 |
| 291 // Map of stream id to stream state. | 278 // Map of stream id to stream state. |
| 292 base::hash_map<int32, StreamState> streams_; | 279 base::hash_map<int32, StreamState> streams_; |
| 293 | 280 |
| 294 bool allow_future_sync_points_; | 281 bool allow_future_sync_points_; |
| 295 bool allow_real_time_streams_; | 282 bool allow_real_time_streams_; |
| 296 | 283 |
| 297 // Member variables should appear before the WeakPtrFactory, to ensure | 284 // Member variables should appear before the WeakPtrFactory, to ensure |
| 298 // that any WeakPtrs to Controller are invalidated before its members | 285 // that any WeakPtrs to Controller are invalidated before its members |
| 299 // variable's destructors are executed, rendering them invalid. | 286 // variable's destructors are executed, rendering them invalid. |
| 300 base::WeakPtrFactory<GpuChannel> weak_factory_; | 287 base::WeakPtrFactory<GpuChannel> weak_factory_; |
| 301 | 288 |
| 302 DISALLOW_COPY_AND_ASSIGN(GpuChannel); | 289 DISALLOW_COPY_AND_ASSIGN(GpuChannel); |
| 303 }; | 290 }; |
| 304 | 291 |
| 305 // This filter does three things: | 292 // This filter does three things: |
| 306 // - it counts and timestamps each message forwarded to the channel | 293 // - it counts and timestamps each message forwarded to the channel |
| 307 // so that we can preempt other channels if a message takes too long to | 294 // so that we can preempt other channels if a message takes too long to |
| 308 // process. To guarantee fairness, we must wait a minimum amount of time | 295 // process. To guarantee fairness, we must wait a minimum amount of time |
| 309 // before preempting and we limit the amount of time that we can preempt in | 296 // before preempting and we limit the amount of time that we can preempt in |
| 310 // one shot (see constants above). | 297 // one shot (see constants above). |
| 311 // - it handles the GpuCommandBufferMsg_InsertSyncPoint message on the IO | 298 // - it handles the GpuCommandBufferMsg_InsertSyncPoint message on the IO |
| 312 // thread, generating the sync point ID and responding immediately, and then | 299 // thread, generating the sync point ID and responding immediately, and then |
| 313 // posting a task to insert the GpuCommandBufferMsg_RetireSyncPoint message | 300 // posting a task to insert the GpuCommandBufferMsg_RetireSyncPoint message |
| 314 // into the channel's queue. | 301 // into the channel's queue. |
| 315 // - it generates mailbox names for clients of the GPU process on the IO thread. | 302 // - it generates mailbox names for clients of the GPU process on the IO thread. |
| 316 class GpuChannelMessageFilter : public IPC::MessageFilter { | 303 class GpuChannelMessageFilter : public IPC::MessageFilter { |
| 317 public: | 304 public: |
| 318 GpuChannelMessageFilter( | 305 GpuChannelMessageFilter(GpuChannelMessageQueue* message_queue, |
| 319 scoped_refptr<GpuChannelMessageQueue> message_queue, | 306 gpu::SyncPointManager* sync_point_manager, |
| 320 gpu::SyncPointManager* sync_point_manager, | 307 base::SingleThreadTaskRunner* task_runner, |
| 321 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 308 bool future_sync_points); |
| 322 bool future_sync_points); | |
| 323 | 309 |
| 324 // IPC::MessageFilter implementation. | 310 // IPC::MessageFilter implementation. |
| 325 void OnFilterAdded(IPC::Sender* sender) override; | 311 void OnFilterAdded(IPC::Sender* sender) override; |
| 326 void OnFilterRemoved() override; | 312 void OnFilterRemoved() override; |
| 327 void OnChannelConnected(int32 peer_pid) override; | 313 void OnChannelConnected(int32 peer_pid) override; |
| 328 void OnChannelError() override; | 314 void OnChannelError() override; |
| 329 void OnChannelClosing() override; | 315 void OnChannelClosing() override; |
| 330 bool OnMessageReceived(const IPC::Message& message) override; | 316 bool OnMessageReceived(const IPC::Message& message) override; |
| 331 | 317 |
| 332 void AddChannelFilter(scoped_refptr<IPC::MessageFilter> filter); | 318 void AddChannelFilter(scoped_refptr<IPC::MessageFilter> filter); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 | 376 |
| 391 bool a_stub_is_descheduled_; | 377 bool a_stub_is_descheduled_; |
| 392 | 378 |
| 393 // True if this channel can create future sync points. | 379 // True if this channel can create future sync points. |
| 394 bool future_sync_points_; | 380 bool future_sync_points_; |
| 395 | 381 |
| 396 // This number is only ever incremented/read on the IO thread. | 382 // This number is only ever incremented/read on the IO thread. |
| 397 static uint32_t global_order_counter_; | 383 static uint32_t global_order_counter_; |
| 398 }; | 384 }; |
| 399 | 385 |
| 386 struct GpuChannelMessage { | |
| 387 uint32_t order_number; | |
| 388 base::TimeTicks time_received; | |
| 389 IPC::Message message; | |
| 390 | |
| 391 // TODO(dyen): Temporary sync point data, remove once new sync point lands. | |
| 392 bool retire_sync_point; | |
| 393 uint32 sync_point; | |
| 394 | |
| 395 GpuChannelMessage(uint32_t order_num, const IPC::Message& msg) | |
| 396 : order_number(order_num), | |
| 397 time_received(base::TimeTicks::Now()), | |
| 398 message(msg), | |
| 399 retire_sync_point(false), | |
| 400 sync_point(0) {} | |
| 401 }; | |
| 402 | |
| 403 class GpuChannelMessageQueue | |
| 404 : public base::RefCountedThreadSafe<GpuChannelMessageQueue> { | |
| 405 public: | |
| 406 static scoped_refptr<GpuChannelMessageQueue> Create( | |
| 407 const base::WeakPtr<GpuChannel>& gpu_channel, | |
| 408 base::SingleThreadTaskRunner* task_runner); | |
| 409 | |
| 410 // Returns the global order number for the last processed IPC message. | |
| 411 uint32_t GetUnprocessedOrderNum() const; | |
| 412 | |
| 413 // Returns the global order number for the last unprocessed IPC message. | |
| 414 uint32_t processed_order_num() const { return processed_order_num_; } | |
| 415 | |
| 416 // Returns the global order number for the next IPC message to be processed. | |
| 417 uint32_t current_order_num() const { return current_order_num_; } | |
| 418 | |
| 419 bool HasQueuedMessages() const; | |
| 420 | |
| 421 base::TimeTicks GetNextMessageTimeTick() const; | |
| 422 | |
| 423 GpuChannelMessage* GetNextMessage() const; | |
| 424 | |
| 425 // Should be called after a message returned by GetNextMessage is processed. | |
| 426 // Returns true if there are more messages on the queue. | |
| 427 bool MessageProcessed(uint32_t order_number); | |
| 428 | |
| 429 void PushBackMessage(uint32_t order_number, const IPC::Message& message); | |
| 430 | |
| 431 bool GenerateSyncPointMessage(gpu::SyncPointManager* sync_point_manager, | |
| 432 uint32_t order_number, | |
| 433 const IPC::Message& message, | |
| 434 bool retire_sync_point, | |
| 435 uint32_t* sync_point_number); | |
| 436 | |
| 437 void DeleteAndDisableMessages(GpuChannelManager* gpu_channel_manager); | |
| 438 | |
| 439 private: | |
| 440 friend class base::RefCountedThreadSafe<GpuChannelMessageQueue>; | |
| 441 | |
| 442 GpuChannelMessageQueue(const base::WeakPtr<GpuChannel>& gpu_channel, | |
| 443 base::SingleThreadTaskRunner* task_runner); | |
| 444 ~GpuChannelMessageQueue(); | |
| 445 | |
| 446 void ScheduleHandleMessage(); | |
| 447 | |
| 448 void PushMessageHelper(scoped_ptr<GpuChannelMessage> msg); | |
| 449 | |
| 450 bool HasQueuedMessagesHelper() const; | |
| 451 | |
| 452 bool enabled_; | |
| 453 | |
| 454 // Highest IPC order number seen, set when queued on the IO thread. | |
| 455 uint32_t unprocessed_order_num_; | |
| 456 // Both deques own the messages. | |
| 457 std::deque<GpuChannelMessage*> channel_messages_; | |
| 458 std::deque<GpuChannelMessage*> out_of_order_messages_; | |
| 459 | |
| 460 // This lock protects enabled_, unprocessed_order_num_, and both deques. | |
| 461 mutable base::Lock channel_messages_lock_; | |
| 462 | |
| 463 // Last finished IPC order number. Not protected by a lock as it's only | |
| 464 // accessed on the main thread. | |
| 465 uint32_t processed_order_num_; | |
| 466 | |
| 467 // Next unprocessed IPC message order number. Not protected by a lock as it's | |
| 468 // only accessed on the main thread. | |
| 469 uint32_t current_order_num_; | |
|
piman
2015/09/11 00:38:33
This is not referenced anywhere anymore. Remove/re
sunnyps
2015/09/11 01:53:22
Done.
| |
| 470 | |
| 471 base::WeakPtr<GpuChannel> gpu_channel_; | |
| 472 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 473 | |
| 474 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageQueue); | |
| 475 }; | |
| 476 | |
| 400 } // namespace content | 477 } // namespace content |
| 401 | 478 |
| 402 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ | 479 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ |
| OLD | NEW |