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 "gpu/command_buffer/service/valuebuffer_manager.h" | |
6 | |
7 #include "gpu/command_buffer/service/program_manager.h" | |
8 | |
9 namespace gpu { | |
10 namespace gles2 { | |
11 | |
12 ValueState::ValueState(GLenum target) : target_(target) { | |
13 } | |
14 | |
15 ValueState::~ValueState() { | |
16 } | |
17 | |
18 IntValueState::IntValueState(GLenum target, GLint* data) | |
19 : ValueState(target), data_(data) { | |
20 DCHECK(ValuebufferManager::ApiTypeForSubscriptionTarget(target) & | |
21 (Program::kUniform1i | |
22 | Program::kUniform2i | |
23 | Program::kUniform3i | |
24 | Program::kUniform4i)); | |
25 } | |
26 | |
27 IntValueState::~IntValueState() { | |
28 } | |
29 | |
30 FloatValueState::FloatValueState(GLenum target, GLfloat* data) | |
31 : ValueState(target), data_(data) { | |
32 DCHECK(ValuebufferManager::ApiTypeForSubscriptionTarget(target) & | |
33 (Program::kUniform1f | |
34 | Program::kUniform2f | |
35 | Program::kUniform3f | |
36 | Program::kUniform4f | |
37 | Program::kUniformMatrix2f | |
38 | Program::kUniformMatrix3f | |
39 | Program::kUniformMatrix4f)); | |
40 } | |
41 | |
42 FloatValueState::~FloatValueState() { | |
43 } | |
44 | |
45 Valuebuffer::Valuebuffer(ValuebufferManager* manager, GLuint client_id) | |
46 : manager_(manager), client_id_(client_id), has_been_bound_(false) { | |
47 manager_->StartTracking(this); | |
48 } | |
49 | |
50 Valuebuffer::~Valuebuffer() { | |
51 if (manager_) { | |
52 manager_->StopTracking(this); | |
53 manager_ = NULL; | |
54 } | |
55 } | |
56 | |
57 void Valuebuffer::AddSubscription(GLenum subscription) { | |
58 subscriptions_.insert(subscription); | |
59 } | |
60 | |
61 void Valuebuffer::RemoveSubscription(GLenum subscription) { | |
62 subscriptions_.erase(subscription); | |
63 } | |
64 | |
65 bool Valuebuffer::IsSubscribed(GLenum subscription) { | |
66 return subscriptions_.find(subscription) != subscriptions_.end(); | |
67 } | |
68 | |
69 const ValueState* Valuebuffer::GetState(GLenum target) const { | |
70 StateMap::const_iterator it = active_state_map_.find(target); | |
71 return it != active_state_map_.end() ? it->second.get() : NULL; | |
72 } | |
73 | |
74 void Valuebuffer::UpdateState(const StateMap& pending_state) { | |
75 for (SubscriptionSet::const_iterator it = subscriptions_.begin(); | |
76 it != subscriptions_.end(); ++it) { | |
77 StateMap::const_iterator state_it = pending_state.find((*it)); | |
78 if (state_it != pending_state.end()) { | |
79 std::pair<StateMap::iterator, bool> result = | |
80 active_state_map_.insert(std::make_pair( | |
81 state_it->first, scoped_refptr<ValueState>(state_it->second))); | |
piman
2014/11/04 02:38:22
active_state_map_.insert(*state_it) ?
orglofch
2014/11/04 19:53:28
Done.
| |
82 DCHECK(result.second); | |
83 } | |
84 } | |
85 } | |
86 | |
87 ValuebufferManager::ValuebufferManager() | |
88 : valuebuffer_count_(0), have_context_(true) { | |
89 } | |
90 | |
91 ValuebufferManager::~ValuebufferManager() { | |
92 DCHECK(valuebuffer_map_.empty()); | |
93 DCHECK(pending_state_map_.empty()); | |
94 // If this triggers, that means something is keeping a reference to | |
95 // a Valuebuffer belonging to this. | |
96 CHECK_EQ(valuebuffer_count_, 0u); | |
97 } | |
98 | |
99 void ValuebufferManager::Destroy(bool have_context) { | |
100 have_context_ = have_context; | |
piman
2014/11/04 02:38:22
nit: you're not using have_context_, so you can re
orglofch
2014/11/04 19:53:28
Done.
| |
101 valuebuffer_map_.clear(); | |
102 pending_state_map_.clear(); | |
103 } | |
104 | |
105 void ValuebufferManager::StartTracking(Valuebuffer* /* valuebuffer */) { | |
106 ++valuebuffer_count_; | |
107 } | |
108 | |
109 void ValuebufferManager::StopTracking(Valuebuffer* /* valuebuffer */) { | |
110 --valuebuffer_count_; | |
111 } | |
112 | |
113 void ValuebufferManager::CreateValuebuffer(GLuint client_id) { | |
114 scoped_refptr<Valuebuffer> valuebuffer(new Valuebuffer(this, client_id)); | |
115 std::pair<ValuebufferMap::iterator, bool> result = | |
116 valuebuffer_map_.insert(std::make_pair(client_id, valuebuffer)); | |
117 DCHECK(result.second); | |
118 } | |
119 | |
120 Valuebuffer* ValuebufferManager::GetValuebuffer(GLuint client_id) { | |
121 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); | |
122 return it != valuebuffer_map_.end() ? it->second.get() : NULL; | |
123 } | |
124 | |
125 void ValuebufferManager::RemoveValuebuffer(GLuint client_id) { | |
126 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); | |
127 if (it != valuebuffer_map_.end()) { | |
128 Valuebuffer* valuebuffer = it->second.get(); | |
129 valuebuffer->MarkAsDeleted(); | |
130 valuebuffer_map_.erase(it); | |
131 } | |
132 } | |
133 | |
134 void ValuebufferManager::UpdateValuebufferState(GLuint client_id) { | |
135 ValuebufferMap::iterator it = valuebuffer_map_.find(client_id); | |
136 if (it != valuebuffer_map_.end()) { | |
137 it->second.get()->UpdateState(pending_state_map_); | |
138 } | |
139 } | |
140 | |
141 void ValuebufferManager::UpdateValueState(ValueState* state) { | |
142 DCHECK(state); | |
143 std::pair<Valuebuffer::StateMap::iterator, bool> result = | |
144 pending_state_map_.insert( | |
145 std::make_pair(state->target(), scoped_refptr<ValueState>(state))); | |
146 DCHECK(result.second); | |
147 } | |
148 | |
149 uint32 ValuebufferManager::ApiTypeForSubscriptionTarget(GLenum target) { | |
150 switch (target) { | |
151 case GL_MOUSE_POSITION_CHROMIUM: | |
152 return Program::kUniform2i; | |
153 } | |
154 NOTREACHED() << "Unhandled uniform subscription target " << target; | |
155 return Program::kUniformNone; | |
156 } | |
157 | |
158 } // namespace gles2 | |
159 } // namespace gpu | |
OLD | NEW |