OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/gles2_cmd_decoder_passthrough.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder_passthrough.h" |
6 | 6 |
7 #include "gpu/command_buffer/service/feature_info.h" | 7 #include "gpu/command_buffer/service/feature_info.h" |
8 #include "gpu/command_buffer/service/gl_utils.h" | 8 #include "gpu/command_buffer/service/gl_utils.h" |
9 #include "ui/gl/gl_version_info.h" | 9 #include "ui/gl/gl_version_info.h" |
10 | 10 |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 | 532 |
533 const gpu::gles2::ContextState* GLES2DecoderPassthroughImpl::GetContextState() { | 533 const gpu::gles2::ContextState* GLES2DecoderPassthroughImpl::GetContextState() { |
534 return nullptr; | 534 return nullptr; |
535 } | 535 } |
536 | 536 |
537 scoped_refptr<ShaderTranslatorInterface> | 537 scoped_refptr<ShaderTranslatorInterface> |
538 GLES2DecoderPassthroughImpl::GetTranslator(GLenum type) { | 538 GLES2DecoderPassthroughImpl::GetTranslator(GLenum type) { |
539 return nullptr; | 539 return nullptr; |
540 } | 540 } |
541 | 541 |
| 542 template <typename T> |
| 543 error::Error GLES2DecoderPassthroughImpl::PatchGetNumericResults(GLenum pname, |
| 544 GLsizei length, |
| 545 T* params) { |
| 546 // Likely a gl error if no parameters were returned |
| 547 if (length < 1) { |
| 548 return error::kNoError; |
| 549 } |
| 550 |
| 551 auto get_binding_client_id = [this]( |
| 552 const ClientServiceMap<GLuint, GLuint>* map, T service_id, T* result) { |
| 553 GLuint client_id = 0; |
| 554 if (!map->GetClientID(static_cast<GLuint>(service_id), &client_id)) { |
| 555 return false; |
| 556 } |
| 557 *result = static_cast<T>(client_id); |
| 558 return true; |
| 559 }; |
| 560 |
| 561 switch (pname) { |
| 562 case GL_NUM_EXTENSIONS: |
| 563 *params = *params + static_cast<T>(emulated_extensions_.size()); |
| 564 break; |
| 565 |
| 566 case GL_TEXTURE_BINDING_2D: |
| 567 case GL_TEXTURE_BINDING_CUBE_MAP: |
| 568 case GL_TEXTURE_BINDING_2D_ARRAY: |
| 569 case GL_TEXTURE_BINDING_3D: |
| 570 if (!get_binding_client_id(&resources_->texture_id_map, *params, |
| 571 params)) { |
| 572 return error::kInvalidArguments; |
| 573 } |
| 574 break; |
| 575 |
| 576 case GL_ARRAY_BUFFER_BINDING: |
| 577 case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 578 case GL_PIXEL_PACK_BUFFER_BINDING: |
| 579 case GL_PIXEL_UNPACK_BUFFER_BINDING: |
| 580 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
| 581 case GL_COPY_READ_BUFFER_BINDING: |
| 582 case GL_COPY_WRITE_BUFFER_BINDING: |
| 583 case GL_UNIFORM_BUFFER_BINDING: |
| 584 if (!get_binding_client_id(&resources_->buffer_id_map, *params, params)) { |
| 585 return error::kInvalidArguments; |
| 586 } |
| 587 break; |
| 588 |
| 589 case GL_RENDERBUFFER_BINDING: |
| 590 if (!get_binding_client_id(&resources_->renderbuffer_id_map, *params, |
| 591 params)) { |
| 592 return error::kInvalidArguments; |
| 593 } |
| 594 break; |
| 595 |
| 596 case GL_SAMPLER_BINDING: |
| 597 if (!get_binding_client_id(&resources_->sampler_id_map, *params, |
| 598 params)) { |
| 599 return error::kInvalidArguments; |
| 600 } |
| 601 break; |
| 602 |
| 603 case GL_ACTIVE_PROGRAM: |
| 604 if (!get_binding_client_id(&resources_->program_id_map, *params, |
| 605 params)) { |
| 606 return error::kInvalidArguments; |
| 607 } |
| 608 break; |
| 609 |
| 610 case GL_FRAMEBUFFER_BINDING: |
| 611 case GL_READ_FRAMEBUFFER_BINDING: |
| 612 if (!get_binding_client_id(&framebuffer_id_map_, *params, params)) { |
| 613 return error::kInvalidArguments; |
| 614 } |
| 615 break; |
| 616 |
| 617 case GL_TRANSFORM_FEEDBACK_BINDING: |
| 618 if (!get_binding_client_id(&transform_feedback_id_map_, *params, |
| 619 params)) { |
| 620 return error::kInvalidArguments; |
| 621 } |
| 622 break; |
| 623 |
| 624 case GL_VERTEX_ARRAY_BINDING: |
| 625 if (!get_binding_client_id(&vertex_array_id_map_, *params, params)) { |
| 626 return error::kInvalidArguments; |
| 627 } |
| 628 break; |
| 629 |
| 630 default: |
| 631 break; |
| 632 } |
| 633 |
| 634 return error::kNoError; |
| 635 } |
| 636 |
| 637 // Instantiate templated functions |
| 638 template error::Error GLES2DecoderPassthroughImpl::PatchGetNumericResults( |
| 639 GLenum pname, |
| 640 GLsizei length, |
| 641 GLint* params); |
| 642 template error::Error GLES2DecoderPassthroughImpl::PatchGetNumericResults( |
| 643 GLenum pname, |
| 644 GLsizei length, |
| 645 GLint64* params); |
| 646 template error::Error GLES2DecoderPassthroughImpl::PatchGetNumericResults( |
| 647 GLenum pname, |
| 648 GLsizei length, |
| 649 GLfloat* params); |
| 650 template error::Error GLES2DecoderPassthroughImpl::PatchGetNumericResults( |
| 651 GLenum pname, |
| 652 GLsizei length, |
| 653 GLboolean* params); |
| 654 |
| 655 error::Error |
| 656 GLES2DecoderPassthroughImpl::PatchGetFramebufferAttachmentParameter( |
| 657 GLenum target, |
| 658 GLenum attachment, |
| 659 GLenum pname, |
| 660 GLsizei length, |
| 661 GLint* params) { |
| 662 // Likely a gl error if no parameters were returned |
| 663 if (length < 1) { |
| 664 return error::kNoError; |
| 665 } |
| 666 |
| 667 switch (pname) { |
| 668 // If the attached object name was requested, it needs to be converted back |
| 669 // to a client id. |
| 670 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: { |
| 671 GLint object_type = GL_NONE; |
| 672 glGetFramebufferAttachmentParameterivEXT( |
| 673 target, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, |
| 674 &object_type); |
| 675 |
| 676 switch (object_type) { |
| 677 case GL_TEXTURE: { |
| 678 GLuint client_id = 0; |
| 679 if (!resources_->texture_id_map.GetClientID(*params, &client_id)) { |
| 680 return error::kInvalidArguments; |
| 681 } |
| 682 *params = static_cast<GLint>(client_id); |
| 683 } break; |
| 684 |
| 685 case GL_RENDERBUFFER: { |
| 686 GLuint client_id = 0; |
| 687 if (!resources_->renderbuffer_id_map.GetClientID(*params, |
| 688 &client_id)) { |
| 689 return error::kInvalidArguments; |
| 690 } |
| 691 *params = static_cast<GLint>(client_id); |
| 692 } break; |
| 693 |
| 694 case GL_NONE: |
| 695 // Default framebuffer, don't transform the result |
| 696 break; |
| 697 |
| 698 default: |
| 699 NOTREACHED(); |
| 700 break; |
| 701 } |
| 702 } break; |
| 703 |
| 704 default: |
| 705 break; |
| 706 } |
| 707 |
| 708 return error::kNoError; |
| 709 } |
| 710 |
542 void GLES2DecoderPassthroughImpl::BuildExtensionsString() { | 711 void GLES2DecoderPassthroughImpl::BuildExtensionsString() { |
543 std::ostringstream combined_string_stream; | 712 std::ostringstream combined_string_stream; |
544 combined_string_stream << reinterpret_cast<const char*>( | 713 combined_string_stream << reinterpret_cast<const char*>( |
545 glGetString(GL_EXTENSIONS)) | 714 glGetString(GL_EXTENSIONS)) |
546 << " "; | 715 << " "; |
547 std::copy(emulated_extensions_.begin(), emulated_extensions_.end(), | 716 std::copy(emulated_extensions_.begin(), emulated_extensions_.end(), |
548 std::ostream_iterator<std::string>(combined_string_stream, " ")); | 717 std::ostream_iterator<std::string>(combined_string_stream, " ")); |
549 extension_string_ = combined_string_stream.str(); | 718 extension_string_ = combined_string_stream.str(); |
550 } | 719 } |
551 | 720 |
552 #define GLES2_CMD_OP(name) \ | 721 #define GLES2_CMD_OP(name) \ |
553 { \ | 722 { \ |
554 &GLES2DecoderPassthroughImpl::Handle##name, cmds::name::kArgFlags, \ | 723 &GLES2DecoderPassthroughImpl::Handle##name, cmds::name::kArgFlags, \ |
555 cmds::name::cmd_flags, \ | 724 cmds::name::cmd_flags, \ |
556 sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ | 725 sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ |
557 }, /* NOLINT */ | 726 }, /* NOLINT */ |
558 | 727 |
559 const GLES2DecoderPassthroughImpl::CommandInfo | 728 const GLES2DecoderPassthroughImpl::CommandInfo |
560 GLES2DecoderPassthroughImpl::command_info[] = { | 729 GLES2DecoderPassthroughImpl::command_info[] = { |
561 GLES2_COMMAND_LIST(GLES2_CMD_OP)}; | 730 GLES2_COMMAND_LIST(GLES2_CMD_OP)}; |
562 | 731 |
563 #undef GLES2_CMD_OP | 732 #undef GLES2_CMD_OP |
564 | 733 |
565 } // namespace gles2 | 734 } // namespace gles2 |
566 } // namespace gpu | 735 } // namespace gpu |
OLD | NEW |