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 <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 DoCopyCompressedTextureCHROMIUM(GLenum target, | |
| 973 GLuint source_id, | |
| 974 GLuint dest_id, | |
| 975 GLenum internal_format, | |
| 976 GLenum dest_type, | |
| 977 GLsizei source_size); | |
| 978 | |
| 972 // Wrapper for TexStorage2DEXT. | 979 // Wrapper for TexStorage2DEXT. |
| 973 void DoTexStorage2DEXT( | 980 void DoTexStorage2DEXT( |
| 974 GLenum target, | 981 GLenum target, |
| 975 GLint levels, | 982 GLint levels, |
| 976 GLenum internal_format, | 983 GLenum internal_format, |
| 977 GLsizei width, | 984 GLsizei width, |
| 978 GLsizei height); | 985 GLsizei height); |
| 979 | 986 |
| 980 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); | 987 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
| 981 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, | 988 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1690 bool ValidateCompressedTexSubDimensions( | 1697 bool ValidateCompressedTexSubDimensions( |
| 1691 const char* function_name, | 1698 const char* function_name, |
| 1692 GLenum target, GLint level, GLint xoffset, GLint yoffset, | 1699 GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 1693 GLsizei width, GLsizei height, GLenum format, | 1700 GLsizei width, GLsizei height, GLenum format, |
| 1694 Texture* texture); | 1701 Texture* texture); |
| 1695 bool ValidateCopyTextureCHROMIUM(const char* function_name, | 1702 bool ValidateCopyTextureCHROMIUM(const char* function_name, |
| 1696 GLenum target, | 1703 GLenum target, |
| 1697 TextureRef* source_texture_ref, | 1704 TextureRef* source_texture_ref, |
| 1698 TextureRef* dest_texture_ref, | 1705 TextureRef* dest_texture_ref, |
| 1699 GLenum dest_internal_format); | 1706 GLenum dest_internal_format); |
| 1707 bool ValidateCopyCompressedTextureCHROMIUM(const char* function_name, | |
| 1708 GLenum target, | |
| 1709 TextureRef* source_texture_ref, | |
| 1710 TextureRef* dest_texture_ref, | |
| 1711 GLenum dest_internal_format); | |
| 1700 | 1712 |
| 1701 void RenderWarning(const char* filename, int line, const std::string& msg); | 1713 void RenderWarning(const char* filename, int line, const std::string& msg); |
| 1702 void PerformanceWarning( | 1714 void PerformanceWarning( |
| 1703 const char* filename, int line, const std::string& msg); | 1715 const char* filename, int line, const std::string& msg); |
| 1704 | 1716 |
| 1705 const FeatureInfo::FeatureFlags& features() const { | 1717 const FeatureInfo::FeatureFlags& features() const { |
| 1706 return feature_info_->feature_flags(); | 1718 return feature_info_->feature_flags(); |
| 1707 } | 1719 } |
| 1708 | 1720 |
| 1709 const FeatureInfo::Workarounds& workarounds() const { | 1721 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 || | 11528 source_internal_format == GL_LUMINANCE_ALPHA || |
| 11517 source_internal_format == GL_BGRA_EXT; | 11529 source_internal_format == GL_BGRA_EXT; |
| 11518 if (!valid_source_format || !valid_dest_format) { | 11530 if (!valid_source_format || !valid_dest_format) { |
| 11519 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | 11531 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 11520 "invalid internal format"); | 11532 "invalid internal format"); |
| 11521 return false; | 11533 return false; |
| 11522 } | 11534 } |
| 11523 return true; | 11535 return true; |
| 11524 } | 11536 } |
| 11525 | 11537 |
| 11538 bool GLES2DecoderImpl::ValidateCopyCompressedTextureCHROMIUM( | |
| 11539 const char* function_name, | |
| 11540 GLenum target, | |
| 11541 TextureRef* source_texture_ref, | |
| 11542 TextureRef* dest_texture_ref, | |
| 11543 GLenum dest_internal_format) { | |
| 11544 if (!source_texture_ref || !dest_texture_ref) { | |
| 11545 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); | |
| 11546 return false; | |
| 11547 } | |
| 11548 | |
| 11549 if (GL_TEXTURE_2D != target) { | |
| 11550 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, | |
| 11551 "invalid texture target"); | |
| 11552 return false; | |
| 11553 } | |
| 11554 | |
| 11555 Texture* source_texture = source_texture_ref->texture(); | |
| 11556 Texture* dest_texture = dest_texture_ref->texture(); | |
| 11557 if (source_texture == dest_texture) { | |
| 11558 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | |
| 11559 "source and destination textures are the same"); | |
| 11560 return false; | |
| 11561 } | |
| 11562 | |
| 11563 if (dest_texture->target() != GL_TEXTURE_2D || | |
| 11564 (source_texture->target() != GL_TEXTURE_2D && | |
| 11565 source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && | |
| 11566 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { | |
| 11567 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, | |
| 11568 "invalid texture target binding"); | |
| 11569 return false; | |
| 11570 } | |
| 11571 | |
| 11572 GLenum source_type = 0; | |
| 11573 GLenum source_internal_format = 0; | |
| 11574 source_texture->GetLevelType(source_texture->target(), 0, &source_type, | |
| 11575 &source_internal_format); | |
| 11576 | |
| 11577 if (dest_internal_format != source_internal_format) { | |
| 11578 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | |
| 11579 "source and destination formats doesn't match"); | |
| 11580 return false; | |
| 11581 } | |
| 11582 | |
| 11583 bool valid_format = | |
| 11584 dest_internal_format == GL_ATC_RGB_AMD || | |
| 11585 dest_internal_format == GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD || | |
| 11586 dest_internal_format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT || | |
| 11587 dest_internal_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT || | |
| 11588 dest_internal_format == GL_ETC1_RGB8_OES; | |
| 11589 | |
| 11590 if (!valid_format) { | |
| 11591 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, | |
| 11592 "invalid internal format"); | |
| 11593 return false; | |
| 11594 } | |
| 11595 | |
| 11596 return true; | |
| 11597 } | |
| 11598 | |
| 11526 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target, | 11599 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target, |
| 11527 GLuint source_id, | 11600 GLuint source_id, |
| 11528 GLuint dest_id, | 11601 GLuint dest_id, |
| 11529 GLenum internal_format, | 11602 GLenum internal_format, |
| 11530 GLenum dest_type) { | 11603 GLenum dest_type) { |
| 11531 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); | 11604 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); |
| 11532 | 11605 |
| 11533 TextureRef* source_texture_ref = GetTexture(source_id); | 11606 TextureRef* source_texture_ref = GetTexture(source_id); |
| 11534 TextureRef* dest_texture_ref = GetTexture(dest_id); | 11607 TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 11535 Texture* source_texture = source_texture_ref->texture(); | 11608 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(), | 11879 this, source_texture->target(), source_texture->service_id(), |
| 11807 source_internal_format, dest_texture->service_id(), | 11880 source_internal_format, dest_texture->service_id(), |
| 11808 dest_internal_format, xoffset, yoffset, dest_width, dest_height, | 11881 dest_internal_format, xoffset, yoffset, dest_width, dest_height, |
| 11809 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, | 11882 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, |
| 11810 unpack_unpremultiply_alpha_); | 11883 unpack_unpremultiply_alpha_); |
| 11811 } | 11884 } |
| 11812 | 11885 |
| 11813 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | 11886 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 11814 } | 11887 } |
| 11815 | 11888 |
| 11889 void GLES2DecoderImpl::DoCopyCompressedTextureCHROMIUM(GLenum target, | |
| 11890 GLuint source_id, | |
| 11891 GLuint dest_id, | |
| 11892 GLenum internal_format, | |
| 11893 GLenum dest_type, | |
| 11894 GLsizei source_size) { | |
| 11895 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyCompressedTextureCHROMIUM"); | |
| 11896 | |
| 11897 TextureRef* source_texture_ref = GetTexture(source_id); | |
| 11898 TextureRef* dest_texture_ref = GetTexture(dest_id); | |
| 11899 Texture* source_texture = source_texture_ref->texture(); | |
| 11900 Texture* dest_texture = dest_texture_ref->texture(); | |
| 11901 int source_width = 0; | |
| 11902 int source_height = 0; | |
| 11903 gfx::GLImage* image = | |
| 11904 source_texture->GetLevelImage(source_texture->target(), 0); | |
| 11905 if (image) { | |
| 11906 gfx::Size size = image->GetSize(); | |
| 11907 source_width = size.width(); | |
| 11908 source_height = size.height(); | |
| 11909 if (source_width <= 0 || source_height <= 0) { | |
| 11910 LOCAL_SET_GL_ERROR( | |
| 11911 GL_INVALID_VALUE, | |
| 11912 "glCopyCompressedTextureChromium", "invalid image size"); | |
| 11913 return; | |
| 11914 } | |
| 11915 } else { | |
| 11916 if (!source_texture->GetLevelSize( | |
| 11917 source_texture->target(), 0, &source_width, &source_height)) { | |
| 11918 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | |
| 11919 "glCopyCompressedTextureChromium", | |
| 11920 "source texture has no level 0"); | |
| 11921 return; | |
| 11922 } | |
| 11923 | |
| 11924 // Check that this type of texture is allowed. | |
| 11925 if (!texture_manager()->ValidForTarget(source_texture->target(), 0, | |
| 11926 source_width, source_height, 1)) { | |
| 11927 LOCAL_SET_GL_ERROR( | |
| 11928 GL_INVALID_VALUE, "glCopyCompressedTextureCHROMIUM", | |
| 11929 "Bad dimensions"); | |
| 11930 return; | |
| 11931 } | |
| 11932 } | |
| 11933 | |
| 11934 GLenum source_type = 0; | |
| 11935 GLenum source_internal_format = 0; | |
| 11936 source_texture->GetLevelType( | |
| 11937 source_texture->target(), 0, &source_type, &source_internal_format); | |
| 11938 | |
| 11939 if (dest_texture->IsImmutable()) { | |
| 11940 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, | |
| 11941 "glCopyCompressedTextureCHROMIUM", | |
| 11942 "texture is immutable"); | |
| 11943 return; | |
| 11944 } | |
| 11945 | |
| 11946 if (!ValidateCopyCompressedTextureCHROMIUM( | |
| 11947 "glCopyCompressedTextureCHROMIUM", | |
| 11948 target, | |
| 11949 source_texture_ref, dest_texture_ref, | |
| 11950 internal_format)) { | |
| 11951 return; | |
| 11952 } | |
| 11953 | |
| 11954 // Clear the source texture if necessary. | |
| 11955 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, | |
| 11956 source_texture->target(), 0)) { | |
| 11957 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyCompressedTextureCHROMIUM", | |
| 11958 "dimensions too big"); | |
| 11959 return; | |
| 11960 } | |
| 11961 | |
| 11962 GLenum dest_type_previous = dest_type; | |
| 11963 GLenum dest_internal_format = internal_format; | |
| 11964 int dest_width = 0; | |
| 11965 int dest_height = 0; | |
| 11966 bool dest_level_defined = | |
| 11967 dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height); | |
| 11968 | |
| 11969 if (dest_level_defined) { | |
| 11970 dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type_previous, | |
| 11971 &dest_internal_format); | |
| 11972 } | |
| 11973 | |
| 11974 // Resize the destination texture to the dimensions of the source texture. | |
| 11975 if (!dest_level_defined || dest_width != source_width || | |
| 11976 dest_height != source_height || | |
| 11977 dest_internal_format != internal_format || | |
| 11978 dest_type_previous != dest_type) { | |
| 11979 // Ensure that the glCompressedTexImage2D succeeds. | |
| 11980 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyCompressedTextureCHROMIUM"); | |
| 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); | |
| 11984 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyCompressedTextureCHROMIUM"); | |
| 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, dest_type, true); | |
| 11993 } else { | |
| 11994 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | |
| 11995 true); | |
|
piman
2015/05/28 20:34:27
We should only do that after we successfully fille
christiank
2015/06/05 12:53:31
Can I keep this code as is, now that I have update
| |
| 11996 } | |
| 11997 | |
| 11998 ScopedModifyPixels modify(dest_texture_ref); | |
| 11999 | |
| 12000 DCHECK(!unpack_flip_y_); | |
| 12001 DCHECK(!(unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_)); | |
|
piman
2015/05/28 20:34:27
These can't be DCHECKed, we can't trust the client
christiank
2015/06/05 12:53:31
Fixed.
| |
| 12002 | |
| 12003 // Try using GLImage::CopyTexImage when possible. | |
| 12004 if (image) { | |
| 12005 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | |
| 12006 if (image->CopyTexImage(GL_TEXTURE_2D)) | |
| 12007 return; | |
| 12008 } | |
| 12009 | |
| 12010 // As a fallback, read back the texture data and upload it again. | |
| 12011 if (!feature_info_->gl_version_info().is_es) { | |
|
reveman
2015/05/28 14:06:48
can you early out at the top of this function if t
christiank
2015/05/28 14:40:29
We still want to use GLImage::CopyTexImage on Open
reveman
2015/05/28 16:33:08
Ok, that's a problem. If a texture is backed by an
christiank
2015/06/01 12:14:16
It's rather important as Android is my primary dri
| |
| 12012 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | |
| 12013 | |
| 12014 scoped_ptr<GLbyte[]> image_data(new GLbyte[source_size]); | |
|
piman
2015/05/28 20:34:27
We can't trust source_size from the client. Instea
christiank
2015/06/05 12:53:31
I see. What's the best way of storing the byte siz
| |
| 12015 glBindTexture(GL_TEXTURE_2D, source_texture->service_id()); | |
| 12016 glGetCompressedTexImage(GL_TEXTURE_2D, 0, image_data.get()); | |
|
reveman
2015/05/28 14:06:49
can you add a TRACE_EVENT around this somehow? I u
christiank
2015/06/05 12:53:31
I added an event to trace both the inefficient glG
| |
| 12017 | |
| 12018 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); | |
| 12019 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
| 12020 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| 12021 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 12022 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
|
piman
2015/05/28 20:34:27
Why do we do these? I don't think they belong.
christiank
2015/06/05 12:53:31
We don't, you're right. Wrong thinking on my part.
| |
| 12023 | |
| 12024 glCompressedTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, | |
| 12025 source_height, 0, source_size, image_data.get()); | |
| 12026 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyCompressedTextureCHROMIUM"); | |
| 12027 if (error != GL_NO_ERROR) { | |
| 12028 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); | |
| 12029 return; | |
| 12030 } | |
| 12031 | |
| 12032 texture_manager()->SetLevelInfo( | |
| 12033 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, | |
| 12034 source_height, 1, 0, internal_format, dest_type, true); | |
| 12035 | |
| 12036 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | |
| 12037 } else { | |
| 12038 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopyCompressedTextureCHROMIUM", | |
| 12039 "platform doesn't support copying compressed textures"); | |
| 12040 } | |
| 12041 } | |
| 12042 | |
| 11816 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { | 12043 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
| 11817 switch (internalformat) { | 12044 switch (internalformat) { |
| 11818 case GL_RGB565: | 12045 case GL_RGB565: |
| 11819 return GL_UNSIGNED_SHORT_5_6_5; | 12046 return GL_UNSIGNED_SHORT_5_6_5; |
| 11820 case GL_RGBA4: | 12047 case GL_RGBA4: |
| 11821 return GL_UNSIGNED_SHORT_4_4_4_4; | 12048 return GL_UNSIGNED_SHORT_4_4_4_4; |
| 11822 case GL_RGB5_A1: | 12049 case GL_RGB5_A1: |
| 11823 return GL_UNSIGNED_SHORT_5_5_5_1; | 12050 return GL_UNSIGNED_SHORT_5_5_5_1; |
| 11824 case GL_RGB8_OES: | 12051 case GL_RGB8_OES: |
| 11825 return GL_UNSIGNED_BYTE; | 12052 return GL_UNSIGNED_BYTE; |
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12957 } | 13184 } |
| 12958 } | 13185 } |
| 12959 | 13186 |
| 12960 // Include the auto-generated part of this file. We split this because it means | 13187 // 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 | 13188 // 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. | 13189 // instead of having to edit some template or the code generator. |
| 12963 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 13190 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 12964 | 13191 |
| 12965 } // namespace gles2 | 13192 } // namespace gles2 |
| 12966 } // namespace gpu | 13193 } // namespace gpu |
| OLD | NEW |