Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc

Issue 2656563002: Support cube map dest target for CopyTextureCHROMIUM extension (Closed)
Patch Set: fix nits Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 GLuint source_id, 544 GLuint source_id,
545 GLint source_level, 545 GLint source_level,
546 GLenum dest_target, 546 GLenum dest_target,
547 GLuint dest_id, 547 GLuint dest_id,
548 GLint dest_level, 548 GLint dest_level,
549 GLenum dest_internal_format, 549 GLenum dest_internal_format,
550 GLsizei width, 550 GLsizei width,
551 GLsizei height, 551 GLsizei height,
552 GLuint framebuffer) { 552 GLuint framebuffer) {
553 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), source_target); 553 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), source_target);
554 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), dest_target); 554 GLenum dest_binding_target =
555 gpu::gles2::GLES2Util::GLFaceTargetToTextureTarget(dest_target);
556 DCHECK(dest_binding_target == GL_TEXTURE_2D ||
557 dest_binding_target == GL_TEXTURE_CUBE_MAP);
555 DCHECK(source_level == 0 || decoder->GetFeatureInfo()->IsES3Capable()); 558 DCHECK(source_level == 0 || decoder->GetFeatureInfo()->IsES3Capable());
556 if (BindFramebufferTexture2D(source_target, source_id, source_level, 559 if (BindFramebufferTexture2D(source_target, source_id, source_level,
557 framebuffer)) { 560 framebuffer)) {
558 glBindTexture(dest_target, dest_id); 561 glBindTexture(dest_binding_target, dest_id);
559 glTexParameterf(dest_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 562 glTexParameterf(dest_binding_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
560 glTexParameterf(dest_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 563 glTexParameterf(dest_binding_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
561 glTexParameteri(dest_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 564 glTexParameteri(dest_binding_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
562 glTexParameteri(dest_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 565 glTexParameteri(dest_binding_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
563 glCopyTexImage2D(dest_target, dest_level, dest_internal_format, 0 /* x */, 566 glCopyTexImage2D(dest_target, dest_level, dest_internal_format, 0 /* x */,
564 0 /* y */, width, height, 0 /* border */); 567 0 /* y */, width, height, 0 /* border */);
565 } 568 }
566 569
567 decoder->RestoreTextureState(source_id); 570 decoder->RestoreTextureState(source_id);
568 decoder->RestoreTextureState(dest_id); 571 decoder->RestoreTextureState(dest_id);
569 decoder->RestoreTextureUnitBindings(0); 572 decoder->RestoreTextureUnitBindings(0);
570 decoder->RestoreActiveTexture(); 573 decoder->RestoreActiveTexture();
571 decoder->RestoreFramebufferBindings(); 574 decoder->RestoreFramebufferBindings();
572 } 575 }
573 576
574 void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder, 577 void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder,
575 GLenum source_target, 578 GLenum source_target,
576 GLuint source_id, 579 GLuint source_id,
577 GLint source_level, 580 GLint source_level,
578 GLenum dest_target, 581 GLenum dest_target,
579 GLuint dest_id, 582 GLuint dest_id,
580 GLint dest_level, 583 GLint dest_level,
581 GLint xoffset, 584 GLint xoffset,
582 GLint yoffset, 585 GLint yoffset,
583 GLint source_x, 586 GLint source_x,
584 GLint source_y, 587 GLint source_y,
585 GLsizei source_width, 588 GLsizei source_width,
586 GLsizei source_height, 589 GLsizei source_height,
587 GLuint framebuffer) { 590 GLuint framebuffer) {
588 DCHECK(source_target == GL_TEXTURE_2D || 591 DCHECK(source_target == GL_TEXTURE_2D ||
589 source_target == GL_TEXTURE_RECTANGLE_ARB); 592 source_target == GL_TEXTURE_RECTANGLE_ARB);
590 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), dest_target); 593 GLenum dest_binding_target =
594 gpu::gles2::GLES2Util::GLFaceTargetToTextureTarget(dest_target);
595 DCHECK(dest_binding_target == GL_TEXTURE_2D ||
596 dest_binding_target == GL_TEXTURE_CUBE_MAP);
591 DCHECK(source_level == 0 || decoder->GetFeatureInfo()->IsES3Capable()); 597 DCHECK(source_level == 0 || decoder->GetFeatureInfo()->IsES3Capable());
592 if (BindFramebufferTexture2D(source_target, source_id, source_level, 598 if (BindFramebufferTexture2D(source_target, source_id, source_level,
593 framebuffer)) { 599 framebuffer)) {
594 glBindTexture(dest_target, dest_id); 600 glBindTexture(dest_binding_target, dest_id);
595 glTexParameterf(dest_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 601 glTexParameterf(dest_binding_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
596 glTexParameterf(dest_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 602 glTexParameterf(dest_binding_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
597 glTexParameteri(dest_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 603 glTexParameteri(dest_binding_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
598 glTexParameteri(dest_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 604 glTexParameteri(dest_binding_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
599 glCopyTexSubImage2D(dest_target, dest_level, xoffset, yoffset, source_x, 605 glCopyTexSubImage2D(dest_target, dest_level, xoffset, yoffset, source_x,
600 source_y, source_width, source_height); 606 source_y, source_width, source_height);
601 } 607 }
602 608
603 decoder->RestoreTextureState(source_id); 609 decoder->RestoreTextureState(source_id);
604 decoder->RestoreTextureState(dest_id); 610 decoder->RestoreTextureState(dest_id);
605 decoder->RestoreTextureUnitBindings(0); 611 decoder->RestoreTextureUnitBindings(0);
606 decoder->RestoreActiveTexture(); 612 decoder->RestoreActiveTexture();
607 decoder->RestoreFramebufferBindings(); 613 decoder->RestoreFramebufferBindings();
608 } 614 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 GLuint dest_id, 712 GLuint dest_id,
707 GLint dest_level, 713 GLint dest_level,
708 GLenum dest_internal_format, 714 GLenum dest_internal_format,
709 GLsizei width, 715 GLsizei width,
710 GLsizei height, 716 GLsizei height,
711 bool flip_y, 717 bool flip_y,
712 bool premultiply_alpha, 718 bool premultiply_alpha,
713 bool unpremultiply_alpha, 719 bool unpremultiply_alpha,
714 CopyTextureMethod method) { 720 CopyTextureMethod method) {
715 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; 721 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha;
722 GLenum dest_binding_target =
723 gpu::gles2::GLES2Util::GLFaceTargetToTextureTarget(dest_target);
716 724
717 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, 725 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2,
718 // so restrict this to GL_TEXTURE_2D. 726 // so restrict this to GL_TEXTURE_2D and GL_TEXTURE_CUBE_MAP.
719 if (source_target == GL_TEXTURE_2D && dest_target == GL_TEXTURE_2D && 727 if (source_target == GL_TEXTURE_2D &&
728 (dest_binding_target == GL_TEXTURE_2D ||
729 dest_binding_target == GL_TEXTURE_CUBE_MAP) &&
720 !flip_y && !premultiply_alpha_change && method == DIRECT_COPY) { 730 !flip_y && !premultiply_alpha_change && method == DIRECT_COPY) {
721 DoCopyTexImage2D(decoder, source_target, source_id, source_level, 731 DoCopyTexImage2D(decoder, source_target, source_id, source_level,
722 dest_target, dest_id, dest_level, dest_internal_format, 732 dest_target, dest_id, dest_level, dest_internal_format,
723 width, height, framebuffer_); 733 width, height, framebuffer_);
724 return; 734 return;
725 } 735 }
726 736
737 // Draw to level 0 of an intermediate GL_TEXTURE_2D texture.
727 GLuint dest_texture = dest_id; 738 GLuint dest_texture = dest_id;
728 GLuint intermediate_texture = 0; 739 GLuint intermediate_texture = 0;
729 GLint original_dest_level = dest_level; 740 GLint original_dest_level = dest_level;
741 GLenum original_dest_target = dest_target;
742 GLenum original_internal_format = dest_internal_format;
730 if (method == DRAW_AND_COPY) { 743 if (method == DRAW_AND_COPY) {
731 GLenum adjusted_internal_format = 744 GLenum adjusted_internal_format =
732 getIntermediateFormat(dest_internal_format); 745 getIntermediateFormat(dest_internal_format);
746 dest_target = GL_TEXTURE_2D;
733 glGenTextures(1, &intermediate_texture); 747 glGenTextures(1, &intermediate_texture);
734 glBindTexture(dest_target, intermediate_texture); 748 glBindTexture(dest_target, intermediate_texture);
735 GLenum format = TextureManager::ExtractFormatFromStorageFormat( 749 GLenum format = TextureManager::ExtractFormatFromStorageFormat(
736 adjusted_internal_format); 750 adjusted_internal_format);
737 GLenum type = 751 GLenum type =
738 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format); 752 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format);
739 753
740 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0, 754 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0,
741 format, type, nullptr); 755 format, type, nullptr);
742 dest_texture = intermediate_texture; 756 dest_texture = intermediate_texture;
743 dest_level = 0; 757 dest_level = 0;
744 dest_internal_format = adjusted_internal_format; 758 dest_internal_format = adjusted_internal_format;
745 } 759 }
746 // Use kIdentityMatrix if no transform passed in. 760 // Use kIdentityMatrix if no transform passed in.
747 DoCopyTextureWithTransform( 761 DoCopyTextureWithTransform(
748 decoder, source_target, source_id, source_level, source_internal_format, 762 decoder, source_target, source_id, source_level, source_internal_format,
749 dest_target, dest_texture, dest_level, dest_internal_format, width, 763 dest_target, dest_texture, dest_level, dest_internal_format, width,
750 height, flip_y, premultiply_alpha, unpremultiply_alpha, kIdentityMatrix); 764 height, flip_y, premultiply_alpha, unpremultiply_alpha, kIdentityMatrix);
751 765
752 if (method == DRAW_AND_COPY) { 766 if (method == DRAW_AND_COPY) {
753 source_level = 0; 767 source_level = 0;
754 dest_level = original_dest_level;
755 DoCopyTexImage2D(decoder, dest_target, intermediate_texture, source_level, 768 DoCopyTexImage2D(decoder, dest_target, intermediate_texture, source_level,
756 dest_target, dest_id, dest_level, dest_internal_format, 769 original_dest_target, dest_id, original_dest_level,
757 width, height, framebuffer_); 770 original_internal_format, width, height, framebuffer_);
758 glDeleteTextures(1, &intermediate_texture); 771 glDeleteTextures(1, &intermediate_texture);
759 } 772 }
760 } 773 }
761 774
762 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture( 775 void CopyTextureCHROMIUMResourceManager::DoCopySubTexture(
763 const gles2::GLES2Decoder* decoder, 776 const gles2::GLES2Decoder* decoder,
764 GLenum source_target, 777 GLenum source_target,
765 GLuint source_id, 778 GLuint source_id,
766 GLint source_level, 779 GLint source_level,
767 GLenum source_internal_format, 780 GLenum source_internal_format,
(...skipping 17 matching lines...) Expand all
785 CopyTextureMethod method) { 798 CopyTextureMethod method) {
786 bool use_gl_copy_tex_sub_image_2d = true; 799 bool use_gl_copy_tex_sub_image_2d = true;
787 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) 800 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
788 // glDrawArrays is faster than glCopyTexSubImage2D on IA Mesa driver, 801 // glDrawArrays is faster than glCopyTexSubImage2D on IA Mesa driver,
789 // although opposite in Android. 802 // although opposite in Android.
790 // TODO(dshwang): After Mesa fixes this issue, remove this hack. 803 // TODO(dshwang): After Mesa fixes this issue, remove this hack.
791 // https://bugs.freedesktop.org/show_bug.cgi?id=98478 crbug.com/535198 804 // https://bugs.freedesktop.org/show_bug.cgi?id=98478 crbug.com/535198
792 use_gl_copy_tex_sub_image_2d = false; 805 use_gl_copy_tex_sub_image_2d = false;
793 #endif 806 #endif
794 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; 807 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha;
808 GLenum dest_binding_target =
809 gpu::gles2::GLES2Util::GLFaceTargetToTextureTarget(dest_target);
795 810
796 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, 811 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2,
797 // so restrict this to GL_TEXTURE_2D. 812 // so restrict this to GL_TEXTURE_2D and GL_TEXTURE_CUBE_MAP.
798 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D && 813 if (use_gl_copy_tex_sub_image_2d && source_target == GL_TEXTURE_2D &&
799 dest_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && 814 (dest_binding_target == GL_TEXTURE_2D ||
800 method == DIRECT_COPY) { 815 dest_binding_target == GL_TEXTURE_CUBE_MAP) &&
816 !flip_y && !premultiply_alpha_change && method == DIRECT_COPY) {
801 DoCopyTexSubImage2D(decoder, source_target, source_id, source_level, 817 DoCopyTexSubImage2D(decoder, source_target, source_id, source_level,
802 dest_target, dest_id, dest_level, xoffset, yoffset, x, 818 dest_target, dest_id, dest_level, xoffset, yoffset, x,
803 y, width, height, framebuffer_); 819 y, width, height, framebuffer_);
804 return; 820 return;
805 } 821 }
806 822
823 // Draw to level 0 of an intermediate GL_TEXTURE_2D texture.
807 GLint dest_xoffset = xoffset; 824 GLint dest_xoffset = xoffset;
808 GLint dest_yoffset = yoffset; 825 GLint dest_yoffset = yoffset;
809 GLuint dest_texture = dest_id; 826 GLuint dest_texture = dest_id;
810 GLint original_dest_level = dest_level; 827 GLint original_dest_level = dest_level;
828 GLenum original_dest_target = dest_target;
811 GLuint intermediate_texture = 0; 829 GLuint intermediate_texture = 0;
812 if (method == DRAW_AND_COPY) { 830 if (method == DRAW_AND_COPY) {
813 GLenum adjusted_internal_format = 831 GLenum adjusted_internal_format =
814 getIntermediateFormat(dest_internal_format); 832 getIntermediateFormat(dest_internal_format);
833 dest_target = GL_TEXTURE_2D;
815 glGenTextures(1, &intermediate_texture); 834 glGenTextures(1, &intermediate_texture);
816 glBindTexture(dest_target, intermediate_texture); 835 glBindTexture(dest_target, intermediate_texture);
817 GLenum format = TextureManager::ExtractFormatFromStorageFormat( 836 GLenum format = TextureManager::ExtractFormatFromStorageFormat(
818 adjusted_internal_format); 837 adjusted_internal_format);
819 GLenum type = 838 GLenum type =
820 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format); 839 TextureManager::ExtractTypeFromStorageFormat(adjusted_internal_format);
821 840
822 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0, 841 glTexImage2D(dest_target, 0, adjusted_internal_format, width, height, 0,
823 format, type, nullptr); 842 format, type, nullptr);
824 dest_texture = intermediate_texture; 843 dest_texture = intermediate_texture;
825 dest_level = 0; 844 dest_level = 0;
826 dest_internal_format = adjusted_internal_format; 845 dest_internal_format = adjusted_internal_format;
827 dest_xoffset = 0; 846 dest_xoffset = 0;
828 dest_yoffset = 0; 847 dest_yoffset = 0;
829 dest_width = width; 848 dest_width = width;
830 dest_height = height; 849 dest_height = height;
831 } 850 }
832 851
833 DoCopySubTextureWithTransform( 852 DoCopySubTextureWithTransform(
834 decoder, source_target, source_id, source_level, source_internal_format, 853 decoder, source_target, source_id, source_level, source_internal_format,
835 dest_target, dest_texture, dest_level, dest_internal_format, dest_xoffset, 854 dest_target, dest_texture, dest_level, dest_internal_format, dest_xoffset,
836 dest_yoffset, x, y, width, height, dest_width, dest_height, source_width, 855 dest_yoffset, x, y, width, height, dest_width, dest_height, source_width,
837 source_height, flip_y, premultiply_alpha, unpremultiply_alpha, 856 source_height, flip_y, premultiply_alpha, unpremultiply_alpha,
838 kIdentityMatrix); 857 kIdentityMatrix);
839 858
840 if (method == DRAW_AND_COPY) { 859 if (method == DRAW_AND_COPY) {
841 source_level = 0; 860 source_level = 0;
842 dest_level = original_dest_level;
843 DoCopyTexSubImage2D(decoder, dest_target, intermediate_texture, 861 DoCopyTexSubImage2D(decoder, dest_target, intermediate_texture,
844 source_level, dest_target, dest_id, dest_level, xoffset, 862 source_level, original_dest_target, dest_id,
845 yoffset, 0, 0, width, height, framebuffer_); 863 original_dest_level, xoffset, yoffset, 0, 0, width,
864 height, framebuffer_);
846 glDeleteTextures(1, &intermediate_texture); 865 glDeleteTextures(1, &intermediate_texture);
847 } 866 }
848 } 867 }
849 868
850 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform( 869 void CopyTextureCHROMIUMResourceManager::DoCopySubTextureWithTransform(
851 const gles2::GLES2Decoder* decoder, 870 const gles2::GLES2Decoder* decoder,
852 GLenum source_target, 871 GLenum source_target,
853 GLuint source_id, 872 GLuint source_id,
854 GLint source_level, 873 GLint source_level,
855 GLenum source_internal_format, 874 GLenum source_internal_format,
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 decoder->RestoreTextureUnitBindings(0); 1155 decoder->RestoreTextureUnitBindings(0);
1137 decoder->RestoreActiveTexture(); 1156 decoder->RestoreActiveTexture();
1138 decoder->RestoreProgramBindings(); 1157 decoder->RestoreProgramBindings();
1139 decoder->RestoreBufferBindings(); 1158 decoder->RestoreBufferBindings();
1140 decoder->RestoreFramebufferBindings(); 1159 decoder->RestoreFramebufferBindings();
1141 decoder->RestoreGlobalState(); 1160 decoder->RestoreGlobalState();
1142 } 1161 }
1143 1162
1144 } // namespace gles2 1163 } // namespace gles2
1145 } // namespace gpu 1164 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698