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 |
11 namespace gpu { | 11 namespace gpu { |
12 namespace gles2 { | 12 namespace gles2 { |
13 | 13 |
14 namespace { | 14 namespace { |
15 template <typename ClientType, typename ServiceType, typename DeleteFunction> | 15 template <typename ClientType, typename ServiceType, typename DeleteFunction> |
16 void DeleteServiceObjects(ClientServiceMap<ClientType, ServiceType>* id_map, | 16 void DeleteServiceObjects(ClientServiceMap<ClientType, ServiceType>* id_map, |
17 bool have_context, | 17 bool have_context, |
18 DeleteFunction delete_function) { | 18 DeleteFunction delete_function) { |
19 if (have_context) { | 19 if (have_context) { |
20 for (auto client_service_id_pair : *id_map) { | 20 for (auto client_service_id_pair : *id_map) { |
21 delete_function(client_service_id_pair.second); | 21 delete_function(client_service_id_pair.second); |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 id_map->Clear(); | 25 id_map->Clear(); |
26 } | 26 } |
27 | 27 |
| 28 template <typename ClientType, typename ServiceType, typename ResultType> |
| 29 bool GetClientID(const ClientServiceMap<ClientType, ServiceType>* map, |
| 30 ResultType service_id, |
| 31 ResultType* result) { |
| 32 ClientType client_id = 0; |
| 33 if (!map->GetClientID(static_cast<ServiceType>(service_id), &client_id)) { |
| 34 return false; |
| 35 } |
| 36 *result = static_cast<ResultType>(client_id); |
| 37 return true; |
| 38 }; |
| 39 |
28 } // anonymous namespace | 40 } // anonymous namespace |
29 | 41 |
30 PassthroughResources::PassthroughResources() {} | 42 PassthroughResources::PassthroughResources() {} |
31 | 43 |
32 PassthroughResources::~PassthroughResources() {} | 44 PassthroughResources::~PassthroughResources() {} |
33 | 45 |
34 void PassthroughResources::Destroy(bool have_context) { | 46 void PassthroughResources::Destroy(bool have_context) { |
35 DeleteServiceObjects(&texture_id_map, have_context, | 47 DeleteServiceObjects(&texture_id_map, have_context, |
36 [](GLuint texture) { glDeleteTextures(1, &texture); }); | 48 [](GLuint texture) { glDeleteTextures(1, &texture); }); |
37 DeleteServiceObjects(&buffer_id_map, have_context, | 49 DeleteServiceObjects(&buffer_id_map, have_context, |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 | 544 |
533 const gpu::gles2::ContextState* GLES2DecoderPassthroughImpl::GetContextState() { | 545 const gpu::gles2::ContextState* GLES2DecoderPassthroughImpl::GetContextState() { |
534 return nullptr; | 546 return nullptr; |
535 } | 547 } |
536 | 548 |
537 scoped_refptr<ShaderTranslatorInterface> | 549 scoped_refptr<ShaderTranslatorInterface> |
538 GLES2DecoderPassthroughImpl::GetTranslator(GLenum type) { | 550 GLES2DecoderPassthroughImpl::GetTranslator(GLenum type) { |
539 return nullptr; | 551 return nullptr; |
540 } | 552 } |
541 | 553 |
| 554 void* GLES2DecoderPassthroughImpl::GetScratchMemory(size_t size) { |
| 555 if (scratch_memory_.size() < size) { |
| 556 scratch_memory_.resize(size, 0); |
| 557 } |
| 558 return scratch_memory_.data(); |
| 559 } |
| 560 |
| 561 template <typename T> |
| 562 error::Error GLES2DecoderPassthroughImpl::PatchGetNumericResults(GLenum pname, |
| 563 GLsizei length, |
| 564 T* params) { |
| 565 // Likely a gl error if no parameters were returned |
| 566 if (length < 1) { |
| 567 return error::kNoError; |
| 568 } |
| 569 |
| 570 switch (pname) { |
| 571 case GL_NUM_EXTENSIONS: |
| 572 *params = *params + static_cast<T>(emulated_extensions_.size()); |
| 573 break; |
| 574 |
| 575 case GL_TEXTURE_BINDING_2D: |
| 576 case GL_TEXTURE_BINDING_CUBE_MAP: |
| 577 case GL_TEXTURE_BINDING_2D_ARRAY: |
| 578 case GL_TEXTURE_BINDING_3D: |
| 579 if (!GetClientID(&resources_->texture_id_map, *params, params)) { |
| 580 return error::kInvalidArguments; |
| 581 } |
| 582 break; |
| 583 |
| 584 case GL_ARRAY_BUFFER_BINDING: |
| 585 case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 586 case GL_PIXEL_PACK_BUFFER_BINDING: |
| 587 case GL_PIXEL_UNPACK_BUFFER_BINDING: |
| 588 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
| 589 case GL_COPY_READ_BUFFER_BINDING: |
| 590 case GL_COPY_WRITE_BUFFER_BINDING: |
| 591 case GL_UNIFORM_BUFFER_BINDING: |
| 592 if (!GetClientID(&resources_->buffer_id_map, *params, params)) { |
| 593 return error::kInvalidArguments; |
| 594 } |
| 595 break; |
| 596 |
| 597 case GL_RENDERBUFFER_BINDING: |
| 598 if (!GetClientID(&resources_->renderbuffer_id_map, *params, params)) { |
| 599 return error::kInvalidArguments; |
| 600 } |
| 601 break; |
| 602 |
| 603 case GL_SAMPLER_BINDING: |
| 604 if (!GetClientID(&resources_->sampler_id_map, *params, params)) { |
| 605 return error::kInvalidArguments; |
| 606 } |
| 607 break; |
| 608 |
| 609 case GL_ACTIVE_PROGRAM: |
| 610 if (!GetClientID(&resources_->program_id_map, *params, params)) { |
| 611 return error::kInvalidArguments; |
| 612 } |
| 613 break; |
| 614 |
| 615 case GL_FRAMEBUFFER_BINDING: |
| 616 case GL_READ_FRAMEBUFFER_BINDING: |
| 617 if (!GetClientID(&framebuffer_id_map_, *params, params)) { |
| 618 return error::kInvalidArguments; |
| 619 } |
| 620 break; |
| 621 |
| 622 case GL_TRANSFORM_FEEDBACK_BINDING: |
| 623 if (!GetClientID(&transform_feedback_id_map_, *params, params)) { |
| 624 return error::kInvalidArguments; |
| 625 } |
| 626 break; |
| 627 |
| 628 case GL_VERTEX_ARRAY_BINDING: |
| 629 if (!GetClientID(&vertex_array_id_map_, *params, params)) { |
| 630 return error::kInvalidArguments; |
| 631 } |
| 632 break; |
| 633 |
| 634 default: |
| 635 break; |
| 636 } |
| 637 |
| 638 return error::kNoError; |
| 639 } |
| 640 |
| 641 // Instantiate templated functions |
| 642 #define INSTANTIATE_PATCH_NUMERIC_RESULTS(type) \ |
| 643 template error::Error GLES2DecoderPassthroughImpl::PatchGetNumericResults( \ |
| 644 GLenum, GLsizei, type*) |
| 645 INSTANTIATE_PATCH_NUMERIC_RESULTS(GLint); |
| 646 INSTANTIATE_PATCH_NUMERIC_RESULTS(GLint64); |
| 647 INSTANTIATE_PATCH_NUMERIC_RESULTS(GLfloat); |
| 648 INSTANTIATE_PATCH_NUMERIC_RESULTS(GLboolean); |
| 649 #undef INSTANTIATE_PATCH_NUMERIC_RESULTS |
| 650 |
| 651 error::Error |
| 652 GLES2DecoderPassthroughImpl::PatchGetFramebufferAttachmentParameter( |
| 653 GLenum target, |
| 654 GLenum attachment, |
| 655 GLenum pname, |
| 656 GLsizei length, |
| 657 GLint* params) { |
| 658 // Likely a gl error if no parameters were returned |
| 659 if (length < 1) { |
| 660 return error::kNoError; |
| 661 } |
| 662 |
| 663 switch (pname) { |
| 664 // If the attached object name was requested, it needs to be converted back |
| 665 // to a client id. |
| 666 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: { |
| 667 GLint object_type = GL_NONE; |
| 668 glGetFramebufferAttachmentParameterivEXT( |
| 669 target, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, |
| 670 &object_type); |
| 671 |
| 672 switch (object_type) { |
| 673 case GL_TEXTURE: |
| 674 if (!GetClientID(&resources_->texture_id_map, *params, params)) { |
| 675 return error::kInvalidArguments; |
| 676 } |
| 677 break; |
| 678 |
| 679 case GL_RENDERBUFFER: |
| 680 if (!GetClientID(&resources_->renderbuffer_id_map, *params, params)) { |
| 681 return error::kInvalidArguments; |
| 682 } |
| 683 break; |
| 684 |
| 685 case GL_NONE: |
| 686 // Default framebuffer, don't transform the result |
| 687 break; |
| 688 |
| 689 default: |
| 690 NOTREACHED(); |
| 691 break; |
| 692 } |
| 693 } break; |
| 694 |
| 695 default: |
| 696 break; |
| 697 } |
| 698 |
| 699 return error::kNoError; |
| 700 } |
| 701 |
542 void GLES2DecoderPassthroughImpl::BuildExtensionsString() { | 702 void GLES2DecoderPassthroughImpl::BuildExtensionsString() { |
543 std::ostringstream combined_string_stream; | 703 std::ostringstream combined_string_stream; |
544 combined_string_stream << reinterpret_cast<const char*>( | 704 combined_string_stream << reinterpret_cast<const char*>( |
545 glGetString(GL_EXTENSIONS)) | 705 glGetString(GL_EXTENSIONS)) |
546 << " "; | 706 << " "; |
547 std::copy(emulated_extensions_.begin(), emulated_extensions_.end(), | 707 std::copy(emulated_extensions_.begin(), emulated_extensions_.end(), |
548 std::ostream_iterator<std::string>(combined_string_stream, " ")); | 708 std::ostream_iterator<std::string>(combined_string_stream, " ")); |
549 extension_string_ = combined_string_stream.str(); | 709 extension_string_ = combined_string_stream.str(); |
550 } | 710 } |
551 | 711 |
552 #define GLES2_CMD_OP(name) \ | 712 #define GLES2_CMD_OP(name) \ |
553 { \ | 713 { \ |
554 &GLES2DecoderPassthroughImpl::Handle##name, cmds::name::kArgFlags, \ | 714 &GLES2DecoderPassthroughImpl::Handle##name, cmds::name::kArgFlags, \ |
555 cmds::name::cmd_flags, \ | 715 cmds::name::cmd_flags, \ |
556 sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ | 716 sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ |
557 }, /* NOLINT */ | 717 }, /* NOLINT */ |
558 | 718 |
559 const GLES2DecoderPassthroughImpl::CommandInfo | 719 const GLES2DecoderPassthroughImpl::CommandInfo |
560 GLES2DecoderPassthroughImpl::command_info[] = { | 720 GLES2DecoderPassthroughImpl::command_info[] = { |
561 GLES2_COMMAND_LIST(GLES2_CMD_OP)}; | 721 GLES2_COMMAND_LIST(GLES2_CMD_OP)}; |
562 | 722 |
563 #undef GLES2_CMD_OP | 723 #undef GLES2_CMD_OP |
564 | 724 |
565 } // namespace gles2 | 725 } // namespace gles2 |
566 } // namespace gpu | 726 } // namespace gpu |
OLD | NEW |