Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "gpu/command_buffer/service/memory_program_cache.h" | |
| 6 #include "base/bind.h" | |
| 7 #include "base/file_path.h" | |
| 8 #include "base/sha1.h" | |
| 9 #include "net/disk_cache/disk_cache.h" | |
| 10 #include "ui/gl/gl_bindings.h" | |
| 11 | |
| 12 namespace gpu { | |
| 13 namespace gles2 { | |
| 14 | |
| 15 typedef std::map<std::string, GLint> location_map; | |
|
greggman
2012/06/19 22:27:50
style: types are CamelCase
Also, this should be i
dmurph
2012/06/23 01:37:28
Done.
| |
| 16 | |
| 17 MemoryProgramCache::MemoryProgramCache() {} | |
| 18 | |
| 19 MemoryProgramCache::~MemoryProgramCache() { | |
| 20 store_map::iterator it; | |
| 21 for(it = store_.begin(); it != store_.end();) { | |
| 22 CachedProgramKey key = it->first; | |
| 23 StoreValue value = it->second; | |
| 24 ++it; | |
| 25 store_.erase(key); | |
|
greggman
2012/06/19 22:27:50
I don't think you can delete things like this from
dmurph
2012/06/23 01:37:28
This way works correctly. Although I'm removing t
| |
| 26 delete[] key.hashed_src_0; | |
| 27 delete[] key.hashed_src_1; | |
| 28 delete key.bind_attrib_location_map; | |
| 29 delete[] (char*)value.data; | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 void MemoryProgramCache::LoadLinkedProgram( | |
| 34 GLuint program, | |
| 35 ShaderManager::ShaderInfo* shader_a, | |
| 36 ShaderManager::ShaderInfo* shader_b, | |
| 37 location_map* bind_attrib_location_map) const { | |
| 38 unsigned char sha1_a[kHashLength]; | |
| 39 unsigned char sha1_b[kHashLength]; | |
| 40 computeHash(*shader_a->source(), sha1_a); | |
| 41 computeHash(*shader_b->source(), sha1_b); | |
| 42 | |
| 43 CachedProgramKey key(sha1_a, sha1_b, bind_attrib_location_map); | |
| 44 StoreValue value = store_.find(key)->second; | |
| 45 glProgramBinary(program, value.format, value.data, value.length); | |
| 46 shader_a->SetAttribMap(value.attrib_map_0); | |
| 47 shader_a->SetUniformMap(value.uniform_map_0); | |
| 48 shader_b->SetAttribMap(value.attrib_map_1); | |
| 49 shader_b->SetUniformMap(value.uniform_map_1); | |
| 50 } | |
| 51 | |
| 52 void MemoryProgramCache::SaveLinkedProgram( | |
| 53 GLuint program, | |
| 54 ShaderManager::ShaderInfo* shader_a, | |
| 55 ShaderManager::ShaderInfo* shader_b, | |
| 56 location_map* bind_attrib_location_map) { | |
| 57 GLsizei length; | |
| 58 GLenum format; | |
| 59 GLsizei bufferlength = 0; | |
| 60 glGetProgramiv(program, 0x8741, &bufferlength); | |
| 61 GLvoid* binary = new char[bufferlength]; | |
| 62 glGetProgramBinary(program, | |
| 63 bufferlength, | |
| 64 &length, | |
| 65 &format, | |
| 66 binary); | |
| 67 if(length == 0) { | |
| 68 fprintf(stderr, "got length of 0\n"); | |
| 69 SetLinkedProgramStatus(*shader_a->source(), | |
| 70 *shader_b->source(), | |
| 71 bind_attrib_location_map, | |
| 72 LINK_UNKNOWN); | |
| 73 return; | |
| 74 } | |
| 75 | |
| 76 unsigned char sha1_a[kHashLength]; | |
| 77 unsigned char sha1_b[kHashLength]; | |
| 78 computeHash(*shader_a->source(), sha1_a); | |
| 79 computeHash(*shader_b->source(), sha1_b); | |
| 80 | |
| 81 StoreValue value(length, | |
| 82 format, | |
| 83 binary, | |
| 84 shader_a->attrib_map(), | |
| 85 shader_a->uniform_map(), | |
| 86 shader_b->attrib_map(), | |
| 87 shader_b->uniform_map()); | |
| 88 | |
| 89 CachedProgramKey key(sha1_a, sha1_b, bind_attrib_location_map); | |
| 90 if (store_.find(key) == store_.end()) { | |
| 91 unsigned char* allocated_sha_a = new unsigned char[kHashLength]; | |
| 92 unsigned char* allocated_sha_b = new unsigned char[kHashLength]; | |
| 93 location_map* allocated_location_map = bind_attrib_location_map != NULL ? | |
| 94 new location_map(*bind_attrib_location_map) : | |
| 95 NULL; | |
| 96 memcpy(allocated_sha_a, sha1_a, kHashLength); | |
| 97 memcpy(allocated_sha_b, sha1_b, kHashLength); | |
| 98 | |
| 99 CachedProgramKey allocated_key(allocated_sha_a, | |
| 100 allocated_sha_b, | |
| 101 allocated_location_map); | |
| 102 store_[allocated_key] = value; | |
| 103 } else { | |
| 104 store_[key] = value; | |
| 105 } | |
| 106 SetLinkedProgramStatus(*shader_a->source(), | |
| 107 *shader_b->source(), | |
| 108 bind_attrib_location_map, | |
| 109 LINK_SUCCEEDED); | |
| 110 } | |
| 111 | |
| 112 } // namespace gles2 | |
| 113 } // namespace gpu | |
| OLD | NEW |