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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "content/common/gpu/gpu_channel.h" | 14 #include "content/common/gpu/gpu_channel.h" |
15 #include "content/common/gpu/gpu_channel_manager.h" | 15 #include "content/common/gpu/gpu_channel_manager.h" |
16 #include "content/common/gpu/gpu_command_buffer_stub.h" | 16 #include "content/common/gpu/gpu_command_buffer_stub.h" |
17 #include "content/common/gpu/gpu_memory_manager.h" | 17 #include "content/common/gpu/gpu_memory_manager.h" |
18 #include "content/common/gpu/gpu_messages.h" | 18 #include "content/common/gpu/gpu_messages.h" |
19 #include "content/common/gpu/gpu_watchdog.h" | 19 #include "content/common/gpu/gpu_watchdog.h" |
20 #include "content/common/gpu/image_transport_surface.h" | 20 #include "content/common/gpu/image_transport_surface.h" |
21 #include "gpu/command_buffer/common/constants.h" | 21 #include "gpu/command_buffer/common/constants.h" |
22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
23 #include "ui/gfx/gl/gl_bindings.h" | 23 #include "ui/gfx/gl/gl_bindings.h" |
24 #include "ui/gfx/gl/gl_switches.h" | 24 #include "ui/gfx/gl/gl_switches.h" |
25 | 25 |
26 #if defined(OS_WIN) | |
27 #include "content/common/sandbox_policy.h" | |
28 #endif | |
29 | |
30 GpuCommandBufferStub::SurfaceState::SurfaceState(int32 surface_id, | 26 GpuCommandBufferStub::SurfaceState::SurfaceState(int32 surface_id, |
31 bool visible, | 27 bool visible, |
32 base::TimeTicks last_used_time) | 28 base::TimeTicks last_used_time) |
33 : surface_id(surface_id), | 29 : surface_id(surface_id), |
34 visible(visible), | 30 visible(visible), |
35 last_used_time(last_used_time) { | 31 last_used_time(last_used_time) { |
36 } | 32 } |
37 | 33 |
38 GpuCommandBufferStub::GpuCommandBufferStub( | 34 GpuCommandBufferStub::GpuCommandBufferStub( |
39 GpuChannel* channel, | 35 GpuChannel* channel, |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 reply_message->set_reply_error(); | 460 reply_message->set_reply_error(); |
465 } | 461 } |
466 Send(reply_message); | 462 Send(reply_message); |
467 } | 463 } |
468 | 464 |
469 void GpuCommandBufferStub::OnRegisterTransferBuffer( | 465 void GpuCommandBufferStub::OnRegisterTransferBuffer( |
470 base::SharedMemoryHandle transfer_buffer, | 466 base::SharedMemoryHandle transfer_buffer, |
471 size_t size, | 467 size_t size, |
472 int32 id_request, | 468 int32 id_request, |
473 IPC::Message* reply_message) { | 469 IPC::Message* reply_message) { |
| 470 #if defined(OS_WIN) |
| 471 // Windows dups the shared memory handle it receives into the current process |
| 472 // and closes it when this variable goes out of scope. |
| 473 base::SharedMemory shared_memory(transfer_buffer, |
| 474 false, |
| 475 channel_->renderer_process()); |
| 476 #else |
| 477 // POSIX receives a dup of the shared memory handle and closes the dup when |
| 478 // this variable goes out of scope. |
474 base::SharedMemory shared_memory(transfer_buffer, false); | 479 base::SharedMemory shared_memory(transfer_buffer, false); |
| 480 #endif |
475 | 481 |
476 if (command_buffer_.get()) { | 482 if (command_buffer_.get()) { |
477 int32 id = command_buffer_->RegisterTransferBuffer(&shared_memory, | 483 int32 id = command_buffer_->RegisterTransferBuffer(&shared_memory, |
478 size, | 484 size, |
479 id_request); | 485 id_request); |
480 GpuCommandBufferMsg_RegisterTransferBuffer::WriteReplyParams(reply_message, | 486 GpuCommandBufferMsg_RegisterTransferBuffer::WriteReplyParams(reply_message, |
481 id); | 487 id); |
482 } else { | 488 } else { |
483 reply_message->set_reply_error(); | 489 reply_message->set_reply_error(); |
484 } | 490 } |
485 | 491 |
486 Send(reply_message); | 492 Send(reply_message); |
487 } | 493 } |
488 | 494 |
489 void GpuCommandBufferStub::OnDestroyTransferBuffer( | 495 void GpuCommandBufferStub::OnDestroyTransferBuffer( |
490 int32 id, | 496 int32 id, |
491 IPC::Message* reply_message) { | 497 IPC::Message* reply_message) { |
492 if (command_buffer_.get()) { | 498 if (command_buffer_.get()) { |
493 command_buffer_->DestroyTransferBuffer(id); | 499 command_buffer_->DestroyTransferBuffer(id); |
494 } else { | 500 } else { |
495 reply_message->set_reply_error(); | 501 reply_message->set_reply_error(); |
496 } | 502 } |
497 Send(reply_message); | 503 Send(reply_message); |
498 } | 504 } |
499 | 505 |
500 void GpuCommandBufferStub::OnGetTransferBuffer( | 506 void GpuCommandBufferStub::OnGetTransferBuffer( |
501 int32 id, | 507 int32 id, |
502 IPC::Message* reply_message) { | 508 IPC::Message* reply_message) { |
| 509 // Fail if the renderer process has not provided its process handle. |
| 510 if (!channel_->renderer_process()) |
| 511 return; |
| 512 |
503 if (command_buffer_.get()) { | 513 if (command_buffer_.get()) { |
504 base::SharedMemoryHandle transfer_buffer = base::SharedMemoryHandle(); | 514 base::SharedMemoryHandle transfer_buffer = base::SharedMemoryHandle(); |
505 uint32 size = 0; | 515 uint32 size = 0; |
506 | 516 |
507 gpu::Buffer buffer = command_buffer_->GetTransferBuffer(id); | 517 gpu::Buffer buffer = command_buffer_->GetTransferBuffer(id); |
508 if (buffer.shared_memory) { | 518 if (buffer.shared_memory) { |
509 #if defined(OS_WIN) | 519 // Assume service is responsible for duplicating the handle to the calling |
510 transfer_buffer = NULL; | 520 // process. |
511 sandbox::BrokerDuplicateHandle(buffer.shared_memory->handle(), | 521 buffer.shared_memory->ShareToProcess(channel_->renderer_process(), |
512 channel_->renderer_pid(), &transfer_buffer, FILE_MAP_READ | | |
513 FILE_MAP_WRITE, 0); | |
514 CHECK(transfer_buffer != NULL); | |
515 #else | |
516 buffer.shared_memory->ShareToProcess(channel_->renderer_pid(), | |
517 &transfer_buffer); | 522 &transfer_buffer); |
518 #endif | |
519 size = buffer.size; | 523 size = buffer.size; |
520 } | 524 } |
521 | 525 |
522 GpuCommandBufferMsg_GetTransferBuffer::WriteReplyParams(reply_message, | 526 GpuCommandBufferMsg_GetTransferBuffer::WriteReplyParams(reply_message, |
523 transfer_buffer, | 527 transfer_buffer, |
524 size); | 528 size); |
525 } else { | 529 } else { |
526 reply_message->set_reply_error(); | 530 reply_message->set_reply_error(); |
527 } | 531 } |
528 Send(reply_message); | 532 Send(reply_message); |
(...skipping 17 matching lines...) Expand all Loading... |
546 void GpuCommandBufferStub::OnCreateVideoDecoder( | 550 void GpuCommandBufferStub::OnCreateVideoDecoder( |
547 media::VideoCodecProfile profile, | 551 media::VideoCodecProfile profile, |
548 IPC::Message* reply_message) { | 552 IPC::Message* reply_message) { |
549 int decoder_route_id = channel_->GenerateRouteID(); | 553 int decoder_route_id = channel_->GenerateRouteID(); |
550 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams( | 554 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams( |
551 reply_message, decoder_route_id); | 555 reply_message, decoder_route_id); |
552 GpuVideoDecodeAccelerator* decoder = | 556 GpuVideoDecodeAccelerator* decoder = |
553 new GpuVideoDecodeAccelerator(this, decoder_route_id, this); | 557 new GpuVideoDecodeAccelerator(this, decoder_route_id, this); |
554 video_decoders_.AddWithID(decoder, decoder_route_id); | 558 video_decoders_.AddWithID(decoder, decoder_route_id); |
555 channel_->AddRoute(decoder_route_id, decoder); | 559 channel_->AddRoute(decoder_route_id, decoder); |
556 decoder->Initialize(profile, reply_message); | 560 decoder->Initialize(profile, reply_message, |
| 561 channel_->renderer_process()); |
557 } | 562 } |
558 | 563 |
559 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { | 564 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { |
560 channel_->RemoveRoute(decoder_route_id); | 565 channel_->RemoveRoute(decoder_route_id); |
561 video_decoders_.Remove(decoder_route_id); | 566 video_decoders_.Remove(decoder_route_id); |
562 } | 567 } |
563 | 568 |
564 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { | 569 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { |
565 DCHECK(surface_state_.get()); | 570 DCHECK(surface_state_.get()); |
566 surface_state_->visible = visible; | 571 surface_state_->visible = visible; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 } | 636 } |
632 | 637 |
633 void GpuCommandBufferStub::SetMemoryAllocation( | 638 void GpuCommandBufferStub::SetMemoryAllocation( |
634 const GpuMemoryAllocation& allocation) { | 639 const GpuMemoryAllocation& allocation) { |
635 allocation_ = allocation; | 640 allocation_ = allocation; |
636 | 641 |
637 SendMemoryAllocationToProxy(allocation); | 642 SendMemoryAllocationToProxy(allocation); |
638 } | 643 } |
639 | 644 |
640 #endif // defined(ENABLE_GPU) | 645 #endif // defined(ENABLE_GPU) |
OLD | NEW |