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/gpu_channel_host.h" | 5 #include "content/common/gpu/client/gpu_channel_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/posix/eintr_wrapper.h" | 11 #include "base/posix/eintr_wrapper.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 #include "content/common/gpu/client/command_buffer_proxy_impl.h" | 16 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
17 #include "content/common/gpu/gpu_messages.h" | 17 #include "content/common/gpu/gpu_messages.h" |
18 #include "ipc/ipc_sync_message_filter.h" | 18 #include "ipc/ipc_sync_message_filter.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 #if defined(OS_WIN) | 21 #if defined(OS_WIN) || defined(OS_MACOSX) |
22 #include "content/public/common/sandbox_init.h" | 22 #include "content/public/common/sandbox_init.h" |
23 #endif | 23 #endif |
24 | 24 |
25 using base::AutoLock; | 25 using base::AutoLock; |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 GpuListenerInfo::GpuListenerInfo() {} | 29 GpuListenerInfo::GpuListenerInfo() {} |
30 | 30 |
31 GpuListenerInfo::~GpuListenerInfo() {} | 31 GpuListenerInfo::~GpuListenerInfo() {} |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 io_task_runner->PostTask( | 296 io_task_runner->PostTask( |
297 FROM_HERE, base::Bind(&GpuChannelHost::MessageFilter::RemoveRoute, | 297 FROM_HERE, base::Bind(&GpuChannelHost::MessageFilter::RemoveRoute, |
298 channel_filter_.get(), route_id)); | 298 channel_filter_.get(), route_id)); |
299 } | 299 } |
300 | 300 |
301 base::SharedMemoryHandle GpuChannelHost::ShareToGpuProcess( | 301 base::SharedMemoryHandle GpuChannelHost::ShareToGpuProcess( |
302 base::SharedMemoryHandle source_handle) { | 302 base::SharedMemoryHandle source_handle) { |
303 if (IsLost()) | 303 if (IsLost()) |
304 return base::SharedMemory::NULLHandle(); | 304 return base::SharedMemory::NULLHandle(); |
305 | 305 |
306 #if defined(OS_WIN) | 306 #if defined(OS_WIN) || defined(OS_MACOSX) |
307 // Windows needs to explicitly duplicate the handle out to another process. | 307 // Windows and Mac need to explicitly duplicate the handle out to another |
| 308 // process. |
308 base::SharedMemoryHandle target_handle; | 309 base::SharedMemoryHandle target_handle; |
309 base::ProcessId peer_pid; | 310 base::ProcessId peer_pid; |
310 { | 311 { |
311 AutoLock lock(context_lock_); | 312 AutoLock lock(context_lock_); |
312 if (!channel_) | 313 if (!channel_) |
313 return base::SharedMemory::NULLHandle(); | 314 return base::SharedMemory::NULLHandle(); |
314 peer_pid = channel_->GetPeerPID(); | 315 peer_pid = channel_->GetPeerPID(); |
315 } | 316 } |
316 if (!BrokerDuplicateHandle(source_handle, | 317 #if defined(OS_WIN) |
317 peer_pid, | 318 bool success = |
318 &target_handle, | 319 BrokerDuplicateHandle(source_handle, peer_pid, &target_handle, |
319 FILE_GENERIC_READ | FILE_GENERIC_WRITE, | 320 FILE_GENERIC_READ | FILE_GENERIC_WRITE, 0); |
320 0)) { | 321 #elif defined(OS_MACOSX) |
| 322 bool success = BrokerDuplicateSharedMemoryHandle(source_handle, peer_pid, |
| 323 &target_handle); |
| 324 #endif |
| 325 if (!success) |
321 return base::SharedMemory::NULLHandle(); | 326 return base::SharedMemory::NULLHandle(); |
322 } | |
323 | 327 |
324 return target_handle; | 328 return target_handle; |
325 #else | 329 #else |
326 int duped_handle = HANDLE_EINTR(dup(source_handle.fd)); | 330 return base::SharedMemory::DuplicateHandle(source_handle); |
327 if (duped_handle < 0) | 331 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
328 return base::SharedMemory::NULLHandle(); | |
329 | |
330 return base::FileDescriptor(duped_handle, true); | |
331 #endif | |
332 } | 332 } |
333 | 333 |
334 int32 GpuChannelHost::ReserveTransferBufferId() { | 334 int32 GpuChannelHost::ReserveTransferBufferId() { |
335 return next_transfer_buffer_id_.GetNext(); | 335 return next_transfer_buffer_id_.GetNext(); |
336 } | 336 } |
337 | 337 |
338 gfx::GpuMemoryBufferHandle GpuChannelHost::ShareGpuMemoryBufferToGpuProcess( | 338 gfx::GpuMemoryBufferHandle GpuChannelHost::ShareGpuMemoryBufferToGpuProcess( |
339 const gfx::GpuMemoryBufferHandle& source_handle, | 339 const gfx::GpuMemoryBufferHandle& source_handle, |
340 bool* requires_sync_point) { | 340 bool* requires_sync_point) { |
341 switch (source_handle.type) { | 341 switch (source_handle.type) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 436 |
437 listeners_.clear(); | 437 listeners_.clear(); |
438 } | 438 } |
439 | 439 |
440 bool GpuChannelHost::MessageFilter::IsLost() const { | 440 bool GpuChannelHost::MessageFilter::IsLost() const { |
441 AutoLock lock(lock_); | 441 AutoLock lock(lock_); |
442 return lost_; | 442 return lost_; |
443 } | 443 } |
444 | 444 |
445 } // namespace content | 445 } // namespace content |
OLD | NEW |