| 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 "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" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 CommandBufferProxyImpl::~CommandBufferProxyImpl() { | 61 CommandBufferProxyImpl::~CommandBufferProxyImpl() { |
| 62 FOR_EACH_OBSERVER(DeletionObserver, deletion_observers_, OnWillDeleteImpl()); | 62 FOR_EACH_OBSERVER(DeletionObserver, deletion_observers_, OnWillDeleteImpl()); |
| 63 if (channel_) { | 63 if (channel_) { |
| 64 channel_->DestroyCommandBuffer(this); | 64 channel_->DestroyCommandBuffer(this); |
| 65 channel_ = nullptr; | 65 channel_ = nullptr; |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool CommandBufferProxyImpl::OnMessageReceived(const IPC::Message& message) { | 69 bool CommandBufferProxyImpl::OnMessageReceived(const IPC::Message& message) { |
| 70 scoped_ptr<base::AutoLock> lock; | 70 std::unique_ptr<base::AutoLock> lock; |
| 71 if (lock_) | 71 if (lock_) |
| 72 lock.reset(new base::AutoLock(*lock_)); | 72 lock.reset(new base::AutoLock(*lock_)); |
| 73 bool handled = true; | 73 bool handled = true; |
| 74 IPC_BEGIN_MESSAGE_MAP(CommandBufferProxyImpl, message) | 74 IPC_BEGIN_MESSAGE_MAP(CommandBufferProxyImpl, message) |
| 75 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Destroyed, OnDestroyed); | 75 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Destroyed, OnDestroyed); |
| 76 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage); | 76 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage); |
| 77 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalAck, OnSignalAck); | 77 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalAck, OnSignalAck); |
| 78 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffersCompleted, | 78 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffersCompleted, |
| 79 OnSwapBuffersCompleted); | 79 OnSwapBuffersCompleted); |
| 80 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateVSyncParameters, | 80 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateVSyncParameters, |
| 81 OnUpdateVSyncParameters); | 81 OnUpdateVSyncParameters); |
| 82 IPC_MESSAGE_UNHANDLED(handled = false) | 82 IPC_MESSAGE_UNHANDLED(handled = false) |
| 83 IPC_END_MESSAGE_MAP() | 83 IPC_END_MESSAGE_MAP() |
| 84 | 84 |
| 85 if (!handled) { | 85 if (!handled) { |
| 86 DLOG(ERROR) << "Gpu process sent invalid message."; | 86 DLOG(ERROR) << "Gpu process sent invalid message."; |
| 87 InvalidGpuMessage(); | 87 InvalidGpuMessage(); |
| 88 } | 88 } |
| 89 return handled; | 89 return handled; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void CommandBufferProxyImpl::OnChannelError() { | 92 void CommandBufferProxyImpl::OnChannelError() { |
| 93 scoped_ptr<base::AutoLock> lock; | 93 std::unique_ptr<base::AutoLock> lock; |
| 94 if (lock_) | 94 if (lock_) |
| 95 lock.reset(new base::AutoLock(*lock_)); | 95 lock.reset(new base::AutoLock(*lock_)); |
| 96 | 96 |
| 97 gpu::error::ContextLostReason context_lost_reason = | 97 gpu::error::ContextLostReason context_lost_reason = |
| 98 gpu::error::kGpuChannelLost; | 98 gpu::error::kGpuChannelLost; |
| 99 if (shared_state_shm_ && shared_state_shm_->memory()) { | 99 if (shared_state_shm_ && shared_state_shm_->memory()) { |
| 100 TryUpdateState(); | 100 TryUpdateState(); |
| 101 // The GPU process might have intentionally been crashed | 101 // The GPU process might have intentionally been crashed |
| 102 // (exit_on_context_lost), so try to find out the original reason. | 102 // (exit_on_context_lost), so try to find out the original reason. |
| 103 if (last_state_.error == gpu::error::kLostContext) | 103 if (last_state_.error == gpu::error::kLostContext) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 128 } | 128 } |
| 129 | 129 |
| 130 void CommandBufferProxyImpl::OnConsoleMessage( | 130 void CommandBufferProxyImpl::OnConsoleMessage( |
| 131 const GPUCommandBufferConsoleMessage& message) { | 131 const GPUCommandBufferConsoleMessage& message) { |
| 132 if (!console_message_callback_.is_null()) { | 132 if (!console_message_callback_.is_null()) { |
| 133 console_message_callback_.Run(message.message, message.id); | 133 console_message_callback_.Run(message.message, message.id); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 void CommandBufferProxyImpl::AddDeletionObserver(DeletionObserver* observer) { | 137 void CommandBufferProxyImpl::AddDeletionObserver(DeletionObserver* observer) { |
| 138 scoped_ptr<base::AutoLock> lock; | 138 std::unique_ptr<base::AutoLock> lock; |
| 139 if (lock_) | 139 if (lock_) |
| 140 lock.reset(new base::AutoLock(*lock_)); | 140 lock.reset(new base::AutoLock(*lock_)); |
| 141 deletion_observers_.AddObserver(observer); | 141 deletion_observers_.AddObserver(observer); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void CommandBufferProxyImpl::RemoveDeletionObserver( | 144 void CommandBufferProxyImpl::RemoveDeletionObserver( |
| 145 DeletionObserver* observer) { | 145 DeletionObserver* observer) { |
| 146 scoped_ptr<base::AutoLock> lock; | 146 std::unique_ptr<base::AutoLock> lock; |
| 147 if (lock_) | 147 if (lock_) |
| 148 lock.reset(new base::AutoLock(*lock_)); | 148 lock.reset(new base::AutoLock(*lock_)); |
| 149 deletion_observers_.RemoveObserver(observer); | 149 deletion_observers_.RemoveObserver(observer); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void CommandBufferProxyImpl::OnSignalAck(uint32_t id) { | 152 void CommandBufferProxyImpl::OnSignalAck(uint32_t id) { |
| 153 SignalTaskMap::iterator it = signal_tasks_.find(id); | 153 SignalTaskMap::iterator it = signal_tasks_.find(id); |
| 154 if (it == signal_tasks_.end()) { | 154 if (it == signal_tasks_.end()) { |
| 155 DLOG(ERROR) << "Gpu process sent invalid SignalAck."; | 155 DLOG(ERROR) << "Gpu process sent invalid SignalAck."; |
| 156 InvalidGpuMessage(); | 156 InvalidGpuMessage(); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 size_t size, | 345 size_t size, |
| 346 int32_t* id) { | 346 int32_t* id) { |
| 347 CheckLock(); | 347 CheckLock(); |
| 348 *id = -1; | 348 *id = -1; |
| 349 | 349 |
| 350 if (last_state_.error != gpu::error::kNoError) | 350 if (last_state_.error != gpu::error::kNoError) |
| 351 return NULL; | 351 return NULL; |
| 352 | 352 |
| 353 int32_t new_id = channel_->ReserveTransferBufferId(); | 353 int32_t new_id = channel_->ReserveTransferBufferId(); |
| 354 | 354 |
| 355 scoped_ptr<base::SharedMemory> shared_memory( | 355 std::unique_ptr<base::SharedMemory> shared_memory( |
| 356 channel_->factory()->AllocateSharedMemory(size)); | 356 channel_->factory()->AllocateSharedMemory(size)); |
| 357 if (!shared_memory) { | 357 if (!shared_memory) { |
| 358 if (last_state_.error == gpu::error::kNoError) | 358 if (last_state_.error == gpu::error::kNoError) |
| 359 last_state_.error = gpu::error::kOutOfBounds; | 359 last_state_.error = gpu::error::kOutOfBounds; |
| 360 return NULL; | 360 return NULL; |
| 361 } | 361 } |
| 362 | 362 |
| 363 DCHECK(!shared_memory->memory()); | 363 DCHECK(!shared_memory->memory()); |
| 364 if (!shared_memory->Map(size)) { | 364 if (!shared_memory->Map(size)) { |
| 365 if (last_state_.error == gpu::error::kNoError) | 365 if (last_state_.error == gpu::error::kNoError) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 469 |
| 470 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); | 470 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); |
| 471 } | 471 } |
| 472 | 472 |
| 473 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( | 473 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( |
| 474 size_t width, | 474 size_t width, |
| 475 size_t height, | 475 size_t height, |
| 476 unsigned internal_format, | 476 unsigned internal_format, |
| 477 unsigned usage) { | 477 unsigned usage) { |
| 478 CheckLock(); | 478 CheckLock(); |
| 479 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | 479 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( |
| 480 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | 480 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( |
| 481 gfx::Size(width, height), | 481 gfx::Size(width, height), |
| 482 gpu::ImageFactory::DefaultBufferFormatForImageFormat(internal_format), | 482 gpu::ImageFactory::DefaultBufferFormatForImageFormat(internal_format), |
| 483 gfx::BufferUsage::SCANOUT)); | 483 gfx::BufferUsage::SCANOUT)); |
| 484 if (!buffer) | 484 if (!buffer) |
| 485 return -1; | 485 return -1; |
| 486 | 486 |
| 487 return CreateImage(buffer->AsClientBuffer(), width, height, internal_format); | 487 return CreateImage(buffer->AsClientBuffer(), width, height, internal_format); |
| 488 } | 488 } |
| 489 | 489 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 LOG(ERROR) << "Received invalid reply from the GPU process."; | 719 LOG(ERROR) << "Received invalid reply from the GPU process."; |
| 720 last_state_.error = gpu::error::kLostContext; | 720 last_state_.error = gpu::error::kLostContext; |
| 721 last_state_.context_lost_reason = gpu::error::kInvalidGpuMessage; | 721 last_state_.context_lost_reason = gpu::error::kInvalidGpuMessage; |
| 722 callback_thread_->PostTask( | 722 callback_thread_->PostTask( |
| 723 FROM_HERE, | 723 FROM_HERE, |
| 724 base::Bind(&CommandBufferProxyImpl::InvalidGpuReplyOnClientThread, | 724 base::Bind(&CommandBufferProxyImpl::InvalidGpuReplyOnClientThread, |
| 725 weak_this_)); | 725 weak_this_)); |
| 726 } | 726 } |
| 727 | 727 |
| 728 void CommandBufferProxyImpl::InvalidGpuReplyOnClientThread() { | 728 void CommandBufferProxyImpl::InvalidGpuReplyOnClientThread() { |
| 729 scoped_ptr<base::AutoLock> lock; | 729 std::unique_ptr<base::AutoLock> lock; |
| 730 if (lock_) | 730 if (lock_) |
| 731 lock.reset(new base::AutoLock(*lock_)); | 731 lock.reset(new base::AutoLock(*lock_)); |
| 732 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext); | 732 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext); |
| 733 } | 733 } |
| 734 | 734 |
| 735 } // namespace gpu | 735 } // namespace gpu |
| OLD | NEW |