| 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" |
| 11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "content/common/child_process_messages.h" | 13 #include "content/common/child_process_messages.h" |
| 14 #include "content/common/gpu/gpu_memory_allocation.h" | 14 #include "content/common/gpu/gpu_memory_allocation.h" |
| 15 #include "content/common/gpu/client/gpu_channel_host.h" | 15 #include "content/common/gpu/client/gpu_channel_host.h" |
| 16 #include "content/common/gpu/gpu_messages.h" | 16 #include "content/common/gpu/gpu_messages.h" |
| 17 #include "content/common/plugin_messages.h" | 17 #include "content/common/plugin_messages.h" |
| 18 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 19 #include "gpu/command_buffer/common/cmd_buffer_common.h" | 19 #include "gpu/command_buffer/common/cmd_buffer_common.h" |
| 20 #include "gpu/command_buffer/common/command_buffer_shared.h" | 20 #include "gpu/command_buffer/common/command_buffer_shared.h" |
| 21 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 22 | 22 |
| 23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 24 #include "content/public/common/sandbox_init.h" | 24 #include "content/public/common/sandbox_init.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 using gpu::Buffer; | 27 using gpu::Buffer; |
| 28 | 28 |
| 29 namespace content { |
| 30 |
| 29 CommandBufferProxyImpl::CommandBufferProxyImpl( | 31 CommandBufferProxyImpl::CommandBufferProxyImpl( |
| 30 GpuChannelHost* channel, | 32 GpuChannelHost* channel, |
| 31 int route_id) | 33 int route_id) |
| 32 : shared_state_(NULL), | 34 : shared_state_(NULL), |
| 33 channel_(channel), | 35 channel_(channel), |
| 34 route_id_(route_id), | 36 route_id_(route_id), |
| 35 flush_count_(0), | 37 flush_count_(0), |
| 36 last_put_offset_(-1), | 38 last_put_offset_(-1), |
| 37 next_signal_id_(0), | 39 next_signal_id_(0), |
| 38 state_buffer_(-1) { | 40 state_buffer_(-1) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 // fails. Otherwise, callee takes ownership before this variable | 256 // fails. Otherwise, callee takes ownership before this variable |
| 255 // goes out of scope by duping the handle. | 257 // goes out of scope by duping the handle. |
| 256 scoped_ptr<base::SharedMemory> shm( | 258 scoped_ptr<base::SharedMemory> shm( |
| 257 channel_->factory()->AllocateSharedMemory(size)); | 259 channel_->factory()->AllocateSharedMemory(size)); |
| 258 if (!shm.get()) | 260 if (!shm.get()) |
| 259 return -1; | 261 return -1; |
| 260 | 262 |
| 261 base::SharedMemoryHandle handle = shm->handle(); | 263 base::SharedMemoryHandle handle = shm->handle(); |
| 262 #if defined(OS_WIN) | 264 #if defined(OS_WIN) |
| 263 // Windows needs to explicitly duplicate the handle out to another process. | 265 // Windows needs to explicitly duplicate the handle out to another process. |
| 264 if (!content::BrokerDuplicateHandle(handle, channel_->gpu_pid(), | 266 if (!BrokerDuplicateHandle(handle, channel_->gpu_pid(), &handle, |
| 265 &handle, FILE_MAP_WRITE, 0)) { | 267 FILE_MAP_WRITE, 0)) { |
| 266 return -1; | 268 return -1; |
| 267 } | 269 } |
| 268 #elif defined(OS_POSIX) | 270 #elif defined(OS_POSIX) |
| 269 DCHECK(!handle.auto_close); | 271 DCHECK(!handle.auto_close); |
| 270 #endif | 272 #endif |
| 271 | 273 |
| 272 int32 id; | 274 int32 id; |
| 273 if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer(route_id_, | 275 if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer(route_id_, |
| 274 handle, | 276 handle, |
| 275 size, | 277 size, |
| 276 id_request, | 278 id_request, |
| 277 &id))) { | 279 &id))) { |
| 278 return -1; | 280 return -1; |
| 279 } | 281 } |
| 280 | 282 |
| 281 return id; | 283 return id; |
| 282 } | 284 } |
| 283 | 285 |
| 284 int32 CommandBufferProxyImpl::RegisterTransferBuffer( | 286 int32 CommandBufferProxyImpl::RegisterTransferBuffer( |
| 285 base::SharedMemory* shared_memory, | 287 base::SharedMemory* shared_memory, |
| 286 size_t size, | 288 size_t size, |
| 287 int32 id_request) { | 289 int32 id_request) { |
| 288 if (last_state_.error != gpu::error::kNoError) | 290 if (last_state_.error != gpu::error::kNoError) |
| 289 return -1; | 291 return -1; |
| 290 | 292 |
| 291 // Returns FileDescriptor with auto_close off. | 293 // Returns FileDescriptor with auto_close off. |
| 292 base::SharedMemoryHandle handle = shared_memory->handle(); | 294 base::SharedMemoryHandle handle = shared_memory->handle(); |
| 293 #if defined(OS_WIN) | 295 #if defined(OS_WIN) |
| 294 // Windows needs to explicitly duplicate the handle out to another process. | 296 // Windows needs to explicitly duplicate the handle out to another process. |
| 295 if (!content::BrokerDuplicateHandle(handle, channel_->gpu_pid(), | 297 if (!BrokerDuplicateHandle(handle, channel_->gpu_pid(), &handle, |
| 296 &handle, FILE_MAP_WRITE, 0)) { | 298 FILE_MAP_WRITE, 0)) { |
| 297 return -1; | 299 return -1; |
| 298 } | 300 } |
| 299 #endif | 301 #endif |
| 300 | 302 |
| 301 int32 id; | 303 int32 id; |
| 302 if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer( | 304 if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer( |
| 303 route_id_, | 305 route_id_, |
| 304 handle, | 306 handle, |
| 305 size, | 307 size, |
| 306 id_request, | 308 id_request, |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 556 |
| 555 void CommandBufferProxyImpl::SetOnConsoleMessageCallback( | 557 void CommandBufferProxyImpl::SetOnConsoleMessageCallback( |
| 556 const GpuConsoleMessageCallback& callback) { | 558 const GpuConsoleMessageCallback& callback) { |
| 557 console_message_callback_ = callback; | 559 console_message_callback_ = callback; |
| 558 } | 560 } |
| 559 | 561 |
| 560 void CommandBufferProxyImpl::TryUpdateState() { | 562 void CommandBufferProxyImpl::TryUpdateState() { |
| 561 if (last_state_.error == gpu::error::kNoError) | 563 if (last_state_.error == gpu::error::kNoError) |
| 562 shared_state_->Read(&last_state_); | 564 shared_state_->Read(&last_state_); |
| 563 } | 565 } |
| 566 |
| 567 } // namespace content |
| OLD | NEW |