| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stdint.h> | |
| 6 | |
| 7 #include "gpu/command_buffer/service/gl_utils.h" | |
| 8 #include "gpu/command_buffer/service/program_manager.h" | |
| 9 #include "gpu/command_buffer/service/valuebuffer_manager.h" | |
| 10 | |
| 11 namespace gpu { | |
| 12 namespace gles2 { | |
| 13 | |
| 14 SubscriptionRefSet::Observer::~Observer() { | |
| 15 } | |
| 16 | |
| 17 SubscriptionRefSet::SubscriptionRefSet() { | |
| 18 } | |
| 19 | |
| 20 SubscriptionRefSet::~SubscriptionRefSet() { | |
| 21 // Make sure no valuebuffers are still holding references to targets | |
| 22 DCHECK(reference_set_.empty()); | |
| 23 } | |
| 24 | |
| 25 void SubscriptionRefSet::AddSubscription(unsigned int target) { | |
| 26 RefSet::iterator it = reference_set_.find(target); | |
| 27 if (it == reference_set_.end()) { | |
| 28 reference_set_.insert(std::make_pair(target, 1)); | |
| 29 FOR_EACH_OBSERVER(Observer, observers_, OnAddSubscription(target)); | |
| 30 } else { | |
| 31 ++it->second; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 void SubscriptionRefSet::RemoveSubscription(unsigned int target) { | |
| 36 RefSet::iterator it = reference_set_.find(target); | |
| 37 DCHECK(it != reference_set_.end()); | |
| 38 if (it->second == 1) { | |
| 39 reference_set_.erase(it); | |
| 40 FOR_EACH_OBSERVER(Observer, observers_, OnRemoveSubscription(target)); | |
| 41 } else { | |
| 42 --it->second; | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void SubscriptionRefSet::AddObserver(Observer* observer) { | |
| 47 observers_.AddObserver(observer); | |
| 48 } | |
| 49 | |
| 50 void SubscriptionRefSet::RemoveObserver(Observer* observer) { | |
| 51 observers_.RemoveObserver(observer); | |
| 52 } | |
| 53 | |
| 54 Valuebuffer::Valuebuffer(ValuebufferManager* manager, unsigned int client_id) | |
| 55 : manager_(manager), client_id_(client_id), has_been_bound_(false) { | |
| 56 manager_->StartTracking(this); | |
| 57 active_state_map_ = new ValueStateMap(); | |
| 58 } | |
| 59 | |
| 60 Valuebuffer::~Valuebuffer() { | |
| 61 if (manager_) { | |
| 62 for (SubscriptionSet::const_iterator it = subscriptions_.begin(); | |
| 63 it != subscriptions_.end(); ++it) { | |
| 64 manager_->NotifyRemoveSubscription(*it); | |
| 65 } | |
| 66 manager_->StopTracking(this); | |
| 67 manager_ = NULL; | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 void Valuebuffer::AddSubscription(unsigned int subscription) { | |
| 72 if (subscriptions_.find(subscription) == subscriptions_.end()) { | |
| 73 subscriptions_.insert(subscription); | |
| 74 manager_->NotifyAddSubscription(subscription); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 void Valuebuffer::RemoveSubscription(unsigned int subscription) { | |
| 79 SubscriptionSet::iterator it = subscriptions_.find(subscription); | |
| 80 if (subscriptions_.find(subscription) != subscriptions_.end()) { | |
| 81 subscriptions_.erase(it); | |
| 82 manager_->NotifyRemoveSubscription(subscription); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 bool Valuebuffer::IsSubscribed(unsigned int subscription) { | |
| 87 return subscriptions_.find(subscription) != subscriptions_.end(); | |
| 88 } | |
| 89 | |
| 90 const ValueState* Valuebuffer::GetState(unsigned int target) const { | |
| 91 return active_state_map_->GetState(target); | |
| 92 } | |
| 93 | |
| 94 void Valuebuffer::UpdateState(const ValueStateMap* pending_state) { | |
| 95 DCHECK(pending_state); | |
| 96 for (SubscriptionSet::const_iterator it = subscriptions_.begin(); | |
| 97 it != subscriptions_.end(); ++it) { | |
| 98 const ValueState *state = pending_state->GetState(*it); | |
| 99 if (state != NULL) { | |
| 100 active_state_map_->UpdateState(*it, *state); | |
| 101 } | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 ValuebufferManager::ValuebufferManager(SubscriptionRefSet* ref_set, | |
| 106 ValueStateMap* state_map) | |
| 107 : valuebuffer_count_(0), | |
| 108 pending_state_map_(state_map), | |
| 109 subscription_ref_set_(ref_set) { | |
| 110 } | |
| 111 | |
| 112 ValuebufferManager::~ValuebufferManager() { | |
| 113 DCHECK(valuebuffer_map_.empty()); | |
| 114 // If this triggers, that means something is keeping a reference to | |
| 115 // a Valuebuffer belonging to this. | |
| 116 CHECK_EQ(valuebuffer_count_, 0u); | |
| 117 } | |
| 118 | |
| 119 void ValuebufferManager::Destroy() { | |
| 120 valuebuffer_map_.clear(); | |
| 121 } | |
| 122 | |
| 123 void ValuebufferManager::StartTracking(Valuebuffer* /* valuebuffer */) { | |
| 124 ++valuebuffer_count_; | |
| 125 } | |
| 126 | |
| 127 void ValuebufferManager::StopTracking(Valuebuffer* /* valuebuffer */) { | |
| 128 --valuebuffer_count_; | |
| 129 } | |
| 130 | |
| 131 void ValuebufferManager::NotifyAddSubscription(unsigned int target) { | |
| 132 subscription_ref_set_->AddSubscription(target); | |
| 133 } | |
| 134 void ValuebufferManager::NotifyRemoveSubscription(unsigned int target) { | |
| 135 subscription_ref_set_->RemoveSubscription(target); | |
| 136 } | |
| 137 | |
| 138 void ValuebufferManager::CreateValuebuffer(unsigned int client_id) { | |
| 139 scoped_refptr<Valuebuffer> valuebuffer(new Valuebuffer(this, client_id)); | |
| 140 std::pair<ValuebufferMap::iterator, bool> result = | |
| 141 valuebuffer_map_.insert(std::make_pair(client_id, valuebuffer)); | |
| 142 DCHECK(result.second); | |
| 143 } | |
| 144 | |
| 145 Valuebuffer* ValuebufferManager::GetValuebuffer(unsigned int client_id) { | |
| 146 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); | |
| 147 return it != valuebuffer_map_.end() ? it->second.get() : NULL; | |
| 148 } | |
| 149 | |
| 150 void ValuebufferManager::RemoveValuebuffer(unsigned int client_id) { | |
| 151 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); | |
| 152 if (it != valuebuffer_map_.end()) { | |
| 153 Valuebuffer* valuebuffer = it->second.get(); | |
| 154 valuebuffer->MarkAsDeleted(); | |
| 155 valuebuffer_map_.erase(it); | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 void ValuebufferManager::UpdateValuebufferState(Valuebuffer* valuebuffer) { | |
| 160 DCHECK(valuebuffer); | |
| 161 valuebuffer->UpdateState(pending_state_map_.get()); | |
| 162 } | |
| 163 | |
| 164 uint32_t ValuebufferManager::ApiTypeForSubscriptionTarget(unsigned int target) { | |
| 165 switch (target) { | |
| 166 case GL_MOUSE_POSITION_CHROMIUM: | |
| 167 return Program::kUniform2i; | |
| 168 } | |
| 169 NOTREACHED() << "Unhandled uniform subscription target " << target; | |
| 170 return Program::kUniformNone; | |
| 171 } | |
| 172 | |
| 173 } // namespace gles2 | |
| 174 } // namespace gpu | |
| OLD | NEW |