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

Side by Side Diff: content/common/gpu/client/command_buffer_proxy_impl.cc

Issue 1581273002: Harden CommandBufferProxyImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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 #include "content/common/gpu/client/command_buffer_proxy_impl.h" 5 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage); 76 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage);
77 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalAck, 77 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalAck,
78 OnSignalAck); 78 OnSignalAck);
79 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffersCompleted, 79 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffersCompleted,
80 OnSwapBuffersCompleted); 80 OnSwapBuffersCompleted);
81 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateVSyncParameters, 81 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateVSyncParameters,
82 OnUpdateVSyncParameters); 82 OnUpdateVSyncParameters);
83 IPC_MESSAGE_UNHANDLED(handled = false) 83 IPC_MESSAGE_UNHANDLED(handled = false)
84 IPC_END_MESSAGE_MAP() 84 IPC_END_MESSAGE_MAP()
85 85
86 DCHECK(handled); 86 if (!handled) {
87 DLOG(ERROR) << "Gpu process sent invalid message.";
88 InvalidGpuMessage();
89 }
87 return handled; 90 return handled;
88 } 91 }
89 92
90 void CommandBufferProxyImpl::OnChannelError() { 93 void CommandBufferProxyImpl::OnChannelError() {
91 scoped_ptr<base::AutoLock> lock; 94 scoped_ptr<base::AutoLock> lock;
92 if (lock_) 95 if (lock_)
93 lock.reset(new base::AutoLock(*lock_)); 96 lock.reset(new base::AutoLock(*lock_));
94 97
95 gpu::error::ContextLostReason context_lost_reason = 98 gpu::error::ContextLostReason context_lost_reason =
96 gpu::error::kGpuChannelLost; 99 gpu::error::kGpuChannelLost;
(...skipping 15 matching lines...) Expand all
112 channel_->DestroyCommandBuffer(this); 115 channel_->DestroyCommandBuffer(this);
113 channel_ = nullptr; 116 channel_ = nullptr;
114 } 117 }
115 118
116 // When the client sees that the context is lost, they should delete this 119 // When the client sees that the context is lost, they should delete this
117 // CommandBufferProxyImpl and create a new one. 120 // CommandBufferProxyImpl and create a new one.
118 last_state_.error = error; 121 last_state_.error = error;
119 last_state_.context_lost_reason = reason; 122 last_state_.context_lost_reason = reason;
120 123
121 if (!context_lost_callback_.is_null()) { 124 if (!context_lost_callback_.is_null()) {
122 context_lost_callback_.Run(); 125 context_lost_callback_.Run();
vmiura 2016/01/14 05:02:11 Is it OK that we will run the context lost callbac
piman 2016/01/14 18:27:58 Good catch, no it's not OK, actually whether or no
123 // Avoid calling the error callback more than once. 126 // Avoid calling the error callback more than once.
124 context_lost_callback_.Reset(); 127 context_lost_callback_.Reset();
125 } 128 }
126 } 129 }
127 130
128 void CommandBufferProxyImpl::OnConsoleMessage( 131 void CommandBufferProxyImpl::OnConsoleMessage(
129 const GPUCommandBufferConsoleMessage& message) { 132 const GPUCommandBufferConsoleMessage& message) {
130 if (!console_message_callback_.is_null()) { 133 if (!console_message_callback_.is_null()) {
131 console_message_callback_.Run(message.message, message.id); 134 console_message_callback_.Run(message.message, message.id);
132 } 135 }
133 } 136 }
134 137
135 void CommandBufferProxyImpl::AddDeletionObserver(DeletionObserver* observer) { 138 void CommandBufferProxyImpl::AddDeletionObserver(DeletionObserver* observer) {
136 scoped_ptr<base::AutoLock> lock; 139 scoped_ptr<base::AutoLock> lock;
137 if (lock_) 140 if (lock_)
138 lock.reset(new base::AutoLock(*lock_)); 141 lock.reset(new base::AutoLock(*lock_));
139 deletion_observers_.AddObserver(observer); 142 deletion_observers_.AddObserver(observer);
140 } 143 }
141 144
142 void CommandBufferProxyImpl::RemoveDeletionObserver( 145 void CommandBufferProxyImpl::RemoveDeletionObserver(
143 DeletionObserver* observer) { 146 DeletionObserver* observer) {
144 scoped_ptr<base::AutoLock> lock; 147 scoped_ptr<base::AutoLock> lock;
145 if (lock_) 148 if (lock_)
146 lock.reset(new base::AutoLock(*lock_)); 149 lock.reset(new base::AutoLock(*lock_));
147 deletion_observers_.RemoveObserver(observer); 150 deletion_observers_.RemoveObserver(observer);
148 } 151 }
149 152
150 void CommandBufferProxyImpl::OnSignalAck(uint32_t id) { 153 void CommandBufferProxyImpl::OnSignalAck(uint32_t id) {
151 SignalTaskMap::iterator it = signal_tasks_.find(id); 154 SignalTaskMap::iterator it = signal_tasks_.find(id);
152 DCHECK(it != signal_tasks_.end()); 155 if (it == signal_tasks_.end()) {
156 DLOG(ERROR) << "Gpu process sent invalid SignalAck.";
157 InvalidGpuMessage();
158 return;
159 }
153 base::Closure callback = it->second; 160 base::Closure callback = it->second;
154 signal_tasks_.erase(it); 161 signal_tasks_.erase(it);
155 callback.Run(); 162 callback.Run();
156 } 163 }
157 164
158 void CommandBufferProxyImpl::SetContextLostCallback( 165 void CommandBufferProxyImpl::SetContextLostCallback(
159 const base::Closure& callback) { 166 const base::Closure& callback) {
160 CheckLock(); 167 CheckLock();
161 context_lost_callback_ = callback; 168 context_lost_callback_ = callback;
162 } 169 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 "end", 304 "end",
298 end); 305 end);
299 TryUpdateState(); 306 TryUpdateState();
300 if (!InRange(start, end, last_state_.token) && 307 if (!InRange(start, end, last_state_.token) &&
301 last_state_.error == gpu::error::kNoError) { 308 last_state_.error == gpu::error::kNoError) {
302 gpu::CommandBuffer::State state; 309 gpu::CommandBuffer::State state;
303 if (Send(new GpuCommandBufferMsg_WaitForTokenInRange( 310 if (Send(new GpuCommandBufferMsg_WaitForTokenInRange(
304 route_id_, start, end, &state))) 311 route_id_, start, end, &state)))
305 OnUpdateState(state); 312 OnUpdateState(state);
306 } 313 }
307 DCHECK(InRange(start, end, last_state_.token) || 314 if (!InRange(start, end, last_state_.token) &&
308 last_state_.error != gpu::error::kNoError); 315 last_state_.error == gpu::error::kNoError) {
316 DLOG(ERROR) << "GPU state invalid after WaitForTokenInRange.";
317 InvalidGpuMessage();
318 }
309 } 319 }
310 320
311 void CommandBufferProxyImpl::WaitForGetOffsetInRange(int32_t start, 321 void CommandBufferProxyImpl::WaitForGetOffsetInRange(int32_t start,
312 int32_t end) { 322 int32_t end) {
313 CheckLock(); 323 CheckLock();
314 TRACE_EVENT2("gpu", 324 TRACE_EVENT2("gpu",
315 "CommandBufferProxyImpl::WaitForGetOffset", 325 "CommandBufferProxyImpl::WaitForGetOffset",
316 "start", 326 "start",
317 start, 327 start,
318 "end", 328 "end",
319 end); 329 end);
320 TryUpdateState(); 330 TryUpdateState();
321 if (!InRange(start, end, last_state_.get_offset) && 331 if (!InRange(start, end, last_state_.get_offset) &&
322 last_state_.error == gpu::error::kNoError) { 332 last_state_.error == gpu::error::kNoError) {
323 gpu::CommandBuffer::State state; 333 gpu::CommandBuffer::State state;
324 if (Send(new GpuCommandBufferMsg_WaitForGetOffsetInRange( 334 if (Send(new GpuCommandBufferMsg_WaitForGetOffsetInRange(
325 route_id_, start, end, &state))) 335 route_id_, start, end, &state)))
326 OnUpdateState(state); 336 OnUpdateState(state);
327 } 337 }
328 DCHECK(InRange(start, end, last_state_.get_offset) || 338 if (!InRange(start, end, last_state_.get_offset) &&
329 last_state_.error != gpu::error::kNoError); 339 last_state_.error == gpu::error::kNoError) {
340 DLOG(ERROR) << "GPU state invalid after WaitForGetOffsetInRange.";
341 InvalidGpuMessage();
342 }
330 } 343 }
331 344
332 void CommandBufferProxyImpl::SetGetBuffer(int32_t shm_id) { 345 void CommandBufferProxyImpl::SetGetBuffer(int32_t shm_id) {
333 CheckLock(); 346 CheckLock();
334 if (last_state_.error != gpu::error::kNoError) 347 if (last_state_.error != gpu::error::kNoError)
335 return; 348 return;
336 349
337 Send(new GpuCommandBufferMsg_SetGetBuffer(route_id_, shm_id)); 350 Send(new GpuCommandBufferMsg_SetGetBuffer(route_id_, shm_id));
338 last_put_offset_ = -1; 351 last_put_offset_ = -1;
339 } 352 }
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 swap_buffers_completion_callback_.Run(latency_info, result); 784 swap_buffers_completion_callback_.Run(latency_info, result);
772 } 785 }
773 } 786 }
774 787
775 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, 788 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase,
776 base::TimeDelta interval) { 789 base::TimeDelta interval) {
777 if (!update_vsync_parameters_completion_callback_.is_null()) 790 if (!update_vsync_parameters_completion_callback_.is_null())
778 update_vsync_parameters_completion_callback_.Run(timebase, interval); 791 update_vsync_parameters_completion_callback_.Run(timebase, interval);
779 } 792 }
780 793
794 void CommandBufferProxyImpl::InvalidGpuMessage() {
795 LOG(ERROR) << "Received invalid message or reply from the GPU process.";
796 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext);
797 }
798
781 } // namespace content 799 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/client/command_buffer_proxy_impl.h ('k') | gpu/command_buffer/common/constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698