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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/hash.h" | 8 #include "base/hash.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 | 654 |
655 decoder_->GetLogger()->SetMsgCallback( | 655 decoder_->GetLogger()->SetMsgCallback( |
656 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, | 656 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, |
657 base::Unretained(this))); | 657 base::Unretained(this))); |
658 decoder_->SetShaderCacheCallback( | 658 decoder_->SetShaderCacheCallback( |
659 base::Bind(&GpuCommandBufferStub::SendCachedShader, | 659 base::Bind(&GpuCommandBufferStub::SendCachedShader, |
660 base::Unretained(this))); | 660 base::Unretained(this))); |
661 decoder_->SetWaitSyncPointCallback( | 661 decoder_->SetWaitSyncPointCallback( |
662 base::Bind(&GpuCommandBufferStub::OnWaitSyncPoint, | 662 base::Bind(&GpuCommandBufferStub::OnWaitSyncPoint, |
663 base::Unretained(this))); | 663 base::Unretained(this))); |
664 decoder_->SetFenceSyncReleaseCallback(base::Bind( | |
665 &GpuCommandBufferStub::OnFenceSyncRelease, base::Unretained(this))); | |
666 decoder_->SetWaitFenceSyncCallback(base::Bind( | |
667 &GpuCommandBufferStub::OnWaitFenceSync, base::Unretained(this))); | |
664 | 668 |
665 command_buffer_->SetPutOffsetChangeCallback( | 669 command_buffer_->SetPutOffsetChangeCallback( |
666 base::Bind(&GpuCommandBufferStub::PutChanged, base::Unretained(this))); | 670 base::Bind(&GpuCommandBufferStub::PutChanged, base::Unretained(this))); |
667 command_buffer_->SetGetBufferChangeCallback( | 671 command_buffer_->SetGetBufferChangeCallback( |
668 base::Bind(&gpu::GpuScheduler::SetGetBuffer, | 672 base::Bind(&gpu::GpuScheduler::SetGetBuffer, |
669 base::Unretained(scheduler_.get()))); | 673 base::Unretained(scheduler_.get()))); |
670 command_buffer_->SetParseErrorCallback( | 674 command_buffer_->SetParseErrorCallback( |
671 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); | 675 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); |
672 scheduler_->SetSchedulingChangedCallback(base::Bind( | 676 scheduler_->SetSchedulingChangedCallback(base::Bind( |
673 &GpuCommandBufferStub::OnSchedulingChanged, base::Unretained(this))); | 677 &GpuCommandBufferStub::OnSchedulingChanged, base::Unretained(this))); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
938 if (retire) | 942 if (retire) |
939 OnRetireSyncPoint(sync_point); | 943 OnRetireSyncPoint(sync_point); |
940 } | 944 } |
941 | 945 |
942 void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) { | 946 void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) { |
943 DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point); | 947 DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point); |
944 sync_points_.pop_front(); | 948 sync_points_.pop_front(); |
945 | 949 |
946 gpu::gles2::MailboxManager* mailbox_manager = | 950 gpu::gles2::MailboxManager* mailbox_manager = |
947 context_group_->mailbox_manager(); | 951 context_group_->mailbox_manager(); |
948 if (mailbox_manager->UsesSync() && MakeCurrent()) | 952 if (mailbox_manager->UsesSync() && MakeCurrent()) { |
949 mailbox_manager->PushTextureUpdates(sync_point); | 953 // Old sync points are global and do not have a command buffer ID, |
954 // We can simply use the global sync point number as the release count with | |
955 // 0 for the command buffer ID (under normal circumstances 0 is invalid so | |
956 // will not be used) until the old sync points are replaced. | |
957 gpu::gles2::SyncToken sync_token = { | |
958 gpu::CommandBufferNamespace::GPU_IO, | |
959 0, | |
960 sync_point | |
961 }; | |
962 mailbox_manager->PushTextureUpdates(sync_token); | |
963 } | |
950 | 964 |
951 GpuChannelManager* manager = channel_->gpu_channel_manager(); | 965 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
952 manager->sync_point_manager()->RetireSyncPoint(sync_point); | 966 manager->sync_point_manager()->RetireSyncPoint(sync_point); |
953 } | 967 } |
954 | 968 |
955 bool GpuCommandBufferStub::OnWaitSyncPoint(uint32 sync_point) { | 969 bool GpuCommandBufferStub::OnWaitSyncPoint(uint32 sync_point) { |
956 DCHECK(!waiting_for_sync_point_); | 970 DCHECK(!waiting_for_sync_point_); |
957 DCHECK(scheduler_->scheduled()); | 971 DCHECK(scheduler_->scheduled()); |
958 if (!sync_point) | 972 if (!sync_point) |
959 return true; | 973 return true; |
960 GpuChannelManager* manager = channel_->gpu_channel_manager(); | 974 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
961 if (manager->sync_point_manager()->IsSyncPointRetired(sync_point)) { | 975 if (manager->sync_point_manager()->IsSyncPointRetired(sync_point)) { |
962 PullTextureUpdates(sync_point); | 976 // Old sync points are global and do not have a command buffer ID, |
977 // We can simply use the global sync point number as the release count with | |
978 // 0 for the command buffer ID (under normal circumstances 0 is invalid so | |
979 // will not be used) until the old sync points are replaced. | |
980 PullTextureUpdates(gpu::CommandBufferNamespace::GPU_IO, 0, sync_point); | |
963 return true; | 981 return true; |
964 } | 982 } |
965 | 983 |
966 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", | 984 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", |
967 this); | 985 this); |
968 | 986 |
969 scheduler_->SetScheduled(false); | 987 scheduler_->SetScheduled(false); |
970 waiting_for_sync_point_ = true; | 988 waiting_for_sync_point_ = true; |
971 manager->sync_point_manager()->AddSyncPointCallback( | 989 manager->sync_point_manager()->AddSyncPointCallback( |
972 sync_point, | 990 sync_point, |
973 base::Bind(&RunOnThread, task_runner_, | 991 base::Bind(&RunOnThread, task_runner_, |
974 base::Bind(&GpuCommandBufferStub::OnWaitSyncPointCompleted, | 992 base::Bind(&GpuCommandBufferStub::OnWaitSyncPointCompleted, |
975 this->AsWeakPtr(), sync_point))); | 993 this->AsWeakPtr(), sync_point))); |
976 return !waiting_for_sync_point_; | 994 return !waiting_for_sync_point_; |
977 } | 995 } |
978 | 996 |
979 void GpuCommandBufferStub::OnWaitSyncPointCompleted(uint32 sync_point) { | 997 void GpuCommandBufferStub::OnWaitSyncPointCompleted(uint32 sync_point) { |
980 DCHECK(waiting_for_sync_point_); | 998 DCHECK(waiting_for_sync_point_); |
981 DCHECK(!scheduler_->scheduled()); | 999 DCHECK(!scheduler_->scheduled()); |
982 TRACE_EVENT_ASYNC_END1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", | 1000 TRACE_EVENT_ASYNC_END1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", |
983 this); | 1001 this); |
984 PullTextureUpdates(sync_point); | 1002 // Old sync points are global and do not have a command buffer ID, |
1003 // We can simply use the global sync point number as the release count with | |
1004 // 0 for the command buffer ID (under normal circumstances 0 is invalid so | |
1005 // will not be used) until the old sync points are replaced. | |
1006 PullTextureUpdates(gpu::CommandBufferNamespace::GPU_IO, 0, sync_point); | |
985 waiting_for_sync_point_ = false; | 1007 waiting_for_sync_point_ = false; |
986 scheduler_->SetScheduled(true); | 1008 scheduler_->SetScheduled(true); |
987 } | 1009 } |
988 | 1010 |
989 void GpuCommandBufferStub::PullTextureUpdates(uint32 sync_point) { | 1011 void GpuCommandBufferStub::PullTextureUpdates( |
1012 gpu::CommandBufferNamespace namespace_id, | |
1013 uint64_t command_buffer_id, | |
1014 uint32_t release) { | |
990 gpu::gles2::MailboxManager* mailbox_manager = | 1015 gpu::gles2::MailboxManager* mailbox_manager = |
991 context_group_->mailbox_manager(); | 1016 context_group_->mailbox_manager(); |
992 if (mailbox_manager->UsesSync() && MakeCurrent()) | 1017 if (mailbox_manager->UsesSync() && MakeCurrent()) { |
993 mailbox_manager->PullTextureUpdates(sync_point); | 1018 gpu::gles2::SyncToken sync_token = { |
1019 namespace_id, | |
1020 command_buffer_id, | |
1021 release | |
1022 }; | |
1023 mailbox_manager->PullTextureUpdates(sync_token); | |
1024 } | |
994 } | 1025 } |
995 | 1026 |
996 void GpuCommandBufferStub::OnSignalSyncPoint(uint32 sync_point, uint32 id) { | 1027 void GpuCommandBufferStub::OnSignalSyncPoint(uint32 sync_point, uint32 id) { |
997 GpuChannelManager* manager = channel_->gpu_channel_manager(); | 1028 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
998 manager->sync_point_manager()->AddSyncPointCallback( | 1029 manager->sync_point_manager()->AddSyncPointCallback( |
999 sync_point, | 1030 sync_point, |
1000 base::Bind(&RunOnThread, task_runner_, | 1031 base::Bind(&RunOnThread, task_runner_, |
1001 base::Bind(&GpuCommandBufferStub::OnSignalSyncPointAck, | 1032 base::Bind(&GpuCommandBufferStub::OnSignalSyncPointAck, |
1002 this->AsWeakPtr(), id))); | 1033 this->AsWeakPtr(), id))); |
1003 } | 1034 } |
(...skipping 14 matching lines...) Expand all Loading... | |
1018 this->AsWeakPtr(), | 1049 this->AsWeakPtr(), |
1019 id)); | 1050 id)); |
1020 return; | 1051 return; |
1021 } | 1052 } |
1022 } | 1053 } |
1023 } | 1054 } |
1024 // Something went wrong, run callback immediately. | 1055 // Something went wrong, run callback immediately. |
1025 OnSignalSyncPointAck(id); | 1056 OnSignalSyncPointAck(id); |
1026 } | 1057 } |
1027 | 1058 |
1059 void GpuCommandBufferStub::OnFenceSyncRelease(uint32_t release) { | |
1060 if (!sync_point_client_->client_state()->IsFenceSyncReleased(release)) { | |
1061 gpu::gles2::MailboxManager* mailbox_manager = | |
1062 context_group_->mailbox_manager(); | |
1063 if (mailbox_manager->UsesSync() && MakeCurrent()) { | |
1064 gpu::gles2::SyncToken sync_token = { | |
1065 gpu::CommandBufferNamespace::GPU_IO, | |
1066 command_buffer_id_, | |
1067 release | |
1068 }; | |
1069 mailbox_manager->PushTextureUpdates(sync_token); | |
1070 } | |
1071 | |
1072 sync_point_client_->ReleaseFenceSync(release); | |
1073 } | |
1074 } | |
1075 | |
1076 bool GpuCommandBufferStub::OnWaitFenceSync( | |
1077 gpu::CommandBufferNamespace namespace_id, | |
1078 uint64_t command_buffer_id, | |
1079 uint32_t release) { | |
1080 GpuChannelManager* manager = channel_->gpu_channel_manager(); | |
1081 DCHECK(manager); | |
1082 | |
1083 gpu::SyncPointManager* sync_point_manager = manager->sync_point_manager(); | |
1084 DCHECK(sync_point_manager); | |
1085 | |
1086 scoped_refptr<gpu::SyncPointClientState> release_state = | |
1087 sync_point_manager->GetSyncPointClientState(namespace_id, | |
1088 command_buffer_id); | |
1089 | |
1090 if (!release_state.get()) | |
1091 return true; | |
1092 | |
1093 if (release_state->IsFenceSyncReleased(release)) { | |
1094 PullTextureUpdates(namespace_id, command_buffer_id, release); | |
1095 return true; | |
1096 } | |
1097 | |
1098 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitFenceSync", this, | |
1099 "GpuCommandBufferStub", this); | |
1100 scheduler_->SetScheduled(false); | |
1101 | |
1102 sync_point_client_->Wait( | |
1103 release_state, | |
1104 release, | |
1105 base::Bind(&GpuCommandBufferStub::OnWaitFenceSyncCompleted, | |
1106 this->AsWeakPtr(), namespace_id, command_buffer_id, release)); | |
1107 | |
1108 return scheduler_->scheduled(); | |
sunnyps
2015/09/23 21:44:45
Can we use the waiting_for_sync_point_ variable he
David Yen
2015/09/25 20:13:33
Yes, I missed this new variable in the merge. Done
| |
1109 } | |
1110 | |
1111 void GpuCommandBufferStub::OnWaitFenceSyncCompleted( | |
1112 gpu::CommandBufferNamespace namespace_id, | |
1113 uint64_t command_buffer_id, | |
1114 uint32_t release) { | |
1115 DCHECK(waiting_for_sync_point_); | |
sunnyps
2015/09/23 21:44:45
This DCHECK will fail because OnWaitFenceSync does
David Yen
2015/09/25 20:13:33
Done.
| |
1116 DCHECK(!scheduler_->scheduled()); | |
1117 TRACE_EVENT_ASYNC_END1("gpu", "WaitFenceSync", this, "GpuCommandBufferStub", | |
1118 this); | |
1119 PullTextureUpdates(namespace_id, command_buffer_id, release); | |
1120 scheduler_->SetScheduled(true); | |
1121 } | |
1028 | 1122 |
1029 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( | 1123 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( |
1030 bool has_callback) { | 1124 bool has_callback) { |
1031 TRACE_EVENT0( | 1125 TRACE_EVENT0( |
1032 "gpu", | 1126 "gpu", |
1033 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); | 1127 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); |
1034 if (has_callback) { | 1128 if (has_callback) { |
1035 if (!memory_manager_client_state_) { | 1129 if (!memory_manager_client_state_) { |
1036 memory_manager_client_state_.reset(GetMemoryManager()->CreateClientState( | 1130 memory_manager_client_state_.reset(GetMemoryManager()->CreateClientState( |
1037 this, surface_id_ != 0, true)); | 1131 this, surface_id_ != 0, true)); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1228 result)); | 1322 result)); |
1229 } | 1323 } |
1230 | 1324 |
1231 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, | 1325 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, |
1232 base::TimeDelta interval) { | 1326 base::TimeDelta interval) { |
1233 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, | 1327 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, |
1234 interval)); | 1328 interval)); |
1235 } | 1329 } |
1236 | 1330 |
1237 } // namespace content | 1331 } // namespace content |
OLD | NEW |