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_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 | 74 |
75 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
76 #include "base/win/win_util.h" | 76 #include "base/win/win_util.h" |
77 #endif | 77 #endif |
78 | 78 |
79 namespace gpu { | 79 namespace gpu { |
80 namespace gles2 { | 80 namespace gles2 { |
81 | 81 |
82 namespace { | 82 namespace { |
83 | 83 |
84 static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; | 84 const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
85 static const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; | 85 const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; |
86 static const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; | 86 const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; |
87 static const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod"; | 87 const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod"; |
88 | |
89 const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, | |
90 0.0f, 1.0f, 0.0f, 0.0f, | |
91 0.0f, 0.0f, 1.0f, 0.0f, | |
92 0.0f, 0.0f, 0.0f, 1.0f}; | |
88 | 93 |
89 static bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, | 94 static bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, |
90 GLint rangeMax, | 95 GLint rangeMax, |
91 GLint precision) { | 96 GLint precision) { |
92 return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16); | 97 return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16); |
93 } | 98 } |
94 | 99 |
95 static void GetShaderPrecisionFormatImpl(GLenum shader_type, | 100 static void GetShaderPrecisionFormatImpl(GLenum shader_type, |
96 GLenum precision_type, | 101 GLenum precision_type, |
97 GLint *range, GLint *precision) { | 102 GLint *range, GLint *precision) { |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
929 const void * data); | 934 const void * data); |
930 | 935 |
931 // Wrapper for TexImageIOSurface2DCHROMIUM. | 936 // Wrapper for TexImageIOSurface2DCHROMIUM. |
932 void DoTexImageIOSurface2DCHROMIUM( | 937 void DoTexImageIOSurface2DCHROMIUM( |
933 GLenum target, | 938 GLenum target, |
934 GLsizei width, | 939 GLsizei width, |
935 GLsizei height, | 940 GLsizei height, |
936 GLuint io_surface_id, | 941 GLuint io_surface_id, |
937 GLuint plane); | 942 GLuint plane); |
938 | 943 |
939 void DoCopyTextureCHROMIUM( | 944 void DoCopyTextureCHROMIUM(GLenum target, |
940 GLenum target, | 945 GLuint source_id, |
941 GLuint source_id, | 946 GLuint dest_id, |
942 GLuint target_id, | 947 GLint level, |
943 GLint level, | 948 GLenum internal_format, |
944 GLenum internal_format, | 949 GLenum dest_type); |
945 GLenum dest_type); | 950 |
951 void DoCopySubTextureCHROMIUM(GLenum target, | |
952 GLuint source_id, | |
953 GLuint dest_id, | |
954 GLint level, | |
955 GLint xoffset, | |
956 GLint yoffset); | |
946 | 957 |
947 // Wrapper for TexStorage2DEXT. | 958 // Wrapper for TexStorage2DEXT. |
948 void DoTexStorage2DEXT( | 959 void DoTexStorage2DEXT( |
949 GLenum target, | 960 GLenum target, |
950 GLint levels, | 961 GLint levels, |
951 GLenum internal_format, | 962 GLenum internal_format, |
952 GLsizei width, | 963 GLsizei width, |
953 GLsizei height); | 964 GLsizei height); |
954 | 965 |
955 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); | 966 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1652 const char* function_name, | 1663 const char* function_name, |
1653 GLint level, GLsizei width, GLsizei height, GLenum format); | 1664 GLint level, GLsizei width, GLsizei height, GLenum format); |
1654 bool ValidateCompressedTexFuncData( | 1665 bool ValidateCompressedTexFuncData( |
1655 const char* function_name, | 1666 const char* function_name, |
1656 GLsizei width, GLsizei height, GLenum format, size_t size); | 1667 GLsizei width, GLsizei height, GLenum format, size_t size); |
1657 bool ValidateCompressedTexSubDimensions( | 1668 bool ValidateCompressedTexSubDimensions( |
1658 const char* function_name, | 1669 const char* function_name, |
1659 GLenum target, GLint level, GLint xoffset, GLint yoffset, | 1670 GLenum target, GLint level, GLint xoffset, GLint yoffset, |
1660 GLsizei width, GLsizei height, GLenum format, | 1671 GLsizei width, GLsizei height, GLenum format, |
1661 Texture* texture); | 1672 Texture* texture); |
1673 bool ValidateCopyTextureCHROMIUM(const char* function_name, | |
1674 GLenum target, | |
1675 TextureRef* source_texture_ref, | |
1676 TextureRef* dest_texture_ref, | |
1677 GLint level, | |
1678 GLenum dest_internal_format); | |
1662 | 1679 |
1663 void RenderWarning(const char* filename, int line, const std::string& msg); | 1680 void RenderWarning(const char* filename, int line, const std::string& msg); |
1664 void PerformanceWarning( | 1681 void PerformanceWarning( |
1665 const char* filename, int line, const std::string& msg); | 1682 const char* filename, int line, const std::string& msg); |
1666 | 1683 |
1667 const FeatureInfo::FeatureFlags& features() const { | 1684 const FeatureInfo::FeatureFlags& features() const { |
1668 return feature_info_->feature_flags(); | 1685 return feature_info_->feature_flags(); |
1669 } | 1686 } |
1670 | 1687 |
1671 const FeatureInfo::Workarounds& workarounds() const { | 1688 const FeatureInfo::Workarounds& workarounds() const { |
(...skipping 9038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10710 return GL_LUMINANCE_ALPHA; | 10727 return GL_LUMINANCE_ALPHA; |
10711 case GL_BGRA8_EXT: | 10728 case GL_BGRA8_EXT: |
10712 return GL_BGRA_EXT; | 10729 return GL_BGRA_EXT; |
10713 case GL_SRGB8_ALPHA8_EXT: | 10730 case GL_SRGB8_ALPHA8_EXT: |
10714 return GL_SRGB_ALPHA_EXT; | 10731 return GL_SRGB_ALPHA_EXT; |
10715 default: | 10732 default: |
10716 return GL_NONE; | 10733 return GL_NONE; |
10717 } | 10734 } |
10718 } | 10735 } |
10719 | 10736 |
10720 void GLES2DecoderImpl::DoCopyTextureCHROMIUM( | 10737 bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUM( |
10721 GLenum target, GLuint source_id, GLuint dest_id, GLint level, | 10738 const char* function_name, |
10722 GLenum internal_format, GLenum dest_type) { | 10739 GLenum target, |
10723 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); | 10740 TextureRef* source_texture_ref, |
10724 | 10741 TextureRef* dest_texture_ref, |
10725 TextureRef* dest_texture_ref = GetTexture(dest_id); | 10742 GLint level, |
10726 TextureRef* source_texture_ref = GetTexture(source_id); | 10743 GLenum dest_internal_format) { |
10727 | |
10728 if (!source_texture_ref || !dest_texture_ref) { | 10744 if (!source_texture_ref || !dest_texture_ref) { |
10729 LOCAL_SET_GL_ERROR( | 10745 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); |
10730 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id"); | 10746 return false; |
10731 return; | |
10732 } | 10747 } |
10733 | 10748 |
10734 if (GL_TEXTURE_2D != target) { | 10749 if (GL_TEXTURE_2D != target) { |
10735 LOCAL_SET_GL_ERROR( | 10750 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
10736 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "invalid texture target"); | 10751 "invalid texture target"); |
10737 return; | 10752 return false; |
10753 } | |
10754 | |
10755 // because glFramebufferTexture2D() doesn't support level > 0. | |
dshwang
2015/02/10 18:11:55
add comment why level > 0 is not supported.
piman
2015/02/25 21:32:17
If we won't ever support it, we should remove the
| |
10756 if (level) { | |
10757 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "level must be 0"); | |
10758 return false; | |
10738 } | 10759 } |
10739 | 10760 |
10740 Texture* source_texture = source_texture_ref->texture(); | 10761 Texture* source_texture = source_texture_ref->texture(); |
10741 Texture* dest_texture = dest_texture_ref->texture(); | 10762 Texture* dest_texture = dest_texture_ref->texture(); |
10763 if (source_texture == dest_texture) { | |
10764 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | |
10765 "source and destination textures are the same"); | |
10766 return false; | |
10767 } | |
10768 | |
10742 if (dest_texture->target() != GL_TEXTURE_2D || | 10769 if (dest_texture->target() != GL_TEXTURE_2D || |
10743 (source_texture->target() != GL_TEXTURE_2D && | 10770 (source_texture->target() != GL_TEXTURE_2D && |
10744 source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && | 10771 source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && |
10745 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { | 10772 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { |
10746 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | 10773 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
10747 "glCopyTextureCHROMIUM", | |
10748 "invalid texture target binding"); | 10774 "invalid texture target binding"); |
10749 return; | 10775 return false; |
10750 } | 10776 } |
10751 | 10777 |
10752 int source_width, source_height, dest_width, dest_height; | 10778 GLenum source_type = 0; |
10779 GLenum source_internal_format = 0; | |
10780 source_texture->GetLevelType(source_texture->target(), 0, &source_type, | |
10781 &source_internal_format); | |
10753 | 10782 |
10783 // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, | |
10784 // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not | |
10785 // renderable on some platforms. | |
10786 bool valid_dest_format = dest_internal_format == GL_RGB || | |
10787 dest_internal_format == GL_RGBA || | |
10788 dest_internal_format == GL_BGRA_EXT; | |
10789 bool valid_source_format = source_internal_format == GL_ALPHA || | |
10790 source_internal_format == GL_RGB || | |
10791 source_internal_format == GL_RGBA || | |
10792 source_internal_format == GL_LUMINANCE || | |
10793 source_internal_format == GL_LUMINANCE_ALPHA || | |
10794 source_internal_format == GL_BGRA_EXT; | |
10795 if (!valid_source_format || !valid_dest_format) { | |
10796 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | |
10797 "invalid internal format"); | |
10798 return false; | |
10799 } | |
10800 return true; | |
10801 } | |
10802 | |
10803 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target, | |
10804 GLuint source_id, | |
10805 GLuint dest_id, | |
10806 GLint level, | |
10807 GLenum internal_format, | |
10808 GLenum dest_type) { | |
10809 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); | |
10810 | |
10811 TextureRef* source_texture_ref = GetTexture(source_id); | |
10812 TextureRef* dest_texture_ref = GetTexture(dest_id); | |
10813 Texture* source_texture = source_texture_ref->texture(); | |
10814 Texture* dest_texture = dest_texture_ref->texture(); | |
10815 int source_width = 0; | |
10816 int source_height = 0; | |
10754 gfx::GLImage* image = | 10817 gfx::GLImage* image = |
10755 source_texture->GetLevelImage(source_texture->target(), 0); | 10818 source_texture->GetLevelImage(source_texture->target(), 0); |
10756 if (image) { | 10819 if (image) { |
10757 gfx::Size size = image->GetSize(); | 10820 gfx::Size size = image->GetSize(); |
10758 source_width = size.width(); | 10821 source_width = size.width(); |
10759 source_height = size.height(); | 10822 source_height = size.height(); |
10760 if (source_width <= 0 || source_height <= 0) { | 10823 if (source_width <= 0 || source_height <= 0) { |
10761 LOCAL_SET_GL_ERROR( | 10824 LOCAL_SET_GL_ERROR( |
10762 GL_INVALID_VALUE, | 10825 GL_INVALID_VALUE, |
10763 "glCopyTextureChromium", "invalid image size"); | 10826 "glCopyTextureChromium", "invalid image size"); |
(...skipping 10 matching lines...) Expand all Loading... | |
10774 | 10837 |
10775 // Check that this type of texture is allowed. | 10838 // Check that this type of texture is allowed. |
10776 if (!texture_manager()->ValidForTarget( | 10839 if (!texture_manager()->ValidForTarget( |
10777 source_texture->target(), level, source_width, source_height, 1)) { | 10840 source_texture->target(), level, source_width, source_height, 1)) { |
10778 LOCAL_SET_GL_ERROR( | 10841 LOCAL_SET_GL_ERROR( |
10779 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); | 10842 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); |
10780 return; | 10843 return; |
10781 } | 10844 } |
10782 } | 10845 } |
10783 | 10846 |
10784 // Clear the source texture if necessary. | |
10785 if (!texture_manager()->ClearTextureLevel( | |
10786 this, source_texture_ref, source_texture->target(), 0)) { | |
10787 LOCAL_SET_GL_ERROR( | |
10788 GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", "dimensions too big"); | |
10789 return; | |
10790 } | |
10791 | |
10792 GLenum source_type = 0; | 10847 GLenum source_type = 0; |
10793 GLenum source_internal_format = 0; | 10848 GLenum source_internal_format = 0; |
10794 source_texture->GetLevelType( | 10849 source_texture->GetLevelType( |
10795 source_texture->target(), 0, &source_type, &source_internal_format); | 10850 source_texture->target(), 0, &source_type, &source_internal_format); |
10796 | 10851 |
10797 // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, | 10852 if (dest_texture->IsImmutable()) { |
10798 // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not | 10853 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopyTextureCHROMIUM", |
10799 // renderable on some platforms. | 10854 "texture is immutable"); |
10800 bool valid_dest_format = internal_format == GL_RGB || | |
10801 internal_format == GL_RGBA || | |
10802 internal_format == GL_BGRA_EXT; | |
10803 bool valid_source_format = source_internal_format == GL_ALPHA || | |
10804 source_internal_format == GL_RGB || | |
10805 source_internal_format == GL_RGBA || | |
10806 source_internal_format == GL_LUMINANCE || | |
10807 source_internal_format == GL_LUMINANCE_ALPHA || | |
10808 source_internal_format == GL_BGRA_EXT; | |
10809 if (!valid_source_format || !valid_dest_format) { | |
10810 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, | |
10811 "glCopyTextureCHROMIUM", | |
10812 "invalid internal format"); | |
10813 return; | 10855 return; |
10814 } | 10856 } |
10815 | 10857 |
10858 if (!ValidateCopyTextureCHROMIUM("glCopyTextureCHROMIUM", target, | |
10859 source_texture_ref, dest_texture_ref, level, | |
10860 internal_format)) { | |
10861 return; | |
10862 } | |
10863 | |
10864 // Clear the source texture if necessary. | |
10865 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, | |
10866 source_texture->target(), 0)) { | |
10867 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", | |
10868 "dimensions too big"); | |
10869 return; | |
10870 } | |
10871 | |
10816 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is | 10872 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
10817 // needed because it takes 10s of milliseconds to initialize. | 10873 // needed because it takes 10s of milliseconds to initialize. |
10818 if (!copy_texture_CHROMIUM_.get()) { | 10874 if (!copy_texture_CHROMIUM_.get()) { |
10819 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); | 10875 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
10820 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); | 10876 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
10821 copy_texture_CHROMIUM_->Initialize(this); | 10877 copy_texture_CHROMIUM_->Initialize(this); |
10822 RestoreCurrentFramebufferBindings(); | 10878 RestoreCurrentFramebufferBindings(); |
10823 if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) | 10879 if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) |
10824 return; | 10880 return; |
10825 } | 10881 } |
10826 | 10882 |
10827 GLenum dest_type_previous = dest_type; | 10883 GLenum dest_type_previous = dest_type; |
10828 GLenum dest_internal_format = internal_format; | 10884 GLenum dest_internal_format = internal_format; |
10885 int dest_width = 0; | |
10886 int dest_height = 0; | |
10829 bool dest_level_defined = dest_texture->GetLevelSize( | 10887 bool dest_level_defined = dest_texture->GetLevelSize( |
10830 GL_TEXTURE_2D, level, &dest_width, &dest_height); | 10888 GL_TEXTURE_2D, level, &dest_width, &dest_height); |
10831 | 10889 |
10832 if (dest_level_defined) { | 10890 if (dest_level_defined) { |
10833 dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous, | 10891 dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous, |
10834 &dest_internal_format); | 10892 &dest_internal_format); |
10835 } | 10893 } |
10836 | 10894 |
10837 // Resize the destination texture to the dimensions of the source texture. | 10895 // Resize the destination texture to the dimensions of the source texture. |
10838 if (!dest_level_defined || dest_width != source_width || | 10896 if (!dest_level_defined || dest_width != source_width || |
(...skipping 30 matching lines...) Expand all Loading... | |
10869 if (image->CopyTexImage(GL_TEXTURE_2D)) | 10927 if (image->CopyTexImage(GL_TEXTURE_2D)) |
10870 return; | 10928 return; |
10871 } | 10929 } |
10872 | 10930 |
10873 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | 10931 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
10874 | 10932 |
10875 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix | 10933 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
10876 // before presenting. | 10934 // before presenting. |
10877 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { | 10935 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
10878 // TODO(hkuang): get the StreamTexture transform matrix in GPU process | 10936 // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
10879 // instead of using default matrix crbug.com/226218. | 10937 // instead of using kIdentityMatrix crbug.com/226218. |
10880 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, | |
10881 0.0f, 1.0f, 0.0f, 0.0f, | |
10882 0.0f, 0.0f, 1.0f, 0.0f, | |
10883 0.0f, 0.0f, 0.0f, 1.0f}; | |
10884 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( | 10938 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
10885 this, | 10939 this, source_texture->target(), source_texture->service_id(), |
10886 source_texture->target(), | 10940 dest_texture->service_id(), level, source_width, source_height, |
10887 source_texture->service_id(), | 10941 unpack_flip_y_, unpack_premultiply_alpha_, unpack_unpremultiply_alpha_, |
10888 dest_texture->service_id(), | 10942 kIdentityMatrix); |
10889 level, | |
10890 source_width, | |
10891 source_height, | |
10892 unpack_flip_y_, | |
10893 unpack_premultiply_alpha_, | |
10894 unpack_unpremultiply_alpha_, | |
10895 default_matrix); | |
10896 } else { | 10943 } else { |
10897 copy_texture_CHROMIUM_->DoCopyTexture(this, | 10944 copy_texture_CHROMIUM_->DoCopyTexture( |
10898 source_texture->target(), | 10945 this, source_texture->target(), source_texture->service_id(), |
10899 source_texture->service_id(), | 10946 source_internal_format, dest_texture->service_id(), level, |
10900 source_internal_format, | 10947 internal_format, source_width, source_height, unpack_flip_y_, |
10901 dest_texture->service_id(), | 10948 unpack_premultiply_alpha_, unpack_unpremultiply_alpha_); |
10902 level, | |
10903 internal_format, | |
10904 source_width, | |
10905 source_height, | |
10906 unpack_flip_y_, | |
10907 unpack_premultiply_alpha_, | |
10908 unpack_unpremultiply_alpha_); | |
10909 } | 10949 } |
10910 | 10950 |
10911 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | 10951 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
10952 } | |
10953 | |
10954 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(GLenum target, | |
10955 GLuint source_id, | |
10956 GLuint dest_id, | |
10957 GLint level, | |
10958 GLint xoffset, | |
10959 GLint yoffset) { | |
10960 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopySubTextureCHROMIUM"); | |
10961 | |
10962 TextureRef* source_texture_ref = GetTexture(source_id); | |
10963 TextureRef* dest_texture_ref = GetTexture(dest_id); | |
10964 Texture* source_texture = source_texture_ref->texture(); | |
10965 Texture* dest_texture = dest_texture_ref->texture(); | |
10966 int source_width = 0; | |
10967 int source_height = 0; | |
10968 gfx::GLImage* image = | |
10969 source_texture->GetLevelImage(source_texture->target(), 0); | |
10970 if (image) { | |
10971 gfx::Size size = image->GetSize(); | |
10972 source_width = size.width(); | |
10973 source_height = size.height(); | |
10974 if (source_width <= 0 || source_height <= 0) { | |
10975 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", | |
10976 "invalid image size"); | |
10977 return; | |
10978 } | |
10979 } else { | |
10980 if (!source_texture->GetLevelSize(source_texture->target(), 0, | |
10981 &source_width, &source_height)) { | |
10982 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", | |
10983 "source texture has no level 0"); | |
10984 return; | |
10985 } | |
10986 | |
10987 // Check that this type of texture is allowed. | |
10988 if (!texture_manager()->ValidForTarget(source_texture->target(), level, | |
10989 source_width, source_height, 1)) { | |
10990 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", | |
10991 "source texture bad dimensions"); | |
10992 return; | |
10993 } | |
10994 } | |
10995 | |
10996 GLenum source_type = 0; | |
10997 GLenum source_internal_format = 0; | |
10998 source_texture->GetLevelType(source_texture->target(), 0, &source_type, | |
10999 &source_internal_format); | |
11000 GLenum dest_type = 0; | |
11001 GLenum dest_internal_format = 0; | |
11002 bool dest_level_defined = dest_texture->GetLevelType( | |
11003 dest_texture->target(), level, &dest_type, &dest_internal_format); | |
11004 if (!dest_level_defined) { | |
11005 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopySubTextureCHROMIUM", | |
11006 "destination texture is not defined"); | |
11007 return; | |
11008 } | |
11009 if (!dest_texture->ValidForTexture(dest_texture->target(), level, xoffset, | |
11010 yoffset, source_width, source_height, | |
11011 dest_type)) { | |
11012 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", | |
11013 "destination texture bad dimensions."); | |
11014 return; | |
11015 } | |
11016 | |
11017 if (!ValidateCopyTextureCHROMIUM("glCopySubTextureCHROMIUM", target, | |
11018 source_texture_ref, dest_texture_ref, level, | |
11019 dest_internal_format)) { | |
11020 return; | |
11021 } | |
11022 | |
11023 // Clear the source texture if necessary. | |
11024 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, | |
11025 source_texture->target(), 0)) { | |
11026 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM", | |
11027 "source texture dimensions too big"); | |
11028 return; | |
11029 } | |
11030 | |
11031 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is | |
11032 // needed because it takes 10s of milliseconds to initialize. | |
11033 if (!copy_texture_CHROMIUM_.get()) { | |
11034 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopySubTextureCHROMIUM"); | |
11035 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); | |
11036 copy_texture_CHROMIUM_->Initialize(this); | |
11037 RestoreCurrentFramebufferBindings(); | |
11038 if (LOCAL_PEEK_GL_ERROR("glCopySubTextureCHROMIUM") != GL_NO_ERROR) | |
11039 return; | |
11040 } | |
11041 | |
11042 int dest_width = 0; | |
11043 int dest_height = 0; | |
11044 bool ok = dest_texture->GetLevelSize(GL_TEXTURE_2D, level, &dest_width, | |
11045 &dest_height); | |
11046 DCHECK(ok); | |
11047 if (xoffset != 0 || yoffset != 0 || source_width != dest_width || | |
11048 source_height != dest_height) { | |
11049 if (!texture_manager()->ClearTextureLevel(this, dest_texture_ref, target, | |
11050 level)) { | |
11051 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM", | |
11052 "destination texture dimensions too big"); | |
11053 return; | |
11054 } | |
11055 } else { | |
11056 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, level, | |
11057 true); | |
11058 } | |
11059 | |
11060 ScopedModifyPixels modify(dest_texture_ref); | |
11061 | |
11062 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | |
11063 | |
11064 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix | |
11065 // before presenting. | |
11066 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { | |
11067 // TODO(hkuang): get the StreamTexture transform matrix in GPU process | |
11068 // instead of using kIdentityMatrix crbug.com/226218. | |
11069 copy_texture_CHROMIUM_->DoCopySubTextureWithTransform( | |
11070 this, source_texture->target(), source_texture->service_id(), | |
11071 dest_texture->service_id(), level, xoffset, yoffset, dest_width, | |
11072 dest_height, source_width, source_height, unpack_flip_y_, | |
11073 unpack_premultiply_alpha_, unpack_unpremultiply_alpha_, | |
11074 kIdentityMatrix); | |
11075 } else { | |
11076 copy_texture_CHROMIUM_->DoCopySubTexture( | |
11077 this, source_texture->target(), source_texture->service_id(), | |
11078 source_internal_format, dest_texture->service_id(), level, | |
11079 dest_internal_format, xoffset, yoffset, dest_width, dest_height, | |
11080 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, | |
11081 unpack_unpremultiply_alpha_); | |
11082 } | |
11083 | |
11084 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | |
10912 } | 11085 } |
10913 | 11086 |
10914 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { | 11087 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
10915 switch (internalformat) { | 11088 switch (internalformat) { |
10916 case GL_RGB565: | 11089 case GL_RGB565: |
10917 return GL_UNSIGNED_SHORT_5_6_5; | 11090 return GL_UNSIGNED_SHORT_5_6_5; |
10918 case GL_RGBA4: | 11091 case GL_RGBA4: |
10919 return GL_UNSIGNED_SHORT_4_4_4_4; | 11092 return GL_UNSIGNED_SHORT_4_4_4_4; |
10920 case GL_RGB5_A1: | 11093 case GL_RGB5_A1: |
10921 return GL_UNSIGNED_SHORT_5_5_5_1; | 11094 return GL_UNSIGNED_SHORT_5_5_5_1; |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11503 DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || | 11676 DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || |
11504 matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); | 11677 matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); |
11505 | 11678 |
11506 if (!features().chromium_path_rendering) { | 11679 if (!features().chromium_path_rendering) { |
11507 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, | 11680 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
11508 "glMatrixLoadIdentityCHROMIUM", | 11681 "glMatrixLoadIdentityCHROMIUM", |
11509 "function not available"); | 11682 "function not available"); |
11510 return; | 11683 return; |
11511 } | 11684 } |
11512 | 11685 |
11513 static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, | |
11514 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, | |
11515 0.0f, 0.0f, 0.0f, 1.0f}; | |
11516 | |
11517 GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM | 11686 GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM |
11518 ? state_.projection_matrix | 11687 ? state_.projection_matrix |
11519 : state_.modelview_matrix; | 11688 : state_.modelview_matrix; |
11520 memcpy(target_matrix, kIdentityMatrix, sizeof(kIdentityMatrix)); | 11689 memcpy(target_matrix, kIdentityMatrix, sizeof(kIdentityMatrix)); |
11521 // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV | 11690 // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV |
11522 // since the values of the _NV and _CHROMIUM tokens match. | 11691 // since the values of the _NV and _CHROMIUM tokens match. |
11523 glMatrixLoadIdentityEXT(matrix_mode); | 11692 glMatrixLoadIdentityEXT(matrix_mode); |
11524 } | 11693 } |
11525 | 11694 |
11526 bool GLES2DecoderImpl::ValidateAsyncTransfer( | 11695 bool GLES2DecoderImpl::ValidateAsyncTransfer( |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11864 } | 12033 } |
11865 } | 12034 } |
11866 | 12035 |
11867 // Include the auto-generated part of this file. We split this because it means | 12036 // Include the auto-generated part of this file. We split this because it means |
11868 // we can easily edit the non-auto generated parts right here in this file | 12037 // we can easily edit the non-auto generated parts right here in this file |
11869 // instead of having to edit some template or the code generator. | 12038 // instead of having to edit some template or the code generator. |
11870 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 12039 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
11871 | 12040 |
11872 } // namespace gles2 | 12041 } // namespace gles2 |
11873 } // namespace gpu | 12042 } // namespace gpu |
OLD | NEW |