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