Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: content/common/gpu/gpu_command_buffer_stub.cc

Issue 9958034: Convert plugin and GPU process to brokered handle duplication. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 reply_message->set_reply_error(); 465 reply_message->set_reply_error();
462 } 466 }
463 Send(reply_message); 467 Send(reply_message);
464 } 468 }
465 469
466 void GpuCommandBufferStub::OnRegisterTransferBuffer( 470 void GpuCommandBufferStub::OnRegisterTransferBuffer(
467 base::SharedMemoryHandle transfer_buffer, 471 base::SharedMemoryHandle transfer_buffer,
468 size_t size, 472 size_t size,
469 int32 id_request, 473 int32 id_request,
470 IPC::Message* reply_message) { 474 IPC::Message* reply_message) {
471 #if defined(OS_WIN)
472 // Windows dups the shared memory handle it receives into the current process
473 // and closes it when this variable goes out of scope.
474 base::SharedMemory shared_memory(transfer_buffer,
475 false,
476 channel_->renderer_process());
477 #else
478 // POSIX receives a dup of the shared memory handle and closes the dup when
479 // this variable goes out of scope.
480 base::SharedMemory shared_memory(transfer_buffer, false); 475 base::SharedMemory shared_memory(transfer_buffer, false);
481 #endif
482 476
483 if (command_buffer_.get()) { 477 if (command_buffer_.get()) {
484 int32 id = command_buffer_->RegisterTransferBuffer(&shared_memory, 478 int32 id = command_buffer_->RegisterTransferBuffer(&shared_memory,
485 size, 479 size,
486 id_request); 480 id_request);
487 GpuCommandBufferMsg_RegisterTransferBuffer::WriteReplyParams(reply_message, 481 GpuCommandBufferMsg_RegisterTransferBuffer::WriteReplyParams(reply_message,
488 id); 482 id);
489 } else { 483 } else {
490 reply_message->set_reply_error(); 484 reply_message->set_reply_error();
491 } 485 }
492 486
493 Send(reply_message); 487 Send(reply_message);
494 } 488 }
495 489
496 void GpuCommandBufferStub::OnDestroyTransferBuffer( 490 void GpuCommandBufferStub::OnDestroyTransferBuffer(
497 int32 id, 491 int32 id,
498 IPC::Message* reply_message) { 492 IPC::Message* reply_message) {
499 if (command_buffer_.get()) { 493 if (command_buffer_.get()) {
500 command_buffer_->DestroyTransferBuffer(id); 494 command_buffer_->DestroyTransferBuffer(id);
501 } else { 495 } else {
502 reply_message->set_reply_error(); 496 reply_message->set_reply_error();
503 } 497 }
504 Send(reply_message); 498 Send(reply_message);
505 } 499 }
506 500
507 void GpuCommandBufferStub::OnGetTransferBuffer( 501 void GpuCommandBufferStub::OnGetTransferBuffer(
508 int32 id, 502 int32 id,
509 IPC::Message* reply_message) { 503 IPC::Message* reply_message) {
510 // Fail if the renderer process has not provided its process handle.
511 if (!channel_->renderer_process())
512 return;
513
514 if (command_buffer_.get()) { 504 if (command_buffer_.get()) {
515 base::SharedMemoryHandle transfer_buffer = base::SharedMemoryHandle(); 505 base::SharedMemoryHandle transfer_buffer = base::SharedMemoryHandle();
516 uint32 size = 0; 506 uint32 size = 0;
517 507
518 gpu::Buffer buffer = command_buffer_->GetTransferBuffer(id); 508 gpu::Buffer buffer = command_buffer_->GetTransferBuffer(id);
519 if (buffer.shared_memory) { 509 if (buffer.shared_memory) {
520 // Assume service is responsible for duplicating the handle to the calling 510 #if defined(OS_WIN)
521 // process. 511 transfer_buffer = NULL;
522 buffer.shared_memory->ShareToProcess(channel_->renderer_process(), 512 sandbox::BrokerDuplicateHandle(buffer.shared_memory->handle(),
513 channel_->renderer_pid(), &transfer_buffer, FILE_MAP_WRITE, 0);
514 DCHECK(transfer_buffer != NULL);
apatrick_chromium 2012/04/09 18:40:58 It might be better to crash if you think this coul
jschuh 2012/04/10 19:02:12 It should fail only on a policy violation or a dea
515 #else
516 buffer.shared_memory->ShareToProcess(channel_->renderer_pid(),
523 &transfer_buffer); 517 &transfer_buffer);
518 #endif
524 size = buffer.size; 519 size = buffer.size;
525 } 520 }
526 521
527 GpuCommandBufferMsg_GetTransferBuffer::WriteReplyParams(reply_message, 522 GpuCommandBufferMsg_GetTransferBuffer::WriteReplyParams(reply_message,
528 transfer_buffer, 523 transfer_buffer,
529 size); 524 size);
530 } else { 525 } else {
531 reply_message->set_reply_error(); 526 reply_message->set_reply_error();
532 } 527 }
533 Send(reply_message); 528 Send(reply_message);
(...skipping 17 matching lines...) Expand all
551 void GpuCommandBufferStub::OnCreateVideoDecoder( 546 void GpuCommandBufferStub::OnCreateVideoDecoder(
552 media::VideoCodecProfile profile, 547 media::VideoCodecProfile profile,
553 IPC::Message* reply_message) { 548 IPC::Message* reply_message) {
554 int decoder_route_id = channel_->GenerateRouteID(); 549 int decoder_route_id = channel_->GenerateRouteID();
555 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams( 550 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(
556 reply_message, decoder_route_id); 551 reply_message, decoder_route_id);
557 GpuVideoDecodeAccelerator* decoder = 552 GpuVideoDecodeAccelerator* decoder =
558 new GpuVideoDecodeAccelerator(this, decoder_route_id, this); 553 new GpuVideoDecodeAccelerator(this, decoder_route_id, this);
559 video_decoders_.AddWithID(decoder, decoder_route_id); 554 video_decoders_.AddWithID(decoder, decoder_route_id);
560 channel_->AddRoute(decoder_route_id, decoder); 555 channel_->AddRoute(decoder_route_id, decoder);
561 decoder->Initialize(profile, reply_message, 556 decoder->Initialize(profile, reply_message);
562 channel_->renderer_process());
563 } 557 }
564 558
565 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { 559 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) {
566 channel_->RemoveRoute(decoder_route_id); 560 channel_->RemoveRoute(decoder_route_id);
567 video_decoders_.Remove(decoder_route_id); 561 video_decoders_.Remove(decoder_route_id);
568 } 562 }
569 563
570 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { 564 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) {
571 DCHECK(surface_state_.get()); 565 DCHECK(surface_state_.get());
572 surface_state_->visible = visible; 566 surface_state_->visible = visible;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 } 631 }
638 632
639 void GpuCommandBufferStub::SetMemoryAllocation( 633 void GpuCommandBufferStub::SetMemoryAllocation(
640 const GpuMemoryAllocation& allocation) { 634 const GpuMemoryAllocation& allocation) {
641 allocation_ = allocation; 635 allocation_ = allocation;
642 636
643 SendMemoryAllocationToProxy(allocation); 637 SendMemoryAllocationToProxy(allocation);
644 } 638 }
645 639
646 #endif // defined(ENABLE_GPU) 640 #endif // defined(ENABLE_GPU)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698