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

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

Issue 2772513005: gpu: Move out of order / control message handling to message filter. (Closed)
Patch Set: Created 3 years, 9 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') | gpu/ipc/service/gpu_channel.cc » ('J')
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 public: 52 public:
53 FilteredSender(); 53 FilteredSender();
54 ~FilteredSender() override; 54 ~FilteredSender() override;
55 55
56 virtual void AddFilter(IPC::MessageFilter* filter) = 0; 56 virtual void AddFilter(IPC::MessageFilter* filter) = 0;
57 virtual void RemoveFilter(IPC::MessageFilter* filter) = 0; 57 virtual void RemoveFilter(IPC::MessageFilter* filter) = 0;
58 }; 58 };
59 59
60 // Encapsulates an IPC channel between the GPU process and one renderer 60 // Encapsulates an IPC channel between the GPU process and one renderer
61 // process. On the renderer side there's a corresponding GpuChannelHost. 61 // process. On the renderer side there's a corresponding GpuChannelHost.
62 class GPU_EXPORT GpuChannel : public IPC::Listener, public FilteredSender { 62 class GPU_EXPORT GpuChannel : public IPC::Listener,
63 public FilteredSender,
64 public base::SupportsWeakPtr<GpuChannel> {
63 public: 65 public:
64 // Takes ownership of the renderer process handle. 66 // Takes ownership of the renderer process handle.
65 GpuChannel(GpuChannelManager* gpu_channel_manager, 67 GpuChannel(GpuChannelManager* gpu_channel_manager,
66 SyncPointManager* sync_point_manager, 68 SyncPointManager* sync_point_manager,
67 GpuWatchdogThread* watchdog, 69 GpuWatchdogThread* watchdog,
68 gl::GLShareGroup* share_group, 70 gl::GLShareGroup* share_group,
69 gles2::MailboxManager* mailbox_manager, 71 gles2::MailboxManager* mailbox_manager,
70 PreemptionFlag* preempting_flag, 72 PreemptionFlag* preempting_flag,
71 PreemptionFlag* preempted_flag, 73 PreemptionFlag* preempted_flag,
72 base::SingleThreadTaskRunner* task_runner, 74 base::SingleThreadTaskRunner* task_runner,
(...skipping 30 matching lines...) Expand all
103 const scoped_refptr<PreemptionFlag>& preempted_flag() const { 105 const scoped_refptr<PreemptionFlag>& preempted_flag() const {
104 return preempted_flag_; 106 return preempted_flag_;
105 } 107 }
106 108
107 virtual base::ProcessId GetClientPID() const; 109 virtual base::ProcessId GetClientPID() const;
108 110
109 int client_id() const { return client_id_; } 111 int client_id() const { return client_id_; }
110 112
111 uint64_t client_tracing_id() const { return client_tracing_id_; } 113 uint64_t client_tracing_id() const { return client_tracing_id_; }
112 114
113 base::WeakPtr<GpuChannel> AsWeakPtr();
114
115 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() const { 115 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() const {
116 return io_task_runner_; 116 return io_task_runner_;
117 } 117 }
118 118
119 void HandleMessageOnIOThread(const IPC::Message& msg);
120
119 // IPC::Listener implementation: 121 // IPC::Listener implementation:
120 bool OnMessageReceived(const IPC::Message& msg) override; 122 bool OnMessageReceived(const IPC::Message& msg) override;
121 void OnChannelConnected(int32_t peer_pid) override; 123 void OnChannelConnected(int32_t peer_pid) override;
122 void OnChannelError() override; 124 void OnChannelError() override;
123 125
124 // FilteredSender implementation: 126 // FilteredSender implementation:
125 bool Send(IPC::Message* msg) override; 127 bool Send(IPC::Message* msg) override;
126 void AddFilter(IPC::MessageFilter* filter) override; 128 void AddFilter(IPC::MessageFilter* filter) override;
127 void RemoveFilter(IPC::MessageFilter* filter) override; 129 void RemoveFilter(IPC::MessageFilter* filter) override;
128 130
(...skipping 22 matching lines...) Expand all
151 153
152 scoped_refptr<gl::GLImage> CreateImageForGpuMemoryBuffer( 154 scoped_refptr<gl::GLImage> CreateImageForGpuMemoryBuffer(
153 const gfx::GpuMemoryBufferHandle& handle, 155 const gfx::GpuMemoryBufferHandle& handle,
154 const gfx::Size& size, 156 const gfx::Size& size,
155 gfx::BufferFormat format, 157 gfx::BufferFormat format,
156 uint32_t internalformat, 158 uint32_t internalformat,
157 SurfaceHandle surface_handle); 159 SurfaceHandle surface_handle);
158 160
159 GpuChannelMessageFilter* filter() const { return filter_.get(); } 161 GpuChannelMessageFilter* filter() const { return filter_.get(); }
160 162
163 void PostHandleMessageOnQueue();
161 void PostHandleOutOfOrderMessage(const IPC::Message& message); 164 void PostHandleOutOfOrderMessage(const IPC::Message& message);
162 void PostHandleMessage();
163 165
164 // Synchronously handle the message to make testing convenient. 166 // Synchronously handle the message to make testing convenient.
165 void HandleMessageForTesting(const IPC::Message& msg); 167 void HandleMessageForTesting(const IPC::Message& msg);
166 168
167 #if defined(OS_ANDROID) 169 #if defined(OS_ANDROID)
168 const GpuCommandBufferStub* GetOneStub() const; 170 const GpuCommandBufferStub* GetOneStub() const;
169 #endif 171 #endif
170 172
171 protected: 173 protected:
172 scoped_refptr<GpuChannelMessageQueue> message_queue_; 174 scoped_refptr<GpuChannelMessageQueue> message_queue_;
173 175
174 // The message filter on the io thread. 176 // The message filter on the io thread.
175 scoped_refptr<GpuChannelMessageFilter> filter_; 177 scoped_refptr<GpuChannelMessageFilter> filter_;
176 178
177 // Map of routing id to command buffer stub. 179 // Map of routing id to command buffer stub.
178 std::unordered_map<int32_t, std::unique_ptr<GpuCommandBufferStub>> stubs_; 180 std::unordered_map<int32_t, std::unique_ptr<GpuCommandBufferStub>> stubs_;
179 181
180 private: 182 private:
181 friend class TestGpuChannel; 183 friend class TestGpuChannel;
182 184
183 bool OnControlMessageReceived(const IPC::Message& msg); 185 bool OnControlMessageReceived(const IPC::Message& msg);
184 186
185 void HandleMessage(); 187 void HandleMessageOnQueue();
186 188
187 // Some messages such as WaitForGetOffsetInRange and WaitForTokenInRange are 189 // Some messages such as WaitForGetOffsetInRange and WaitForTokenInRange are
188 // processed as soon as possible because the client is blocked until they 190 // processed as soon as possible because the client is blocked until they
189 // are completed. 191 // are completed.
190 void HandleOutOfOrderMessage(const IPC::Message& msg); 192 void HandleOutOfOrderMessage(const IPC::Message& msg);
191 193
192 void HandleMessageHelper(const IPC::Message& msg); 194 void HandleMessageHelper(const IPC::Message& msg);
193 195
194 // Message handlers for control messages. 196 // Message handlers for control messages.
195 void OnCreateCommandBuffer(const GPUCreateCommandBufferConfig& init_params, 197 void OnCreateCommandBuffer(const GPUCreateCommandBufferConfig& init_params,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 GpuWatchdogThread* const watchdog_; 251 GpuWatchdogThread* const watchdog_;
250 252
251 // Can view command buffers be created on this channel. 253 // Can view command buffers be created on this channel.
252 const bool allow_view_command_buffers_; 254 const bool allow_view_command_buffers_;
253 255
254 // Can real time streams be created on this channel. 256 // Can real time streams be created on this channel.
255 const bool allow_real_time_streams_; 257 const bool allow_real_time_streams_;
256 258
257 base::ProcessId peer_pid_; 259 base::ProcessId peer_pid_;
258 260
259 // Member variables should appear before the WeakPtrFactory, to ensure
260 // that any WeakPtrs to Controller are invalidated before its members
261 // variable's destructors are executed, rendering them invalid.
piman 2017/03/24 04:31:40 I think we should keep this property. Using Suppor
sunnyps 2017/03/24 21:27:22 Done.
262 base::WeakPtrFactory<GpuChannel> weak_factory_;
263
264 DISALLOW_COPY_AND_ASSIGN(GpuChannel); 261 DISALLOW_COPY_AND_ASSIGN(GpuChannel);
265 }; 262 };
266 263
267 // This filter does three things: 264 // This filter does three things:
268 // - it counts and timestamps each message forwarded to the channel 265 // - it counts and timestamps each message forwarded to the channel
269 // so that we can preempt other channels if a message takes too long to 266 // so that we can preempt other channels if a message takes too long to
270 // process. To guarantee fairness, we must wait a minimum amount of time 267 // process. To guarantee fairness, we must wait a minimum amount of time
271 // before preempting and we limit the amount of time that we can preempt in 268 // before preempting and we limit the amount of time that we can preempt in
272 // one shot (see constants above). 269 // one shot (see constants above).
273 // - it handles the GpuCommandBufferMsg_InsertSyncPoint message on the IO 270 // - it handles the GpuCommandBufferMsg_InsertSyncPoint message on the IO
274 // thread, generating the sync point ID and responding immediately, and then 271 // thread, generating the sync point ID and responding immediately, and then
275 // posting a task to insert the GpuCommandBufferMsg_RetireSyncPoint message 272 // posting a task to insert the GpuCommandBufferMsg_RetireSyncPoint message
276 // into the channel's queue. 273 // into the channel's queue.
277 // - it generates mailbox names for clients of the GPU process on the IO thread. 274 // - it generates mailbox names for clients of the GPU process on the IO thread.
278 class GPU_EXPORT GpuChannelMessageFilter : public IPC::MessageFilter { 275 class GPU_EXPORT GpuChannelMessageFilter : public IPC::MessageFilter {
279 public: 276 public:
280 explicit GpuChannelMessageFilter( 277 explicit GpuChannelMessageFilter(GpuChannel* gpu_channel);
281 scoped_refptr<GpuChannelMessageQueue> message_queue); 278
279 void Destroy();
282 280
283 // IPC::MessageFilter implementation. 281 // IPC::MessageFilter implementation.
284 void OnFilterAdded(IPC::Channel* channel) override; 282 void OnFilterAdded(IPC::Channel* channel) override;
285 void OnFilterRemoved() override; 283 void OnFilterRemoved() override;
286 void OnChannelConnected(int32_t peer_pid) override; 284 void OnChannelConnected(int32_t peer_pid) override;
287 void OnChannelError() override; 285 void OnChannelError() override;
288 void OnChannelClosing() override; 286 void OnChannelClosing() override;
289 bool OnMessageReceived(const IPC::Message& message) override; 287 bool OnMessageReceived(const IPC::Message& message) override;
290 288
291 void AddChannelFilter(scoped_refptr<IPC::MessageFilter> filter); 289 void AddChannelFilter(scoped_refptr<IPC::MessageFilter> filter);
292 void RemoveChannelFilter(scoped_refptr<IPC::MessageFilter> filter); 290 void RemoveChannelFilter(scoped_refptr<IPC::MessageFilter> filter);
293 291
294 bool Send(IPC::Message* message); 292 bool Send(IPC::Message* message);
295 293
296 protected: 294 private:
297 ~GpuChannelMessageFilter() override; 295 ~GpuChannelMessageFilter() override;
298 296
299 private:
300 bool MessageErrorHandler(const IPC::Message& message, const char* error_msg); 297 bool MessageErrorHandler(const IPC::Message& message, const char* error_msg);
301 298
302 scoped_refptr<GpuChannelMessageQueue> message_queue_; 299 IPC::Channel* ipc_channel_ = nullptr;
303 300 base::ProcessId peer_pid_ = base::kNullProcessId;
304 IPC::Channel* channel_;
305 base::ProcessId peer_pid_;
306 std::vector<scoped_refptr<IPC::MessageFilter>> channel_filters_; 301 std::vector<scoped_refptr<IPC::MessageFilter>> channel_filters_;
302 GpuChannel* gpu_channel_ = nullptr;
303 base::Lock lock_;
307 304
308 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageFilter); 305 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageFilter);
309 }; 306 };
310 307
311 struct GpuChannelMessage { 308 struct GpuChannelMessage {
312 IPC::Message message; 309 IPC::Message message;
313 uint32_t order_number; 310 uint32_t order_number;
314 base::TimeTicks time_received; 311 base::TimeTicks time_received;
315 312
316 GpuChannelMessage(const IPC::Message& msg, 313 GpuChannelMessage(const IPC::Message& msg,
317 uint32_t order_num, 314 uint32_t order_num,
318 base::TimeTicks ts) 315 base::TimeTicks ts)
319 : message(msg), order_number(order_num), time_received(ts) {} 316 : message(msg), order_number(order_num), time_received(ts) {}
320 317
321 private: 318 private:
322 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessage); 319 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessage);
323 }; 320 };
324 321
325 class GpuChannelMessageQueue 322 class GpuChannelMessageQueue
326 : public base::RefCountedThreadSafe<GpuChannelMessageQueue> { 323 : public base::RefCountedThreadSafe<GpuChannelMessageQueue> {
327 public: 324 public:
328 static scoped_refptr<GpuChannelMessageQueue> Create( 325 static scoped_refptr<GpuChannelMessageQueue> Create(
329 GpuChannel* channel, 326 GpuChannel* channel,
330 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 327 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
331 scoped_refptr<PreemptionFlag> preempting_flag, 328 scoped_refptr<PreemptionFlag> preempting_flag,
332 scoped_refptr<PreemptionFlag> preempted_flag, 329 scoped_refptr<PreemptionFlag> preempted_flag,
333 SyncPointManager* sync_point_manager); 330 SyncPointManager* sync_point_manager);
334 331
335 void Disable(); 332 void Destroy();
336 void DisableIO();
337 333
338 SequenceId sequence_id() const { 334 SequenceId sequence_id() const {
339 return sync_point_order_data_->sequence_id(); 335 return sync_point_order_data_->sequence_id();
340 } 336 }
341 337
342 bool IsScheduled() const; 338 bool IsScheduled() const;
343 void SetScheduled(bool scheduled); 339 void SetScheduled(bool scheduled);
344 340
345 bool HasQueuedMessages() const; 341 bool HasQueuedMessages() const;
346 342
347 base::TimeTicks GetNextMessageTimeTick() const;
348
349 // Should be called before a message begins to be processed. Returns false if 343 // Should be called before a message begins to be processed. Returns false if
350 // there are no messages to process. 344 // there are no messages to process.
351 const GpuChannelMessage* BeginMessageProcessing(); 345 const GpuChannelMessage* BeginMessageProcessing();
352 // Should be called if a message began processing but did not finish. 346 // Should be called if a message began processing but did not finish.
353 void PauseMessageProcessing(); 347 void PauseMessageProcessing();
354 // Should be called if a message is completely processed. Returns true if 348 // Should be called if a message is completely processed. Returns true if
355 // there are more messages to process. 349 // there are more messages to process.
356 void FinishMessageProcessing(); 350 void FinishMessageProcessing();
357 351
358 bool PushBackMessage(const IPC::Message& message); 352 void PushBackMessage(const IPC::Message& message);
359 353
360 private: 354 private:
361 enum PreemptionState { 355 enum PreemptionState {
362 // Either there's no other channel to preempt, there are no messages 356 // Either there's no other channel to preempt, there are no messages
363 // pending processing, or we just finished preempting and have to wait 357 // pending processing, or we just finished preempting and have to wait
364 // before preempting again. 358 // before preempting again.
365 IDLE, 359 IDLE,
366 // We are waiting kPreemptWaitTimeMs before checking if we should preempt. 360 // We are waiting kPreemptWaitTimeMs before checking if we should preempt.
367 WAITING, 361 WAITING,
368 // We can preempt whenever any IPC processing takes more than 362 // We can preempt whenever any IPC processing takes more than
(...skipping 27 matching lines...) Expand all
396 void TransitionToIdle(); 390 void TransitionToIdle();
397 void TransitionToWaiting(); 391 void TransitionToWaiting();
398 void TransitionToChecking(); 392 void TransitionToChecking();
399 void TransitionToPreempting(); 393 void TransitionToPreempting();
400 void TransitionToWouldPreemptDescheduled(); 394 void TransitionToWouldPreemptDescheduled();
401 395
402 bool ShouldTransitionToIdle() const; 396 bool ShouldTransitionToIdle() const;
403 397
404 // These can be accessed from both IO and main threads and are protected by 398 // These can be accessed from both IO and main threads and are protected by
405 // |channel_lock_|. 399 // |channel_lock_|.
406 bool enabled_;
407 bool scheduled_; 400 bool scheduled_;
408 GpuChannel* const channel_; 401 GpuChannel* const channel_;
409 std::deque<std::unique_ptr<GpuChannelMessage>> channel_messages_; 402 std::deque<std::unique_ptr<GpuChannelMessage>> channel_messages_;
410 mutable base::Lock channel_lock_; 403 mutable base::Lock channel_lock_;
411 404
412 // The following are accessed on the IO thread only. 405 // The following are accessed on the IO thread only.
413 // No lock is necessary for preemption state because it's only accessed on the 406 // No lock is necessary for preemption state because it's only accessed on the
414 // IO thread. 407 // IO thread.
415 PreemptionState preemption_state_; 408 PreemptionState preemption_state_;
416 // Maximum amount of time that we can spend in PREEMPTING. 409 // Maximum amount of time that we can spend in PREEMPTING.
(...skipping 10 matching lines...) Expand all
427 scoped_refptr<PreemptionFlag> preempting_flag_; 420 scoped_refptr<PreemptionFlag> preempting_flag_;
428 scoped_refptr<PreemptionFlag> preempted_flag_; 421 scoped_refptr<PreemptionFlag> preempted_flag_;
429 SyncPointManager* const sync_point_manager_; 422 SyncPointManager* const sync_point_manager_;
430 423
431 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageQueue); 424 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageQueue);
432 }; 425 };
433 426
434 } // namespace gpu 427 } // namespace gpu
435 428
436 #endif // GPU_IPC_SERVICE_GPU_CHANNEL_H_ 429 #endif // GPU_IPC_SERVICE_GPU_CHANNEL_H_
OLDNEW
« no previous file with comments | « no previous file | gpu/ipc/service/gpu_channel.cc » ('j') | gpu/ipc/service/gpu_channel.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698