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 #include "gpu/ipc/service/gpu_channel.h" | 5 #include "gpu/ipc/service/gpu_channel.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
28 #include "base/timer/timer.h" | 28 #include "base/timer/timer.h" |
29 #include "base/trace_event/memory_dump_manager.h" | 29 #include "base/trace_event/memory_dump_manager.h" |
30 #include "base/trace_event/process_memory_dump.h" | 30 #include "base/trace_event/process_memory_dump.h" |
31 #include "base/trace_event/trace_event.h" | 31 #include "base/trace_event/trace_event.h" |
32 #include "build/build_config.h" | 32 #include "build/build_config.h" |
33 #include "gpu/command_buffer/common/mailbox.h" | 33 #include "gpu/command_buffer/common/mailbox.h" |
34 #include "gpu/command_buffer/service/command_executor.h" | 34 #include "gpu/command_buffer/service/command_executor.h" |
35 #include "gpu/command_buffer/service/image_factory.h" | 35 #include "gpu/command_buffer/service/image_factory.h" |
36 #include "gpu/command_buffer/service/mailbox_manager.h" | 36 #include "gpu/command_buffer/service/mailbox_manager.h" |
37 #include "gpu/command_buffer/service/sync_point_manager.h" | |
38 #include "gpu/ipc/common/gpu_messages.h" | 37 #include "gpu/ipc/common/gpu_messages.h" |
39 #include "gpu/ipc/service/gpu_channel_manager.h" | 38 #include "gpu/ipc/service/gpu_channel_manager.h" |
40 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" | 39 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" |
41 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 40 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
42 #include "ipc/ipc_channel.h" | 41 #include "ipc/ipc_channel.h" |
43 #include "ipc/message_filter.h" | 42 #include "ipc/message_filter.h" |
44 #include "ui/gl/gl_context.h" | 43 #include "ui/gl/gl_context.h" |
45 #include "ui/gl/gl_image_shared_memory.h" | 44 #include "ui/gl/gl_image_shared_memory.h" |
46 #include "ui/gl/gl_surface.h" | 45 #include "ui/gl/gl_surface.h" |
47 | 46 |
(...skipping 10 matching lines...) Expand all Loading... |
58 const int64_t kPreemptWaitTimeMs = 2 * kVsyncIntervalMs; | 57 const int64_t kPreemptWaitTimeMs = 2 * kVsyncIntervalMs; |
59 | 58 |
60 // Once we trigger a preemption, the maximum duration that we will wait | 59 // Once we trigger a preemption, the maximum duration that we will wait |
61 // before clearing the preemption. | 60 // before clearing the preemption. |
62 const int64_t kMaxPreemptTimeMs = kVsyncIntervalMs; | 61 const int64_t kMaxPreemptTimeMs = kVsyncIntervalMs; |
63 | 62 |
64 // Stop the preemption once the time for the longest pending IPC drops | 63 // Stop the preemption once the time for the longest pending IPC drops |
65 // below this threshold. | 64 // below this threshold. |
66 const int64_t kStopPreemptThresholdMs = kVsyncIntervalMs; | 65 const int64_t kStopPreemptThresholdMs = kVsyncIntervalMs; |
67 | 66 |
| 67 CommandBufferId GenerateCommandBufferId(int channel_id, int32_t route_id) { |
| 68 return CommandBufferId::FromUnsafeValue( |
| 69 (static_cast<uint64_t>(channel_id) << 32) | route_id); |
| 70 } |
| 71 |
68 } // anonymous namespace | 72 } // anonymous namespace |
69 | 73 |
70 scoped_refptr<GpuChannelMessageQueue> GpuChannelMessageQueue::Create( | 74 scoped_refptr<GpuChannelMessageQueue> GpuChannelMessageQueue::Create( |
71 int32_t stream_id, | |
72 GpuStreamPriority stream_priority, | |
73 GpuChannel* channel, | 75 GpuChannel* channel, |
74 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 76 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
75 const scoped_refptr<PreemptionFlag>& preempting_flag, | 77 scoped_refptr<PreemptionFlag> preempting_flag, |
76 const scoped_refptr<PreemptionFlag>& preempted_flag, | 78 scoped_refptr<PreemptionFlag> preempted_flag, |
77 SyncPointManager* sync_point_manager) { | 79 SyncPointManager* sync_point_manager) { |
78 return new GpuChannelMessageQueue(stream_id, stream_priority, channel, | 80 return new GpuChannelMessageQueue( |
79 io_task_runner, preempting_flag, | 81 channel, std::move(io_task_runner), std::move(preempting_flag), |
80 preempted_flag, sync_point_manager); | 82 std::move(preempted_flag), sync_point_manager); |
81 } | |
82 | |
83 scoped_refptr<SyncPointOrderData> | |
84 GpuChannelMessageQueue::GetSyncPointOrderData() { | |
85 return sync_point_order_data_; | |
86 } | 83 } |
87 | 84 |
88 GpuChannelMessageQueue::GpuChannelMessageQueue( | 85 GpuChannelMessageQueue::GpuChannelMessageQueue( |
89 int32_t stream_id, | |
90 GpuStreamPriority stream_priority, | |
91 GpuChannel* channel, | 86 GpuChannel* channel, |
92 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 87 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
93 const scoped_refptr<PreemptionFlag>& preempting_flag, | 88 scoped_refptr<PreemptionFlag> preempting_flag, |
94 const scoped_refptr<PreemptionFlag>& preempted_flag, | 89 scoped_refptr<PreemptionFlag> preempted_flag, |
95 SyncPointManager* sync_point_manager) | 90 SyncPointManager* sync_point_manager) |
96 : stream_id_(stream_id), | 91 : enabled_(true), |
97 stream_priority_(stream_priority), | |
98 enabled_(true), | |
99 scheduled_(true), | 92 scheduled_(true), |
100 channel_(channel), | 93 channel_(channel), |
101 preemption_state_(IDLE), | 94 preemption_state_(IDLE), |
102 max_preemption_time_( | 95 max_preemption_time_( |
103 base::TimeDelta::FromMilliseconds(kMaxPreemptTimeMs)), | 96 base::TimeDelta::FromMilliseconds(kMaxPreemptTimeMs)), |
104 timer_(new base::OneShotTimer), | 97 timer_(new base::OneShotTimer), |
105 sync_point_order_data_(SyncPointOrderData::Create()), | 98 sync_point_order_data_(sync_point_manager->CreateSyncPointOrderData()), |
106 io_task_runner_(io_task_runner), | 99 io_task_runner_(std::move(io_task_runner)), |
107 preempting_flag_(preempting_flag), | 100 preempting_flag_(std::move(preempting_flag)), |
108 preempted_flag_(preempted_flag), | 101 preempted_flag_(std::move(preempted_flag)), |
109 sync_point_manager_(sync_point_manager) { | 102 sync_point_manager_(sync_point_manager) { |
110 timer_->SetTaskRunner(io_task_runner); | 103 timer_->SetTaskRunner(io_task_runner_); |
111 io_thread_checker_.DetachFromThread(); | 104 io_thread_checker_.DetachFromThread(); |
112 } | 105 } |
113 | 106 |
114 GpuChannelMessageQueue::~GpuChannelMessageQueue() { | 107 GpuChannelMessageQueue::~GpuChannelMessageQueue() { |
115 DCHECK(!enabled_); | 108 DCHECK(!enabled_); |
116 DCHECK(channel_messages_.empty()); | 109 DCHECK(channel_messages_.empty()); |
117 } | 110 } |
118 | 111 |
119 void GpuChannelMessageQueue::Disable() { | 112 void GpuChannelMessageQueue::Disable() { |
120 { | 113 { |
121 base::AutoLock auto_lock(channel_lock_); | 114 base::AutoLock auto_lock(channel_lock_); |
122 DCHECK(enabled_); | 115 DCHECK(enabled_); |
123 enabled_ = false; | 116 enabled_ = false; |
124 } | 117 } |
125 | 118 |
126 // We guarantee that the queues will no longer be modified after enabled_ | 119 // We guarantee that the queues will no longer be modified after enabled_ |
127 // is set to false, it is now safe to modify the queue without the lock. | 120 // is set to false, it is now safe to modify the queue without the lock. |
128 // All public facing modifying functions check enabled_ while all | 121 // All public facing modifying functions check enabled_ while all |
129 // private modifying functions DCHECK(enabled_) to enforce this. | 122 // private modifying functions DCHECK(enabled_) to enforce this. |
130 while (!channel_messages_.empty()) { | 123 while (!channel_messages_.empty()) { |
131 const IPC::Message& msg = channel_messages_.front()->message; | 124 const IPC::Message& msg = channel_messages_.front()->message; |
132 if (msg.is_sync()) { | 125 if (msg.is_sync()) { |
133 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | 126 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); |
134 reply->set_reply_error(); | 127 reply->set_reply_error(); |
135 channel_->Send(reply); | 128 channel_->Send(reply); |
136 } | 129 } |
137 channel_messages_.pop_front(); | 130 channel_messages_.pop_front(); |
138 } | 131 } |
139 | 132 |
140 sync_point_order_data_->Destroy(); | 133 if (sync_point_order_data_) { |
141 sync_point_order_data_ = nullptr; | 134 sync_point_order_data_->Destroy(); |
| 135 sync_point_order_data_ = nullptr; |
| 136 } |
142 | 137 |
143 io_task_runner_->PostTask( | 138 io_task_runner_->PostTask( |
144 FROM_HERE, base::Bind(&GpuChannelMessageQueue::DisableIO, this)); | 139 FROM_HERE, base::Bind(&GpuChannelMessageQueue::DisableIO, this)); |
145 } | 140 } |
146 | 141 |
147 void GpuChannelMessageQueue::DisableIO() { | 142 void GpuChannelMessageQueue::DisableIO() { |
148 DCHECK(io_thread_checker_.CalledOnValidThread()); | 143 DCHECK(io_thread_checker_.CalledOnValidThread()); |
149 timer_ = nullptr; | 144 timer_ = nullptr; |
150 } | 145 } |
151 | 146 |
152 bool GpuChannelMessageQueue::IsScheduled() const { | 147 bool GpuChannelMessageQueue::IsScheduled() const { |
153 base::AutoLock lock(channel_lock_); | 148 base::AutoLock lock(channel_lock_); |
154 return scheduled_; | 149 return scheduled_; |
155 } | 150 } |
156 | 151 |
157 void GpuChannelMessageQueue::OnRescheduled(bool scheduled) { | 152 void GpuChannelMessageQueue::SetScheduled(bool scheduled) { |
158 base::AutoLock lock(channel_lock_); | 153 base::AutoLock lock(channel_lock_); |
159 DCHECK(enabled_); | 154 DCHECK(enabled_); |
160 if (scheduled_ == scheduled) | 155 if (scheduled_ == scheduled) |
161 return; | 156 return; |
162 scheduled_ = scheduled; | 157 scheduled_ = scheduled; |
163 if (scheduled) | 158 if (scheduled) |
164 channel_->PostHandleMessage(this); | 159 channel_->PostHandleMessage(); |
165 if (preempting_flag_) { | 160 if (preempting_flag_) { |
166 io_task_runner_->PostTask( | 161 io_task_runner_->PostTask( |
167 FROM_HERE, | 162 FROM_HERE, |
168 base::Bind(&GpuChannelMessageQueue::UpdatePreemptionState, this)); | 163 base::Bind(&GpuChannelMessageQueue::UpdatePreemptionState, this)); |
169 } | 164 } |
170 } | 165 } |
171 | 166 |
172 uint32_t GpuChannelMessageQueue::GetUnprocessedOrderNum() const { | |
173 return sync_point_order_data_->unprocessed_order_num(); | |
174 } | |
175 | |
176 uint32_t GpuChannelMessageQueue::GetProcessedOrderNum() const { | |
177 return sync_point_order_data_->processed_order_num(); | |
178 } | |
179 | |
180 bool GpuChannelMessageQueue::PushBackMessage(const IPC::Message& message) { | 167 bool GpuChannelMessageQueue::PushBackMessage(const IPC::Message& message) { |
181 base::AutoLock auto_lock(channel_lock_); | 168 base::AutoLock auto_lock(channel_lock_); |
182 if (enabled_) { | 169 if (enabled_) { |
183 if (message.type() == GpuCommandBufferMsg_WaitForTokenInRange::ID || | 170 if (message.type() == GpuCommandBufferMsg_WaitForTokenInRange::ID || |
184 message.type() == GpuCommandBufferMsg_WaitForGetOffsetInRange::ID) { | 171 message.type() == GpuCommandBufferMsg_WaitForGetOffsetInRange::ID) { |
185 channel_->PostHandleOutOfOrderMessage(message); | 172 channel_->PostHandleOutOfOrderMessage(message); |
186 return true; | 173 return true; |
187 } | 174 } |
188 | 175 |
189 uint32_t order_num = sync_point_order_data_->GenerateUnprocessedOrderNumber( | 176 uint32_t order_num = |
190 sync_point_manager_); | 177 sync_point_order_data_->GenerateUnprocessedOrderNumber(); |
191 std::unique_ptr<GpuChannelMessage> msg( | 178 std::unique_ptr<GpuChannelMessage> msg( |
192 new GpuChannelMessage(message, order_num, base::TimeTicks::Now())); | 179 new GpuChannelMessage(message, order_num, base::TimeTicks::Now())); |
193 | 180 |
194 if (channel_messages_.empty()) { | 181 if (channel_messages_.empty()) { |
195 DCHECK(scheduled_); | 182 DCHECK(scheduled_); |
196 channel_->PostHandleMessage(this); | 183 channel_->PostHandleMessage(); |
197 } | 184 } |
198 | 185 |
199 channel_messages_.push_back(std::move(msg)); | 186 channel_messages_.push_back(std::move(msg)); |
200 | 187 |
201 if (preempting_flag_) | 188 if (preempting_flag_) |
202 UpdatePreemptionStateHelper(); | 189 UpdatePreemptionStateHelper(); |
203 | 190 |
204 return true; | 191 return true; |
205 } | 192 } |
206 return false; | 193 return false; |
207 } | 194 } |
208 | 195 |
209 const GpuChannelMessage* GpuChannelMessageQueue::BeginMessageProcessing() { | 196 const GpuChannelMessage* GpuChannelMessageQueue::BeginMessageProcessing() { |
210 base::AutoLock auto_lock(channel_lock_); | 197 base::AutoLock auto_lock(channel_lock_); |
211 DCHECK(enabled_); | 198 DCHECK(enabled_); |
212 // If we have been preempted by another channel, just post a task to wake up. | 199 // If we have been preempted by another channel, just post a task to wake up. |
213 if (preempted_flag_ && preempted_flag_->IsSet()) { | 200 if (preempted_flag_ && preempted_flag_->IsSet()) { |
214 channel_->PostHandleMessage(this); | 201 channel_->PostHandleMessage(); |
215 return nullptr; | 202 return nullptr; |
216 } | 203 } |
217 if (channel_messages_.empty()) | 204 if (channel_messages_.empty()) |
218 return nullptr; | 205 return nullptr; |
219 sync_point_order_data_->BeginProcessingOrderNumber( | 206 sync_point_order_data_->BeginProcessingOrderNumber( |
220 channel_messages_.front()->order_number); | 207 channel_messages_.front()->order_number); |
221 return channel_messages_.front().get(); | 208 return channel_messages_.front().get(); |
222 } | 209 } |
223 | 210 |
224 void GpuChannelMessageQueue::PauseMessageProcessing() { | 211 void GpuChannelMessageQueue::PauseMessageProcessing() { |
225 base::AutoLock auto_lock(channel_lock_); | 212 base::AutoLock auto_lock(channel_lock_); |
226 DCHECK(!channel_messages_.empty()); | 213 DCHECK(!channel_messages_.empty()); |
227 | 214 |
228 // If we have been preempted by another channel, just post a task to wake up. | 215 // If we have been preempted by another channel, just post a task to wake up. |
229 if (scheduled_) | 216 if (scheduled_) |
230 channel_->PostHandleMessage(this); | 217 channel_->PostHandleMessage(); |
231 | 218 |
232 sync_point_order_data_->PauseProcessingOrderNumber( | 219 sync_point_order_data_->PauseProcessingOrderNumber( |
233 channel_messages_.front()->order_number); | 220 channel_messages_.front()->order_number); |
234 } | 221 } |
235 | 222 |
236 void GpuChannelMessageQueue::FinishMessageProcessing() { | 223 void GpuChannelMessageQueue::FinishMessageProcessing() { |
237 base::AutoLock auto_lock(channel_lock_); | 224 base::AutoLock auto_lock(channel_lock_); |
238 DCHECK(!channel_messages_.empty()); | 225 DCHECK(!channel_messages_.empty()); |
239 DCHECK(scheduled_); | 226 DCHECK(scheduled_); |
240 | 227 |
241 sync_point_order_data_->FinishProcessingOrderNumber( | 228 sync_point_order_data_->FinishProcessingOrderNumber( |
242 channel_messages_.front()->order_number); | 229 channel_messages_.front()->order_number); |
243 channel_messages_.pop_front(); | 230 channel_messages_.pop_front(); |
244 | 231 |
245 if (!channel_messages_.empty()) | 232 if (!channel_messages_.empty()) |
246 channel_->PostHandleMessage(this); | 233 channel_->PostHandleMessage(); |
247 | 234 |
248 if (preempting_flag_) { | 235 if (preempting_flag_) { |
249 io_task_runner_->PostTask( | 236 io_task_runner_->PostTask( |
250 FROM_HERE, | 237 FROM_HERE, |
251 base::Bind(&GpuChannelMessageQueue::UpdatePreemptionState, this)); | 238 base::Bind(&GpuChannelMessageQueue::UpdatePreemptionState, this)); |
252 } | 239 } |
253 } | 240 } |
254 | 241 |
255 void GpuChannelMessageQueue::UpdatePreemptionState() { | 242 void GpuChannelMessageQueue::UpdatePreemptionState() { |
256 DCHECK(io_thread_checker_.CalledOnValidThread()); | 243 DCHECK(io_thread_checker_.CalledOnValidThread()); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 DCHECK(preempting_flag_); | 423 DCHECK(preempting_flag_); |
437 channel_lock_.AssertAcquired(); | 424 channel_lock_.AssertAcquired(); |
438 DCHECK(preemption_state_ == CHECKING || preemption_state_ == PREEMPTING); | 425 DCHECK(preemption_state_ == CHECKING || preemption_state_ == PREEMPTING); |
439 DCHECK(!scheduled_); | 426 DCHECK(!scheduled_); |
440 | 427 |
441 preemption_state_ = WOULD_PREEMPT_DESCHEDULED; | 428 preemption_state_ = WOULD_PREEMPT_DESCHEDULED; |
442 preempting_flag_->Reset(); | 429 preempting_flag_->Reset(); |
443 TRACE_COUNTER_ID1("gpu", "GpuChannel::Preempting", this, 0); | 430 TRACE_COUNTER_ID1("gpu", "GpuChannel::Preempting", this, 0); |
444 } | 431 } |
445 | 432 |
446 GpuChannelMessageFilter::GpuChannelMessageFilter() | 433 GpuChannelMessageFilter::GpuChannelMessageFilter( |
447 : channel_(nullptr), peer_pid_(base::kNullProcessId) {} | 434 scoped_refptr<GpuChannelMessageQueue> message_queue) |
| 435 : message_queue_(std::move(message_queue)), |
| 436 channel_(nullptr), |
| 437 peer_pid_(base::kNullProcessId) {} |
448 | 438 |
449 GpuChannelMessageFilter::~GpuChannelMessageFilter() {} | 439 GpuChannelMessageFilter::~GpuChannelMessageFilter() {} |
450 | 440 |
451 void GpuChannelMessageFilter::OnFilterAdded(IPC::Channel* channel) { | 441 void GpuChannelMessageFilter::OnFilterAdded(IPC::Channel* channel) { |
452 DCHECK(!channel_); | 442 DCHECK(!channel_); |
453 channel_ = channel; | 443 channel_ = channel; |
454 for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_) { | 444 for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_) { |
455 filter->OnFilterAdded(channel_); | 445 filter->OnFilterAdded(channel_); |
456 } | 446 } |
457 } | 447 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 } | 484 } |
495 | 485 |
496 void GpuChannelMessageFilter::RemoveChannelFilter( | 486 void GpuChannelMessageFilter::RemoveChannelFilter( |
497 scoped_refptr<IPC::MessageFilter> filter) { | 487 scoped_refptr<IPC::MessageFilter> filter) { |
498 if (channel_) | 488 if (channel_) |
499 filter->OnFilterRemoved(); | 489 filter->OnFilterRemoved(); |
500 channel_filters_.erase( | 490 channel_filters_.erase( |
501 std::find(channel_filters_.begin(), channel_filters_.end(), filter)); | 491 std::find(channel_filters_.begin(), channel_filters_.end(), filter)); |
502 } | 492 } |
503 | 493 |
504 // This gets called from the main thread and assumes that all messages which | |
505 // lead to creation of a new route are synchronous messages. | |
506 // TODO(sunnyps): Create routes (and streams) on the IO thread so that we can | |
507 // make the CreateCommandBuffer/VideoDecoder/VideoEncoder messages asynchronous. | |
508 void GpuChannelMessageFilter::AddRoute( | |
509 int32_t route_id, | |
510 const scoped_refptr<GpuChannelMessageQueue>& queue) { | |
511 base::AutoLock lock(routes_lock_); | |
512 routes_.insert(std::make_pair(route_id, queue)); | |
513 } | |
514 | |
515 void GpuChannelMessageFilter::RemoveRoute(int32_t route_id) { | |
516 base::AutoLock lock(routes_lock_); | |
517 routes_.erase(route_id); | |
518 } | |
519 | |
520 bool GpuChannelMessageFilter::OnMessageReceived(const IPC::Message& message) { | 494 bool GpuChannelMessageFilter::OnMessageReceived(const IPC::Message& message) { |
521 DCHECK(channel_); | 495 DCHECK(channel_); |
522 | 496 |
523 if (message.should_unblock() || message.is_reply()) | 497 if (message.should_unblock() || message.is_reply()) |
524 return MessageErrorHandler(message, "Unexpected message type"); | 498 return MessageErrorHandler(message, "Unexpected message type"); |
525 | 499 |
526 if (message.type() == GpuChannelMsg_Nop::ID) { | 500 if (message.type() == GpuChannelMsg_Nop::ID) { |
527 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message); | 501 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message); |
528 Send(reply); | 502 Send(reply); |
529 return true; | 503 return true; |
530 } | 504 } |
531 | 505 |
532 for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_) { | 506 for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_) { |
533 if (filter->OnMessageReceived(message)) | 507 if (filter->OnMessageReceived(message)) |
534 return true; | 508 return true; |
535 } | 509 } |
536 | 510 |
537 scoped_refptr<GpuChannelMessageQueue> message_queue = | 511 if (!message_queue_->PushBackMessage(message)) |
538 LookupStreamByRoute(message.routing_id()); | |
539 | |
540 if (!message_queue) | |
541 return MessageErrorHandler(message, "Could not find message queue"); | |
542 | |
543 if (!message_queue->PushBackMessage(message)) | |
544 return MessageErrorHandler(message, "Channel destroyed"); | 512 return MessageErrorHandler(message, "Channel destroyed"); |
545 | 513 |
546 return true; | 514 return true; |
547 } | 515 } |
548 | 516 |
549 bool GpuChannelMessageFilter::Send(IPC::Message* message) { | 517 bool GpuChannelMessageFilter::Send(IPC::Message* message) { |
550 return channel_->Send(message); | 518 return channel_->Send(message); |
551 } | 519 } |
552 | 520 |
553 scoped_refptr<GpuChannelMessageQueue> | |
554 GpuChannelMessageFilter::LookupStreamByRoute(int32_t route_id) { | |
555 base::AutoLock lock(routes_lock_); | |
556 auto it = routes_.find(route_id); | |
557 if (it != routes_.end()) | |
558 return it->second; | |
559 return nullptr; | |
560 } | |
561 | |
562 bool GpuChannelMessageFilter::MessageErrorHandler(const IPC::Message& message, | 521 bool GpuChannelMessageFilter::MessageErrorHandler(const IPC::Message& message, |
563 const char* error_msg) { | 522 const char* error_msg) { |
564 DLOG(ERROR) << error_msg; | 523 DLOG(ERROR) << error_msg; |
565 if (message.is_sync()) { | 524 if (message.is_sync()) { |
566 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message); | 525 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message); |
567 reply->set_reply_error(); | 526 reply->set_reply_error(); |
568 Send(reply); | 527 Send(reply); |
569 } | 528 } |
570 return true; | 529 return true; |
571 } | 530 } |
(...skipping 28 matching lines...) Expand all Loading... |
600 io_task_runner_(io_task_runner), | 559 io_task_runner_(io_task_runner), |
601 share_group_(share_group), | 560 share_group_(share_group), |
602 mailbox_manager_(mailbox), | 561 mailbox_manager_(mailbox), |
603 watchdog_(watchdog), | 562 watchdog_(watchdog), |
604 allow_view_command_buffers_(allow_view_command_buffers), | 563 allow_view_command_buffers_(allow_view_command_buffers), |
605 allow_real_time_streams_(allow_real_time_streams), | 564 allow_real_time_streams_(allow_real_time_streams), |
606 weak_factory_(this) { | 565 weak_factory_(this) { |
607 DCHECK(gpu_channel_manager); | 566 DCHECK(gpu_channel_manager); |
608 DCHECK(client_id); | 567 DCHECK(client_id); |
609 | 568 |
610 filter_ = new GpuChannelMessageFilter(); | 569 message_queue_ = |
| 570 GpuChannelMessageQueue::Create(this, io_task_runner, preempting_flag, |
| 571 preempted_flag, sync_point_manager); |
611 | 572 |
612 scoped_refptr<GpuChannelMessageQueue> control_queue = | 573 filter_ = new GpuChannelMessageFilter(message_queue_); |
613 CreateStream(GPU_STREAM_DEFAULT, GpuStreamPriority::HIGH); | |
614 AddRouteToStream(MSG_ROUTING_CONTROL, GPU_STREAM_DEFAULT); | |
615 } | 574 } |
616 | 575 |
617 GpuChannel::~GpuChannel() { | 576 GpuChannel::~GpuChannel() { |
618 // Clear stubs first because of dependencies. | 577 // Clear stubs first because of dependencies. |
619 stubs_.clear(); | 578 stubs_.clear(); |
620 | 579 |
621 for (auto& kv : streams_) | 580 message_queue_->Disable(); |
622 kv.second->Disable(); | |
623 | 581 |
624 if (preempting_flag_.get()) | 582 if (preempting_flag_.get()) |
625 preempting_flag_->Reset(); | 583 preempting_flag_->Reset(); |
626 } | 584 } |
627 | 585 |
628 IPC::ChannelHandle GpuChannel::Init(base::WaitableEvent* shutdown_event) { | 586 IPC::ChannelHandle GpuChannel::Init(base::WaitableEvent* shutdown_event) { |
629 DCHECK(shutdown_event); | 587 DCHECK(shutdown_event); |
630 DCHECK(!channel_); | 588 DCHECK(!channel_); |
631 | 589 |
632 mojo::MessagePipe pipe; | 590 mojo::MessagePipe pipe; |
(...skipping 12 matching lines...) Expand all Loading... |
645 | 603 |
646 base::WeakPtr<GpuChannel> GpuChannel::AsWeakPtr() { | 604 base::WeakPtr<GpuChannel> GpuChannel::AsWeakPtr() { |
647 return weak_factory_.GetWeakPtr(); | 605 return weak_factory_.GetWeakPtr(); |
648 } | 606 } |
649 | 607 |
650 base::ProcessId GpuChannel::GetClientPID() const { | 608 base::ProcessId GpuChannel::GetClientPID() const { |
651 DCHECK_NE(peer_pid_, base::kNullProcessId); | 609 DCHECK_NE(peer_pid_, base::kNullProcessId); |
652 return peer_pid_; | 610 return peer_pid_; |
653 } | 611 } |
654 | 612 |
655 uint32_t GpuChannel::GetProcessedOrderNum() const { | |
656 uint32_t processed_order_num = 0; | |
657 for (auto& kv : streams_) { | |
658 processed_order_num = | |
659 std::max(processed_order_num, kv.second->GetProcessedOrderNum()); | |
660 } | |
661 return processed_order_num; | |
662 } | |
663 | |
664 uint32_t GpuChannel::GetUnprocessedOrderNum() const { | |
665 uint32_t unprocessed_order_num = 0; | |
666 for (auto& kv : streams_) { | |
667 unprocessed_order_num = | |
668 std::max(unprocessed_order_num, kv.second->GetUnprocessedOrderNum()); | |
669 } | |
670 return unprocessed_order_num; | |
671 } | |
672 | |
673 bool GpuChannel::OnMessageReceived(const IPC::Message& msg) { | 613 bool GpuChannel::OnMessageReceived(const IPC::Message& msg) { |
674 // All messages should be pushed to channel_messages_ and handled separately. | 614 // All messages should be pushed to channel_messages_ and handled separately. |
675 NOTREACHED(); | 615 NOTREACHED(); |
676 return false; | 616 return false; |
677 } | 617 } |
678 | 618 |
679 void GpuChannel::OnChannelConnected(int32_t peer_pid) { | 619 void GpuChannel::OnChannelConnected(int32_t peer_pid) { |
680 peer_pid_ = peer_pid; | 620 peer_pid_ = peer_pid; |
681 } | 621 } |
682 | 622 |
(...skipping 10 matching lines...) Expand all Loading... |
693 << " with type " << message->type(); | 633 << " with type " << message->type(); |
694 | 634 |
695 if (!channel_) { | 635 if (!channel_) { |
696 delete message; | 636 delete message; |
697 return false; | 637 return false; |
698 } | 638 } |
699 | 639 |
700 return channel_->Send(message); | 640 return channel_->Send(message); |
701 } | 641 } |
702 | 642 |
703 void GpuChannel::OnStreamRescheduled(int32_t stream_id, bool scheduled) { | 643 void GpuChannel::OnCommandBufferScheduled(GpuCommandBufferStub* stub) { |
704 scoped_refptr<GpuChannelMessageQueue> queue = LookupStream(stream_id); | 644 message_queue_->SetScheduled(true); |
705 DCHECK(queue); | 645 // TODO(sunnyps): Enable gpu scheduler task queue for stub's sequence. |
706 queue->OnRescheduled(scheduled); | 646 } |
| 647 |
| 648 void GpuChannel::OnCommandBufferDescheduled(GpuCommandBufferStub* stub) { |
| 649 message_queue_->SetScheduled(false); |
| 650 // TODO(sunnyps): Disable gpu scheduler task queue for stub's sequence. |
707 } | 651 } |
708 | 652 |
709 GpuCommandBufferStub* GpuChannel::LookupCommandBuffer(int32_t route_id) { | 653 GpuCommandBufferStub* GpuChannel::LookupCommandBuffer(int32_t route_id) { |
710 auto it = stubs_.find(route_id); | 654 auto it = stubs_.find(route_id); |
711 if (it == stubs_.end()) | 655 if (it == stubs_.end()) |
712 return nullptr; | 656 return nullptr; |
713 | 657 |
714 return it->second.get(); | 658 return it->second.get(); |
715 } | 659 } |
716 | 660 |
717 void GpuChannel::LoseAllContexts() { | 661 void GpuChannel::LoseAllContexts() { |
718 gpu_channel_manager_->LoseAllContexts(); | 662 gpu_channel_manager_->LoseAllContexts(); |
719 } | 663 } |
720 | 664 |
721 void GpuChannel::MarkAllContextsLost() { | 665 void GpuChannel::MarkAllContextsLost() { |
722 for (auto& kv : stubs_) | 666 for (auto& kv : stubs_) |
723 kv.second->MarkContextLost(); | 667 kv.second->MarkContextLost(); |
724 } | 668 } |
725 | 669 |
726 bool GpuChannel::AddRoute(int32_t route_id, | 670 bool GpuChannel::AddRoute(int32_t route_id, |
727 int32_t stream_id, | 671 SequenceId sequence_id, |
728 IPC::Listener* listener) { | 672 IPC::Listener* listener) { |
729 if (router_.AddRoute(route_id, listener)) { | 673 // TODO(sunnyps): Add route id to sequence id mapping to filter. |
730 AddRouteToStream(route_id, stream_id); | 674 return router_.AddRoute(route_id, listener); |
731 return true; | |
732 } | |
733 return false; | |
734 } | 675 } |
735 | 676 |
736 void GpuChannel::RemoveRoute(int32_t route_id) { | 677 void GpuChannel::RemoveRoute(int32_t route_id) { |
737 router_.RemoveRoute(route_id); | 678 router_.RemoveRoute(route_id); |
738 RemoveRouteFromStream(route_id); | |
739 } | 679 } |
740 | 680 |
741 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { | 681 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { |
742 bool handled = true; | 682 bool handled = true; |
743 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) | 683 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) |
744 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateCommandBuffer, | 684 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateCommandBuffer, |
745 OnCreateCommandBuffer) | 685 OnCreateCommandBuffer) |
746 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, | 686 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, |
747 OnDestroyCommandBuffer) | 687 OnDestroyCommandBuffer) |
748 IPC_MESSAGE_HANDLER(GpuChannelMsg_GetDriverBugWorkArounds, | 688 IPC_MESSAGE_HANDLER(GpuChannelMsg_GetDriverBugWorkArounds, |
749 OnGetDriverBugWorkArounds) | 689 OnGetDriverBugWorkArounds) |
750 IPC_MESSAGE_UNHANDLED(handled = false) | 690 IPC_MESSAGE_UNHANDLED(handled = false) |
751 IPC_END_MESSAGE_MAP() | 691 IPC_END_MESSAGE_MAP() |
752 return handled; | 692 return handled; |
753 } | 693 } |
754 | 694 |
755 scoped_refptr<SyncPointOrderData> GpuChannel::GetSyncPointOrderData( | 695 void GpuChannel::PostHandleMessage() { |
756 int32_t stream_id) { | 696 task_runner_->PostTask(FROM_HERE, base::Bind(&GpuChannel::HandleMessage, |
757 auto it = streams_.find(stream_id); | 697 weak_factory_.GetWeakPtr())); |
758 DCHECK(it != streams_.end()); | |
759 DCHECK(it->second); | |
760 return it->second->GetSyncPointOrderData(); | |
761 } | |
762 | |
763 void GpuChannel::PostHandleMessage( | |
764 const scoped_refptr<GpuChannelMessageQueue>& queue) { | |
765 task_runner_->PostTask(FROM_HERE, | |
766 base::Bind(&GpuChannel::HandleMessage, | |
767 weak_factory_.GetWeakPtr(), queue)); | |
768 } | 698 } |
769 | 699 |
770 void GpuChannel::PostHandleOutOfOrderMessage(const IPC::Message& msg) { | 700 void GpuChannel::PostHandleOutOfOrderMessage(const IPC::Message& msg) { |
771 task_runner_->PostTask(FROM_HERE, | 701 task_runner_->PostTask(FROM_HERE, |
772 base::Bind(&GpuChannel::HandleOutOfOrderMessage, | 702 base::Bind(&GpuChannel::HandleOutOfOrderMessage, |
773 weak_factory_.GetWeakPtr(), msg)); | 703 weak_factory_.GetWeakPtr(), msg)); |
774 } | 704 } |
775 | 705 |
776 void GpuChannel::HandleMessage( | 706 void GpuChannel::HandleMessage() { |
777 const scoped_refptr<GpuChannelMessageQueue>& message_queue) { | |
778 const GpuChannelMessage* channel_msg = | 707 const GpuChannelMessage* channel_msg = |
779 message_queue->BeginMessageProcessing(); | 708 message_queue_->BeginMessageProcessing(); |
780 if (!channel_msg) | 709 if (!channel_msg) |
781 return; | 710 return; |
782 | 711 |
783 const IPC::Message& msg = channel_msg->message; | 712 const IPC::Message& msg = channel_msg->message; |
784 int32_t routing_id = msg.routing_id(); | 713 int32_t routing_id = msg.routing_id(); |
785 GpuCommandBufferStub* stub = LookupCommandBuffer(routing_id); | 714 GpuCommandBufferStub* stub = LookupCommandBuffer(routing_id); |
786 | 715 |
787 DCHECK(!stub || stub->IsScheduled()); | 716 DCHECK(!stub || stub->IsScheduled()); |
788 | 717 |
789 DVLOG(1) << "received message @" << &msg << " on channel @" << this | 718 DVLOG(1) << "received message @" << &msg << " on channel @" << this |
790 << " with type " << msg.type(); | 719 << " with type " << msg.type(); |
791 | 720 |
792 HandleMessageHelper(msg); | 721 HandleMessageHelper(msg); |
793 | 722 |
794 // If we get descheduled or yield while processing a message. | 723 // If we get descheduled or yield while processing a message. |
795 if ((stub && stub->HasUnprocessedCommands()) || | 724 if (stub && (stub->HasUnprocessedCommands() || !stub->IsScheduled())) { |
796 !message_queue->IsScheduled()) { | |
797 DCHECK((uint32_t)GpuCommandBufferMsg_AsyncFlush::ID == msg.type() || | 725 DCHECK((uint32_t)GpuCommandBufferMsg_AsyncFlush::ID == msg.type() || |
798 (uint32_t)GpuCommandBufferMsg_WaitSyncToken::ID == msg.type()); | 726 (uint32_t)GpuCommandBufferMsg_WaitSyncToken::ID == msg.type()); |
799 message_queue->PauseMessageProcessing(); | 727 DCHECK_EQ(stub->IsScheduled(), message_queue_->IsScheduled()); |
| 728 message_queue_->PauseMessageProcessing(); |
800 } else { | 729 } else { |
801 message_queue->FinishMessageProcessing(); | 730 message_queue_->FinishMessageProcessing(); |
802 } | 731 } |
803 } | 732 } |
804 | 733 |
805 void GpuChannel::HandleMessageHelper(const IPC::Message& msg) { | 734 void GpuChannel::HandleMessageHelper(const IPC::Message& msg) { |
806 int32_t routing_id = msg.routing_id(); | 735 int32_t routing_id = msg.routing_id(); |
807 | 736 |
808 bool handled = false; | 737 bool handled = false; |
809 if (routing_id == MSG_ROUTING_CONTROL) { | 738 if (routing_id == MSG_ROUTING_CONTROL) { |
810 handled = OnControlMessageReceived(msg); | 739 handled = OnControlMessageReceived(msg); |
811 } else { | 740 } else { |
(...skipping 12 matching lines...) Expand all Loading... |
824 } | 753 } |
825 | 754 |
826 void GpuChannel::HandleOutOfOrderMessage(const IPC::Message& msg) { | 755 void GpuChannel::HandleOutOfOrderMessage(const IPC::Message& msg) { |
827 HandleMessageHelper(msg); | 756 HandleMessageHelper(msg); |
828 } | 757 } |
829 | 758 |
830 void GpuChannel::HandleMessageForTesting(const IPC::Message& msg) { | 759 void GpuChannel::HandleMessageForTesting(const IPC::Message& msg) { |
831 HandleMessageHelper(msg); | 760 HandleMessageHelper(msg); |
832 } | 761 } |
833 | 762 |
834 scoped_refptr<GpuChannelMessageQueue> GpuChannel::CreateStream( | |
835 int32_t stream_id, | |
836 GpuStreamPriority stream_priority) { | |
837 DCHECK(streams_.find(stream_id) == streams_.end()); | |
838 scoped_refptr<GpuChannelMessageQueue> queue = GpuChannelMessageQueue::Create( | |
839 stream_id, stream_priority, this, io_task_runner_, | |
840 (stream_id == GPU_STREAM_DEFAULT) ? preempting_flag_ : nullptr, | |
841 preempted_flag_, sync_point_manager_); | |
842 streams_.insert(std::make_pair(stream_id, queue)); | |
843 streams_to_num_routes_.insert(std::make_pair(stream_id, 0)); | |
844 return queue; | |
845 } | |
846 | |
847 scoped_refptr<GpuChannelMessageQueue> GpuChannel::LookupStream( | |
848 int32_t stream_id) { | |
849 auto stream_it = streams_.find(stream_id); | |
850 if (stream_it != streams_.end()) | |
851 return stream_it->second; | |
852 return nullptr; | |
853 } | |
854 | |
855 void GpuChannel::DestroyStreamIfNecessary( | |
856 const scoped_refptr<GpuChannelMessageQueue>& queue) { | |
857 int32_t stream_id = queue->stream_id(); | |
858 if (streams_to_num_routes_[stream_id] == 0) { | |
859 queue->Disable(); | |
860 streams_to_num_routes_.erase(stream_id); | |
861 streams_.erase(stream_id); | |
862 } | |
863 } | |
864 | |
865 void GpuChannel::AddRouteToStream(int32_t route_id, int32_t stream_id) { | |
866 DCHECK(streams_.find(stream_id) != streams_.end()); | |
867 DCHECK(routes_to_streams_.find(route_id) == routes_to_streams_.end()); | |
868 streams_to_num_routes_[stream_id]++; | |
869 routes_to_streams_.insert(std::make_pair(route_id, stream_id)); | |
870 filter_->AddRoute(route_id, streams_[stream_id]); | |
871 } | |
872 | |
873 void GpuChannel::RemoveRouteFromStream(int32_t route_id) { | |
874 DCHECK(routes_to_streams_.find(route_id) != routes_to_streams_.end()); | |
875 int32_t stream_id = routes_to_streams_[route_id]; | |
876 DCHECK(streams_.find(stream_id) != streams_.end()); | |
877 routes_to_streams_.erase(route_id); | |
878 streams_to_num_routes_[stream_id]--; | |
879 filter_->RemoveRoute(route_id); | |
880 DestroyStreamIfNecessary(streams_[stream_id]); | |
881 } | |
882 | |
883 #if defined(OS_ANDROID) | 763 #if defined(OS_ANDROID) |
884 const GpuCommandBufferStub* GpuChannel::GetOneStub() const { | 764 const GpuCommandBufferStub* GpuChannel::GetOneStub() const { |
885 for (const auto& kv : stubs_) { | 765 for (const auto& kv : stubs_) { |
886 const GpuCommandBufferStub* stub = kv.second.get(); | 766 const GpuCommandBufferStub* stub = kv.second.get(); |
887 if (stub->decoder() && !stub->decoder()->WasContextLost()) | 767 if (stub->decoder() && !stub->decoder()->WasContextLost()) |
888 return stub; | 768 return stub; |
889 } | 769 } |
890 return nullptr; | 770 return nullptr; |
891 } | 771 } |
892 #endif | 772 #endif |
(...skipping 28 matching lines...) Expand all Loading... |
921 !allow_view_command_buffers_) { | 801 !allow_view_command_buffers_) { |
922 DLOG(ERROR) << "GpuChannel::CreateCommandBuffer(): attempt to create a " | 802 DLOG(ERROR) << "GpuChannel::CreateCommandBuffer(): attempt to create a " |
923 "view context on a non-priviledged channel"; | 803 "view context on a non-priviledged channel"; |
924 return nullptr; | 804 return nullptr; |
925 } | 805 } |
926 | 806 |
927 int32_t share_group_id = init_params.share_group_id; | 807 int32_t share_group_id = init_params.share_group_id; |
928 GpuCommandBufferStub* share_group = LookupCommandBuffer(share_group_id); | 808 GpuCommandBufferStub* share_group = LookupCommandBuffer(share_group_id); |
929 | 809 |
930 if (!share_group && share_group_id != MSG_ROUTING_NONE) { | 810 if (!share_group && share_group_id != MSG_ROUTING_NONE) { |
931 DLOG(ERROR) | 811 DLOG(ERROR) << "GpuChannel::CreateCommandBuffer(): invalid share group id"; |
932 << "GpuChannel::CreateCommandBuffer(): invalid share group id"; | |
933 return nullptr; | 812 return nullptr; |
934 } | 813 } |
935 | 814 |
936 int32_t stream_id = init_params.stream_id; | 815 int32_t stream_id = init_params.stream_id; |
937 if (share_group && stream_id != share_group->stream_id()) { | 816 if (share_group && stream_id != share_group->stream_id()) { |
938 DLOG(ERROR) << "GpuChannel::CreateCommandBuffer(): stream id does not " | 817 DLOG(ERROR) << "GpuChannel::CreateCommandBuffer(): stream id does not " |
939 "match share group stream id"; | 818 "match share group stream id"; |
940 return nullptr; | 819 return nullptr; |
941 } | 820 } |
942 | 821 |
(...skipping 12 matching lines...) Expand all Loading... |
955 "not initialized"; | 834 "not initialized"; |
956 return nullptr; | 835 return nullptr; |
957 } | 836 } |
958 | 837 |
959 if (share_group && share_group->decoder()->WasContextLost()) { | 838 if (share_group && share_group->decoder()->WasContextLost()) { |
960 DLOG(ERROR) << "GpuChannel::CreateCommandBuffer(): shared context was " | 839 DLOG(ERROR) << "GpuChannel::CreateCommandBuffer(): shared context was " |
961 "already lost"; | 840 "already lost"; |
962 return nullptr; | 841 return nullptr; |
963 } | 842 } |
964 | 843 |
965 scoped_refptr<GpuChannelMessageQueue> queue = LookupStream(stream_id); | 844 CommandBufferId command_buffer_id = |
966 if (!queue) | 845 GenerateCommandBufferId(client_id_, route_id); |
967 queue = CreateStream(stream_id, stream_priority); | 846 |
| 847 // TODO(sunnyps): Lookup sequence id using stream id to sequence id map. |
| 848 SequenceId sequence_id = message_queue_->sequence_id(); |
968 | 849 |
969 std::unique_ptr<GpuCommandBufferStub> stub(GpuCommandBufferStub::Create( | 850 std::unique_ptr<GpuCommandBufferStub> stub(GpuCommandBufferStub::Create( |
970 this, share_group, init_params, route_id, std::move(shared_state_shm))); | 851 this, share_group, init_params, command_buffer_id, sequence_id, stream_id, |
| 852 route_id, std::move(shared_state_shm))); |
971 | 853 |
972 if (!stub) { | 854 if (!AddRoute(route_id, sequence_id, stub.get())) { |
973 DestroyStreamIfNecessary(queue); | |
974 return nullptr; | |
975 } | |
976 | |
977 if (!AddRoute(route_id, stream_id, stub.get())) { | |
978 DestroyStreamIfNecessary(queue); | |
979 DLOG(ERROR) << "GpuChannel::CreateCommandBuffer(): failed to add route"; | 855 DLOG(ERROR) << "GpuChannel::CreateCommandBuffer(): failed to add route"; |
980 return nullptr; | 856 return nullptr; |
981 } | 857 } |
982 | 858 |
983 return stub; | 859 return stub; |
984 } | 860 } |
985 | 861 |
986 void GpuChannel::OnDestroyCommandBuffer(int32_t route_id) { | 862 void GpuChannel::OnDestroyCommandBuffer(int32_t route_id) { |
987 TRACE_EVENT1("gpu", "GpuChannel::OnDestroyCommandBuffer", | 863 TRACE_EVENT1("gpu", "GpuChannel::OnDestroyCommandBuffer", "route_id", |
988 "route_id", route_id); | 864 route_id); |
989 | 865 |
990 std::unique_ptr<GpuCommandBufferStub> stub; | 866 std::unique_ptr<GpuCommandBufferStub> stub; |
991 auto it = stubs_.find(route_id); | 867 auto it = stubs_.find(route_id); |
992 if (it != stubs_.end()) { | 868 if (it != stubs_.end()) { |
993 stub = std::move(it->second); | 869 stub = std::move(it->second); |
994 stubs_.erase(it); | 870 stubs_.erase(it); |
995 } | 871 } |
996 // In case the renderer is currently blocked waiting for a sync reply from the | 872 // In case the renderer is currently blocked waiting for a sync reply from the |
997 // stub, we need to make sure to reschedule the correct stream here. | 873 // stub, we need to make sure to reschedule the correct stream here. |
998 if (stub && !stub->IsScheduled()) { | 874 if (stub && !stub->IsScheduled()) { |
999 // This stub won't get a chance to reschedule the stream so do that now. | 875 // This stub won't get a chance to be scheduled so do that now. |
1000 OnStreamRescheduled(stub->stream_id(), true); | 876 OnCommandBufferScheduled(stub.get()); |
1001 } | 877 } |
1002 | 878 |
1003 RemoveRoute(route_id); | 879 RemoveRoute(route_id); |
1004 } | 880 } |
1005 | 881 |
1006 void GpuChannel::OnGetDriverBugWorkArounds( | 882 void GpuChannel::OnGetDriverBugWorkArounds( |
1007 std::vector<std::string>* gpu_driver_bug_workarounds) { | 883 std::vector<std::string>* gpu_driver_bug_workarounds) { |
1008 gpu_driver_bug_workarounds->clear(); | 884 gpu_driver_bug_workarounds->clear(); |
1009 #define GPU_OP(type, name) \ | 885 #define GPU_OP(type, name) \ |
1010 if (gpu_channel_manager_->gpu_driver_bug_workarounds().name) \ | 886 if (gpu_channel_manager_->gpu_driver_bug_workarounds().name) \ |
1011 gpu_driver_bug_workarounds->push_back(#name); | 887 gpu_driver_bug_workarounds->push_back(#name); |
1012 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP) | 888 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP) |
1013 #undef GPU_OP | 889 #undef GPU_OP |
1014 } | 890 } |
1015 | 891 |
1016 void GpuChannel::CacheShader(const std::string& key, | 892 void GpuChannel::CacheShader(const std::string& key, |
1017 const std::string& shader) { | 893 const std::string& shader) { |
1018 gpu_channel_manager_->delegate()->StoreShaderToDisk(client_id_, key, shader); | 894 gpu_channel_manager_->delegate()->StoreShaderToDisk(client_id_, key, shader); |
1019 } | 895 } |
1020 | 896 |
1021 void GpuChannel::AddFilter(IPC::MessageFilter* filter) { | 897 void GpuChannel::AddFilter(IPC::MessageFilter* filter) { |
1022 io_task_runner_->PostTask( | 898 io_task_runner_->PostTask( |
1023 FROM_HERE, base::Bind(&GpuChannelMessageFilter::AddChannelFilter, | 899 FROM_HERE, base::Bind(&GpuChannelMessageFilter::AddChannelFilter, filter_, |
1024 filter_, make_scoped_refptr(filter))); | 900 make_scoped_refptr(filter))); |
1025 } | 901 } |
1026 | 902 |
1027 void GpuChannel::RemoveFilter(IPC::MessageFilter* filter) { | 903 void GpuChannel::RemoveFilter(IPC::MessageFilter* filter) { |
1028 io_task_runner_->PostTask( | 904 io_task_runner_->PostTask( |
1029 FROM_HERE, base::Bind(&GpuChannelMessageFilter::RemoveChannelFilter, | 905 FROM_HERE, base::Bind(&GpuChannelMessageFilter::RemoveChannelFilter, |
1030 filter_, make_scoped_refptr(filter))); | 906 filter_, make_scoped_refptr(filter))); |
1031 } | 907 } |
1032 | 908 |
1033 uint64_t GpuChannel::GetMemoryUsage() { | 909 uint64_t GpuChannel::GetMemoryUsage() { |
1034 // Collect the unique memory trackers in use by the |stubs_|. | 910 // Collect the unique memory trackers in use by the |stubs_|. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 | 948 |
1073 return manager->gpu_memory_buffer_factory() | 949 return manager->gpu_memory_buffer_factory() |
1074 ->AsImageFactory() | 950 ->AsImageFactory() |
1075 ->CreateImageForGpuMemoryBuffer(handle, size, format, internalformat, | 951 ->CreateImageForGpuMemoryBuffer(handle, size, format, internalformat, |
1076 client_id_, surface_handle); | 952 client_id_, surface_handle); |
1077 } | 953 } |
1078 } | 954 } |
1079 } | 955 } |
1080 | 956 |
1081 } // namespace gpu | 957 } // namespace gpu |
OLD | NEW |