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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include "gpu/command_buffer/client/program_info_manager.h" | 8 #include "gpu/command_buffer/client/program_info_manager.h" |
6 | 9 |
7 namespace { | 10 namespace { |
8 | 11 |
9 template<typename T> static T LocalGetAs( | 12 template <typename T> |
10 const std::vector<int8>& data, uint32 offset, size_t size) { | 13 static T LocalGetAs(const std::vector<int8_t>& data, |
11 const int8* p = &data[0] + offset; | 14 uint32_t offset, |
| 15 size_t size) { |
| 16 const int8_t* p = &data[0] + offset; |
12 if (offset + size > data.size()) { | 17 if (offset + size > data.size()) { |
13 NOTREACHED(); | 18 NOTREACHED(); |
14 return NULL; | 19 return NULL; |
15 } | 20 } |
16 return static_cast<T>(static_cast<const void*>(p)); | 21 return static_cast<T>(static_cast<const void*>(p)); |
17 } | 22 } |
18 | 23 |
19 } // namespace anonymous | 24 } // namespace anonymous |
20 | 25 |
21 namespace gpu { | 26 namespace gpu { |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 params[ii] = uniforms_es3_[indices[ii]].is_row_major; | 327 params[ii] = uniforms_es3_[indices[ii]].is_row_major; |
323 } | 328 } |
324 return true; | 329 return true; |
325 default: | 330 default: |
326 NOTREACHED(); | 331 NOTREACHED(); |
327 break; | 332 break; |
328 } | 333 } |
329 return false; | 334 return false; |
330 } | 335 } |
331 | 336 |
332 void ProgramInfoManager::Program::UpdateES2(const std::vector<int8>& result) { | 337 void ProgramInfoManager::Program::UpdateES2(const std::vector<int8_t>& result) { |
333 if (cached_es2_) { | 338 if (cached_es2_) { |
334 return; | 339 return; |
335 } | 340 } |
336 if (result.empty()) { | 341 if (result.empty()) { |
337 // This should only happen on a lost context. | 342 // This should only happen on a lost context. |
338 return; | 343 return; |
339 } | 344 } |
340 DCHECK_GE(result.size(), sizeof(ProgramInfoHeader)); | 345 DCHECK_GE(result.size(), sizeof(ProgramInfoHeader)); |
341 const ProgramInfoHeader* header = LocalGetAs<const ProgramInfoHeader*>( | 346 const ProgramInfoHeader* header = LocalGetAs<const ProgramInfoHeader*>( |
342 result, 0, sizeof(header)); | 347 result, 0, sizeof(header)); |
343 link_status_ = header->link_status != 0; | 348 link_status_ = header->link_status != 0; |
344 if (!link_status_) { | 349 if (!link_status_) { |
345 return; | 350 return; |
346 } | 351 } |
347 DCHECK_EQ(0u, attrib_infos_.size()); | 352 DCHECK_EQ(0u, attrib_infos_.size()); |
348 DCHECK_EQ(0u, uniform_infos_.size()); | 353 DCHECK_EQ(0u, uniform_infos_.size()); |
349 DCHECK_EQ(0, max_attrib_name_length_); | 354 DCHECK_EQ(0, max_attrib_name_length_); |
350 DCHECK_EQ(0, max_uniform_name_length_); | 355 DCHECK_EQ(0, max_uniform_name_length_); |
351 const ProgramInput* inputs = LocalGetAs<const ProgramInput*>( | 356 const ProgramInput* inputs = LocalGetAs<const ProgramInput*>( |
352 result, sizeof(*header), | 357 result, sizeof(*header), |
353 sizeof(ProgramInput) * (header->num_attribs + header->num_uniforms)); | 358 sizeof(ProgramInput) * (header->num_attribs + header->num_uniforms)); |
354 const ProgramInput* input = inputs; | 359 const ProgramInput* input = inputs; |
355 for (uint32 ii = 0; ii < header->num_attribs; ++ii) { | 360 for (uint32_t ii = 0; ii < header->num_attribs; ++ii) { |
356 const int32* location = LocalGetAs<const int32*>( | 361 const int32_t* location = LocalGetAs<const int32_t*>( |
357 result, input->location_offset, sizeof(int32)); | 362 result, input->location_offset, sizeof(int32_t)); |
358 const char* name_buf = LocalGetAs<const char*>( | 363 const char* name_buf = LocalGetAs<const char*>( |
359 result, input->name_offset, input->name_length); | 364 result, input->name_offset, input->name_length); |
360 std::string name(name_buf, input->name_length); | 365 std::string name(name_buf, input->name_length); |
361 attrib_infos_.push_back( | 366 attrib_infos_.push_back( |
362 VertexAttrib(input->size, input->type, name, *location)); | 367 VertexAttrib(input->size, input->type, name, *location)); |
363 max_attrib_name_length_ = std::max( | 368 max_attrib_name_length_ = std::max( |
364 static_cast<GLsizei>(name.size() + 1), max_attrib_name_length_); | 369 static_cast<GLsizei>(name.size() + 1), max_attrib_name_length_); |
365 ++input; | 370 ++input; |
366 } | 371 } |
367 for (uint32 ii = 0; ii < header->num_uniforms; ++ii) { | 372 for (uint32_t ii = 0; ii < header->num_uniforms; ++ii) { |
368 const int32* locations = LocalGetAs<const int32*>( | 373 const int32_t* locations = LocalGetAs<const int32_t*>( |
369 result, input->location_offset, sizeof(int32) * input->size); | 374 result, input->location_offset, sizeof(int32_t) * input->size); |
370 const char* name_buf = LocalGetAs<const char*>( | 375 const char* name_buf = LocalGetAs<const char*>( |
371 result, input->name_offset, input->name_length); | 376 result, input->name_offset, input->name_length); |
372 std::string name(name_buf, input->name_length); | 377 std::string name(name_buf, input->name_length); |
373 UniformInfo info(input->size, input->type, name); | 378 UniformInfo info(input->size, input->type, name); |
374 max_uniform_name_length_ = std::max( | 379 max_uniform_name_length_ = std::max( |
375 static_cast<GLsizei>(name.size() + 1), max_uniform_name_length_); | 380 static_cast<GLsizei>(name.size() + 1), max_uniform_name_length_); |
376 for (int32 jj = 0; jj < input->size; ++jj) { | 381 for (int32_t jj = 0; jj < input->size; ++jj) { |
377 info.element_locations.push_back(locations[jj]); | 382 info.element_locations.push_back(locations[jj]); |
378 } | 383 } |
379 uniform_infos_.push_back(info); | 384 uniform_infos_.push_back(info); |
380 ++input; | 385 ++input; |
381 } | 386 } |
382 DCHECK_EQ(header->num_attribs + header->num_uniforms, | 387 DCHECK_EQ(header->num_attribs + header->num_uniforms, |
383 static_cast<uint32>(input - inputs)); | 388 static_cast<uint32_t>(input - inputs)); |
384 cached_es2_ = true; | 389 cached_es2_ = true; |
385 } | 390 } |
386 | 391 |
387 void ProgramInfoManager::Program::UpdateES3UniformBlocks( | 392 void ProgramInfoManager::Program::UpdateES3UniformBlocks( |
388 const std::vector<int8>& result) { | 393 const std::vector<int8_t>& result) { |
389 if (cached_es3_uniform_blocks_) { | 394 if (cached_es3_uniform_blocks_) { |
390 return; | 395 return; |
391 } | 396 } |
392 if (result.empty()) { | 397 if (result.empty()) { |
393 // This should only happen on a lost context. | 398 // This should only happen on a lost context. |
394 return; | 399 return; |
395 } | 400 } |
396 DCHECK_EQ(0u, uniform_blocks_.size()); | 401 DCHECK_EQ(0u, uniform_blocks_.size()); |
397 DCHECK_EQ(0u, active_uniform_block_max_name_length_); | 402 DCHECK_EQ(0u, active_uniform_block_max_name_length_); |
398 | 403 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 static_cast<GLuint>(indices[uu]); | 454 static_cast<GLuint>(indices[uu]); |
450 } | 455 } |
451 indices += entries[ii].active_uniforms; | 456 indices += entries[ii].active_uniforms; |
452 data = reinterpret_cast<const char*>(indices); | 457 data = reinterpret_cast<const char*>(indices); |
453 } | 458 } |
454 DCHECK_EQ(data_size, size); | 459 DCHECK_EQ(data_size, size); |
455 cached_es3_uniform_blocks_ = true; | 460 cached_es3_uniform_blocks_ = true; |
456 } | 461 } |
457 | 462 |
458 void ProgramInfoManager::Program::UpdateES3Uniformsiv( | 463 void ProgramInfoManager::Program::UpdateES3Uniformsiv( |
459 const std::vector<int8>& result) { | 464 const std::vector<int8_t>& result) { |
460 if (cached_es3_uniformsiv_) { | 465 if (cached_es3_uniformsiv_) { |
461 return; | 466 return; |
462 } | 467 } |
463 if (result.empty()) { | 468 if (result.empty()) { |
464 // This should only happen on a lost context. | 469 // This should only happen on a lost context. |
465 return; | 470 return; |
466 } | 471 } |
467 DCHECK_EQ(0u, uniforms_es3_.size()); | 472 DCHECK_EQ(0u, uniforms_es3_.size()); |
468 | 473 |
469 // |result| comes from GPU process. We consider it trusted data. Therefore, | 474 // |result| comes from GPU process. We consider it trusted data. Therefore, |
(...skipping 21 matching lines...) Expand all Loading... |
491 uniforms_es3_[ii].block_index = entries[ii].block_index; | 496 uniforms_es3_[ii].block_index = entries[ii].block_index; |
492 uniforms_es3_[ii].offset = entries[ii].offset; | 497 uniforms_es3_[ii].offset = entries[ii].offset; |
493 uniforms_es3_[ii].array_stride = entries[ii].array_stride; | 498 uniforms_es3_[ii].array_stride = entries[ii].array_stride; |
494 uniforms_es3_[ii].matrix_stride = entries[ii].matrix_stride; | 499 uniforms_es3_[ii].matrix_stride = entries[ii].matrix_stride; |
495 uniforms_es3_[ii].is_row_major = entries[ii].is_row_major; | 500 uniforms_es3_[ii].is_row_major = entries[ii].is_row_major; |
496 } | 501 } |
497 cached_es3_uniformsiv_ = true; | 502 cached_es3_uniformsiv_ = true; |
498 } | 503 } |
499 | 504 |
500 void ProgramInfoManager::Program::UpdateES3TransformFeedbackVaryings( | 505 void ProgramInfoManager::Program::UpdateES3TransformFeedbackVaryings( |
501 const std::vector<int8>& result) { | 506 const std::vector<int8_t>& result) { |
502 if (cached_es3_transform_feedback_varyings_) { | 507 if (cached_es3_transform_feedback_varyings_) { |
503 return; | 508 return; |
504 } | 509 } |
505 if (result.empty()) { | 510 if (result.empty()) { |
506 // This should only happen on a lost context. | 511 // This should only happen on a lost context. |
507 return; | 512 return; |
508 } | 513 } |
509 DCHECK_EQ(0u, transform_feedback_buffer_mode_); | 514 DCHECK_EQ(0u, transform_feedback_buffer_mode_); |
510 DCHECK_EQ(0u, transform_feedback_varyings_.size()); | 515 DCHECK_EQ(0u, transform_feedback_varyings_.size()); |
511 DCHECK_EQ(0u, transform_feedback_varying_max_length_); | 516 DCHECK_EQ(0u, transform_feedback_varying_max_length_); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 GLES2Implementation* gl, GLuint program, ProgramInfoType type) { | 594 GLES2Implementation* gl, GLuint program, ProgramInfoType type) { |
590 lock_.AssertAcquired(); | 595 lock_.AssertAcquired(); |
591 ProgramInfoMap::iterator it = program_infos_.find(program); | 596 ProgramInfoMap::iterator it = program_infos_.find(program); |
592 if (it == program_infos_.end()) { | 597 if (it == program_infos_.end()) { |
593 return NULL; | 598 return NULL; |
594 } | 599 } |
595 Program* info = &it->second; | 600 Program* info = &it->second; |
596 if (info->IsCached(type)) | 601 if (info->IsCached(type)) |
597 return info; | 602 return info; |
598 | 603 |
599 std::vector<int8> result; | 604 std::vector<int8_t> result; |
600 switch (type) { | 605 switch (type) { |
601 case kES2: | 606 case kES2: |
602 { | 607 { |
603 base::AutoUnlock unlock(lock_); | 608 base::AutoUnlock unlock(lock_); |
604 // lock_ can't be held across IPC call or else it may deadlock in | 609 // lock_ can't be held across IPC call or else it may deadlock in |
605 // pepper. http://crbug.com/418651 | 610 // pepper. http://crbug.com/418651 |
606 gl->GetProgramInfoCHROMIUMHelper(program, &result); | 611 gl->GetProgramInfoCHROMIUMHelper(program, &result); |
607 } | 612 } |
608 info->UpdateES2(result); | 613 info->UpdateES2(result); |
609 break; | 614 break; |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 } | 1039 } |
1035 return true; | 1040 return true; |
1036 } | 1041 } |
1037 } | 1042 } |
1038 return gl->GetUniformIndicesHelper(program, count, names, indices); | 1043 return gl->GetUniformIndicesHelper(program, count, names, indices); |
1039 } | 1044 } |
1040 | 1045 |
1041 } // namespace gles2 | 1046 } // namespace gles2 |
1042 } // namespace gpu | 1047 } // namespace gpu |
1043 | 1048 |
OLD | NEW |