| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/sha1.h" | 13 #include "base/sha1.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "gpu/command_buffer/common/activity_flags.h" |
| 15 #include "gpu/command_buffer/common/constants.h" | 16 #include "gpu/command_buffer/common/constants.h" |
| 16 #include "gpu/command_buffer/service/disk_cache_proto.pb.h" | 17 #include "gpu/command_buffer/service/disk_cache_proto.pb.h" |
| 17 #include "gpu/command_buffer/service/gl_utils.h" | 18 #include "gpu/command_buffer/service/gl_utils.h" |
| 18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 19 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 19 #include "gpu/command_buffer/service/gpu_preferences.h" | 20 #include "gpu/command_buffer/service/gpu_preferences.h" |
| 20 #include "gpu/command_buffer/service/shader_manager.h" | 21 #include "gpu/command_buffer/service/shader_manager.h" |
| 21 #include "ui/gl/gl_bindings.h" | 22 #include "ui/gl/gl_bindings.h" |
| 22 | 23 |
| 23 namespace gpu { | 24 namespace gpu { |
| 24 namespace gles2 { | 25 namespace gles2 { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return gl::g_current_gl_driver && | 205 return gl::g_current_gl_driver && |
| 205 (gl::g_current_gl_driver->ext.b_GL_ARB_get_program_binary || | 206 (gl::g_current_gl_driver->ext.b_GL_ARB_get_program_binary || |
| 206 gl::g_current_gl_driver->ext.b_GL_OES_get_program_binary); | 207 gl::g_current_gl_driver->ext.b_GL_OES_get_program_binary); |
| 207 } | 208 } |
| 208 | 209 |
| 209 } // namespace | 210 } // namespace |
| 210 | 211 |
| 211 MemoryProgramCache::MemoryProgramCache( | 212 MemoryProgramCache::MemoryProgramCache( |
| 212 size_t max_cache_size_bytes, | 213 size_t max_cache_size_bytes, |
| 213 bool disable_gpu_shader_disk_cache, | 214 bool disable_gpu_shader_disk_cache, |
| 214 bool disable_program_caching_for_transform_feedback) | 215 bool disable_program_caching_for_transform_feedback, |
| 216 GpuProcessActivityFlags* activity_flags) |
| 215 : max_size_bytes_(max_cache_size_bytes), | 217 : max_size_bytes_(max_cache_size_bytes), |
| 216 disable_gpu_shader_disk_cache_(disable_gpu_shader_disk_cache), | 218 disable_gpu_shader_disk_cache_(disable_gpu_shader_disk_cache), |
| 217 disable_program_caching_for_transform_feedback_( | 219 disable_program_caching_for_transform_feedback_( |
| 218 disable_program_caching_for_transform_feedback), | 220 disable_program_caching_for_transform_feedback), |
| 219 curr_size_bytes_(0), | 221 curr_size_bytes_(0), |
| 220 store_(ProgramMRUCache::NO_AUTO_EVICT) { | 222 store_(ProgramMRUCache::NO_AUTO_EVICT), |
| 221 } | 223 activity_flags_(activity_flags) {} |
| 222 | 224 |
| 223 MemoryProgramCache::~MemoryProgramCache() {} | 225 MemoryProgramCache::~MemoryProgramCache() {} |
| 224 | 226 |
| 225 void MemoryProgramCache::ClearBackend() { | 227 void MemoryProgramCache::ClearBackend() { |
| 226 store_.Clear(); | 228 store_.Clear(); |
| 227 DCHECK_EQ(0U, curr_size_bytes_); | 229 DCHECK_EQ(0U, curr_size_bytes_); |
| 228 } | 230 } |
| 229 | 231 |
| 230 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram( | 232 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram( |
| 231 GLuint program, | 233 GLuint program, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 256 transform_feedback_varyings, | 258 transform_feedback_varyings, |
| 257 transform_feedback_buffer_mode, | 259 transform_feedback_buffer_mode, |
| 258 sha); | 260 sha); |
| 259 const std::string sha_string(sha, kHashLength); | 261 const std::string sha_string(sha, kHashLength); |
| 260 | 262 |
| 261 ProgramMRUCache::iterator found = store_.Get(sha_string); | 263 ProgramMRUCache::iterator found = store_.Get(sha_string); |
| 262 if (found == store_.end()) { | 264 if (found == store_.end()) { |
| 263 return PROGRAM_LOAD_FAILURE; | 265 return PROGRAM_LOAD_FAILURE; |
| 264 } | 266 } |
| 265 const scoped_refptr<ProgramCacheValue> value = found->second; | 267 const scoped_refptr<ProgramCacheValue> value = found->second; |
| 266 glProgramBinary(program, | 268 |
| 267 value->format(), | 269 { |
| 268 static_cast<const GLvoid*>(value->data()), | 270 GpuProcessActivityFlags::ScopedSetFlag scoped_set_flag( |
| 269 value->length()); | 271 activity_flags_, ActivityFlagsBase::FLAG_LOADING_PROGRAM_BINARY); |
| 272 glProgramBinary(program, value->format(), |
| 273 static_cast<const GLvoid*>(value->data()), value->length()); |
| 274 } |
| 275 |
| 270 GLint success = 0; | 276 GLint success = 0; |
| 271 glGetProgramiv(program, GL_LINK_STATUS, &success); | 277 glGetProgramiv(program, GL_LINK_STATUS, &success); |
| 272 if (success == GL_FALSE) { | 278 if (success == GL_FALSE) { |
| 273 return PROGRAM_LOAD_FAILURE; | 279 return PROGRAM_LOAD_FAILURE; |
| 274 } | 280 } |
| 275 shader_a->set_attrib_map(value->attrib_map_0()); | 281 shader_a->set_attrib_map(value->attrib_map_0()); |
| 276 shader_a->set_uniform_map(value->uniform_map_0()); | 282 shader_a->set_uniform_map(value->uniform_map_0()); |
| 277 shader_a->set_varying_map(value->varying_map_0()); | 283 shader_a->set_varying_map(value->varying_map_0()); |
| 278 shader_a->set_output_variable_list(value->output_variable_list_0()); | 284 shader_a->set_output_variable_list(value->output_variable_list_0()); |
| 279 shader_a->set_interface_block_map(value->interface_block_map_0()); | 285 shader_a->set_interface_block_map(value->interface_block_map_0()); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 program_cache_->LinkedProgramCacheSuccess(program_hash); | 510 program_cache_->LinkedProgramCacheSuccess(program_hash); |
| 505 } | 511 } |
| 506 | 512 |
| 507 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { | 513 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { |
| 508 program_cache_->curr_size_bytes_ -= length_; | 514 program_cache_->curr_size_bytes_ -= length_; |
| 509 program_cache_->Evict(program_hash_); | 515 program_cache_->Evict(program_hash_); |
| 510 } | 516 } |
| 511 | 517 |
| 512 } // namespace gles2 | 518 } // namespace gles2 |
| 513 } // namespace gpu | 519 } // namespace gpu |
| OLD | NEW |