| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/services/gles2/command_buffer_impl.h" | 5 #include "mojo/services/gles2/command_buffer_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 | 9 |
| 10 #include "gpu/command_buffer/common/constants.h" | 10 #include "gpu/command_buffer/common/constants.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) { | 137 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) { |
| 138 // TODO(piman): handle out-of-order. | 138 // TODO(piman): handle out-of-order. |
| 139 AllocationScope scope; | 139 AllocationScope scope; |
| 140 sync_client_->DidMakeProgress(command_buffer_->GetState()); | 140 sync_client_->DidMakeProgress(command_buffer_->GetState()); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void CommandBufferImpl::RegisterTransferBuffer(int32_t id, | 143 void CommandBufferImpl::RegisterTransferBuffer(int32_t id, |
| 144 const ShmHandle& transfer_buffer, | 144 const ShmHandle& transfer_buffer, |
| 145 uint32_t size) { | 145 uint32_t size) { |
| 146 bool read_only = false; | 146 // Duplicate the shared memory for this process. |
| 147 base::SharedMemory shared_memory(transfer_buffer, read_only); | 147 base::SharedMemory shared_memory(transfer_buffer, false); |
| 148 command_buffer_->RegisterTransferBuffer(id, &shared_memory, size); | 148 base::SharedMemoryHandle duped_shared_memory_handle; |
| 149 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), |
| 150 &duped_shared_memory_handle)) { |
| 151 DVLOG(0) << "Failed to duplicate shared memory handle."; |
| 152 return; |
| 153 } |
| 154 scoped_ptr<base::SharedMemory> duped_shared_memory( |
| 155 new base::SharedMemory(duped_shared_memory_handle, false)); |
| 156 |
| 157 // Map the shared memory into this process. This validates the size. |
| 158 if (!duped_shared_memory->Map(size)) { |
| 159 DVLOG(0) << "Failed to map shared memory."; |
| 160 return; |
| 161 } |
| 162 |
| 163 command_buffer_->RegisterTransferBuffer(id, duped_shared_memory.Pass(), size); |
| 149 } | 164 } |
| 150 | 165 |
| 151 void CommandBufferImpl::DestroyTransferBuffer(int32_t id) { | 166 void CommandBufferImpl::DestroyTransferBuffer(int32_t id) { |
| 152 command_buffer_->DestroyTransferBuffer(id); | 167 command_buffer_->DestroyTransferBuffer(id); |
| 153 } | 168 } |
| 154 | 169 |
| 155 void CommandBufferImpl::Echo(const Callback<void()>& callback) { | 170 void CommandBufferImpl::Echo(const Callback<void()>& callback) { |
| 156 callback.Run(); | 171 callback.Run(); |
| 157 } | 172 } |
| 158 | 173 |
| 159 void CommandBufferImpl::RequestAnimationFrames() { | 174 void CommandBufferImpl::RequestAnimationFrames() { |
| 160 timer_.Start(FROM_HERE, | 175 timer_.Start(FROM_HERE, |
| 161 base::TimeDelta::FromMilliseconds(16), | 176 base::TimeDelta::FromMilliseconds(16), |
| 162 this, | 177 this, |
| 163 &CommandBufferImpl::DrawAnimationFrame); | 178 &CommandBufferImpl::DrawAnimationFrame); |
| 164 } | 179 } |
| 165 | 180 |
| 166 void CommandBufferImpl::CancelAnimationFrames() { timer_.Stop(); } | 181 void CommandBufferImpl::CancelAnimationFrames() { timer_.Stop(); } |
| 167 | 182 |
| 168 void CommandBufferImpl::OnParseError() { | 183 void CommandBufferImpl::OnParseError() { |
| 169 gpu::CommandBuffer::State state = command_buffer_->GetState(); | 184 gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 170 client_->LostContext(state.context_lost_reason); | 185 client_->LostContext(state.context_lost_reason); |
| 171 } | 186 } |
| 172 | 187 |
| 173 void CommandBufferImpl::DrawAnimationFrame() { client_->DrawAnimationFrame(); } | 188 void CommandBufferImpl::DrawAnimationFrame() { client_->DrawAnimationFrame(); } |
| 174 | 189 |
| 175 } // namespace services | 190 } // namespace services |
| 176 } // namespace mojo | 191 } // namespace mojo |
| OLD | NEW |