| 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 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 539 |
| 540 gpu::SyncPointManager* sync_point_manager = manager->sync_point_manager(); | 540 gpu::SyncPointManager* sync_point_manager = manager->sync_point_manager(); |
| 541 DCHECK(sync_point_manager); | 541 DCHECK(sync_point_manager); |
| 542 | 542 |
| 543 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group_.get())); | 543 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group_.get())); |
| 544 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), | 544 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), |
| 545 decoder_.get(), | 545 decoder_.get(), |
| 546 decoder_.get())); | 546 decoder_.get())); |
| 547 sync_point_client_ = | 547 sync_point_client_ = |
| 548 sync_point_manager->CreateSyncPointClient( | 548 sync_point_manager->CreateSyncPointClient( |
| 549 channel_->GetSyncPointClientState(), | 549 channel_->GetSyncPointOrderData(), |
| 550 gpu::CommandBufferNamespace::GPU_IO, | 550 gpu::CommandBufferNamespace::GPU_IO, |
| 551 command_buffer_id_); | 551 command_buffer_id_); |
| 552 | 552 |
| 553 if (preemption_flag_.get()) | 553 if (preemption_flag_.get()) |
| 554 scheduler_->SetPreemptByFlag(preemption_flag_); | 554 scheduler_->SetPreemptByFlag(preemption_flag_); |
| 555 | 555 |
| 556 decoder_->set_engine(scheduler_.get()); | 556 decoder_->set_engine(scheduler_.get()); |
| 557 | 557 |
| 558 if (!handle_.is_null()) { | 558 if (!handle_.is_null()) { |
| 559 surface_ = ImageTransportSurface::CreateSurface( | 559 surface_ = ImageTransportSurface::CreateSurface( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 | 646 |
| 647 decoder_->GetLogger()->SetMsgCallback( | 647 decoder_->GetLogger()->SetMsgCallback( |
| 648 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, | 648 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, |
| 649 base::Unretained(this))); | 649 base::Unretained(this))); |
| 650 decoder_->SetShaderCacheCallback( | 650 decoder_->SetShaderCacheCallback( |
| 651 base::Bind(&GpuCommandBufferStub::SendCachedShader, | 651 base::Bind(&GpuCommandBufferStub::SendCachedShader, |
| 652 base::Unretained(this))); | 652 base::Unretained(this))); |
| 653 decoder_->SetWaitSyncPointCallback( | 653 decoder_->SetWaitSyncPointCallback( |
| 654 base::Bind(&GpuCommandBufferStub::OnWaitSyncPoint, | 654 base::Bind(&GpuCommandBufferStub::OnWaitSyncPoint, |
| 655 base::Unretained(this))); | 655 base::Unretained(this))); |
| 656 decoder_->SetFenceSyncReleaseCallback(base::Bind( |
| 657 &GpuCommandBufferStub::OnFenceSyncRelease, base::Unretained(this))); |
| 658 decoder_->SetWaitFenceSyncCallback(base::Bind( |
| 659 &GpuCommandBufferStub::OnWaitFenceSync, base::Unretained(this))); |
| 656 | 660 |
| 657 command_buffer_->SetPutOffsetChangeCallback( | 661 command_buffer_->SetPutOffsetChangeCallback( |
| 658 base::Bind(&GpuCommandBufferStub::PutChanged, base::Unretained(this))); | 662 base::Bind(&GpuCommandBufferStub::PutChanged, base::Unretained(this))); |
| 659 command_buffer_->SetGetBufferChangeCallback( | 663 command_buffer_->SetGetBufferChangeCallback( |
| 660 base::Bind(&gpu::GpuScheduler::SetGetBuffer, | 664 base::Bind(&gpu::GpuScheduler::SetGetBuffer, |
| 661 base::Unretained(scheduler_.get()))); | 665 base::Unretained(scheduler_.get()))); |
| 662 command_buffer_->SetParseErrorCallback( | 666 command_buffer_->SetParseErrorCallback( |
| 663 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); | 667 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); |
| 664 scheduler_->SetSchedulingChangedCallback(base::Bind( | 668 scheduler_->SetSchedulingChangedCallback(base::Bind( |
| 665 &GpuCommandBufferStub::OnSchedulingChanged, base::Unretained(this))); | 669 &GpuCommandBufferStub::OnSchedulingChanged, base::Unretained(this))); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 if (retire) | 939 if (retire) |
| 936 OnRetireSyncPoint(sync_point); | 940 OnRetireSyncPoint(sync_point); |
| 937 } | 941 } |
| 938 | 942 |
| 939 void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) { | 943 void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) { |
| 940 DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point); | 944 DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point); |
| 941 sync_points_.pop_front(); | 945 sync_points_.pop_front(); |
| 942 | 946 |
| 943 gpu::gles2::MailboxManager* mailbox_manager = | 947 gpu::gles2::MailboxManager* mailbox_manager = |
| 944 context_group_->mailbox_manager(); | 948 context_group_->mailbox_manager(); |
| 945 if (mailbox_manager->UsesSync() && MakeCurrent()) | 949 if (mailbox_manager->UsesSync() && MakeCurrent()) { |
| 946 mailbox_manager->PushTextureUpdates(sync_point); | 950 // Old sync points are global and do not have a command buffer ID, |
| 951 // We can simply use the global sync point number as the release count with |
| 952 // 0 for the command buffer ID (under normal circumstances 0 is invalid so |
| 953 // will not be used) until the old sync points are replaced. |
| 954 gpu::gles2::SyncToken sync_token = { |
| 955 gpu::CommandBufferNamespace::GPU_IO, |
| 956 0, |
| 957 sync_point |
| 958 }; |
| 959 mailbox_manager->PushTextureUpdates(sync_token); |
| 960 } |
| 947 | 961 |
| 948 GpuChannelManager* manager = channel_->gpu_channel_manager(); | 962 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
| 949 manager->sync_point_manager()->RetireSyncPoint(sync_point); | 963 manager->sync_point_manager()->RetireSyncPoint(sync_point); |
| 950 } | 964 } |
| 951 | 965 |
| 952 bool GpuCommandBufferStub::OnWaitSyncPoint(uint32 sync_point) { | 966 bool GpuCommandBufferStub::OnWaitSyncPoint(uint32 sync_point) { |
| 953 DCHECK(!waiting_for_sync_point_); | 967 DCHECK(!waiting_for_sync_point_); |
| 954 DCHECK(scheduler_->scheduled()); | 968 DCHECK(scheduler_->scheduled()); |
| 955 if (!sync_point) | 969 if (!sync_point) |
| 956 return true; | 970 return true; |
| 957 GpuChannelManager* manager = channel_->gpu_channel_manager(); | 971 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
| 958 if (manager->sync_point_manager()->IsSyncPointRetired(sync_point)) { | 972 if (manager->sync_point_manager()->IsSyncPointRetired(sync_point)) { |
| 959 PullTextureUpdates(sync_point); | 973 // Old sync points are global and do not have a command buffer ID, |
| 974 // We can simply use the global sync point number as the release count with |
| 975 // 0 for the command buffer ID (under normal circumstances 0 is invalid so |
| 976 // will not be used) until the old sync points are replaced. |
| 977 PullTextureUpdates(gpu::CommandBufferNamespace::GPU_IO, 0, sync_point); |
| 960 return true; | 978 return true; |
| 961 } | 979 } |
| 962 | 980 |
| 963 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", | 981 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", |
| 964 this); | 982 this); |
| 965 | 983 |
| 966 scheduler_->SetScheduled(false); | 984 scheduler_->SetScheduled(false); |
| 967 waiting_for_sync_point_ = true; | 985 waiting_for_sync_point_ = true; |
| 968 manager->sync_point_manager()->AddSyncPointCallback( | 986 manager->sync_point_manager()->AddSyncPointCallback( |
| 969 sync_point, | 987 sync_point, |
| 970 base::Bind(&RunOnThread, task_runner_, | 988 base::Bind(&RunOnThread, task_runner_, |
| 971 base::Bind(&GpuCommandBufferStub::OnWaitSyncPointCompleted, | 989 base::Bind(&GpuCommandBufferStub::OnWaitSyncPointCompleted, |
| 972 this->AsWeakPtr(), sync_point))); | 990 this->AsWeakPtr(), sync_point))); |
| 973 return !waiting_for_sync_point_; | 991 return !waiting_for_sync_point_; |
| 974 } | 992 } |
| 975 | 993 |
| 976 void GpuCommandBufferStub::OnWaitSyncPointCompleted(uint32 sync_point) { | 994 void GpuCommandBufferStub::OnWaitSyncPointCompleted(uint32 sync_point) { |
| 977 DCHECK(waiting_for_sync_point_); | 995 DCHECK(waiting_for_sync_point_); |
| 978 DCHECK(!scheduler_->scheduled()); | 996 DCHECK(!scheduler_->scheduled()); |
| 979 TRACE_EVENT_ASYNC_END1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", | 997 TRACE_EVENT_ASYNC_END1("gpu", "WaitSyncPoint", this, "GpuCommandBufferStub", |
| 980 this); | 998 this); |
| 981 PullTextureUpdates(sync_point); | 999 // Old sync points are global and do not have a command buffer ID, |
| 1000 // We can simply use the global sync point number as the release count with |
| 1001 // 0 for the command buffer ID (under normal circumstances 0 is invalid so |
| 1002 // will not be used) until the old sync points are replaced. |
| 1003 PullTextureUpdates(gpu::CommandBufferNamespace::GPU_IO, 0, sync_point); |
| 982 waiting_for_sync_point_ = false; | 1004 waiting_for_sync_point_ = false; |
| 983 scheduler_->SetScheduled(true); | 1005 scheduler_->SetScheduled(true); |
| 984 } | 1006 } |
| 985 | 1007 |
| 986 void GpuCommandBufferStub::PullTextureUpdates(uint32 sync_point) { | 1008 void GpuCommandBufferStub::PullTextureUpdates( |
| 1009 gpu::CommandBufferNamespace namespace_id, |
| 1010 uint64_t command_buffer_id, |
| 1011 uint32_t release) { |
| 987 gpu::gles2::MailboxManager* mailbox_manager = | 1012 gpu::gles2::MailboxManager* mailbox_manager = |
| 988 context_group_->mailbox_manager(); | 1013 context_group_->mailbox_manager(); |
| 989 if (mailbox_manager->UsesSync() && MakeCurrent()) | 1014 if (mailbox_manager->UsesSync() && MakeCurrent()) { |
| 990 mailbox_manager->PullTextureUpdates(sync_point); | 1015 gpu::gles2::SyncToken sync_token = { |
| 1016 namespace_id, |
| 1017 command_buffer_id, |
| 1018 release |
| 1019 }; |
| 1020 mailbox_manager->PullTextureUpdates(sync_token); |
| 1021 } |
| 991 } | 1022 } |
| 992 | 1023 |
| 993 void GpuCommandBufferStub::OnSignalSyncPoint(uint32 sync_point, uint32 id) { | 1024 void GpuCommandBufferStub::OnSignalSyncPoint(uint32 sync_point, uint32 id) { |
| 994 GpuChannelManager* manager = channel_->gpu_channel_manager(); | 1025 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
| 995 manager->sync_point_manager()->AddSyncPointCallback( | 1026 manager->sync_point_manager()->AddSyncPointCallback( |
| 996 sync_point, | 1027 sync_point, |
| 997 base::Bind(&RunOnThread, task_runner_, | 1028 base::Bind(&RunOnThread, task_runner_, |
| 998 base::Bind(&GpuCommandBufferStub::OnSignalSyncPointAck, | 1029 base::Bind(&GpuCommandBufferStub::OnSignalSyncPointAck, |
| 999 this->AsWeakPtr(), id))); | 1030 this->AsWeakPtr(), id))); |
| 1000 } | 1031 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1015 this->AsWeakPtr(), | 1046 this->AsWeakPtr(), |
| 1016 id)); | 1047 id)); |
| 1017 return; | 1048 return; |
| 1018 } | 1049 } |
| 1019 } | 1050 } |
| 1020 } | 1051 } |
| 1021 // Something went wrong, run callback immediately. | 1052 // Something went wrong, run callback immediately. |
| 1022 OnSignalSyncPointAck(id); | 1053 OnSignalSyncPointAck(id); |
| 1023 } | 1054 } |
| 1024 | 1055 |
| 1056 void GpuCommandBufferStub::OnFenceSyncRelease(uint64_t release) { |
| 1057 if (sync_point_client_->client_state()->IsFenceSyncReleased(release)) { |
| 1058 DLOG(ERROR) << "Fence Sync has already been released."; |
| 1059 return; |
| 1060 } |
| 1061 |
| 1062 gpu::gles2::MailboxManager* mailbox_manager = |
| 1063 context_group_->mailbox_manager(); |
| 1064 if (mailbox_manager->UsesSync() && MakeCurrent()) { |
| 1065 gpu::gles2::SyncToken sync_token = { |
| 1066 gpu::CommandBufferNamespace::GPU_IO, |
| 1067 command_buffer_id_, |
| 1068 release |
| 1069 }; |
| 1070 mailbox_manager->PushTextureUpdates(sync_token); |
| 1071 } |
| 1072 |
| 1073 sync_point_client_->ReleaseFenceSync(release); |
| 1074 } |
| 1075 |
| 1076 bool GpuCommandBufferStub::OnWaitFenceSync( |
| 1077 gpu::CommandBufferNamespace namespace_id, |
| 1078 uint64_t command_buffer_id, |
| 1079 uint64_t release) { |
| 1080 DCHECK(!waiting_for_sync_point_); |
| 1081 DCHECK(scheduler_->scheduled()); |
| 1082 |
| 1083 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
| 1084 DCHECK(manager); |
| 1085 |
| 1086 gpu::SyncPointManager* sync_point_manager = manager->sync_point_manager(); |
| 1087 DCHECK(sync_point_manager); |
| 1088 |
| 1089 scoped_refptr<gpu::SyncPointClientState> release_state = |
| 1090 sync_point_manager->GetSyncPointClientState(namespace_id, |
| 1091 command_buffer_id); |
| 1092 |
| 1093 if (!release_state) |
| 1094 return true; |
| 1095 |
| 1096 if (release_state->IsFenceSyncReleased(release)) { |
| 1097 PullTextureUpdates(namespace_id, command_buffer_id, release); |
| 1098 return true; |
| 1099 } |
| 1100 |
| 1101 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitFenceSync", this, |
| 1102 "GpuCommandBufferStub", this); |
| 1103 scheduler_->SetScheduled(false); |
| 1104 waiting_for_sync_point_ = true; |
| 1105 sync_point_client_->WaitNonThreadSafe( |
| 1106 release_state, |
| 1107 release, |
| 1108 task_runner_, |
| 1109 base::Bind(&GpuCommandBufferStub::OnWaitFenceSyncCompleted, |
| 1110 this->AsWeakPtr(), namespace_id, command_buffer_id, release)); |
| 1111 |
| 1112 return scheduler_->scheduled(); |
| 1113 } |
| 1114 |
| 1115 void GpuCommandBufferStub::OnWaitFenceSyncCompleted( |
| 1116 gpu::CommandBufferNamespace namespace_id, |
| 1117 uint64_t command_buffer_id, |
| 1118 uint64_t release) { |
| 1119 DCHECK(waiting_for_sync_point_); |
| 1120 DCHECK(!scheduler_->scheduled()); |
| 1121 TRACE_EVENT_ASYNC_END1("gpu", "WaitFenceSync", this, "GpuCommandBufferStub", |
| 1122 this); |
| 1123 PullTextureUpdates(namespace_id, command_buffer_id, release); |
| 1124 waiting_for_sync_point_ = false; |
| 1125 scheduler_->SetScheduled(true); |
| 1126 } |
| 1025 | 1127 |
| 1026 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( | 1128 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( |
| 1027 bool has_callback) { | 1129 bool has_callback) { |
| 1028 TRACE_EVENT0( | 1130 TRACE_EVENT0( |
| 1029 "gpu", | 1131 "gpu", |
| 1030 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); | 1132 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); |
| 1031 if (has_callback) { | 1133 if (has_callback) { |
| 1032 if (!memory_manager_client_state_) { | 1134 if (!memory_manager_client_state_) { |
| 1033 memory_manager_client_state_.reset( | 1135 memory_manager_client_state_.reset( |
| 1034 GetMemoryManager()->CreateClientState(this, !offscreen_, true)); | 1136 GetMemoryManager()->CreateClientState(this, !offscreen_, true)); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 result)); | 1320 result)); |
| 1219 } | 1321 } |
| 1220 | 1322 |
| 1221 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, | 1323 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, |
| 1222 base::TimeDelta interval) { | 1324 base::TimeDelta interval) { |
| 1223 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, | 1325 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, |
| 1224 interval)); | 1326 interval)); |
| 1225 } | 1327 } |
| 1226 | 1328 |
| 1227 } // namespace content | 1329 } // namespace content |
| OLD | NEW |