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 #if defined(OS_WIN) | 5 #if defined(OS_WIN) |
6 #include <windows.h> | 6 #include <windows.h> |
7 #endif | 7 #endif |
8 | 8 |
9 #include "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
10 | 10 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 void OnFilterAdded(IPC::Sender* sender) override { | 91 void OnFilterAdded(IPC::Sender* sender) override { |
92 DCHECK(!sender_); | 92 DCHECK(!sender_); |
93 sender_ = sender; | 93 sender_ = sender; |
94 } | 94 } |
95 | 95 |
96 void OnFilterRemoved() override { | 96 void OnFilterRemoved() override { |
97 DCHECK(sender_); | 97 DCHECK(sender_); |
98 sender_ = NULL; | 98 sender_ = NULL; |
99 } | 99 } |
100 | 100 |
| 101 struct MessageStatus { |
| 102 int routing_id; |
| 103 bool forwarded; |
| 104 bool handled; |
| 105 }; |
| 106 |
| 107 void OnRetireSyncPoint(uint32 sync_point) { |
| 108 if (future_sync_points_) { |
| 109 current_status_.handled = false; |
| 110 } else { |
| 111 DLOG(ERROR) << "Untrusted client should not send " |
| 112 "GpuCommandBufferMsg_RetireSyncPoint message"; |
| 113 current_status_.forwarded = false; |
| 114 } |
| 115 } |
| 116 |
| 117 void OnAsyncFlush(int32 put_offset, |
| 118 uint32 flush_count, |
| 119 const std::vector<uint32>& sync_points, |
| 120 const std::vector<ui::LatencyInfo>& latency_info) { |
| 121 std::vector<uint32> sanitized_sync_points; |
| 122 for (uint32 sync_point : sync_points) { |
| 123 if (sync_point_manager_->WasSyncPointGenerated(sync_point)) |
| 124 sanitized_sync_points.push_back(sync_point); |
| 125 } |
| 126 message_loop_->PostTask( |
| 127 FROM_HERE, |
| 128 base::Bind(base::IgnoreResult(&GpuChannel::OnMessageReceived), |
| 129 gpu_channel_, |
| 130 GpuCommandBufferMsg_AsyncFlush( |
| 131 current_status_.routing_id, put_offset, flush_count, |
| 132 sanitized_sync_points, latency_info))); |
| 133 } |
| 134 |
| 135 void OnInsertSyncPoint(bool retire, uint32* sync_point) { |
| 136 if (!future_sync_points_ && !retire) { |
| 137 *sync_point = 0; |
| 138 LOG(ERROR) << "Untrusted contexts can't create future sync points"; |
| 139 current_status_.forwarded = false; |
| 140 return; |
| 141 } |
| 142 *sync_point = sync_point_manager_->GenerateSyncPoint(); |
| 143 message_loop_->PostTask( |
| 144 FROM_HERE, |
| 145 base::Bind(&GpuChannelMessageFilter::InsertSyncPointOnMainThread, |
| 146 gpu_channel_, sync_point_manager_, |
| 147 current_status_.routing_id, retire, *sync_point)); |
| 148 } |
| 149 |
101 bool OnMessageReceived(const IPC::Message& message) override { | 150 bool OnMessageReceived(const IPC::Message& message) override { |
102 DCHECK(sender_); | 151 DCHECK(sender_); |
103 | 152 |
104 bool handled = false; | 153 current_status_.routing_id = message.routing_id(); |
105 if ((message.type() == GpuCommandBufferMsg_RetireSyncPoint::ID) && | 154 current_status_.forwarded = true; |
106 !future_sync_points_) { | 155 current_status_.handled = true; |
107 DLOG(ERROR) << "Untrusted client should not send " | 156 IPC_BEGIN_MESSAGE_MAP(GpuChannelMessageFilter, message) |
108 "GpuCommandBufferMsg_RetireSyncPoint message"; | 157 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RetireSyncPoint, |
109 return true; | 158 OnRetireSyncPoint) |
| 159 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush) |
| 160 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_InsertSyncPoint, |
| 161 OnInsertSyncPoint) |
| 162 IPC_MESSAGE_UNHANDLED(current_status_.handled = false) |
| 163 IPC_END_MESSAGE_MAP() |
| 164 |
| 165 if (current_status_.forwarded) { |
| 166 // All other messages get processed by the GpuChannel. |
| 167 messages_forwarded_to_channel_++; |
| 168 if (preempting_flag_.get()) |
| 169 pending_messages_.push(PendingMessage(messages_forwarded_to_channel_)); |
| 170 UpdatePreemptionState(); |
110 } | 171 } |
111 | 172 |
112 if (message.type() == GpuCommandBufferMsg_InsertSyncPoint::ID) { | 173 return current_status_.handled; |
113 Tuple1<bool> retire; | |
114 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message); | |
115 if (!GpuCommandBufferMsg_InsertSyncPoint::ReadSendParam(&message, | |
116 &retire)) { | |
117 reply->set_reply_error(); | |
118 Send(reply); | |
119 return true; | |
120 } | |
121 if (!future_sync_points_ && !retire.a) { | |
122 LOG(ERROR) << "Untrusted contexts can't create future sync points"; | |
123 reply->set_reply_error(); | |
124 Send(reply); | |
125 return true; | |
126 } | |
127 uint32 sync_point = sync_point_manager_->GenerateSyncPoint(); | |
128 GpuCommandBufferMsg_InsertSyncPoint::WriteReplyParams(reply, sync_point); | |
129 Send(reply); | |
130 message_loop_->PostTask( | |
131 FROM_HERE, | |
132 base::Bind(&GpuChannelMessageFilter::InsertSyncPointOnMainThread, | |
133 gpu_channel_, | |
134 sync_point_manager_, | |
135 message.routing_id(), | |
136 retire.a, | |
137 sync_point)); | |
138 handled = true; | |
139 } | |
140 | |
141 // All other messages get processed by the GpuChannel. | |
142 messages_forwarded_to_channel_++; | |
143 if (preempting_flag_.get()) | |
144 pending_messages_.push(PendingMessage(messages_forwarded_to_channel_)); | |
145 UpdatePreemptionState(); | |
146 | |
147 return handled; | |
148 } | 174 } |
149 | 175 |
150 void MessageProcessed(uint64 messages_processed) { | 176 void MessageProcessed(uint64 messages_processed) { |
151 while (!pending_messages_.empty() && | 177 while (!pending_messages_.empty() && |
152 pending_messages_.front().message_number <= messages_processed) | 178 pending_messages_.front().message_number <= messages_processed) |
153 pending_messages_.pop(); | 179 pending_messages_.pop(); |
154 UpdatePreemptionState(); | 180 UpdatePreemptionState(); |
155 } | 181 } |
156 | 182 |
157 void SetPreemptingFlagAndSchedulingState( | 183 void SetPreemptingFlagAndSchedulingState( |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 gpu_channel->MessageProcessed(); | 401 gpu_channel->MessageProcessed(); |
376 } | 402 } |
377 } | 403 } |
378 manager->RetireSyncPoint(sync_point); | 404 manager->RetireSyncPoint(sync_point); |
379 } | 405 } |
380 | 406 |
381 // NOTE: this weak pointer is never dereferenced on the IO thread, it's only | 407 // NOTE: this weak pointer is never dereferenced on the IO thread, it's only |
382 // passed through - therefore the WeakPtr assumptions are respected. | 408 // passed through - therefore the WeakPtr assumptions are respected. |
383 base::WeakPtr<GpuChannel> gpu_channel_; | 409 base::WeakPtr<GpuChannel> gpu_channel_; |
384 IPC::Sender* sender_; | 410 IPC::Sender* sender_; |
| 411 MessageStatus current_status_; |
385 scoped_refptr<gpu::SyncPointManager> sync_point_manager_; | 412 scoped_refptr<gpu::SyncPointManager> sync_point_manager_; |
386 scoped_refptr<base::MessageLoopProxy> message_loop_; | 413 scoped_refptr<base::MessageLoopProxy> message_loop_; |
387 scoped_refptr<gpu::PreemptionFlag> preempting_flag_; | 414 scoped_refptr<gpu::PreemptionFlag> preempting_flag_; |
388 | 415 |
389 std::queue<PendingMessage> pending_messages_; | 416 std::queue<PendingMessage> pending_messages_; |
390 | 417 |
391 // Count of the number of IPCs forwarded to the GpuChannel. | 418 // Count of the number of IPCs forwarded to the GpuChannel. |
392 uint64 messages_forwarded_to_channel_; | 419 uint64 messages_forwarded_to_channel_; |
393 | 420 |
394 base::OneShotTimer<GpuChannelMessageFilter> timer_; | 421 base::OneShotTimer<GpuChannelMessageFilter> timer_; |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 } | 882 } |
856 } | 883 } |
857 } | 884 } |
858 | 885 |
859 void GpuChannel::HandleUpdateValueState( | 886 void GpuChannel::HandleUpdateValueState( |
860 unsigned int target, const gpu::ValueState& state) { | 887 unsigned int target, const gpu::ValueState& state) { |
861 pending_valuebuffer_state_->UpdateState(target, state); | 888 pending_valuebuffer_state_->UpdateState(target, state); |
862 } | 889 } |
863 | 890 |
864 } // namespace content | 891 } // namespace content |
OLD | NEW |