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

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

Issue 1365563002: Make channel preemption not require view contexts for hookup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wakeup_gpu
Patch Set: rebase Created 5 years, 2 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
« no previous file with comments | « content/common/gpu/gpu_channel.h ('k') | content/common/gpu/gpu_channel_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
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); 243 timer_ = make_scoped_ptr(new base::OneShotTimer);
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
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
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
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 preempted_flag_.get(), subscription_ref_set_.get(),
731 gfx::Size(), disallowed_features_, init_params.attribs, 722 pending_valuebuffer_state_.get(), gfx::Size(), disallowed_features_,
732 init_params.gpu_preference, stream_id, route_id, surface_id, watchdog_, 723 init_params.attribs, init_params.gpu_preference, stream_id, route_id,
733 software_, init_params.active_url)); 724 offscreen, watchdog_, init_params.active_url));
734
735 if (preempted_flag_.get())
736 stub->SetPreemptByFlag(preempted_flag_);
737 725
738 if (!router_.AddRoute(route_id, stub.get())) { 726 if (!router_.AddRoute(route_id, stub.get())) {
739 DLOG(ERROR) << "GpuChannel::CreateViewCommandBuffer(): " 727 DLOG(ERROR) << "GpuChannel::CreateViewCommandBuffer(): "
740 "failed to add route"; 728 "failed to add route";
741 return CREATE_COMMAND_BUFFER_FAILED_AND_CHANNEL_LOST; 729 return CREATE_COMMAND_BUFFER_FAILED_AND_CHANNEL_LOST;
742 } 730 }
743 731
744 if (stream_it != streams_.end()) { 732 if (stream_it != streams_.end()) {
745 stream_it->second.AddRoute(route_id); 733 stream_it->second.AddRoute(route_id);
746 } else { 734 } else {
(...skipping 20 matching lines...) Expand all
767 } 755 }
768 756
769 bool GpuChannel::AddRoute(int32 route_id, IPC::Listener* listener) { 757 bool GpuChannel::AddRoute(int32 route_id, IPC::Listener* listener) {
770 return router_.AddRoute(route_id, listener); 758 return router_.AddRoute(route_id, listener);
771 } 759 }
772 760
773 void GpuChannel::RemoveRoute(int32 route_id) { 761 void GpuChannel::RemoveRoute(int32 route_id) {
774 router_.RemoveRoute(route_id); 762 router_.RemoveRoute(route_id);
775 } 763 }
776 764
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( 765 void GpuChannel::SetPreemptByFlag(
790 scoped_refptr<gpu::PreemptionFlag> preempted_flag) { 766 scoped_refptr<gpu::PreemptionFlag> preempted_flag) {
767 DCHECK(stubs_.empty());
791 preempted_flag_ = preempted_flag; 768 preempted_flag_ = preempted_flag;
792
793 for (auto& kv : stubs_)
794 kv.second->SetPreemptByFlag(preempted_flag_);
795 } 769 }
796 770
797 void GpuChannel::OnDestroy() { 771 void GpuChannel::OnDestroy() {
798 TRACE_EVENT0("gpu", "GpuChannel::OnDestroy"); 772 TRACE_EVENT0("gpu", "GpuChannel::OnDestroy");
799 gpu_channel_manager_->RemoveChannel(client_id_); 773 gpu_channel_manager_->RemoveChannel(client_id_);
800 } 774 }
801 775
802 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { 776 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) {
803 bool handled = true; 777 bool handled = true;
804 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) 778 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 } 926 }
953 927
954 auto stream_it = streams_.find(stream_id); 928 auto stream_it = streams_.find(stream_id);
955 if (stream_it != streams_.end() && 929 if (stream_it != streams_.end() &&
956 stream_priority != GpuStreamPriority::INHERIT && 930 stream_priority != GpuStreamPriority::INHERIT &&
957 stream_priority != stream_it->second.priority()) { 931 stream_priority != stream_it->second.priority()) {
958 *succeeded = false; 932 *succeeded = false;
959 return; 933 return;
960 } 934 }
961 935
936 bool offscreen = true;
962 scoped_ptr<GpuCommandBufferStub> stub(new GpuCommandBufferStub( 937 scoped_ptr<GpuCommandBufferStub> stub(new GpuCommandBufferStub(
963 this, task_runner_.get(), share_group, gfx::GLSurfaceHandle(), 938 this, task_runner_.get(), share_group, gfx::GLSurfaceHandle(),
964 mailbox_manager_.get(), subscription_ref_set_.get(), 939 mailbox_manager_.get(), preempted_flag_.get(),
965 pending_valuebuffer_state_.get(), size, disallowed_features_, 940 subscription_ref_set_.get(), pending_valuebuffer_state_.get(), size,
966 init_params.attribs, init_params.gpu_preference, init_params.stream_id, 941 disallowed_features_, init_params.attribs, init_params.gpu_preference,
967 route_id, 0, watchdog_, software_, init_params.active_url)); 942 init_params.stream_id, route_id, offscreen, watchdog_,
968 943 init_params.active_url));
969 if (preempted_flag_.get())
970 stub->SetPreemptByFlag(preempted_flag_);
971 944
972 if (!router_.AddRoute(route_id, stub.get())) { 945 if (!router_.AddRoute(route_id, stub.get())) {
973 DLOG(ERROR) << "GpuChannel::OnCreateOffscreenCommandBuffer(): " 946 DLOG(ERROR) << "GpuChannel::OnCreateOffscreenCommandBuffer(): "
974 "failed to add route"; 947 "failed to add route";
975 *succeeded = false; 948 *succeeded = false;
976 return; 949 return;
977 } 950 }
978 951
979 if (stream_it != streams_.end()) { 952 if (stream_it != streams_.end()) {
980 stream_it->second.AddRoute(route_id); 953 stream_it->second.AddRoute(route_id);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 } 1057 }
1085 } 1058 }
1086 } 1059 }
1087 1060
1088 void GpuChannel::HandleUpdateValueState( 1061 void GpuChannel::HandleUpdateValueState(
1089 unsigned int target, const gpu::ValueState& state) { 1062 unsigned int target, const gpu::ValueState& state) {
1090 pending_valuebuffer_state_->UpdateState(target, state); 1063 pending_valuebuffer_state_->UpdateState(target, state);
1091 } 1064 }
1092 1065
1093 } // namespace content 1066 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_channel.h ('k') | content/common/gpu/gpu_channel_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698