Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: gpu/ipc/service/gpu_channel.h

Issue 2870333003: gpu: Remove gpu channel filter and queue from header. (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gpu/ipc/service/gpu_channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_IPC_SERVICE_GPU_CHANNEL_H_ 5 #ifndef GPU_IPC_SERVICE_GPU_CHANNEL_H_
6 #define GPU_IPC_SERVICE_GPU_CHANNEL_H_ 6 #define GPU_IPC_SERVICE_GPU_CHANNEL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 GpuChannelManager* gpu_channel_manager() const { 107 GpuChannelManager* gpu_channel_manager() const {
108 return gpu_channel_manager_; 108 return gpu_channel_manager_;
109 } 109 }
110 110
111 Scheduler* scheduler() const { return scheduler_; } 111 Scheduler* scheduler() const { return scheduler_; }
112 112
113 SyncPointManager* sync_point_manager() const { return sync_point_manager_; } 113 SyncPointManager* sync_point_manager() const { return sync_point_manager_; }
114 114
115 GpuWatchdogThread* watchdog() const { return watchdog_; } 115 GpuWatchdogThread* watchdog() const { return watchdog_; }
116 116
117 const scoped_refptr<GpuChannelMessageFilter>& filter() const {
118 return filter_;
119 }
120
121 const scoped_refptr<gles2::MailboxManager>& mailbox_manager() const { 117 const scoped_refptr<gles2::MailboxManager>& mailbox_manager() const {
122 return mailbox_manager_; 118 return mailbox_manager_;
123 } 119 }
124 120
125 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner() const { 121 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner() const {
126 return task_runner_; 122 return task_runner_;
127 } 123 }
128 124
129 const scoped_refptr<PreemptionFlag>& preempted_flag() const { 125 const scoped_refptr<PreemptionFlag>& preempted_flag() const {
130 return preempted_flag_; 126 return preempted_flag_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void HandleMessage(const IPC::Message& msg); 181 void HandleMessage(const IPC::Message& msg);
186 182
187 // Handle messages enqueued in |message_queue_|. 183 // Handle messages enqueued in |message_queue_|.
188 void HandleMessageOnQueue(); 184 void HandleMessageOnQueue();
189 185
190 // Some messages such as WaitForGetOffsetInRange and WaitForTokenInRange are 186 // Some messages such as WaitForGetOffsetInRange and WaitForTokenInRange are
191 // processed as soon as possible because the client is blocked until they 187 // processed as soon as possible because the client is blocked until they
192 // are completed. 188 // are completed.
193 void HandleOutOfOrderMessage(const IPC::Message& msg); 189 void HandleOutOfOrderMessage(const IPC::Message& msg);
194 190
191 void HandleMessageForTesting(const IPC::Message& msg);
192
195 #if defined(OS_ANDROID) 193 #if defined(OS_ANDROID)
196 const GpuCommandBufferStub* GetOneStub() const; 194 const GpuCommandBufferStub* GetOneStub() const;
197 #endif 195 #endif
198 196
199 private: 197 private:
200 bool OnControlMessageReceived(const IPC::Message& msg); 198 bool OnControlMessageReceived(const IPC::Message& msg);
201 199
202 void HandleMessageHelper(const IPC::Message& msg); 200 void HandleMessageHelper(const IPC::Message& msg);
203 201
204 // Message handlers for control messages. 202 // Message handlers for control messages.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 const bool is_gpu_host_; 274 const bool is_gpu_host_;
277 275
278 // Member variables should appear before the WeakPtrFactory, to ensure that 276 // Member variables should appear before the WeakPtrFactory, to ensure that
279 // any WeakPtrs to Controller are invalidated before its members variable's 277 // any WeakPtrs to Controller are invalidated before its members variable's
280 // destructors are executed, rendering them invalid. 278 // destructors are executed, rendering them invalid.
281 base::WeakPtrFactory<GpuChannel> weak_factory_; 279 base::WeakPtrFactory<GpuChannel> weak_factory_;
282 280
283 DISALLOW_COPY_AND_ASSIGN(GpuChannel); 281 DISALLOW_COPY_AND_ASSIGN(GpuChannel);
284 }; 282 };
285 283
286 // This filter does the following:
287 // - handles the Nop message used for verifying sync tokens on the IO thread
288 // - forwards messages to child message filters
289 // - posts control and out of order messages to the main thread
290 // - forwards other messages to the message queue or the scheduler
291 class GPU_EXPORT GpuChannelMessageFilter : public IPC::MessageFilter {
292 public:
293 GpuChannelMessageFilter(
294 GpuChannel* gpu_channel,
295 Scheduler* scheduler,
296 scoped_refptr<GpuChannelMessageQueue> message_queue,
297 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);
298
299 // Methods called on main thread.
300 void Destroy();
301
302 // Called when scheduler is enabled.
303 void AddRoute(int32_t route_id, SequenceId sequence_id);
304 void RemoveRoute(int32_t route_id);
305
306 // Methods called on IO thread.
307 // IPC::MessageFilter implementation.
308 void OnFilterAdded(IPC::Channel* channel) override;
309 void OnFilterRemoved() override;
310 void OnChannelConnected(int32_t peer_pid) override;
311 void OnChannelError() override;
312 void OnChannelClosing() override;
313 bool OnMessageReceived(const IPC::Message& message) override;
314
315 void AddChannelFilter(scoped_refptr<IPC::MessageFilter> filter);
316 void RemoveChannelFilter(scoped_refptr<IPC::MessageFilter> filter);
317
318 bool Send(IPC::Message* message);
319
320 private:
321 ~GpuChannelMessageFilter() override;
322
323 bool MessageErrorHandler(const IPC::Message& message, const char* error_msg);
324
325 IPC::Channel* ipc_channel_ = nullptr;
326 base::ProcessId peer_pid_ = base::kNullProcessId;
327 std::vector<scoped_refptr<IPC::MessageFilter>> channel_filters_;
328
329 GpuChannel* gpu_channel_ = nullptr;
330 // Map of route id to scheduler sequence id.
331 base::flat_map<int32_t, SequenceId> route_sequences_;
332 mutable base::Lock gpu_channel_lock_;
333
334 Scheduler* scheduler_;
335 scoped_refptr<GpuChannelMessageQueue> message_queue_;
336 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
337
338 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageFilter);
339 };
340
341 struct GpuChannelMessage {
342 IPC::Message message;
343 uint32_t order_number;
344 base::TimeTicks time_received;
345
346 GpuChannelMessage(const IPC::Message& msg,
347 uint32_t order_num,
348 base::TimeTicks ts)
349 : message(msg), order_number(order_num), time_received(ts) {}
350
351 private:
352 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessage);
353 };
354
355 // This message queue counts and timestamps each message forwarded to the
356 // channel so that we can preempt other channels if a message takes too long to
357 // process. To guarantee fairness, we must wait a minimum amount of time before
358 // preempting and we limit the amount of time that we can preempt in one shot
359 // (see constants above).
360 class GpuChannelMessageQueue
361 : public base::RefCountedThreadSafe<GpuChannelMessageQueue> {
362 public:
363 GpuChannelMessageQueue(
364 GpuChannel* channel,
365 scoped_refptr<SyncPointOrderData> sync_point_order_data,
366 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
367 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
368 scoped_refptr<PreemptionFlag> preempting_flag,
369 scoped_refptr<PreemptionFlag> preempted_flag);
370
371 void Destroy();
372
373 SequenceId sequence_id() const {
374 return sync_point_order_data_->sequence_id();
375 }
376
377 bool IsScheduled() const;
378 void SetScheduled(bool scheduled);
379
380 // Should be called before a message begins to be processed. Returns false if
381 // there are no messages to process.
382 const GpuChannelMessage* BeginMessageProcessing();
383 // Should be called if a message began processing but did not finish.
384 void PauseMessageProcessing();
385 // Should be called if a message is completely processed. Returns true if
386 // there are more messages to process.
387 void FinishMessageProcessing();
388
389 void PushBackMessage(const IPC::Message& message);
390
391 private:
392 enum PreemptionState {
393 // Either there's no other channel to preempt, there are no messages
394 // pending processing, or we just finished preempting and have to wait
395 // before preempting again.
396 IDLE,
397 // We are waiting kPreemptWaitTimeMs before checking if we should preempt.
398 WAITING,
399 // We can preempt whenever any IPC processing takes more than
400 // kPreemptWaitTimeMs.
401 CHECKING,
402 // We are currently preempting (i.e. no stub is descheduled).
403 PREEMPTING,
404 // We would like to preempt, but some stub is descheduled.
405 WOULD_PREEMPT_DESCHEDULED,
406 };
407
408 friend class base::RefCountedThreadSafe<GpuChannelMessageQueue>;
409
410 ~GpuChannelMessageQueue();
411
412 void PostHandleMessageOnQueue();
413
414 void UpdatePreemptionState();
415 void UpdatePreemptionStateHelper();
416
417 void UpdateStateIdle();
418 void UpdateStateWaiting();
419 void UpdateStateChecking();
420 void UpdateStatePreempting();
421 void UpdateStateWouldPreemptDescheduled();
422
423 void TransitionToIdle();
424 void TransitionToWaiting();
425 void TransitionToChecking();
426 void TransitionToPreempting();
427 void TransitionToWouldPreemptDescheduled();
428
429 bool ShouldTransitionToIdle() const;
430
431 // These can be accessed from both IO and main threads and are protected by
432 // |channel_lock_|.
433 bool scheduled_ = true;
434 GpuChannel* channel_ = nullptr; // set to nullptr on Destroy
435 std::deque<std::unique_ptr<GpuChannelMessage>> channel_messages_;
436 bool handle_message_post_task_pending_ = false;
437 mutable base::Lock channel_lock_;
438
439 // The following are accessed on the IO thread only.
440 // No lock is necessary for preemption state because it's only accessed on the
441 // IO thread.
442 PreemptionState preemption_state_ = IDLE;
443 // Maximum amount of time that we can spend in PREEMPTING.
444 // It is reset when we transition to IDLE.
445 base::TimeDelta max_preemption_time_;
446 // This timer is used and runs tasks on the IO thread.
447 std::unique_ptr<base::OneShotTimer> timer_;
448 base::ThreadChecker io_thread_checker_;
449
450 // Keeps track of sync point related state such as message order numbers.
451 scoped_refptr<SyncPointOrderData> sync_point_order_data_;
452
453 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
454 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
455 scoped_refptr<PreemptionFlag> preempting_flag_;
456 scoped_refptr<PreemptionFlag> preempted_flag_;
457
458 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageQueue);
459 };
460
461 } // namespace gpu 284 } // namespace gpu
462 285
463 #endif // GPU_IPC_SERVICE_GPU_CHANNEL_H_ 286 #endif // GPU_IPC_SERVICE_GPU_CHANNEL_H_
OLDNEW
« no previous file with comments | « no previous file | gpu/ipc/service/gpu_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698