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

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

Issue 495313003: Let GpuChannel handle deferred IPC messages of SwapBuffer in batch (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 6 years, 4 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') | no next file » | 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 #if defined(OS_WIN) 5 #if defined(OS_WIN)
6 #include <windows.h> 6 #include <windows.h>
7 #endif 7 #endif
8 8
9 #include "content/common/gpu/gpu_channel.h" 9 #include "content/common/gpu/gpu_channel.h"
10 10
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 IPC_MESSAGE_HANDLER(GpuChannelMsg_DevToolsStartEventsRecording, 655 IPC_MESSAGE_HANDLER(GpuChannelMsg_DevToolsStartEventsRecording,
656 OnDevToolsStartEventsRecording) 656 OnDevToolsStartEventsRecording)
657 IPC_MESSAGE_HANDLER(GpuChannelMsg_DevToolsStopEventsRecording, 657 IPC_MESSAGE_HANDLER(GpuChannelMsg_DevToolsStopEventsRecording,
658 OnDevToolsStopEventsRecording) 658 OnDevToolsStopEventsRecording)
659 IPC_MESSAGE_UNHANDLED(handled = false) 659 IPC_MESSAGE_UNHANDLED(handled = false)
660 IPC_END_MESSAGE_MAP() 660 IPC_END_MESSAGE_MAP()
661 DCHECK(handled) << msg.type(); 661 DCHECK(handled) << msg.type();
662 return handled; 662 return handled;
663 } 663 }
664 664
665 size_t GpuChannel::MatchSwapBufferMessagesPattern(
666 IPC::Message* current_message) {
667 DCHECK(current_message);
668 if (deferred_messages_.empty() || !current_message)
669 return 0;
670 // Only care about SetLatencyInfo and AsyncFlush message.
671 if (current_message->type() != GpuCommandBufferMsg_SetLatencyInfo::ID &&
672 current_message->type() != GpuCommandBufferMsg_AsyncFlush::ID)
673 return 0;
674
675 size_t index = 0;
676 int32 routing_id = current_message->routing_id();
677
678 // In case of the current message is SetLatencyInfo, we try to look ahead one
679 // more deferred messages.
680 IPC::Message *first_message = NULL;
681 IPC::Message *second_message = NULL;
682
683 // Fetch the first message and move index to point to the second message.
684 first_message = deferred_messages_[index++];
685
686 // If the current message is AsyncFlush, the expected message sequence for
687 // SwapBuffer should be AsyncFlush->Echo. We only try to match Echo message.
688 if (current_message->type() == GpuCommandBufferMsg_AsyncFlush::ID &&
689 first_message->type() == GpuCommandBufferMsg_Echo::ID &&
690 first_message->routing_id() == routing_id) {
691 return 1;
692 }
693
694 // If the current message is SetLatencyInfo, the expected message sequence
695 // for SwapBuffer should be SetLatencyInfo->AsyncFlush->Echo (optional).
696 if (current_message->type() == GpuCommandBufferMsg_SetLatencyInfo::ID &&
697 first_message->type() == GpuCommandBufferMsg_AsyncFlush::ID &&
698 first_message->routing_id() == routing_id) {
699 if (deferred_messages_.size() >= 2)
700 second_message = deferred_messages_[index];
701 if (!second_message)
702 return 1;
703 if (second_message->type() == GpuCommandBufferMsg_Echo::ID &&
704 second_message->routing_id() == routing_id) {
705 return 2;
706 }
707 }
708 // No matched message is found.
709 return 0;
710 }
711
665 void GpuChannel::HandleMessage() { 712 void GpuChannel::HandleMessage() {
666 handle_messages_scheduled_ = false; 713 handle_messages_scheduled_ = false;
667 if (deferred_messages_.empty()) 714 if (deferred_messages_.empty())
668 return; 715 return;
669 716
670 bool should_fast_track_ack = false; 717 size_t matched_messages_num = 0;
718 bool should_handle_swapbuffer_msgs_immediate = false;
671 IPC::Message* m = deferred_messages_.front(); 719 IPC::Message* m = deferred_messages_.front();
672 GpuCommandBufferStub* stub = stubs_.Lookup(m->routing_id()); 720 GpuCommandBufferStub* stub = stubs_.Lookup(m->routing_id());
673 721
674 do { 722 do {
675 if (stub) { 723 if (stub) {
676 if (!stub->IsScheduled()) 724 if (!stub->IsScheduled())
677 return; 725 return;
678 if (stub->IsPreempted()) { 726 if (stub->IsPreempted()) {
679 OnScheduled(); 727 OnScheduled();
680 return; 728 return;
(...skipping 27 matching lines...) Expand all
708 if (stub->HasUnprocessedCommands()) { 756 if (stub->HasUnprocessedCommands()) {
709 deferred_messages_.push_front(new GpuCommandBufferMsg_Rescheduled( 757 deferred_messages_.push_front(new GpuCommandBufferMsg_Rescheduled(
710 stub->route_id())); 758 stub->route_id()));
711 message_processed = false; 759 message_processed = false;
712 } 760 }
713 } 761 }
714 } 762 }
715 if (message_processed) 763 if (message_processed)
716 MessageProcessed(); 764 MessageProcessed();
717 765
718 // We want the EchoACK following the SwapBuffers to be sent as close as 766 if (deferred_messages_.empty())
719 // possible, avoiding scheduling other channels in the meantime. 767 break;
720 should_fast_track_ack = false; 768
721 if (!deferred_messages_.empty()) { 769 // We process the pending messages immediately if these messages matches
722 m = deferred_messages_.front(); 770 // the pattern of SwapBuffers, for example, GLRenderer always issues
723 stub = stubs_.Lookup(m->routing_id()); 771 // SwapBuffers calls with a specifix IPC message patterns, for example,
Ken Russell (switch to Gerrit) 2014/08/25 23:03:03 typo: specific. Here and in CL description.
Hongbo Min 2014/08/26 11:37:00 Done.
724 should_fast_track_ack = 772 // it should be SetLatencyInfo->AsyncFlush->Echo sequence.
725 (m->type() == GpuCommandBufferMsg_Echo::ID) && 773 //
726 stub && stub->IsScheduled(); 774 // Instead of posting a task to message loop, it could avoid the possibility
775 // of being blocked by other channels, and make SwapBuffers executed as soon
776 // as possible.
777 m = deferred_messages_.front();
jbauman 2014/08/26 00:00:43 I think you could move these two lines to the begi
Hongbo Min 2014/08/26 11:37:00 Done.
778 stub = stubs_.Lookup(m->routing_id());
779 if (!should_handle_swapbuffer_msgs_immediate) {
780 // Start from the current processing message to match SwapBuffer pattern.
781 matched_messages_num = MatchSwapBufferMessagesPattern(message.get());
782 should_handle_swapbuffer_msgs_immediate =
783 matched_messages_num > 0 && stub && stub->IsScheduled();
784 } else {
785 --matched_messages_num;
Ken Russell (switch to Gerrit) 2014/08/25 23:03:03 Before this line, please DCHECK(matched_messages_n
Hongbo Min 2014/08/26 11:37:00 Done.
786 if (!stub || !stub->IsScheduled() || matched_messages_num == 0)
787 should_handle_swapbuffer_msgs_immediate = false;
727 } 788 }
728 } while (should_fast_track_ack); 789 } while (should_handle_swapbuffer_msgs_immediate);
729 790
730 if (!deferred_messages_.empty()) { 791 if (!deferred_messages_.empty()) {
731 OnScheduled(); 792 OnScheduled();
732 } 793 }
733 } 794 }
734 795
735 void GpuChannel::OnCreateOffscreenCommandBuffer( 796 void GpuChannel::OnCreateOffscreenCommandBuffer(
736 const gfx::Size& size, 797 const gfx::Size& size,
737 const GPUCreateCommandBufferConfig& init_params, 798 const GPUCreateCommandBufferConfig& init_params,
738 int32 route_id, 799 int32 route_id,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 uint64 GpuChannel::GetMemoryUsage() { 885 uint64 GpuChannel::GetMemoryUsage() {
825 uint64 size = 0; 886 uint64 size = 0;
826 for (StubMap::Iterator<GpuCommandBufferStub> it(&stubs_); 887 for (StubMap::Iterator<GpuCommandBufferStub> it(&stubs_);
827 !it.IsAtEnd(); it.Advance()) { 888 !it.IsAtEnd(); it.Advance()) {
828 size += it.GetCurrentValue()->GetMemoryUsage(); 889 size += it.GetCurrentValue()->GetMemoryUsage();
829 } 890 }
830 return size; 891 return size;
831 } 892 }
832 893
833 } // namespace content 894 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_channel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698