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 <cmath> | 10 #include <cmath> |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
962 GLuint dest_id, | 962 GLuint dest_id, |
963 GLenum internal_format, | 963 GLenum internal_format, |
964 GLenum dest_type); | 964 GLenum dest_type); |
965 | 965 |
966 void DoCopySubTextureCHROMIUM(GLenum target, | 966 void DoCopySubTextureCHROMIUM(GLenum target, |
967 GLuint source_id, | 967 GLuint source_id, |
968 GLuint dest_id, | 968 GLuint dest_id, |
969 GLint xoffset, | 969 GLint xoffset, |
970 GLint yoffset); | 970 GLint yoffset); |
971 | 971 |
972 void DoCompressedCopyTextureCHROMIUM(GLenum target, | |
973 GLuint source_id, | |
974 GLuint dest_id, | |
975 GLenum internal_format, | |
976 GLsizei source_size); | |
977 | |
972 // Wrapper for TexStorage2DEXT. | 978 // Wrapper for TexStorage2DEXT. |
973 void DoTexStorage2DEXT( | 979 void DoTexStorage2DEXT( |
974 GLenum target, | 980 GLenum target, |
975 GLint levels, | 981 GLint levels, |
976 GLenum internal_format, | 982 GLenum internal_format, |
977 GLsizei width, | 983 GLsizei width, |
978 GLsizei height); | 984 GLsizei height); |
979 | 985 |
980 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); | 986 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
981 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, | 987 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1690 bool ValidateCompressedTexSubDimensions( | 1696 bool ValidateCompressedTexSubDimensions( |
1691 const char* function_name, | 1697 const char* function_name, |
1692 GLenum target, GLint level, GLint xoffset, GLint yoffset, | 1698 GLenum target, GLint level, GLint xoffset, GLint yoffset, |
1693 GLsizei width, GLsizei height, GLenum format, | 1699 GLsizei width, GLsizei height, GLenum format, |
1694 Texture* texture); | 1700 Texture* texture); |
1695 bool ValidateCopyTextureCHROMIUM(const char* function_name, | 1701 bool ValidateCopyTextureCHROMIUM(const char* function_name, |
1696 GLenum target, | 1702 GLenum target, |
1697 TextureRef* source_texture_ref, | 1703 TextureRef* source_texture_ref, |
1698 TextureRef* dest_texture_ref, | 1704 TextureRef* dest_texture_ref, |
1699 GLenum dest_internal_format); | 1705 GLenum dest_internal_format); |
1706 bool ValidateCompressedCopyTextureCHROMIUM(const char* function_name, | |
1707 GLenum target, | |
1708 TextureRef* source_texture_ref, | |
1709 TextureRef* dest_texture_ref, | |
1710 GLenum dest_internal_format); | |
1700 | 1711 |
1701 void RenderWarning(const char* filename, int line, const std::string& msg); | 1712 void RenderWarning(const char* filename, int line, const std::string& msg); |
1702 void PerformanceWarning( | 1713 void PerformanceWarning( |
1703 const char* filename, int line, const std::string& msg); | 1714 const char* filename, int line, const std::string& msg); |
1704 | 1715 |
1705 const FeatureInfo::FeatureFlags& features() const { | 1716 const FeatureInfo::FeatureFlags& features() const { |
1706 return feature_info_->feature_flags(); | 1717 return feature_info_->feature_flags(); |
1707 } | 1718 } |
1708 | 1719 |
1709 const FeatureInfo::Workarounds& workarounds() const { | 1720 const FeatureInfo::Workarounds& workarounds() const { |
(...skipping 9806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11516 source_internal_format == GL_LUMINANCE_ALPHA || | 11527 source_internal_format == GL_LUMINANCE_ALPHA || |
11517 source_internal_format == GL_BGRA_EXT; | 11528 source_internal_format == GL_BGRA_EXT; |
11518 if (!valid_source_format || !valid_dest_format) { | 11529 if (!valid_source_format || !valid_dest_format) { |
11519 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | 11530 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
11520 "invalid internal format"); | 11531 "invalid internal format"); |
11521 return false; | 11532 return false; |
11522 } | 11533 } |
11523 return true; | 11534 return true; |
11524 } | 11535 } |
11525 | 11536 |
11537 bool GLES2DecoderImpl::ValidateCompressedCopyTextureCHROMIUM( | |
11538 const char* function_name, | |
11539 GLenum target, | |
11540 TextureRef* source_texture_ref, | |
11541 TextureRef* dest_texture_ref, | |
11542 GLenum dest_internal_format) { | |
11543 if (!source_texture_ref || !dest_texture_ref) { | |
11544 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); | |
11545 return false; | |
11546 } | |
11547 | |
11548 if (GL_TEXTURE_2D != target) { | |
11549 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, | |
11550 "invalid texture target"); | |
11551 return false; | |
11552 } | |
11553 | |
11554 Texture* source_texture = source_texture_ref->texture(); | |
11555 Texture* dest_texture = dest_texture_ref->texture(); | |
11556 if (source_texture == dest_texture) { | |
11557 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | |
11558 "source and destination textures are the same"); | |
11559 return false; | |
11560 } | |
11561 | |
11562 if (dest_texture->target() != GL_TEXTURE_2D || | |
11563 (source_texture->target() != GL_TEXTURE_2D && | |
11564 source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && | |
11565 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { | |
11566 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, | |
11567 "invalid texture target binding"); | |
11568 return false; | |
11569 } | |
11570 | |
11571 GLenum source_type = 0; | |
11572 GLenum source_internal_format = 0; | |
11573 source_texture->GetLevelType(source_texture->target(), 0, &source_type, | |
11574 &source_internal_format); | |
11575 | |
11576 if (dest_internal_format != source_internal_format) { | |
11577 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | |
11578 "source and destination formats doesn't match"); | |
11579 return false; | |
11580 } | |
11581 | |
11582 bool valid_format = | |
11583 dest_internal_format == GL_ATC_RGB_AMD || | |
11584 dest_internal_format == GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD || | |
11585 dest_internal_format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT || | |
11586 dest_internal_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT || | |
11587 dest_internal_format == GL_ETC1_RGB8_OES; | |
11588 | |
11589 if (!valid_format) { | |
11590 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | |
11591 "invalid internal format"); | |
11592 return false; | |
11593 } | |
11594 | |
11595 return true; | |
11596 } | |
11597 | |
11526 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target, | 11598 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target, |
11527 GLuint source_id, | 11599 GLuint source_id, |
11528 GLuint dest_id, | 11600 GLuint dest_id, |
11529 GLenum internal_format, | 11601 GLenum internal_format, |
11530 GLenum dest_type) { | 11602 GLenum dest_type) { |
11531 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); | 11603 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); |
11532 | 11604 |
11533 TextureRef* source_texture_ref = GetTexture(source_id); | 11605 TextureRef* source_texture_ref = GetTexture(source_id); |
11534 TextureRef* dest_texture_ref = GetTexture(dest_id); | 11606 TextureRef* dest_texture_ref = GetTexture(dest_id); |
11535 Texture* source_texture = source_texture_ref->texture(); | 11607 Texture* source_texture = source_texture_ref->texture(); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11806 this, source_texture->target(), source_texture->service_id(), | 11878 this, source_texture->target(), source_texture->service_id(), |
11807 source_internal_format, dest_texture->service_id(), | 11879 source_internal_format, dest_texture->service_id(), |
11808 dest_internal_format, xoffset, yoffset, dest_width, dest_height, | 11880 dest_internal_format, xoffset, yoffset, dest_width, dest_height, |
11809 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, | 11881 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, |
11810 unpack_unpremultiply_alpha_); | 11882 unpack_unpremultiply_alpha_); |
11811 } | 11883 } |
11812 | 11884 |
11813 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | 11885 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
11814 } | 11886 } |
11815 | 11887 |
11888 void GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM(GLenum target, | |
11889 GLuint source_id, | |
11890 GLuint dest_id, | |
11891 GLenum internal_format, | |
11892 GLsizei source_size) { | |
11893 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DCompressedCopyTextureCHROMIUM"); | |
11894 | |
11895 TextureRef* source_texture_ref = GetTexture(source_id); | |
11896 TextureRef* dest_texture_ref = GetTexture(dest_id); | |
11897 Texture* source_texture = source_texture_ref->texture(); | |
11898 Texture* dest_texture = dest_texture_ref->texture(); | |
11899 int source_width = 0; | |
11900 int source_height = 0; | |
11901 gfx::GLImage* image = | |
11902 source_texture->GetLevelImage(source_texture->target(), 0); | |
11903 if (image) { | |
piman
2015/06/09 00:24:19
Do we need these 2 separate paths? Presumably the
christiank
2015/06/11 07:31:57
I think you might be right. However, CopyTextureCH
| |
11904 gfx::Size size = image->GetSize(); | |
11905 source_width = size.width(); | |
11906 source_height = size.height(); | |
11907 if (source_width <= 0 || source_height <= 0) { | |
11908 LOCAL_SET_GL_ERROR( | |
11909 GL_INVALID_VALUE, | |
11910 "glCompressedCopyTextureCHROMIUM", "invalid image size"); | |
11911 return; | |
11912 } | |
11913 } else { | |
11914 if (!source_texture->GetLevelSize( | |
11915 source_texture->target(), 0, &source_width, &source_height)) { | |
11916 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | |
11917 "glCompressedCopyTextureCHROMIUM", | |
11918 "source texture has no level 0"); | |
11919 return; | |
11920 } | |
11921 | |
11922 // Check that this type of texture is allowed. | |
11923 if (!texture_manager()->ValidForTarget(source_texture->target(), 0, | |
11924 source_width, source_height, 1)) { | |
piman
2015/06/09 00:24:19
Is this needed? The validity should have been test
christiank
2015/06/11 07:31:57
I don't think so. But same thing here, CopyTexture
| |
11925 LOCAL_SET_GL_ERROR( | |
11926 GL_INVALID_VALUE, "glCompressedCopyTextureCHROMIUM", | |
11927 "Bad dimensions"); | |
11928 return; | |
11929 } | |
11930 } | |
11931 | |
11932 GLenum source_type = 0; | |
11933 GLenum source_internal_format = 0; | |
11934 source_texture->GetLevelType( | |
11935 source_texture->target(), 0, &source_type, &source_internal_format); | |
11936 | |
11937 if (dest_texture->IsImmutable()) { | |
11938 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, | |
11939 "glCompressedCopyTextureCHROMIUM", | |
11940 "texture is immutable"); | |
11941 return; | |
11942 } | |
11943 | |
11944 if (!ValidateCompressedCopyTextureCHROMIUM( | |
11945 "glCompressedCopyTextureCHROMIUM", | |
11946 target, | |
11947 source_texture_ref, dest_texture_ref, | |
11948 internal_format)) { | |
11949 return; | |
11950 } | |
11951 | |
11952 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is | |
11953 // needed because it takes 10s of milliseconds to initialize. | |
11954 if (!copy_texture_CHROMIUM_.get()) { | |
11955 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); | |
11956 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); | |
11957 copy_texture_CHROMIUM_->Initialize(this); | |
11958 RestoreCurrentFramebufferBindings(); | |
11959 if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) | |
11960 return; | |
11961 } | |
11962 | |
11963 // Clear the source texture if necessary. | |
11964 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, | |
11965 source_texture->target(), 0)) { | |
11966 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCompressedCopyTextureCHROMIUM", | |
11967 "dimensions too big"); | |
11968 return; | |
11969 } | |
11970 | |
11971 int dest_width = 0; | |
11972 int dest_height = 0; | |
11973 bool dest_level_defined = | |
11974 dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height); | |
11975 | |
11976 // Resize the destination texture to the dimensions of the source texture. | |
11977 if (!dest_level_defined || dest_width != source_width || | |
11978 dest_height != source_height) { | |
piman
2015/06/09 00:24:19
What if it was defined, but not as a compressed te
christiank
2015/06/11 07:31:56
Done.
| |
11979 // Ensure that the glCompressedTexImage2D succeeds. | |
11980 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); | |
11981 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | |
11982 glCompressedTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, | |
11983 source_height, 0, source_size, NULL); | |
piman
2015/06/09 00:24:19
Really, this is only useful if we have an image. I
christiank
2015/06/11 07:31:56
Done.
| |
11984 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopyTextureCHROMIUM"); | |
11985 if (error != GL_NO_ERROR) { | |
11986 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); | |
11987 return; | |
11988 } | |
11989 | |
11990 texture_manager()->SetLevelInfo( | |
11991 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, | |
11992 source_height, 1, 0, internal_format, source_type, true); | |
11993 } else { | |
11994 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | |
11995 true); | |
11996 } | |
11997 | |
11998 ScopedModifyPixels modify(dest_texture_ref); | |
11999 | |
12000 bool unpack_premultiply_alpha_change = | |
12001 unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_; | |
12002 if (unpack_flip_y_ || unpack_premultiply_alpha_change) { | |
12003 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCompressedCopyTextureCHROMIUM", | |
12004 "pixel-storage multipliers are not supported"); | |
12005 } | |
12006 | |
12007 // Try using GLImage::CopyTexImage when possible. | |
12008 if (image) { | |
12009 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | |
12010 if (image->CopyTexImage(GL_TEXTURE_2D)) | |
12011 return; | |
12012 } | |
12013 | |
12014 TRACE_EVENT0( | |
12015 "gpu", | |
12016 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); | |
12017 | |
12018 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | |
12019 | |
12020 // As a fallback, copy into a non-compressed GL_RGBA texture. | |
12021 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); | |
12022 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | |
12023 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, source_width, source_height, | |
12024 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | |
12025 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopyTextureCHROMIUM"); | |
12026 if (error != GL_NO_ERROR) { | |
12027 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); | |
12028 return; | |
12029 } | |
12030 | |
12031 texture_manager()->SetLevelInfo( | |
12032 dest_texture_ref, GL_TEXTURE_2D, 0, GL_RGBA, source_width, | |
12033 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); | |
12034 | |
12035 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix | |
12036 // before presenting. | |
12037 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { | |
12038 // TODO(hkuang): get the StreamTexture transform matrix in GPU process | |
12039 // instead of using kIdentityMatrix crbug.com/226218. | |
12040 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( | |
12041 this, source_texture->target(), source_texture->service_id(), | |
12042 dest_texture->service_id(), source_width, source_height, | |
12043 unpack_flip_y_, unpack_premultiply_alpha_, | |
12044 unpack_unpremultiply_alpha_, kIdentityMatrix); | |
12045 } else { | |
12046 copy_texture_CHROMIUM_->DoCopyTexture( | |
12047 this, source_texture->target(), source_texture->service_id(), | |
12048 source_internal_format, dest_texture->service_id(), GL_RGBA, | |
12049 source_width, source_height, unpack_flip_y_, | |
12050 unpack_premultiply_alpha_, unpack_unpremultiply_alpha_); | |
12051 } | |
12052 | |
12053 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | |
12054 } | |
12055 | |
11816 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { | 12056 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
11817 switch (internalformat) { | 12057 switch (internalformat) { |
11818 case GL_RGB565: | 12058 case GL_RGB565: |
11819 return GL_UNSIGNED_SHORT_5_6_5; | 12059 return GL_UNSIGNED_SHORT_5_6_5; |
11820 case GL_RGBA4: | 12060 case GL_RGBA4: |
11821 return GL_UNSIGNED_SHORT_4_4_4_4; | 12061 return GL_UNSIGNED_SHORT_4_4_4_4; |
11822 case GL_RGB5_A1: | 12062 case GL_RGB5_A1: |
11823 return GL_UNSIGNED_SHORT_5_5_5_1; | 12063 return GL_UNSIGNED_SHORT_5_5_5_1; |
11824 case GL_RGB8_OES: | 12064 case GL_RGB8_OES: |
11825 return GL_UNSIGNED_BYTE; | 12065 return GL_UNSIGNED_BYTE; |
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12957 } | 13197 } |
12958 } | 13198 } |
12959 | 13199 |
12960 // Include the auto-generated part of this file. We split this because it means | 13200 // Include the auto-generated part of this file. We split this because it means |
12961 // we can easily edit the non-auto generated parts right here in this file | 13201 // we can easily edit the non-auto generated parts right here in this file |
12962 // instead of having to edit some template or the code generator. | 13202 // instead of having to edit some template or the code generator. |
12963 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 13203 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
12964 | 13204 |
12965 } // namespace gles2 | 13205 } // namespace gles2 |
12966 } // namespace gpu | 13206 } // namespace gpu |
OLD | NEW |