OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
14 | 14 |
15 namespace gpu { | 15 namespace gpu { |
16 namespace gles2 { | 16 namespace gles2 { |
17 | 17 |
18 static int ShaderTypeToIndex(GLenum shader_type) { | 18 static int ShaderTypeToIndex(GLenum shader_type) { |
19 switch (shader_type) { | 19 switch (shader_type) { |
20 case GL_VERTEX_SHADER: | 20 case GL_VERTEX_SHADER: |
21 return 0; | 21 return 0; |
22 case GL_FRAGMENT_SHADER: | 22 case GL_FRAGMENT_SHADER: |
23 return 1; | 23 return 1; |
24 default: | 24 default: |
25 NOTREACHED(); | 25 NOTREACHED(); |
26 return 0; | 26 return 0; |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
| 30 |
| 31 ProgramManager::ProgramInfo::UniformInfo::UniformInfo(GLsizei _size, |
| 32 GLenum _type, |
| 33 const std::string& _name) |
| 34 : size(_size), |
| 35 type(_type), |
| 36 name(_name) { |
| 37 } |
| 38 |
| 39 ProgramManager::ProgramInfo::UniformInfo::~UniformInfo() {} |
| 40 |
30 bool ProgramManager::IsInvalidPrefix(const char* name, size_t length) { | 41 bool ProgramManager::IsInvalidPrefix(const char* name, size_t length) { |
31 static const char kInvalidPrefix[] = { 'g', 'l', '_' }; | 42 static const char kInvalidPrefix[] = { 'g', 'l', '_' }; |
32 return (length >= sizeof(kInvalidPrefix) && | 43 return (length >= sizeof(kInvalidPrefix) && |
33 memcmp(name, kInvalidPrefix, sizeof(kInvalidPrefix)) == 0); | 44 memcmp(name, kInvalidPrefix, sizeof(kInvalidPrefix)) == 0); |
34 } | 45 } |
35 | 46 |
| 47 ProgramManager::ProgramInfo::ProgramInfo(GLuint service_id) |
| 48 : max_attrib_name_length_(0), |
| 49 max_uniform_name_length_(0), |
| 50 service_id_(service_id), |
| 51 valid_(false) { |
| 52 } |
| 53 |
36 void ProgramManager::ProgramInfo::Reset() { | 54 void ProgramManager::ProgramInfo::Reset() { |
37 valid_ = false; | 55 valid_ = false; |
38 max_uniform_name_length_ = 0; | 56 max_uniform_name_length_ = 0; |
39 max_attrib_name_length_ = 0; | 57 max_attrib_name_length_ = 0; |
40 attrib_infos_.clear(); | 58 attrib_infos_.clear(); |
41 uniform_infos_.clear(); | 59 uniform_infos_.clear(); |
42 sampler_indices_.clear(); | 60 sampler_indices_.clear(); |
43 attrib_location_to_index_map_.clear(); | 61 attrib_location_to_index_map_.clear(); |
44 uniform_location_to_index_map_.clear(); | 62 uniform_location_to_index_map_.clear(); |
45 UpdateLogInfo(); | 63 UpdateLogInfo(); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 331 |
314 bool ProgramManager::ProgramInfo::CanLink() const { | 332 bool ProgramManager::ProgramInfo::CanLink() const { |
315 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { | 333 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { |
316 if (!attached_shaders_[ii] || !attached_shaders_[ii]->IsValid()) { | 334 if (!attached_shaders_[ii] || !attached_shaders_[ii]->IsValid()) { |
317 return false; | 335 return false; |
318 } | 336 } |
319 } | 337 } |
320 return true; | 338 return true; |
321 } | 339 } |
322 | 340 |
| 341 ProgramManager::ProgramInfo::~ProgramInfo() {} |
| 342 |
| 343 ProgramManager::ProgramManager() {} |
| 344 |
323 ProgramManager::~ProgramManager() { | 345 ProgramManager::~ProgramManager() { |
324 DCHECK(program_infos_.empty()); | 346 DCHECK(program_infos_.empty()); |
325 } | 347 } |
326 | 348 |
327 void ProgramManager::Destroy(bool have_context) { | 349 void ProgramManager::Destroy(bool have_context) { |
328 while (!program_infos_.empty()) { | 350 while (!program_infos_.empty()) { |
329 if (have_context) { | 351 if (have_context) { |
330 ProgramInfo* info = program_infos_.begin()->second; | 352 ProgramInfo* info = program_infos_.begin()->second; |
331 if (!info->IsDeleted()) { | 353 if (!info->IsDeleted()) { |
332 glDeleteProgram(info->service_id()); | 354 glDeleteProgram(info->service_id()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 return true; | 389 return true; |
368 } | 390 } |
369 } | 391 } |
370 return false; | 392 return false; |
371 } | 393 } |
372 | 394 |
373 } // namespace gles2 | 395 } // namespace gles2 |
374 } // namespace gpu | 396 } // namespace gpu |
375 | 397 |
376 | 398 |
OLD | NEW |