| 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/client/command_buffer_proxy_impl.h" | 5 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 using gpu::Buffer; | 27 using gpu::Buffer; |
| 28 | 28 |
| 29 CommandBufferProxyImpl::CommandBufferProxyImpl( | 29 CommandBufferProxyImpl::CommandBufferProxyImpl( |
| 30 GpuChannelHost* channel, | 30 GpuChannelHost* channel, |
| 31 int route_id) | 31 int route_id) |
| 32 : shared_state_(NULL), | 32 : shared_state_(NULL), |
| 33 channel_(channel), | 33 channel_(channel), |
| 34 route_id_(route_id), | 34 route_id_(route_id), |
| 35 flush_count_(0), | 35 flush_count_(0), |
| 36 last_put_offset_(-1), | 36 last_put_offset_(-1), |
| 37 next_signal_id_(0) { | 37 next_signal_id_(0), |
| 38 state_buffer_(-1) { |
| 38 } | 39 } |
| 39 | 40 |
| 40 CommandBufferProxyImpl::~CommandBufferProxyImpl() { | 41 CommandBufferProxyImpl::~CommandBufferProxyImpl() { |
| 42 if (state_buffer_ != -1) |
| 43 DestroyTransferBuffer(state_buffer_); |
| 41 // Delete all the locally cached shared memory objects, closing the handle | 44 // Delete all the locally cached shared memory objects, closing the handle |
| 42 // in this process. | 45 // in this process. |
| 43 for (TransferBufferMap::iterator it = transfer_buffers_.begin(); | 46 for (TransferBufferMap::iterator it = transfer_buffers_.begin(); |
| 44 it != transfer_buffers_.end(); | 47 it != transfer_buffers_.end(); |
| 45 ++it) { | 48 ++it) { |
| 46 delete it->second.shared_memory; | 49 delete it->second.shared_memory; |
| 47 it->second.shared_memory = NULL; | 50 it->second.shared_memory = NULL; |
| 48 } | 51 } |
| 49 for (Decoders::iterator it = video_decoder_hosts_.begin(); | 52 for (Decoders::iterator it = video_decoder_hosts_.begin(); |
| 50 it != video_decoder_hosts_.end(); ++it) { | 53 it != video_decoder_hosts_.end(); ++it) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if (!Send(new GpuCommandBufferMsg_Initialize(route_id_, &result))) { | 144 if (!Send(new GpuCommandBufferMsg_Initialize(route_id_, &result))) { |
| 142 LOG(ERROR) << "Could not send GpuCommandBufferMsg_Initialize."; | 145 LOG(ERROR) << "Could not send GpuCommandBufferMsg_Initialize."; |
| 143 return false; | 146 return false; |
| 144 } | 147 } |
| 145 | 148 |
| 146 if (!result) { | 149 if (!result) { |
| 147 LOG(ERROR) << "Failed to initialize command buffer service."; | 150 LOG(ERROR) << "Failed to initialize command buffer service."; |
| 148 return false; | 151 return false; |
| 149 } | 152 } |
| 150 | 153 |
| 151 int32 state_buffer = CreateTransferBuffer(sizeof *shared_state_, -1); | 154 state_buffer_ = CreateTransferBuffer(sizeof *shared_state_, -1); |
| 152 | 155 |
| 153 if (state_buffer == -1) { | 156 if (state_buffer_ == -1) { |
| 154 LOG(ERROR) << "Failed to create shared state transfer buffer."; | 157 LOG(ERROR) << "Failed to create shared state transfer buffer."; |
| 155 return false; | 158 return false; |
| 156 } | 159 } |
| 157 | 160 |
| 158 gpu::Buffer buffer = GetTransferBuffer(state_buffer); | 161 gpu::Buffer buffer = GetTransferBuffer(state_buffer_); |
| 159 if (!buffer.ptr) { | 162 if (!buffer.ptr) { |
| 160 LOG(ERROR) << "Failed to get shared state transfer buffer"; | 163 LOG(ERROR) << "Failed to get shared state transfer buffer"; |
| 161 return false; | 164 return false; |
| 162 } | 165 } |
| 163 | 166 |
| 164 shared_state_ = reinterpret_cast<gpu::CommandBufferSharedState*>(buffer.ptr); | 167 shared_state_ = reinterpret_cast<gpu::CommandBufferSharedState*>(buffer.ptr); |
| 165 shared_state_->Initialize(); | 168 shared_state_->Initialize(); |
| 166 | 169 |
| 167 if (!Send(new GpuCommandBufferMsg_SetSharedStateBuffer(route_id_, | 170 if (!Send(new GpuCommandBufferMsg_SetSharedStateBuffer(route_id_, |
| 168 state_buffer))) { | 171 state_buffer_))) { |
| 169 LOG(ERROR) << "Failed to initialize shared command buffer state."; | 172 LOG(ERROR) << "Failed to initialize shared command buffer state."; |
| 170 return false; | 173 return false; |
| 171 } | 174 } |
| 172 | 175 |
| 173 return true; | 176 return true; |
| 174 } | 177 } |
| 175 | 178 |
| 176 gpu::CommandBuffer::State CommandBufferProxyImpl::GetState() { | 179 gpu::CommandBuffer::State CommandBufferProxyImpl::GetState() { |
| 177 // Send will flag state with lost context if IPC fails. | 180 // Send will flag state with lost context if IPC fails. |
| 178 if (last_state_.error == gpu::error::kNoError) { | 181 if (last_state_.error == gpu::error::kNoError) { |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 554 |
| 552 void CommandBufferProxyImpl::SetOnConsoleMessageCallback( | 555 void CommandBufferProxyImpl::SetOnConsoleMessageCallback( |
| 553 const GpuConsoleMessageCallback& callback) { | 556 const GpuConsoleMessageCallback& callback) { |
| 554 console_message_callback_ = callback; | 557 console_message_callback_ = callback; |
| 555 } | 558 } |
| 556 | 559 |
| 557 void CommandBufferProxyImpl::TryUpdateState() { | 560 void CommandBufferProxyImpl::TryUpdateState() { |
| 558 if (last_state_.error == gpu::error::kNoError) | 561 if (last_state_.error == gpu::error::kNoError) |
| 559 shared_state_->Read(&last_state_); | 562 shared_state_->Read(&last_state_); |
| 560 } | 563 } |
| OLD | NEW |