Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: gpu/command_buffer/service/memory_program_cache.cc

Issue 1716813002: Use GpuPreferences to avoid directly accessing switches in gpu related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.h" 12 #include "base/metrics/histogram.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/constants.h" 15 #include "gpu/command_buffer/common/constants.h"
16 #include "gpu/command_buffer/service/disk_cache_proto.pb.h" 16 #include "gpu/command_buffer/service/disk_cache_proto.pb.h"
17 #include "gpu/command_buffer/service/gl_utils.h" 17 #include "gpu/command_buffer/service/gl_utils.h"
18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
19 #include "gpu/command_buffer/service/gpu_switches.h" 19 #include "gpu/command_buffer/service/gpu_preferences.h"
20 #include "gpu/command_buffer/service/shader_manager.h" 20 #include "gpu/command_buffer/service/shader_manager.h"
21 #include "ui/gl/gl_bindings.h" 21 #include "ui/gl/gl_bindings.h"
22 22
23 namespace {
24
25 size_t GetCacheSizeBytes() {
26 const base::CommandLine* command_line =
27 base::CommandLine::ForCurrentProcess();
28 if (command_line->HasSwitch(switches::kGpuProgramCacheSizeKb)) {
29 size_t size;
30 if (base::StringToSizeT(
31 command_line->GetSwitchValueNative(switches::kGpuProgramCacheSizeKb),
32 &size))
33 return size * 1024;
34 }
35 return gpu::kDefaultMaxProgramCacheMemoryBytes;
36 }
37
38 } // anonymous namespace
39
40 namespace gpu { 23 namespace gpu {
41 namespace gles2 { 24 namespace gles2 {
42 25
43 namespace { 26 namespace {
44 27
45 void FillShaderVariableProto( 28 void FillShaderVariableProto(
46 ShaderVariableProto* proto, const sh::ShaderVariable& variable) { 29 ShaderVariableProto* proto, const sh::ShaderVariable& variable) {
47 proto->set_type(variable.type); 30 proto->set_type(variable.type);
48 proto->set_precision(variable.precision); 31 proto->set_precision(variable.precision);
49 proto->set_name(variable.name); 32 proto->set_name(variable.name);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 std::string shader; 142 std::string shader;
160 proto->SerializeToString(&shader); 143 proto->SerializeToString(&shader);
161 144
162 std::string key; 145 std::string key;
163 base::Base64Encode(sha_string, &key); 146 base::Base64Encode(sha_string, &key);
164 callback.Run(key, shader); 147 callback.Run(key, shader);
165 } 148 }
166 149
167 } // namespace 150 } // namespace
168 151
169 MemoryProgramCache::MemoryProgramCache() 152 MemoryProgramCache::MemoryProgramCache(size_t max_cache_size_bytes,
170 : max_size_bytes_(GetCacheSizeBytes()), 153 bool disable_gpu_shader_disk_cache)
154 : max_size_bytes_(max_cache_size_bytes),
155 disable_gpu_shader_disk_cache_(disable_gpu_shader_disk_cache),
171 curr_size_bytes_(0), 156 curr_size_bytes_(0),
172 store_(ProgramMRUCache::NO_AUTO_EVICT) { 157 store_(ProgramMRUCache::NO_AUTO_EVICT) {
173 } 158 }
174
175 MemoryProgramCache::MemoryProgramCache(const size_t max_cache_size_bytes)
176 : max_size_bytes_(max_cache_size_bytes),
177 curr_size_bytes_(0),
178 store_(ProgramMRUCache::NO_AUTO_EVICT) {
179 }
180 159
181 MemoryProgramCache::~MemoryProgramCache() {} 160 MemoryProgramCache::~MemoryProgramCache() {}
182 161
183 void MemoryProgramCache::ClearBackend() { 162 void MemoryProgramCache::ClearBackend() {
184 store_.Clear(); 163 store_.Clear();
185 DCHECK_EQ(0U, curr_size_bytes_); 164 DCHECK_EQ(0U, curr_size_bytes_);
186 } 165 }
187 166
188 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram( 167 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram(
189 GLuint program, 168 GLuint program,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 206 }
228 shader_a->set_attrib_map(value->attrib_map_0()); 207 shader_a->set_attrib_map(value->attrib_map_0());
229 shader_a->set_uniform_map(value->uniform_map_0()); 208 shader_a->set_uniform_map(value->uniform_map_0());
230 shader_a->set_varying_map(value->varying_map_0()); 209 shader_a->set_varying_map(value->varying_map_0());
231 shader_a->set_output_variable_list(value->output_variable_list_0()); 210 shader_a->set_output_variable_list(value->output_variable_list_0());
232 shader_b->set_attrib_map(value->attrib_map_1()); 211 shader_b->set_attrib_map(value->attrib_map_1());
233 shader_b->set_uniform_map(value->uniform_map_1()); 212 shader_b->set_uniform_map(value->uniform_map_1());
234 shader_b->set_varying_map(value->varying_map_1()); 213 shader_b->set_varying_map(value->varying_map_1());
235 shader_b->set_output_variable_list(value->output_variable_list_1()); 214 shader_b->set_output_variable_list(value->output_variable_list_1());
236 215
237 if (!shader_callback.is_null() && 216 if (!shader_callback.is_null() && !disable_gpu_shader_disk_cache_) {
238 !base::CommandLine::ForCurrentProcess()->HasSwitch(
239 switches::kDisableGpuShaderDiskCache)) {
240 scoped_ptr<GpuProgramProto> proto( 217 scoped_ptr<GpuProgramProto> proto(
241 GpuProgramProto::default_instance().New()); 218 GpuProgramProto::default_instance().New());
242 proto->set_sha(sha, kHashLength); 219 proto->set_sha(sha, kHashLength);
243 proto->set_format(value->format()); 220 proto->set_format(value->format());
244 proto->set_program(value->data(), value->length()); 221 proto->set_program(value->data(), value->length());
245 222
246 FillShaderProto(proto->mutable_vertex_shader(), a_sha, shader_a); 223 FillShaderProto(proto->mutable_vertex_shader(), a_sha, shader_a);
247 FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b); 224 FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b);
248 RunShaderCallback(shader_callback, proto.get(), sha_string); 225 RunShaderCallback(shader_callback, proto.get(), sha_string);
249 } 226 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // accessed. 275 // accessed.
299 ProgramMRUCache::iterator existing = store_.Peek(sha_string); 276 ProgramMRUCache::iterator existing = store_.Peek(sha_string);
300 if(existing != store_.end()) 277 if(existing != store_.end())
301 store_.Erase(existing); 278 store_.Erase(existing);
302 279
303 while (curr_size_bytes_ + length > max_size_bytes_) { 280 while (curr_size_bytes_ + length > max_size_bytes_) {
304 DCHECK(!store_.empty()); 281 DCHECK(!store_.empty());
305 store_.Erase(store_.rbegin()); 282 store_.Erase(store_.rbegin());
306 } 283 }
307 284
308 if (!shader_callback.is_null() && 285 if (!shader_callback.is_null() && !disable_gpu_shader_disk_cache_) {
309 !base::CommandLine::ForCurrentProcess()->HasSwitch(
310 switches::kDisableGpuShaderDiskCache)) {
311 scoped_ptr<GpuProgramProto> proto( 286 scoped_ptr<GpuProgramProto> proto(
312 GpuProgramProto::default_instance().New()); 287 GpuProgramProto::default_instance().New());
313 proto->set_sha(sha, kHashLength); 288 proto->set_sha(sha, kHashLength);
314 proto->set_format(format); 289 proto->set_format(format);
315 proto->set_program(binary.get(), length); 290 proto->set_program(binary.get(), length);
316 291
317 FillShaderProto(proto->mutable_vertex_shader(), a_sha, shader_a); 292 FillShaderProto(proto->mutable_vertex_shader(), a_sha, shader_a);
318 FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b); 293 FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b);
319 RunShaderCallback(shader_callback, proto.get(), sha_string); 294 RunShaderCallback(shader_callback, proto.get(), sha_string);
320 } 295 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 program_cache_->LinkedProgramCacheSuccess(program_hash); 408 program_cache_->LinkedProgramCacheSuccess(program_hash);
434 } 409 }
435 410
436 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { 411 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() {
437 program_cache_->curr_size_bytes_ -= length_; 412 program_cache_->curr_size_bytes_ -= length_;
438 program_cache_->Evict(program_hash_); 413 program_cache_->Evict(program_hash_);
439 } 414 }
440 415
441 } // namespace gles2 416 } // namespace gles2
442 } // namespace gpu 417 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/memory_program_cache.h ('k') | gpu/command_buffer/service/memory_program_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698