From 467cbf47df58dbc215b058958bd07ab3d359c83e Mon Sep 17 00:00:00 2001 From: "dmurph@chromium.org" Date: Tue, 31 Jul 2012 01:19:13 +0000 Subject: Added null check for shader source when compiling, and fixed re-caching behavior to spec BUG=139711,139681 Review URL: https://chromiumcodereview.appspot.com/10826073 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149104 0039d316-1c4b-4281-b951-d872f2087c98 --- gpu/command_buffer/service/memory_program_cache.cc | 22 +++++++------- .../service/memory_program_cache_unittest.cc | 34 +++++++++++++++++++++- gpu/command_buffer/service/program_manager.cc | 3 +- 3 files changed, 46 insertions(+), 13 deletions(-) (limited to 'gpu/command_buffer/service') diff --git a/gpu/command_buffer/service/memory_program_cache.cc b/gpu/command_buffer/service/memory_program_cache.cc index 0a061cb..e669ac4 100644 --- a/gpu/command_buffer/service/memory_program_cache.cc +++ b/gpu/command_buffer/service/memory_program_cache.cc @@ -88,22 +88,18 @@ void MemoryProgramCache::SaveLinkedProgram( const ShaderManager::ShaderInfo* shader_a, const ShaderManager::ShaderInfo* shader_b, const LocationMap* bind_attrib_location_map) { - GLsizei length; GLenum format; - GLsizei buffer_length = 0; - glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &buffer_length); - if (static_cast(buffer_length) > max_size_bytes_) { + GLsizei length = 0; + glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length); + if (length == 0 || static_cast(length) > max_size_bytes_) { return; } - scoped_array binary(new char[buffer_length]); + scoped_array binary(new char[length]); glGetProgramBinary(program, - buffer_length, - &length, + length, + NULL, &format, binary.get()); - if (length == 0) { - return; - } char a_sha[kHashLength]; char b_sha[kHashLength]; @@ -118,7 +114,11 @@ void MemoryProgramCache::SaveLinkedProgram( const std::string sha_string(sha, sizeof(sha)); if (store_.find(sha_string) != store_.end()) { - return; + const StoreMap::iterator found = store_.find(sha_string); + const ProgramCacheValue* evicting = found->second; + curr_size_bytes_ -= evicting->length; + Evict(sha_string, evicting->shader_0_hash, evicting->shader_1_hash); + store_.erase(found); } while (curr_size_bytes_ + length > max_size_bytes_) { diff --git a/gpu/command_buffer/service/memory_program_cache_unittest.cc b/gpu/command_buffer/service/memory_program_cache_unittest.cc index 5d40785..7d3f3e6 100644 --- a/gpu/command_buffer/service/memory_program_cache_unittest.cc +++ b/gpu/command_buffer/service/memory_program_cache_unittest.cc @@ -38,7 +38,9 @@ class ProgramBinaryEmulator { GLsizei* length, GLenum* format, GLvoid* binary) { - *length = length_; + if (length) { + *length = length_; + } *format = format_; memcpy(binary, binary_, length_); } @@ -413,5 +415,35 @@ TEST_F(MemoryProgramCacheTest, LoadCorrectProgram) { NULL)); } +TEST_F(MemoryProgramCacheTest, OverwriteOnNewSave) { + const GLenum kFormat = 1; + const int kProgramId = 10; + const int kBinaryLength = 20; + char test_binary[kBinaryLength]; + for (int i = 0; i < kBinaryLength; ++i) { + test_binary[i] = i; + } + ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary); + + SetExpectationsForSaveLinkedProgram(kProgramId, &emulator); + cache_->SaveLinkedProgram(kProgramId, vertex_shader_, fragment_shader_, NULL); + + + char test_binary2[kBinaryLength]; + for (int i = 0; i < kBinaryLength; ++i) { + test_binary2[i] = (i*2) % 250; + } + ProgramBinaryEmulator emulator2(kBinaryLength, kFormat, test_binary2); + SetExpectationsForSaveLinkedProgram(kProgramId, &emulator2); + cache_->SaveLinkedProgram(kProgramId, vertex_shader_, fragment_shader_, NULL); + + SetExpectationsForLoadLinkedProgram(kProgramId, &emulator2); + EXPECT_EQ(ProgramCache::PROGRAM_LOAD_SUCCESS, cache_->LoadLinkedProgram( + kProgramId, + vertex_shader_, + fragment_shader_, + NULL)); +} + } // namespace gles2 } // namespace gpu diff --git a/gpu/command_buffer/service/program_manager.cc b/gpu/command_buffer/service/program_manager.cc index 21b9238..b109be9 100644 --- a/gpu/command_buffer/service/program_manager.cc +++ b/gpu/command_buffer/service/program_manager.cc @@ -382,7 +382,8 @@ void ProgramManager::DoCompileShader(ShaderManager::ShaderInfo* info, ShaderTranslator* translator, FeatureInfo* feature_info) { if (program_cache_ && - program_cache_->GetShaderCompilationStatus(*info->source()) == + program_cache_->GetShaderCompilationStatus(info->source() ? + *info->source() : "") == ProgramCache::COMPILATION_SUCCEEDED) { info->SetStatus(true, "", translator); info->FlagSourceAsCompiled(false); -- cgit v1.1