OLD | NEW |
---|---|
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/valuebuffer_manager.h" | 5 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
6 #include "gpu/command_buffer/service/gl_utils.h" | |
6 | 7 |
7 #include "gpu/command_buffer/service/program_manager.h" | 8 #include "gpu/command_buffer/service/program_manager.h" |
8 | 9 |
9 namespace gpu { | 10 namespace gpu { |
10 namespace gles2 { | 11 namespace gles2 { |
11 | 12 |
12 Valuebuffer::Valuebuffer(ValuebufferManager* manager, GLuint client_id) | 13 Valuebuffer::Valuebuffer(ValuebufferManager* manager, unsigned int client_id) |
13 : manager_(manager), client_id_(client_id), has_been_bound_(false) { | 14 : manager_(manager), client_id_(client_id), has_been_bound_(false) { |
14 manager_->StartTracking(this); | 15 manager_->StartTracking(this); |
15 } | 16 } |
16 | 17 |
17 Valuebuffer::~Valuebuffer() { | 18 Valuebuffer::~Valuebuffer() { |
18 if (manager_) { | 19 if (manager_) { |
19 manager_->StopTracking(this); | 20 manager_->StopTracking(this); |
20 manager_ = NULL; | 21 manager_ = NULL; |
21 } | 22 } |
22 } | 23 } |
23 | 24 |
24 void Valuebuffer::AddSubscription(GLenum subscription) { | 25 void Valuebuffer::AddSubscription(unsigned int subscription) { |
25 subscriptions_.insert(subscription); | 26 subscriptions_.insert(subscription); |
26 } | 27 } |
27 | 28 |
28 void Valuebuffer::RemoveSubscription(GLenum subscription) { | 29 void Valuebuffer::RemoveSubscription(unsigned int subscription) { |
29 subscriptions_.erase(subscription); | 30 subscriptions_.erase(subscription); |
30 } | 31 } |
31 | 32 |
32 bool Valuebuffer::IsSubscribed(GLenum subscription) { | 33 bool Valuebuffer::IsSubscribed(unsigned int subscription) { |
33 return subscriptions_.find(subscription) != subscriptions_.end(); | 34 return subscriptions_.find(subscription) != subscriptions_.end(); |
34 } | 35 } |
35 | 36 |
36 const ValueState *Valuebuffer::GetState(GLenum target) const { | 37 const ValueState *Valuebuffer::GetState(unsigned int target) const { |
37 StateMap::const_iterator it = active_state_map_.find(target); | 38 StateMap::const_iterator it = active_state_map_.find(target); |
38 return it != active_state_map_.end() ? &it->second : NULL; | 39 return it != active_state_map_.end() ? &it->second : NULL; |
39 } | 40 } |
40 | 41 |
41 void Valuebuffer::UpdateState(const StateMap& pending_state) { | 42 void Valuebuffer::UpdateState(const StateMap& pending_state) { |
42 for (SubscriptionSet::const_iterator it = subscriptions_.begin(); | 43 for (SubscriptionSet::const_iterator it = subscriptions_.begin(); |
43 it != subscriptions_.end(); ++it) { | 44 it != subscriptions_.end(); ++it) { |
44 StateMap::const_iterator pending_state_it = pending_state.find((*it)); | 45 StateMap::const_iterator pending_state_it = pending_state.find((*it)); |
45 if (pending_state_it != pending_state.end()) { | 46 if (pending_state_it != pending_state.end()) { |
46 active_state_map_[pending_state_it->first] = pending_state_it->second; | 47 active_state_map_[pending_state_it->first] = pending_state_it->second; |
47 } | 48 } |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 ValuebufferManager::ValuebufferManager() | 52 ValuebufferManager::ValuebufferManager() |
52 : valuebuffer_count_(0) { | 53 : valuebuffer_count_(0) { |
53 } | 54 } |
54 | 55 |
55 ValuebufferManager::~ValuebufferManager() { | 56 ValuebufferManager::~ValuebufferManager() { |
56 DCHECK(valuebuffer_map_.empty()); | 57 valuebuffer_map_.clear(); |
57 DCHECK(pending_state_map_.empty()); | 58 pending_state_map_.clear(); |
58 // If this triggers, that means something is keeping a reference to | 59 // If this triggers, that means something is keeping a reference to |
59 // a Valuebuffer belonging to this. | 60 // a Valuebuffer belonging to this. |
60 CHECK_EQ(valuebuffer_count_, 0u); | 61 CHECK_EQ(valuebuffer_count_, 0u); |
61 } | 62 } |
62 | 63 |
63 void ValuebufferManager::Destroy() { | |
64 valuebuffer_map_.clear(); | |
65 pending_state_map_.clear(); | |
66 } | |
67 | |
68 void ValuebufferManager::StartTracking(Valuebuffer* /* valuebuffer */) { | 64 void ValuebufferManager::StartTracking(Valuebuffer* /* valuebuffer */) { |
69 ++valuebuffer_count_; | 65 ++valuebuffer_count_; |
70 } | 66 } |
71 | 67 |
72 void ValuebufferManager::StopTracking(Valuebuffer* /* valuebuffer */) { | 68 void ValuebufferManager::StopTracking(Valuebuffer* /* valuebuffer */) { |
73 --valuebuffer_count_; | 69 --valuebuffer_count_; |
74 } | 70 } |
75 | 71 |
76 void ValuebufferManager::CreateValuebuffer(GLuint client_id) { | 72 void ValuebufferManager::CreateValuebuffer(unsigned int client_id) { |
77 scoped_refptr<Valuebuffer> valuebuffer(new Valuebuffer(this, client_id)); | 73 scoped_refptr<Valuebuffer> valuebuffer(new Valuebuffer(this, client_id)); |
78 std::pair<ValuebufferMap::iterator, bool> result = | 74 std::pair<ValuebufferMap::iterator, bool> result = |
79 valuebuffer_map_.insert(std::make_pair(client_id, valuebuffer)); | 75 valuebuffer_map_.insert(std::make_pair(client_id, valuebuffer)); |
80 DCHECK(result.second); | 76 DCHECK(result.second); |
81 } | 77 } |
82 | 78 |
83 Valuebuffer* ValuebufferManager::GetValuebuffer(GLuint client_id) { | 79 Valuebuffer* ValuebufferManager::GetValuebuffer(unsigned int client_id) { |
84 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); | 80 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); |
85 return it != valuebuffer_map_.end() ? it->second.get() : NULL; | 81 return it != valuebuffer_map_.end() ? it->second.get() : NULL; |
86 } | 82 } |
87 | 83 |
88 void ValuebufferManager::RemoveValuebuffer(GLuint client_id) { | 84 void ValuebufferManager::RemoveValuebuffer(unsigned int client_id) { |
89 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); | 85 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); |
90 if (it != valuebuffer_map_.end()) { | 86 if (it != valuebuffer_map_.end()) { |
91 Valuebuffer* valuebuffer = it->second.get(); | 87 Valuebuffer* valuebuffer = it->second.get(); |
92 valuebuffer->MarkAsDeleted(); | 88 valuebuffer->MarkAsDeleted(); |
93 valuebuffer_map_.erase(it); | 89 valuebuffer_map_.erase(it); |
94 } | 90 } |
95 } | 91 } |
96 | 92 |
97 void ValuebufferManager::UpdateValuebufferState(Valuebuffer* valuebuffer) { | 93 void ValuebufferManager::UpdateValuebufferState(Valuebuffer* valuebuffer) { |
98 DCHECK(valuebuffer); | 94 DCHECK(valuebuffer); |
99 valuebuffer->UpdateState(pending_state_map_); | 95 valuebuffer->UpdateState(pending_state_map_); |
100 } | 96 } |
101 | 97 |
102 void ValuebufferManager::UpdateValueState( | 98 void ValuebufferManager::UpdateValueState( |
103 GLenum target, const ValueState& state) { | 99 GLenum target, const ValueState& state) { |
104 pending_state_map_[target] = state; | 100 pending_state_map_[target] = state; |
105 } | 101 } |
106 | 102 |
107 uint32 ValuebufferManager::ApiTypeForSubscriptionTarget(GLenum target) { | 103 const ValueState *ValuebufferManager::GetPendingState( |
piman
2014/11/26 20:47:09
nit: star on the left.
orglofch
2014/12/01 01:54:29
Done. Removed, no longer needed for testing.
| |
104 unsigned int target) const { | |
105 Valuebuffer::StateMap::const_iterator it = pending_state_map_.find(target); | |
106 return it != pending_state_map_.end() ? &it->second : NULL; | |
107 } | |
108 | |
109 uint32 ValuebufferManager::ApiTypeForSubscriptionTarget(unsigned int target) { | |
108 switch (target) { | 110 switch (target) { |
109 case GL_MOUSE_POSITION_CHROMIUM: | 111 case GL_MOUSE_POSITION_CHROMIUM: |
110 return Program::kUniform2i; | 112 return Program::kUniform2i; |
111 } | 113 } |
112 NOTREACHED() << "Unhandled uniform subscription target " << target; | 114 NOTREACHED() << "Unhandled uniform subscription target " << target; |
113 return Program::kUniformNone; | 115 return Program::kUniformNone; |
114 } | 116 } |
115 | 117 |
116 } // namespace gles2 | 118 } // namespace gles2 |
117 } // namespace gpu | 119 } // namespace gpu |
OLD | NEW |