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/client/program_info_manager.h" | 5 #include "gpu/command_buffer/client/program_info_manager.h" |
6 | 6 |
7 namespace { | 7 namespace { |
8 | 8 |
9 template<typename T> static T LocalGetAs( | 9 template<typename T> static T LocalGetAs( |
10 const std::vector<int8>& data, uint32 offset, size_t size) { | 10 const std::vector<int8>& data, uint32 offset, size_t size) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // See "OpenGL ES 3.0.0, Section 2.11.3 Program Objects." | 157 // See "OpenGL ES 3.0.0, Section 2.11.3 Program Objects." |
158 if (info.name == name || | 158 if (info.name == name || |
159 (info.is_array && | 159 (info.is_array && |
160 info.name.compare(0, info.name.size() - 3, name) == 0)) { | 160 info.name.compare(0, info.name.size() - 3, name) == 0)) { |
161 return ii; | 161 return ii; |
162 } | 162 } |
163 } | 163 } |
164 return GL_INVALID_INDEX; | 164 return GL_INVALID_INDEX; |
165 } | 165 } |
166 | 166 |
| 167 GLint ProgramInfoManager::Program::GetFragDataIndex( |
| 168 const std::string& name) const { |
| 169 base::hash_map<std::string, GLint>::const_iterator iter = |
| 170 frag_data_indices_.find(name); |
| 171 if (iter == frag_data_indices_.end()) |
| 172 return -1; |
| 173 return iter->second; |
| 174 } |
| 175 |
| 176 void ProgramInfoManager::Program::CacheFragDataIndex(const std::string& name, |
| 177 GLint index) { |
| 178 frag_data_indices_[name] = index; |
| 179 } |
| 180 |
167 GLint ProgramInfoManager::Program::GetFragDataLocation( | 181 GLint ProgramInfoManager::Program::GetFragDataLocation( |
168 const std::string& name) const { | 182 const std::string& name) const { |
169 base::hash_map<std::string, GLint>::const_iterator iter = | 183 base::hash_map<std::string, GLint>::const_iterator iter = |
170 frag_data_locations_.find(name); | 184 frag_data_locations_.find(name); |
171 if (iter == frag_data_locations_.end()) | 185 if (iter == frag_data_locations_.end()) |
172 return -1; | 186 return -1; |
173 return iter->second; | 187 return iter->second; |
174 } | 188 } |
175 | 189 |
176 void ProgramInfoManager::Program::CacheFragDataLocation( | 190 void ProgramInfoManager::Program::CacheFragDataLocation( |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 { | 728 { |
715 base::AutoLock auto_lock(lock_); | 729 base::AutoLock auto_lock(lock_); |
716 Program* info = GetProgramInfo(gl, program, kES2); | 730 Program* info = GetProgramInfo(gl, program, kES2); |
717 if (info) { | 731 if (info) { |
718 return info->GetUniformLocation(name); | 732 return info->GetUniformLocation(name); |
719 } | 733 } |
720 } | 734 } |
721 return gl->GetUniformLocationHelper(program, name); | 735 return gl->GetUniformLocationHelper(program, name); |
722 } | 736 } |
723 | 737 |
| 738 GLint ProgramInfoManager::GetFragDataIndex(GLES2Implementation* gl, |
| 739 GLuint program, |
| 740 const char* name) { |
| 741 // TODO(zmo): make FragData indexes part of the ProgramInfo that are |
| 742 // fetched altogether from the service side. See crbug.com/452104. |
| 743 { |
| 744 base::AutoLock auto_lock(lock_); |
| 745 Program* info = GetProgramInfo(gl, program, kNone); |
| 746 if (info) { |
| 747 GLint possible_index = info->GetFragDataIndex(name); |
| 748 if (possible_index != -1) |
| 749 return possible_index; |
| 750 } |
| 751 } |
| 752 GLint index = gl->GetFragDataIndexEXTHelper(program, name); |
| 753 if (index != -1) { |
| 754 base::AutoLock auto_lock(lock_); |
| 755 Program* info = GetProgramInfo(gl, program, kNone); |
| 756 if (info) { |
| 757 info->CacheFragDataIndex(name, index); |
| 758 } |
| 759 } |
| 760 return index; |
| 761 } |
| 762 |
724 GLint ProgramInfoManager::GetFragDataLocation( | 763 GLint ProgramInfoManager::GetFragDataLocation( |
725 GLES2Implementation* gl, GLuint program, const char* name) { | 764 GLES2Implementation* gl, GLuint program, const char* name) { |
726 // TODO(zmo): make FragData locations part of the ProgramInfo that are | 765 // TODO(zmo): make FragData locations part of the ProgramInfo that are |
727 // fetched altogether from the service side. See crbug.com/452104. | 766 // fetched altogether from the service side. See crbug.com/452104. |
728 { | 767 { |
729 base::AutoLock auto_lock(lock_); | 768 base::AutoLock auto_lock(lock_); |
730 Program* info = GetProgramInfo(gl, program, kNone); | 769 Program* info = GetProgramInfo(gl, program, kNone); |
731 if (info) { | 770 if (info) { |
732 GLint possible_loc = info->GetFragDataLocation(name); | 771 GLint possible_loc = info->GetFragDataLocation(name); |
733 if (possible_loc != -1) | 772 if (possible_loc != -1) |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 } | 1029 } |
991 return true; | 1030 return true; |
992 } | 1031 } |
993 } | 1032 } |
994 return gl->GetUniformIndicesHelper(program, count, names, indices); | 1033 return gl->GetUniformIndicesHelper(program, count, names, indices); |
995 } | 1034 } |
996 | 1035 |
997 } // namespace gles2 | 1036 } // namespace gles2 |
998 } // namespace gpu | 1037 } // namespace gpu |
999 | 1038 |
OLD | NEW |