Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: gpu/command_buffer/service/in_process_command_buffer.cc

Issue 849103002: Share SyncPointManager implementation in in-process cmd buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECKs Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 base::LazyInstance<ThreadedSyncPointManager> g_sync_point_manager =
133 public:
134 SyncPointManager();
135 ~SyncPointManager();
136
137 uint32 GenerateSyncPoint();
138 void RetireSyncPoint(uint32 sync_point);
139
140 bool IsSyncPointPassed(uint32 sync_point);
141 void WaitSyncPoint(uint32 sync_point);
142
143 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 std::set<uint32> pending_sync_points_;
148 uint32 next_sync_point_;
149 base::ConditionVariable cond_var_;
150 };
151
152 SyncPointManager::SyncPointManager() : next_sync_point_(1), cond_var_(&lock_) {}
153
154 SyncPointManager::~SyncPointManager() {
155 DCHECK_EQ(pending_sync_points_.size(), 0U);
156 }
157
158 uint32 SyncPointManager::GenerateSyncPoint() {
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 }
165
166 void SyncPointManager::RetireSyncPoint(uint32 sync_point) {
167 base::AutoLock lock(lock_);
168 DCHECK(pending_sync_points_.count(sync_point));
169 pending_sync_points_.erase(sync_point);
170 cond_var_.Broadcast();
171 }
172
173 bool SyncPointManager::IsSyncPointPassed(uint32 sync_point) {
174 base::AutoLock lock(lock_);
175 return pending_sync_points_.count(sync_point) == 0;
176 }
177
178 void SyncPointManager::WaitSyncPoint(uint32 sync_point) {
179 base::AutoLock lock(lock_);
180 while (pending_sync_points_.count(sync_point)) {
181 cond_var_.Wait();
182 }
183 }
184
185 base::LazyInstance<SyncPointManager> g_sync_point_manager =
186 LAZY_INSTANCE_INITIALIZER; 134 LAZY_INSTANCE_INITIALIZER;
187 135
188 base::SharedMemoryHandle ShareToGpuThread( 136 base::SharedMemoryHandle ShareToGpuThread(
189 base::SharedMemoryHandle source_handle) { 137 base::SharedMemoryHandle source_handle) {
190 #if defined(OS_WIN) 138 #if defined(OS_WIN)
191 // Windows needs to explicitly duplicate the handle to current process. 139 // Windows needs to explicitly duplicate the handle to current process.
192 base::SharedMemoryHandle target_handle; 140 base::SharedMemoryHandle target_handle;
193 if (!DuplicateHandle(GetCurrentProcess(), 141 if (!DuplicateHandle(GetCurrentProcess(),
194 source_handle, 142 source_handle,
195 GetCurrentProcess(), 143 GetCurrentProcess(),
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 g_sync_point_manager.Get().WaitSyncPoint(sync_point); 783 g_sync_point_manager.Get().WaitSyncPoint(sync_point);
836 gles2::MailboxManager* mailbox_manager = 784 gles2::MailboxManager* mailbox_manager =
837 decoder_->GetContextGroup()->mailbox_manager(); 785 decoder_->GetContextGroup()->mailbox_manager();
838 mailbox_manager->PullTextureUpdates(sync_point); 786 mailbox_manager->PullTextureUpdates(sync_point);
839 return true; 787 return true;
840 } 788 }
841 789
842 void InProcessCommandBuffer::SignalSyncPointOnGpuThread( 790 void InProcessCommandBuffer::SignalSyncPointOnGpuThread(
843 unsigned sync_point, 791 unsigned sync_point,
844 const base::Closure& callback) { 792 const base::Closure& callback) {
845 if (g_sync_point_manager.Get().IsSyncPointPassed(sync_point)) { 793 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 } 794 }
855 795
856 void InProcessCommandBuffer::SignalQuery(unsigned query_id, 796 void InProcessCommandBuffer::SignalQuery(unsigned query_id,
857 const base::Closure& callback) { 797 const base::Closure& callback) {
858 CheckSequencedThread(); 798 CheckSequencedThread();
859 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread, 799 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread,
860 base::Unretained(this), 800 base::Unretained(this),
861 query_id, 801 query_id,
862 WrapCallback(callback))); 802 WrapCallback(callback)));
863 } 803 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 885
946 #if defined(OS_ANDROID) 886 #if defined(OS_ANDROID)
947 scoped_refptr<gfx::SurfaceTexture> 887 scoped_refptr<gfx::SurfaceTexture>
948 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { 888 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) {
949 DCHECK(stream_texture_manager_); 889 DCHECK(stream_texture_manager_);
950 return stream_texture_manager_->GetSurfaceTexture(stream_id); 890 return stream_texture_manager_->GetSurfaceTexture(stream_id);
951 } 891 }
952 #endif 892 #endif
953 893
954 } // namespace gpu 894 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/service/sync_point_manager.h » ('j') | gpu/command_buffer/service/sync_point_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698