Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "gpu/command_buffer/service/in_process_command_buffer.h" | 5 #include "gpu/command_buffer/service/in_process_command_buffer.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "gpu/command_buffer/service/context_group.h" | 24 #include "gpu/command_buffer/service/context_group.h" |
| 25 #include "gpu/command_buffer/service/gl_context_virtual.h" | 25 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 26 #include "gpu/command_buffer/service/gpu_scheduler.h" | 26 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 27 #include "gpu/command_buffer/service/gpu_switches.h" | 27 #include "gpu/command_buffer/service/gpu_switches.h" |
| 28 #include "gpu/command_buffer/service/image_factory.h" | 28 #include "gpu/command_buffer/service/image_factory.h" |
| 29 #include "gpu/command_buffer/service/image_manager.h" | 29 #include "gpu/command_buffer/service/image_manager.h" |
| 30 #include "gpu/command_buffer/service/mailbox_manager_impl.h" | 30 #include "gpu/command_buffer/service/mailbox_manager_impl.h" |
| 31 #include "gpu/command_buffer/service/mailbox_manager_sync.h" | 31 #include "gpu/command_buffer/service/mailbox_manager_sync.h" |
| 32 #include "gpu/command_buffer/service/memory_tracking.h" | 32 #include "gpu/command_buffer/service/memory_tracking.h" |
| 33 #include "gpu/command_buffer/service/query_manager.h" | 33 #include "gpu/command_buffer/service/query_manager.h" |
| 34 #include "gpu/command_buffer/service/sync_point_manager.h" | |
| 34 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 35 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 35 #include "gpu/command_buffer/service/valuebuffer_manager.h" | 36 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
| 36 #include "ui/gfx/geometry/size.h" | 37 #include "ui/gfx/geometry/size.h" |
| 37 #include "ui/gl/gl_context.h" | 38 #include "ui/gl/gl_context.h" |
| 38 #include "ui/gl/gl_image.h" | 39 #include "ui/gl/gl_image.h" |
| 39 #include "ui/gl/gl_share_group.h" | 40 #include "ui/gl/gl_share_group.h" |
| 40 | 41 |
| 41 #if defined(OS_ANDROID) | 42 #if defined(OS_ANDROID) |
| 42 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h " | 43 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h " |
| 43 #include "ui/gl/android/surface_texture.h" | 44 #include "ui/gl/android/surface_texture.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 124 |
| 124 class ScopedEvent { | 125 class ScopedEvent { |
| 125 public: | 126 public: |
| 126 ScopedEvent(base::WaitableEvent* event) : event_(event) {} | 127 ScopedEvent(base::WaitableEvent* event) : event_(event) {} |
| 127 ~ScopedEvent() { event_->Signal(); } | 128 ~ScopedEvent() { event_->Signal(); } |
| 128 | 129 |
| 129 private: | 130 private: |
| 130 base::WaitableEvent* event_; | 131 base::WaitableEvent* event_; |
| 131 }; | 132 }; |
| 132 | 133 |
| 133 class SyncPointManager { | 134 class SyncPointManagerWrapper { |
|
no sievers
2015/02/05 21:55:04
nit: put a comment that this class allows for a se
boliu
2015/02/05 23:50:44
Done.
| |
| 134 public: | 135 public: |
| 135 SyncPointManager(); | 136 SyncPointManagerWrapper(); |
| 136 ~SyncPointManager(); | |
| 137 | 137 |
| 138 uint32 GenerateSyncPoint(); | 138 uint32 GenerateSyncPoint(); |
| 139 void RetireSyncPoint(uint32 sync_point); | 139 void RetireSyncPoint(uint32 sync_point); |
| 140 void AddSyncPointCallback(uint32 sync_point, const base::Closure& callback); | |
| 140 | 141 |
| 141 bool IsSyncPointPassed(uint32 sync_point); | |
| 142 void WaitSyncPoint(uint32 sync_point); | 142 void WaitSyncPoint(uint32 sync_point); |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 // This lock protects access to pending_sync_points_ and next_sync_point_ and | 145 void SyncPointRetired(); |
| 146 // is used with the ConditionVariable to signal when a sync point is retired. | 146 |
| 147 base::Lock lock_; | 147 const scoped_refptr<SyncPointManager> manager_; |
| 148 std::set<uint32> pending_sync_points_; | 148 base::Lock retire_lock_; |
| 149 uint32 next_sync_point_; | 149 base::ConditionVariable retire_cond_var_; |
| 150 base::ConditionVariable cond_var_; | 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(SyncPointManagerWrapper); | |
| 151 }; | 152 }; |
| 152 | 153 |
| 153 SyncPointManager::SyncPointManager() : next_sync_point_(1), cond_var_(&lock_) {} | 154 SyncPointManagerWrapper::SyncPointManagerWrapper() |
| 154 | 155 : manager_(new SyncPointManager), retire_cond_var_(&retire_lock_) { |
| 155 SyncPointManager::~SyncPointManager() { | |
| 156 DCHECK_EQ(pending_sync_points_.size(), 0U); | |
| 157 } | 156 } |
| 158 | 157 |
| 159 uint32 SyncPointManager::GenerateSyncPoint() { | 158 uint32 SyncPointManagerWrapper::GenerateSyncPoint() { |
| 160 base::AutoLock lock(lock_); | 159 uint32 sync_point = manager_->GenerateSyncPoint(); |
| 161 uint32 sync_point = next_sync_point_++; | 160 manager_->AddSyncPointCallback( |
| 162 DCHECK_EQ(pending_sync_points_.count(sync_point), 0U); | 161 sync_point, base::Bind(&SyncPointManagerWrapper::SyncPointRetired, |
| 163 pending_sync_points_.insert(sync_point); | 162 base::Unretained(this))); |
| 164 return sync_point; | 163 return sync_point; |
| 165 } | 164 } |
| 166 | 165 |
| 167 void SyncPointManager::RetireSyncPoint(uint32 sync_point) { | 166 void SyncPointManagerWrapper::RetireSyncPoint(uint32 sync_point) { |
| 168 base::AutoLock lock(lock_); | 167 manager_->RetireSyncPoint(sync_point); |
| 169 DCHECK(pending_sync_points_.count(sync_point)); | |
| 170 pending_sync_points_.erase(sync_point); | |
| 171 cond_var_.Broadcast(); | |
| 172 } | 168 } |
| 173 | 169 |
| 174 bool SyncPointManager::IsSyncPointPassed(uint32 sync_point) { | 170 void SyncPointManagerWrapper::AddSyncPointCallback( |
| 175 base::AutoLock lock(lock_); | 171 uint32 sync_point, |
| 176 return pending_sync_points_.count(sync_point) == 0; | 172 const base::Closure& callback) { |
| 173 manager_->AddSyncPointCallback(sync_point, callback); | |
| 177 } | 174 } |
| 178 | 175 |
| 179 void SyncPointManager::WaitSyncPoint(uint32 sync_point) { | 176 void SyncPointManagerWrapper::WaitSyncPoint(uint32 sync_point) { |
| 180 base::AutoLock lock(lock_); | 177 base::AutoLock lock(retire_lock_); |
| 181 while (pending_sync_points_.count(sync_point)) { | 178 while (!manager_->IsSyncPointRetired(sync_point)) { |
| 182 cond_var_.Wait(); | 179 retire_cond_var_.Wait(); |
| 183 } | 180 } |
| 184 } | 181 } |
| 185 | 182 |
| 186 base::LazyInstance<SyncPointManager> g_sync_point_manager = | 183 void SyncPointManagerWrapper::SyncPointRetired() { |
|
no sievers
2015/02/05 21:55:04
nit: maybe OnSyncPointRetired()?
boliu
2015/02/05 23:50:44
Done.
| |
| 184 base::AutoLock lock(retire_lock_); | |
| 185 retire_cond_var_.Broadcast(); | |
| 186 } | |
| 187 | |
| 188 base::LazyInstance<SyncPointManagerWrapper> g_sync_point_manager = | |
| 187 LAZY_INSTANCE_INITIALIZER; | 189 LAZY_INSTANCE_INITIALIZER; |
| 188 | 190 |
| 189 base::SharedMemoryHandle ShareToGpuThread( | 191 base::SharedMemoryHandle ShareToGpuThread( |
| 190 base::SharedMemoryHandle source_handle) { | 192 base::SharedMemoryHandle source_handle) { |
| 191 #if defined(OS_WIN) | 193 #if defined(OS_WIN) |
| 192 // Windows needs to explicitly duplicate the handle to current process. | 194 // Windows needs to explicitly duplicate the handle to current process. |
| 193 base::SharedMemoryHandle target_handle; | 195 base::SharedMemoryHandle target_handle; |
| 194 if (!DuplicateHandle(GetCurrentProcess(), | 196 if (!DuplicateHandle(GetCurrentProcess(), |
| 195 source_handle, | 197 source_handle, |
| 196 GetCurrentProcess(), | 198 GetCurrentProcess(), |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 847 g_sync_point_manager.Get().WaitSyncPoint(sync_point); | 849 g_sync_point_manager.Get().WaitSyncPoint(sync_point); |
| 848 gles2::MailboxManager* mailbox_manager = | 850 gles2::MailboxManager* mailbox_manager = |
| 849 decoder_->GetContextGroup()->mailbox_manager(); | 851 decoder_->GetContextGroup()->mailbox_manager(); |
| 850 mailbox_manager->PullTextureUpdates(sync_point); | 852 mailbox_manager->PullTextureUpdates(sync_point); |
| 851 return true; | 853 return true; |
| 852 } | 854 } |
| 853 | 855 |
| 854 void InProcessCommandBuffer::SignalSyncPointOnGpuThread( | 856 void InProcessCommandBuffer::SignalSyncPointOnGpuThread( |
| 855 unsigned sync_point, | 857 unsigned sync_point, |
| 856 const base::Closure& callback) { | 858 const base::Closure& callback) { |
| 857 if (g_sync_point_manager.Get().IsSyncPointPassed(sync_point)) { | 859 g_sync_point_manager.Get().AddSyncPointCallback(sync_point, callback); |
| 858 callback.Run(); | |
| 859 } else { | |
| 860 service_->ScheduleIdleWork( | |
| 861 base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread, | |
| 862 gpu_thread_weak_ptr_, | |
| 863 sync_point, | |
| 864 callback)); | |
| 865 } | |
| 866 } | 860 } |
| 867 | 861 |
| 868 void InProcessCommandBuffer::SignalQuery(unsigned query_id, | 862 void InProcessCommandBuffer::SignalQuery(unsigned query_id, |
| 869 const base::Closure& callback) { | 863 const base::Closure& callback) { |
| 870 CheckSequencedThread(); | 864 CheckSequencedThread(); |
| 871 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread, | 865 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread, |
| 872 base::Unretained(this), | 866 base::Unretained(this), |
| 873 query_id, | 867 query_id, |
| 874 WrapCallback(callback))); | 868 WrapCallback(callback))); |
| 875 } | 869 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 957 | 951 |
| 958 #if defined(OS_ANDROID) | 952 #if defined(OS_ANDROID) |
| 959 scoped_refptr<gfx::SurfaceTexture> | 953 scoped_refptr<gfx::SurfaceTexture> |
| 960 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { | 954 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { |
| 961 DCHECK(stream_texture_manager_); | 955 DCHECK(stream_texture_manager_); |
| 962 return stream_texture_manager_->GetSurfaceTexture(stream_id); | 956 return stream_texture_manager_->GetSurfaceTexture(stream_id); |
| 963 } | 957 } |
| 964 #endif | 958 #endif |
| 965 | 959 |
| 966 } // namespace gpu | 960 } // namespace gpu |
| OLD | NEW |