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

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: Post a task for lost context callback when in a reply 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 channel_(channel), 44 channel_(channel),
45 command_buffer_id_(CommandBufferProxyID(channel->channel_id(), route_id)), 45 command_buffer_id_(CommandBufferProxyID(channel->channel_id(), route_id)),
46 route_id_(route_id), 46 route_id_(route_id),
47 stream_id_(stream_id), 47 stream_id_(stream_id),
48 flush_count_(0), 48 flush_count_(0),
49 last_put_offset_(-1), 49 last_put_offset_(-1),
50 last_barrier_put_offset_(-1), 50 last_barrier_put_offset_(-1),
51 next_fence_sync_release_(1), 51 next_fence_sync_release_(1),
52 flushed_fence_sync_release_(0), 52 flushed_fence_sync_release_(0),
53 verified_fence_sync_release_(0), 53 verified_fence_sync_release_(0),
54 next_signal_id_(0) { 54 next_signal_id_(0),
55 weak_this_(AsWeakPtr()),
56 callback_thread_(base::ThreadTaskRunnerHandle::Get()) {
55 DCHECK(channel); 57 DCHECK(channel);
56 DCHECK(stream_id); 58 DCHECK(stream_id);
57 } 59 }
58 60
59 CommandBufferProxyImpl::~CommandBufferProxyImpl() { 61 CommandBufferProxyImpl::~CommandBufferProxyImpl() {
60 FOR_EACH_OBSERVER(DeletionObserver, 62 FOR_EACH_OBSERVER(DeletionObserver,
61 deletion_observers_, 63 deletion_observers_,
62 OnWillDeleteImpl()); 64 OnWillDeleteImpl());
63 if (channel_) { 65 if (channel_) {
64 channel_->DestroyCommandBuffer(this); 66 channel_->DestroyCommandBuffer(this);
(...skipping 11 matching lines...) Expand all
76 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage); 78 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage);
77 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalAck, 79 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalAck,
78 OnSignalAck); 80 OnSignalAck);
79 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffersCompleted, 81 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffersCompleted,
80 OnSwapBuffersCompleted); 82 OnSwapBuffersCompleted);
81 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateVSyncParameters, 83 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateVSyncParameters,
82 OnUpdateVSyncParameters); 84 OnUpdateVSyncParameters);
83 IPC_MESSAGE_UNHANDLED(handled = false) 85 IPC_MESSAGE_UNHANDLED(handled = false)
84 IPC_END_MESSAGE_MAP() 86 IPC_END_MESSAGE_MAP()
85 87
86 DCHECK(handled); 88 if (!handled) {
89 DLOG(ERROR) << "Gpu process sent invalid message.";
90 InvalidGpuMessage();
91 }
87 return handled; 92 return handled;
88 } 93 }
89 94
90 void CommandBufferProxyImpl::OnChannelError() { 95 void CommandBufferProxyImpl::OnChannelError() {
91 scoped_ptr<base::AutoLock> lock; 96 scoped_ptr<base::AutoLock> lock;
92 if (lock_) 97 if (lock_)
93 lock.reset(new base::AutoLock(*lock_)); 98 lock.reset(new base::AutoLock(*lock_));
94 99
95 gpu::error::ContextLostReason context_lost_reason = 100 gpu::error::ContextLostReason context_lost_reason =
96 gpu::error::kGpuChannelLost; 101 gpu::error::kGpuChannelLost;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 void CommandBufferProxyImpl::RemoveDeletionObserver( 147 void CommandBufferProxyImpl::RemoveDeletionObserver(
143 DeletionObserver* observer) { 148 DeletionObserver* observer) {
144 scoped_ptr<base::AutoLock> lock; 149 scoped_ptr<base::AutoLock> lock;
145 if (lock_) 150 if (lock_)
146 lock.reset(new base::AutoLock(*lock_)); 151 lock.reset(new base::AutoLock(*lock_));
147 deletion_observers_.RemoveObserver(observer); 152 deletion_observers_.RemoveObserver(observer);
148 } 153 }
149 154
150 void CommandBufferProxyImpl::OnSignalAck(uint32_t id) { 155 void CommandBufferProxyImpl::OnSignalAck(uint32_t id) {
151 SignalTaskMap::iterator it = signal_tasks_.find(id); 156 SignalTaskMap::iterator it = signal_tasks_.find(id);
152 DCHECK(it != signal_tasks_.end()); 157 if (it == signal_tasks_.end()) {
158 DLOG(ERROR) << "Gpu process sent invalid SignalAck.";
159 InvalidGpuMessage();
160 return;
161 }
153 base::Closure callback = it->second; 162 base::Closure callback = it->second;
154 signal_tasks_.erase(it); 163 signal_tasks_.erase(it);
155 callback.Run(); 164 callback.Run();
156 } 165 }
157 166
158 void CommandBufferProxyImpl::SetContextLostCallback( 167 void CommandBufferProxyImpl::SetContextLostCallback(
159 const base::Closure& callback) { 168 const base::Closure& callback) {
160 CheckLock(); 169 CheckLock();
161 context_lost_callback_ = callback; 170 context_lost_callback_ = callback;
162 } 171 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 "end", 306 "end",
298 end); 307 end);
299 TryUpdateState(); 308 TryUpdateState();
300 if (!InRange(start, end, last_state_.token) && 309 if (!InRange(start, end, last_state_.token) &&
301 last_state_.error == gpu::error::kNoError) { 310 last_state_.error == gpu::error::kNoError) {
302 gpu::CommandBuffer::State state; 311 gpu::CommandBuffer::State state;
303 if (Send(new GpuCommandBufferMsg_WaitForTokenInRange( 312 if (Send(new GpuCommandBufferMsg_WaitForTokenInRange(
304 route_id_, start, end, &state))) 313 route_id_, start, end, &state)))
305 OnUpdateState(state); 314 OnUpdateState(state);
306 } 315 }
307 DCHECK(InRange(start, end, last_state_.token) || 316 if (!InRange(start, end, last_state_.token) &&
308 last_state_.error != gpu::error::kNoError); 317 last_state_.error == gpu::error::kNoError) {
318 DLOG(ERROR) << "GPU state invalid after WaitForTokenInRange.";
319 InvalidGpuReply();
320 }
309 } 321 }
310 322
311 void CommandBufferProxyImpl::WaitForGetOffsetInRange(int32_t start, 323 void CommandBufferProxyImpl::WaitForGetOffsetInRange(int32_t start,
312 int32_t end) { 324 int32_t end) {
313 CheckLock(); 325 CheckLock();
314 TRACE_EVENT2("gpu", 326 TRACE_EVENT2("gpu",
315 "CommandBufferProxyImpl::WaitForGetOffset", 327 "CommandBufferProxyImpl::WaitForGetOffset",
316 "start", 328 "start",
317 start, 329 start,
318 "end", 330 "end",
319 end); 331 end);
320 TryUpdateState(); 332 TryUpdateState();
321 if (!InRange(start, end, last_state_.get_offset) && 333 if (!InRange(start, end, last_state_.get_offset) &&
322 last_state_.error == gpu::error::kNoError) { 334 last_state_.error == gpu::error::kNoError) {
323 gpu::CommandBuffer::State state; 335 gpu::CommandBuffer::State state;
324 if (Send(new GpuCommandBufferMsg_WaitForGetOffsetInRange( 336 if (Send(new GpuCommandBufferMsg_WaitForGetOffsetInRange(
325 route_id_, start, end, &state))) 337 route_id_, start, end, &state)))
326 OnUpdateState(state); 338 OnUpdateState(state);
327 } 339 }
328 DCHECK(InRange(start, end, last_state_.get_offset) || 340 if (!InRange(start, end, last_state_.get_offset) &&
329 last_state_.error != gpu::error::kNoError); 341 last_state_.error == gpu::error::kNoError) {
342 DLOG(ERROR) << "GPU state invalid after WaitForGetOffsetInRange.";
343 InvalidGpuReply();
344 }
330 } 345 }
331 346
332 void CommandBufferProxyImpl::SetGetBuffer(int32_t shm_id) { 347 void CommandBufferProxyImpl::SetGetBuffer(int32_t shm_id) {
333 CheckLock(); 348 CheckLock();
334 if (last_state_.error != gpu::error::kNoError) 349 if (last_state_.error != gpu::error::kNoError)
335 return; 350 return;
336 351
337 Send(new GpuCommandBufferMsg_SetGetBuffer(route_id_, shm_id)); 352 Send(new GpuCommandBufferMsg_SetGetBuffer(route_id_, shm_id));
338 last_put_offset_ = -1; 353 last_put_offset_ = -1;
339 } 354 }
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 swap_buffers_completion_callback_.Run(latency_info, result); 786 swap_buffers_completion_callback_.Run(latency_info, result);
772 } 787 }
773 } 788 }
774 789
775 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, 790 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase,
776 base::TimeDelta interval) { 791 base::TimeDelta interval) {
777 if (!update_vsync_parameters_completion_callback_.is_null()) 792 if (!update_vsync_parameters_completion_callback_.is_null())
778 update_vsync_parameters_completion_callback_.Run(timebase, interval); 793 update_vsync_parameters_completion_callback_.Run(timebase, interval);
779 } 794 }
780 795
796 void CommandBufferProxyImpl::InvalidGpuMessage() {
797 LOG(ERROR) << "Received invalid message from the GPU process.";
798 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext);
799 }
800
801 void CommandBufferProxyImpl::InvalidGpuReply() {
802 CheckLock();
803 LOG(ERROR) << "Received invalid reply from the GPU process.";
804 last_state_.error = gpu::error::kLostContext;
805 last_state_.context_lost_reason = gpu::error::kInvalidGpuMessage;
806 callback_thread_->PostTask(
807 FROM_HERE,
808 base::Bind(&CommandBufferProxyImpl::InvalidGpuReplyOnClientThread,
809 weak_this_));
810 }
811
812 void CommandBufferProxyImpl::InvalidGpuReplyOnClientThread() {
813 scoped_ptr<base::AutoLock> lock;
814 if (lock_)
815 lock.reset(new base::AutoLock(*lock_));
816 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext);
817 }
818
781 } // namespace content 819 } // 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