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

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: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SyncPointManager* GetSyncPointManager() {
133 public: 134 static base::LazyInstance<scoped_refptr<SyncPointManager>>
134 SyncPointManager(); 135 g_sync_point_manager = LAZY_INSTANCE_INITIALIZER;
135 ~SyncPointManager(); 136 if (!g_sync_point_manager.Get().get())
no sievers 2015/01/15 20:10:47 not thread-safe. you can probably just wrap the re
136 137 g_sync_point_manager.Get() = new SyncPointManager;
137 uint32 GenerateSyncPoint(); 138 return g_sync_point_manager.Get().get();
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 } 139 }
157 140
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;
187
188 base::SharedMemoryHandle ShareToGpuThread( 141 base::SharedMemoryHandle ShareToGpuThread(
189 base::SharedMemoryHandle source_handle) { 142 base::SharedMemoryHandle source_handle) {
190 #if defined(OS_WIN) 143 #if defined(OS_WIN)
191 // Windows needs to explicitly duplicate the handle to current process. 144 // Windows needs to explicitly duplicate the handle to current process.
192 base::SharedMemoryHandle target_handle; 145 base::SharedMemoryHandle target_handle;
193 if (!DuplicateHandle(GetCurrentProcess(), 146 if (!DuplicateHandle(GetCurrentProcess(),
194 source_handle, 147 source_handle,
195 GetCurrentProcess(), 148 GetCurrentProcess(),
196 &target_handle, 149 &target_handle,
197 FILE_GENERIC_READ | FILE_GENERIC_WRITE, 150 FILE_GENERIC_READ | FILE_GENERIC_WRITE,
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 gfx::Size(width, height), 736 gfx::Size(width, height),
784 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat), 737 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat),
785 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); 738 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage)));
786 if (!buffer) 739 if (!buffer)
787 return -1; 740 return -1;
788 741
789 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); 742 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat);
790 } 743 }
791 744
792 uint32 InProcessCommandBuffer::InsertSyncPoint() { 745 uint32 InProcessCommandBuffer::InsertSyncPoint() {
793 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); 746 uint32 sync_point = GetSyncPointManager()->GenerateSyncPoint();
794 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, 747 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread,
795 base::Unretained(this), 748 base::Unretained(this),
796 sync_point)); 749 sync_point));
797 return sync_point; 750 return sync_point;
798 } 751 }
799 752
800 uint32 InProcessCommandBuffer::InsertFutureSyncPoint() { 753 uint32 InProcessCommandBuffer::InsertFutureSyncPoint() {
801 return g_sync_point_manager.Get().GenerateSyncPoint(); 754 return GetSyncPointManager()->GenerateSyncPoint();
802 } 755 }
803 756
804 void InProcessCommandBuffer::RetireSyncPoint(uint32 sync_point) { 757 void InProcessCommandBuffer::RetireSyncPoint(uint32 sync_point) {
805 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, 758 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread,
806 base::Unretained(this), 759 base::Unretained(this),
807 sync_point)); 760 sync_point));
808 } 761 }
809 762
810 void InProcessCommandBuffer::RetireSyncPointOnGpuThread(uint32 sync_point) { 763 void InProcessCommandBuffer::RetireSyncPointOnGpuThread(uint32 sync_point) {
811 gles2::MailboxManager* mailbox_manager = 764 gles2::MailboxManager* mailbox_manager =
812 decoder_->GetContextGroup()->mailbox_manager(); 765 decoder_->GetContextGroup()->mailbox_manager();
813 if (mailbox_manager->UsesSync()) { 766 if (mailbox_manager->UsesSync()) {
814 bool make_current_success = false; 767 bool make_current_success = false;
815 { 768 {
816 base::AutoLock lock(command_buffer_lock_); 769 base::AutoLock lock(command_buffer_lock_);
817 make_current_success = MakeCurrent(); 770 make_current_success = MakeCurrent();
818 } 771 }
819 if (make_current_success) 772 if (make_current_success)
820 mailbox_manager->PushTextureUpdates(sync_point); 773 mailbox_manager->PushTextureUpdates(sync_point);
821 } 774 }
822 g_sync_point_manager.Get().RetireSyncPoint(sync_point); 775 GetSyncPointManager()->RetireSyncPoint(sync_point);
823 } 776 }
824 777
825 void InProcessCommandBuffer::SignalSyncPoint(unsigned sync_point, 778 void InProcessCommandBuffer::SignalSyncPoint(unsigned sync_point,
826 const base::Closure& callback) { 779 const base::Closure& callback) {
827 CheckSequencedThread(); 780 CheckSequencedThread();
828 QueueTask(base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread, 781 QueueTask(base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread,
829 base::Unretained(this), 782 base::Unretained(this),
830 sync_point, 783 sync_point,
831 WrapCallback(callback))); 784 WrapCallback(callback)));
832 } 785 }
833 786
834 bool InProcessCommandBuffer::WaitSyncPointOnGpuThread(unsigned sync_point) { 787 bool InProcessCommandBuffer::WaitSyncPointOnGpuThread(unsigned sync_point) {
835 g_sync_point_manager.Get().WaitSyncPoint(sync_point); 788 // GetSyncPointManager()->WaitSyncPoint(sync_point); TODO(boliu)
836 gles2::MailboxManager* mailbox_manager = 789 gles2::MailboxManager* mailbox_manager =
837 decoder_->GetContextGroup()->mailbox_manager(); 790 decoder_->GetContextGroup()->mailbox_manager();
838 mailbox_manager->PullTextureUpdates(sync_point); 791 mailbox_manager->PullTextureUpdates(sync_point);
839 return true; 792 return true;
840 } 793 }
841 794
842 void InProcessCommandBuffer::SignalSyncPointOnGpuThread( 795 void InProcessCommandBuffer::SignalSyncPointOnGpuThread(
843 unsigned sync_point, 796 unsigned sync_point,
844 const base::Closure& callback) { 797 const base::Closure& callback) {
845 if (g_sync_point_manager.Get().IsSyncPointPassed(sync_point)) { 798 GetSyncPointManager()->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 } 799 }
855 800
856 void InProcessCommandBuffer::SignalQuery(unsigned query_id, 801 void InProcessCommandBuffer::SignalQuery(unsigned query_id,
857 const base::Closure& callback) { 802 const base::Closure& callback) {
858 CheckSequencedThread(); 803 CheckSequencedThread();
859 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread, 804 QueueTask(base::Bind(&InProcessCommandBuffer::SignalQueryOnGpuThread,
860 base::Unretained(this), 805 base::Unretained(this),
861 query_id, 806 query_id,
862 WrapCallback(callback))); 807 WrapCallback(callback)));
863 } 808 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 890
946 #if defined(OS_ANDROID) 891 #if defined(OS_ANDROID)
947 scoped_refptr<gfx::SurfaceTexture> 892 scoped_refptr<gfx::SurfaceTexture>
948 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { 893 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) {
949 DCHECK(stream_texture_manager_); 894 DCHECK(stream_texture_manager_);
950 return stream_texture_manager_->GetSurfaceTexture(stream_id); 895 return stream_texture_manager_->GetSurfaceTexture(stream_id);
951 } 896 }
952 #endif 897 #endif
953 898
954 } // namespace gpu 899 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698