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

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

Issue 1859703002: convert //gpu to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 4 years, 8 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"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 shader_a->set_attrib_map(value->attrib_map_0()); 207 shader_a->set_attrib_map(value->attrib_map_0());
208 shader_a->set_uniform_map(value->uniform_map_0()); 208 shader_a->set_uniform_map(value->uniform_map_0());
209 shader_a->set_varying_map(value->varying_map_0()); 209 shader_a->set_varying_map(value->varying_map_0());
210 shader_a->set_output_variable_list(value->output_variable_list_0()); 210 shader_a->set_output_variable_list(value->output_variable_list_0());
211 shader_b->set_attrib_map(value->attrib_map_1()); 211 shader_b->set_attrib_map(value->attrib_map_1());
212 shader_b->set_uniform_map(value->uniform_map_1()); 212 shader_b->set_uniform_map(value->uniform_map_1());
213 shader_b->set_varying_map(value->varying_map_1()); 213 shader_b->set_varying_map(value->varying_map_1());
214 shader_b->set_output_variable_list(value->output_variable_list_1()); 214 shader_b->set_output_variable_list(value->output_variable_list_1());
215 215
216 if (!shader_callback.is_null() && !disable_gpu_shader_disk_cache_) { 216 if (!shader_callback.is_null() && !disable_gpu_shader_disk_cache_) {
217 scoped_ptr<GpuProgramProto> proto( 217 std::unique_ptr<GpuProgramProto> proto(
218 GpuProgramProto::default_instance().New()); 218 GpuProgramProto::default_instance().New());
219 proto->set_sha(sha, kHashLength); 219 proto->set_sha(sha, kHashLength);
220 proto->set_format(value->format()); 220 proto->set_format(value->format());
221 proto->set_program(value->data(), value->length()); 221 proto->set_program(value->data(), value->length());
222 222
223 FillShaderProto(proto->mutable_vertex_shader(), a_sha, shader_a); 223 FillShaderProto(proto->mutable_vertex_shader(), a_sha, shader_a);
224 FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b); 224 FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b);
225 RunShaderCallback(shader_callback, proto.get(), sha_string); 225 RunShaderCallback(shader_callback, proto.get(), sha_string);
226 } 226 }
227 227
228 return PROGRAM_LOAD_SUCCESS; 228 return PROGRAM_LOAD_SUCCESS;
229 } 229 }
230 230
231 void MemoryProgramCache::SaveLinkedProgram( 231 void MemoryProgramCache::SaveLinkedProgram(
232 GLuint program, 232 GLuint program,
233 const Shader* shader_a, 233 const Shader* shader_a,
234 const Shader* shader_b, 234 const Shader* shader_b,
235 const LocationMap* bind_attrib_location_map, 235 const LocationMap* bind_attrib_location_map,
236 const std::vector<std::string>& transform_feedback_varyings, 236 const std::vector<std::string>& transform_feedback_varyings,
237 GLenum transform_feedback_buffer_mode, 237 GLenum transform_feedback_buffer_mode,
238 const ShaderCacheCallback& shader_callback) { 238 const ShaderCacheCallback& shader_callback) {
239 GLenum format; 239 GLenum format;
240 GLsizei length = 0; 240 GLsizei length = 0;
241 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length); 241 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length);
242 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) { 242 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) {
243 return; 243 return;
244 } 244 }
245 scoped_ptr<char[]> binary(new char[length]); 245 std::unique_ptr<char[]> binary(new char[length]);
246 glGetProgramBinary(program, 246 glGetProgramBinary(program,
247 length, 247 length,
248 NULL, 248 NULL,
249 &format, 249 &format,
250 binary.get()); 250 binary.get());
251 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.ProgramBinarySizeBytes", length); 251 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.ProgramBinarySizeBytes", length);
252 252
253 char a_sha[kHashLength]; 253 char a_sha[kHashLength];
254 char b_sha[kHashLength]; 254 char b_sha[kHashLength];
255 DCHECK(shader_a && !shader_a->last_compiled_source().empty() && 255 DCHECK(shader_a && !shader_a->last_compiled_source().empty() &&
(...skipping 20 matching lines...) Expand all
276 ProgramMRUCache::iterator existing = store_.Peek(sha_string); 276 ProgramMRUCache::iterator existing = store_.Peek(sha_string);
277 if(existing != store_.end()) 277 if(existing != store_.end())
278 store_.Erase(existing); 278 store_.Erase(existing);
279 279
280 while (curr_size_bytes_ + length > max_size_bytes_) { 280 while (curr_size_bytes_ + length > max_size_bytes_) {
281 DCHECK(!store_.empty()); 281 DCHECK(!store_.empty());
282 store_.Erase(store_.rbegin()); 282 store_.Erase(store_.rbegin());
283 } 283 }
284 284
285 if (!shader_callback.is_null() && !disable_gpu_shader_disk_cache_) { 285 if (!shader_callback.is_null() && !disable_gpu_shader_disk_cache_) {
286 scoped_ptr<GpuProgramProto> proto( 286 std::unique_ptr<GpuProgramProto> proto(
287 GpuProgramProto::default_instance().New()); 287 GpuProgramProto::default_instance().New());
288 proto->set_sha(sha, kHashLength); 288 proto->set_sha(sha, kHashLength);
289 proto->set_format(format); 289 proto->set_format(format);
290 proto->set_program(binary.get(), length); 290 proto->set_program(binary.get(), length);
291 291
292 FillShaderProto(proto->mutable_vertex_shader(), a_sha, shader_a); 292 FillShaderProto(proto->mutable_vertex_shader(), a_sha, shader_a);
293 FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b); 293 FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b);
294 RunShaderCallback(shader_callback, proto.get(), sha_string); 294 RunShaderCallback(shader_callback, proto.get(), sha_string);
295 } 295 }
296 296
297 store_.Put( 297 store_.Put(
298 sha_string, 298 sha_string,
299 new ProgramCacheValue( 299 new ProgramCacheValue(
300 length, format, binary.release(), sha_string, a_sha, 300 length, format, binary.release(), sha_string, a_sha,
301 shader_a->attrib_map(), shader_a->uniform_map(), 301 shader_a->attrib_map(), shader_a->uniform_map(),
302 shader_a->varying_map(), shader_a->output_variable_list(), b_sha, 302 shader_a->varying_map(), shader_a->output_variable_list(), b_sha,
303 shader_b->attrib_map(), shader_b->uniform_map(), 303 shader_b->attrib_map(), shader_b->uniform_map(),
304 shader_b->varying_map(), shader_b->output_variable_list(), this)); 304 shader_b->varying_map(), shader_b->output_variable_list(), this));
305 305
306 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.MemorySizeAfterKb", 306 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.MemorySizeAfterKb",
307 curr_size_bytes_ / 1024); 307 curr_size_bytes_ / 1024);
308 } 308 }
309 309
310 void MemoryProgramCache::LoadProgram(const std::string& program) { 310 void MemoryProgramCache::LoadProgram(const std::string& program) {
311 scoped_ptr<GpuProgramProto> proto(GpuProgramProto::default_instance().New()); 311 std::unique_ptr<GpuProgramProto> proto(
312 GpuProgramProto::default_instance().New());
312 if (proto->ParseFromString(program)) { 313 if (proto->ParseFromString(program)) {
313 AttributeMap vertex_attribs; 314 AttributeMap vertex_attribs;
314 UniformMap vertex_uniforms; 315 UniformMap vertex_uniforms;
315 VaryingMap vertex_varyings; 316 VaryingMap vertex_varyings;
316 OutputVariableList vertex_output_variables; 317 OutputVariableList vertex_output_variables;
317 for (int i = 0; i < proto->vertex_shader().attribs_size(); i++) { 318 for (int i = 0; i < proto->vertex_shader().attribs_size(); i++) {
318 RetrieveShaderAttributeInfo(proto->vertex_shader().attribs(i), 319 RetrieveShaderAttributeInfo(proto->vertex_shader().attribs(i),
319 &vertex_attribs); 320 &vertex_attribs);
320 } 321 }
321 for (int i = 0; i < proto->vertex_shader().uniforms_size(); i++) { 322 for (int i = 0; i < proto->vertex_shader().uniforms_size(); i++) {
(...skipping 24 matching lines...) Expand all
346 for (int i = 0; i < proto->fragment_shader().varyings_size(); i++) { 347 for (int i = 0; i < proto->fragment_shader().varyings_size(); i++) {
347 RetrieveShaderVaryingInfo(proto->fragment_shader().varyings(i), 348 RetrieveShaderVaryingInfo(proto->fragment_shader().varyings(i),
348 &fragment_varyings); 349 &fragment_varyings);
349 } 350 }
350 for (int i = 0; i < proto->fragment_shader().output_variables_size(); i++) { 351 for (int i = 0; i < proto->fragment_shader().output_variables_size(); i++) {
351 RetrieveShaderOutputVariableInfo( 352 RetrieveShaderOutputVariableInfo(
352 proto->fragment_shader().output_variables(i), 353 proto->fragment_shader().output_variables(i),
353 &fragment_output_variables); 354 &fragment_output_variables);
354 } 355 }
355 356
356 scoped_ptr<char[]> binary(new char[proto->program().length()]); 357 std::unique_ptr<char[]> binary(new char[proto->program().length()]);
357 memcpy(binary.get(), proto->program().c_str(), proto->program().length()); 358 memcpy(binary.get(), proto->program().c_str(), proto->program().length());
358 359
359 store_.Put( 360 store_.Put(
360 proto->sha(), 361 proto->sha(),
361 new ProgramCacheValue( 362 new ProgramCacheValue(
362 proto->program().length(), proto->format(), binary.release(), 363 proto->program().length(), proto->format(), binary.release(),
363 proto->sha(), proto->vertex_shader().sha().c_str(), vertex_attribs, 364 proto->sha(), proto->vertex_shader().sha().c_str(), vertex_attribs,
364 vertex_uniforms, vertex_varyings, vertex_output_variables, 365 vertex_uniforms, vertex_varyings, vertex_output_variables,
365 proto->fragment_shader().sha().c_str(), fragment_attribs, 366 proto->fragment_shader().sha().c_str(), fragment_attribs,
366 fragment_uniforms, fragment_varyings, fragment_output_variables, 367 fragment_uniforms, fragment_varyings, fragment_output_variables,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 program_cache_->LinkedProgramCacheSuccess(program_hash); 409 program_cache_->LinkedProgramCacheSuccess(program_hash);
409 } 410 }
410 411
411 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { 412 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() {
412 program_cache_->curr_size_bytes_ -= length_; 413 program_cache_->curr_size_bytes_ -= length_;
413 program_cache_->Evict(program_hash_); 414 program_cache_->Evict(program_hash_);
414 } 415 }
415 416
416 } // namespace gles2 417 } // namespace gles2
417 } // namespace gpu 418 } // 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