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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // This wrapper adds the WaitSyncPoint which allows waiting on a sync point
135 // on the service thread, implemented using a condition variable.
136 class SyncPointManagerWrapper {
134 public: 137 public:
135 SyncPointManager(); 138 SyncPointManagerWrapper();
136 ~SyncPointManager();
137 139
138 uint32 GenerateSyncPoint(); 140 uint32 GenerateSyncPoint();
139 void RetireSyncPoint(uint32 sync_point); 141 void RetireSyncPoint(uint32 sync_point);
142 void AddSyncPointCallback(uint32 sync_point, const base::Closure& callback);
140 143
141 bool IsSyncPointPassed(uint32 sync_point);
142 void WaitSyncPoint(uint32 sync_point); 144 void WaitSyncPoint(uint32 sync_point);
143 145
144 private: 146 private:
145 // This lock protects access to pending_sync_points_ and next_sync_point_ and 147 void OnSyncPointRetired();
146 // is used with the ConditionVariable to signal when a sync point is retired. 148
147 base::Lock lock_; 149 const scoped_refptr<SyncPointManager> manager_;
148 std::set<uint32> pending_sync_points_; 150 base::Lock retire_lock_;
149 uint32 next_sync_point_; 151 base::ConditionVariable retire_cond_var_;
150 base::ConditionVariable cond_var_; 152
153 DISALLOW_COPY_AND_ASSIGN(SyncPointManagerWrapper);
151 }; 154 };
152 155
153 SyncPointManager::SyncPointManager() : next_sync_point_(1), cond_var_(&lock_) {} 156 SyncPointManagerWrapper::SyncPointManagerWrapper()
154 157 : manager_(SyncPointManager::Create(true)),
155 SyncPointManager::~SyncPointManager() { 158 retire_cond_var_(&retire_lock_) {
156 DCHECK_EQ(pending_sync_points_.size(), 0U);
157 } 159 }
158 160
159 uint32 SyncPointManager::GenerateSyncPoint() { 161 uint32 SyncPointManagerWrapper::GenerateSyncPoint() {
160 base::AutoLock lock(lock_); 162 uint32 sync_point = manager_->GenerateSyncPoint();
161 uint32 sync_point = next_sync_point_++; 163 manager_->AddSyncPointCallback(
162 DCHECK_EQ(pending_sync_points_.count(sync_point), 0U); 164 sync_point, base::Bind(&SyncPointManagerWrapper::OnSyncPointRetired,
163 pending_sync_points_.insert(sync_point); 165 base::Unretained(this)));
164 return sync_point; 166 return sync_point;
165 } 167 }
166 168
167 void SyncPointManager::RetireSyncPoint(uint32 sync_point) { 169 void SyncPointManagerWrapper::RetireSyncPoint(uint32 sync_point) {
168 base::AutoLock lock(lock_); 170 manager_->RetireSyncPoint(sync_point);
169 DCHECK(pending_sync_points_.count(sync_point));
170 pending_sync_points_.erase(sync_point);
171 cond_var_.Broadcast();
172 } 171 }
173 172
174 bool SyncPointManager::IsSyncPointPassed(uint32 sync_point) { 173 void SyncPointManagerWrapper::AddSyncPointCallback(
175 base::AutoLock lock(lock_); 174 uint32 sync_point,
176 return pending_sync_points_.count(sync_point) == 0; 175 const base::Closure& callback) {
176 manager_->AddSyncPointCallback(sync_point, callback);
177 } 177 }
178 178
179 void SyncPointManager::WaitSyncPoint(uint32 sync_point) { 179 void SyncPointManagerWrapper::WaitSyncPoint(uint32 sync_point) {
180 base::AutoLock lock(lock_); 180 base::AutoLock lock(retire_lock_);
181 while (pending_sync_points_.count(sync_point)) { 181 while (!manager_->IsSyncPointRetired(sync_point)) {
182 cond_var_.Wait(); 182 retire_cond_var_.Wait();
183 } 183 }
184 } 184 }
185 185
186 base::LazyInstance<SyncPointManager> g_sync_point_manager = 186 void SyncPointManagerWrapper::OnSyncPointRetired() {
187 base::AutoLock lock(retire_lock_);
188 retire_cond_var_.Broadcast();
189 }
190
191 base::LazyInstance<SyncPointManagerWrapper> g_sync_point_manager =
187 LAZY_INSTANCE_INITIALIZER; 192 LAZY_INSTANCE_INITIALIZER;
188 193
189 base::SharedMemoryHandle ShareToGpuThread( 194 base::SharedMemoryHandle ShareToGpuThread(
190 base::SharedMemoryHandle source_handle) { 195 base::SharedMemoryHandle source_handle) {
191 #if defined(OS_WIN) 196 #if defined(OS_WIN)
192 // Windows needs to explicitly duplicate the handle to current process. 197 // Windows needs to explicitly duplicate the handle to current process.
193 base::SharedMemoryHandle target_handle; 198 base::SharedMemoryHandle target_handle;
194 if (!DuplicateHandle(GetCurrentProcess(), 199 if (!DuplicateHandle(GetCurrentProcess(),
195 source_handle, 200 source_handle,
196 GetCurrentProcess(), 201 GetCurrentProcess(),
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 g_sync_point_manager.Get().WaitSyncPoint(sync_point); 856 g_sync_point_manager.Get().WaitSyncPoint(sync_point);
852 gles2::MailboxManager* mailbox_manager = 857 gles2::MailboxManager* mailbox_manager =
853 decoder_->GetContextGroup()->mailbox_manager(); 858 decoder_->GetContextGroup()->mailbox_manager();
854 mailbox_manager->PullTextureUpdates(sync_point); 859 mailbox_manager->PullTextureUpdates(sync_point);
855 return true; 860 return true;
856 } 861 }
857 862
858 void InProcessCommandBuffer::SignalSyncPointOnGpuThread( 863 void InProcessCommandBuffer::SignalSyncPointOnGpuThread(
859 unsigned sync_point, 864 unsigned sync_point,
860 const base::Closure& callback) { 865 const base::Closure& callback) {
861 if (g_sync_point_manager.Get().IsSyncPointPassed(sync_point)) { 866 g_sync_point_manager.Get().AddSyncPointCallback(sync_point, callback);
862 callback.Run();
863 } else {
864 service_->ScheduleIdleWork(
865 base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread,
866 gpu_thread_weak_ptr_,
867 sync_point,
868 callback));
869 }
870 } 867 }
871 868
872 void InProcessCommandBuffer::SignalQuery(unsigned query_id, 869 void InProcessCommandBuffer::SignalQuery(unsigned query_id,
873 const base::Closure& callback) { 870 const base::Closure& callback) {
874 CheckSequencedThread(); 871 CheckSequencedThread();
875 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread, 872 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread,
876 base::Unretained(this), 873 base::Unretained(this),
877 query_id, 874 query_id,
878 WrapCallback(callback))); 875 WrapCallback(callback)));
879 } 876 }
(...skipping 19 matching lines...) Expand all
899 base::Callback<uint32(void)> task = 896 base::Callback<uint32(void)> task =
900 base::Bind(&InProcessCommandBuffer::CreateStreamTextureOnGpuThread, 897 base::Bind(&InProcessCommandBuffer::CreateStreamTextureOnGpuThread,
901 base::Unretained(this), 898 base::Unretained(this),
902 texture_id); 899 texture_id);
903 QueueTask( 900 QueueTask(
904 base::Bind(&RunTaskWithResult<uint32>, task, &stream_id, &completion)); 901 base::Bind(&RunTaskWithResult<uint32>, task, &stream_id, &completion));
905 completion.Wait(); 902 completion.Wait();
906 return stream_id; 903 return stream_id;
907 } 904 }
908 905
906 void InProcessCommandBuffer::SetLock(base::Lock*) {
907 }
908
909 uint32 InProcessCommandBuffer::CreateStreamTextureOnGpuThread( 909 uint32 InProcessCommandBuffer::CreateStreamTextureOnGpuThread(
910 uint32 client_texture_id) { 910 uint32 client_texture_id) {
911 #if defined(OS_ANDROID) 911 #if defined(OS_ANDROID)
912 return stream_texture_manager_->CreateStreamTexture( 912 return stream_texture_manager_->CreateStreamTexture(
913 client_texture_id, decoder_->GetContextGroup()->texture_manager()); 913 client_texture_id, decoder_->GetContextGroup()->texture_manager());
914 #else 914 #else
915 return 0; 915 return 0;
916 #endif 916 #endif
917 } 917 }
918 918
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 961
962 #if defined(OS_ANDROID) 962 #if defined(OS_ANDROID)
963 scoped_refptr<gfx::SurfaceTexture> 963 scoped_refptr<gfx::SurfaceTexture>
964 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { 964 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) {
965 DCHECK(stream_texture_manager_); 965 DCHECK(stream_texture_manager_);
966 return stream_texture_manager_->GetSurfaceTexture(stream_id); 966 return stream_texture_manager_->GetSurfaceTexture(stream_id);
967 } 967 }
968 #endif 968 #endif
969 969
970 } // namespace gpu 970 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/in_process_command_buffer.h ('k') | gpu/command_buffer/service/memory_program_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698