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 <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
882 GLint yoffset, | 882 GLint yoffset, |
883 GLint zoffset, | 883 GLint zoffset, |
884 GLsizei width, | 884 GLsizei width, |
885 GLsizei height, | 885 GLsizei height, |
886 GLsizei depth, | 886 GLsizei depth, |
887 GLenum format, | 887 GLenum format, |
888 GLsizei imageSize, | 888 GLsizei imageSize, |
889 const void* data, | 889 const void* data, |
890 ContextState::Dimension dimension); | 890 ContextState::Dimension dimension); |
891 | 891 |
892 bool ValidateCopyTexFormatHelper(GLenum internal_format, | |
893 GLenum read_format, | |
894 GLenum read_type, | |
895 std::string* output_error_msg); | |
892 // Validate if |format| is valid for CopyTex{Sub}Image functions. | 896 // Validate if |format| is valid for CopyTex{Sub}Image functions. |
893 // If not, generate a GL error and return false. | 897 // If not, generate a GL error and return false. |
894 bool ValidateCopyTexFormat(const char* func_name, GLenum internal_format, | 898 bool ValidateCopyTexFormat(const char* func_name, GLenum internal_format, |
895 GLenum read_format, GLenum read_type); | 899 GLenum read_format, GLenum read_type); |
896 | 900 |
897 // Wrapper for CopyTexImage2D. | 901 // Wrapper for CopyTexImage2D. |
898 void DoCopyTexImage2D( | 902 void DoCopyTexImage2D( |
899 GLenum target, | 903 GLenum target, |
900 GLint level, | 904 GLint level, |
901 GLenum internal_format, | 905 GLenum internal_format, |
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1995 GLsizei size, | 1999 GLsizei size, |
1996 const GLvoid* data); | 2000 const GLvoid* data); |
1997 bool ValidateCompressedTexSubDimensions( | 2001 bool ValidateCompressedTexSubDimensions( |
1998 const char* function_name, | 2002 const char* function_name, |
1999 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, | 2003 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, |
2000 GLsizei width, GLsizei height, GLsizei depth, GLenum format, | 2004 GLsizei width, GLsizei height, GLsizei depth, GLenum format, |
2001 Texture* texture); | 2005 Texture* texture); |
2002 bool ValidateCopyTextureCHROMIUMTextures(const char* function_name, | 2006 bool ValidateCopyTextureCHROMIUMTextures(const char* function_name, |
2003 TextureRef* source_texture_ref, | 2007 TextureRef* source_texture_ref, |
2004 TextureRef* dest_texture_ref); | 2008 TextureRef* dest_texture_ref); |
2005 bool ValidateCopyTextureCHROMIUMInternalFormats( | 2009 SupportedCopyMethodByFormat ValidateCopyTextureCHROMIUMInternalFormats( |
2006 const char* function_name, | 2010 const char* function_name, |
2007 TextureRef* source_texture_ref, | 2011 TextureRef* source_texture_ref, |
2008 GLenum dest_internal_format); | 2012 GLenum dest_internal_format); |
2009 bool ValidateCompressedCopyTextureCHROMIUM(const char* function_name, | 2013 bool ValidateCompressedCopyTextureCHROMIUM(const char* function_name, |
2010 TextureRef* source_texture_ref, | 2014 TextureRef* source_texture_ref, |
2011 TextureRef* dest_texture_ref); | 2015 TextureRef* dest_texture_ref); |
2012 | 2016 |
2013 void RenderWarning(const char* filename, int line, const std::string& msg); | 2017 void RenderWarning(const char* filename, int line, const std::string& msg); |
2014 void PerformanceWarning( | 2018 void PerformanceWarning( |
2015 const char* filename, int line, const std::string& msg); | 2019 const char* filename, int line, const std::string& msg); |
(...skipping 11715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13731 height, depth, format, image_size, data); | 13735 height, depth, format, image_size, data); |
13732 } | 13736 } |
13733 } | 13737 } |
13734 | 13738 |
13735 // This may be a slow command. Exit command processing to allow for | 13739 // This may be a slow command. Exit command processing to allow for |
13736 // context preemption and GPU watchdog checks. | 13740 // context preemption and GPU watchdog checks. |
13737 ExitCommandProcessingEarly(); | 13741 ExitCommandProcessingEarly(); |
13738 return error::kNoError; | 13742 return error::kNoError; |
13739 } | 13743 } |
13740 | 13744 |
13741 bool GLES2DecoderImpl::ValidateCopyTexFormat( | 13745 bool GLES2DecoderImpl::ValidateCopyTexFormatHelper( |
13742 const char* func_name, GLenum internal_format, | 13746 GLenum internal_format, |
13743 GLenum read_format, GLenum read_type) { | 13747 GLenum read_format, |
13748 GLenum read_type, | |
13749 std::string* output_error_msg) { | |
13744 if (read_format == 0) { | 13750 if (read_format == 0) { |
Zhenyao Mo
2016/11/19 00:42:33
Can we DCHECK(output_error_msg)?
qiankun
2016/11/21 16:01:50
Done.
| |
13745 LOCAL_SET_GL_ERROR( | 13751 *output_error_msg = std::string("no valid color image"); |
13746 GL_INVALID_OPERATION, func_name, "no valid color image"); | |
13747 return false; | 13752 return false; |
13748 } | 13753 } |
13749 // Check we have compatible formats. | 13754 // Check we have compatible formats. |
13750 uint32_t channels_exist = GLES2Util::GetChannelsForFormat(read_format); | 13755 uint32_t channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
13751 uint32_t channels_needed = GLES2Util::GetChannelsForFormat(internal_format); | 13756 uint32_t channels_needed = GLES2Util::GetChannelsForFormat(internal_format); |
13752 if (!channels_needed || | 13757 if (!channels_needed || |
13753 (channels_needed & channels_exist) != channels_needed) { | 13758 (channels_needed & channels_exist) != channels_needed) { |
13754 LOCAL_SET_GL_ERROR( | 13759 *output_error_msg = std::string("incompatible format"); |
13755 GL_INVALID_OPERATION, func_name, "incompatible format"); | |
13756 return false; | 13760 return false; |
13757 } | 13761 } |
13758 if (feature_info_->IsWebGL2OrES3Context()) { | 13762 if (feature_info_->IsWebGL2OrES3Context()) { |
13759 GLint color_encoding = GetColorEncodingFromInternalFormat(read_format); | 13763 GLint color_encoding = GetColorEncodingFromInternalFormat(read_format); |
13760 bool float_mismatch = feature_info_->ext_color_buffer_float_available() ? | 13764 bool float_mismatch = feature_info_->ext_color_buffer_float_available() ? |
13761 (GLES2Util::IsIntegerFormat(internal_format) != | 13765 (GLES2Util::IsIntegerFormat(internal_format) != |
13762 GLES2Util::IsIntegerFormat(read_format)) : | 13766 GLES2Util::IsIntegerFormat(read_format)) : |
13763 GLES2Util::IsFloatFormat(internal_format); | 13767 GLES2Util::IsFloatFormat(internal_format); |
13764 if (color_encoding != GetColorEncodingFromInternalFormat(internal_format) || | 13768 if (color_encoding != GetColorEncodingFromInternalFormat(internal_format) || |
13765 float_mismatch || | 13769 float_mismatch || |
13766 (GLES2Util::IsSignedIntegerFormat(internal_format) != | 13770 (GLES2Util::IsSignedIntegerFormat(internal_format) != |
13767 GLES2Util::IsSignedIntegerFormat(read_format)) || | 13771 GLES2Util::IsSignedIntegerFormat(read_format)) || |
13768 (GLES2Util::IsUnsignedIntegerFormat(internal_format) != | 13772 (GLES2Util::IsUnsignedIntegerFormat(internal_format) != |
13769 GLES2Util::IsUnsignedIntegerFormat(read_format))) { | 13773 GLES2Util::IsUnsignedIntegerFormat(read_format))) { |
13770 LOCAL_SET_GL_ERROR( | 13774 *output_error_msg = std::string("incompatible format"); |
13771 GL_INVALID_OPERATION, func_name, "incompatible format"); | |
13772 return false; | 13775 return false; |
13773 } | 13776 } |
13774 } | 13777 } |
13775 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { | 13778 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
13776 LOCAL_SET_GL_ERROR( | 13779 *output_error_msg = |
13777 GL_INVALID_OPERATION, | 13780 std::string("can not be used with depth or stencil textures"); |
13778 func_name, "can not be used with depth or stencil textures"); | |
13779 return false; | 13781 return false; |
13780 } | 13782 } |
13781 if (feature_info_->IsWebGL2OrES3Context()) { | 13783 if (feature_info_->IsWebGL2OrES3Context()) { |
13782 if (GLES2Util::IsSizedColorFormat(internal_format)) { | 13784 if (GLES2Util::IsSizedColorFormat(internal_format)) { |
13783 int sr, sg, sb, sa; | 13785 int sr, sg, sb, sa; |
13784 GLES2Util::GetColorFormatComponentSizes( | 13786 GLES2Util::GetColorFormatComponentSizes( |
13785 read_format, read_type, &sr, &sg, &sb, &sa); | 13787 read_format, read_type, &sr, &sg, &sb, &sa); |
13786 DCHECK(sr > 0 || sg > 0 || sb > 0 || sa > 0); | 13788 DCHECK(sr > 0 || sg > 0 || sb > 0 || sa > 0); |
13787 int dr, dg, db, da; | 13789 int dr, dg, db, da; |
13788 GLES2Util::GetColorFormatComponentSizes( | 13790 GLES2Util::GetColorFormatComponentSizes( |
13789 internal_format, 0, &dr, &dg, &db, &da); | 13791 internal_format, 0, &dr, &dg, &db, &da); |
13790 DCHECK(dr > 0 || dg > 0 || db > 0 || da > 0); | 13792 DCHECK(dr > 0 || dg > 0 || db > 0 || da > 0); |
13791 if ((dr > 0 && sr != dr) || | 13793 if ((dr > 0 && sr != dr) || |
13792 (dg > 0 && sg != dg) || | 13794 (dg > 0 && sg != dg) || |
13793 (db > 0 && sb != db) || | 13795 (db > 0 && sb != db) || |
13794 (da > 0 && sa != da)) { | 13796 (da > 0 && sa != da)) { |
13795 LOCAL_SET_GL_ERROR( | 13797 *output_error_msg = std::string("incompatible color component sizes"); |
13796 GL_INVALID_OPERATION, | |
13797 func_name, "incompatible color component sizes"); | |
13798 return false; | 13798 return false; |
13799 } | 13799 } |
13800 } | 13800 } |
13801 } | 13801 } |
13802 return true; | 13802 return true; |
13803 } | 13803 } |
13804 | 13804 |
13805 bool GLES2DecoderImpl::ValidateCopyTexFormat(const char* func_name, | |
13806 GLenum internal_format, | |
13807 GLenum read_format, | |
13808 GLenum read_type) { | |
13809 std::string output_error_msg; | |
13810 if (!ValidateCopyTexFormatHelper(internal_format, read_format, read_type, | |
13811 &output_error_msg)) { | |
13812 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name, | |
13813 output_error_msg.c_str()); | |
13814 return false; | |
13815 } | |
13816 return true; | |
13817 } | |
13818 | |
13805 void GLES2DecoderImpl::DoCopyTexImage2D( | 13819 void GLES2DecoderImpl::DoCopyTexImage2D( |
13806 GLenum target, | 13820 GLenum target, |
13807 GLint level, | 13821 GLint level, |
13808 GLenum internal_format, | 13822 GLenum internal_format, |
13809 GLint x, | 13823 GLint x, |
13810 GLint y, | 13824 GLint y, |
13811 GLsizei width, | 13825 GLsizei width, |
13812 GLsizei height, | 13826 GLsizei height, |
13813 GLint border) { | 13827 GLint border) { |
13814 const char* func_name = "glCopyTexImage2D"; | 13828 const char* func_name = "glCopyTexImage2D"; |
(...skipping 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15999 case GL_TEXTURE_EXTERNAL_OES: | 16013 case GL_TEXTURE_EXTERNAL_OES: |
16000 break; | 16014 break; |
16001 default: | 16015 default: |
16002 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, | 16016 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
16003 "invalid source texture target binding"); | 16017 "invalid source texture target binding"); |
16004 return false; | 16018 return false; |
16005 } | 16019 } |
16006 return true; | 16020 return true; |
16007 } | 16021 } |
16008 | 16022 |
16009 bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUMInternalFormats( | 16023 SupportedCopyMethodByFormat |
16024 GLES2DecoderImpl::ValidateCopyTextureCHROMIUMInternalFormats( | |
16010 const char* function_name, | 16025 const char* function_name, |
16011 TextureRef* source_texture_ref, | 16026 TextureRef* source_texture_ref, |
16012 GLenum dest_internal_format) { | 16027 GLenum dest_internal_format) { |
16013 GLenum source_type = 0; | 16028 GLenum source_type = 0; |
16014 GLenum source_internal_format = 0; | 16029 GLenum source_internal_format = 0; |
16015 Texture* source_texture = source_texture_ref->texture(); | 16030 Texture* source_texture = source_texture_ref->texture(); |
16016 source_texture->GetLevelType(source_texture->target(), 0, &source_type, | 16031 source_texture->GetLevelType(source_texture->target(), 0, &source_type, |
16017 &source_internal_format); | 16032 &source_internal_format); |
16018 | 16033 |
16019 // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, | 16034 bool valid_dest_format = false; |
16020 // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not | 16035 // TODO(qiankun.miao@intel.com): ALPHA and LUMINANCE formats have bug on GL |
16021 // renderable on some platforms. | 16036 // core profile. See crbug.com/577144. Enable the workaround for |
16022 bool valid_dest_format = | 16037 // glCopyTexImage and glCopyTexSubImage in gles2_cmd_copy_tex_image.cc for |
16023 dest_internal_format == GL_RGB || dest_internal_format == GL_RGBA || | 16038 // glCopyTextureCHROMIUM implementation. |
16024 dest_internal_format == GL_RGB8 || dest_internal_format == GL_RGBA8 || | 16039 switch (dest_internal_format) { |
16025 dest_internal_format == GL_BGRA_EXT || | 16040 case GL_LUMINANCE_ALPHA: |
16026 dest_internal_format == GL_BGRA8_EXT; | 16041 case GL_LUMINANCE: |
16042 case GL_ALPHA: | |
16043 case GL_RGB: | |
16044 case GL_RGBA: | |
16045 case GL_RGB8: | |
16046 case GL_RGBA8: | |
16047 valid_dest_format = true; | |
16048 break; | |
16049 case GL_BGRA_EXT: | |
16050 case GL_BGRA8_EXT: | |
16051 valid_dest_format = feature_info_->texture_format_bgra8888_available(); | |
16052 break; | |
16053 case GL_SRGB_EXT: | |
16054 case GL_SRGB_ALPHA_EXT: | |
16055 valid_dest_format = feature_info_->ext_srgb_available(); | |
16056 break; | |
16057 case GL_R8: | |
16058 case GL_R8UI: | |
16059 case GL_RG8: | |
16060 case GL_RG8UI: | |
16061 case GL_SRGB8: | |
16062 case GL_RGB565: | |
16063 case GL_RGB9_E5: | |
16064 case GL_RGB8UI: | |
16065 case GL_SRGB8_ALPHA8: | |
16066 case GL_RGB5_A1: | |
16067 case GL_RGBA4: | |
16068 case GL_RGBA8UI: | |
16069 valid_dest_format = feature_info_->IsWebGL2OrES3Context(); | |
16070 break; | |
16071 case GL_R16F: | |
16072 case GL_R32F: | |
16073 case GL_RG16F: | |
16074 case GL_RG32F: | |
16075 case GL_RGB16F: | |
16076 case GL_RGB32F: | |
16077 case GL_RGBA16F: | |
16078 case GL_RGBA32F: | |
16079 case GL_R11F_G11F_B10F: | |
16080 valid_dest_format = feature_info_->ext_color_buffer_float_available(); | |
16081 break; | |
16082 default: | |
16083 valid_dest_format = false; | |
16084 break; | |
16085 } | |
16086 | |
16027 bool valid_source_format = | 16087 bool valid_source_format = |
16028 source_internal_format == GL_RED || source_internal_format == GL_ALPHA || | 16088 source_internal_format == GL_RED || source_internal_format == GL_ALPHA || |
16029 source_internal_format == GL_RGB || source_internal_format == GL_RGBA || | 16089 source_internal_format == GL_RGB || source_internal_format == GL_RGBA || |
16030 source_internal_format == GL_RGB8 || source_internal_format == GL_RGBA8 || | 16090 source_internal_format == GL_RGB8 || source_internal_format == GL_RGBA8 || |
16031 source_internal_format == GL_LUMINANCE || | 16091 source_internal_format == GL_LUMINANCE || |
16032 source_internal_format == GL_LUMINANCE_ALPHA || | 16092 source_internal_format == GL_LUMINANCE_ALPHA || |
16033 source_internal_format == GL_BGRA_EXT || | 16093 source_internal_format == GL_BGRA_EXT || |
16034 source_internal_format == GL_BGRA8_EXT || | 16094 source_internal_format == GL_BGRA8_EXT || |
16035 source_internal_format == GL_RGB_YCBCR_420V_CHROMIUM || | 16095 source_internal_format == GL_RGB_YCBCR_420V_CHROMIUM || |
16036 source_internal_format == GL_RGB_YCBCR_422_CHROMIUM; | 16096 source_internal_format == GL_RGB_YCBCR_422_CHROMIUM; |
16037 if (!valid_source_format) { | 16097 if (!valid_source_format) { |
16038 std::string msg = "invalid source internal format " + | 16098 std::string msg = "invalid source internal format " + |
16039 GLES2Util::GetStringEnum(source_internal_format); | 16099 GLES2Util::GetStringEnum(source_internal_format); |
16040 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | 16100 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
16041 msg.c_str()); | 16101 msg.c_str()); |
16042 return false; | 16102 return NONE_COPY; |
16043 } | 16103 } |
16044 if (!valid_dest_format) { | 16104 if (!valid_dest_format) { |
16045 std::string msg = "invalid dest internal format " + | 16105 std::string msg = "invalid dest internal format " + |
16046 GLES2Util::GetStringEnum(dest_internal_format); | 16106 GLES2Util::GetStringEnum(dest_internal_format); |
16047 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | 16107 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
16048 msg.c_str()); | 16108 msg.c_str()); |
16049 return false; | 16109 return NONE_COPY; |
16050 } | 16110 } |
16051 return true; | 16111 |
16112 bool source_format_color_renderable = | |
16113 Texture::ColorRenderable(GetFeatureInfo(), source_internal_format, false); | |
16114 bool dest_format_color_renderable = | |
16115 Texture::ColorRenderable(GetFeatureInfo(), dest_internal_format, false); | |
16116 std::string output_error_msg; | |
16117 | |
16118 // CopyTexImage* should not allow internalformat of GL_BGRA_EXT and | |
16119 // GL_BGRA8_EXT. crbug.com/663086. | |
16120 bool copy_tex_image_format_valid = | |
16121 source_internal_format != GL_BGRA_EXT && | |
16122 dest_internal_format != GL_BGRA_EXT && | |
16123 source_internal_format != GL_BGRA8_EXT && | |
16124 dest_internal_format != GL_BGRA8_EXT && | |
16125 ValidateCopyTexFormatHelper(dest_internal_format, source_internal_format, | |
16126 source_type, &output_error_msg); | |
16127 if (source_format_color_renderable && copy_tex_image_format_valid) | |
16128 return DIRECT_COPY; | |
16129 | |
16130 if (dest_format_color_renderable) | |
16131 return DIRECT_DRAW; | |
16132 | |
16133 return DRAW_AND_COPY; | |
16052 } | 16134 } |
16053 | 16135 |
16054 bool GLES2DecoderImpl::ValidateCompressedCopyTextureCHROMIUM( | 16136 bool GLES2DecoderImpl::ValidateCompressedCopyTextureCHROMIUM( |
16055 const char* function_name, | 16137 const char* function_name, |
16056 TextureRef* source_texture_ref, | 16138 TextureRef* source_texture_ref, |
16057 TextureRef* dest_texture_ref) { | 16139 TextureRef* dest_texture_ref) { |
16058 if (!source_texture_ref || !dest_texture_ref) { | 16140 if (!source_texture_ref || !dest_texture_ref) { |
16059 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); | 16141 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); |
16060 return false; | 16142 return false; |
16061 } | 16143 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16105 GLenum dest_type, | 16187 GLenum dest_type, |
16106 GLboolean unpack_flip_y, | 16188 GLboolean unpack_flip_y, |
16107 GLboolean unpack_premultiply_alpha, | 16189 GLboolean unpack_premultiply_alpha, |
16108 GLboolean unpack_unmultiply_alpha) { | 16190 GLboolean unpack_unmultiply_alpha) { |
16109 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); | 16191 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); |
16110 static const char kFunctionName[] = "glCopyTextureCHROMIUM"; | 16192 static const char kFunctionName[] = "glCopyTextureCHROMIUM"; |
16111 | 16193 |
16112 TextureRef* source_texture_ref = GetTexture(source_id); | 16194 TextureRef* source_texture_ref = GetTexture(source_id); |
16113 TextureRef* dest_texture_ref = GetTexture(dest_id); | 16195 TextureRef* dest_texture_ref = GetTexture(dest_id); |
16114 | 16196 |
16115 if (!texture_manager()->ValidateTextureParameters( | |
16116 GetErrorState(), kFunctionName, true, internal_format, dest_type, | |
16117 internal_format, 0)) | |
16118 return; | |
16119 | |
16120 if (!ValidateCopyTextureCHROMIUMTextures(kFunctionName, source_texture_ref, | 16197 if (!ValidateCopyTextureCHROMIUMTextures(kFunctionName, source_texture_ref, |
16121 dest_texture_ref)) { | 16198 dest_texture_ref)) { |
16122 return; | 16199 return; |
16123 } | 16200 } |
16124 | 16201 |
16125 if (!ValidateCopyTextureCHROMIUMInternalFormats( | |
16126 kFunctionName, source_texture_ref, internal_format)) { | |
16127 return; | |
16128 } | |
16129 | |
16130 Texture* source_texture = source_texture_ref->texture(); | 16202 Texture* source_texture = source_texture_ref->texture(); |
16131 Texture* dest_texture = dest_texture_ref->texture(); | 16203 Texture* dest_texture = dest_texture_ref->texture(); |
16132 GLenum source_target = source_texture->target(); | 16204 GLenum source_target = source_texture->target(); |
16133 GLenum dest_target = dest_texture->target(); | 16205 GLenum dest_target = dest_texture->target(); |
16206 | |
16207 GLenum source_type = 0; | |
16208 GLenum source_internal_format = 0; | |
16209 source_texture->GetLevelType(source_target, 0, &source_type, | |
16210 &source_internal_format); | |
16211 GLenum format = | |
16212 TextureManager::ExtractFormatFromStorageFormat(internal_format); | |
16213 if (!texture_manager()->ValidateTextureParameters( | |
16214 GetErrorState(), kFunctionName, true, format, dest_type, | |
16215 internal_format, 0)) | |
16216 return; | |
Zhenyao Mo
2016/11/19 00:42:33
nit: {} around return when the condition is multi-
qiankun
2016/11/21 16:01:50
Done.
| |
16217 | |
16218 SupportedCopyMethodByFormat method = | |
16219 ValidateCopyTextureCHROMIUMInternalFormats( | |
16220 kFunctionName, source_texture_ref, internal_format); | |
16221 if (NONE_COPY == method) { | |
16222 return; | |
16223 } | |
16224 | |
16225 if (feature_info_->feature_flags().desktop_srgb_support) { | |
16226 bool enable_framebuffer_srgb = | |
16227 GetColorEncodingFromInternalFormat(source_internal_format) == GL_SRGB || | |
16228 GetColorEncodingFromInternalFormat(internal_format) == GL_SRGB; | |
16229 state_.EnableDisableFramebufferSRGB(enable_framebuffer_srgb); | |
16230 } | |
16231 | |
16134 int source_width = 0; | 16232 int source_width = 0; |
16135 int source_height = 0; | 16233 int source_height = 0; |
16136 gl::GLImage* image = | 16234 gl::GLImage* image = |
16137 source_texture->GetLevelImage(source_target, 0); | 16235 source_texture->GetLevelImage(source_target, 0); |
16138 if (image) { | 16236 if (image) { |
16139 gfx::Size size = image->GetSize(); | 16237 gfx::Size size = image->GetSize(); |
16140 source_width = size.width(); | 16238 source_width = size.width(); |
16141 source_height = size.height(); | 16239 source_height = size.height(); |
16142 if (source_width <= 0 || source_height <= 0) { | 16240 if (source_width <= 0 || source_height <= 0) { |
16143 LOCAL_SET_GL_ERROR( | 16241 LOCAL_SET_GL_ERROR( |
(...skipping 11 matching lines...) Expand all Loading... | |
16155 } | 16253 } |
16156 | 16254 |
16157 // Check that this type of texture is allowed. | 16255 // Check that this type of texture is allowed. |
16158 if (!texture_manager()->ValidForTarget(source_target, 0, | 16256 if (!texture_manager()->ValidForTarget(source_target, 0, |
16159 source_width, source_height, 1)) { | 16257 source_width, source_height, 1)) { |
16160 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, "Bad dimensions"); | 16258 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, "Bad dimensions"); |
16161 return; | 16259 return; |
16162 } | 16260 } |
16163 } | 16261 } |
16164 | 16262 |
16165 GLenum source_type = 0; | |
16166 GLenum source_internal_format = 0; | |
16167 source_texture->GetLevelType(source_target, 0, &source_type, | |
16168 &source_internal_format); | |
16169 | |
16170 if (dest_texture->IsImmutable()) { | 16263 if (dest_texture->IsImmutable()) { |
16171 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, kFunctionName, | 16264 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, kFunctionName, |
16172 "texture is immutable"); | 16265 "texture is immutable"); |
16173 return; | 16266 return; |
16174 } | 16267 } |
16175 | 16268 |
16176 // Clear the source texture if necessary. | 16269 // Clear the source texture if necessary. |
16177 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, | 16270 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, |
16178 source_target, 0)) { | 16271 source_target, 0)) { |
16179 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, "dimensions too big"); | 16272 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, "dimensions too big"); |
(...skipping 16 matching lines...) Expand all Loading... | |
16196 } | 16289 } |
16197 | 16290 |
16198 // Resize the destination texture to the dimensions of the source texture. | 16291 // Resize the destination texture to the dimensions of the source texture. |
16199 if (!dest_level_defined || dest_width != source_width || | 16292 if (!dest_level_defined || dest_width != source_width || |
16200 dest_height != source_height || | 16293 dest_height != source_height || |
16201 dest_internal_format != internal_format || | 16294 dest_internal_format != internal_format || |
16202 dest_type_previous != dest_type) { | 16295 dest_type_previous != dest_type) { |
16203 // Ensure that the glTexImage2D succeeds. | 16296 // Ensure that the glTexImage2D succeeds. |
16204 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); | 16297 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); |
16205 glBindTexture(dest_target, dest_texture->service_id()); | 16298 glBindTexture(dest_target, dest_texture->service_id()); |
16206 glTexImage2D( | 16299 glTexImage2D(dest_target, 0, TextureManager::AdjustTexInternalFormat( |
16207 dest_target, 0, TextureManager::AdjustTexInternalFormat( | 16300 feature_info_.get(), internal_format), |
16208 feature_info_.get(), internal_format), | 16301 source_width, source_height, 0, |
16209 source_width, source_height, 0, | 16302 TextureManager::AdjustTexFormat(feature_info_.get(), format), |
16210 TextureManager::AdjustTexFormat(feature_info_.get(), internal_format), | 16303 dest_type, NULL); |
16211 dest_type, NULL); | |
16212 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); | 16304 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); |
16213 if (error != GL_NO_ERROR) { | 16305 if (error != GL_NO_ERROR) { |
16214 RestoreCurrentTextureBindings(&state_, dest_target); | 16306 RestoreCurrentTextureBindings(&state_, dest_target); |
16215 return; | 16307 return; |
16216 } | 16308 } |
16217 | 16309 |
16218 texture_manager()->SetLevelInfo( | 16310 texture_manager()->SetLevelInfo(dest_texture_ref, dest_target, 0, |
16219 dest_texture_ref, dest_target, 0, internal_format, source_width, | 16311 internal_format, source_width, |
16220 source_height, 1, 0, internal_format, dest_type, | 16312 source_height, 1, 0, format, dest_type, |
16221 gfx::Rect(source_width, source_height)); | 16313 gfx::Rect(source_width, source_height)); |
16222 dest_texture->ApplyFormatWorkarounds(feature_info_.get()); | 16314 dest_texture->ApplyFormatWorkarounds(feature_info_.get()); |
16223 } else { | 16315 } else { |
16224 texture_manager()->SetLevelCleared(dest_texture_ref, dest_target, 0, | 16316 texture_manager()->SetLevelCleared(dest_texture_ref, dest_target, 0, true); |
16225 true); | |
16226 } | 16317 } |
16227 | 16318 |
16228 // Try using GLImage::CopyTexImage when possible. | 16319 // Try using GLImage::CopyTexImage when possible. |
16229 bool unpack_premultiply_alpha_change = | 16320 bool unpack_premultiply_alpha_change = |
16230 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; | 16321 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; |
16231 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { | 16322 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { |
16232 glBindTexture(dest_target, dest_texture->service_id()); | 16323 glBindTexture(dest_target, dest_texture->service_id()); |
16233 if (image->CopyTexImage(dest_target)) | 16324 if (image->CopyTexImage(dest_target)) |
16234 return; | 16325 return; |
16235 } | 16326 } |
16236 | 16327 |
16237 DoCopyTexImageIfNeeded(source_texture, source_target); | 16328 DoCopyTexImageIfNeeded(source_texture, source_target); |
16238 | 16329 |
16239 // GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix | 16330 // GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix |
16240 // before presenting. | 16331 // before presenting. |
16241 if (source_target == GL_TEXTURE_EXTERNAL_OES) { | 16332 if (source_target == GL_TEXTURE_EXTERNAL_OES) { |
16242 if (GLStreamTextureImage* image = | 16333 if (GLStreamTextureImage* image = |
16243 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, | 16334 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, |
16244 0)) { | 16335 0)) { |
16245 GLfloat transform_matrix[16]; | 16336 GLfloat transform_matrix[16]; |
16246 image->GetTextureMatrix(transform_matrix); | 16337 image->GetTextureMatrix(transform_matrix); |
16247 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( | 16338 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
16248 this, source_target, source_texture->service_id(), dest_target, | 16339 this, source_target, source_texture->service_id(), |
16249 dest_texture->service_id(), source_width, source_height, | 16340 source_internal_format, dest_target, dest_texture->service_id(), |
16341 internal_format, source_width, source_height, | |
16250 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE, | 16342 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE, |
16251 unpack_unmultiply_alpha == GL_TRUE, transform_matrix); | 16343 unpack_unmultiply_alpha == GL_TRUE, transform_matrix); |
16252 return; | 16344 return; |
16253 } | 16345 } |
16254 } | 16346 } |
16347 | |
16255 copy_texture_CHROMIUM_->DoCopyTexture( | 16348 copy_texture_CHROMIUM_->DoCopyTexture( |
16256 this, source_target, source_texture->service_id(), source_internal_format, | 16349 this, source_target, source_texture->service_id(), source_internal_format, |
16257 dest_target, dest_texture->service_id(), internal_format, source_width, | 16350 dest_target, dest_texture->service_id(), internal_format, source_width, |
16258 source_height, unpack_flip_y == GL_TRUE, | 16351 source_height, unpack_flip_y == GL_TRUE, |
16259 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE); | 16352 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE, |
16353 method); | |
16260 } | 16354 } |
16261 | 16355 |
16262 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( | 16356 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
16263 GLuint source_id, | 16357 GLuint source_id, |
16264 GLuint dest_id, | 16358 GLuint dest_id, |
16265 GLint xoffset, | 16359 GLint xoffset, |
16266 GLint yoffset, | 16360 GLint yoffset, |
16267 GLint x, | 16361 GLint x, |
16268 GLint y, | 16362 GLint y, |
16269 GLsizei width, | 16363 GLsizei width, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16351 "destination texture is not defined"); | 16445 "destination texture is not defined"); |
16352 return; | 16446 return; |
16353 } | 16447 } |
16354 if (!dest_texture->ValidForTexture(dest_target, 0, xoffset, | 16448 if (!dest_texture->ValidForTexture(dest_target, 0, xoffset, |
16355 yoffset, 0, width, height, 1)) { | 16449 yoffset, 0, width, height, 1)) { |
16356 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, | 16450 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, |
16357 "destination texture bad dimensions."); | 16451 "destination texture bad dimensions."); |
16358 return; | 16452 return; |
16359 } | 16453 } |
16360 | 16454 |
16361 if (!ValidateCopyTextureCHROMIUMInternalFormats( | 16455 SupportedCopyMethodByFormat method = |
16362 kFunctionName, source_texture_ref, dest_internal_format)) { | 16456 ValidateCopyTextureCHROMIUMInternalFormats( |
16457 kFunctionName, source_texture_ref, dest_internal_format); | |
16458 if (NONE_COPY == method) { | |
16363 return; | 16459 return; |
Zhenyao Mo
2016/11/19 00:42:33
Can you add a comment here that an INVALID_OPERATI
qiankun
2016/11/21 16:01:50
Done.
| |
16364 } | 16460 } |
16365 | 16461 |
16462 if (feature_info_->feature_flags().desktop_srgb_support) { | |
16463 bool enable_framebuffer_srgb = | |
16464 GetColorEncodingFromInternalFormat(source_internal_format) == GL_SRGB || | |
16465 GetColorEncodingFromInternalFormat(dest_internal_format) == GL_SRGB; | |
16466 state_.EnableDisableFramebufferSRGB(enable_framebuffer_srgb); | |
16467 } | |
16468 | |
16366 // Clear the source texture if necessary. | 16469 // Clear the source texture if necessary. |
16367 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, | 16470 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, |
16368 source_target, 0)) { | 16471 source_target, 0)) { |
16369 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, | 16472 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, |
16370 "source texture dimensions too big"); | 16473 "source texture dimensions too big"); |
16371 return; | 16474 return; |
16372 } | 16475 } |
16373 | 16476 |
16374 if (!InitializeCopyTextureCHROMIUM(kFunctionName)) | 16477 if (!InitializeCopyTextureCHROMIUM(kFunctionName)) |
16375 return; | 16478 return; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16434 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE, | 16537 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE, |
16435 unpack_unmultiply_alpha == GL_TRUE, transform_matrix); | 16538 unpack_unmultiply_alpha == GL_TRUE, transform_matrix); |
16436 return; | 16539 return; |
16437 } | 16540 } |
16438 } | 16541 } |
16439 copy_texture_CHROMIUM_->DoCopySubTexture( | 16542 copy_texture_CHROMIUM_->DoCopySubTexture( |
16440 this, source_target, source_texture->service_id(), source_internal_format, | 16543 this, source_target, source_texture->service_id(), source_internal_format, |
16441 dest_target, dest_texture->service_id(), dest_internal_format, xoffset, | 16544 dest_target, dest_texture->service_id(), dest_internal_format, xoffset, |
16442 yoffset, x, y, width, height, dest_width, dest_height, source_width, | 16545 yoffset, x, y, width, height, dest_width, dest_height, source_width, |
16443 source_height, unpack_flip_y == GL_TRUE, | 16546 source_height, unpack_flip_y == GL_TRUE, |
16444 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE); | 16547 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE, |
16548 method); | |
16445 } | 16549 } |
16446 | 16550 |
16447 bool GLES2DecoderImpl::InitializeCopyTexImageBlitter( | 16551 bool GLES2DecoderImpl::InitializeCopyTexImageBlitter( |
16448 const char* function_name) { | 16552 const char* function_name) { |
16449 if (!copy_tex_image_blit_.get()) { | 16553 if (!copy_tex_image_blit_.get()) { |
16450 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); | 16554 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
16451 copy_tex_image_blit_.reset( | 16555 copy_tex_image_blit_.reset( |
16452 new CopyTexImageResourceManager(feature_info_.get())); | 16556 new CopyTexImageResourceManager(feature_info_.get())); |
16453 copy_tex_image_blit_->Initialize(this); | 16557 copy_tex_image_blit_->Initialize(this); |
16454 if (LOCAL_PEEK_GL_ERROR(function_name) != GL_NO_ERROR) | 16558 if (LOCAL_PEEK_GL_ERROR(function_name) != GL_NO_ERROR) |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16609 | 16713 |
16610 texture_manager()->SetLevelInfo( | 16714 texture_manager()->SetLevelInfo( |
16611 dest_texture_ref, dest_texture->target(), 0, GL_RGBA, source_width, | 16715 dest_texture_ref, dest_texture->target(), 0, GL_RGBA, source_width, |
16612 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 16716 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
16613 gfx::Rect(source_width, source_height)); | 16717 gfx::Rect(source_width, source_height)); |
16614 | 16718 |
16615 copy_texture_CHROMIUM_->DoCopyTexture( | 16719 copy_texture_CHROMIUM_->DoCopyTexture( |
16616 this, source_texture->target(), source_texture->service_id(), | 16720 this, source_texture->target(), source_texture->service_id(), |
16617 source_internal_format, dest_texture->target(), | 16721 source_internal_format, dest_texture->target(), |
16618 dest_texture->service_id(), GL_RGBA, source_width, source_height, false, | 16722 dest_texture->service_id(), GL_RGBA, source_width, source_height, false, |
16619 false, false); | 16723 false, false, DIRECT_DRAW); |
16620 } | 16724 } |
16621 | 16725 |
16622 void GLES2DecoderImpl::TexStorageImpl(GLenum target, | 16726 void GLES2DecoderImpl::TexStorageImpl(GLenum target, |
16623 GLsizei levels, | 16727 GLsizei levels, |
16624 GLenum internal_format, | 16728 GLenum internal_format, |
16625 GLsizei width, | 16729 GLsizei width, |
16626 GLsizei height, | 16730 GLsizei height, |
16627 GLsizei depth, | 16731 GLsizei depth, |
16628 ContextState::Dimension dimension, | 16732 ContextState::Dimension dimension, |
16629 const char* function_name) { | 16733 const char* function_name) { |
(...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18865 } | 18969 } |
18866 | 18970 |
18867 // Include the auto-generated part of this file. We split this because it means | 18971 // Include the auto-generated part of this file. We split this because it means |
18868 // we can easily edit the non-auto generated parts right here in this file | 18972 // we can easily edit the non-auto generated parts right here in this file |
18869 // instead of having to edit some template or the code generator. | 18973 // instead of having to edit some template or the code generator. |
18870 #include "base/macros.h" | 18974 #include "base/macros.h" |
18871 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 18975 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
18872 | 18976 |
18873 } // namespace gles2 | 18977 } // namespace gles2 |
18874 } // namespace gpu | 18978 } // namespace gpu |
OLD | NEW |