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

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

Issue 816543004: Update from https://crrev.com/308996 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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/gl_utils.h" 5 #include "gpu/command_buffer/service/gl_utils.h"
6 #include "gpu/command_buffer/service/program_manager.h" 6 #include "gpu/command_buffer/service/program_manager.h"
7 #include "gpu/command_buffer/service/valuebuffer_manager.h" 7 #include "gpu/command_buffer/service/valuebuffer_manager.h"
8 8
9 namespace gpu { 9 namespace gpu {
10 namespace gles2 { 10 namespace gles2 {
11 11
12 SubscriptionRefSet::Observer::~Observer() {
13 }
14
15 SubscriptionRefSet::SubscriptionRefSet() {
16 }
17
18 SubscriptionRefSet::~SubscriptionRefSet() {
19 // Make sure no valuebuffers are still holding references to targets
20 DCHECK(reference_set_.empty());
21 }
22
23 void SubscriptionRefSet::AddSubscription(unsigned int target) {
24 RefSet::iterator it = reference_set_.find(target);
25 if (it == reference_set_.end()) {
26 reference_set_.insert(std::make_pair(target, 1));
27 FOR_EACH_OBSERVER(Observer, observers_, OnAddSubscription(target));
28 } else {
29 ++it->second;
30 }
31 }
32
33 void SubscriptionRefSet::RemoveSubscription(unsigned int target) {
34 RefSet::iterator it = reference_set_.find(target);
35 DCHECK(it != reference_set_.end());
36 if (it->second == 1) {
37 reference_set_.erase(it);
38 FOR_EACH_OBSERVER(Observer, observers_, OnRemoveSubscription(target));
39 } else {
40 --it->second;
41 }
42 }
43
44 void SubscriptionRefSet::AddObserver(Observer* observer) {
45 observers_.AddObserver(observer);
46 }
47
48 void SubscriptionRefSet::RemoveObserver(Observer* observer) {
49 observers_.RemoveObserver(observer);
50 }
51
12 Valuebuffer::Valuebuffer(ValuebufferManager* manager, unsigned int client_id) 52 Valuebuffer::Valuebuffer(ValuebufferManager* manager, unsigned int client_id)
13 : manager_(manager), client_id_(client_id), has_been_bound_(false) { 53 : manager_(manager), client_id_(client_id), has_been_bound_(false) {
14 manager_->StartTracking(this); 54 manager_->StartTracking(this);
15 active_state_map_ = new ValueStateMap(); 55 active_state_map_ = new ValueStateMap();
16 } 56 }
17 57
18 Valuebuffer::~Valuebuffer() { 58 Valuebuffer::~Valuebuffer() {
19 if (manager_) { 59 if (manager_) {
60 for (SubscriptionSet::const_iterator it = subscriptions_.begin();
61 it != subscriptions_.end(); ++it) {
62 manager_->NotifyRemoveSubscription(*it);
63 }
20 manager_->StopTracking(this); 64 manager_->StopTracking(this);
21 manager_ = NULL; 65 manager_ = NULL;
22 } 66 }
23 } 67 }
24 68
25 void Valuebuffer::AddSubscription(unsigned int subscription) { 69 void Valuebuffer::AddSubscription(unsigned int subscription) {
26 subscriptions_.insert(subscription); 70 if (subscriptions_.find(subscription) == subscriptions_.end()) {
71 subscriptions_.insert(subscription);
72 manager_->NotifyAddSubscription(subscription);
73 }
27 } 74 }
28 75
29 void Valuebuffer::RemoveSubscription(unsigned int subscription) { 76 void Valuebuffer::RemoveSubscription(unsigned int subscription) {
30 subscriptions_.erase(subscription); 77 SubscriptionSet::iterator it = subscriptions_.find(subscription);
78 if (subscriptions_.find(subscription) != subscriptions_.end()) {
79 subscriptions_.erase(it);
80 manager_->NotifyRemoveSubscription(subscription);
81 }
31 } 82 }
32 83
33 bool Valuebuffer::IsSubscribed(unsigned int subscription) { 84 bool Valuebuffer::IsSubscribed(unsigned int subscription) {
34 return subscriptions_.find(subscription) != subscriptions_.end(); 85 return subscriptions_.find(subscription) != subscriptions_.end();
35 } 86 }
36 87
37 const ValueState* Valuebuffer::GetState(unsigned int target) const { 88 const ValueState* Valuebuffer::GetState(unsigned int target) const {
38 return active_state_map_->GetState(target); 89 return active_state_map_->GetState(target);
39 } 90 }
40 91
41 void Valuebuffer::UpdateState(const ValueStateMap* pending_state) { 92 void Valuebuffer::UpdateState(const ValueStateMap* pending_state) {
42 DCHECK(pending_state); 93 DCHECK(pending_state);
43 for (SubscriptionSet::const_iterator it = subscriptions_.begin(); 94 for (SubscriptionSet::const_iterator it = subscriptions_.begin();
44 it != subscriptions_.end(); ++it) { 95 it != subscriptions_.end(); ++it) {
45 const ValueState *state = pending_state->GetState(*it); 96 const ValueState *state = pending_state->GetState(*it);
46 if (state != NULL) { 97 if (state != NULL) {
47 active_state_map_->UpdateState(*it, *state); 98 active_state_map_->UpdateState(*it, *state);
48 } 99 }
49 } 100 }
50 } 101 }
51 102
52 ValuebufferManager::ValuebufferManager(ValueStateMap* state_map) 103 ValuebufferManager::ValuebufferManager(SubscriptionRefSet* ref_set,
104 ValueStateMap* state_map)
53 : valuebuffer_count_(0), 105 : valuebuffer_count_(0),
54 pending_state_map_(state_map) { 106 pending_state_map_(state_map),
107 subscription_ref_set_(ref_set) {
55 } 108 }
56 109
57 ValuebufferManager::~ValuebufferManager() { 110 ValuebufferManager::~ValuebufferManager() {
58 DCHECK(valuebuffer_map_.empty()); 111 DCHECK(valuebuffer_map_.empty());
59 // If this triggers, that means something is keeping a reference to 112 // If this triggers, that means something is keeping a reference to
60 // a Valuebuffer belonging to this. 113 // a Valuebuffer belonging to this.
61 CHECK_EQ(valuebuffer_count_, 0u); 114 CHECK_EQ(valuebuffer_count_, 0u);
62 } 115 }
63 116
64 void ValuebufferManager::Destroy() { 117 void ValuebufferManager::Destroy() {
65 valuebuffer_map_.clear(); 118 valuebuffer_map_.clear();
66 } 119 }
67 120
68 void ValuebufferManager::StartTracking(Valuebuffer* /* valuebuffer */) { 121 void ValuebufferManager::StartTracking(Valuebuffer* /* valuebuffer */) {
69 ++valuebuffer_count_; 122 ++valuebuffer_count_;
70 } 123 }
71 124
72 void ValuebufferManager::StopTracking(Valuebuffer* /* valuebuffer */) { 125 void ValuebufferManager::StopTracking(Valuebuffer* /* valuebuffer */) {
73 --valuebuffer_count_; 126 --valuebuffer_count_;
74 } 127 }
75 128
129 void ValuebufferManager::NotifyAddSubscription(unsigned int target) {
130 subscription_ref_set_->AddSubscription(target);
131 }
132 void ValuebufferManager::NotifyRemoveSubscription(unsigned int target) {
133 subscription_ref_set_->RemoveSubscription(target);
134 }
135
76 void ValuebufferManager::CreateValuebuffer(unsigned int client_id) { 136 void ValuebufferManager::CreateValuebuffer(unsigned int client_id) {
77 scoped_refptr<Valuebuffer> valuebuffer(new Valuebuffer(this, client_id)); 137 scoped_refptr<Valuebuffer> valuebuffer(new Valuebuffer(this, client_id));
78 std::pair<ValuebufferMap::iterator, bool> result = 138 std::pair<ValuebufferMap::iterator, bool> result =
79 valuebuffer_map_.insert(std::make_pair(client_id, valuebuffer)); 139 valuebuffer_map_.insert(std::make_pair(client_id, valuebuffer));
80 DCHECK(result.second); 140 DCHECK(result.second);
81 } 141 }
82 142
83 Valuebuffer* ValuebufferManager::GetValuebuffer(unsigned int client_id) { 143 Valuebuffer* ValuebufferManager::GetValuebuffer(unsigned int client_id) {
84 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); 144 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id);
85 return it != valuebuffer_map_.end() ? it->second.get() : NULL; 145 return it != valuebuffer_map_.end() ? it->second.get() : NULL;
(...skipping 17 matching lines...) Expand all
103 switch (target) { 163 switch (target) {
104 case GL_MOUSE_POSITION_CHROMIUM: 164 case GL_MOUSE_POSITION_CHROMIUM:
105 return Program::kUniform2i; 165 return Program::kUniform2i;
106 } 166 }
107 NOTREACHED() << "Unhandled uniform subscription target " << target; 167 NOTREACHED() << "Unhandled uniform subscription target " << target;
108 return Program::kUniformNone; 168 return Program::kUniformNone;
109 } 169 }
110 170
111 } // namespace gles2 171 } // namespace gles2
112 } // namespace gpu 172 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/valuebuffer_manager.h ('k') | gpu/command_buffer/service/valuebuffer_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698