| 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 "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 #endif | 505 #endif |
| 506 } | 506 } |
| 507 | 507 |
| 508 void DeleteShader(GLuint shader) { | 508 void DeleteShader(GLuint shader) { |
| 509 if (shader) | 509 if (shader) |
| 510 glDeleteShader(shader); | 510 glDeleteShader(shader); |
| 511 } | 511 } |
| 512 | 512 |
| 513 bool BindFramebufferTexture2D(GLenum target, | 513 bool BindFramebufferTexture2D(GLenum target, |
| 514 GLuint texture_id, | 514 GLuint texture_id, |
| 515 GLint level, |
| 515 GLuint framebuffer) { | 516 GLuint framebuffer) { |
| 516 DCHECK(target == GL_TEXTURE_2D || target == GL_TEXTURE_RECTANGLE_ARB); | 517 DCHECK(target == GL_TEXTURE_2D || target == GL_TEXTURE_RECTANGLE_ARB); |
| 517 glActiveTexture(GL_TEXTURE0); | 518 glActiveTexture(GL_TEXTURE0); |
| 518 glBindTexture(target, texture_id); | 519 glBindTexture(target, texture_id); |
| 519 // NVidia drivers require texture settings to be a certain way | 520 // NVidia drivers require texture settings to be a certain way |
| 520 // or they won't report FRAMEBUFFER_COMPLETE. | 521 // or they won't report FRAMEBUFFER_COMPLETE. |
| 522 if (level > 0) |
| 523 glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, level); |
| 521 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 524 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 522 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 525 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 523 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 526 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 524 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 527 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 525 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer); | 528 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer); |
| 526 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, | 529 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, |
| 527 texture_id, 0); | 530 texture_id, level); |
| 528 | 531 |
| 529 #ifndef NDEBUG | 532 #ifndef NDEBUG |
| 530 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | 533 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 531 if (GL_FRAMEBUFFER_COMPLETE != fb_status) { | 534 if (GL_FRAMEBUFFER_COMPLETE != fb_status) { |
| 532 DLOG(ERROR) << "CopyTextureCHROMIUM: Incomplete framebuffer."; | 535 DLOG(ERROR) << "CopyTextureCHROMIUM: Incomplete framebuffer."; |
| 533 return false; | 536 return false; |
| 534 } | 537 } |
| 535 #endif | 538 #endif |
| 536 return true; | 539 return true; |
| 537 } | 540 } |
| 538 | 541 |
| 539 void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder, | 542 void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder, |
| 540 GLenum source_target, | 543 GLenum source_target, |
| 541 GLuint source_id, | 544 GLuint source_id, |
| 545 GLint source_level, |
| 542 GLenum dest_target, | 546 GLenum dest_target, |
| 543 GLuint dest_id, | 547 GLuint dest_id, |
| 548 GLint dest_level, |
| 544 GLenum dest_internal_format, | 549 GLenum dest_internal_format, |
| 545 GLsizei width, | 550 GLsizei width, |
| 546 GLsizei height, | 551 GLsizei height, |
| 547 GLuint framebuffer) { | 552 GLuint framebuffer) { |
| 548 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), source_target); | 553 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), source_target); |
| 549 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), dest_target); | 554 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), dest_target); |
| 550 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { | 555 DCHECK(source_level == 0 || decoder->GetFeatureInfo()->IsES3Capable()); |
| 556 if (BindFramebufferTexture2D(source_target, source_id, source_level, |
| 557 framebuffer)) { |
| 551 glBindTexture(dest_target, dest_id); | 558 glBindTexture(dest_target, dest_id); |
| 552 glTexParameterf(dest_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 559 glTexParameterf(dest_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 553 glTexParameterf(dest_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 560 glTexParameterf(dest_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 554 glTexParameteri(dest_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 561 glTexParameteri(dest_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 555 glTexParameteri(dest_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 562 glTexParameteri(dest_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 556 glCopyTexImage2D(dest_target, 0 /* level */, dest_internal_format, | 563 glCopyTexImage2D(dest_target, dest_level, dest_internal_format, 0 /* x */, |
| 557 0 /* x */, 0 /* y */, width, height, 0 /* border */); | 564 0 /* y */, width, height, 0 /* border */); |
| 558 } | 565 } |
| 559 | 566 |
| 560 decoder->RestoreTextureState(source_id); | 567 decoder->RestoreTextureState(source_id); |
| 561 decoder->RestoreTextureState(dest_id); | 568 decoder->RestoreTextureState(dest_id); |
| 562 decoder->RestoreTextureUnitBindings(0); | 569 decoder->RestoreTextureUnitBindings(0); |
| 563 decoder->RestoreActiveTexture(); | 570 decoder->RestoreActiveTexture(); |
| 564 decoder->RestoreFramebufferBindings(); | 571 decoder->RestoreFramebufferBindings(); |
| 565 } | 572 } |
| 566 | 573 |
| 567 void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder, | 574 void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder, |
| 568 GLenum source_target, | 575 GLenum source_target, |
| 569 GLuint source_id, | 576 GLuint source_id, |
| 577 GLint source_level, |
| 570 GLenum dest_target, | 578 GLenum dest_target, |
| 571 GLuint dest_id, | 579 GLuint dest_id, |
| 580 GLint dest_level, |
| 572 GLint xoffset, | 581 GLint xoffset, |
| 573 GLint yoffset, | 582 GLint yoffset, |
| 574 GLint source_x, | 583 GLint source_x, |
| 575 GLint source_y, | 584 GLint source_y, |
| 576 GLsizei source_width, | 585 GLsizei source_width, |
| 577 GLsizei source_height, | 586 GLsizei source_height, |
| 578 GLuint framebuffer) { | 587 GLuint framebuffer) { |
| 579 DCHECK(source_target == GL_TEXTURE_2D || | 588 DCHECK(source_target == GL_TEXTURE_2D || |
| 580 source_target == GL_TEXTURE_RECTANGLE_ARB); | 589 source_target == GL_TEXTURE_RECTANGLE_ARB); |
| 581 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), dest_target); | 590 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), dest_target); |
| 582 if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) { | 591 DCHECK(source_level == 0 || decoder->GetFeatureInfo()->IsES3Capable()); |
| 592 if (BindFramebufferTexture2D(source_target, source_id, source_level, |
| 593 framebuffer)) { |
| 583 glBindTexture(dest_target, dest_id); | 594 glBindTexture(dest_target, dest_id); |
| 584 glTexParameterf(dest_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 595 glTexParameterf(dest_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 585 glTexParameterf(dest_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 596 glTexParameterf(dest_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 586 glTexParameteri(dest_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 597 glTexParameteri(dest_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 587 glTexParameteri(dest_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 598 glTexParameteri(dest_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 588 glCopyTexSubImage2D(dest_target, 0 /* level */, xoffset, yoffset, | 599 glCopyTexSubImage2D(dest_target, dest_level, xoffset, yoffset, source_x, |
| 589 source_x, source_y, source_width, source_height); | 600 source_y, source_width, source_height); |
| 590 } | 601 } |
| 591 | 602 |
| 592 decoder->RestoreTextureState(source_id); | 603 decoder->RestoreTextureState(source_id); |
| 593 decoder->RestoreTextureState(dest_id); | 604 decoder->RestoreTextureState(dest_id); |
| 594 decoder->RestoreTextureUnitBindings(0); | 605 decoder->RestoreTextureUnitBindings(0); |
| 595 decoder->RestoreActiveTexture(); | 606 decoder->RestoreActiveTexture(); |
| 596 decoder->RestoreFramebufferBindings(); | 607 decoder->RestoreFramebufferBindings(); |
| 597 } | 608 } |
| 598 | 609 |
| 599 } // namespace | 610 } // namespace |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 } | 693 } |
| 683 | 694 |
| 684 glDeleteBuffersARB(1, &buffer_id_); | 695 glDeleteBuffersARB(1, &buffer_id_); |
| 685 buffer_id_ = 0; | 696 buffer_id_ = 0; |
| 686 } | 697 } |
| 687 | 698 |
| 688 void CopyTextureCHROMIUMResourceManager::DoCopyTexture( | 699 void CopyTextureCHROMIUMResourceManager::DoCopyTexture( |
| 689 const gles2::GLES2Decoder* decoder, | 700 const gles2::GLES2Decoder* decoder, |
| 690 GLenum source_target, | 701 GLenum source_target, |
| 691 GLuint source_id, | 702 GLuint source_id, |
| 703 GLint source_level, |
| 692 GLenum source_internal_format, | 704 GLenum source_internal_format, |
| 693 GLenum dest_target, | 705 GLenum dest_target, |
| 694 GLuint dest_id, | 706 GLuint dest_id, |
| 707 GLint dest_level, |
| 695 GLenum dest_internal_format, | 708 GLenum dest_internal_format, |
| 696 GLsizei width, | 709 GLsizei width, |
| 697 GLsizei height, | 710 GLsizei height, |
| 698 bool flip_y, | 711 bool flip_y, |
| 699 bool premultiply_alpha, | 712 bool premultiply_alpha, |
| 700 bool unpremultiply_alpha, | 713 bool unpremultiply_alpha, |
| 701 CopyTextureMethod method) { | 714 CopyTextureMethod method) { |
| 702 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 715 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
| 703 | 716 |
| 704 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 717 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
| 705 // so restrict this to GL_TEXTURE_2D. | 718 // so restrict this to GL_TEXTURE_2D. |
| 706 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && | 719 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && |
| 707 !flip_y && !premultiply_alpha_change && method == DIRECT_COPY) { | 720 !flip_y && !premultiply_alpha_change && method == DIRECT_COPY) { |
| 708 DoCopyTexImage2D(decoder, | 721 DoCopyTexImage2D(decoder, source_target, source_id, source_level, |
| 709 source_target, | 722 dest_target, dest_id, dest_level, dest_internal_format, |
| 710 source_id, | 723 width, height, framebuffer_); |
| 711 dest_target, | |
| 712 dest_id, | |
| 713 dest_internal_format, | |
| 714 width, | |
| 715 height, | |
| 716 framebuffer_); | |
| 717 return; | 724 return; |
| 718 } | 725 } |
| 719 | 726 |
| 720 GLuint dest_texture = dest_id; | 727 GLuint dest_texture = dest_id; |
| 721 GLuint intermediate_texture = 0; | 728 GLuint intermediate_texture = 0; |
| 729 GLint original_dest_level = dest_level; |
| 722 if (method == DRAW_AND_COPY) { | 730 if (method == DRAW_AND_COPY) { |
| 723 GLenum adjusted_internal_format = | 731 GLenum adjusted_internal_format = |
| 724 getIntermediateFormat(dest_internal_format); | 732 getIntermediateFormat(dest_internal_format); |
| 725 glGenTextures(1, &intermediate_texture); | 733 glGenTextures(1, &intermediate_texture); |
| 726 glBindTexture(dest_target, intermediate_texture); | 734 glBindTexture(dest_target, intermediate_texture); |
| 727 GLenum format = TextureManager::ExtractFormatFromStorageFormat( | 735 GLenum format = TextureManager::ExtractFormatFromStorageFormat( |
| 728 adjusted_internal_format); | 736 adjusted_internal_format); |
| 729 GLenum type = | 737 GLenum type = |
| 730 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format); | 738 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format); |
| 731 | 739 |
| 732 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0, | 740 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0, |
| 733 format, type, nullptr); | 741 format, type, nullptr); |
| 734 dest_texture = intermediate_texture; | 742 dest_texture = intermediate_texture; |
| 743 dest_level = 0; |
| 735 dest_internal_format = adjusted_internal_format; | 744 dest_internal_format = adjusted_internal_format; |
| 736 } | 745 } |
| 737 // Use kIdentityMatrix if no transform passed in. | 746 // Use kIdentityMatrix if no transform passed in. |
| 738 DoCopyTextureWithTransform( | 747 DoCopyTextureWithTransform( |
| 739 decoder, source_target, source_id, source_internal_format, dest_target, | 748 decoder, source_target, source_id, source_level, source_internal_format, |
| 740 dest_texture, dest_internal_format, width, height, flip_y, | 749 dest_target, dest_texture, dest_level, dest_internal_format, width, |
| 741 premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); | 750 height, flip_y, premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); |
| 742 | 751 |
| 743 if (method == DRAW_AND_COPY) { | 752 if (method == DRAW_AND_COPY) { |
| 744 DoCopyTexImage2D(decoder, dest_target, intermediate_texture, dest_target, | 753 source_level = 0; |
| 745 dest_id, dest_internal_format, width, height, | 754 dest_level = original_dest_level; |
| 746 framebuffer_); | 755 DoCopyTexImage2D(decoder, dest_target, intermediate_texture, source_level, |
| 756 dest_target, dest_id, dest_level, dest_internal_format, |
| 757 width, height, framebuffer_); |
| 747 glDeleteTextures(1, &intermediate_texture); | 758 glDeleteTextures(1, &intermediate_texture); |
| 748 } | 759 } |
| 749 } | 760 } |
| 750 | 761 |
| 751 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( | 762 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( |
| 752 const gles2::GLES2Decoder* decoder, | 763 const gles2::GLES2Decoder* decoder, |
| 753 GLenum source_target, | 764 GLenum source_target, |
| 754 GLuint source_id, | 765 GLuint source_id, |
| 766 GLint source_level, |
| 755 GLenum source_internal_format, | 767 GLenum source_internal_format, |
| 756 GLenum dest_target, | 768 GLenum dest_target, |
| 757 GLuint dest_id, | 769 GLuint dest_id, |
| 770 GLint dest_level, |
| 758 GLenum dest_internal_format, | 771 GLenum dest_internal_format, |
| 759 GLint xoffset, | 772 GLint xoffset, |
| 760 GLint yoffset, | 773 GLint yoffset, |
| 761 GLint x, | 774 GLint x, |
| 762 GLint y, | 775 GLint y, |
| 763 GLsizei width, | 776 GLsizei width, |
| 764 GLsizei height, | 777 GLsizei height, |
| 765 GLsizei dest_width, | 778 GLsizei dest_width, |
| 766 GLsizei dest_height, | 779 GLsizei dest_height, |
| 767 GLsizei source_width, | 780 GLsizei source_width, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 778 // https://bugs.freedesktop.org/show_bug.cgi?id=98478 crbug.com/535198 | 791 // https://bugs.freedesktop.org/show_bug.cgi?id=98478 crbug.com/535198 |
| 779 use_gl_copy_tex_sub_image_2d = false; | 792 use_gl_copy_tex_sub_image_2d = false; |
| 780 #endif | 793 #endif |
| 781 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 794 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
| 782 | 795 |
| 783 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 796 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, |
| 784 // so restrict this to GL_TEXTURE_2D. | 797 // so restrict this to GL_TEXTURE_2D. |
| 785 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D && | 798 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D && |
| 786 dest_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && | 799 dest_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && |
| 787 method == DIRECT_COPY) { | 800 method == DIRECT_COPY) { |
| 788 DoCopyTexSubImage2D(decoder, source_target, source_id, dest_target, dest_id, | 801 DoCopyTexSubImage2D(decoder, source_target, source_id, source_level, |
| 789 xoffset, yoffset, x, y, width, height, framebuffer_); | 802 dest_target, dest_id, dest_level, xoffset, yoffset, x, |
| 803 y, width, height, framebuffer_); |
| 790 return; | 804 return; |
| 791 } | 805 } |
| 792 | 806 |
| 793 GLint dest_xoffset = xoffset; | 807 GLint dest_xoffset = xoffset; |
| 794 GLint dest_yoffset = yoffset; | 808 GLint dest_yoffset = yoffset; |
| 795 GLuint dest_texture = dest_id; | 809 GLuint dest_texture = dest_id; |
| 810 GLint original_dest_level = dest_level; |
| 796 GLuint intermediate_texture = 0; | 811 GLuint intermediate_texture = 0; |
| 797 if (method == DRAW_AND_COPY) { | 812 if (method == DRAW_AND_COPY) { |
| 798 GLenum adjusted_internal_format = | 813 GLenum adjusted_internal_format = |
| 799 getIntermediateFormat(dest_internal_format); | 814 getIntermediateFormat(dest_internal_format); |
| 800 glGenTextures(1, &intermediate_texture); | 815 glGenTextures(1, &intermediate_texture); |
| 801 glBindTexture(dest_target, intermediate_texture); | 816 glBindTexture(dest_target, intermediate_texture); |
| 802 GLenum format = TextureManager::ExtractFormatFromStorageFormat( | 817 GLenum format = TextureManager::ExtractFormatFromStorageFormat( |
| 803 adjusted_internal_format); | 818 adjusted_internal_format); |
| 804 GLenum type = | 819 GLenum type = |
| 805 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format); | 820 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format); |
| 806 | 821 |
| 807 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0, | 822 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0, |
| 808 format, type, nullptr); | 823 format, type, nullptr); |
| 809 dest_texture = intermediate_texture; | 824 dest_texture = intermediate_texture; |
| 825 dest_level = 0; |
| 810 dest_internal_format = adjusted_internal_format; | 826 dest_internal_format = adjusted_internal_format; |
| 811 dest_xoffset = 0; | 827 dest_xoffset = 0; |
| 812 dest_yoffset = 0; | 828 dest_yoffset = 0; |
| 813 dest_width = width; | 829 dest_width = width; |
| 814 dest_height = height; | 830 dest_height = height; |
| 815 } | 831 } |
| 816 | 832 |
| 817 DoCopySubTextureWithTransform( | 833 DoCopySubTextureWithTransform( |
| 818 decoder, source_target, source_id, source_internal_format, dest_target, | 834 decoder, source_target, source_id, source_level, source_internal_format, |
| 819 dest_texture, dest_internal_format, dest_xoffset, dest_yoffset, x, y, | 835 dest_target, dest_texture, dest_level, dest_internal_format, dest_xoffset, |
| 820 width, height, dest_width, dest_height, source_width, source_height, | 836 dest_yoffset, x, y, width, height, dest_width, dest_height, source_width, |
| 821 flip_y, premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); | 837 source_height, flip_y, premultiply_alpha, unpremultiply_alpha, |
| 838 kIdentityMatrix); |
| 822 | 839 |
| 823 if (method == DRAW_AND_COPY) { | 840 if (method == DRAW_AND_COPY) { |
| 824 DoCopyTexSubImage2D(decoder, dest_target, intermediate_texture, dest_target, | 841 source_level = 0; |
| 825 dest_id, xoffset, yoffset, 0, 0, width, height, | 842 dest_level = original_dest_level; |
| 826 framebuffer_); | 843 DoCopyTexSubImage2D(decoder, dest_target, intermediate_texture, |
| 844 source_level, dest_target, dest_id, dest_level, xoffset, |
| 845 yoffset, 0, 0, width, height, framebuffer_); |
| 827 glDeleteTextures(1, &intermediate_texture); | 846 glDeleteTextures(1, &intermediate_texture); |
| 828 } | 847 } |
| 829 } | 848 } |
| 830 | 849 |
| 831 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform( | 850 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform( |
| 832 const gles2::GLES2Decoder* decoder, | 851 const gles2::GLES2Decoder* decoder, |
| 833 GLenum source_target, | 852 GLenum source_target, |
| 834 GLuint source_id, | 853 GLuint source_id, |
| 854 GLint source_level, |
| 835 GLenum source_internal_format, | 855 GLenum source_internal_format, |
| 836 GLenum dest_target, | 856 GLenum dest_target, |
| 837 GLuint dest_id, | 857 GLuint dest_id, |
| 858 GLint dest_level, |
| 838 GLenum dest_internal_format, | 859 GLenum dest_internal_format, |
| 839 GLint xoffset, | 860 GLint xoffset, |
| 840 GLint yoffset, | 861 GLint yoffset, |
| 841 GLint x, | 862 GLint x, |
| 842 GLint y, | 863 GLint y, |
| 843 GLsizei width, | 864 GLsizei width, |
| 844 GLsizei height, | 865 GLsizei height, |
| 845 GLsizei dest_width, | 866 GLsizei dest_width, |
| 846 GLsizei dest_height, | 867 GLsizei dest_height, |
| 847 GLsizei source_width, | 868 GLsizei source_width, |
| 848 GLsizei source_height, | 869 GLsizei source_height, |
| 849 bool flip_y, | 870 bool flip_y, |
| 850 bool premultiply_alpha, | 871 bool premultiply_alpha, |
| 851 bool unpremultiply_alpha, | 872 bool unpremultiply_alpha, |
| 852 const GLfloat transform_matrix[16]) { | 873 const GLfloat transform_matrix[16]) { |
| 853 DoCopyTextureInternal( | 874 DoCopyTextureInternal( |
| 854 decoder, source_target, source_id, source_internal_format, dest_target, | 875 decoder, source_target, source_id, source_level, source_internal_format, |
| 855 dest_id, dest_internal_format, xoffset, yoffset, x, y, width, height, | 876 dest_target, dest_id, dest_level, dest_internal_format, xoffset, yoffset, |
| 856 dest_width, dest_height, source_width, source_height, flip_y, | 877 x, y, width, height, dest_width, dest_height, source_width, source_height, |
| 857 premultiply_alpha, unpremultiply_alpha, transform_matrix); | 878 flip_y, premultiply_alpha, unpremultiply_alpha, transform_matrix); |
| 858 } | 879 } |
| 859 | 880 |
| 860 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( | 881 void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform( |
| 861 const gles2::GLES2Decoder* decoder, | 882 const gles2::GLES2Decoder* decoder, |
| 862 GLenum source_target, | 883 GLenum source_target, |
| 863 GLuint source_id, | 884 GLuint source_id, |
| 885 GLint source_level, |
| 864 GLenum source_format, | 886 GLenum source_format, |
| 865 GLenum dest_target, | 887 GLenum dest_target, |
| 866 GLuint dest_id, | 888 GLuint dest_id, |
| 889 GLint dest_level, |
| 867 GLenum dest_format, | 890 GLenum dest_format, |
| 868 GLsizei width, | 891 GLsizei width, |
| 869 GLsizei height, | 892 GLsizei height, |
| 870 bool flip_y, | 893 bool flip_y, |
| 871 bool premultiply_alpha, | 894 bool premultiply_alpha, |
| 872 bool unpremultiply_alpha, | 895 bool unpremultiply_alpha, |
| 873 const GLfloat transform_matrix[16]) { | 896 const GLfloat transform_matrix[16]) { |
| 874 GLsizei dest_width = width; | 897 GLsizei dest_width = width; |
| 875 GLsizei dest_height = height; | 898 GLsizei dest_height = height; |
| 876 DoCopyTextureInternal( | 899 DoCopyTextureInternal(decoder, source_target, source_id, source_level, |
| 877 decoder, source_target, source_id, source_format, dest_target, dest_id, | 900 source_format, dest_target, dest_id, dest_level, |
| 878 dest_format, 0, 0, 0, 0, width, height, dest_width, dest_height, width, | 901 dest_format, 0, 0, 0, 0, width, height, dest_width, |
| 879 height, flip_y, premultiply_alpha, unpremultiply_alpha, transform_matrix); | 902 dest_height, width, height, flip_y, premultiply_alpha, |
| 903 unpremultiply_alpha, transform_matrix); |
| 880 } | 904 } |
| 881 | 905 |
| 882 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( | 906 void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( |
| 883 const gles2::GLES2Decoder* decoder, | 907 const gles2::GLES2Decoder* decoder, |
| 884 GLenum source_target, | 908 GLenum source_target, |
| 885 GLuint source_id, | 909 GLuint source_id, |
| 910 GLint source_level, |
| 886 GLenum source_format, | 911 GLenum source_format, |
| 887 GLenum dest_target, | 912 GLenum dest_target, |
| 888 GLuint dest_id, | 913 GLuint dest_id, |
| 914 GLint dest_level, |
| 889 GLenum dest_format, | 915 GLenum dest_format, |
| 890 GLint xoffset, | 916 GLint xoffset, |
| 891 GLint yoffset, | 917 GLint yoffset, |
| 892 GLint x, | 918 GLint x, |
| 893 GLint y, | 919 GLint y, |
| 894 GLsizei width, | 920 GLsizei width, |
| 895 GLsizei height, | 921 GLsizei height, |
| 896 GLsizei dest_width, | 922 GLsizei dest_width, |
| 897 GLsizei dest_height, | 923 GLsizei dest_height, |
| 898 GLsizei source_width, | 924 GLsizei source_width, |
| 899 GLsizei source_height, | 925 GLsizei source_height, |
| 900 bool flip_y, | 926 bool flip_y, |
| 901 bool premultiply_alpha, | 927 bool premultiply_alpha, |
| 902 bool unpremultiply_alpha, | 928 bool unpremultiply_alpha, |
| 903 const GLfloat transform_matrix[16]) { | 929 const GLfloat transform_matrix[16]) { |
| 904 DCHECK(source_target == GL_TEXTURE_2D || | 930 DCHECK(source_target == GL_TEXTURE_2D || |
| 905 source_target == GL_TEXTURE_RECTANGLE_ARB || | 931 source_target == GL_TEXTURE_RECTANGLE_ARB || |
| 906 source_target == GL_TEXTURE_EXTERNAL_OES); | 932 source_target == GL_TEXTURE_EXTERNAL_OES); |
| 907 DCHECK(dest_target == GL_TEXTURE_2D || | 933 DCHECK(dest_target == GL_TEXTURE_2D || |
| 908 dest_target == GL_TEXTURE_RECTANGLE_ARB); | 934 dest_target == GL_TEXTURE_RECTANGLE_ARB); |
| 935 DCHECK_GE(source_level, 0); |
| 936 DCHECK_GE(dest_level, 0); |
| 909 DCHECK_GE(xoffset, 0); | 937 DCHECK_GE(xoffset, 0); |
| 910 DCHECK_LE(xoffset + width, dest_width); | 938 DCHECK_LE(xoffset + width, dest_width); |
| 911 DCHECK_GE(yoffset, 0); | 939 DCHECK_GE(yoffset, 0); |
| 912 DCHECK_LE(yoffset + height, dest_height); | 940 DCHECK_LE(yoffset + height, dest_height); |
| 913 if (dest_width == 0 || dest_height == 0 || source_width == 0 || | 941 if (dest_width == 0 || dest_height == 0 || source_width == 0 || |
| 914 source_height == 0) { | 942 source_height == 0) { |
| 915 return; | 943 return; |
| 916 } | 944 } |
| 917 | 945 |
| 918 if (!initialized_) { | 946 if (!initialized_) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 // So everything is the same but the sign of A is flipped. | 1078 // So everything is the same but the sign of A is flipped. |
| 1051 GLfloat m_x = source_target == GL_TEXTURE_RECTANGLE_ARB ? source_width : 1; | 1079 GLfloat m_x = source_target == GL_TEXTURE_RECTANGLE_ARB ? source_width : 1; |
| 1052 GLfloat m_y = source_target == GL_TEXTURE_RECTANGLE_ARB ? source_height : 1; | 1080 GLfloat m_y = source_target == GL_TEXTURE_RECTANGLE_ARB ? source_height : 1; |
| 1053 GLfloat sign_a = flip_y ? -1 : 1; | 1081 GLfloat sign_a = flip_y ? -1 : 1; |
| 1054 glUniform2f(info->vertex_source_mult_handle, width / 2.f * m_x / source_width, | 1082 glUniform2f(info->vertex_source_mult_handle, width / 2.f * m_x / source_width, |
| 1055 height / 2.f * m_y / source_height * sign_a); | 1083 height / 2.f * m_y / source_height * sign_a); |
| 1056 glUniform2f(info->vertex_source_add_handle, | 1084 glUniform2f(info->vertex_source_add_handle, |
| 1057 (x + width / 2.f) * m_x / source_width, | 1085 (x + width / 2.f) * m_x / source_width, |
| 1058 (y + height / 2.f) * m_y / source_height); | 1086 (y + height / 2.f) * m_y / source_height); |
| 1059 | 1087 |
| 1060 if (BindFramebufferTexture2D(dest_target, dest_id, framebuffer_)) { | 1088 DCHECK(dest_level == 0 || decoder->GetFeatureInfo()->IsES3Capable()); |
| 1089 if (BindFramebufferTexture2D(dest_target, dest_id, dest_level, |
| 1090 framebuffer_)) { |
| 1061 #ifndef NDEBUG | 1091 #ifndef NDEBUG |
| 1062 // glValidateProgram of MACOSX validates FBO unlike other platforms, so | 1092 // glValidateProgram of MACOSX validates FBO unlike other platforms, so |
| 1063 // glValidateProgram must be called after FBO binding. crbug.com/463439 | 1093 // glValidateProgram must be called after FBO binding. crbug.com/463439 |
| 1064 glValidateProgram(info->program); | 1094 glValidateProgram(info->program); |
| 1065 GLint validation_status; | 1095 GLint validation_status; |
| 1066 glGetProgramiv(info->program, GL_VALIDATE_STATUS, &validation_status); | 1096 glGetProgramiv(info->program, GL_VALIDATE_STATUS, &validation_status); |
| 1067 if (GL_TRUE != validation_status) { | 1097 if (GL_TRUE != validation_status) { |
| 1068 DLOG(ERROR) << "CopyTextureCHROMIUM: Invalid shader."; | 1098 DLOG(ERROR) << "CopyTextureCHROMIUM: Invalid shader."; |
| 1069 return; | 1099 return; |
| 1070 } | 1100 } |
| 1071 #endif | 1101 #endif |
| 1072 | 1102 |
| 1073 glUniform1i(info->sampler_handle, 0); | 1103 glUniform1i(info->sampler_handle, 0); |
| 1074 | 1104 |
| 1075 glBindTexture(source_target, source_id); | 1105 glBindTexture(source_target, source_id); |
| 1106 DCHECK(source_level == 0 || decoder->GetFeatureInfo()->IsES3Capable()); |
| 1107 if (source_level > 0) |
| 1108 glTexParameteri(source_target, GL_TEXTURE_BASE_LEVEL, source_level); |
| 1076 glTexParameterf(source_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 1109 glTexParameterf(source_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1077 glTexParameterf(source_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 1110 glTexParameterf(source_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1078 glTexParameteri(source_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 1111 glTexParameteri(source_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1079 glTexParameteri(source_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 1112 glTexParameteri(source_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1080 | 1113 |
| 1081 glDisable(GL_DEPTH_TEST); | 1114 glDisable(GL_DEPTH_TEST); |
| 1082 glDisable(GL_STENCIL_TEST); | 1115 glDisable(GL_STENCIL_TEST); |
| 1083 glDisable(GL_CULL_FACE); | 1116 glDisable(GL_CULL_FACE); |
| 1084 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 1117 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 1085 glDepthMask(GL_FALSE); | 1118 glDepthMask(GL_FALSE); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1103 decoder->RestoreTextureUnitBindings(0); | 1136 decoder->RestoreTextureUnitBindings(0); |
| 1104 decoder->RestoreActiveTexture(); | 1137 decoder->RestoreActiveTexture(); |
| 1105 decoder->RestoreProgramBindings(); | 1138 decoder->RestoreProgramBindings(); |
| 1106 decoder->RestoreBufferBindings(); | 1139 decoder->RestoreBufferBindings(); |
| 1107 decoder->RestoreFramebufferBindings(); | 1140 decoder->RestoreFramebufferBindings(); |
| 1108 decoder->RestoreGlobalState(); | 1141 decoder->RestoreGlobalState(); |
| 1109 } | 1142 } |
| 1110 | 1143 |
| 1111 } // namespace gles2 | 1144 } // namespace gles2 |
| 1112 } // namespace gpu | 1145 } // namespace gpu |
| OLD | NEW |