Chromium Code Reviews| 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/gpu_channel.h" | 5 #include "content/common/gpu/gpu_channel.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 channel_messages_.push_back(msg.release()); | 215 channel_messages_.push_back(msg.release()); |
| 216 if (!had_messages) | 216 if (!had_messages) |
| 217 ScheduleHandleMessage(); | 217 ScheduleHandleMessage(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 GpuChannelMessageFilter::GpuChannelMessageFilter( | 220 GpuChannelMessageFilter::GpuChannelMessageFilter( |
| 221 const base::WeakPtr<GpuChannel>& gpu_channel, | 221 const base::WeakPtr<GpuChannel>& gpu_channel, |
| 222 GpuChannelMessageQueue* message_queue, | 222 GpuChannelMessageQueue* message_queue, |
| 223 gpu::SyncPointManager* sync_point_manager, | 223 gpu::SyncPointManager* sync_point_manager, |
| 224 base::SingleThreadTaskRunner* task_runner, | 224 base::SingleThreadTaskRunner* task_runner, |
| 225 gpu::PreemptionFlag* preempting_flag, | |
| 225 bool future_sync_points) | 226 bool future_sync_points) |
| 226 : preemption_state_(IDLE), | 227 : preemption_state_(IDLE), |
| 227 gpu_channel_(gpu_channel), | 228 gpu_channel_(gpu_channel), |
| 228 message_queue_(message_queue), | 229 message_queue_(message_queue), |
| 229 sender_(nullptr), | 230 sender_(nullptr), |
| 230 peer_pid_(base::kNullProcessId), | 231 peer_pid_(base::kNullProcessId), |
| 231 sync_point_manager_(sync_point_manager), | 232 sync_point_manager_(sync_point_manager), |
| 232 task_runner_(task_runner), | 233 task_runner_(task_runner), |
| 234 preempting_flag_(preempting_flag), | |
| 233 a_stub_is_descheduled_(false), | 235 a_stub_is_descheduled_(false), |
| 234 future_sync_points_(future_sync_points) {} | 236 future_sync_points_(future_sync_points) {} |
| 235 | 237 |
| 236 GpuChannelMessageFilter::~GpuChannelMessageFilter() {} | 238 GpuChannelMessageFilter::~GpuChannelMessageFilter() {} |
| 237 | 239 |
| 238 void GpuChannelMessageFilter::OnFilterAdded(IPC::Sender* sender) { | 240 void GpuChannelMessageFilter::OnFilterAdded(IPC::Sender* sender) { |
| 239 DCHECK(!sender_); | 241 DCHECK(!sender_); |
| 240 sender_ = sender; | 242 sender_ = sender; |
| 241 timer_ = make_scoped_ptr(new base::OneShotTimer<GpuChannelMessageFilter>); | 243 timer_ = make_scoped_ptr(new base::OneShotTimer<GpuChannelMessageFilter>); |
| 242 for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_) { | 244 for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 } | 363 } |
| 362 | 364 |
| 363 UpdatePreemptionState(); | 365 UpdatePreemptionState(); |
| 364 return handled; | 366 return handled; |
| 365 } | 367 } |
| 366 | 368 |
| 367 void GpuChannelMessageFilter::OnMessageProcessed() { | 369 void GpuChannelMessageFilter::OnMessageProcessed() { |
| 368 UpdatePreemptionState(); | 370 UpdatePreemptionState(); |
| 369 } | 371 } |
| 370 | 372 |
| 371 void GpuChannelMessageFilter::SetPreemptingFlagAndSchedulingState( | |
| 372 gpu::PreemptionFlag* preempting_flag, | |
| 373 bool a_stub_is_descheduled) { | |
| 374 preempting_flag_ = preempting_flag; | |
| 375 a_stub_is_descheduled_ = a_stub_is_descheduled; | |
| 376 } | |
| 377 | |
| 378 void GpuChannelMessageFilter::UpdateStubSchedulingState( | 373 void GpuChannelMessageFilter::UpdateStubSchedulingState( |
| 379 bool a_stub_is_descheduled) { | 374 bool a_stub_is_descheduled) { |
| 380 a_stub_is_descheduled_ = a_stub_is_descheduled; | 375 a_stub_is_descheduled_ = a_stub_is_descheduled; |
| 381 UpdatePreemptionState(); | 376 UpdatePreemptionState(); |
| 382 } | 377 } |
| 383 | 378 |
| 384 bool GpuChannelMessageFilter::Send(IPC::Message* message) { | 379 bool GpuChannelMessageFilter::Send(IPC::Message* message) { |
| 385 return sender_->Send(message); | 380 return sender_->Send(message); |
| 386 } | 381 } |
| 387 | 382 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 } | 537 } |
| 543 | 538 |
| 544 bool GpuChannel::StreamState::HasRoutes() const { | 539 bool GpuChannel::StreamState::HasRoutes() const { |
| 545 return !routes_.empty(); | 540 return !routes_.empty(); |
| 546 } | 541 } |
| 547 | 542 |
| 548 GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager, | 543 GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager, |
| 549 GpuWatchdog* watchdog, | 544 GpuWatchdog* watchdog, |
| 550 gfx::GLShareGroup* share_group, | 545 gfx::GLShareGroup* share_group, |
| 551 gpu::gles2::MailboxManager* mailbox, | 546 gpu::gles2::MailboxManager* mailbox, |
| 547 gpu::PreemptionFlag* preempting_flag, | |
| 552 base::SingleThreadTaskRunner* task_runner, | 548 base::SingleThreadTaskRunner* task_runner, |
| 553 base::SingleThreadTaskRunner* io_task_runner, | 549 base::SingleThreadTaskRunner* io_task_runner, |
| 554 int client_id, | 550 int client_id, |
| 555 uint64_t client_tracing_id, | 551 uint64_t client_tracing_id, |
| 556 bool software, | |
| 557 bool allow_future_sync_points, | 552 bool allow_future_sync_points, |
| 558 bool allow_real_time_streams) | 553 bool allow_real_time_streams) |
| 559 : gpu_channel_manager_(gpu_channel_manager), | 554 : gpu_channel_manager_(gpu_channel_manager), |
| 560 channel_id_(IPC::Channel::GenerateVerifiedChannelID("gpu")), | 555 channel_id_(IPC::Channel::GenerateVerifiedChannelID("gpu")), |
| 556 preempting_flag_(preempting_flag), | |
| 561 client_id_(client_id), | 557 client_id_(client_id), |
| 562 client_tracing_id_(client_tracing_id), | 558 client_tracing_id_(client_tracing_id), |
| 563 task_runner_(task_runner), | 559 task_runner_(task_runner), |
| 564 io_task_runner_(io_task_runner), | 560 io_task_runner_(io_task_runner), |
| 565 share_group_(share_group ? share_group : new gfx::GLShareGroup), | 561 share_group_(share_group), |
| 566 mailbox_manager_(mailbox | 562 mailbox_manager_(mailbox), |
| 567 ? scoped_refptr<gpu::gles2::MailboxManager>(mailbox) | |
| 568 : gpu::gles2::MailboxManager::Create()), | |
| 569 subscription_ref_set_(new gpu::gles2::SubscriptionRefSet), | 563 subscription_ref_set_(new gpu::gles2::SubscriptionRefSet), |
| 570 pending_valuebuffer_state_(new gpu::ValueStateMap), | 564 pending_valuebuffer_state_(new gpu::ValueStateMap), |
| 571 watchdog_(watchdog), | 565 watchdog_(watchdog), |
| 572 software_(software), | |
| 573 num_stubs_descheduled_(0), | 566 num_stubs_descheduled_(0), |
| 574 allow_future_sync_points_(allow_future_sync_points), | 567 allow_future_sync_points_(allow_future_sync_points), |
| 575 allow_real_time_streams_(allow_real_time_streams), | 568 allow_real_time_streams_(allow_real_time_streams), |
| 576 weak_factory_(this) { | 569 weak_factory_(this) { |
| 577 DCHECK(gpu_channel_manager); | 570 DCHECK(gpu_channel_manager); |
| 578 DCHECK(client_id); | 571 DCHECK(client_id); |
| 579 | 572 |
| 580 message_queue_ = | 573 message_queue_ = |
| 581 GpuChannelMessageQueue::Create(weak_factory_.GetWeakPtr(), task_runner); | 574 GpuChannelMessageQueue::Create(weak_factory_.GetWeakPtr(), task_runner); |
| 582 | 575 |
| 583 filter_ = new GpuChannelMessageFilter( | 576 filter_ = new GpuChannelMessageFilter( |
| 584 weak_factory_.GetWeakPtr(), message_queue_.get(), | 577 weak_factory_.GetWeakPtr(), message_queue_.get(), |
| 585 gpu_channel_manager_->sync_point_manager(), task_runner_.get(), | 578 gpu_channel_manager_->sync_point_manager(), task_runner_.get(), |
| 586 allow_future_sync_points_); | 579 preempting_flag, allow_future_sync_points_); |
| 587 | 580 |
| 588 subscription_ref_set_->AddObserver(this); | 581 subscription_ref_set_->AddObserver(this); |
| 589 } | 582 } |
| 590 | 583 |
| 591 GpuChannel::~GpuChannel() { | 584 GpuChannel::~GpuChannel() { |
| 592 // Clear stubs first because of dependencies. | 585 // Clear stubs first because of dependencies. |
| 593 stubs_.clear(); | 586 stubs_.clear(); |
| 594 | 587 |
| 595 message_queue_->DeleteAndDisableMessages(gpu_channel_manager_); | 588 message_queue_->DeleteAndDisableMessages(gpu_channel_manager_); |
| 596 | 589 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 io_task_runner_->PostTask( | 680 io_task_runner_->PostTask( |
| 688 FROM_HERE, | 681 FROM_HERE, |
| 689 base::Bind(&GpuChannelMessageFilter::UpdateStubSchedulingState, | 682 base::Bind(&GpuChannelMessageFilter::UpdateStubSchedulingState, |
| 690 filter_, a_stub_is_descheduled)); | 683 filter_, a_stub_is_descheduled)); |
| 691 } | 684 } |
| 692 } | 685 } |
| 693 } | 686 } |
| 694 | 687 |
| 695 CreateCommandBufferResult GpuChannel::CreateViewCommandBuffer( | 688 CreateCommandBufferResult GpuChannel::CreateViewCommandBuffer( |
| 696 const gfx::GLSurfaceHandle& window, | 689 const gfx::GLSurfaceHandle& window, |
| 697 int32 surface_id, | |
| 698 const GPUCreateCommandBufferConfig& init_params, | 690 const GPUCreateCommandBufferConfig& init_params, |
| 699 int32 route_id) { | 691 int32 route_id) { |
| 700 TRACE_EVENT1("gpu", | 692 TRACE_EVENT1("gpu", "GpuChannel::CreateViewCommandBuffer", "route_id", |
| 701 "GpuChannel::CreateViewCommandBuffer", | 693 route_id); |
| 702 "surface_id", | |
| 703 surface_id); | |
| 704 | 694 |
| 705 int32 share_group_id = init_params.share_group_id; | 695 int32 share_group_id = init_params.share_group_id; |
| 706 GpuCommandBufferStub* share_group = stubs_.get(share_group_id); | 696 GpuCommandBufferStub* share_group = stubs_.get(share_group_id); |
| 707 | 697 |
| 708 if (!share_group && share_group_id != MSG_ROUTING_NONE) | 698 if (!share_group && share_group_id != MSG_ROUTING_NONE) |
| 709 return CREATE_COMMAND_BUFFER_FAILED; | 699 return CREATE_COMMAND_BUFFER_FAILED; |
| 710 | 700 |
| 711 int32 stream_id = init_params.stream_id; | 701 int32 stream_id = init_params.stream_id; |
| 712 GpuStreamPriority stream_priority = init_params.stream_priority; | 702 GpuStreamPriority stream_priority = init_params.stream_priority; |
| 713 | 703 |
| 714 if (share_group && stream_id != share_group->stream_id()) | 704 if (share_group && stream_id != share_group->stream_id()) |
| 715 return CREATE_COMMAND_BUFFER_FAILED; | 705 return CREATE_COMMAND_BUFFER_FAILED; |
| 716 | 706 |
| 717 if (!allow_real_time_streams_ && | 707 if (!allow_real_time_streams_ && |
| 718 stream_priority == GpuStreamPriority::REAL_TIME) | 708 stream_priority == GpuStreamPriority::REAL_TIME) |
| 719 return CREATE_COMMAND_BUFFER_FAILED; | 709 return CREATE_COMMAND_BUFFER_FAILED; |
| 720 | 710 |
| 721 auto stream_it = streams_.find(stream_id); | 711 auto stream_it = streams_.find(stream_id); |
| 722 if (stream_it != streams_.end() && | 712 if (stream_it != streams_.end() && |
| 723 stream_priority != GpuStreamPriority::INHERIT && | 713 stream_priority != GpuStreamPriority::INHERIT && |
| 724 stream_priority != stream_it->second.priority()) { | 714 stream_priority != stream_it->second.priority()) { |
| 725 return CREATE_COMMAND_BUFFER_FAILED; | 715 return CREATE_COMMAND_BUFFER_FAILED; |
| 726 } | 716 } |
| 727 | 717 |
| 718 bool offscreen = false; | |
| 728 scoped_ptr<GpuCommandBufferStub> stub(new GpuCommandBufferStub( | 719 scoped_ptr<GpuCommandBufferStub> stub(new GpuCommandBufferStub( |
| 729 this, task_runner_.get(), share_group, window, mailbox_manager_.get(), | 720 this, task_runner_.get(), share_group, window, mailbox_manager_.get(), |
| 730 subscription_ref_set_.get(), pending_valuebuffer_state_.get(), | 721 subscription_ref_set_.get(), pending_valuebuffer_state_.get(), |
| 731 gfx::Size(), disallowed_features_, init_params.attribs, | 722 gfx::Size(), disallowed_features_, init_params.attribs, |
| 732 init_params.gpu_preference, stream_id, route_id, surface_id, watchdog_, | 723 init_params.gpu_preference, stream_id, route_id, offscreen, watchdog_, |
| 733 software_, init_params.active_url)); | 724 init_params.active_url)); |
| 734 | 725 |
| 735 if (preempted_flag_.get()) | 726 if (preempted_flag_.get()) |
| 736 stub->SetPreemptByFlag(preempted_flag_); | 727 stub->SetPreemptByFlag(preempted_flag_); |
|
no sievers
2015/09/23 21:53:21
Can you remove this method from GpuCommandBufferSt
piman
2015/09/23 23:33:37
Done.
| |
| 737 | 728 |
| 738 if (!router_.AddRoute(route_id, stub.get())) { | 729 if (!router_.AddRoute(route_id, stub.get())) { |
| 739 DLOG(ERROR) << "GpuChannel::CreateViewCommandBuffer(): " | 730 DLOG(ERROR) << "GpuChannel::CreateViewCommandBuffer(): " |
| 740 "failed to add route"; | 731 "failed to add route"; |
| 741 return CREATE_COMMAND_BUFFER_FAILED_AND_CHANNEL_LOST; | 732 return CREATE_COMMAND_BUFFER_FAILED_AND_CHANNEL_LOST; |
| 742 } | 733 } |
| 743 | 734 |
| 744 if (stream_it != streams_.end()) { | 735 if (stream_it != streams_.end()) { |
| 745 stream_it->second.AddRoute(route_id); | 736 stream_it->second.AddRoute(route_id); |
| 746 } else { | 737 } else { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 767 } | 758 } |
| 768 | 759 |
| 769 bool GpuChannel::AddRoute(int32 route_id, IPC::Listener* listener) { | 760 bool GpuChannel::AddRoute(int32 route_id, IPC::Listener* listener) { |
| 770 return router_.AddRoute(route_id, listener); | 761 return router_.AddRoute(route_id, listener); |
| 771 } | 762 } |
| 772 | 763 |
| 773 void GpuChannel::RemoveRoute(int32 route_id) { | 764 void GpuChannel::RemoveRoute(int32 route_id) { |
| 774 router_.RemoveRoute(route_id); | 765 router_.RemoveRoute(route_id); |
| 775 } | 766 } |
| 776 | 767 |
| 777 gpu::PreemptionFlag* GpuChannel::GetPreemptionFlag() { | |
| 778 if (!preempting_flag_.get()) { | |
| 779 preempting_flag_ = new gpu::PreemptionFlag; | |
| 780 io_task_runner_->PostTask( | |
| 781 FROM_HERE, | |
| 782 base::Bind( | |
| 783 &GpuChannelMessageFilter::SetPreemptingFlagAndSchedulingState, | |
| 784 filter_, preempting_flag_, num_stubs_descheduled_ > 0)); | |
| 785 } | |
| 786 return preempting_flag_.get(); | |
| 787 } | |
| 788 | |
| 789 void GpuChannel::SetPreemptByFlag( | 768 void GpuChannel::SetPreemptByFlag( |
| 790 scoped_refptr<gpu::PreemptionFlag> preempted_flag) { | 769 scoped_refptr<gpu::PreemptionFlag> preempted_flag) { |
| 770 DCHECK(stubs_.empty()); | |
| 791 preempted_flag_ = preempted_flag; | 771 preempted_flag_ = preempted_flag; |
| 792 | |
| 793 for (auto& kv : stubs_) | |
| 794 kv.second->SetPreemptByFlag(preempted_flag_); | |
| 795 } | 772 } |
| 796 | 773 |
| 797 void GpuChannel::OnDestroy() { | 774 void GpuChannel::OnDestroy() { |
| 798 TRACE_EVENT0("gpu", "GpuChannel::OnDestroy"); | 775 TRACE_EVENT0("gpu", "GpuChannel::OnDestroy"); |
| 799 gpu_channel_manager_->RemoveChannel(client_id_); | 776 gpu_channel_manager_->RemoveChannel(client_id_); |
| 800 } | 777 } |
| 801 | 778 |
| 802 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { | 779 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { |
| 803 bool handled = true; | 780 bool handled = true; |
| 804 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) | 781 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 } | 929 } |
| 953 | 930 |
| 954 auto stream_it = streams_.find(stream_id); | 931 auto stream_it = streams_.find(stream_id); |
| 955 if (stream_it != streams_.end() && | 932 if (stream_it != streams_.end() && |
| 956 stream_priority != GpuStreamPriority::INHERIT && | 933 stream_priority != GpuStreamPriority::INHERIT && |
| 957 stream_priority != stream_it->second.priority()) { | 934 stream_priority != stream_it->second.priority()) { |
| 958 *succeeded = false; | 935 *succeeded = false; |
| 959 return; | 936 return; |
| 960 } | 937 } |
| 961 | 938 |
| 939 bool offscreen = true; | |
| 962 scoped_ptr<GpuCommandBufferStub> stub(new GpuCommandBufferStub( | 940 scoped_ptr<GpuCommandBufferStub> stub(new GpuCommandBufferStub( |
| 963 this, task_runner_.get(), share_group, gfx::GLSurfaceHandle(), | 941 this, task_runner_.get(), share_group, gfx::GLSurfaceHandle(), |
| 964 mailbox_manager_.get(), subscription_ref_set_.get(), | 942 mailbox_manager_.get(), subscription_ref_set_.get(), |
| 965 pending_valuebuffer_state_.get(), size, disallowed_features_, | 943 pending_valuebuffer_state_.get(), size, disallowed_features_, |
| 966 init_params.attribs, init_params.gpu_preference, init_params.stream_id, | 944 init_params.attribs, init_params.gpu_preference, init_params.stream_id, |
| 967 route_id, 0, watchdog_, software_, init_params.active_url)); | 945 route_id, offscreen, watchdog_, init_params.active_url)); |
| 968 | 946 |
| 969 if (preempted_flag_.get()) | 947 if (preempted_flag_.get()) |
| 970 stub->SetPreemptByFlag(preempted_flag_); | 948 stub->SetPreemptByFlag(preempted_flag_); |
| 971 | 949 |
| 972 if (!router_.AddRoute(route_id, stub.get())) { | 950 if (!router_.AddRoute(route_id, stub.get())) { |
| 973 DLOG(ERROR) << "GpuChannel::OnCreateOffscreenCommandBuffer(): " | 951 DLOG(ERROR) << "GpuChannel::OnCreateOffscreenCommandBuffer(): " |
| 974 "failed to add route"; | 952 "failed to add route"; |
| 975 *succeeded = false; | 953 *succeeded = false; |
| 976 return; | 954 return; |
| 977 } | 955 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1084 } | 1062 } |
| 1085 } | 1063 } |
| 1086 } | 1064 } |
| 1087 | 1065 |
| 1088 void GpuChannel::HandleUpdateValueState( | 1066 void GpuChannel::HandleUpdateValueState( |
| 1089 unsigned int target, const gpu::ValueState& state) { | 1067 unsigned int target, const gpu::ValueState& state) { |
| 1090 pending_valuebuffer_state_->UpdateState(target, state); | 1068 pending_valuebuffer_state_->UpdateState(target, state); |
| 1091 } | 1069 } |
| 1092 | 1070 |
| 1093 } // namespace content | 1071 } // namespace content |
| OLD | NEW |