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. |
|
David Yen
2015/09/10 21:23:04
Was this accidentally deleted? I'm using this in m
sunnyps
2015/09/10 23:38:36
Done. Renamed to current_order_num per naming conv
| |
| 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 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 | 377 |
| 391 bool a_stub_is_descheduled_; | 378 bool a_stub_is_descheduled_; |
| 392 | 379 |
| 393 // True if this channel can create future sync points. | 380 // True if this channel can create future sync points. |
| 394 bool future_sync_points_; | 381 bool future_sync_points_; |
| 395 | 382 |
| 396 // This number is only ever incremented/read on the IO thread. | 383 // This number is only ever incremented/read on the IO thread. |
| 397 static uint32_t global_order_counter_; | 384 static uint32_t global_order_counter_; |
| 398 }; | 385 }; |
| 399 | 386 |
| 387 struct GpuChannelMessage { | |
| 388 uint32_t order_number; | |
| 389 base::TimeTicks time_received; | |
| 390 IPC::Message message; | |
| 391 | |
| 392 // TODO(dyen): Temporary sync point data, remove once new sync point lands. | |
| 393 bool retire_sync_point; | |
| 394 uint32 sync_point; | |
| 395 | |
| 396 GpuChannelMessage(uint32_t order_num, const IPC::Message& msg) | |
| 397 : order_number(order_num), | |
| 398 time_received(base::TimeTicks::Now()), | |
| 399 message(msg), | |
| 400 retire_sync_point(false), | |
| 401 sync_point(0) {} | |
| 402 }; | |
| 403 | |
| 404 class GpuChannelMessageQueue | |
| 405 : public base::RefCountedThreadSafe<GpuChannelMessageQueue> { | |
| 406 public: | |
| 407 static scoped_refptr<GpuChannelMessageQueue> Create( | |
| 408 base::WeakPtr<GpuChannel> gpu_channel, | |
|
dcheng
2015/09/10 21:30:37
const base::WeakPtr<GpuChannel>& here and in the c
sunnyps
2015/09/10 23:38:36
Done. Also removed the unnecessary refcounting her
| |
| 409 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 410 | |
| 411 // Returns the global order number for the last processed IPC message. | |
| 412 uint32_t GetUnprocessedOrderNum() const; | |
| 413 | |
| 414 // Returns the global order number for the last unprocessed IPC message. | |
| 415 uint32_t GetProccessedOrderNum() const; | |
|
dcheng
2015/09/10 21:30:37
FWIW, simple accessors are usually inline and name
sunnyps
2015/09/10 23:38:36
Done.
| |
| 416 | |
| 417 bool HasQueuedMessages() const; | |
| 418 | |
| 419 base::TimeTicks GetNextMessageTimeTick() const; | |
| 420 | |
| 421 GpuChannelMessage* GetNextMessage() const; | |
| 422 | |
| 423 // Should be called after a message returned by GetNextMessage is processed. | |
| 424 // Returns true if there are more messages on the queue. | |
| 425 bool MessageProcessed(uint32_t order_number); | |
| 426 | |
| 427 void PushBackMessage(uint32_t order_number, const IPC::Message& message); | |
| 428 | |
| 429 bool GenerateSyncPointMessage(gpu::SyncPointManager* sync_point_manager, | |
| 430 uint32_t order_number, | |
| 431 const IPC::Message& message, | |
| 432 bool retire_sync_point, | |
| 433 uint32_t* sync_point_number); | |
| 434 | |
| 435 void DeleteAndDisableMessages(GpuChannelManager* gpu_channel_manager); | |
| 436 | |
| 437 private: | |
| 438 friend class base::RefCountedThreadSafe<GpuChannelMessageQueue>; | |
| 439 | |
| 440 GpuChannelMessageQueue( | |
| 441 base::WeakPtr<GpuChannel> gpu_channel, | |
| 442 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 443 ~GpuChannelMessageQueue(); | |
| 444 | |
| 445 void ScheduleHandleMessage(); | |
| 446 | |
| 447 void PushMessageHelper(GpuChannelMessage* msg); | |
|
dcheng
2015/09/10 21:30:37
scoped_ptr<GpuChannelMessage> msg to make the owne
sunnyps
2015/09/10 23:38:36
Done.
| |
| 448 | |
| 449 bool HasQueuedMessagesHelper() const; | |
| 450 | |
| 451 bool enabled_; | |
| 452 | |
| 453 // Highest IPC order number seen, set when queued on the IO thread. | |
| 454 uint32_t unprocessed_order_num_; | |
| 455 std::deque<GpuChannelMessage*> channel_messages_; | |
|
dcheng
2015/09/10 21:30:37
Ownership semantics for these members should be do
sunnyps
2015/09/10 23:38:36
Done.
| |
| 456 std::deque<GpuChannelMessage*> out_of_order_messages_; | |
| 457 | |
| 458 // This lock protects enabled_, unprocessed_order_num_, and both deques. | |
| 459 mutable base::Lock channel_messages_lock_; | |
| 460 | |
| 461 // Last finished IPC order number. Not protected by a lock as it's only | |
| 462 // accessed on the main thread. | |
| 463 uint32_t processed_order_num_; | |
| 464 | |
| 465 base::WeakPtr<GpuChannel> gpu_channel_; | |
| 466 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 467 | |
| 468 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageQueue); | |
| 469 }; | |
| 470 | |
| 400 } // namespace content | 471 } // namespace content |
| 401 | 472 |
| 402 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ | 473 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ |
| OLD | NEW |