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_cache.h" | 5 #include "gpu/command_buffer/service/program_cache.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "gpu/command_buffer/service/shader_manager.h" | 8 #include "gpu/command_buffer/service/shader_manager.h" |
9 | 9 |
10 namespace gpu { | 10 namespace gpu { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 void ProgramCache::ComputeProgramHash( | 145 void ProgramCache::ComputeProgramHash( |
146 const char* hashed_shader_0, | 146 const char* hashed_shader_0, |
147 const char* hashed_shader_1, | 147 const char* hashed_shader_1, |
148 const std::map<std::string, GLint>* bind_attrib_location_map, | 148 const std::map<std::string, GLint>* bind_attrib_location_map, |
149 char* result) const { | 149 char* result) const { |
150 const size_t shader0_size = kHashLength; | 150 const size_t shader0_size = kHashLength; |
151 const size_t shader1_size = kHashLength; | 151 const size_t shader1_size = kHashLength; |
152 const size_t map_size = CalculateMapSize(bind_attrib_location_map); | 152 const size_t map_size = CalculateMapSize(bind_attrib_location_map); |
153 const size_t total_size = shader0_size + shader1_size + map_size; | 153 const size_t total_size = shader0_size + shader1_size + map_size; |
154 | 154 |
155 scoped_array<unsigned char> buffer(new unsigned char[total_size]); | 155 scoped_ptr<unsigned char[]> buffer(new unsigned char[total_size]); |
156 memcpy(buffer.get(), hashed_shader_0, shader0_size); | 156 memcpy(buffer.get(), hashed_shader_0, shader0_size); |
157 memcpy(&buffer[shader0_size], hashed_shader_1, shader1_size); | 157 memcpy(&buffer[shader0_size], hashed_shader_1, shader1_size); |
158 if (map_size != 0) { | 158 if (map_size != 0) { |
159 // copy our map | 159 // copy our map |
160 size_t current_pos = shader0_size + shader1_size; | 160 size_t current_pos = shader0_size + shader1_size; |
161 std::map<std::string, GLint>::const_iterator it; | 161 std::map<std::string, GLint>::const_iterator it; |
162 for (it = bind_attrib_location_map->begin(); | 162 for (it = bind_attrib_location_map->begin(); |
163 it != bind_attrib_location_map->end(); | 163 it != bind_attrib_location_map->end(); |
164 ++it) { | 164 ++it) { |
165 const size_t name_size = it->first.length(); | 165 const size_t name_size = it->first.length(); |
166 memcpy(&buffer.get()[current_pos], it->first.c_str(), name_size); | 166 memcpy(&buffer.get()[current_pos], it->first.c_str(), name_size); |
167 current_pos += name_size; | 167 current_pos += name_size; |
168 const GLint value = it->second; | 168 const GLint value = it->second; |
169 buffer[current_pos++] = value >> 24; | 169 buffer[current_pos++] = value >> 24; |
170 buffer[current_pos++] = value >> 16; | 170 buffer[current_pos++] = value >> 16; |
171 buffer[current_pos++] = value >> 8; | 171 buffer[current_pos++] = value >> 8; |
172 buffer[current_pos++] = value; | 172 buffer[current_pos++] = value; |
173 } | 173 } |
174 } | 174 } |
175 base::SHA1HashBytes(buffer.get(), | 175 base::SHA1HashBytes(buffer.get(), |
176 total_size, reinterpret_cast<unsigned char*>(result)); | 176 total_size, reinterpret_cast<unsigned char*>(result)); |
177 } | 177 } |
178 | 178 |
179 } // namespace gles2 | 179 } // namespace gles2 |
180 } // namespace gpu | 180 } // namespace gpu |
OLD | NEW |