Chromium Code Reviews| 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 GLenum internal_format, |
| 943 GLint level, | 948 GLenum dest_type); |
| 944 GLenum internal_format, | 949 |
| 945 GLenum dest_type); | 950 void DoCopySubTextureCHROMIUM(GLenum target, |
| 951 GLuint source_id, | |
| 952 GLuint dest_id, | |
| 953 GLint xoffset, | |
| 954 GLint yoffset); | |
| 946 | 955 |
| 947 // Wrapper for TexStorage2DEXT. | 956 // Wrapper for TexStorage2DEXT. |
| 948 void DoTexStorage2DEXT( | 957 void DoTexStorage2DEXT( |
| 949 GLenum target, | 958 GLenum target, |
| 950 GLint levels, | 959 GLint levels, |
| 951 GLenum internal_format, | 960 GLenum internal_format, |
| 952 GLsizei width, | 961 GLsizei width, |
| 953 GLsizei height); | 962 GLsizei height); |
| 954 | 963 |
| 955 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); | 964 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1651 const char* function_name, | 1660 const char* function_name, |
| 1652 GLint level, GLsizei width, GLsizei height, GLenum format); | 1661 GLint level, GLsizei width, GLsizei height, GLenum format); |
| 1653 bool ValidateCompressedTexFuncData( | 1662 bool ValidateCompressedTexFuncData( |
| 1654 const char* function_name, | 1663 const char* function_name, |
| 1655 GLsizei width, GLsizei height, GLenum format, size_t size); | 1664 GLsizei width, GLsizei height, GLenum format, size_t size); |
| 1656 bool ValidateCompressedTexSubDimensions( | 1665 bool ValidateCompressedTexSubDimensions( |
| 1657 const char* function_name, | 1666 const char* function_name, |
| 1658 GLenum target, GLint level, GLint xoffset, GLint yoffset, | 1667 GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 1659 GLsizei width, GLsizei height, GLenum format, | 1668 GLsizei width, GLsizei height, GLenum format, |
| 1660 Texture* texture); | 1669 Texture* texture); |
| 1670 bool ValidateCopyTextureCHROMIUM(const char* function_name, | |
| 1671 GLenum target, | |
| 1672 TextureRef* source_texture_ref, | |
| 1673 TextureRef* dest_texture_ref, | |
| 1674 GLenum dest_internal_format); | |
| 1661 | 1675 |
| 1662 void RenderWarning(const char* filename, int line, const std::string& msg); | 1676 void RenderWarning(const char* filename, int line, const std::string& msg); |
| 1663 void PerformanceWarning( | 1677 void PerformanceWarning( |
| 1664 const char* filename, int line, const std::string& msg); | 1678 const char* filename, int line, const std::string& msg); |
| 1665 | 1679 |
| 1666 const FeatureInfo::FeatureFlags& features() const { | 1680 const FeatureInfo::FeatureFlags& features() const { |
| 1667 return feature_info_->feature_flags(); | 1681 return feature_info_->feature_flags(); |
| 1668 } | 1682 } |
| 1669 | 1683 |
| 1670 const FeatureInfo::Workarounds& workarounds() const { | 1684 const FeatureInfo::Workarounds& workarounds() const { |
| (...skipping 9257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10928 return GL_LUMINANCE_ALPHA; | 10942 return GL_LUMINANCE_ALPHA; |
| 10929 case GL_BGRA8_EXT: | 10943 case GL_BGRA8_EXT: |
| 10930 return GL_BGRA_EXT; | 10944 return GL_BGRA_EXT; |
| 10931 case GL_SRGB8_ALPHA8_EXT: | 10945 case GL_SRGB8_ALPHA8_EXT: |
| 10932 return GL_SRGB_ALPHA_EXT; | 10946 return GL_SRGB_ALPHA_EXT; |
| 10933 default: | 10947 default: |
| 10934 return GL_NONE; | 10948 return GL_NONE; |
| 10935 } | 10949 } |
| 10936 } | 10950 } |
| 10937 | 10951 |
| 10938 void GLES2DecoderImpl::DoCopyTextureCHROMIUM( | 10952 bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUM( |
| 10939 GLenum target, GLuint source_id, GLuint dest_id, GLint level, | 10953 const char* function_name, |
| 10940 GLenum internal_format, GLenum dest_type) { | 10954 GLenum target, |
| 10941 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); | 10955 TextureRef* source_texture_ref, |
| 10942 | 10956 TextureRef* dest_texture_ref, |
| 10943 TextureRef* dest_texture_ref = GetTexture(dest_id); | 10957 GLenum dest_internal_format) { |
| 10944 TextureRef* source_texture_ref = GetTexture(source_id); | |
| 10945 | |
| 10946 if (!source_texture_ref || !dest_texture_ref) { | 10958 if (!source_texture_ref || !dest_texture_ref) { |
| 10947 LOCAL_SET_GL_ERROR( | 10959 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); |
| 10948 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id"); | 10960 return false; |
| 10949 return; | |
| 10950 } | 10961 } |
| 10951 | 10962 |
| 10952 if (GL_TEXTURE_2D != target) { | 10963 if (GL_TEXTURE_2D != target) { |
| 10953 LOCAL_SET_GL_ERROR( | 10964 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
| 10954 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "invalid texture target"); | 10965 "invalid texture target"); |
| 10955 return; | 10966 return false; |
| 10956 } | 10967 } |
| 10957 | 10968 |
| 10958 Texture* source_texture = source_texture_ref->texture(); | 10969 Texture* source_texture = source_texture_ref->texture(); |
| 10959 Texture* dest_texture = dest_texture_ref->texture(); | 10970 Texture* dest_texture = dest_texture_ref->texture(); |
| 10971 if (source_texture == dest_texture) { | |
| 10972 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | |
| 10973 "source and destination textures are the same"); | |
| 10974 return false; | |
| 10975 } | |
| 10976 | |
| 10960 if (dest_texture->target() != GL_TEXTURE_2D || | 10977 if (dest_texture->target() != GL_TEXTURE_2D || |
| 10961 (source_texture->target() != GL_TEXTURE_2D && | 10978 (source_texture->target() != GL_TEXTURE_2D && |
| 10962 source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && | 10979 source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && |
| 10963 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { | 10980 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { |
| 10964 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | 10981 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
| 10965 "glCopyTextureCHROMIUM", | |
| 10966 "invalid texture target binding"); | 10982 "invalid texture target binding"); |
| 10967 return; | 10983 return false; |
| 10968 } | 10984 } |
| 10969 | 10985 |
| 10970 int source_width, source_height, dest_width, dest_height; | 10986 GLenum source_type = 0; |
| 10987 GLenum source_internal_format = 0; | |
| 10988 source_texture->GetLevelType(source_texture->target(), 0, &source_type, | |
| 10989 &source_internal_format); | |
| 10971 | 10990 |
| 10991 // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, | |
| 10992 // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not | |
| 10993 // renderable on some platforms. | |
| 10994 bool valid_dest_format = dest_internal_format == GL_RGB || | |
| 10995 dest_internal_format == GL_RGBA || | |
| 10996 dest_internal_format == GL_BGRA_EXT; | |
| 10997 bool valid_source_format = source_internal_format == GL_ALPHA || | |
| 10998 source_internal_format == GL_RGB || | |
| 10999 source_internal_format == GL_RGBA || | |
| 11000 source_internal_format == GL_LUMINANCE || | |
| 11001 source_internal_format == GL_LUMINANCE_ALPHA || | |
| 11002 source_internal_format == GL_BGRA_EXT; | |
| 11003 if (!valid_source_format || !valid_dest_format) { | |
| 11004 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | |
| 11005 "invalid internal format"); | |
| 11006 return false; | |
| 11007 } | |
| 11008 return true; | |
| 11009 } | |
| 11010 | |
| 11011 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target, | |
| 11012 GLuint source_id, | |
| 11013 GLuint dest_id, | |
| 11014 GLenum internal_format, | |
| 11015 GLenum dest_type) { | |
| 11016 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); | |
| 11017 | |
| 11018 TextureRef* source_texture_ref = GetTexture(source_id); | |
| 11019 TextureRef* dest_texture_ref = GetTexture(dest_id); | |
| 11020 Texture* source_texture = source_texture_ref->texture(); | |
| 11021 Texture* dest_texture = dest_texture_ref->texture(); | |
| 11022 int source_width = 0; | |
| 11023 int source_height = 0; | |
| 10972 gfx::GLImage* image = | 11024 gfx::GLImage* image = |
| 10973 source_texture->GetLevelImage(source_texture->target(), 0); | 11025 source_texture->GetLevelImage(source_texture->target(), 0); |
| 10974 if (image) { | 11026 if (image) { |
| 10975 gfx::Size size = image->GetSize(); | 11027 gfx::Size size = image->GetSize(); |
| 10976 source_width = size.width(); | 11028 source_width = size.width(); |
| 10977 source_height = size.height(); | 11029 source_height = size.height(); |
| 10978 if (source_width <= 0 || source_height <= 0) { | 11030 if (source_width <= 0 || source_height <= 0) { |
| 10979 LOCAL_SET_GL_ERROR( | 11031 LOCAL_SET_GL_ERROR( |
| 10980 GL_INVALID_VALUE, | 11032 GL_INVALID_VALUE, |
| 10981 "glCopyTextureChromium", "invalid image size"); | 11033 "glCopyTextureChromium", "invalid image size"); |
| 10982 return; | 11034 return; |
| 10983 } | 11035 } |
| 10984 } else { | 11036 } else { |
| 10985 if (!source_texture->GetLevelSize( | 11037 if (!source_texture->GetLevelSize( |
| 10986 source_texture->target(), 0, &source_width, &source_height)) { | 11038 source_texture->target(), 0, &source_width, &source_height)) { |
| 10987 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | 11039 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 10988 "glCopyTextureChromium", | 11040 "glCopyTextureChromium", |
| 10989 "source texture has no level 0"); | 11041 "source texture has no level 0"); |
| 10990 return; | 11042 return; |
| 10991 } | 11043 } |
| 10992 | 11044 |
| 10993 // Check that this type of texture is allowed. | 11045 // Check that this type of texture is allowed. |
| 10994 if (!texture_manager()->ValidForTarget( | 11046 if (!texture_manager()->ValidForTarget(source_texture->target(), 0, |
| 10995 source_texture->target(), level, source_width, source_height, 1)) { | 11047 source_width, source_height, 1)) { |
| 10996 LOCAL_SET_GL_ERROR( | 11048 LOCAL_SET_GL_ERROR( |
| 10997 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); | 11049 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); |
| 10998 return; | 11050 return; |
| 10999 } | 11051 } |
| 11000 } | 11052 } |
| 11001 | 11053 |
| 11002 // Clear the source texture if necessary. | |
| 11003 if (!texture_manager()->ClearTextureLevel( | |
| 11004 this, source_texture_ref, source_texture->target(), 0)) { | |
| 11005 LOCAL_SET_GL_ERROR( | |
| 11006 GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", "dimensions too big"); | |
| 11007 return; | |
| 11008 } | |
| 11009 | |
| 11010 GLenum source_type = 0; | 11054 GLenum source_type = 0; |
| 11011 GLenum source_internal_format = 0; | 11055 GLenum source_internal_format = 0; |
| 11012 source_texture->GetLevelType( | 11056 source_texture->GetLevelType( |
| 11013 source_texture->target(), 0, &source_type, &source_internal_format); | 11057 source_texture->target(), 0, &source_type, &source_internal_format); |
| 11014 | 11058 |
| 11015 // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, | 11059 if (dest_texture->IsImmutable()) { |
| 11016 // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not | 11060 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopyTextureCHROMIUM", |
| 11017 // renderable on some platforms. | 11061 "texture is immutable"); |
| 11018 bool valid_dest_format = internal_format == GL_RGB || | |
| 11019 internal_format == GL_RGBA || | |
| 11020 internal_format == GL_BGRA_EXT; | |
| 11021 bool valid_source_format = source_internal_format == GL_ALPHA || | |
| 11022 source_internal_format == GL_RGB || | |
| 11023 source_internal_format == GL_RGBA || | |
| 11024 source_internal_format == GL_LUMINANCE || | |
| 11025 source_internal_format == GL_LUMINANCE_ALPHA || | |
| 11026 source_internal_format == GL_BGRA_EXT; | |
| 11027 if (!valid_source_format || !valid_dest_format) { | |
| 11028 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, | |
| 11029 "glCopyTextureCHROMIUM", | |
| 11030 "invalid internal format"); | |
| 11031 return; | 11062 return; |
| 11032 } | 11063 } |
| 11033 | 11064 |
| 11065 if (!ValidateCopyTextureCHROMIUM("glCopyTextureCHROMIUM", target, | |
| 11066 source_texture_ref, dest_texture_ref, | |
| 11067 internal_format)) { | |
| 11068 return; | |
| 11069 } | |
| 11070 | |
| 11071 // Clear the source texture if necessary. | |
| 11072 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, | |
| 11073 source_texture->target(), 0)) { | |
| 11074 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", | |
| 11075 "dimensions too big"); | |
| 11076 return; | |
| 11077 } | |
| 11078 | |
| 11034 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is | 11079 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 11035 // needed because it takes 10s of milliseconds to initialize. | 11080 // needed because it takes 10s of milliseconds to initialize. |
| 11036 if (!copy_texture_CHROMIUM_.get()) { | 11081 if (!copy_texture_CHROMIUM_.get()) { |
| 11037 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); | 11082 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
| 11038 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); | 11083 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
| 11039 copy_texture_CHROMIUM_->Initialize(this); | 11084 copy_texture_CHROMIUM_->Initialize(this); |
| 11040 RestoreCurrentFramebufferBindings(); | 11085 RestoreCurrentFramebufferBindings(); |
| 11041 if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) | 11086 if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) |
| 11042 return; | 11087 return; |
| 11043 } | 11088 } |
| 11044 | 11089 |
| 11045 GLenum dest_type_previous = dest_type; | 11090 GLenum dest_type_previous = dest_type; |
| 11046 GLenum dest_internal_format = internal_format; | 11091 GLenum dest_internal_format = internal_format; |
| 11047 bool dest_level_defined = dest_texture->GetLevelSize( | 11092 int dest_width = 0; |
| 11048 GL_TEXTURE_2D, level, &dest_width, &dest_height); | 11093 int dest_height = 0; |
| 11094 bool dest_level_defined = | |
| 11095 dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height); | |
| 11049 | 11096 |
| 11050 if (dest_level_defined) { | 11097 if (dest_level_defined) { |
| 11051 dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous, | 11098 dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type_previous, |
| 11052 &dest_internal_format); | 11099 &dest_internal_format); |
| 11053 } | 11100 } |
| 11054 | 11101 |
| 11055 // Resize the destination texture to the dimensions of the source texture. | 11102 // Resize the destination texture to the dimensions of the source texture. |
| 11056 if (!dest_level_defined || dest_width != source_width || | 11103 if (!dest_level_defined || dest_width != source_width || |
| 11057 dest_height != source_height || | 11104 dest_height != source_height || |
| 11058 dest_internal_format != internal_format || | 11105 dest_internal_format != internal_format || |
| 11059 dest_type_previous != dest_type) { | 11106 dest_type_previous != dest_type) { |
| 11060 // Ensure that the glTexImage2D succeeds. | 11107 // Ensure that the glTexImage2D succeeds. |
| 11061 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); | 11108 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
| 11062 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | 11109 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
| 11063 glTexImage2D( | 11110 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, source_height, |
| 11064 GL_TEXTURE_2D, level, internal_format, source_width, source_height, | 11111 0, internal_format, dest_type, NULL); |
| 11065 0, internal_format, dest_type, NULL); | |
| 11066 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); | 11112 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); |
| 11067 if (error != GL_NO_ERROR) { | 11113 if (error != GL_NO_ERROR) { |
| 11068 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); | 11114 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
| 11069 return; | 11115 return; |
| 11070 } | 11116 } |
| 11071 | 11117 |
| 11072 texture_manager()->SetLevelInfo( | 11118 texture_manager()->SetLevelInfo( |
| 11073 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, | 11119 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, |
| 11074 source_height, 1, 0, internal_format, dest_type, true); | 11120 source_height, 1, 0, internal_format, dest_type, true); |
| 11075 } else { | 11121 } else { |
| 11076 texture_manager()->SetLevelCleared( | 11122 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
| 11077 dest_texture_ref, GL_TEXTURE_2D, level, true); | 11123 true); |
| 11078 } | 11124 } |
| 11079 | 11125 |
| 11080 ScopedModifyPixels modify(dest_texture_ref); | 11126 ScopedModifyPixels modify(dest_texture_ref); |
| 11081 | 11127 |
| 11082 // Try using GLImage::CopyTexImage when possible. | 11128 // Try using GLImage::CopyTexSubImage when possible. |
| 11083 bool unpack_premultiply_alpha_change = | 11129 bool unpack_premultiply_alpha_change = |
| 11084 unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_; | 11130 unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_; |
| 11085 if (image && !unpack_flip_y_ && !unpack_premultiply_alpha_change && !level) { | 11131 if (image && !unpack_flip_y_ && !unpack_premultiply_alpha_change) { |
| 11086 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | 11132 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
| 11087 if (image->CopyTexImage(GL_TEXTURE_2D)) | 11133 if (image->CopyTexSubImage(GL_TEXTURE_2D, 0, 0)) |
|
dshwang
2015/03/04 09:35:42
we can use CopyTexSubImage in CopyTextureCHROMIUM
| |
| 11088 return; | 11134 return; |
| 11089 } | 11135 } |
| 11090 | 11136 |
| 11091 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | 11137 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 11092 | 11138 |
| 11093 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix | 11139 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
| 11094 // before presenting. | 11140 // before presenting. |
| 11095 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { | 11141 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
| 11096 // TODO(hkuang): get the StreamTexture transform matrix in GPU process | 11142 // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
| 11097 // instead of using default matrix crbug.com/226218. | 11143 // instead of using kIdentityMatrix crbug.com/226218. |
| 11098 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, | |
| 11099 0.0f, 1.0f, 0.0f, 0.0f, | |
| 11100 0.0f, 0.0f, 1.0f, 0.0f, | |
| 11101 0.0f, 0.0f, 0.0f, 1.0f}; | |
| 11102 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( | 11144 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
| 11103 this, | 11145 this, source_texture->target(), source_texture->service_id(), |
| 11104 source_texture->target(), | 11146 dest_texture->service_id(), source_width, source_height, unpack_flip_y_, |
| 11105 source_texture->service_id(), | 11147 unpack_premultiply_alpha_, unpack_unpremultiply_alpha_, |
| 11106 dest_texture->service_id(), | 11148 kIdentityMatrix); |
| 11107 level, | |
| 11108 source_width, | |
| 11109 source_height, | |
| 11110 unpack_flip_y_, | |
| 11111 unpack_premultiply_alpha_, | |
| 11112 unpack_unpremultiply_alpha_, | |
| 11113 default_matrix); | |
| 11114 } else { | 11149 } else { |
| 11115 copy_texture_CHROMIUM_->DoCopyTexture(this, | 11150 copy_texture_CHROMIUM_->DoCopyTexture( |
| 11116 source_texture->target(), | 11151 this, source_texture->target(), source_texture->service_id(), |
| 11117 source_texture->service_id(), | 11152 source_internal_format, dest_texture->service_id(), internal_format, |
| 11118 source_internal_format, | 11153 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, |
| 11119 dest_texture->service_id(), | 11154 unpack_unpremultiply_alpha_); |
| 11120 level, | |
| 11121 internal_format, | |
| 11122 source_width, | |
| 11123 source_height, | |
| 11124 unpack_flip_y_, | |
| 11125 unpack_premultiply_alpha_, | |
| 11126 unpack_unpremultiply_alpha_); | |
| 11127 } | 11155 } |
| 11128 | 11156 |
| 11129 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | 11157 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 11158 } | |
| 11159 | |
| 11160 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(GLenum target, | |
| 11161 GLuint source_id, | |
| 11162 GLuint dest_id, | |
| 11163 GLint xoffset, | |
| 11164 GLint yoffset) { | |
| 11165 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopySubTextureCHROMIUM"); | |
| 11166 | |
| 11167 TextureRef* source_texture_ref = GetTexture(source_id); | |
| 11168 TextureRef* dest_texture_ref = GetTexture(dest_id); | |
| 11169 Texture* source_texture = source_texture_ref->texture(); | |
| 11170 Texture* dest_texture = dest_texture_ref->texture(); | |
| 11171 int source_width = 0; | |
| 11172 int source_height = 0; | |
| 11173 gfx::GLImage* image = | |
| 11174 source_texture->GetLevelImage(source_texture->target(), 0); | |
| 11175 if (image) { | |
| 11176 gfx::Size size = image->GetSize(); | |
| 11177 source_width = size.width(); | |
| 11178 source_height = size.height(); | |
| 11179 if (source_width <= 0 || source_height <= 0) { | |
| 11180 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", | |
| 11181 "invalid image size"); | |
| 11182 return; | |
| 11183 } | |
| 11184 } else { | |
| 11185 if (!source_texture->GetLevelSize(source_texture->target(), 0, | |
| 11186 &source_width, &source_height)) { | |
| 11187 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", | |
| 11188 "source texture has no level 0"); | |
| 11189 return; | |
| 11190 } | |
| 11191 | |
| 11192 // Check that this type of texture is allowed. | |
| 11193 if (!texture_manager()->ValidForTarget(source_texture->target(), 0, | |
| 11194 source_width, source_height, 1)) { | |
| 11195 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", | |
| 11196 "source texture bad dimensions"); | |
| 11197 return; | |
| 11198 } | |
| 11199 } | |
| 11200 | |
| 11201 GLenum source_type = 0; | |
| 11202 GLenum source_internal_format = 0; | |
| 11203 source_texture->GetLevelType(source_texture->target(), 0, &source_type, | |
| 11204 &source_internal_format); | |
| 11205 GLenum dest_type = 0; | |
| 11206 GLenum dest_internal_format = 0; | |
| 11207 bool dest_level_defined = dest_texture->GetLevelType( | |
| 11208 dest_texture->target(), 0, &dest_type, &dest_internal_format); | |
| 11209 if (!dest_level_defined) { | |
| 11210 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopySubTextureCHROMIUM", | |
| 11211 "destination texture is not defined"); | |
| 11212 return; | |
| 11213 } | |
| 11214 if (!dest_texture->ValidForTexture(dest_texture->target(), 0, xoffset, | |
| 11215 yoffset, source_width, source_height, | |
| 11216 dest_type)) { | |
| 11217 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", | |
| 11218 "destination texture bad dimensions."); | |
| 11219 return; | |
| 11220 } | |
| 11221 | |
| 11222 if (!ValidateCopyTextureCHROMIUM("glCopySubTextureCHROMIUM", target, | |
| 11223 source_texture_ref, dest_texture_ref, | |
| 11224 dest_internal_format)) { | |
| 11225 return; | |
| 11226 } | |
| 11227 | |
| 11228 // Clear the source texture if necessary. | |
| 11229 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, | |
| 11230 source_texture->target(), 0)) { | |
| 11231 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM", | |
| 11232 "source texture dimensions too big"); | |
| 11233 return; | |
| 11234 } | |
| 11235 | |
| 11236 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is | |
| 11237 // needed because it takes 10s of milliseconds to initialize. | |
| 11238 if (!copy_texture_CHROMIUM_.get()) { | |
| 11239 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopySubTextureCHROMIUM"); | |
| 11240 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); | |
| 11241 copy_texture_CHROMIUM_->Initialize(this); | |
| 11242 RestoreCurrentFramebufferBindings(); | |
| 11243 if (LOCAL_PEEK_GL_ERROR("glCopySubTextureCHROMIUM") != GL_NO_ERROR) | |
| 11244 return; | |
| 11245 } | |
| 11246 | |
| 11247 int dest_width = 0; | |
| 11248 int dest_height = 0; | |
| 11249 bool ok = | |
| 11250 dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height); | |
| 11251 DCHECK(ok); | |
| 11252 if (xoffset != 0 || yoffset != 0 || source_width != dest_width || | |
| 11253 source_height != dest_height) { | |
| 11254 if (!texture_manager()->ClearTextureLevel(this, dest_texture_ref, target, | |
| 11255 0)) { | |
| 11256 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM", | |
| 11257 "destination texture dimensions too big"); | |
| 11258 return; | |
| 11259 } | |
| 11260 } else { | |
| 11261 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | |
| 11262 true); | |
| 11263 } | |
| 11264 | |
| 11265 ScopedModifyPixels modify(dest_texture_ref); | |
| 11266 | |
| 11267 // Try using GLImage::CopyTexSubImage when possible. | |
| 11268 bool unpack_premultiply_alpha_change = | |
| 11269 unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_; | |
| 11270 if (image && !unpack_flip_y_ && !unpack_premultiply_alpha_change) { | |
| 11271 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | |
| 11272 if (image->CopyTexSubImage(GL_TEXTURE_2D, xoffset, yoffset)) | |
|
dshwang
2015/03/04 09:35:42
reverted patch hits one-copy performance badly bec
| |
| 11273 return; | |
| 11274 } | |
| 11275 | |
| 11276 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | |
| 11277 | |
| 11278 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix | |
| 11279 // before presenting. | |
| 11280 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { | |
| 11281 // TODO(hkuang): get the StreamTexture transform matrix in GPU process | |
| 11282 // instead of using kIdentityMatrix crbug.com/226218. | |
| 11283 copy_texture_CHROMIUM_->DoCopySubTextureWithTransform( | |
| 11284 this, source_texture->target(), source_texture->service_id(), | |
| 11285 dest_texture->service_id(), xoffset, yoffset, dest_width, dest_height, | |
| 11286 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, | |
| 11287 unpack_unpremultiply_alpha_, kIdentityMatrix); | |
| 11288 } else { | |
| 11289 copy_texture_CHROMIUM_->DoCopySubTexture( | |
| 11290 this, source_texture->target(), source_texture->service_id(), | |
| 11291 source_internal_format, dest_texture->service_id(), | |
| 11292 dest_internal_format, xoffset, yoffset, dest_width, dest_height, | |
| 11293 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, | |
| 11294 unpack_unpremultiply_alpha_); | |
| 11295 } | |
| 11296 | |
| 11297 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | |
| 11130 } | 11298 } |
| 11131 | 11299 |
| 11132 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { | 11300 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
| 11133 switch (internalformat) { | 11301 switch (internalformat) { |
| 11134 case GL_RGB565: | 11302 case GL_RGB565: |
| 11135 return GL_UNSIGNED_SHORT_5_6_5; | 11303 return GL_UNSIGNED_SHORT_5_6_5; |
| 11136 case GL_RGBA4: | 11304 case GL_RGBA4: |
| 11137 return GL_UNSIGNED_SHORT_4_4_4_4; | 11305 return GL_UNSIGNED_SHORT_4_4_4_4; |
| 11138 case GL_RGB5_A1: | 11306 case GL_RGB5_A1: |
| 11139 return GL_UNSIGNED_SHORT_5_5_5_1; | 11307 return GL_UNSIGNED_SHORT_5_5_5_1; |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11721 DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || | 11889 DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || |
| 11722 matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); | 11890 matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); |
| 11723 | 11891 |
| 11724 if (!features().chromium_path_rendering) { | 11892 if (!features().chromium_path_rendering) { |
| 11725 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, | 11893 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 11726 "glMatrixLoadIdentityCHROMIUM", | 11894 "glMatrixLoadIdentityCHROMIUM", |
| 11727 "function not available"); | 11895 "function not available"); |
| 11728 return; | 11896 return; |
| 11729 } | 11897 } |
| 11730 | 11898 |
| 11731 static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, | |
| 11732 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, | |
| 11733 0.0f, 0.0f, 0.0f, 1.0f}; | |
| 11734 | |
| 11735 GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM | 11899 GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM |
| 11736 ? state_.projection_matrix | 11900 ? state_.projection_matrix |
| 11737 : state_.modelview_matrix; | 11901 : state_.modelview_matrix; |
| 11738 memcpy(target_matrix, kIdentityMatrix, sizeof(kIdentityMatrix)); | 11902 memcpy(target_matrix, kIdentityMatrix, sizeof(kIdentityMatrix)); |
| 11739 // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV | 11903 // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV |
| 11740 // since the values of the _NV and _CHROMIUM tokens match. | 11904 // since the values of the _NV and _CHROMIUM tokens match. |
| 11741 glMatrixLoadIdentityEXT(matrix_mode); | 11905 glMatrixLoadIdentityEXT(matrix_mode); |
| 11742 } | 11906 } |
| 11743 | 11907 |
| 11744 bool GLES2DecoderImpl::ValidateAsyncTransfer( | 11908 bool GLES2DecoderImpl::ValidateAsyncTransfer( |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12127 } | 12291 } |
| 12128 } | 12292 } |
| 12129 | 12293 |
| 12130 // Include the auto-generated part of this file. We split this because it means | 12294 // Include the auto-generated part of this file. We split this because it means |
| 12131 // we can easily edit the non-auto generated parts right here in this file | 12295 // we can easily edit the non-auto generated parts right here in this file |
| 12132 // instead of having to edit some template or the code generator. | 12296 // instead of having to edit some template or the code generator. |
| 12133 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 12297 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 12134 | 12298 |
| 12135 } // namespace gles2 | 12299 } // namespace gles2 |
| 12136 } // namespace gpu | 12300 } // namespace gpu |
| OLD | NEW |