Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: gpu/command_buffer/client/program_info_manager.cc

Issue 10855274: Fix Uniform Name Parsing (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gpu/command_buffer/common/gles2_cmd_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../client/program_info_manager.h" 5 #include "../client/program_info_manager.h"
6 #include "../client/atomicops.h" 6 #include "../client/atomicops.h"
7 #include "../client/gles2_implementation.h" 7 #include "../client/gles2_implementation.h"
8 #include "../common/gles2_cmd_utils.h"
8 9
9 #include <map> 10 #include <map>
10 11
11 namespace gpu { 12 namespace gpu {
12 namespace gles2 { 13 namespace gles2 {
13 14
14 class NonCachedProgramInfoManager : public ProgramInfoManager { 15 class NonCachedProgramInfoManager : public ProgramInfoManager {
15 public: 16 public:
16 NonCachedProgramInfoManager(); 17 NonCachedProgramInfoManager();
17 virtual ~NonCachedProgramInfoManager(); 18 virtual ~NonCachedProgramInfoManager();
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 const std::string& name) const { 220 const std::string& name) const {
220 for (GLuint ii = 0; ii < attrib_infos_.size(); ++ii) { 221 for (GLuint ii = 0; ii < attrib_infos_.size(); ++ii) {
221 const VertexAttribInfo& info = attrib_infos_[ii]; 222 const VertexAttribInfo& info = attrib_infos_[ii];
222 if (info.name == name) { 223 if (info.name == name) {
223 return info.location; 224 return info.location;
224 } 225 }
225 } 226 }
226 return -1; 227 return -1;
227 } 228 }
228 229
229 // TODO(gman): Add a faster lookup.
230 GLint CachedProgramInfoManager::ProgramInfo::GetUniformLocation( 230 GLint CachedProgramInfoManager::ProgramInfo::GetUniformLocation(
231 const std::string& name) const { 231 const std::string& name) const {
232 bool getting_array_location = false;
233 size_t open_pos = std::string::npos;
234 int index = 0;
235 if (!GLES2Util::ParseUniformName(
236 name, &open_pos, &index, &getting_array_location)) {
237 return -1;
238 }
232 for (GLuint ii = 0; ii < uniform_infos_.size(); ++ii) { 239 for (GLuint ii = 0; ii < uniform_infos_.size(); ++ii) {
233 const UniformInfo& info = uniform_infos_[ii]; 240 const UniformInfo& info = uniform_infos_[ii];
234 if (info.name == name || 241 if (info.name == name ||
235 (info.is_array && 242 (info.is_array &&
236 info.name.compare(0, info.name.size() - 3, name) == 0)) { 243 info.name.compare(0, info.name.size() - 3, name) == 0)) {
237 return info.element_locations[0]; 244 return info.element_locations[0];
238 } else if (info.is_array && 245 } else if (getting_array_location && info.is_array) {
239 name.size() >= 3 && name[name.size() - 1] == ']') {
240 // Look for an array specification. 246 // Look for an array specification.
241 size_t open_pos = name.find_last_of('['); 247 size_t open_pos_2 = info.name.find_last_of('[');
242 if (open_pos != std::string::npos && 248 if (open_pos_2 == open_pos &&
243 open_pos < name.size() - 2 &&
244 info.name.size() > open_pos &&
245 name.compare(0, open_pos, info.name, 0, open_pos) == 0) { 249 name.compare(0, open_pos, info.name, 0, open_pos) == 0) {
246 GLint index = 0; 250 if (index >= 0 && index < info.size) {
247 size_t last = name.size() - 1;
248 bool bad = false;
249 for (size_t pos = open_pos + 1; pos < last; ++pos) {
250 int8 digit = name[pos] - '0';
251 if (digit < 0 || digit > 9) {
252 bad = true;
253 break;
254 }
255 index = index * 10 + digit;
256 }
257 if (!bad && index >= 0 && index < info.size) {
258 return info.element_locations[index]; 251 return info.element_locations[index];
259 } 252 }
260 } 253 }
261 } 254 }
262 } 255 }
263 return -1; 256 return -1;
264 } 257 }
265 258
266 bool CachedProgramInfoManager::ProgramInfo::GetProgramiv( 259 bool CachedProgramInfoManager::ProgramInfo::GetProgramiv(
267 GLenum pname, GLint* params) { 260 GLenum pname, GLint* params) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 if (shared_resources_across_processes) { 490 if (shared_resources_across_processes) {
498 return new NonCachedProgramInfoManager(); 491 return new NonCachedProgramInfoManager();
499 } else { 492 } else {
500 return new CachedProgramInfoManager(); 493 return new CachedProgramInfoManager();
501 } 494 }
502 } 495 }
503 496
504 } // namespace gles2 497 } // namespace gles2
505 } // namespace gpu 498 } // namespace gpu
506 499
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/common/gles2_cmd_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698