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 |
26 GpuCommandBufferStub::SurfaceState::SurfaceState(int32 surface_id, | 30 GpuCommandBufferStub::SurfaceState::SurfaceState(int32 surface_id, |
27 bool visible, | 31 bool visible, |
28 base::TimeTicks last_used_time) | 32 base::TimeTicks last_used_time) |
29 : surface_id(surface_id), | 33 : surface_id(surface_id), |
30 visible(visible), | 34 visible(visible), |
31 last_used_time(last_used_time) { | 35 last_used_time(last_used_time) { |
32 } | 36 } |
33 | 37 |
34 GpuCommandBufferStub::GpuCommandBufferStub( | 38 GpuCommandBufferStub::GpuCommandBufferStub( |
35 GpuChannel* channel, | 39 GpuChannel* channel, |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 reply_message->set_reply_error(); | 464 reply_message->set_reply_error(); |
461 } | 465 } |
462 Send(reply_message); | 466 Send(reply_message); |
463 } | 467 } |
464 | 468 |
465 void GpuCommandBufferStub::OnRegisterTransferBuffer( | 469 void GpuCommandBufferStub::OnRegisterTransferBuffer( |
466 base::SharedMemoryHandle transfer_buffer, | 470 base::SharedMemoryHandle transfer_buffer, |
467 size_t size, | 471 size_t size, |
468 int32 id_request, | 472 int32 id_request, |
469 IPC::Message* reply_message) { | 473 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. | |
479 base::SharedMemory shared_memory(transfer_buffer, false); | 474 base::SharedMemory shared_memory(transfer_buffer, false); |
480 #endif | |
481 | 475 |
482 if (command_buffer_.get()) { | 476 if (command_buffer_.get()) { |
483 int32 id = command_buffer_->RegisterTransferBuffer(&shared_memory, | 477 int32 id = command_buffer_->RegisterTransferBuffer(&shared_memory, |
484 size, | 478 size, |
485 id_request); | 479 id_request); |
486 GpuCommandBufferMsg_RegisterTransferBuffer::WriteReplyParams(reply_message, | 480 GpuCommandBufferMsg_RegisterTransferBuffer::WriteReplyParams(reply_message, |
487 id); | 481 id); |
488 } else { | 482 } else { |
489 reply_message->set_reply_error(); | 483 reply_message->set_reply_error(); |
490 } | 484 } |
491 | 485 |
492 Send(reply_message); | 486 Send(reply_message); |
493 } | 487 } |
494 | 488 |
495 void GpuCommandBufferStub::OnDestroyTransferBuffer( | 489 void GpuCommandBufferStub::OnDestroyTransferBuffer( |
496 int32 id, | 490 int32 id, |
497 IPC::Message* reply_message) { | 491 IPC::Message* reply_message) { |
498 if (command_buffer_.get()) { | 492 if (command_buffer_.get()) { |
499 command_buffer_->DestroyTransferBuffer(id); | 493 command_buffer_->DestroyTransferBuffer(id); |
500 } else { | 494 } else { |
501 reply_message->set_reply_error(); | 495 reply_message->set_reply_error(); |
502 } | 496 } |
503 Send(reply_message); | 497 Send(reply_message); |
504 } | 498 } |
505 | 499 |
506 void GpuCommandBufferStub::OnGetTransferBuffer( | 500 void GpuCommandBufferStub::OnGetTransferBuffer( |
507 int32 id, | 501 int32 id, |
508 IPC::Message* reply_message) { | 502 IPC::Message* reply_message) { |
509 // Fail if the renderer process has not provided its process handle. | |
510 if (!channel_->renderer_process()) | |
511 return; | |
512 | |
513 if (command_buffer_.get()) { | 503 if (command_buffer_.get()) { |
514 base::SharedMemoryHandle transfer_buffer = base::SharedMemoryHandle(); | 504 base::SharedMemoryHandle transfer_buffer = base::SharedMemoryHandle(); |
515 uint32 size = 0; | 505 uint32 size = 0; |
516 | 506 |
517 gpu::Buffer buffer = command_buffer_->GetTransferBuffer(id); | 507 gpu::Buffer buffer = command_buffer_->GetTransferBuffer(id); |
518 if (buffer.shared_memory) { | 508 if (buffer.shared_memory) { |
519 // Assume service is responsible for duplicating the handle to the calling | 509 #if defined(OS_WIN) |
520 // process. | 510 transfer_buffer = NULL; |
521 buffer.shared_memory->ShareToProcess(channel_->renderer_process(), | 511 sandbox::BrokerDuplicateHandle(buffer.shared_memory->handle(), |
| 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(), |
522 &transfer_buffer); | 517 &transfer_buffer); |
| 518 #endif |
523 size = buffer.size; | 519 size = buffer.size; |
524 } | 520 } |
525 | 521 |
526 GpuCommandBufferMsg_GetTransferBuffer::WriteReplyParams(reply_message, | 522 GpuCommandBufferMsg_GetTransferBuffer::WriteReplyParams(reply_message, |
527 transfer_buffer, | 523 transfer_buffer, |
528 size); | 524 size); |
529 } else { | 525 } else { |
530 reply_message->set_reply_error(); | 526 reply_message->set_reply_error(); |
531 } | 527 } |
532 Send(reply_message); | 528 Send(reply_message); |
(...skipping 17 matching lines...) Expand all Loading... |
550 void GpuCommandBufferStub::OnCreateVideoDecoder( | 546 void GpuCommandBufferStub::OnCreateVideoDecoder( |
551 media::VideoCodecProfile profile, | 547 media::VideoCodecProfile profile, |
552 IPC::Message* reply_message) { | 548 IPC::Message* reply_message) { |
553 int decoder_route_id = channel_->GenerateRouteID(); | 549 int decoder_route_id = channel_->GenerateRouteID(); |
554 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams( | 550 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams( |
555 reply_message, decoder_route_id); | 551 reply_message, decoder_route_id); |
556 GpuVideoDecodeAccelerator* decoder = | 552 GpuVideoDecodeAccelerator* decoder = |
557 new GpuVideoDecodeAccelerator(this, decoder_route_id, this); | 553 new GpuVideoDecodeAccelerator(this, decoder_route_id, this); |
558 video_decoders_.AddWithID(decoder, decoder_route_id); | 554 video_decoders_.AddWithID(decoder, decoder_route_id); |
559 channel_->AddRoute(decoder_route_id, decoder); | 555 channel_->AddRoute(decoder_route_id, decoder); |
560 decoder->Initialize(profile, reply_message, | 556 decoder->Initialize(profile, reply_message); |
561 channel_->renderer_process()); | |
562 } | 557 } |
563 | 558 |
564 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { | 559 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { |
565 channel_->RemoveRoute(decoder_route_id); | 560 channel_->RemoveRoute(decoder_route_id); |
566 video_decoders_.Remove(decoder_route_id); | 561 video_decoders_.Remove(decoder_route_id); |
567 } | 562 } |
568 | 563 |
569 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { | 564 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { |
570 DCHECK(surface_state_.get()); | 565 DCHECK(surface_state_.get()); |
571 surface_state_->visible = visible; | 566 surface_state_->visible = visible; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 } | 631 } |
637 | 632 |
638 void GpuCommandBufferStub::SetMemoryAllocation( | 633 void GpuCommandBufferStub::SetMemoryAllocation( |
639 const GpuMemoryAllocation& allocation) { | 634 const GpuMemoryAllocation& allocation) { |
640 allocation_ = allocation; | 635 allocation_ = allocation; |
641 | 636 |
642 SendMemoryAllocationToProxy(allocation); | 637 SendMemoryAllocationToProxy(allocation); |
643 } | 638 } |
644 | 639 |
645 #endif // defined(ENABLE_GPU) | 640 #endif // defined(ENABLE_GPU) |
OLD | NEW |