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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/numerics/safe_math.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
20 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 21 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
21 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
22 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 23 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
23 #include "gpu/command_buffer/service/gpu_switches.h" | 24 #include "gpu/command_buffer/service/gpu_switches.h" |
24 #include "gpu/command_buffer/service/program_cache.h" | 25 #include "gpu/command_buffer/service/program_cache.h" |
25 #include "gpu/command_buffer/service/shader_manager.h" | 26 #include "gpu/command_buffer/service/shader_manager.h" |
26 #include "gpu/command_buffer/service/shader_translator.h" | 27 #include "gpu/command_buffer/service/shader_translator.h" |
(...skipping 32 matching lines...) Loading... |
59 return true; | 60 return true; |
60 } | 61 } |
61 | 62 |
62 // Look for an array specification. | 63 // Look for an array specification. |
63 size_t open_pos = name.find_last_of('['); | 64 size_t open_pos = name.find_last_of('['); |
64 if (open_pos == std::string::npos || | 65 if (open_pos == std::string::npos || |
65 open_pos >= name.size() - 2) { | 66 open_pos >= name.size() - 2) { |
66 return false; | 67 return false; |
67 } | 68 } |
68 | 69 |
69 GLint index = 0; | 70 base::CheckedNumeric<GLint> index = 0; |
70 size_t last = name.size() - 1; | 71 size_t last = name.size() - 1; |
71 for (size_t pos = open_pos + 1; pos < last; ++pos) { | 72 for (size_t pos = open_pos + 1; pos < last; ++pos) { |
72 int8 digit = name[pos] - '0'; | 73 int8 digit = name[pos] - '0'; |
73 if (digit < 0 || digit > 9) { | 74 if (digit < 0 || digit > 9) { |
74 return false; | 75 return false; |
75 } | 76 } |
76 index = index * 10 + digit; | 77 index = index * 10 + digit; |
77 } | 78 } |
| 79 if (!index.IsValid()) { |
| 80 return false; |
| 81 } |
78 | 82 |
79 *element_index = index; | 83 *element_index = index.ValueOrDie(); |
80 *new_name = name.substr(0, open_pos); | 84 *new_name = name.substr(0, open_pos); |
81 return true; | 85 return true; |
82 } | 86 } |
83 | 87 |
84 bool IsBuiltInFragmentVarying(const std::string& name) { | 88 bool IsBuiltInFragmentVarying(const std::string& name) { |
85 // Built-in variables for fragment shaders. | 89 // Built-in variables for fragment shaders. |
86 const char* kBuiltInVaryings[] = { | 90 const char* kBuiltInVaryings[] = { |
87 "gl_FragCoord", | 91 "gl_FragCoord", |
88 "gl_FrontFacing", | 92 "gl_FrontFacing", |
89 "gl_PointCoord" | 93 "gl_PointCoord" |
(...skipping 1321 matching lines...) Loading... |
1411 DCHECK(program); | 1415 DCHECK(program); |
1412 program->ClearUniforms(&zero_); | 1416 program->ClearUniforms(&zero_); |
1413 } | 1417 } |
1414 | 1418 |
1415 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { | 1419 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { |
1416 return index + element * 0x10000; | 1420 return index + element * 0x10000; |
1417 } | 1421 } |
1418 | 1422 |
1419 } // namespace gles2 | 1423 } // namespace gles2 |
1420 } // namespace gpu | 1424 } // namespace gpu |
OLD | NEW |