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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/service/in_process_command_buffer.cc
diff --git a/gpu/command_buffer/service/in_process_command_buffer.cc b/gpu/command_buffer/service/in_process_command_buffer.cc
index c3123457f64ff1c42bbffcef368c49d86ba3f149..f065b5217b288f8f31900cd1b0a62adce3fe833f 100644
--- a/gpu/command_buffer/service/in_process_command_buffer.cc
+++ b/gpu/command_buffer/service/in_process_command_buffer.cc
@@ -31,6 +31,7 @@
#include "gpu/command_buffer/service/mailbox_manager_sync.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/query_manager.h"
+#include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/command_buffer/service/transfer_buffer_manager.h"
#include "gpu/command_buffer/service/valuebuffer_manager.h"
#include "ui/gfx/geometry/size.h"
@@ -129,62 +130,14 @@ class ScopedEvent {
base::WaitableEvent* event_;
};
-class SyncPointManager {
- public:
- SyncPointManager();
- ~SyncPointManager();
-
- uint32 GenerateSyncPoint();
- void RetireSyncPoint(uint32 sync_point);
-
- bool IsSyncPointPassed(uint32 sync_point);
- void WaitSyncPoint(uint32 sync_point);
-
-private:
- // This lock protects access to pending_sync_points_ and next_sync_point_ and
- // is used with the ConditionVariable to signal when a sync point is retired.
- base::Lock lock_;
- std::set<uint32> pending_sync_points_;
- uint32 next_sync_point_;
- base::ConditionVariable cond_var_;
-};
-
-SyncPointManager::SyncPointManager() : next_sync_point_(1), cond_var_(&lock_) {}
-
-SyncPointManager::~SyncPointManager() {
- DCHECK_EQ(pending_sync_points_.size(), 0U);
-}
-
-uint32 SyncPointManager::GenerateSyncPoint() {
- base::AutoLock lock(lock_);
- uint32 sync_point = next_sync_point_++;
- DCHECK_EQ(pending_sync_points_.count(sync_point), 0U);
- pending_sync_points_.insert(sync_point);
- return sync_point;
+SyncPointManager* GetSyncPointManager() {
+ static base::LazyInstance<scoped_refptr<SyncPointManager>>
+ g_sync_point_manager = LAZY_INSTANCE_INITIALIZER;
+ 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
+ g_sync_point_manager.Get() = new SyncPointManager;
+ return g_sync_point_manager.Get().get();
}
-void SyncPointManager::RetireSyncPoint(uint32 sync_point) {
- base::AutoLock lock(lock_);
- DCHECK(pending_sync_points_.count(sync_point));
- pending_sync_points_.erase(sync_point);
- cond_var_.Broadcast();
-}
-
-bool SyncPointManager::IsSyncPointPassed(uint32 sync_point) {
- base::AutoLock lock(lock_);
- return pending_sync_points_.count(sync_point) == 0;
-}
-
-void SyncPointManager::WaitSyncPoint(uint32 sync_point) {
- base::AutoLock lock(lock_);
- while (pending_sync_points_.count(sync_point)) {
- cond_var_.Wait();
- }
-}
-
-base::LazyInstance<SyncPointManager> g_sync_point_manager =
- LAZY_INSTANCE_INITIALIZER;
-
base::SharedMemoryHandle ShareToGpuThread(
base::SharedMemoryHandle source_handle) {
#if defined(OS_WIN)
@@ -790,7 +743,7 @@ int32 InProcessCommandBuffer::CreateGpuMemoryBufferImage(
}
uint32 InProcessCommandBuffer::InsertSyncPoint() {
- uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint();
+ uint32 sync_point = GetSyncPointManager()->GenerateSyncPoint();
QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread,
base::Unretained(this),
sync_point));
@@ -798,7 +751,7 @@ uint32 InProcessCommandBuffer::InsertSyncPoint() {
}
uint32 InProcessCommandBuffer::InsertFutureSyncPoint() {
- return g_sync_point_manager.Get().GenerateSyncPoint();
+ return GetSyncPointManager()->GenerateSyncPoint();
}
void InProcessCommandBuffer::RetireSyncPoint(uint32 sync_point) {
@@ -819,7 +772,7 @@ void InProcessCommandBuffer::RetireSyncPointOnGpuThread(uint32 sync_point) {
if (make_current_success)
mailbox_manager->PushTextureUpdates(sync_point);
}
- g_sync_point_manager.Get().RetireSyncPoint(sync_point);
+ GetSyncPointManager()->RetireSyncPoint(sync_point);
}
void InProcessCommandBuffer::SignalSyncPoint(unsigned sync_point,
@@ -832,7 +785,7 @@ void InProcessCommandBuffer::SignalSyncPoint(unsigned sync_point,
}
bool InProcessCommandBuffer::WaitSyncPointOnGpuThread(unsigned sync_point) {
- g_sync_point_manager.Get().WaitSyncPoint(sync_point);
+ // GetSyncPointManager()->WaitSyncPoint(sync_point); TODO(boliu)
gles2::MailboxManager* mailbox_manager =
decoder_->GetContextGroup()->mailbox_manager();
mailbox_manager->PullTextureUpdates(sync_point);
@@ -842,15 +795,7 @@ bool InProcessCommandBuffer::WaitSyncPointOnGpuThread(unsigned sync_point) {
void InProcessCommandBuffer::SignalSyncPointOnGpuThread(
unsigned sync_point,
const base::Closure& callback) {
- if (g_sync_point_manager.Get().IsSyncPointPassed(sync_point)) {
- callback.Run();
- } else {
- service_->ScheduleIdleWork(
- base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread,
- gpu_thread_weak_ptr_,
- sync_point,
- callback));
- }
+ GetSyncPointManager()->AddSyncPointCallback(sync_point, callback);
}
void InProcessCommandBuffer::SignalQuery(unsigned query_id,
« 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