| 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 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "base/thread_task_runner_handle.h" | 27 #include "base/thread_task_runner_handle.h" |
| 28 #include "base/timer/timer.h" | 28 #include "base/timer/timer.h" |
| 29 #include "base/trace_event/memory_dump_manager.h" | 29 #include "base/trace_event/memory_dump_manager.h" |
| 30 #include "base/trace_event/process_memory_dump.h" | 30 #include "base/trace_event/process_memory_dump.h" |
| 31 #include "base/trace_event/trace_event.h" | 31 #include "base/trace_event/trace_event.h" |
| 32 #include "build/build_config.h" | 32 #include "build/build_config.h" |
| 33 #include "content/common/gpu/gpu_channel_manager.h" | 33 #include "content/common/gpu/gpu_channel_manager.h" |
| 34 #include "content/common/gpu/gpu_channel_manager_delegate.h" | 34 #include "content/common/gpu/gpu_channel_manager_delegate.h" |
| 35 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 35 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
| 36 #include "content/common/gpu/gpu_messages.h" | 36 #include "content/common/gpu/gpu_messages.h" |
| 37 #include "content/common/gpu/media/gpu_jpeg_decode_accelerator.h" |
| 37 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
| 38 #include "gpu/command_buffer/common/mailbox.h" | 39 #include "gpu/command_buffer/common/mailbox.h" |
| 39 #include "gpu/command_buffer/common/value_state.h" | 40 #include "gpu/command_buffer/common/value_state.h" |
| 40 #include "gpu/command_buffer/service/gpu_scheduler.h" | 41 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 41 #include "gpu/command_buffer/service/image_factory.h" | 42 #include "gpu/command_buffer/service/image_factory.h" |
| 42 #include "gpu/command_buffer/service/mailbox_manager.h" | 43 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 43 #include "gpu/command_buffer/service/sync_point_manager.h" | 44 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 44 #include "gpu/command_buffer/service/valuebuffer_manager.h" | 45 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
| 45 #include "ipc/ipc_channel.h" | 46 #include "ipc/ipc_channel.h" |
| 46 #include "ipc/message_filter.h" | 47 #include "ipc/message_filter.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 65 const int64_t kPreemptWaitTimeMs = 2 * kVsyncIntervalMs; | 66 const int64_t kPreemptWaitTimeMs = 2 * kVsyncIntervalMs; |
| 66 | 67 |
| 67 // Once we trigger a preemption, the maximum duration that we will wait | 68 // Once we trigger a preemption, the maximum duration that we will wait |
| 68 // before clearing the preemption. | 69 // before clearing the preemption. |
| 69 const int64_t kMaxPreemptTimeMs = kVsyncIntervalMs; | 70 const int64_t kMaxPreemptTimeMs = kVsyncIntervalMs; |
| 70 | 71 |
| 71 // Stop the preemption once the time for the longest pending IPC drops | 72 // Stop the preemption once the time for the longest pending IPC drops |
| 72 // below this threshold. | 73 // below this threshold. |
| 73 const int64_t kStopPreemptThresholdMs = kVsyncIntervalMs; | 74 const int64_t kStopPreemptThresholdMs = kVsyncIntervalMs; |
| 74 | 75 |
| 76 void SendCreateJpegDecoderResult( |
| 77 scoped_ptr<IPC::Message> reply_message, |
| 78 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 79 base::WeakPtr<GpuChannel> channel, |
| 80 scoped_refptr<GpuChannelMessageFilter> filter, |
| 81 bool result) { |
| 82 GpuChannelMsg_CreateJpegDecoder::WriteReplyParams(reply_message.get(), |
| 83 result); |
| 84 if (io_task_runner->BelongsToCurrentThread()) { |
| 85 filter->Send(reply_message.release()); |
| 86 } else { |
| 87 channel->Send(reply_message.release()); |
| 88 } |
| 89 } |
| 90 |
| 75 } // anonymous namespace | 91 } // anonymous namespace |
| 76 | 92 |
| 77 scoped_refptr<GpuChannelMessageQueue> GpuChannelMessageQueue::Create( | 93 scoped_refptr<GpuChannelMessageQueue> GpuChannelMessageQueue::Create( |
| 78 int32_t stream_id, | 94 int32_t stream_id, |
| 79 GpuStreamPriority stream_priority, | 95 GpuStreamPriority stream_priority, |
| 80 GpuChannel* channel, | 96 GpuChannel* channel, |
| 81 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 97 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 82 const scoped_refptr<gpu::PreemptionFlag>& preempting_flag, | 98 const scoped_refptr<gpu::PreemptionFlag>& preempting_flag, |
| 83 const scoped_refptr<gpu::PreemptionFlag>& preempted_flag, | 99 const scoped_refptr<gpu::PreemptionFlag>& preempted_flag, |
| 84 gpu::SyncPointManager* sync_point_manager) { | 100 gpu::SyncPointManager* sync_point_manager) { |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 gpu::PreemptionFlag* preempting_flag, | 598 gpu::PreemptionFlag* preempting_flag, |
| 583 gpu::PreemptionFlag* preempted_flag, | 599 gpu::PreemptionFlag* preempted_flag, |
| 584 base::SingleThreadTaskRunner* task_runner, | 600 base::SingleThreadTaskRunner* task_runner, |
| 585 base::SingleThreadTaskRunner* io_task_runner, | 601 base::SingleThreadTaskRunner* io_task_runner, |
| 586 int32_t client_id, | 602 int32_t client_id, |
| 587 uint64_t client_tracing_id, | 603 uint64_t client_tracing_id, |
| 588 bool allow_view_command_buffers, | 604 bool allow_view_command_buffers, |
| 589 bool allow_real_time_streams) | 605 bool allow_real_time_streams) |
| 590 : gpu_channel_manager_(gpu_channel_manager), | 606 : gpu_channel_manager_(gpu_channel_manager), |
| 591 sync_point_manager_(sync_point_manager), | 607 sync_point_manager_(sync_point_manager), |
| 592 unhandled_message_listener_(nullptr), | |
| 593 channel_id_(IPC::Channel::GenerateVerifiedChannelID("gpu")), | 608 channel_id_(IPC::Channel::GenerateVerifiedChannelID("gpu")), |
| 594 preempting_flag_(preempting_flag), | 609 preempting_flag_(preempting_flag), |
| 595 preempted_flag_(preempted_flag), | 610 preempted_flag_(preempted_flag), |
| 596 client_id_(client_id), | 611 client_id_(client_id), |
| 597 client_tracing_id_(client_tracing_id), | 612 client_tracing_id_(client_tracing_id), |
| 598 task_runner_(task_runner), | 613 task_runner_(task_runner), |
| 599 io_task_runner_(io_task_runner), | 614 io_task_runner_(io_task_runner), |
| 600 share_group_(share_group), | 615 share_group_(share_group), |
| 601 mailbox_manager_(mailbox), | 616 mailbox_manager_(mailbox), |
| 602 subscription_ref_set_(new gpu::gles2::SubscriptionRefSet), | 617 subscription_ref_set_(new gpu::gles2::SubscriptionRefSet), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 base::ScopedFD renderer_fd = channel_->TakeClientFileDescriptor(); | 660 base::ScopedFD renderer_fd = channel_->TakeClientFileDescriptor(); |
| 646 DCHECK(renderer_fd.is_valid()); | 661 DCHECK(renderer_fd.is_valid()); |
| 647 channel_handle.socket = base::FileDescriptor(std::move(renderer_fd)); | 662 channel_handle.socket = base::FileDescriptor(std::move(renderer_fd)); |
| 648 #endif | 663 #endif |
| 649 | 664 |
| 650 channel_->AddFilter(filter_.get()); | 665 channel_->AddFilter(filter_.get()); |
| 651 | 666 |
| 652 return channel_handle; | 667 return channel_handle; |
| 653 } | 668 } |
| 654 | 669 |
| 655 void GpuChannel::SetUnhandledMessageListener(IPC::Listener* listener) { | |
| 656 unhandled_message_listener_ = listener; | |
| 657 } | |
| 658 | |
| 659 base::WeakPtr<GpuChannel> GpuChannel::AsWeakPtr() { | |
| 660 return weak_factory_.GetWeakPtr(); | |
| 661 } | |
| 662 | |
| 663 base::ProcessId GpuChannel::GetClientPID() const { | 670 base::ProcessId GpuChannel::GetClientPID() const { |
| 664 return channel_->GetPeerPID(); | 671 return channel_->GetPeerPID(); |
| 665 } | 672 } |
| 666 | 673 |
| 667 uint32_t GpuChannel::GetProcessedOrderNum() const { | 674 uint32_t GpuChannel::GetProcessedOrderNum() const { |
| 668 uint32_t processed_order_num = 0; | 675 uint32_t processed_order_num = 0; |
| 669 for (auto& kv : streams_) { | 676 for (auto& kv : streams_) { |
| 670 processed_order_num = | 677 processed_order_num = |
| 671 std::max(processed_order_num, kv.second->GetProcessedOrderNum()); | 678 std::max(processed_order_num, kv.second->GetProcessedOrderNum()); |
| 672 } | 679 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 759 |
| 753 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { | 760 bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { |
| 754 bool handled = true; | 761 bool handled = true; |
| 755 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) | 762 IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg) |
| 756 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateViewCommandBuffer, | 763 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateViewCommandBuffer, |
| 757 OnCreateViewCommandBuffer) | 764 OnCreateViewCommandBuffer) |
| 758 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer, | 765 IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer, |
| 759 OnCreateOffscreenCommandBuffer) | 766 OnCreateOffscreenCommandBuffer) |
| 760 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, | 767 IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, |
| 761 OnDestroyCommandBuffer) | 768 OnDestroyCommandBuffer) |
| 769 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuChannelMsg_CreateJpegDecoder, |
| 770 OnCreateJpegDecoder) |
| 762 IPC_MESSAGE_UNHANDLED(handled = false) | 771 IPC_MESSAGE_UNHANDLED(handled = false) |
| 763 IPC_END_MESSAGE_MAP() | 772 IPC_END_MESSAGE_MAP() |
| 773 DCHECK(handled) << msg.type(); |
| 764 return handled; | 774 return handled; |
| 765 } | 775 } |
| 766 | 776 |
| 767 scoped_refptr<gpu::SyncPointOrderData> GpuChannel::GetSyncPointOrderData( | 777 scoped_refptr<gpu::SyncPointOrderData> GpuChannel::GetSyncPointOrderData( |
| 768 int32_t stream_id) { | 778 int32_t stream_id) { |
| 769 auto it = streams_.find(stream_id); | 779 auto it = streams_.find(stream_id); |
| 770 DCHECK(it != streams_.end()); | 780 DCHECK(it != streams_.end()); |
| 771 DCHECK(it->second); | 781 DCHECK(it->second); |
| 772 return it->second->GetSyncPointOrderData(); | 782 return it->second->GetSyncPointOrderData(); |
| 773 } | 783 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 void GpuChannel::HandleMessageHelper(const IPC::Message& msg) { | 825 void GpuChannel::HandleMessageHelper(const IPC::Message& msg) { |
| 816 int32_t routing_id = msg.routing_id(); | 826 int32_t routing_id = msg.routing_id(); |
| 817 | 827 |
| 818 bool handled = false; | 828 bool handled = false; |
| 819 if (routing_id == MSG_ROUTING_CONTROL) { | 829 if (routing_id == MSG_ROUTING_CONTROL) { |
| 820 handled = OnControlMessageReceived(msg); | 830 handled = OnControlMessageReceived(msg); |
| 821 } else { | 831 } else { |
| 822 handled = router_.RouteMessage(msg); | 832 handled = router_.RouteMessage(msg); |
| 823 } | 833 } |
| 824 | 834 |
| 825 if (!handled && unhandled_message_listener_) | |
| 826 handled = unhandled_message_listener_->OnMessageReceived(msg); | |
| 827 | |
| 828 // Respond to sync messages even if router failed to route. | 835 // Respond to sync messages even if router failed to route. |
| 829 if (!handled && msg.is_sync()) { | 836 if (!handled && msg.is_sync()) { |
| 830 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | 837 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); |
| 831 reply->set_reply_error(); | 838 reply->set_reply_error(); |
| 832 Send(reply); | 839 Send(reply); |
| 833 } | 840 } |
| 834 } | 841 } |
| 835 | 842 |
| 836 void GpuChannel::HandleOutOfOrderMessage(const IPC::Message& msg) { | 843 void GpuChannel::HandleOutOfOrderMessage(const IPC::Message& msg) { |
| 837 HandleMessageHelper(msg); | 844 HandleMessageHelper(msg); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 // In case the renderer is currently blocked waiting for a sync reply from the | 992 // In case the renderer is currently blocked waiting for a sync reply from the |
| 986 // stub, we need to make sure to reschedule the correct stream here. | 993 // stub, we need to make sure to reschedule the correct stream here. |
| 987 if (stub && !stub->IsScheduled()) { | 994 if (stub && !stub->IsScheduled()) { |
| 988 // This stub won't get a chance to reschedule the stream so do that now. | 995 // This stub won't get a chance to reschedule the stream so do that now. |
| 989 OnStreamRescheduled(stub->stream_id(), true); | 996 OnStreamRescheduled(stub->stream_id(), true); |
| 990 } | 997 } |
| 991 | 998 |
| 992 RemoveRoute(route_id); | 999 RemoveRoute(route_id); |
| 993 } | 1000 } |
| 994 | 1001 |
| 1002 void GpuChannel::OnCreateJpegDecoder(int32_t route_id, |
| 1003 IPC::Message* reply_msg) { |
| 1004 scoped_ptr<IPC::Message> msg(reply_msg); |
| 1005 if (!jpeg_decoder_) { |
| 1006 jpeg_decoder_.reset(new GpuJpegDecodeAccelerator(this, io_task_runner_)); |
| 1007 } |
| 1008 jpeg_decoder_->AddClient( |
| 1009 route_id, |
| 1010 base::Bind(&SendCreateJpegDecoderResult, base::Passed(&msg), |
| 1011 io_task_runner_, weak_factory_.GetWeakPtr(), filter_)); |
| 1012 } |
| 1013 |
| 995 void GpuChannel::CacheShader(const std::string& key, | 1014 void GpuChannel::CacheShader(const std::string& key, |
| 996 const std::string& shader) { | 1015 const std::string& shader) { |
| 997 gpu_channel_manager_->delegate()->StoreShaderToDisk(client_id_, key, shader); | 1016 gpu_channel_manager_->delegate()->StoreShaderToDisk(client_id_, key, shader); |
| 998 } | 1017 } |
| 999 | 1018 |
| 1000 void GpuChannel::AddFilter(IPC::MessageFilter* filter) { | 1019 void GpuChannel::AddFilter(IPC::MessageFilter* filter) { |
| 1001 io_task_runner_->PostTask( | 1020 io_task_runner_->PostTask( |
| 1002 FROM_HERE, base::Bind(&GpuChannelMessageFilter::AddChannelFilter, | 1021 FROM_HERE, base::Bind(&GpuChannelMessageFilter::AddChannelFilter, |
| 1003 filter_, make_scoped_refptr(filter))); | 1022 filter_, make_scoped_refptr(filter))); |
| 1004 } | 1023 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 } | 1077 } |
| 1059 } | 1078 } |
| 1060 } | 1079 } |
| 1061 | 1080 |
| 1062 void GpuChannel::HandleUpdateValueState( | 1081 void GpuChannel::HandleUpdateValueState( |
| 1063 unsigned int target, const gpu::ValueState& state) { | 1082 unsigned int target, const gpu::ValueState& state) { |
| 1064 pending_valuebuffer_state_->UpdateState(target, state); | 1083 pending_valuebuffer_state_->UpdateState(target, state); |
| 1065 } | 1084 } |
| 1066 | 1085 |
| 1067 } // namespace content | 1086 } // namespace content |
| OLD | NEW |