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 #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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( | 665 size_t GpuChannel::MatchSwapBufferMessagesPattern( |
666 IPC::Message* current_message) { | 666 IPC::Message* current_message) { |
667 DCHECK(current_message); | 667 DCHECK(current_message); |
668 if (deferred_messages_.empty() || !current_message) | 668 if (deferred_messages_.empty() || !current_message) |
669 return 0; | 669 return 0; |
670 // Only care about SetLatencyInfo and AsyncFlush message. | 670 // Only care about AsyncFlush message. |
671 if (current_message->type() != GpuCommandBufferMsg_SetLatencyInfo::ID && | 671 if (current_message->type() != GpuCommandBufferMsg_AsyncFlush::ID) |
672 current_message->type() != GpuCommandBufferMsg_AsyncFlush::ID) | |
673 return 0; | 672 return 0; |
674 | 673 |
675 size_t index = 0; | 674 size_t index = 0; |
676 int32 routing_id = current_message->routing_id(); | 675 int32 routing_id = current_message->routing_id(); |
677 | 676 |
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. | 677 // Fetch the first message and move index to point to the second message. |
684 first_message = deferred_messages_[index++]; | 678 IPC::Message* first_message = deferred_messages_[index++]; |
685 | 679 |
686 // If the current message is AsyncFlush, the expected message sequence for | 680 // If the current message is AsyncFlush, the expected message sequence for |
687 // SwapBuffer should be AsyncFlush->Echo. We only try to match Echo message. | 681 // SwapBuffer should be AsyncFlush->Echo. We only try to match Echo message. |
688 if (current_message->type() == GpuCommandBufferMsg_AsyncFlush::ID && | 682 if (current_message->type() == GpuCommandBufferMsg_AsyncFlush::ID && |
689 first_message->type() == GpuCommandBufferMsg_Echo::ID && | 683 first_message->type() == GpuCommandBufferMsg_Echo::ID && |
690 first_message->routing_id() == routing_id) { | 684 first_message->routing_id() == routing_id) { |
691 return 1; | 685 return 1; |
692 } | 686 } |
693 | 687 |
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. | 688 // No matched message is found. |
709 return 0; | 689 return 0; |
710 } | 690 } |
711 | 691 |
712 void GpuChannel::HandleMessage() { | 692 void GpuChannel::HandleMessage() { |
713 handle_messages_scheduled_ = false; | 693 handle_messages_scheduled_ = false; |
714 if (deferred_messages_.empty()) | 694 if (deferred_messages_.empty()) |
715 return; | 695 return; |
716 | 696 |
717 size_t matched_messages_num = 0; | 697 size_t matched_messages_num = 0; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 } | 744 } |
765 if (message_processed) | 745 if (message_processed) |
766 MessageProcessed(); | 746 MessageProcessed(); |
767 | 747 |
768 if (deferred_messages_.empty()) | 748 if (deferred_messages_.empty()) |
769 break; | 749 break; |
770 | 750 |
771 // We process the pending messages immediately if these messages matches | 751 // We process the pending messages immediately if these messages matches |
772 // the pattern of SwapBuffers, for example, GLRenderer always issues | 752 // the pattern of SwapBuffers, for example, GLRenderer always issues |
773 // SwapBuffers calls with a specific IPC message patterns, for example, | 753 // SwapBuffers calls with a specific IPC message patterns, for example, |
774 // it should be SetLatencyInfo->AsyncFlush->Echo sequence. | 754 // it should be AsyncFlush->Echo sequence. |
775 // | 755 // |
776 // Instead of posting a task to message loop, it could avoid the possibility | 756 // Instead of posting a task to message loop, it could avoid the possibility |
777 // of being blocked by other channels, and make SwapBuffers executed as soon | 757 // of being blocked by other channels, and make SwapBuffers executed as soon |
778 // as possible. | 758 // as possible. |
779 if (!should_handle_swapbuffer_msgs_immediate) { | 759 if (!should_handle_swapbuffer_msgs_immediate) { |
780 // Start from the current processing message to match SwapBuffer pattern. | 760 // Start from the current processing message to match SwapBuffer pattern. |
781 matched_messages_num = MatchSwapBufferMessagesPattern(message.get()); | 761 matched_messages_num = MatchSwapBufferMessagesPattern(message.get()); |
782 should_handle_swapbuffer_msgs_immediate = | 762 should_handle_swapbuffer_msgs_immediate = |
783 matched_messages_num > 0 && stub; | 763 matched_messages_num > 0 && stub; |
784 } else { | 764 } else { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 uint64 GpuChannel::GetMemoryUsage() { | 866 uint64 GpuChannel::GetMemoryUsage() { |
887 uint64 size = 0; | 867 uint64 size = 0; |
888 for (StubMap::Iterator<GpuCommandBufferStub> it(&stubs_); | 868 for (StubMap::Iterator<GpuCommandBufferStub> it(&stubs_); |
889 !it.IsAtEnd(); it.Advance()) { | 869 !it.IsAtEnd(); it.Advance()) { |
890 size += it.GetCurrentValue()->GetMemoryUsage(); | 870 size += it.GetCurrentValue()->GetMemoryUsage(); |
891 } | 871 } |
892 return size; | 872 return size; |
893 } | 873 } |
894 | 874 |
895 } // namespace content | 875 } // namespace content |
OLD | NEW |