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: gpu/ipc/client/command_buffer_proxy_impl.cc

Issue 1864723003: Make lost context and error message callbacks on GpuControl go to client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: errorcallback: blimp Created 4 years, 8 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 "gpu/ipc/client/command_buffer_proxy_impl.h" 5 #include "gpu/ipc/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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/shared_memory.h" 12 #include "base/memory/shared_memory.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
16 #include "gpu/command_buffer/client/gpu_control_client.h"
16 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 17 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
17 #include "gpu/command_buffer/common/cmd_buffer_common.h" 18 #include "gpu/command_buffer/common/cmd_buffer_common.h"
18 #include "gpu/command_buffer/common/command_buffer_id.h" 19 #include "gpu/command_buffer/common/command_buffer_id.h"
19 #include "gpu/command_buffer/common/command_buffer_shared.h" 20 #include "gpu/command_buffer/common/command_buffer_shared.h"
20 #include "gpu/command_buffer/common/gpu_memory_allocation.h" 21 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
21 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" 22 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
22 #include "gpu/command_buffer/common/sync_token.h" 23 #include "gpu/command_buffer/common/sync_token.h"
23 #include "gpu/ipc/client/gpu_channel_host.h" 24 #include "gpu/ipc/client/gpu_channel_host.h"
24 #include "gpu/ipc/common/gpu_messages.h" 25 #include "gpu/ipc/common/gpu_messages.h"
25 #include "gpu/ipc/common/gpu_param_traits.h" 26 #include "gpu/ipc/common/gpu_param_traits.h"
26 #include "ui/gfx/geometry/size.h" 27 #include "ui/gfx/geometry/size.h"
27 #include "ui/gl/gl_bindings.h" 28 #include "ui/gl/gl_bindings.h"
28 29
29 namespace gpu { 30 namespace gpu {
30 31
31 namespace { 32 namespace {
32 33
33 gpu::CommandBufferId CommandBufferProxyID(int channel_id, int32_t route_id) { 34 gpu::CommandBufferId CommandBufferProxyID(int channel_id, int32_t route_id) {
34 return gpu::CommandBufferId::FromUnsafeValue( 35 return gpu::CommandBufferId::FromUnsafeValue(
35 (static_cast<uint64_t>(channel_id) << 32) | route_id); 36 (static_cast<uint64_t>(channel_id) << 32) | route_id);
36 } 37 }
37 38
38 } // namespace 39 } // namespace
39 40
40 CommandBufferProxyImpl::CommandBufferProxyImpl(GpuChannelHost* channel, 41 CommandBufferProxyImpl::CommandBufferProxyImpl(GpuChannelHost* channel,
41 int32_t route_id, 42 int32_t route_id,
42 int32_t stream_id) 43 int32_t stream_id)
43 : lock_(nullptr), 44 : lock_(nullptr),
45 gpu_control_client_(nullptr),
44 channel_(channel), 46 channel_(channel),
45 command_buffer_id_(CommandBufferProxyID(channel->channel_id(), route_id)), 47 command_buffer_id_(CommandBufferProxyID(channel->channel_id(), route_id)),
46 route_id_(route_id), 48 route_id_(route_id),
47 stream_id_(stream_id), 49 stream_id_(stream_id),
48 flush_count_(0), 50 flush_count_(0),
49 last_put_offset_(-1), 51 last_put_offset_(-1),
50 last_barrier_put_offset_(-1), 52 last_barrier_put_offset_(-1),
51 next_fence_sync_release_(1), 53 next_fence_sync_release_(1),
52 flushed_fence_sync_release_(0), 54 flushed_fence_sync_release_(0),
53 verified_fence_sync_release_(0), 55 verified_fence_sync_release_(0),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 110
109 void CommandBufferProxyImpl::OnDestroyed(gpu::error::ContextLostReason reason, 111 void CommandBufferProxyImpl::OnDestroyed(gpu::error::ContextLostReason reason,
110 gpu::error::Error error) { 112 gpu::error::Error error) {
111 CheckLock(); 113 CheckLock();
112 // Prevent any further messages from being sent. 114 // Prevent any further messages from being sent.
113 if (channel_) { 115 if (channel_) {
114 channel_->DestroyCommandBuffer(this); 116 channel_->DestroyCommandBuffer(this);
115 channel_ = nullptr; 117 channel_ = nullptr;
116 } 118 }
117 119
118 // When the client sees that the context is lost, they should delete this
119 // CommandBufferProxyImpl and create a new one.
120 last_state_.error = error; 120 last_state_.error = error;
121 last_state_.context_lost_reason = reason; 121 last_state_.context_lost_reason = reason;
122 122
123 if (!context_lost_callback_.is_null()) { 123 // When the client sees that the context is lost, they should delete this
124 context_lost_callback_.Run(); 124 // CommandBufferProxyImpl and create a new one.
125 // Avoid calling the error callback more than once. 125 DCHECK(gpu_control_client_);
no sievers 2016/04/07 21:07:58 OnDestroyed() might be triggered more than once I
danakj 2016/04/07 21:45:18 Ah.. I had done this but in content/ and the file
126 context_lost_callback_.Reset(); 126 gpu_control_client_->OnGpuControlLostContext();
127 }
128 } 127 }
129 128
130 void CommandBufferProxyImpl::OnConsoleMessage( 129 void CommandBufferProxyImpl::OnConsoleMessage(
131 const GPUCommandBufferConsoleMessage& message) { 130 const GPUCommandBufferConsoleMessage& message) {
132 if (!console_message_callback_.is_null()) { 131 DCHECK(gpu_control_client_);
133 console_message_callback_.Run(message.message, message.id); 132 gpu_control_client_->OnGpuControlErrorMessage(message.message.c_str(),
134 } 133 message.id);
135 } 134 }
136 135
137 void CommandBufferProxyImpl::AddDeletionObserver(DeletionObserver* observer) { 136 void CommandBufferProxyImpl::AddDeletionObserver(DeletionObserver* observer) {
138 scoped_ptr<base::AutoLock> lock; 137 scoped_ptr<base::AutoLock> lock;
139 if (lock_) 138 if (lock_)
140 lock.reset(new base::AutoLock(*lock_)); 139 lock.reset(new base::AutoLock(*lock_));
141 deletion_observers_.AddObserver(observer); 140 deletion_observers_.AddObserver(observer);
142 } 141 }
143 142
144 void CommandBufferProxyImpl::RemoveDeletionObserver( 143 void CommandBufferProxyImpl::RemoveDeletionObserver(
145 DeletionObserver* observer) { 144 DeletionObserver* observer) {
146 scoped_ptr<base::AutoLock> lock; 145 scoped_ptr<base::AutoLock> lock;
147 if (lock_) 146 if (lock_)
148 lock.reset(new base::AutoLock(*lock_)); 147 lock.reset(new base::AutoLock(*lock_));
149 deletion_observers_.RemoveObserver(observer); 148 deletion_observers_.RemoveObserver(observer);
150 } 149 }
151 150
152 void CommandBufferProxyImpl::OnSignalAck(uint32_t id) { 151 void CommandBufferProxyImpl::OnSignalAck(uint32_t id) {
153 SignalTaskMap::iterator it = signal_tasks_.find(id); 152 SignalTaskMap::iterator it = signal_tasks_.find(id);
154 if (it == signal_tasks_.end()) { 153 if (it == signal_tasks_.end()) {
155 DLOG(ERROR) << "Gpu process sent invalid SignalAck."; 154 DLOG(ERROR) << "Gpu process sent invalid SignalAck.";
156 InvalidGpuMessage(); 155 InvalidGpuMessage();
157 return; 156 return;
158 } 157 }
159 base::Closure callback = it->second; 158 base::Closure callback = it->second;
160 signal_tasks_.erase(it); 159 signal_tasks_.erase(it);
161 callback.Run(); 160 callback.Run();
162 } 161 }
163 162
164 void CommandBufferProxyImpl::SetContextLostCallback(
165 const base::Closure& callback) {
166 CheckLock();
167 context_lost_callback_ = callback;
168 }
169
170 bool CommandBufferProxyImpl::Initialize() { 163 bool CommandBufferProxyImpl::Initialize() {
171 TRACE_EVENT0("gpu", "CommandBufferProxyImpl::Initialize"); 164 TRACE_EVENT0("gpu", "CommandBufferProxyImpl::Initialize");
172 shared_state_shm_.reset(channel_->factory() 165 shared_state_shm_.reset(channel_->factory()
173 ->AllocateSharedMemory(sizeof(*shared_state())) 166 ->AllocateSharedMemory(sizeof(*shared_state()))
174 .release()); 167 .release());
175 if (!shared_state_shm_) 168 if (!shared_state_shm_)
176 return false; 169 return false;
177 170
178 if (!shared_state_shm_->Map(sizeof(*shared_state()))) 171 if (!shared_state_shm_->Map(sizeof(*shared_state())))
179 return false; 172 return false;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 380 }
388 381
389 void CommandBufferProxyImpl::DestroyTransferBuffer(int32_t id) { 382 void CommandBufferProxyImpl::DestroyTransferBuffer(int32_t id) {
390 CheckLock(); 383 CheckLock();
391 if (last_state_.error != gpu::error::kNoError) 384 if (last_state_.error != gpu::error::kNoError)
392 return; 385 return;
393 386
394 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); 387 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id));
395 } 388 }
396 389
390 void CommandBufferProxyImpl::SetGpuControlClient(GpuControlClient* client) {
391 CheckLock();
392 gpu_control_client_ = client;
393 }
394
397 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { 395 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() {
398 return capabilities_; 396 return capabilities_;
399 } 397 }
400 398
401 int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer, 399 int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer,
402 size_t width, 400 size_t width,
403 size_t height, 401 size_t height,
404 unsigned internal_format) { 402 unsigned internal_format) {
405 CheckLock(); 403 CheckLock();
406 if (last_state_.error != gpu::error::kNoError) 404 if (last_state_.error != gpu::error::kNoError)
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 } 653 }
656 654
657 void CommandBufferProxyImpl::OnUpdateState( 655 void CommandBufferProxyImpl::OnUpdateState(
658 const gpu::CommandBuffer::State& state) { 656 const gpu::CommandBuffer::State& state) {
659 // Handle wraparound. It works as long as we don't have more than 2B state 657 // Handle wraparound. It works as long as we don't have more than 2B state
660 // updates in flight across which reordering occurs. 658 // updates in flight across which reordering occurs.
661 if (state.generation - last_state_.generation < 0x80000000U) 659 if (state.generation - last_state_.generation < 0x80000000U)
662 last_state_ = state; 660 last_state_ = state;
663 } 661 }
664 662
665 void CommandBufferProxyImpl::SetOnConsoleMessageCallback(
666 const GpuConsoleMessageCallback& callback) {
667 CheckLock();
668 console_message_callback_ = callback;
669 }
670
671 void CommandBufferProxyImpl::TryUpdateState() { 663 void CommandBufferProxyImpl::TryUpdateState() {
672 if (last_state_.error == gpu::error::kNoError) 664 if (last_state_.error == gpu::error::kNoError)
673 shared_state()->Read(&last_state_); 665 shared_state()->Read(&last_state_);
674 } 666 }
675 667
676 void CommandBufferProxyImpl::UpdateVerifiedReleases(uint32_t verified_flush) { 668 void CommandBufferProxyImpl::UpdateVerifiedReleases(uint32_t verified_flush) {
677 while (!flushed_release_flush_id_.empty()) { 669 while (!flushed_release_flush_id_.empty()) {
678 const std::pair<uint64_t, uint32_t>& front_item = 670 const std::pair<uint64_t, uint32_t>& front_item =
679 flushed_release_flush_id_.front(); 671 flushed_release_flush_id_.front();
680 if (front_item.second > verified_flush) 672 if (front_item.second > verified_flush)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 } 718 }
727 719
728 void CommandBufferProxyImpl::InvalidGpuReplyOnClientThread() { 720 void CommandBufferProxyImpl::InvalidGpuReplyOnClientThread() {
729 scoped_ptr<base::AutoLock> lock; 721 scoped_ptr<base::AutoLock> lock;
730 if (lock_) 722 if (lock_)
731 lock.reset(new base::AutoLock(*lock_)); 723 lock.reset(new base::AutoLock(*lock_));
732 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext); 724 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext);
733 } 725 }
734 726
735 } // namespace gpu 727 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698