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 "content/common/gpu/gpu_channel.h" | 5 #include "content/common/gpu/gpu_channel.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 // Once we trigger a preemption, the maximum duration that we will wait | 63 // Once we trigger a preemption, the maximum duration that we will wait |
64 // before clearing the preemption. | 64 // before clearing the preemption. |
65 const int64 kMaxPreemptTimeMs = kVsyncIntervalMs; | 65 const int64 kMaxPreemptTimeMs = kVsyncIntervalMs; |
66 | 66 |
67 // Stop the preemption once the time for the longest pending IPC drops | 67 // Stop the preemption once the time for the longest pending IPC drops |
68 // below this threshold. | 68 // below this threshold. |
69 const int64 kStopPreemptThresholdMs = kVsyncIntervalMs; | 69 const int64 kStopPreemptThresholdMs = kVsyncIntervalMs; |
70 | 70 |
71 } // anonymous namespace | 71 } // anonymous namespace |
72 | 72 |
73 // Begin order numbers at 1 so 0 can mean no orders. | |
74 uint32_t GpuChannelMessageQueue::global_order_counter_ = 1; | |
75 | |
76 scoped_refptr<GpuChannelMessageQueue> GpuChannelMessageQueue::Create( | 73 scoped_refptr<GpuChannelMessageQueue> GpuChannelMessageQueue::Create( |
77 const base::WeakPtr<GpuChannel>& gpu_channel, | 74 const base::WeakPtr<GpuChannel>& gpu_channel, |
78 base::SingleThreadTaskRunner* task_runner) { | 75 base::SingleThreadTaskRunner* task_runner) { |
79 return new GpuChannelMessageQueue(gpu_channel, task_runner); | 76 return new GpuChannelMessageQueue(gpu_channel, task_runner); |
80 } | 77 } |
81 | 78 |
79 scoped_refptr<gpu::SyncPointClientState> | |
80 GpuChannelMessageQueue::sync_point_client_state() { | |
81 return sync_point_client_state_; | |
82 } | |
83 | |
82 GpuChannelMessageQueue::GpuChannelMessageQueue( | 84 GpuChannelMessageQueue::GpuChannelMessageQueue( |
83 const base::WeakPtr<GpuChannel>& gpu_channel, | 85 const base::WeakPtr<GpuChannel>& gpu_channel, |
84 base::SingleThreadTaskRunner* task_runner) | 86 base::SingleThreadTaskRunner* task_runner) |
85 : enabled_(true), | 87 : enabled_(true), |
86 unprocessed_order_num_(0), | 88 sync_point_client_state_(gpu::SyncPointClientState::Create()), |
87 processed_order_num_(0), | |
88 gpu_channel_(gpu_channel), | 89 gpu_channel_(gpu_channel), |
89 task_runner_(task_runner) {} | 90 task_runner_(task_runner) {} |
90 | 91 |
91 GpuChannelMessageQueue::~GpuChannelMessageQueue() { | 92 GpuChannelMessageQueue::~GpuChannelMessageQueue() { |
92 DCHECK(channel_messages_.empty()); | 93 DCHECK(channel_messages_.empty()); |
93 } | 94 } |
94 | 95 |
95 uint32_t GpuChannelMessageQueue::GetUnprocessedOrderNum() const { | 96 uint32_t GpuChannelMessageQueue::GetUnprocessedOrderNum() const { |
96 base::AutoLock auto_lock(channel_messages_lock_); | 97 return sync_point_client_state_->unprocessed_order_num(); |
97 return unprocessed_order_num_; | |
98 } | 98 } |
99 | 99 |
100 void GpuChannelMessageQueue::PushBackMessage(const IPC::Message& message) { | 100 uint32_t GpuChannelMessageQueue::GetProcessedOrderNum() const { |
101 return sync_point_client_state_->processed_order_num(); | |
102 } | |
103 | |
104 void GpuChannelMessageQueue::PushBackMessage( | |
105 gpu::SyncPointManager* sync_point_manager, const IPC::Message& message) { | |
101 base::AutoLock auto_lock(channel_messages_lock_); | 106 base::AutoLock auto_lock(channel_messages_lock_); |
102 if (enabled_) | 107 if (enabled_) |
piman
2015/09/22 19:43:08
nit: needs {} per style.
David Yen
2015/09/22 20:01:54
Done.
| |
103 PushMessageHelper(make_scoped_ptr(new GpuChannelMessage(message))); | 108 PushMessageHelper(sync_point_manager, |
109 make_scoped_ptr(new GpuChannelMessage(message))); | |
104 } | 110 } |
105 | 111 |
106 bool GpuChannelMessageQueue::GenerateSyncPointMessage( | 112 bool GpuChannelMessageQueue::GenerateSyncPointMessage( |
107 gpu::SyncPointManager* sync_point_manager, | 113 gpu::SyncPointManager* sync_point_manager, |
108 const IPC::Message& message, | 114 const IPC::Message& message, |
109 bool retire_sync_point, | 115 bool retire_sync_point, |
110 uint32_t* sync_point) { | 116 uint32_t* sync_point) { |
111 DCHECK_EQ((uint32_t)GpuCommandBufferMsg_InsertSyncPoint::ID, message.type()); | 117 DCHECK_EQ((uint32_t)GpuCommandBufferMsg_InsertSyncPoint::ID, message.type()); |
112 DCHECK(sync_point); | 118 DCHECK(sync_point); |
113 base::AutoLock auto_lock(channel_messages_lock_); | 119 base::AutoLock auto_lock(channel_messages_lock_); |
114 if (enabled_) { | 120 if (enabled_) { |
115 *sync_point = sync_point_manager->GenerateSyncPoint(); | 121 *sync_point = sync_point_manager->GenerateSyncPoint(); |
116 | 122 |
117 scoped_ptr<GpuChannelMessage> msg(new GpuChannelMessage(message)); | 123 scoped_ptr<GpuChannelMessage> msg(new GpuChannelMessage(message)); |
118 msg->retire_sync_point = retire_sync_point; | 124 msg->retire_sync_point = retire_sync_point; |
119 msg->sync_point = *sync_point; | 125 msg->sync_point = *sync_point; |
120 | 126 |
121 PushMessageHelper(msg.Pass()); | 127 PushMessageHelper(sync_point_manager, msg.Pass()); |
122 return true; | 128 return true; |
123 } | 129 } |
124 return false; | 130 return false; |
125 } | 131 } |
126 | 132 |
127 bool GpuChannelMessageQueue::HasQueuedMessages() const { | 133 bool GpuChannelMessageQueue::HasQueuedMessages() const { |
128 base::AutoLock auto_lock(channel_messages_lock_); | 134 base::AutoLock auto_lock(channel_messages_lock_); |
129 return !channel_messages_.empty(); | 135 return !channel_messages_.empty(); |
130 } | 136 } |
131 | 137 |
132 base::TimeTicks GpuChannelMessageQueue::GetNextMessageTimeTick() const { | 138 base::TimeTicks GpuChannelMessageQueue::GetNextMessageTimeTick() const { |
133 base::AutoLock auto_lock(channel_messages_lock_); | 139 base::AutoLock auto_lock(channel_messages_lock_); |
134 if (!channel_messages_.empty()) | 140 if (!channel_messages_.empty()) |
135 return channel_messages_.front()->time_received; | 141 return channel_messages_.front()->time_received; |
136 return base::TimeTicks(); | 142 return base::TimeTicks(); |
137 } | 143 } |
138 | 144 |
139 GpuChannelMessage* GpuChannelMessageQueue::GetNextMessage() const { | 145 GpuChannelMessage* GpuChannelMessageQueue::GetNextMessage() const { |
140 base::AutoLock auto_lock(channel_messages_lock_); | 146 base::AutoLock auto_lock(channel_messages_lock_); |
141 if (!channel_messages_.empty()) { | 147 if (!channel_messages_.empty()) { |
142 DCHECK_GT(channel_messages_.front()->order_number, processed_order_num_); | 148 DCHECK_GT(channel_messages_.front()->order_number, |
143 DCHECK_LE(channel_messages_.front()->order_number, unprocessed_order_num_); | 149 sync_point_client_state_->processed_order_num()); |
144 return channel_messages_.front(); | 150 DCHECK_LE(channel_messages_.front()->order_number, |
151 sync_point_client_state_->unprocessed_order_num()); | |
152 | |
153 GpuChannelMessage* m = channel_messages_.front(); | |
154 sync_point_client_state_->BeginProcessingOrderNumber(m->order_number); | |
sunnyps
2015/09/22 17:25:59
How does this work? GetNextMessage is const but Be
piman
2015/09/22 19:43:08
scoped_refptr::operator-> is const but returns a T
David Yen
2015/09/22 20:01:54
Done.
| |
155 return m; | |
145 } | 156 } |
146 return nullptr; | 157 return nullptr; |
147 } | 158 } |
148 | 159 |
149 bool GpuChannelMessageQueue::MessageProcessed() { | 160 bool GpuChannelMessageQueue::MessageProcessed() { |
150 base::AutoLock auto_lock(channel_messages_lock_); | 161 base::AutoLock auto_lock(channel_messages_lock_); |
151 DCHECK(!channel_messages_.empty()); | 162 DCHECK(!channel_messages_.empty()); |
152 scoped_ptr<GpuChannelMessage> msg(channel_messages_.front()); | 163 scoped_ptr<GpuChannelMessage> msg(channel_messages_.front()); |
153 channel_messages_.pop_front(); | 164 channel_messages_.pop_front(); |
154 processed_order_num_ = msg->order_number; | 165 sync_point_client_state_->FinishProcessingOrderNumber(msg->order_number); |
155 return !channel_messages_.empty(); | 166 return !channel_messages_.empty(); |
156 } | 167 } |
157 | 168 |
158 void GpuChannelMessageQueue::DeleteAndDisableMessages( | 169 void GpuChannelMessageQueue::DeleteAndDisableMessages( |
159 GpuChannelManager* gpu_channel_manager) { | 170 GpuChannelManager* gpu_channel_manager) { |
160 { | 171 { |
161 base::AutoLock auto_lock(channel_messages_lock_); | 172 base::AutoLock auto_lock(channel_messages_lock_); |
162 DCHECK(enabled_); | 173 DCHECK(enabled_); |
163 enabled_ = false; | 174 enabled_ = false; |
164 } | 175 } |
(...skipping 14 matching lines...) Expand all Loading... | |
179 } | 190 } |
180 } | 191 } |
181 } | 192 } |
182 | 193 |
183 void GpuChannelMessageQueue::ScheduleHandleMessage() { | 194 void GpuChannelMessageQueue::ScheduleHandleMessage() { |
184 task_runner_->PostTask(FROM_HERE, | 195 task_runner_->PostTask(FROM_HERE, |
185 base::Bind(&GpuChannel::HandleMessage, gpu_channel_)); | 196 base::Bind(&GpuChannel::HandleMessage, gpu_channel_)); |
186 } | 197 } |
187 | 198 |
188 void GpuChannelMessageQueue::PushMessageHelper( | 199 void GpuChannelMessageQueue::PushMessageHelper( |
200 gpu::SyncPointManager* sync_point_manager, | |
189 scoped_ptr<GpuChannelMessage> msg) { | 201 scoped_ptr<GpuChannelMessage> msg) { |
190 channel_messages_lock_.AssertAcquired(); | 202 channel_messages_lock_.AssertAcquired(); |
191 DCHECK(enabled_); | 203 DCHECK(enabled_); |
192 | 204 |
193 msg->order_number = global_order_counter_++; | 205 msg->order_number = |
206 sync_point_client_state_->GenerateUnprocessedOrderNumber( | |
207 sync_point_manager); | |
194 msg->time_received = base::TimeTicks::Now(); | 208 msg->time_received = base::TimeTicks::Now(); |
195 | 209 |
196 unprocessed_order_num_ = msg->order_number; | |
197 | |
198 bool had_messages = !channel_messages_.empty(); | 210 bool had_messages = !channel_messages_.empty(); |
199 channel_messages_.push_back(msg.release()); | 211 channel_messages_.push_back(msg.release()); |
200 if (!had_messages) | 212 if (!had_messages) |
201 ScheduleHandleMessage(); | 213 ScheduleHandleMessage(); |
202 } | 214 } |
203 | 215 |
204 GpuChannelMessageFilter::GpuChannelMessageFilter( | 216 GpuChannelMessageFilter::GpuChannelMessageFilter( |
205 const base::WeakPtr<GpuChannel>& gpu_channel, | 217 const base::WeakPtr<GpuChannel>& gpu_channel, |
206 GpuChannelMessageQueue* message_queue, | 218 GpuChannelMessageQueue* message_queue, |
207 gpu::SyncPointManager* sync_point_manager, | 219 gpu::SyncPointManager* sync_point_manager, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 } | 344 } |
333 | 345 |
334 // Forward all other messages to the GPU Channel. | 346 // Forward all other messages to the GPU Channel. |
335 if (!handled) { | 347 if (!handled) { |
336 if (message.type() == GpuCommandBufferMsg_WaitForTokenInRange::ID || | 348 if (message.type() == GpuCommandBufferMsg_WaitForTokenInRange::ID || |
337 message.type() == GpuCommandBufferMsg_WaitForGetOffsetInRange::ID) { | 349 message.type() == GpuCommandBufferMsg_WaitForGetOffsetInRange::ID) { |
338 task_runner_->PostTask(FROM_HERE, | 350 task_runner_->PostTask(FROM_HERE, |
339 base::Bind(&GpuChannel::HandleOutOfOrderMessage, | 351 base::Bind(&GpuChannel::HandleOutOfOrderMessage, |
340 gpu_channel_, message)); | 352 gpu_channel_, message)); |
341 } else { | 353 } else { |
342 message_queue_->PushBackMessage(message); | 354 message_queue_->PushBackMessage(sync_point_manager_, message); |
343 } | 355 } |
344 handled = true; | 356 handled = true; |
345 } | 357 } |
346 | 358 |
347 UpdatePreemptionState(); | 359 UpdatePreemptionState(); |
348 return handled; | 360 return handled; |
349 } | 361 } |
350 | 362 |
351 void GpuChannelMessageFilter::OnMessageProcessed() { | 363 void GpuChannelMessageFilter::OnMessageProcessed() { |
352 UpdatePreemptionState(); | 364 UpdatePreemptionState(); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 channel_->AddFilter(filter_.get()); | 616 channel_->AddFilter(filter_.get()); |
605 | 617 |
606 return channel_handle; | 618 return channel_handle; |
607 } | 619 } |
608 | 620 |
609 base::ProcessId GpuChannel::GetClientPID() const { | 621 base::ProcessId GpuChannel::GetClientPID() const { |
610 return channel_->GetPeerPID(); | 622 return channel_->GetPeerPID(); |
611 } | 623 } |
612 | 624 |
613 uint32_t GpuChannel::GetProcessedOrderNum() const { | 625 uint32_t GpuChannel::GetProcessedOrderNum() const { |
614 return message_queue_->processed_order_num(); | 626 return message_queue_->GetProcessedOrderNum(); |
615 } | 627 } |
616 | 628 |
617 uint32_t GpuChannel::GetUnprocessedOrderNum() const { | 629 uint32_t GpuChannel::GetUnprocessedOrderNum() const { |
618 return message_queue_->GetUnprocessedOrderNum(); | 630 return message_queue_->GetUnprocessedOrderNum(); |
619 } | 631 } |
620 | 632 |
621 bool GpuChannel::OnMessageReceived(const IPC::Message& message) { | 633 bool GpuChannel::OnMessageReceived(const IPC::Message& message) { |
622 // All messages should be pushed to channel_messages_ and handled separately. | 634 // All messages should be pushed to channel_messages_ and handled separately. |
623 NOTREACHED(); | 635 NOTREACHED(); |
624 return false; | 636 return false; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
799 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, | 811 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, |
800 OnDestroyCommandBuffer) | 812 OnDestroyCommandBuffer) |
801 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuMsg_CreateJpegDecoder, | 813 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuMsg_CreateJpegDecoder, |
802 OnCreateJpegDecoder) | 814 OnCreateJpegDecoder) |
803 IPC_MESSAGE_UNHANDLED(handled = false) | 815 IPC_MESSAGE_UNHANDLED(handled = false) |
804 IPC_END_MESSAGE_MAP() | 816 IPC_END_MESSAGE_MAP() |
805 DCHECK(handled) << msg.type(); | 817 DCHECK(handled) << msg.type(); |
806 return handled; | 818 return handled; |
807 } | 819 } |
808 | 820 |
821 scoped_refptr<gpu::SyncPointClientState> GpuChannel::GetSyncPointClientState() { | |
822 return message_queue_->sync_point_client_state(); | |
823 } | |
824 | |
809 void GpuChannel::HandleMessage() { | 825 void GpuChannel::HandleMessage() { |
810 // If we have been preempted by another channel, just post a task to wake up. | 826 // If we have been preempted by another channel, just post a task to wake up. |
811 if (preempted_flag_ && preempted_flag_->IsSet()) { | 827 if (preempted_flag_ && preempted_flag_->IsSet()) { |
812 ScheduleHandleMessage(); | 828 ScheduleHandleMessage(); |
813 return; | 829 return; |
814 } | 830 } |
815 | 831 |
816 GpuChannelMessage* m = message_queue_->GetNextMessage(); | 832 GpuChannelMessage* m = message_queue_->GetNextMessage(); |
817 | 833 |
818 // TODO(sunnyps): This could be a DCHECK maybe? | 834 // TODO(sunnyps): This could be a DCHECK maybe? |
819 if (!m) | 835 if (!m) |
820 return; | 836 return; |
821 | 837 |
822 current_order_num_ = m->order_number; | |
823 const IPC::Message& message = m->message; | 838 const IPC::Message& message = m->message; |
824 int32_t routing_id = message.routing_id(); | 839 int32_t routing_id = message.routing_id(); |
825 GpuCommandBufferStub* stub = stubs_.get(routing_id); | 840 GpuCommandBufferStub* stub = stubs_.get(routing_id); |
826 | 841 |
827 DCHECK(!stub || stub->IsScheduled()); | 842 DCHECK(!stub || stub->IsScheduled()); |
828 | 843 |
829 DVLOG(1) << "received message @" << &message << " on channel @" << this | 844 DVLOG(1) << "received message @" << &message << " on channel @" << this |
830 << " with type " << message.type(); | 845 << " with type " << message.type(); |
831 | 846 |
832 bool handled = false; | 847 bool handled = false; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1062 } | 1077 } |
1063 } | 1078 } |
1064 } | 1079 } |
1065 | 1080 |
1066 void GpuChannel::HandleUpdateValueState( | 1081 void GpuChannel::HandleUpdateValueState( |
1067 unsigned int target, const gpu::ValueState& state) { | 1082 unsigned int target, const gpu::ValueState& state) { |
1068 pending_valuebuffer_state_->UpdateState(target, state); | 1083 pending_valuebuffer_state_->UpdateState(target, state); |
1069 } | 1084 } |
1070 | 1085 |
1071 } // namespace content | 1086 } // namespace content |
OLD | NEW |