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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 | 123 |
123 class ScopedEvent { | 124 class ScopedEvent { |
124 public: | 125 public: |
125 ScopedEvent(base::WaitableEvent* event) : event_(event) {} | 126 ScopedEvent(base::WaitableEvent* event) : event_(event) {} |
126 ~ScopedEvent() { event_->Signal(); } | 127 ~ScopedEvent() { event_->Signal(); } |
127 | 128 |
128 private: | 129 private: |
129 base::WaitableEvent* event_; | 130 base::WaitableEvent* event_; |
130 }; | 131 }; |
131 | 132 |
132 class SyncPointManager { | 133 class ThreadedSyncPointManager { |
no sievers
2015/01/16 20:03:37
nit: put a class comment that explains that 'threa
| |
133 public: | 134 public: |
134 SyncPointManager(); | 135 ThreadedSyncPointManager(); |
135 ~SyncPointManager(); | 136 ~ThreadedSyncPointManager(); |
136 | 137 |
138 // SyncPointManager methods. | |
no sievers
2015/01/16 20:03:37
nit: you are not subclassing SyncPointManager
| |
137 uint32 GenerateSyncPoint(); | 139 uint32 GenerateSyncPoint(); |
138 void RetireSyncPoint(uint32 sync_point); | 140 void RetireSyncPoint(uint32 sync_point); |
141 void AddSyncPointCallback(uint32 sync_point, const base::Closure& callback); | |
142 bool IsSyncPointRetired(uint32 sync_point); | |
139 | 143 |
140 bool IsSyncPointPassed(uint32 sync_point); | |
141 void WaitSyncPoint(uint32 sync_point); | 144 void WaitSyncPoint(uint32 sync_point); |
142 | 145 |
143 private: | 146 private: |
144 // This lock protects access to pending_sync_points_ and next_sync_point_ and | |
145 // is used with the ConditionVariable to signal when a sync point is retired. | |
146 base::Lock lock_; | 147 base::Lock lock_; |
147 std::set<uint32> pending_sync_points_; | |
148 uint32 next_sync_point_; | |
149 base::ConditionVariable cond_var_; | 148 base::ConditionVariable cond_var_; |
149 scoped_refptr<SyncPointManager> sync_point_manager_; | |
150 }; | 150 }; |
151 | 151 |
152 SyncPointManager::SyncPointManager() : next_sync_point_(1), cond_var_(&lock_) {} | 152 ThreadedSyncPointManager::ThreadedSyncPointManager() |
153 | 153 : cond_var_(&lock_), sync_point_manager_(new SyncPointManager) { |
154 SyncPointManager::~SyncPointManager() { | |
155 DCHECK_EQ(pending_sync_points_.size(), 0U); | |
156 } | 154 } |
157 | 155 |
158 uint32 SyncPointManager::GenerateSyncPoint() { | 156 ThreadedSyncPointManager::~ThreadedSyncPointManager() { |
159 base::AutoLock lock(lock_); | |
160 uint32 sync_point = next_sync_point_++; | |
161 DCHECK_EQ(pending_sync_points_.count(sync_point), 0U); | |
162 pending_sync_points_.insert(sync_point); | |
163 return sync_point; | |
164 } | 157 } |
165 | 158 |
166 void SyncPointManager::RetireSyncPoint(uint32 sync_point) { | 159 uint32 ThreadedSyncPointManager::GenerateSyncPoint() { |
167 base::AutoLock lock(lock_); | 160 base::AutoLock lock(lock_); |
no sievers
2015/01/16 20:03:37
This doesn't need the lock since SyncPointManager:
| |
168 DCHECK(pending_sync_points_.count(sync_point)); | 161 return sync_point_manager_->GenerateSyncPoint(); |
169 pending_sync_points_.erase(sync_point); | 162 } |
163 | |
164 void ThreadedSyncPointManager::RetireSyncPoint(uint32 sync_point) { | |
165 base::AutoLock lock(lock_); | |
166 sync_point_manager_->RetireSyncPoint(sync_point); | |
no sievers
2015/01/16 20:03:37
However the other three calls will trigger the Cal
| |
170 cond_var_.Broadcast(); | 167 cond_var_.Broadcast(); |
171 } | 168 } |
172 | 169 |
173 bool SyncPointManager::IsSyncPointPassed(uint32 sync_point) { | 170 void ThreadedSyncPointManager::AddSyncPointCallback( |
171 uint32 sync_point, | |
172 const base::Closure& callback) { | |
174 base::AutoLock lock(lock_); | 173 base::AutoLock lock(lock_); |
175 return pending_sync_points_.count(sync_point) == 0; | 174 sync_point_manager_->AddSyncPointCallback(sync_point, callback); |
176 } | 175 } |
177 | 176 |
178 void SyncPointManager::WaitSyncPoint(uint32 sync_point) { | 177 bool ThreadedSyncPointManager::IsSyncPointRetired(uint32 sync_point) { |
179 base::AutoLock lock(lock_); | 178 base::AutoLock lock(lock_); |
180 while (pending_sync_points_.count(sync_point)) { | 179 return sync_point_manager_->IsSyncPointRetired(sync_point); |
180 } | |
181 | |
182 void ThreadedSyncPointManager::WaitSyncPoint(uint32 sync_point) { | |
183 base::AutoLock lock(lock_); | |
184 while (!sync_point_manager_->IsSyncPointRetired(sync_point)) { | |
181 cond_var_.Wait(); | 185 cond_var_.Wait(); |
no sievers
2015/01/16 20:18:25
We also have to think about the case where we mix
boliu
2015/01/16 20:33:30
Broadcast already cover all the waiting threads. I
| |
182 } | 186 } |
183 } | 187 } |
184 | 188 |
185 base::LazyInstance<SyncPointManager> g_sync_point_manager = | 189 base::LazyInstance<ThreadedSyncPointManager> g_sync_point_manager = |
186 LAZY_INSTANCE_INITIALIZER; | 190 LAZY_INSTANCE_INITIALIZER; |
187 | 191 |
188 base::SharedMemoryHandle ShareToGpuThread( | 192 base::SharedMemoryHandle ShareToGpuThread( |
189 base::SharedMemoryHandle source_handle) { | 193 base::SharedMemoryHandle source_handle) { |
190 #if defined(OS_WIN) | 194 #if defined(OS_WIN) |
191 // Windows needs to explicitly duplicate the handle to current process. | 195 // Windows needs to explicitly duplicate the handle to current process. |
192 base::SharedMemoryHandle target_handle; | 196 base::SharedMemoryHandle target_handle; |
193 if (!DuplicateHandle(GetCurrentProcess(), | 197 if (!DuplicateHandle(GetCurrentProcess(), |
194 source_handle, | 198 source_handle, |
195 GetCurrentProcess(), | 199 GetCurrentProcess(), |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 g_sync_point_manager.Get().WaitSyncPoint(sync_point); | 839 g_sync_point_manager.Get().WaitSyncPoint(sync_point); |
836 gles2::MailboxManager* mailbox_manager = | 840 gles2::MailboxManager* mailbox_manager = |
837 decoder_->GetContextGroup()->mailbox_manager(); | 841 decoder_->GetContextGroup()->mailbox_manager(); |
838 mailbox_manager->PullTextureUpdates(sync_point); | 842 mailbox_manager->PullTextureUpdates(sync_point); |
839 return true; | 843 return true; |
840 } | 844 } |
841 | 845 |
842 void InProcessCommandBuffer::SignalSyncPointOnGpuThread( | 846 void InProcessCommandBuffer::SignalSyncPointOnGpuThread( |
843 unsigned sync_point, | 847 unsigned sync_point, |
844 const base::Closure& callback) { | 848 const base::Closure& callback) { |
845 if (g_sync_point_manager.Get().IsSyncPointPassed(sync_point)) { | 849 g_sync_point_manager.Get().AddSyncPointCallback(sync_point, callback); |
846 callback.Run(); | |
847 } else { | |
848 service_->ScheduleIdleWork( | |
849 base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread, | |
850 gpu_thread_weak_ptr_, | |
851 sync_point, | |
852 callback)); | |
853 } | |
854 } | 850 } |
855 | 851 |
856 void InProcessCommandBuffer::SignalQuery(unsigned query_id, | 852 void InProcessCommandBuffer::SignalQuery(unsigned query_id, |
857 const base::Closure& callback) { | 853 const base::Closure& callback) { |
858 CheckSequencedThread(); | 854 CheckSequencedThread(); |
859 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread, | 855 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread, |
860 base::Unretained(this), | 856 base::Unretained(this), |
861 query_id, | 857 query_id, |
862 WrapCallback(callback))); | 858 WrapCallback(callback))); |
863 } | 859 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
945 | 941 |
946 #if defined(OS_ANDROID) | 942 #if defined(OS_ANDROID) |
947 scoped_refptr<gfx::SurfaceTexture> | 943 scoped_refptr<gfx::SurfaceTexture> |
948 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { | 944 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { |
949 DCHECK(stream_texture_manager_); | 945 DCHECK(stream_texture_manager_); |
950 return stream_texture_manager_->GetSurfaceTexture(stream_id); | 946 return stream_texture_manager_->GetSurfaceTexture(stream_id); |
951 } | 947 } |
952 #endif | 948 #endif |
953 | 949 |
954 } // namespace gpu | 950 } // namespace gpu |
OLD | NEW |