Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 1119723003: Add glCopyCompressedTextureCHROMIUM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 bool valid_dest_format =
11578 dest_internal_format == GL_ATC_RGB_AMD ||
11579 dest_internal_format == GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD ||
11580 dest_internal_format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
11581 dest_internal_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ||
11582 dest_internal_format == GL_ETC1_RGB8_OES;
11583 bool valid_source_format = source_internal_format == GL_ALPHA ||
11584 source_internal_format == GL_RGB ||
11585 source_internal_format == GL_RGBA ||
11586 source_internal_format == GL_LUMINANCE ||
11587 source_internal_format == GL_LUMINANCE_ALPHA ||
11588 source_internal_format == GL_BGRA_EXT;
reveman 2015/04/30 13:36:14 hm, doesn't source format have to match destinatio
christiank 2015/05/05 13:42:22 Conceptually, maybe it should. However, it appears
reveman 2015/05/05 16:12:09 This changed recently, CreateImageCHROMIUM now nee
christiank 2015/05/07 12:47:00 Ah, you're right. My Chromium revision was a littl
reveman 2015/05/07 18:35:49 It used to be that GL_RGBA was the only supported
christiank 2015/05/08 13:04:23 Sure, I'll address it in a separate patch.
christiank 2015/05/12 11:08:58 I have now fixed the format validation.
11589 if (!valid_source_format || !valid_dest_format) {
11590 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
11591 "invalid internal format");
11592 return false;
11593 }
11594 return true;
11595 }
11596
11526 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target, 11597 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target,
11527 GLuint source_id, 11598 GLuint source_id,
11528 GLuint dest_id, 11599 GLuint dest_id,
11529 GLenum internal_format, 11600 GLenum internal_format,
11530 GLenum dest_type) { 11601 GLenum dest_type) {
11531 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); 11602 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM");
11532 11603
11533 TextureRef* source_texture_ref = GetTexture(source_id); 11604 TextureRef* source_texture_ref = GetTexture(source_id);
11534 TextureRef* dest_texture_ref = GetTexture(dest_id); 11605 TextureRef* dest_texture_ref = GetTexture(dest_id);
11535 Texture* source_texture = source_texture_ref->texture(); 11606 Texture* source_texture = source_texture_ref->texture();
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
11806 this, source_texture->target(), source_texture->service_id(), 11877 this, source_texture->target(), source_texture->service_id(),
11807 source_internal_format, dest_texture->service_id(), 11878 source_internal_format, dest_texture->service_id(),
11808 dest_internal_format, xoffset, yoffset, dest_width, dest_height, 11879 dest_internal_format, xoffset, yoffset, dest_width, dest_height,
11809 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, 11880 source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_,
11810 unpack_unpremultiply_alpha_); 11881 unpack_unpremultiply_alpha_);
11811 } 11882 }
11812 11883
11813 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); 11884 DoDidUseTexImageIfNeeded(source_texture, source_texture->target());
11814 } 11885 }
11815 11886
11887 void GLES2DecoderImpl::DoCopyCompressedTextureCHROMIUM(GLenum target,
11888 GLuint source_id,
11889 GLuint dest_id,
11890 GLenum internal_format,
11891 GLenum dest_type,
11892 GLsizei source_size) {
11893 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyCompressedTextureCHROMIUM");
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 gfx::GLImage* image =
11900 source_texture->GetLevelImage(source_texture->target(), 0);
11901 if (!image) {
11902 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopyCompressedTextureCHROMIUM",
11903 "no mage");
11904 return;
11905 }
11906
11907 gfx::Size size = image->GetSize();
11908 int source_width = size.width();
11909 int source_height = size.height();
11910 if (source_width <= 0 || source_height <= 0) {
11911 LOCAL_SET_GL_ERROR(
11912 GL_INVALID_VALUE,
11913 "glCopyCompressedTextureCHROMIUM", "invalid image size");
11914 return;
11915 }
11916
11917 GLenum source_type = 0;
11918 GLenum source_internal_format = 0;
11919 source_texture->GetLevelType(
11920 source_texture->target(), 0, &source_type, &source_internal_format);
11921
11922 if (dest_texture->IsImmutable()) {
11923 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION,
11924 "glCopyCompressedTextureCHROMIUM",
11925 "texture is immutable");
11926 return;
11927 }
11928
11929 if (!ValidateCopyCompressedTextureCHROMIUM(
11930 "glCopyCompressedTextureCHROMIUM",
11931 target,
11932 source_texture_ref, dest_texture_ref,
11933 internal_format)) {
11934 return;
11935 }
11936
11937 // Clear the source texture if necessary.
11938 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
11939 source_texture->target(), 0)) {
11940 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyCompressedTextureCHROMIUM",
11941 "dimensions too big");
11942 return;
11943 }
11944
11945 GLenum dest_type_previous = dest_type;
11946 GLenum dest_internal_format = internal_format;
11947 int dest_width = 0;
11948 int dest_height = 0;
11949 bool dest_level_defined =
11950 dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height);
11951
11952 if (dest_level_defined) {
11953 dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type_previous,
11954 &dest_internal_format);
11955 }
11956
11957 // Resize the destination texture to the dimensions of the source texture.
11958 if (!dest_level_defined || dest_width != source_width ||
11959 dest_height != source_height ||
11960 dest_internal_format != internal_format ||
11961 dest_type_previous != dest_type) {
11962 // Ensure that the glCompressedTexImage2D succeeds.
11963 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyCompressedTextureCHROMIUM");
11964 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
11965 glCompressedTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width,
11966 source_height, 0, source_size, NULL);
11967 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyCompressedTextureCHROMIUM");
11968 if (error != GL_NO_ERROR) {
11969 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D);
11970 return;
11971 }
11972
11973 texture_manager()->SetLevelInfo(
11974 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width,
11975 source_height, 1, 0, internal_format, dest_type, true);
11976 } else {
11977 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0,
11978 true);
11979 }
11980
11981 ScopedModifyPixels modify(dest_texture_ref);
11982
11983 DCHECK(!unpack_flip_y_);
11984 DCHECK(!(unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_));
11985
11986 // Copying compressed textures is only supported using GLImage::CopyTexImage.
11987 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
11988 bool copy_result = image->CopyTexImage(GL_TEXTURE_2D);
11989 DCHECK(copy_result);
reveman 2015/04/30 13:36:14 How do we handle this failure? CopyTexImage is all
christiank 2015/05/05 13:42:22 Tile compression should only be enabled when using
reveman 2015/05/05 16:12:09 It's hard to see how this is enforced right now. I
christiank 2015/05/07 12:47:00 Yes you're right. It certainly feels like a non-co
reveman 2015/05/07 18:35:49 Ideally we'd be able to say that CopyCompressedTex
christiank 2015/05/08 13:04:23 Sure, I imagine GetCompressedTexImage + Compressed
christiank 2015/05/12 11:08:59 Is it okay if I log an error for now? I'd rather a
11990 }
11991
11816 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { 11992 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) {
11817 switch (internalformat) { 11993 switch (internalformat) {
11818 case GL_RGB565: 11994 case GL_RGB565:
11819 return GL_UNSIGNED_SHORT_5_6_5; 11995 return GL_UNSIGNED_SHORT_5_6_5;
11820 case GL_RGBA4: 11996 case GL_RGBA4:
11821 return GL_UNSIGNED_SHORT_4_4_4_4; 11997 return GL_UNSIGNED_SHORT_4_4_4_4;
11822 case GL_RGB5_A1: 11998 case GL_RGB5_A1:
11823 return GL_UNSIGNED_SHORT_5_5_5_1; 11999 return GL_UNSIGNED_SHORT_5_5_5_1;
11824 case GL_RGB8_OES: 12000 case GL_RGB8_OES:
11825 return GL_UNSIGNED_BYTE; 12001 return GL_UNSIGNED_BYTE;
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
12957 } 13133 }
12958 } 13134 }
12959 13135
12960 // Include the auto-generated part of this file. We split this because it means 13136 // 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 13137 // 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. 13138 // instead of having to edit some template or the code generator.
12963 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 13139 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
12964 13140
12965 } // namespace gles2 13141 } // namespace gles2
12966 } // namespace gpu 13142 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_ids_autogen.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698