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