Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync_point_manager.h" | 5 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 6 | 6 |
| 7 #include <climits> | 7 #include <climits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/sequence_checker.h" | |
| 13 #include "gpu/command_buffer/service/gpu_switches.h" | |
| 11 | 14 |
| 12 namespace gpu { | 15 namespace gpu { |
| 13 | 16 |
| 14 static const int kMaxSyncBase = INT_MAX; | 17 static const int kMaxSyncBase = INT_MAX; |
| 15 | 18 |
| 16 SyncPointManager::SyncPointManager() | 19 SyncPointManager::SyncPointManager() |
| 17 : next_sync_point_(base::RandInt(1, kMaxSyncBase)) { | 20 : next_sync_point_(base::RandInt(1, kMaxSyncBase)) { |
| 18 // To reduce the risk that a sync point created in a previous GPU process | 21 // To reduce the risk that a sync point created in a previous GPU process |
| 19 // will be in flight in the next GPU process, randomize the starting sync | 22 // will be in flight in the next GPU process, randomize the starting sync |
| 20 // point number. http://crbug.com/373452 | 23 // point number. http://crbug.com/373452 |
| 24 | |
|
no sievers
2015/02/05 21:55:04
nit: put a comment saying that this is because we'
boliu
2015/02/05 23:50:44
Done.
| |
| 25 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 26 switches::kEnableThreadedTextureMailboxes)) { | |
| 27 sequence_checker_.reset(new base::SequenceChecker); | |
| 28 } | |
| 21 } | 29 } |
| 22 | 30 |
| 23 SyncPointManager::~SyncPointManager() { | 31 SyncPointManager::~SyncPointManager() { |
| 24 } | 32 } |
| 25 | 33 |
| 26 uint32 SyncPointManager::GenerateSyncPoint() { | 34 uint32 SyncPointManager::GenerateSyncPoint() { |
| 27 base::AutoLock lock(lock_); | 35 base::AutoLock lock(lock_); |
| 28 uint32 sync_point = next_sync_point_++; | 36 uint32 sync_point = next_sync_point_++; |
| 29 // When an integer overflow occurs, don't return 0. | 37 // When an integer overflow occurs, don't return 0. |
| 30 if (!sync_point) | 38 if (!sync_point) |
| 31 sync_point = next_sync_point_++; | 39 sync_point = next_sync_point_++; |
| 32 | 40 |
| 33 // Note: wrapping would take days for a buggy/compromized renderer that would | 41 // Note: wrapping would take days for a buggy/compromized renderer that would |
| 34 // insert sync points in a loop, but if that were to happen, better explicitly | 42 // insert sync points in a loop, but if that were to happen, better explicitly |
| 35 // crash the GPU process than risk worse. | 43 // crash the GPU process than risk worse. |
| 36 // For normal operation (at most a few per frame), it would take ~a year to | 44 // For normal operation (at most a few per frame), it would take ~a year to |
| 37 // wrap. | 45 // wrap. |
| 38 CHECK(sync_point_map_.find(sync_point) == sync_point_map_.end()); | 46 CHECK(sync_point_map_.find(sync_point) == sync_point_map_.end()); |
| 39 sync_point_map_.insert(std::make_pair(sync_point, ClosureList())); | 47 sync_point_map_.insert(std::make_pair(sync_point, ClosureList())); |
| 40 return sync_point; | 48 return sync_point; |
| 41 } | 49 } |
| 42 | 50 |
| 43 void SyncPointManager::RetireSyncPoint(uint32 sync_point) { | 51 void SyncPointManager::RetireSyncPoint(uint32 sync_point) { |
| 44 DCHECK(thread_checker_.CalledOnValidThread()); | 52 CheckSequencedThread(); |
| 45 ClosureList list; | 53 ClosureList list; |
| 46 { | 54 { |
| 47 base::AutoLock lock(lock_); | 55 base::AutoLock lock(lock_); |
| 48 SyncPointMap::iterator it = sync_point_map_.find(sync_point); | 56 SyncPointMap::iterator it = sync_point_map_.find(sync_point); |
| 49 if (it == sync_point_map_.end()) { | 57 if (it == sync_point_map_.end()) { |
| 50 LOG(ERROR) << "Attempted to retire sync point that" | 58 LOG(ERROR) << "Attempted to retire sync point that" |
| 51 " didn't exist or was already retired."; | 59 " didn't exist or was already retired."; |
| 52 return; | 60 return; |
| 53 } | 61 } |
| 54 list.swap(it->second); | 62 list.swap(it->second); |
| 55 sync_point_map_.erase(it); | 63 sync_point_map_.erase(it); |
| 56 } | 64 } |
| 57 for (ClosureList::iterator i = list.begin(); i != list.end(); ++i) | 65 for (ClosureList::iterator i = list.begin(); i != list.end(); ++i) |
| 58 i->Run(); | 66 i->Run(); |
| 59 } | 67 } |
| 60 | 68 |
| 61 void SyncPointManager::AddSyncPointCallback(uint32 sync_point, | 69 void SyncPointManager::AddSyncPointCallback(uint32 sync_point, |
| 62 const base::Closure& callback) { | 70 const base::Closure& callback) { |
| 63 DCHECK(thread_checker_.CalledOnValidThread()); | 71 CheckSequencedThread(); |
| 64 { | 72 { |
| 65 base::AutoLock lock(lock_); | 73 base::AutoLock lock(lock_); |
| 66 SyncPointMap::iterator it = sync_point_map_.find(sync_point); | 74 SyncPointMap::iterator it = sync_point_map_.find(sync_point); |
| 67 if (it != sync_point_map_.end()) { | 75 if (it != sync_point_map_.end()) { |
| 68 it->second.push_back(callback); | 76 it->second.push_back(callback); |
| 69 return; | 77 return; |
| 70 } | 78 } |
| 71 } | 79 } |
| 72 callback.Run(); | 80 callback.Run(); |
| 73 } | 81 } |
| 74 | 82 |
| 75 bool SyncPointManager::IsSyncPointRetired(uint32 sync_point) { | 83 bool SyncPointManager::IsSyncPointRetired(uint32 sync_point) { |
| 76 DCHECK(thread_checker_.CalledOnValidThread()); | 84 CheckSequencedThread(); |
| 77 { | 85 { |
| 78 base::AutoLock lock(lock_); | 86 base::AutoLock lock(lock_); |
| 79 SyncPointMap::iterator it = sync_point_map_.find(sync_point); | 87 SyncPointMap::iterator it = sync_point_map_.find(sync_point); |
| 80 return it == sync_point_map_.end(); | 88 return it == sync_point_map_.end(); |
| 81 } | 89 } |
| 82 } | 90 } |
| 83 | 91 |
| 92 void SyncPointManager::CheckSequencedThread() { | |
| 93 DCHECK(!sequence_checker_ || | |
| 94 sequence_checker_->CalledOnValidSequencedThread()); | |
| 95 } | |
| 96 | |
| 84 } // namespace gpu | 97 } // namespace gpu |
| OLD | NEW |