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

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

Issue 2479513002: Reland of Extend CopyTextureCHROMIUM to more ES 3.0 texture formats. (Closed)
Patch Set: fix compressed formats Created 4 years 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 <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 GLint yoffset, 883 GLint yoffset,
884 GLint zoffset, 884 GLint zoffset,
885 GLsizei width, 885 GLsizei width,
886 GLsizei height, 886 GLsizei height,
887 GLsizei depth, 887 GLsizei depth,
888 GLenum format, 888 GLenum format,
889 GLsizei imageSize, 889 GLsizei imageSize,
890 const void* data, 890 const void* data,
891 ContextState::Dimension dimension); 891 ContextState::Dimension dimension);
892 892
893 bool ValidateCopyTexFormatHelper(GLenum internal_format,
894 GLenum read_format,
895 GLenum read_type,
896 std::string* output_error_msg);
893 // Validate if |format| is valid for CopyTex{Sub}Image functions. 897 // Validate if |format| is valid for CopyTex{Sub}Image functions.
894 // If not, generate a GL error and return false. 898 // If not, generate a GL error and return false.
895 bool ValidateCopyTexFormat(const char* func_name, GLenum internal_format, 899 bool ValidateCopyTexFormat(const char* func_name, GLenum internal_format,
896 GLenum read_format, GLenum read_type); 900 GLenum read_format, GLenum read_type);
897 901
898 // Wrapper for CopyTexImage2D. 902 // Wrapper for CopyTexImage2D.
899 void DoCopyTexImage2D( 903 void DoCopyTexImage2D(
900 GLenum target, 904 GLenum target,
901 GLint level, 905 GLint level,
902 GLenum internal_format, 906 GLenum internal_format,
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 GLsizei size, 2000 GLsizei size,
1997 const GLvoid* data); 2001 const GLvoid* data);
1998 bool ValidateCompressedTexSubDimensions( 2002 bool ValidateCompressedTexSubDimensions(
1999 const char* function_name, 2003 const char* function_name,
2000 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, 2004 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
2001 GLsizei width, GLsizei height, GLsizei depth, GLenum format, 2005 GLsizei width, GLsizei height, GLsizei depth, GLenum format,
2002 Texture* texture); 2006 Texture* texture);
2003 bool ValidateCopyTextureCHROMIUMTextures(const char* function_name, 2007 bool ValidateCopyTextureCHROMIUMTextures(const char* function_name,
2004 TextureRef* source_texture_ref, 2008 TextureRef* source_texture_ref,
2005 TextureRef* dest_texture_ref); 2009 TextureRef* dest_texture_ref);
2006 bool ValidateCopyTextureCHROMIUMInternalFormats( 2010 CopyTextureMethod ValidateCopyTextureCHROMIUMInternalFormats(
2007 const char* function_name, 2011 const char* function_name,
2008 TextureRef* source_texture_ref, 2012 TextureRef* source_texture_ref,
2009 GLenum dest_internal_format); 2013 GLenum dest_internal_format);
2010 bool ValidateCompressedCopyTextureCHROMIUM(const char* function_name, 2014 bool ValidateCompressedCopyTextureCHROMIUM(const char* function_name,
2011 TextureRef* source_texture_ref, 2015 TextureRef* source_texture_ref,
2012 TextureRef* dest_texture_ref); 2016 TextureRef* dest_texture_ref);
2013 2017
2014 void RenderWarning(const char* filename, int line, const std::string& msg); 2018 void RenderWarning(const char* filename, int line, const std::string& msg);
2015 void PerformanceWarning( 2019 void PerformanceWarning(
2016 const char* filename, int line, const std::string& msg); 2020 const char* filename, int line, const std::string& msg);
(...skipping 11780 matching lines...) Expand 10 before | Expand all | Expand 10 after
13797 height, depth, format, image_size, data); 13801 height, depth, format, image_size, data);
13798 } 13802 }
13799 } 13803 }
13800 13804
13801 // This may be a slow command. Exit command processing to allow for 13805 // This may be a slow command. Exit command processing to allow for
13802 // context preemption and GPU watchdog checks. 13806 // context preemption and GPU watchdog checks.
13803 ExitCommandProcessingEarly(); 13807 ExitCommandProcessingEarly();
13804 return error::kNoError; 13808 return error::kNoError;
13805 } 13809 }
13806 13810
13807 bool GLES2DecoderImpl::ValidateCopyTexFormat( 13811 bool GLES2DecoderImpl::ValidateCopyTexFormatHelper(
13808 const char* func_name, GLenum internal_format, 13812 GLenum internal_format,
13809 GLenum read_format, GLenum read_type) { 13813 GLenum read_format,
13814 GLenum read_type,
13815 std::string* output_error_msg) {
13816 DCHECK(output_error_msg);
13810 if (read_format == 0) { 13817 if (read_format == 0) {
13811 LOCAL_SET_GL_ERROR( 13818 *output_error_msg = std::string("no valid color image");
13812 GL_INVALID_OPERATION, func_name, "no valid color image");
13813 return false; 13819 return false;
13814 } 13820 }
13815 // Check we have compatible formats. 13821 // Check we have compatible formats.
13816 uint32_t channels_exist = GLES2Util::GetChannelsForFormat(read_format); 13822 uint32_t channels_exist = GLES2Util::GetChannelsForFormat(read_format);
13817 uint32_t channels_needed = GLES2Util::GetChannelsForFormat(internal_format); 13823 uint32_t channels_needed = GLES2Util::GetChannelsForFormat(internal_format);
13818 if (!channels_needed || 13824 if (!channels_needed ||
13819 (channels_needed & channels_exist) != channels_needed) { 13825 (channels_needed & channels_exist) != channels_needed) {
13820 LOCAL_SET_GL_ERROR( 13826 *output_error_msg = std::string("incompatible format");
13821 GL_INVALID_OPERATION, func_name, "incompatible format");
13822 return false; 13827 return false;
13823 } 13828 }
13824 if (feature_info_->IsWebGL2OrES3Context()) { 13829 if (feature_info_->IsWebGL2OrES3Context()) {
13825 GLint color_encoding = GetColorEncodingFromInternalFormat(read_format); 13830 GLint color_encoding = GetColorEncodingFromInternalFormat(read_format);
13826 bool float_mismatch = feature_info_->ext_color_buffer_float_available() ? 13831 bool float_mismatch = feature_info_->ext_color_buffer_float_available() ?
13827 (GLES2Util::IsIntegerFormat(internal_format) != 13832 (GLES2Util::IsIntegerFormat(internal_format) !=
13828 GLES2Util::IsIntegerFormat(read_format)) : 13833 GLES2Util::IsIntegerFormat(read_format)) :
13829 GLES2Util::IsFloatFormat(internal_format); 13834 GLES2Util::IsFloatFormat(internal_format);
13830 if (color_encoding != GetColorEncodingFromInternalFormat(internal_format) || 13835 if (color_encoding != GetColorEncodingFromInternalFormat(internal_format) ||
13831 float_mismatch || 13836 float_mismatch ||
13832 (GLES2Util::IsSignedIntegerFormat(internal_format) != 13837 (GLES2Util::IsSignedIntegerFormat(internal_format) !=
13833 GLES2Util::IsSignedIntegerFormat(read_format)) || 13838 GLES2Util::IsSignedIntegerFormat(read_format)) ||
13834 (GLES2Util::IsUnsignedIntegerFormat(internal_format) != 13839 (GLES2Util::IsUnsignedIntegerFormat(internal_format) !=
13835 GLES2Util::IsUnsignedIntegerFormat(read_format))) { 13840 GLES2Util::IsUnsignedIntegerFormat(read_format))) {
13836 LOCAL_SET_GL_ERROR( 13841 *output_error_msg = std::string("incompatible format");
13837 GL_INVALID_OPERATION, func_name, "incompatible format");
13838 return false; 13842 return false;
13839 } 13843 }
13840 } 13844 }
13841 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { 13845 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) {
13842 LOCAL_SET_GL_ERROR( 13846 *output_error_msg =
13843 GL_INVALID_OPERATION, 13847 std::string("can not be used with depth or stencil textures");
13844 func_name, "can not be used with depth or stencil textures");
13845 return false; 13848 return false;
13846 } 13849 }
13847 if (feature_info_->IsWebGL2OrES3Context()) { 13850 if (feature_info_->IsWebGL2OrES3Context()) {
13848 if (GLES2Util::IsSizedColorFormat(internal_format)) { 13851 if (GLES2Util::IsSizedColorFormat(internal_format)) {
13849 int sr, sg, sb, sa; 13852 int sr, sg, sb, sa;
13850 GLES2Util::GetColorFormatComponentSizes( 13853 GLES2Util::GetColorFormatComponentSizes(
13851 read_format, read_type, &sr, &sg, &sb, &sa); 13854 read_format, read_type, &sr, &sg, &sb, &sa);
13852 DCHECK(sr > 0 || sg > 0 || sb > 0 || sa > 0); 13855 DCHECK(sr > 0 || sg > 0 || sb > 0 || sa > 0);
13853 int dr, dg, db, da; 13856 int dr, dg, db, da;
13854 GLES2Util::GetColorFormatComponentSizes( 13857 GLES2Util::GetColorFormatComponentSizes(
13855 internal_format, 0, &dr, &dg, &db, &da); 13858 internal_format, 0, &dr, &dg, &db, &da);
13856 DCHECK(dr > 0 || dg > 0 || db > 0 || da > 0); 13859 DCHECK(dr > 0 || dg > 0 || db > 0 || da > 0);
13857 if ((dr > 0 && sr != dr) || 13860 if ((dr > 0 && sr != dr) ||
13858 (dg > 0 && sg != dg) || 13861 (dg > 0 && sg != dg) ||
13859 (db > 0 && sb != db) || 13862 (db > 0 && sb != db) ||
13860 (da > 0 && sa != da)) { 13863 (da > 0 && sa != da)) {
13861 LOCAL_SET_GL_ERROR( 13864 *output_error_msg = std::string("incompatible color component sizes");
13862 GL_INVALID_OPERATION,
13863 func_name, "incompatible color component sizes");
13864 return false; 13865 return false;
13865 } 13866 }
13866 } 13867 }
13867 } 13868 }
13868 return true; 13869 return true;
13869 } 13870 }
13870 13871
13872 bool GLES2DecoderImpl::ValidateCopyTexFormat(const char* func_name,
13873 GLenum internal_format,
13874 GLenum read_format,
13875 GLenum read_type) {
13876 std::string output_error_msg;
13877 if (!ValidateCopyTexFormatHelper(internal_format, read_format, read_type,
13878 &output_error_msg)) {
13879 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name,
13880 output_error_msg.c_str());
13881 return false;
13882 }
13883 return true;
13884 }
13885
13871 void GLES2DecoderImpl::DoCopyTexImage2D( 13886 void GLES2DecoderImpl::DoCopyTexImage2D(
13872 GLenum target, 13887 GLenum target,
13873 GLint level, 13888 GLint level,
13874 GLenum internal_format, 13889 GLenum internal_format,
13875 GLint x, 13890 GLint x,
13876 GLint y, 13891 GLint y,
13877 GLsizei width, 13892 GLsizei width,
13878 GLsizei height, 13893 GLsizei height,
13879 GLint border) { 13894 GLint border) {
13880 const char* func_name = "glCopyTexImage2D"; 13895 const char* func_name = "glCopyTexImage2D";
(...skipping 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after
16065 case GL_TEXTURE_EXTERNAL_OES: 16080 case GL_TEXTURE_EXTERNAL_OES:
16066 break; 16081 break;
16067 default: 16082 default:
16068 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, 16083 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
16069 "invalid source texture target binding"); 16084 "invalid source texture target binding");
16070 return false; 16085 return false;
16071 } 16086 }
16072 return true; 16087 return true;
16073 } 16088 }
16074 16089
16075 bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUMInternalFormats( 16090 CopyTextureMethod GLES2DecoderImpl::ValidateCopyTextureCHROMIUMInternalFormats(
16076 const char* function_name, 16091 const char* function_name,
16077 TextureRef* source_texture_ref, 16092 TextureRef* source_texture_ref,
16078 GLenum dest_internal_format) { 16093 GLenum dest_internal_format) {
16079 GLenum source_type = 0; 16094 GLenum source_type = 0;
16080 GLenum source_internal_format = 0; 16095 GLenum source_internal_format = 0;
16081 Texture* source_texture = source_texture_ref->texture(); 16096 Texture* source_texture = source_texture_ref->texture();
16082 source_texture->GetLevelType(source_texture->target(), 0, &source_type, 16097 source_texture->GetLevelType(source_texture->target(), 0, &source_type,
16083 &source_internal_format); 16098 &source_internal_format);
16084 16099
16085 // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, 16100 bool valid_dest_format = false;
16086 // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not 16101 // TODO(qiankun.miao@intel.com): ALPHA, LUMINANCE and LUMINANCE_ALPHA formats
16087 // renderable on some platforms. 16102 // are not supported on GL core profile. See crbug.com/577144. Enable the
16088 bool valid_dest_format = 16103 // workaround for glCopyTexImage and glCopyTexSubImage in
16089 dest_internal_format == GL_RGB || dest_internal_format == GL_RGBA || 16104 // gles2_cmd_copy_tex_image.cc for glCopyTextureCHROMIUM implementation.
16090 dest_internal_format == GL_RGB8 || dest_internal_format == GL_RGBA8 || 16105 switch (dest_internal_format) {
16091 dest_internal_format == GL_BGRA_EXT || 16106 case GL_RGB:
16092 dest_internal_format == GL_BGRA8_EXT; 16107 case GL_RGBA:
16108 case GL_RGB8:
16109 case GL_RGBA8:
16110 valid_dest_format = true;
16111 break;
16112 case GL_BGRA_EXT:
16113 case GL_BGRA8_EXT:
16114 valid_dest_format =
16115 feature_info_->feature_flags().ext_texture_format_bgra8888;
16116 break;
16117 case GL_SRGB_EXT:
16118 case GL_SRGB_ALPHA_EXT:
16119 valid_dest_format = feature_info_->feature_flags().ext_srgb;
16120 break;
16121 case GL_R8:
16122 case GL_R8UI:
16123 case GL_RG8:
16124 case GL_RG8UI:
16125 case GL_SRGB8:
16126 case GL_RGB565:
16127 case GL_RGB8UI:
16128 case GL_SRGB8_ALPHA8:
16129 case GL_RGB5_A1:
16130 case GL_RGBA4:
16131 case GL_RGBA8UI:
16132 valid_dest_format = feature_info_->IsWebGL2OrES3Context();
16133 break;
16134 case GL_RGB9_E5:
16135 valid_dest_format = !gl_version_info().is_es;
16136 break;
16137 case GL_R16F:
16138 case GL_R32F:
16139 case GL_RG16F:
16140 case GL_RG32F:
16141 case GL_RGB16F:
16142 case GL_RGB32F:
16143 case GL_RGBA16F:
16144 case GL_RGBA32F:
16145 case GL_R11F_G11F_B10F:
16146 valid_dest_format = feature_info_->ext_color_buffer_float_available();
16147 break;
16148 default:
16149 valid_dest_format = false;
16150 break;
16151 }
16152
16093 bool valid_source_format = 16153 bool valid_source_format =
16094 source_internal_format == GL_RED || source_internal_format == GL_ALPHA || 16154 source_internal_format == GL_RED || source_internal_format == GL_ALPHA ||
16095 source_internal_format == GL_RGB || source_internal_format == GL_RGBA || 16155 source_internal_format == GL_RGB || source_internal_format == GL_RGBA ||
16096 source_internal_format == GL_RGB8 || source_internal_format == GL_RGBA8 || 16156 source_internal_format == GL_RGB8 || source_internal_format == GL_RGBA8 ||
16097 source_internal_format == GL_LUMINANCE || 16157 source_internal_format == GL_LUMINANCE ||
16098 source_internal_format == GL_LUMINANCE_ALPHA || 16158 source_internal_format == GL_LUMINANCE_ALPHA ||
16099 source_internal_format == GL_BGRA_EXT || 16159 source_internal_format == GL_BGRA_EXT ||
16100 source_internal_format == GL_BGRA8_EXT || 16160 source_internal_format == GL_BGRA8_EXT ||
16101 source_internal_format == GL_RGB_YCBCR_420V_CHROMIUM || 16161 source_internal_format == GL_RGB_YCBCR_420V_CHROMIUM ||
16102 source_internal_format == GL_RGB_YCBCR_422_CHROMIUM; 16162 source_internal_format == GL_RGB_YCBCR_422_CHROMIUM;
16103 if (!valid_source_format) { 16163 if (!valid_source_format) {
16104 std::string msg = "invalid source internal format " + 16164 std::string msg = "invalid source internal format " +
16105 GLES2Util::GetStringEnum(source_internal_format); 16165 GLES2Util::GetStringEnum(source_internal_format);
16106 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, 16166 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
16107 msg.c_str()); 16167 msg.c_str());
16108 return false; 16168 return NOT_COPYABLE;
16109 } 16169 }
16110 if (!valid_dest_format) { 16170 if (!valid_dest_format) {
16111 std::string msg = "invalid dest internal format " + 16171 std::string msg = "invalid dest internal format " +
16112 GLES2Util::GetStringEnum(dest_internal_format); 16172 GLES2Util::GetStringEnum(dest_internal_format);
16113 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, 16173 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
16114 msg.c_str()); 16174 msg.c_str());
16115 return false; 16175 return NOT_COPYABLE;
16116 } 16176 }
16117 return true; 16177
16178 bool source_format_color_renderable =
16179 Texture::ColorRenderable(GetFeatureInfo(), source_internal_format, false);
16180 bool dest_format_color_renderable =
16181 Texture::ColorRenderable(GetFeatureInfo(), dest_internal_format, false);
16182 std::string output_error_msg;
16183
16184 // CopyTexImage* should not allow internalformat of GL_BGRA_EXT and
16185 // GL_BGRA8_EXT. crbug.com/663086.
16186 bool copy_tex_image_format_valid =
16187 source_internal_format != GL_BGRA_EXT &&
16188 dest_internal_format != GL_BGRA_EXT &&
16189 source_internal_format != GL_BGRA8_EXT &&
16190 dest_internal_format != GL_BGRA8_EXT &&
16191 ValidateCopyTexFormatHelper(dest_internal_format, source_internal_format,
16192 source_type, &output_error_msg);
16193 if (source_format_color_renderable && copy_tex_image_format_valid)
16194 return DIRECT_COPY;
16195
16196 if (dest_format_color_renderable)
16197 return DIRECT_DRAW;
16198
16199 return DRAW_AND_COPY;
16118 } 16200 }
16119 16201
16120 bool GLES2DecoderImpl::ValidateCompressedCopyTextureCHROMIUM( 16202 bool GLES2DecoderImpl::ValidateCompressedCopyTextureCHROMIUM(
16121 const char* function_name, 16203 const char* function_name,
16122 TextureRef* source_texture_ref, 16204 TextureRef* source_texture_ref,
16123 TextureRef* dest_texture_ref) { 16205 TextureRef* dest_texture_ref) {
16124 if (!source_texture_ref || !dest_texture_ref) { 16206 if (!source_texture_ref || !dest_texture_ref) {
16125 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); 16207 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id");
16126 return false; 16208 return false;
16127 } 16209 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
16171 GLenum dest_type, 16253 GLenum dest_type,
16172 GLboolean unpack_flip_y, 16254 GLboolean unpack_flip_y,
16173 GLboolean unpack_premultiply_alpha, 16255 GLboolean unpack_premultiply_alpha,
16174 GLboolean unpack_unmultiply_alpha) { 16256 GLboolean unpack_unmultiply_alpha) {
16175 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); 16257 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM");
16176 static const char kFunctionName[] = "glCopyTextureCHROMIUM"; 16258 static const char kFunctionName[] = "glCopyTextureCHROMIUM";
16177 16259
16178 TextureRef* source_texture_ref = GetTexture(source_id); 16260 TextureRef* source_texture_ref = GetTexture(source_id);
16179 TextureRef* dest_texture_ref = GetTexture(dest_id); 16261 TextureRef* dest_texture_ref = GetTexture(dest_id);
16180 16262
16181 if (!texture_manager()->ValidateTextureParameters(
16182 GetErrorState(), kFunctionName, true, internal_format, dest_type,
16183 internal_format, 0))
16184 return;
16185
16186 if (!ValidateCopyTextureCHROMIUMTextures(kFunctionName, source_texture_ref, 16263 if (!ValidateCopyTextureCHROMIUMTextures(kFunctionName, source_texture_ref,
16187 dest_texture_ref)) { 16264 dest_texture_ref)) {
16188 return; 16265 return;
16189 } 16266 }
16190 16267
16191 if (!ValidateCopyTextureCHROMIUMInternalFormats(
16192 kFunctionName, source_texture_ref, internal_format)) {
16193 return;
16194 }
16195
16196 Texture* source_texture = source_texture_ref->texture(); 16268 Texture* source_texture = source_texture_ref->texture();
16197 Texture* dest_texture = dest_texture_ref->texture(); 16269 Texture* dest_texture = dest_texture_ref->texture();
16198 GLenum source_target = source_texture->target(); 16270 GLenum source_target = source_texture->target();
16199 GLenum dest_target = dest_texture->target(); 16271 GLenum dest_target = dest_texture->target();
16272
16273 GLenum source_type = 0;
16274 GLenum source_internal_format = 0;
16275 source_texture->GetLevelType(source_target, 0, &source_type,
16276 &source_internal_format);
16277 GLenum format =
16278 TextureManager::ExtractFormatFromStorageFormat(internal_format);
16279 if (!texture_manager()->ValidateTextureParameters(
16280 GetErrorState(), kFunctionName, true, format, dest_type,
16281 internal_format, 0)) {
16282 return;
16283 }
16284
16285 CopyTextureMethod method = ValidateCopyTextureCHROMIUMInternalFormats(
16286 kFunctionName, source_texture_ref, internal_format);
16287 // INVALID_OPERATION is already generated by
16288 // ValidateCopyTextureCHROMIUMInternalFormats.
16289 if (NOT_COPYABLE == method) {
16290 return;
16291 }
16292
16293 if (feature_info_->feature_flags().desktop_srgb_support) {
16294 bool enable_framebuffer_srgb =
16295 GetColorEncodingFromInternalFormat(source_internal_format) == GL_SRGB ||
16296 GetColorEncodingFromInternalFormat(internal_format) == GL_SRGB;
16297 state_.EnableDisableFramebufferSRGB(enable_framebuffer_srgb);
16298 }
16299
16200 int source_width = 0; 16300 int source_width = 0;
16201 int source_height = 0; 16301 int source_height = 0;
16202 gl::GLImage* image = 16302 gl::GLImage* image =
16203 source_texture->GetLevelImage(source_target, 0); 16303 source_texture->GetLevelImage(source_target, 0);
16204 if (image) { 16304 if (image) {
16205 gfx::Size size = image->GetSize(); 16305 gfx::Size size = image->GetSize();
16206 source_width = size.width(); 16306 source_width = size.width();
16207 source_height = size.height(); 16307 source_height = size.height();
16208 if (source_width <= 0 || source_height <= 0) { 16308 if (source_width <= 0 || source_height <= 0) {
16209 LOCAL_SET_GL_ERROR( 16309 LOCAL_SET_GL_ERROR(
(...skipping 11 matching lines...) Expand all
16221 } 16321 }
16222 16322
16223 // Check that this type of texture is allowed. 16323 // Check that this type of texture is allowed.
16224 if (!texture_manager()->ValidForTarget(source_target, 0, 16324 if (!texture_manager()->ValidForTarget(source_target, 0,
16225 source_width, source_height, 1)) { 16325 source_width, source_height, 1)) {
16226 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, "Bad dimensions"); 16326 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, "Bad dimensions");
16227 return; 16327 return;
16228 } 16328 }
16229 } 16329 }
16230 16330
16231 GLenum source_type = 0;
16232 GLenum source_internal_format = 0;
16233 source_texture->GetLevelType(source_target, 0, &source_type,
16234 &source_internal_format);
16235
16236 if (dest_texture->IsImmutable()) { 16331 if (dest_texture->IsImmutable()) {
16237 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, kFunctionName, 16332 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, kFunctionName,
16238 "texture is immutable"); 16333 "texture is immutable");
16239 return; 16334 return;
16240 } 16335 }
16241 16336
16242 // Clear the source texture if necessary. 16337 // Clear the source texture if necessary.
16243 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, 16338 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
16244 source_target, 0)) { 16339 source_target, 0)) {
16245 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, "dimensions too big"); 16340 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, "dimensions too big");
(...skipping 16 matching lines...) Expand all
16262 } 16357 }
16263 16358
16264 // Resize the destination texture to the dimensions of the source texture. 16359 // Resize the destination texture to the dimensions of the source texture.
16265 if (!dest_level_defined || dest_width != source_width || 16360 if (!dest_level_defined || dest_width != source_width ||
16266 dest_height != source_height || 16361 dest_height != source_height ||
16267 dest_internal_format != internal_format || 16362 dest_internal_format != internal_format ||
16268 dest_type_previous != dest_type) { 16363 dest_type_previous != dest_type) {
16269 // Ensure that the glTexImage2D succeeds. 16364 // Ensure that the glTexImage2D succeeds.
16270 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); 16365 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName);
16271 glBindTexture(dest_target, dest_texture->service_id()); 16366 glBindTexture(dest_target, dest_texture->service_id());
16272 glTexImage2D( 16367 glTexImage2D(dest_target, 0, TextureManager::AdjustTexInternalFormat(
16273 dest_target, 0, TextureManager::AdjustTexInternalFormat( 16368 feature_info_.get(), internal_format),
16274 feature_info_.get(), internal_format), 16369 source_width, source_height, 0,
16275 source_width, source_height, 0, 16370 TextureManager::AdjustTexFormat(feature_info_.get(), format),
16276 TextureManager::AdjustTexFormat(feature_info_.get(), internal_format), 16371 dest_type, NULL);
16277 dest_type, NULL);
16278 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); 16372 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName);
16279 if (error != GL_NO_ERROR) { 16373 if (error != GL_NO_ERROR) {
16280 RestoreCurrentTextureBindings(&state_, dest_target); 16374 RestoreCurrentTextureBindings(&state_, dest_target);
16281 return; 16375 return;
16282 } 16376 }
16283 16377
16284 texture_manager()->SetLevelInfo( 16378 texture_manager()->SetLevelInfo(dest_texture_ref, dest_target, 0,
16285 dest_texture_ref, dest_target, 0, internal_format, source_width, 16379 internal_format, source_width,
16286 source_height, 1, 0, internal_format, dest_type, 16380 source_height, 1, 0, format, dest_type,
16287 gfx::Rect(source_width, source_height)); 16381 gfx::Rect(source_width, source_height));
16288 dest_texture->ApplyFormatWorkarounds(feature_info_.get()); 16382 dest_texture->ApplyFormatWorkarounds(feature_info_.get());
16289 } else { 16383 } else {
16290 texture_manager()->SetLevelCleared(dest_texture_ref, dest_target, 0, 16384 texture_manager()->SetLevelCleared(dest_texture_ref, dest_target, 0, true);
16291 true);
16292 } 16385 }
16293 16386
16294 // Try using GLImage::CopyTexImage when possible. 16387 // Try using GLImage::CopyTexImage when possible.
16295 bool unpack_premultiply_alpha_change = 16388 bool unpack_premultiply_alpha_change =
16296 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; 16389 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0;
16297 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { 16390 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) {
16298 glBindTexture(dest_target, dest_texture->service_id()); 16391 glBindTexture(dest_target, dest_texture->service_id());
16299 if (image->CopyTexImage(dest_target)) 16392 if (image->CopyTexImage(dest_target))
16300 return; 16393 return;
16301 } 16394 }
16302 16395
16303 DoCopyTexImageIfNeeded(source_texture, source_target); 16396 DoCopyTexImageIfNeeded(source_texture, source_target);
16304 16397
16305 // GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix 16398 // GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix
16306 // before presenting. 16399 // before presenting.
16307 if (source_target == GL_TEXTURE_EXTERNAL_OES) { 16400 if (source_target == GL_TEXTURE_EXTERNAL_OES) {
16308 if (GLStreamTextureImage* image = 16401 if (GLStreamTextureImage* image =
16309 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, 16402 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES,
16310 0)) { 16403 0)) {
16311 GLfloat transform_matrix[16]; 16404 GLfloat transform_matrix[16];
16312 image->GetTextureMatrix(transform_matrix); 16405 image->GetTextureMatrix(transform_matrix);
16313 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( 16406 copy_texture_CHROMIUM_->DoCopyTextureWithTransform(
16314 this, source_target, source_texture->service_id(), dest_target, 16407 this, source_target, source_texture->service_id(),
16315 dest_texture->service_id(), source_width, source_height, 16408 source_internal_format, dest_target, dest_texture->service_id(),
16409 internal_format, source_width, source_height,
16316 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE, 16410 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE,
16317 unpack_unmultiply_alpha == GL_TRUE, transform_matrix); 16411 unpack_unmultiply_alpha == GL_TRUE, transform_matrix);
16318 return; 16412 return;
16319 } 16413 }
16320 } 16414 }
16415
16321 copy_texture_CHROMIUM_->DoCopyTexture( 16416 copy_texture_CHROMIUM_->DoCopyTexture(
16322 this, source_target, source_texture->service_id(), source_internal_format, 16417 this, source_target, source_texture->service_id(), source_internal_format,
16323 dest_target, dest_texture->service_id(), internal_format, source_width, 16418 dest_target, dest_texture->service_id(), internal_format, source_width,
16324 source_height, unpack_flip_y == GL_TRUE, 16419 source_height, unpack_flip_y == GL_TRUE,
16325 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE); 16420 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE,
16421 method);
16326 } 16422 }
16327 16423
16328 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( 16424 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
16329 GLuint source_id, 16425 GLuint source_id,
16330 GLuint dest_id, 16426 GLuint dest_id,
16331 GLint xoffset, 16427 GLint xoffset,
16332 GLint yoffset, 16428 GLint yoffset,
16333 GLint x, 16429 GLint x,
16334 GLint y, 16430 GLint y,
16335 GLsizei width, 16431 GLsizei width,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
16417 "destination texture is not defined"); 16513 "destination texture is not defined");
16418 return; 16514 return;
16419 } 16515 }
16420 if (!dest_texture->ValidForTexture(dest_target, 0, xoffset, 16516 if (!dest_texture->ValidForTexture(dest_target, 0, xoffset,
16421 yoffset, 0, width, height, 1)) { 16517 yoffset, 0, width, height, 1)) {
16422 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, 16518 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName,
16423 "destination texture bad dimensions."); 16519 "destination texture bad dimensions.");
16424 return; 16520 return;
16425 } 16521 }
16426 16522
16427 if (!ValidateCopyTextureCHROMIUMInternalFormats( 16523 CopyTextureMethod method = ValidateCopyTextureCHROMIUMInternalFormats(
16428 kFunctionName, source_texture_ref, dest_internal_format)) { 16524 kFunctionName, source_texture_ref, dest_internal_format);
16525 // INVALID_OPERATION is already generated by
16526 // ValidateCopyTextureCHROMIUMInternalFormats.
16527 if (NOT_COPYABLE == method) {
16429 return; 16528 return;
16430 } 16529 }
16431 16530
16531 if (feature_info_->feature_flags().desktop_srgb_support) {
16532 bool enable_framebuffer_srgb =
16533 GetColorEncodingFromInternalFormat(source_internal_format) == GL_SRGB ||
16534 GetColorEncodingFromInternalFormat(dest_internal_format) == GL_SRGB;
16535 state_.EnableDisableFramebufferSRGB(enable_framebuffer_srgb);
16536 }
16537
16432 // Clear the source texture if necessary. 16538 // Clear the source texture if necessary.
16433 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, 16539 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
16434 source_target, 0)) { 16540 source_target, 0)) {
16435 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, 16541 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName,
16436 "source texture dimensions too big"); 16542 "source texture dimensions too big");
16437 return; 16543 return;
16438 } 16544 }
16439 16545
16440 if (!InitializeCopyTextureCHROMIUM(kFunctionName)) 16546 if (!InitializeCopyTextureCHROMIUM(kFunctionName))
16441 return; 16547 return;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
16500 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE, 16606 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE,
16501 unpack_unmultiply_alpha == GL_TRUE, transform_matrix); 16607 unpack_unmultiply_alpha == GL_TRUE, transform_matrix);
16502 return; 16608 return;
16503 } 16609 }
16504 } 16610 }
16505 copy_texture_CHROMIUM_->DoCopySubTexture( 16611 copy_texture_CHROMIUM_->DoCopySubTexture(
16506 this, source_target, source_texture->service_id(), source_internal_format, 16612 this, source_target, source_texture->service_id(), source_internal_format,
16507 dest_target, dest_texture->service_id(), dest_internal_format, xoffset, 16613 dest_target, dest_texture->service_id(), dest_internal_format, xoffset,
16508 yoffset, x, y, width, height, dest_width, dest_height, source_width, 16614 yoffset, x, y, width, height, dest_width, dest_height, source_width,
16509 source_height, unpack_flip_y == GL_TRUE, 16615 source_height, unpack_flip_y == GL_TRUE,
16510 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE); 16616 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE,
16617 method);
16511 } 16618 }
16512 16619
16513 bool GLES2DecoderImpl::InitializeCopyTexImageBlitter( 16620 bool GLES2DecoderImpl::InitializeCopyTexImageBlitter(
16514 const char* function_name) { 16621 const char* function_name) {
16515 if (!copy_tex_image_blit_.get()) { 16622 if (!copy_tex_image_blit_.get()) {
16516 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); 16623 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name);
16517 copy_tex_image_blit_.reset( 16624 copy_tex_image_blit_.reset(
16518 new CopyTexImageResourceManager(feature_info_.get())); 16625 new CopyTexImageResourceManager(feature_info_.get()));
16519 copy_tex_image_blit_->Initialize(this); 16626 copy_tex_image_blit_->Initialize(this);
16520 if (LOCAL_PEEK_GL_ERROR(function_name) != GL_NO_ERROR) 16627 if (LOCAL_PEEK_GL_ERROR(function_name) != GL_NO_ERROR)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
16675 16782
16676 texture_manager()->SetLevelInfo( 16783 texture_manager()->SetLevelInfo(
16677 dest_texture_ref, dest_texture->target(), 0, GL_RGBA, source_width, 16784 dest_texture_ref, dest_texture->target(), 0, GL_RGBA, source_width,
16678 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 16785 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
16679 gfx::Rect(source_width, source_height)); 16786 gfx::Rect(source_width, source_height));
16680 16787
16681 copy_texture_CHROMIUM_->DoCopyTexture( 16788 copy_texture_CHROMIUM_->DoCopyTexture(
16682 this, source_texture->target(), source_texture->service_id(), 16789 this, source_texture->target(), source_texture->service_id(),
16683 source_internal_format, dest_texture->target(), 16790 source_internal_format, dest_texture->target(),
16684 dest_texture->service_id(), GL_RGBA, source_width, source_height, false, 16791 dest_texture->service_id(), GL_RGBA, source_width, source_height, false,
16685 false, false); 16792 false, false, DIRECT_DRAW);
16686 } 16793 }
16687 16794
16688 void GLES2DecoderImpl::TexStorageImpl(GLenum target, 16795 void GLES2DecoderImpl::TexStorageImpl(GLenum target,
16689 GLsizei levels, 16796 GLsizei levels,
16690 GLenum internal_format, 16797 GLenum internal_format,
16691 GLsizei width, 16798 GLsizei width,
16692 GLsizei height, 16799 GLsizei height,
16693 GLsizei depth, 16800 GLsizei depth,
16694 ContextState::Dimension dimension, 16801 ContextState::Dimension dimension,
16695 const char* function_name) { 16802 const char* function_name) {
(...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after
18931 } 19038 }
18932 19039
18933 // Include the auto-generated part of this file. We split this because it means 19040 // Include the auto-generated part of this file. We split this because it means
18934 // we can easily edit the non-auto generated parts right here in this file 19041 // we can easily edit the non-auto generated parts right here in this file
18935 // instead of having to edit some template or the code generator. 19042 // instead of having to edit some template or the code generator.
18936 #include "base/macros.h" 19043 #include "base/macros.h"
18937 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 19044 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
18938 19045
18939 } // namespace gles2 19046 } // namespace gles2
18940 } // namespace gpu 19047 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698