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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 const int64 kStopPreemptThresholdMs = kVsyncIntervalMs; | 69 const int64 kStopPreemptThresholdMs = kVsyncIntervalMs; |
70 | 70 |
71 } // anonymous namespace | 71 } // anonymous namespace |
72 | 72 |
73 scoped_refptr<GpuChannelMessageQueue> GpuChannelMessageQueue::Create( | 73 scoped_refptr<GpuChannelMessageQueue> GpuChannelMessageQueue::Create( |
74 const base::WeakPtr<GpuChannel>& gpu_channel, | 74 const base::WeakPtr<GpuChannel>& gpu_channel, |
75 base::SingleThreadTaskRunner* task_runner) { | 75 base::SingleThreadTaskRunner* task_runner) { |
76 return new GpuChannelMessageQueue(gpu_channel, task_runner); | 76 return new GpuChannelMessageQueue(gpu_channel, task_runner); |
77 } | 77 } |
78 | 78 |
79 scoped_refptr<gpu::SyncPointClientState> | 79 scoped_refptr<gpu::SyncPointOrderData> |
80 GpuChannelMessageQueue::GetSyncPointClientState() { | 80 GpuChannelMessageQueue::GetSyncPointOrderData() { |
81 return sync_point_client_state_; | 81 return sync_point_order_data_; |
82 } | 82 } |
83 | 83 |
84 GpuChannelMessageQueue::GpuChannelMessageQueue( | 84 GpuChannelMessageQueue::GpuChannelMessageQueue( |
85 const base::WeakPtr<GpuChannel>& gpu_channel, | 85 const base::WeakPtr<GpuChannel>& gpu_channel, |
86 base::SingleThreadTaskRunner* task_runner) | 86 base::SingleThreadTaskRunner* task_runner) |
87 : enabled_(true), | 87 : enabled_(true), |
88 sync_point_client_state_(gpu::SyncPointClientState::Create()), | 88 sync_point_order_data_(gpu::SyncPointOrderData::Create()), |
89 gpu_channel_(gpu_channel), | 89 gpu_channel_(gpu_channel), |
90 task_runner_(task_runner) {} | 90 task_runner_(task_runner) {} |
91 | 91 |
92 GpuChannelMessageQueue::~GpuChannelMessageQueue() { | 92 GpuChannelMessageQueue::~GpuChannelMessageQueue() { |
93 DCHECK(channel_messages_.empty()); | 93 DCHECK(channel_messages_.empty()); |
94 } | 94 } |
95 | 95 |
96 uint32_t GpuChannelMessageQueue::GetUnprocessedOrderNum() const { | 96 uint32_t GpuChannelMessageQueue::GetUnprocessedOrderNum() const { |
97 return sync_point_client_state_->unprocessed_order_num(); | 97 return sync_point_order_data_->unprocessed_order_num(); |
98 } | 98 } |
99 | 99 |
100 uint32_t GpuChannelMessageQueue::GetProcessedOrderNum() const { | 100 uint32_t GpuChannelMessageQueue::GetProcessedOrderNum() const { |
101 return sync_point_client_state_->processed_order_num(); | 101 return sync_point_order_data_->processed_order_num(); |
102 } | 102 } |
103 | 103 |
104 void GpuChannelMessageQueue::PushBackMessage( | 104 void GpuChannelMessageQueue::PushBackMessage( |
105 gpu::SyncPointManager* sync_point_manager, const IPC::Message& message) { | 105 gpu::SyncPointManager* sync_point_manager, const IPC::Message& message) { |
106 base::AutoLock auto_lock(channel_messages_lock_); | 106 base::AutoLock auto_lock(channel_messages_lock_); |
107 if (enabled_) { | 107 if (enabled_) { |
108 PushMessageHelper(sync_point_manager, | 108 PushMessageHelper(sync_point_manager, |
109 make_scoped_ptr(new GpuChannelMessage(message))); | 109 make_scoped_ptr(new GpuChannelMessage(message))); |
110 } | 110 } |
111 } | 111 } |
(...skipping 28 matching lines...) Expand all Loading... | |
140 base::AutoLock auto_lock(channel_messages_lock_); | 140 base::AutoLock auto_lock(channel_messages_lock_); |
141 if (!channel_messages_.empty()) | 141 if (!channel_messages_.empty()) |
142 return channel_messages_.front()->time_received; | 142 return channel_messages_.front()->time_received; |
143 return base::TimeTicks(); | 143 return base::TimeTicks(); |
144 } | 144 } |
145 | 145 |
146 GpuChannelMessage* GpuChannelMessageQueue::GetNextMessage() const { | 146 GpuChannelMessage* GpuChannelMessageQueue::GetNextMessage() const { |
147 base::AutoLock auto_lock(channel_messages_lock_); | 147 base::AutoLock auto_lock(channel_messages_lock_); |
148 if (!channel_messages_.empty()) { | 148 if (!channel_messages_.empty()) { |
149 DCHECK_GT(channel_messages_.front()->order_number, | 149 DCHECK_GT(channel_messages_.front()->order_number, |
150 sync_point_client_state_->processed_order_num()); | 150 sync_point_order_data_->processed_order_num()); |
151 DCHECK_LE(channel_messages_.front()->order_number, | 151 DCHECK_LE(channel_messages_.front()->order_number, |
152 sync_point_client_state_->unprocessed_order_num()); | 152 sync_point_order_data_->unprocessed_order_num()); |
153 | 153 |
154 return channel_messages_.front(); | 154 return channel_messages_.front(); |
155 } | 155 } |
156 return nullptr; | 156 return nullptr; |
157 } | 157 } |
158 | 158 |
159 void GpuChannelMessageQueue::BeginMessageProcessing( | 159 void GpuChannelMessageQueue::BeginMessageProcessing( |
160 const GpuChannelMessage* msg) { | 160 const GpuChannelMessage* msg) { |
161 sync_point_client_state_->BeginProcessingOrderNumber(msg->order_number); | 161 sync_point_order_data_->BeginProcessingOrderNumber(msg->order_number); |
162 } | 162 } |
163 | 163 |
164 bool GpuChannelMessageQueue::MessageProcessed() { | 164 bool GpuChannelMessageQueue::MessageProcessed() { |
165 base::AutoLock auto_lock(channel_messages_lock_); | 165 base::AutoLock auto_lock(channel_messages_lock_); |
166 DCHECK(!channel_messages_.empty()); | 166 DCHECK(!channel_messages_.empty()); |
167 scoped_ptr<GpuChannelMessage> msg(channel_messages_.front()); | 167 scoped_ptr<GpuChannelMessage> msg(channel_messages_.front()); |
168 channel_messages_.pop_front(); | 168 channel_messages_.pop_front(); |
169 sync_point_client_state_->FinishProcessingOrderNumber(msg->order_number); | 169 sync_point_order_data_->FinishProcessingOrderNumber(msg->order_number); |
170 return !channel_messages_.empty(); | 170 return !channel_messages_.empty(); |
171 } | 171 } |
172 | 172 |
173 void GpuChannelMessageQueue::DeleteAndDisableMessages( | 173 void GpuChannelMessageQueue::DeleteAndDisableMessages( |
174 GpuChannelManager* gpu_channel_manager) { | 174 GpuChannelManager* gpu_channel_manager) { |
175 { | 175 { |
176 base::AutoLock auto_lock(channel_messages_lock_); | 176 base::AutoLock auto_lock(channel_messages_lock_); |
177 DCHECK(enabled_); | 177 DCHECK(enabled_); |
178 enabled_ = false; | 178 enabled_ = false; |
179 } | 179 } |
180 | 180 |
181 // We guarantee that the queues will no longer be modified after enabled_ | 181 // We guarantee that the queues will no longer be modified after enabled_ |
182 // is set to false, it is now safe to modify the queue without the lock. | 182 // is set to false, it is now safe to modify the queue without the lock. |
183 // All public facing modifying functions check enabled_ while all | 183 // All public facing modifying functions check enabled_ while all |
184 // private modifying functions DCHECK(enabled_) to enforce this. | 184 // private modifying functions DCHECK(enabled_) to enforce this. |
185 while (!channel_messages_.empty()) { | 185 while (!channel_messages_.empty()) { |
186 scoped_ptr<GpuChannelMessage> msg(channel_messages_.front()); | 186 scoped_ptr<GpuChannelMessage> msg(channel_messages_.front()); |
187 channel_messages_.pop_front(); | 187 channel_messages_.pop_front(); |
188 // This needs to clean up both GpuCommandBufferMsg_InsertSyncPoint and | 188 // This needs to clean up both GpuCommandBufferMsg_InsertSyncPoint and |
189 // GpuCommandBufferMsg_RetireSyncPoint messages, safer to just check | 189 // GpuCommandBufferMsg_RetireSyncPoint messages, safer to just check |
190 // if we have a sync point number here. | 190 // if we have a sync point number here. |
191 if (msg->sync_point) { | 191 if (msg->sync_point) { |
192 gpu_channel_manager->sync_point_manager()->RetireSyncPoint( | 192 gpu_channel_manager->sync_point_manager()->RetireSyncPoint( |
193 msg->sync_point); | 193 msg->sync_point); |
194 } | 194 } |
195 } | 195 } |
196 | |
197 if (sync_point_order_data_) { | |
198 sync_point_order_data_->Destroy(); | |
199 sync_point_order_data_ = nullptr; | |
200 } | |
196 } | 201 } |
197 | 202 |
198 void GpuChannelMessageQueue::ScheduleHandleMessage() { | 203 void GpuChannelMessageQueue::ScheduleHandleMessage() { |
199 task_runner_->PostTask(FROM_HERE, | 204 task_runner_->PostTask(FROM_HERE, |
200 base::Bind(&GpuChannel::HandleMessage, gpu_channel_)); | 205 base::Bind(&GpuChannel::HandleMessage, gpu_channel_)); |
201 } | 206 } |
202 | 207 |
203 void GpuChannelMessageQueue::PushMessageHelper( | 208 void GpuChannelMessageQueue::PushMessageHelper( |
204 gpu::SyncPointManager* sync_point_manager, | 209 gpu::SyncPointManager* sync_point_manager, |
205 scoped_ptr<GpuChannelMessage> msg) { | 210 scoped_ptr<GpuChannelMessage> msg) { |
206 channel_messages_lock_.AssertAcquired(); | 211 channel_messages_lock_.AssertAcquired(); |
207 DCHECK(enabled_); | 212 DCHECK(enabled_); |
208 | 213 |
209 msg->order_number = | 214 msg->order_number = |
210 sync_point_client_state_->GenerateUnprocessedOrderNumber( | 215 sync_point_order_data_->GenerateUnprocessedOrderNumber( |
211 sync_point_manager); | 216 sync_point_manager); |
212 msg->time_received = base::TimeTicks::Now(); | 217 msg->time_received = base::TimeTicks::Now(); |
213 | 218 |
214 bool had_messages = !channel_messages_.empty(); | 219 bool had_messages = !channel_messages_.empty(); |
215 channel_messages_.push_back(msg.release()); | 220 channel_messages_.push_back(msg.release()); |
216 if (!had_messages) | 221 if (!had_messages) |
217 ScheduleHandleMessage(); | 222 ScheduleHandleMessage(); |
218 } | 223 } |
219 | 224 |
220 GpuChannelMessageFilter::GpuChannelMessageFilter( | 225 GpuChannelMessageFilter::GpuChannelMessageFilter( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 } | 299 } |
295 | 300 |
296 bool GpuChannelMessageFilter::OnMessageReceived(const IPC::Message& message) { | 301 bool GpuChannelMessageFilter::OnMessageReceived(const IPC::Message& message) { |
297 DCHECK(sender_); | 302 DCHECK(sender_); |
298 | 303 |
299 if (message.should_unblock() || message.is_reply()) { | 304 if (message.should_unblock() || message.is_reply()) { |
300 DLOG(ERROR) << "Unexpected message type"; | 305 DLOG(ERROR) << "Unexpected message type"; |
301 return true; | 306 return true; |
302 } | 307 } |
303 | 308 |
309 if (message.type() == GpuChannelMsg_Nop::ID) | |
310 return true; | |
piman
2015/09/30 22:50:22
You will need to send the reply here. This is typi
David Yen
2015/09/30 23:55:18
Done.
| |
311 | |
304 for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_) { | 312 for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_) { |
305 if (filter->OnMessageReceived(message)) { | 313 if (filter->OnMessageReceived(message)) { |
306 return true; | 314 return true; |
307 } | 315 } |
308 } | 316 } |
309 | 317 |
310 bool handled = false; | 318 bool handled = false; |
311 if ((message.type() == GpuCommandBufferMsg_RetireSyncPoint::ID) && | 319 if ((message.type() == GpuCommandBufferMsg_RetireSyncPoint::ID) && |
312 !future_sync_points_) { | 320 !future_sync_points_) { |
313 DLOG(ERROR) << "Untrusted client should not send " | 321 DLOG(ERROR) << "Untrusted client should not send " |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, | 789 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, |
782 OnDestroyCommandBuffer) | 790 OnDestroyCommandBuffer) |
783 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuMsg_CreateJpegDecoder, | 791 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuMsg_CreateJpegDecoder, |
784 OnCreateJpegDecoder) | 792 OnCreateJpegDecoder) |
785 IPC_MESSAGE_UNHANDLED(handled = false) | 793 IPC_MESSAGE_UNHANDLED(handled = false) |
786 IPC_END_MESSAGE_MAP() | 794 IPC_END_MESSAGE_MAP() |
787 DCHECK(handled) << msg.type(); | 795 DCHECK(handled) << msg.type(); |
788 return handled; | 796 return handled; |
789 } | 797 } |
790 | 798 |
791 scoped_refptr<gpu::SyncPointClientState> GpuChannel::GetSyncPointClientState() { | 799 scoped_refptr<gpu::SyncPointOrderData> GpuChannel::GetSyncPointOrderData() { |
792 return message_queue_->GetSyncPointClientState(); | 800 return message_queue_->GetSyncPointOrderData(); |
793 } | 801 } |
794 | 802 |
795 void GpuChannel::HandleMessage() { | 803 void GpuChannel::HandleMessage() { |
796 // If we have been preempted by another channel, just post a task to wake up. | 804 // If we have been preempted by another channel, just post a task to wake up. |
797 if (preempted_flag_ && preempted_flag_->IsSet()) { | 805 if (preempted_flag_ && preempted_flag_->IsSet()) { |
798 ScheduleHandleMessage(); | 806 ScheduleHandleMessage(); |
799 return; | 807 return; |
800 } | 808 } |
801 | 809 |
802 GpuChannelMessage* m = message_queue_->GetNextMessage(); | 810 GpuChannelMessage* m = message_queue_->GetNextMessage(); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1057 } | 1065 } |
1058 } | 1066 } |
1059 } | 1067 } |
1060 | 1068 |
1061 void GpuChannel::HandleUpdateValueState( | 1069 void GpuChannel::HandleUpdateValueState( |
1062 unsigned int target, const gpu::ValueState& state) { | 1070 unsigned int target, const gpu::ValueState& state) { |
1063 pending_valuebuffer_state_->UpdateState(target, state); | 1071 pending_valuebuffer_state_->UpdateState(target, state); |
1064 } | 1072 } |
1065 | 1073 |
1066 } // namespace content | 1074 } // namespace content |
OLD | NEW |