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/program_manager.h" | 5 #include "gpu/command_buffer/service/program_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 } | 186 } |
187 | 187 |
188 Program::UniformInfo::~UniformInfo() {} | 188 Program::UniformInfo::~UniformInfo() {} |
189 | 189 |
190 bool ProgramManager::IsInvalidPrefix(const char* name, size_t length) { | 190 bool ProgramManager::IsInvalidPrefix(const char* name, size_t length) { |
191 static const char kInvalidPrefix[] = { 'g', 'l', '_' }; | 191 static const char kInvalidPrefix[] = { 'g', 'l', '_' }; |
192 return (length >= sizeof(kInvalidPrefix) && | 192 return (length >= sizeof(kInvalidPrefix) && |
193 memcmp(name, kInvalidPrefix, sizeof(kInvalidPrefix)) == 0); | 193 memcmp(name, kInvalidPrefix, sizeof(kInvalidPrefix)) == 0); |
194 } | 194 } |
195 | 195 |
196 Program::Program( | 196 Program::Program(ProgramManager* manager, GLuint service_id) |
197 ProgramManager* manager, GLuint service_id) | |
198 : manager_(manager), | 197 : manager_(manager), |
199 use_count_(0), | 198 use_count_(0), |
200 max_attrib_name_length_(0), | 199 max_attrib_name_length_(0), |
201 max_uniform_name_length_(0), | 200 max_uniform_name_length_(0), |
202 service_id_(service_id), | 201 service_id_(service_id), |
203 deleted_(false), | 202 deleted_(false), |
204 valid_(false), | 203 valid_(false), |
205 link_status_(false), | 204 link_status_(false), |
206 uniforms_cleared_(false), | 205 uniforms_cleared_(false), |
206 needs_update_subscriptions_(true), | |
207 num_uniforms_(0) { | 207 num_uniforms_(0) { |
208 manager_->StartTracking(this); | 208 manager_->StartTracking(this); |
209 } | 209 } |
210 | 210 |
211 void Program::Reset() { | 211 void Program::Reset() { |
212 valid_ = false; | 212 valid_ = false; |
213 link_status_ = false; | 213 link_status_ = false; |
214 needs_update_subscriptions_ = true; | |
214 num_uniforms_ = 0; | 215 num_uniforms_ = 0; |
215 max_uniform_name_length_ = 0; | 216 max_uniform_name_length_ = 0; |
216 max_attrib_name_length_ = 0; | 217 max_attrib_name_length_ = 0; |
217 attrib_infos_.clear(); | 218 attrib_infos_.clear(); |
218 uniform_infos_.clear(); | 219 uniform_infos_.clear(); |
219 sampler_indices_.clear(); | 220 sampler_indices_.clear(); |
220 attrib_location_to_index_map_.clear(); | 221 attrib_location_to_index_map_.clear(); |
221 } | 222 } |
222 | 223 |
223 std::string Program::ProcessLogInfo( | 224 std::string Program::ProcessLogInfo( |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 | 629 |
629 void Program::Validate() { | 630 void Program::Validate() { |
630 if (!IsValid()) { | 631 if (!IsValid()) { |
631 set_log_info("program not linked"); | 632 set_log_info("program not linked"); |
632 return; | 633 return; |
633 } | 634 } |
634 glValidateProgram(service_id()); | 635 glValidateProgram(service_id()); |
635 UpdateLogInfo(); | 636 UpdateLogInfo(); |
636 } | 637 } |
637 | 638 |
639 void Program::SetNeedsUpdateSubscriptions() { | |
640 needs_update_subscriptions_ = true; | |
piman
2014/10/23 02:30:48
When will that be reset to false? In GLES2DecoderI
| |
641 } | |
642 | |
638 GLint Program::GetUniformFakeLocation( | 643 GLint Program::GetUniformFakeLocation( |
639 const std::string& name) const { | 644 const std::string& name) const { |
640 bool getting_array_location = false; | 645 bool getting_array_location = false; |
641 size_t open_pos = std::string::npos; | 646 size_t open_pos = std::string::npos; |
642 int index = 0; | 647 int index = 0; |
643 if (!GLES2Util::ParseUniformName( | 648 if (!GLES2Util::ParseUniformName( |
644 name, &open_pos, &index, &getting_array_location)) { | 649 name, &open_pos, &index, &getting_array_location)) { |
645 return -1; | 650 return -1; |
646 } | 651 } |
647 for (GLuint ii = 0; ii < uniform_infos_.size(); ++ii) { | 652 for (GLuint ii = 0; ii < uniform_infos_.size(); ++ii) { |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 variables[index].type = iter->second.type; | 1196 variables[index].type = iter->second.type; |
1192 variables[index].size = iter->second.size; | 1197 variables[index].size = iter->second.size; |
1193 ++index; | 1198 ++index; |
1194 } | 1199 } |
1195 return ShCheckVariablesWithinPackingLimits( | 1200 return ShCheckVariablesWithinPackingLimits( |
1196 static_cast<int>(manager_->max_varying_vectors()), | 1201 static_cast<int>(manager_->max_varying_vectors()), |
1197 variables.get(), | 1202 variables.get(), |
1198 combined_map.size()) == 1; | 1203 combined_map.size()) == 1; |
1199 } | 1204 } |
1200 | 1205 |
1206 void Program::AddSubscription(GLint location, GLenum target) { | |
1207 subscription_map_[location] = target; | |
1208 } | |
1209 | |
1210 void Program::RemoveSubscription(GLint location) { | |
1211 subscription_map_.erase(location); | |
1212 } | |
1213 | |
1201 static uint32 ComputeOffset(const void* start, const void* position) { | 1214 static uint32 ComputeOffset(const void* start, const void* position) { |
1202 return static_cast<const uint8*>(position) - | 1215 return static_cast<const uint8*>(position) - |
1203 static_cast<const uint8*>(start); | 1216 static_cast<const uint8*>(start); |
1204 } | 1217 } |
1205 | 1218 |
1206 void Program::GetProgramInfo( | 1219 void Program::GetProgramInfo( |
1207 ProgramManager* manager, CommonDecoder::Bucket* bucket) const { | 1220 ProgramManager* manager, CommonDecoder::Bucket* bucket) const { |
1208 // NOTE: It seems to me the math in here does not need check for overflow | 1221 // NOTE: It seems to me the math in here does not need check for overflow |
1209 // because the data being calucated from has various small limits. The max | 1222 // because the data being calucated from has various small limits. The max |
1210 // number of attribs + uniforms is somewhere well under 1024. The maximum size | 1223 // number of attribs + uniforms is somewhere well under 1024. The maximum size |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1357 bool ProgramManager::IsOwned(Program* program) { | 1370 bool ProgramManager::IsOwned(Program* program) { |
1358 for (ProgramMap::iterator it = programs_.begin(); | 1371 for (ProgramMap::iterator it = programs_.begin(); |
1359 it != programs_.end(); ++it) { | 1372 it != programs_.end(); ++it) { |
1360 if (it->second.get() == program) { | 1373 if (it->second.get() == program) { |
1361 return true; | 1374 return true; |
1362 } | 1375 } |
1363 } | 1376 } |
1364 return false; | 1377 return false; |
1365 } | 1378 } |
1366 | 1379 |
1380 void ProgramManager::ActivateUniformSubscriptionState() { | |
brianderson
2014/10/24 00:28:34
It looks like ProgramManager has a 1:1 relationshi
| |
1381 // TODO(orglofch): Make active_state = pending_state | |
1382 // only set needs update subscriptions if !pending_state.empty() | |
1383 for (ProgramMap::iterator it = programs_.begin(); it != programs_.end(); | |
1384 ++it) { | |
piman
2014/10/23 02:30:48
Maybe make it a TODO, but it would be nice not to
| |
1385 it->second.get()->SetNeedsUpdateSubscriptions(); | |
1386 } | |
1387 } | |
1388 | |
1367 void ProgramManager::RemoveProgramInfoIfUnused( | 1389 void ProgramManager::RemoveProgramInfoIfUnused( |
1368 ShaderManager* shader_manager, Program* program) { | 1390 ShaderManager* shader_manager, Program* program) { |
1369 DCHECK(shader_manager); | 1391 DCHECK(shader_manager); |
1370 DCHECK(program); | 1392 DCHECK(program); |
1371 DCHECK(IsOwned(program)); | 1393 DCHECK(IsOwned(program)); |
1372 if (program->IsDeleted() && !program->InUse()) { | 1394 if (program->IsDeleted() && !program->InUse()) { |
1373 program->DetachShaders(shader_manager); | 1395 program->DetachShaders(shader_manager); |
1374 for (ProgramMap::iterator it = programs_.begin(); | 1396 for (ProgramMap::iterator it = programs_.begin(); |
1375 it != programs_.end(); ++it) { | 1397 it != programs_.end(); ++it) { |
1376 if (it->second.get() == program) { | 1398 if (it->second.get() == program) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1410 | 1432 |
1411 void ProgramManager::ClearUniforms(Program* program) { | 1433 void ProgramManager::ClearUniforms(Program* program) { |
1412 DCHECK(program); | 1434 DCHECK(program); |
1413 program->ClearUniforms(&zero_); | 1435 program->ClearUniforms(&zero_); |
1414 } | 1436 } |
1415 | 1437 |
1416 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { | 1438 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { |
1417 return index + element * 0x10000; | 1439 return index + element * 0x10000; |
1418 } | 1440 } |
1419 | 1441 |
1442 Program::UniformApiType ProgramManager::ApiTypeForSubscriptionTarget( | |
1443 GLenum target) { | |
1444 switch (target) { | |
1445 case GL_MOUSE_POSITION_CHROMIUM: | |
1446 return Program::kUniform2i; | |
1447 } | |
1448 NOTREACHED() << "Unhandled uniform subscription target " << target; | |
1449 return Program::kUniformNone; | |
1450 } | |
1451 | |
1420 } // namespace gles2 | 1452 } // namespace gles2 |
1421 } // namespace gpu | 1453 } // namespace gpu |
OLD | NEW |