| 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/memory_program_cache.h" | 5 #include "gpu/command_buffer/service/memory_program_cache.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 std::string shader; | 195 std::string shader; |
| 196 proto->SerializeToString(&shader); | 196 proto->SerializeToString(&shader); |
| 197 | 197 |
| 198 std::string key; | 198 std::string key; |
| 199 base::Base64Encode(sha_string, &key); | 199 base::Base64Encode(sha_string, &key); |
| 200 callback.Run(key, shader); | 200 callback.Run(key, shader); |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace | 203 } // namespace |
| 204 | 204 |
| 205 MemoryProgramCache::MemoryProgramCache(size_t max_cache_size_bytes, | 205 MemoryProgramCache::MemoryProgramCache( |
| 206 bool disable_gpu_shader_disk_cache) | 206 size_t max_cache_size_bytes, |
| 207 bool disable_gpu_shader_disk_cache, |
| 208 bool disable_program_caching_for_transform_feedback) |
| 207 : max_size_bytes_(max_cache_size_bytes), | 209 : max_size_bytes_(max_cache_size_bytes), |
| 208 disable_gpu_shader_disk_cache_(disable_gpu_shader_disk_cache), | 210 disable_gpu_shader_disk_cache_(disable_gpu_shader_disk_cache), |
| 211 disable_program_caching_for_transform_feedback_( |
| 212 disable_program_caching_for_transform_feedback), |
| 209 curr_size_bytes_(0), | 213 curr_size_bytes_(0), |
| 210 store_(ProgramMRUCache::NO_AUTO_EVICT) { | 214 store_(ProgramMRUCache::NO_AUTO_EVICT) { |
| 211 } | 215 } |
| 212 | 216 |
| 213 MemoryProgramCache::~MemoryProgramCache() {} | 217 MemoryProgramCache::~MemoryProgramCache() {} |
| 214 | 218 |
| 215 void MemoryProgramCache::ClearBackend() { | 219 void MemoryProgramCache::ClearBackend() { |
| 216 store_.Clear(); | 220 store_.Clear(); |
| 217 DCHECK_EQ(0U, curr_size_bytes_); | 221 DCHECK_EQ(0U, curr_size_bytes_); |
| 218 } | 222 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 288 } |
| 285 | 289 |
| 286 void MemoryProgramCache::SaveLinkedProgram( | 290 void MemoryProgramCache::SaveLinkedProgram( |
| 287 GLuint program, | 291 GLuint program, |
| 288 const Shader* shader_a, | 292 const Shader* shader_a, |
| 289 const Shader* shader_b, | 293 const Shader* shader_b, |
| 290 const LocationMap* bind_attrib_location_map, | 294 const LocationMap* bind_attrib_location_map, |
| 291 const std::vector<std::string>& transform_feedback_varyings, | 295 const std::vector<std::string>& transform_feedback_varyings, |
| 292 GLenum transform_feedback_buffer_mode, | 296 GLenum transform_feedback_buffer_mode, |
| 293 const ShaderCacheCallback& shader_callback) { | 297 const ShaderCacheCallback& shader_callback) { |
| 298 if (disable_program_caching_for_transform_feedback_ && |
| 299 !transform_feedback_varyings.empty()) { |
| 300 return; |
| 301 } |
| 294 GLenum format; | 302 GLenum format; |
| 295 GLsizei length = 0; | 303 GLsizei length = 0; |
| 296 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length); | 304 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length); |
| 297 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) { | 305 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) { |
| 298 return; | 306 return; |
| 299 } | 307 } |
| 300 std::unique_ptr<char[]> binary(new char[length]); | 308 std::unique_ptr<char[]> binary(new char[length]); |
| 301 glGetProgramBinary(program, | 309 glGetProgramBinary(program, |
| 302 length, | 310 length, |
| 303 NULL, | 311 NULL, |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 program_cache_->LinkedProgramCacheSuccess(program_hash); | 489 program_cache_->LinkedProgramCacheSuccess(program_hash); |
| 482 } | 490 } |
| 483 | 491 |
| 484 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { | 492 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { |
| 485 program_cache_->curr_size_bytes_ -= length_; | 493 program_cache_->curr_size_bytes_ -= length_; |
| 486 program_cache_->Evict(program_hash_); | 494 program_cache_->Evict(program_hash_); |
| 487 } | 495 } |
| 488 | 496 |
| 489 } // namespace gles2 | 497 } // namespace gles2 |
| 490 } // namespace gpu | 498 } // namespace gpu |
| OLD | NEW |