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

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-opengl-lessthan-32 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 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 GLsizei size, 2006 GLsizei size,
2003 const GLvoid* data); 2007 const GLvoid* data);
2004 bool ValidateCompressedTexSubDimensions( 2008 bool ValidateCompressedTexSubDimensions(
2005 const char* function_name, 2009 const char* function_name,
2006 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, 2010 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
2007 GLsizei width, GLsizei height, GLsizei depth, GLenum format, 2011 GLsizei width, GLsizei height, GLsizei depth, GLenum format,
2008 Texture* texture); 2012 Texture* texture);
2009 bool ValidateCopyTextureCHROMIUMTextures(const char* function_name, 2013 bool ValidateCopyTextureCHROMIUMTextures(const char* function_name,
2010 TextureRef* source_texture_ref, 2014 TextureRef* source_texture_ref,
2011 TextureRef* dest_texture_ref); 2015 TextureRef* dest_texture_ref);
2012 bool ValidateCopyTextureCHROMIUMInternalFormats( 2016 CopyTextureMethod ValidateCopyTextureCHROMIUMInternalFormats(
2013 const char* function_name, 2017 const char* function_name,
2014 TextureRef* source_texture_ref, 2018 TextureRef* source_texture_ref,
2015 GLenum dest_internal_format); 2019 GLenum dest_internal_format);
2016 bool ValidateCompressedCopyTextureCHROMIUM(const char* function_name, 2020 bool ValidateCompressedCopyTextureCHROMIUM(const char* function_name,
2017 TextureRef* source_texture_ref, 2021 TextureRef* source_texture_ref,
2018 TextureRef* dest_texture_ref); 2022 TextureRef* dest_texture_ref);
2019 2023
2020 void RenderWarning(const char* filename, int line, const std::string& msg); 2024 void RenderWarning(const char* filename, int line, const std::string& msg);
2021 void PerformanceWarning( 2025 void PerformanceWarning(
2022 const char* filename, int line, const std::string& msg); 2026 const char* filename, int line, const std::string& msg);
(...skipping 11844 matching lines...) Expand 10 before | Expand all | Expand 10 after
13867 height, depth, format, image_size, data); 13871 height, depth, format, image_size, data);
13868 } 13872 }
13869 } 13873 }
13870 13874
13871 // This may be a slow command. Exit command processing to allow for 13875 // This may be a slow command. Exit command processing to allow for
13872 // context preemption and GPU watchdog checks. 13876 // context preemption and GPU watchdog checks.
13873 ExitCommandProcessingEarly(); 13877 ExitCommandProcessingEarly();
13874 return error::kNoError; 13878 return error::kNoError;
13875 } 13879 }
13876 13880
13877 bool GLES2DecoderImpl::ValidateCopyTexFormat( 13881 bool GLES2DecoderImpl::ValidateCopyTexFormatHelper(
13878 const char* func_name, GLenum internal_format, 13882 GLenum internal_format,
13879 GLenum read_format, GLenum read_type) { 13883 GLenum read_format,
13884 GLenum read_type,
13885 std::string* output_error_msg) {
13886 DCHECK(output_error_msg);
13880 if (read_format == 0) { 13887 if (read_format == 0) {
13881 LOCAL_SET_GL_ERROR( 13888 *output_error_msg = std::string("no valid color image");
13882 GL_INVALID_OPERATION, func_name, "no valid color image");
13883 return false; 13889 return false;
13884 } 13890 }
13885 // Check we have compatible formats. 13891 // Check we have compatible formats.
13886 uint32_t channels_exist = GLES2Util::GetChannelsForFormat(read_format); 13892 uint32_t channels_exist = GLES2Util::GetChannelsForFormat(read_format);
13887 uint32_t channels_needed = GLES2Util::GetChannelsForFormat(internal_format); 13893 uint32_t channels_needed = GLES2Util::GetChannelsForFormat(internal_format);
13888 if (!channels_needed || 13894 if (!channels_needed ||
13889 (channels_needed & channels_exist) != channels_needed) { 13895 (channels_needed & channels_exist) != channels_needed) {
13890 LOCAL_SET_GL_ERROR( 13896 *output_error_msg = std::string("incompatible format");
13891 GL_INVALID_OPERATION, func_name, "incompatible format");
13892 return false; 13897 return false;
13893 } 13898 }
13894 if (feature_info_->IsWebGL2OrES3Context()) { 13899 if (feature_info_->IsWebGL2OrES3Context()) {
13895 GLint color_encoding = GetColorEncodingFromInternalFormat(read_format); 13900 GLint color_encoding = GetColorEncodingFromInternalFormat(read_format);
13896 bool float_mismatch = feature_info_->ext_color_buffer_float_available() ? 13901 bool float_mismatch = feature_info_->ext_color_buffer_float_available() ?
13897 (GLES2Util::IsIntegerFormat(internal_format) != 13902 (GLES2Util::IsIntegerFormat(internal_format) !=
13898 GLES2Util::IsIntegerFormat(read_format)) : 13903 GLES2Util::IsIntegerFormat(read_format)) :
13899 GLES2Util::IsFloatFormat(internal_format); 13904 GLES2Util::IsFloatFormat(internal_format);
13900 if (color_encoding != GetColorEncodingFromInternalFormat(internal_format) || 13905 if (color_encoding != GetColorEncodingFromInternalFormat(internal_format) ||
13901 float_mismatch || 13906 float_mismatch ||
13902 (GLES2Util::IsSignedIntegerFormat(internal_format) != 13907 (GLES2Util::IsSignedIntegerFormat(internal_format) !=
13903 GLES2Util::IsSignedIntegerFormat(read_format)) || 13908 GLES2Util::IsSignedIntegerFormat(read_format)) ||
13904 (GLES2Util::IsUnsignedIntegerFormat(internal_format) != 13909 (GLES2Util::IsUnsignedIntegerFormat(internal_format) !=
13905 GLES2Util::IsUnsignedIntegerFormat(read_format))) { 13910 GLES2Util::IsUnsignedIntegerFormat(read_format))) {
13906 LOCAL_SET_GL_ERROR( 13911 *output_error_msg = std::string("incompatible format");
13907 GL_INVALID_OPERATION, func_name, "incompatible format");
13908 return false; 13912 return false;
13909 } 13913 }
13910 } 13914 }
13911 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { 13915 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) {
13912 LOCAL_SET_GL_ERROR( 13916 *output_error_msg =
13913 GL_INVALID_OPERATION, 13917 std::string("can not be used with depth or stencil textures");
13914 func_name, "can not be used with depth or stencil textures");
13915 return false; 13918 return false;
13916 } 13919 }
13917 if (feature_info_->IsWebGL2OrES3Context()) { 13920 if (feature_info_->IsWebGL2OrES3Context()) {
13918 if (GLES2Util::IsSizedColorFormat(internal_format)) { 13921 if (GLES2Util::IsSizedColorFormat(internal_format)) {
13919 int sr, sg, sb, sa; 13922 int sr, sg, sb, sa;
13920 GLES2Util::GetColorFormatComponentSizes( 13923 GLES2Util::GetColorFormatComponentSizes(
13921 read_format, read_type, &sr, &sg, &sb, &sa); 13924 read_format, read_type, &sr, &sg, &sb, &sa);
13922 DCHECK(sr > 0 || sg > 0 || sb > 0 || sa > 0); 13925 DCHECK(sr > 0 || sg > 0 || sb > 0 || sa > 0);
13923 int dr, dg, db, da; 13926 int dr, dg, db, da;
13924 GLES2Util::GetColorFormatComponentSizes( 13927 GLES2Util::GetColorFormatComponentSizes(
13925 internal_format, 0, &dr, &dg, &db, &da); 13928 internal_format, 0, &dr, &dg, &db, &da);
13926 DCHECK(dr > 0 || dg > 0 || db > 0 || da > 0); 13929 DCHECK(dr > 0 || dg > 0 || db > 0 || da > 0);
13927 if ((dr > 0 && sr != dr) || 13930 if ((dr > 0 && sr != dr) ||
13928 (dg > 0 && sg != dg) || 13931 (dg > 0 && sg != dg) ||
13929 (db > 0 && sb != db) || 13932 (db > 0 && sb != db) ||
13930 (da > 0 && sa != da)) { 13933 (da > 0 && sa != da)) {
13931 LOCAL_SET_GL_ERROR( 13934 *output_error_msg = std::string("incompatible color component sizes");
13932 GL_INVALID_OPERATION,
13933 func_name, "incompatible color component sizes");
13934 return false; 13935 return false;
13935 } 13936 }
13936 } 13937 }
13937 } 13938 }
13938 return true; 13939 return true;
13939 } 13940 }
13940 13941
13942 bool GLES2DecoderImpl::ValidateCopyTexFormat(const char* func_name,
13943 GLenum internal_format,
13944 GLenum read_format,
13945 GLenum read_type) {
13946 std::string output_error_msg;
13947 if (!ValidateCopyTexFormatHelper(internal_format, read_format, read_type,
13948 &output_error_msg)) {
13949 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name,
13950 output_error_msg.c_str());
13951 return false;
13952 }
13953 return true;
13954 }
13955
13941 void GLES2DecoderImpl::DoCopyTexImage2D( 13956 void GLES2DecoderImpl::DoCopyTexImage2D(
13942 GLenum target, 13957 GLenum target,
13943 GLint level, 13958 GLint level,
13944 GLenum internal_format, 13959 GLenum internal_format,
13945 GLint x, 13960 GLint x,
13946 GLint y, 13961 GLint y,
13947 GLsizei width, 13962 GLsizei width,
13948 GLsizei height, 13963 GLsizei height,
13949 GLint border) { 13964 GLint border) {
13950 const char* func_name = "glCopyTexImage2D"; 13965 const char* func_name = "glCopyTexImage2D";
(...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after
16133 case GL_TEXTURE_EXTERNAL_OES: 16148 case GL_TEXTURE_EXTERNAL_OES:
16134 break; 16149 break;
16135 default: 16150 default:
16136 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, 16151 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
16137 "invalid source texture target binding"); 16152 "invalid source texture target binding");
16138 return false; 16153 return false;
16139 } 16154 }
16140 return true; 16155 return true;
16141 } 16156 }
16142 16157
16143 bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUMInternalFormats( 16158 CopyTextureMethod GLES2DecoderImpl::ValidateCopyTextureCHROMIUMInternalFormats(
16144 const char* function_name, 16159 const char* function_name,
16145 TextureRef* source_texture_ref, 16160 TextureRef* source_texture_ref,
16146 GLenum dest_internal_format) { 16161 GLenum dest_internal_format) {
16147 GLenum source_type = 0; 16162 GLenum source_type = 0;
16148 GLenum source_internal_format = 0; 16163 GLenum source_internal_format = 0;
16149 Texture* source_texture = source_texture_ref->texture(); 16164 Texture* source_texture = source_texture_ref->texture();
16150 source_texture->GetLevelType(source_texture->target(), 0, &source_type, 16165 source_texture->GetLevelType(source_texture->target(), 0, &source_type,
16151 &source_internal_format); 16166 &source_internal_format);
16152 16167
16153 // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, 16168 bool valid_dest_format = false;
16154 // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not 16169 // TODO(qiankun.miao@intel.com): ALPHA, LUMINANCE and LUMINANCE_ALPHA formats
16155 // renderable on some platforms. 16170 // are not supported on GL core profile. See crbug.com/577144. Enable the
16156 bool valid_dest_format = 16171 // workaround for glCopyTexImage and glCopyTexSubImage in
16157 dest_internal_format == GL_RGB || dest_internal_format == GL_RGBA || 16172 // gles2_cmd_copy_tex_image.cc for glCopyTextureCHROMIUM implementation.
16158 dest_internal_format == GL_RGB8 || dest_internal_format == GL_RGBA8 || 16173 switch (dest_internal_format) {
16159 dest_internal_format == GL_BGRA_EXT || 16174 case GL_RGB:
16160 dest_internal_format == GL_BGRA8_EXT; 16175 case GL_RGBA:
16176 case GL_RGB8:
16177 case GL_RGBA8:
16178 valid_dest_format = true;
16179 break;
16180 case GL_BGRA_EXT:
16181 case GL_BGRA8_EXT:
16182 valid_dest_format =
16183 feature_info_->feature_flags().ext_texture_format_bgra8888;
16184 break;
16185 case GL_SRGB_EXT:
16186 case GL_SRGB_ALPHA_EXT:
16187 valid_dest_format = feature_info_->feature_flags().ext_srgb;
16188 break;
16189 case GL_R8:
16190 case GL_R8UI:
16191 case GL_RG8:
16192 case GL_RG8UI:
16193 case GL_SRGB8:
16194 case GL_RGB565:
16195 case GL_RGB8UI:
16196 case GL_SRGB8_ALPHA8:
16197 case GL_RGB5_A1:
16198 case GL_RGBA4:
16199 case GL_RGBA8UI:
16200 valid_dest_format = feature_info_->IsWebGL2OrES3Context();
16201 break;
16202 case GL_RGB9_E5:
16203 valid_dest_format = !gl_version_info().is_es;
16204 break;
16205 case GL_R16F:
16206 case GL_R32F:
16207 case GL_RG16F:
16208 case GL_RG32F:
16209 case GL_RGB16F:
16210 case GL_RGB32F:
16211 case GL_RGBA16F:
16212 case GL_RGBA32F:
16213 case GL_R11F_G11F_B10F:
16214 valid_dest_format = feature_info_->ext_color_buffer_float_available();
16215 break;
16216 default:
16217 valid_dest_format = false;
16218 break;
16219 }
16220
16161 bool valid_source_format = 16221 bool valid_source_format =
16162 source_internal_format == GL_RED || source_internal_format == GL_ALPHA || 16222 source_internal_format == GL_RED || source_internal_format == GL_ALPHA ||
16163 source_internal_format == GL_RGB || source_internal_format == GL_RGBA || 16223 source_internal_format == GL_RGB || source_internal_format == GL_RGBA ||
16164 source_internal_format == GL_RGB8 || source_internal_format == GL_RGBA8 || 16224 source_internal_format == GL_RGB8 || source_internal_format == GL_RGBA8 ||
16165 source_internal_format == GL_LUMINANCE || 16225 source_internal_format == GL_LUMINANCE ||
16166 source_internal_format == GL_LUMINANCE_ALPHA || 16226 source_internal_format == GL_LUMINANCE_ALPHA ||
16167 source_internal_format == GL_BGRA_EXT || 16227 source_internal_format == GL_BGRA_EXT ||
16168 source_internal_format == GL_BGRA8_EXT || 16228 source_internal_format == GL_BGRA8_EXT ||
16169 source_internal_format == GL_RGB_YCBCR_420V_CHROMIUM || 16229 source_internal_format == GL_RGB_YCBCR_420V_CHROMIUM ||
16170 source_internal_format == GL_RGB_YCBCR_422_CHROMIUM; 16230 source_internal_format == GL_RGB_YCBCR_422_CHROMIUM;
16171 if (!valid_source_format) { 16231 if (!valid_source_format) {
16172 std::string msg = "invalid source internal format " + 16232 std::string msg = "invalid source internal format " +
16173 GLES2Util::GetStringEnum(source_internal_format); 16233 GLES2Util::GetStringEnum(source_internal_format);
16174 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, 16234 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
16175 msg.c_str()); 16235 msg.c_str());
16176 return false; 16236 return NOT_COPYABLE;
16177 } 16237 }
16178 if (!valid_dest_format) { 16238 if (!valid_dest_format) {
16179 std::string msg = "invalid dest internal format " + 16239 std::string msg = "invalid dest internal format " +
16180 GLES2Util::GetStringEnum(dest_internal_format); 16240 GLES2Util::GetStringEnum(dest_internal_format);
16181 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, 16241 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
16182 msg.c_str()); 16242 msg.c_str());
16183 return false; 16243 return NOT_COPYABLE;
16184 } 16244 }
16185 return true; 16245
16246 bool source_format_color_renderable =
16247 Texture::ColorRenderable(GetFeatureInfo(), source_internal_format, false);
16248 bool dest_format_color_renderable =
16249 Texture::ColorRenderable(GetFeatureInfo(), dest_internal_format, false);
16250 std::string output_error_msg;
16251
16252 // CopyTexImage* should not allow internalformat of GL_BGRA_EXT and
16253 // GL_BGRA8_EXT. crbug.com/663086.
16254 bool copy_tex_image_format_valid =
16255 source_internal_format != GL_BGRA_EXT &&
16256 dest_internal_format != GL_BGRA_EXT &&
16257 source_internal_format != GL_BGRA8_EXT &&
16258 dest_internal_format != GL_BGRA8_EXT &&
16259 ValidateCopyTexFormatHelper(dest_internal_format, source_internal_format,
16260 source_type, &output_error_msg);
16261 if (source_format_color_renderable && copy_tex_image_format_valid)
16262 return DIRECT_COPY;
16263
16264 if (dest_format_color_renderable)
16265 return DIRECT_DRAW;
16266
16267 return DRAW_AND_COPY;
16186 } 16268 }
16187 16269
16188 bool GLES2DecoderImpl::ValidateCompressedCopyTextureCHROMIUM( 16270 bool GLES2DecoderImpl::ValidateCompressedCopyTextureCHROMIUM(
16189 const char* function_name, 16271 const char* function_name,
16190 TextureRef* source_texture_ref, 16272 TextureRef* source_texture_ref,
16191 TextureRef* dest_texture_ref) { 16273 TextureRef* dest_texture_ref) {
16192 if (!source_texture_ref || !dest_texture_ref) { 16274 if (!source_texture_ref || !dest_texture_ref) {
16193 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); 16275 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id");
16194 return false; 16276 return false;
16195 } 16277 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
16239 GLenum dest_type, 16321 GLenum dest_type,
16240 GLboolean unpack_flip_y, 16322 GLboolean unpack_flip_y,
16241 GLboolean unpack_premultiply_alpha, 16323 GLboolean unpack_premultiply_alpha,
16242 GLboolean unpack_unmultiply_alpha) { 16324 GLboolean unpack_unmultiply_alpha) {
16243 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); 16325 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM");
16244 static const char kFunctionName[] = "glCopyTextureCHROMIUM"; 16326 static const char kFunctionName[] = "glCopyTextureCHROMIUM";
16245 16327
16246 TextureRef* source_texture_ref = GetTexture(source_id); 16328 TextureRef* source_texture_ref = GetTexture(source_id);
16247 TextureRef* dest_texture_ref = GetTexture(dest_id); 16329 TextureRef* dest_texture_ref = GetTexture(dest_id);
16248 16330
16249 if (!texture_manager()->ValidateTextureParameters(
16250 GetErrorState(), kFunctionName, true, internal_format, dest_type,
16251 internal_format, 0))
16252 return;
16253
16254 if (!ValidateCopyTextureCHROMIUMTextures(kFunctionName, source_texture_ref, 16331 if (!ValidateCopyTextureCHROMIUMTextures(kFunctionName, source_texture_ref,
16255 dest_texture_ref)) { 16332 dest_texture_ref)) {
16256 return; 16333 return;
16257 } 16334 }
16258 16335
16259 if (!ValidateCopyTextureCHROMIUMInternalFormats(
16260 kFunctionName, source_texture_ref, internal_format)) {
16261 return;
16262 }
16263
16264 Texture* source_texture = source_texture_ref->texture(); 16336 Texture* source_texture = source_texture_ref->texture();
16265 Texture* dest_texture = dest_texture_ref->texture(); 16337 Texture* dest_texture = dest_texture_ref->texture();
16266 GLenum source_target = source_texture->target(); 16338 GLenum source_target = source_texture->target();
16267 GLenum dest_target = dest_texture->target(); 16339 GLenum dest_target = dest_texture->target();
16340
16341 GLenum source_type = 0;
16342 GLenum source_internal_format = 0;
16343 source_texture->GetLevelType(source_target, 0, &source_type,
16344 &source_internal_format);
16345 GLenum format =
16346 TextureManager::ExtractFormatFromStorageFormat(internal_format);
16347 if (!texture_manager()->ValidateTextureParameters(
16348 GetErrorState(), kFunctionName, true, format, dest_type,
16349 internal_format, 0)) {
16350 return;
16351 }
16352
16353 CopyTextureMethod method = ValidateCopyTextureCHROMIUMInternalFormats(
16354 kFunctionName, source_texture_ref, internal_format);
16355 // INVALID_OPERATION is already generated by
16356 // ValidateCopyTextureCHROMIUMInternalFormats.
16357 if (NOT_COPYABLE == method) {
16358 return;
16359 }
16360
16361 if (feature_info_->feature_flags().desktop_srgb_support) {
16362 bool enable_framebuffer_srgb =
16363 GetColorEncodingFromInternalFormat(source_internal_format) == GL_SRGB ||
16364 GetColorEncodingFromInternalFormat(internal_format) == GL_SRGB;
16365 state_.EnableDisableFramebufferSRGB(enable_framebuffer_srgb);
16366 }
16367
16268 int source_width = 0; 16368 int source_width = 0;
16269 int source_height = 0; 16369 int source_height = 0;
16270 gl::GLImage* image = 16370 gl::GLImage* image =
16271 source_texture->GetLevelImage(source_target, 0); 16371 source_texture->GetLevelImage(source_target, 0);
16272 if (image) { 16372 if (image) {
16273 gfx::Size size = image->GetSize(); 16373 gfx::Size size = image->GetSize();
16274 source_width = size.width(); 16374 source_width = size.width();
16275 source_height = size.height(); 16375 source_height = size.height();
16276 if (source_width <= 0 || source_height <= 0) { 16376 if (source_width <= 0 || source_height <= 0) {
16277 LOCAL_SET_GL_ERROR( 16377 LOCAL_SET_GL_ERROR(
(...skipping 11 matching lines...) Expand all
16289 } 16389 }
16290 16390
16291 // Check that this type of texture is allowed. 16391 // Check that this type of texture is allowed.
16292 if (!texture_manager()->ValidForTarget(source_target, 0, 16392 if (!texture_manager()->ValidForTarget(source_target, 0,
16293 source_width, source_height, 1)) { 16393 source_width, source_height, 1)) {
16294 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, "Bad dimensions"); 16394 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, "Bad dimensions");
16295 return; 16395 return;
16296 } 16396 }
16297 } 16397 }
16298 16398
16299 GLenum source_type = 0;
16300 GLenum source_internal_format = 0;
16301 source_texture->GetLevelType(source_target, 0, &source_type,
16302 &source_internal_format);
16303
16304 if (dest_texture->IsImmutable()) { 16399 if (dest_texture->IsImmutable()) {
16305 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, kFunctionName, 16400 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, kFunctionName,
16306 "texture is immutable"); 16401 "texture is immutable");
16307 return; 16402 return;
16308 } 16403 }
16309 16404
16310 // Clear the source texture if necessary. 16405 // Clear the source texture if necessary.
16311 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, 16406 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
16312 source_target, 0)) { 16407 source_target, 0)) {
16313 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, "dimensions too big"); 16408 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, "dimensions too big");
(...skipping 16 matching lines...) Expand all
16330 } 16425 }
16331 16426
16332 // Resize the destination texture to the dimensions of the source texture. 16427 // Resize the destination texture to the dimensions of the source texture.
16333 if (!dest_level_defined || dest_width != source_width || 16428 if (!dest_level_defined || dest_width != source_width ||
16334 dest_height != source_height || 16429 dest_height != source_height ||
16335 dest_internal_format != internal_format || 16430 dest_internal_format != internal_format ||
16336 dest_type_previous != dest_type) { 16431 dest_type_previous != dest_type) {
16337 // Ensure that the glTexImage2D succeeds. 16432 // Ensure that the glTexImage2D succeeds.
16338 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); 16433 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName);
16339 glBindTexture(dest_target, dest_texture->service_id()); 16434 glBindTexture(dest_target, dest_texture->service_id());
16340 glTexImage2D( 16435 glTexImage2D(dest_target, 0, TextureManager::AdjustTexInternalFormat(
16341 dest_target, 0, TextureManager::AdjustTexInternalFormat( 16436 feature_info_.get(), internal_format),
16342 feature_info_.get(), internal_format), 16437 source_width, source_height, 0,
16343 source_width, source_height, 0, 16438 TextureManager::AdjustTexFormat(feature_info_.get(), format),
16344 TextureManager::AdjustTexFormat(feature_info_.get(), internal_format), 16439 dest_type, NULL);
16345 dest_type, NULL);
16346 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); 16440 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName);
16347 if (error != GL_NO_ERROR) { 16441 if (error != GL_NO_ERROR) {
16348 RestoreCurrentTextureBindings(&state_, dest_target); 16442 RestoreCurrentTextureBindings(&state_, dest_target);
16349 return; 16443 return;
16350 } 16444 }
16351 16445
16352 texture_manager()->SetLevelInfo( 16446 texture_manager()->SetLevelInfo(dest_texture_ref, dest_target, 0,
16353 dest_texture_ref, dest_target, 0, internal_format, source_width, 16447 internal_format, source_width,
16354 source_height, 1, 0, internal_format, dest_type, 16448 source_height, 1, 0, format, dest_type,
16355 gfx::Rect(source_width, source_height)); 16449 gfx::Rect(source_width, source_height));
16356 dest_texture->ApplyFormatWorkarounds(feature_info_.get()); 16450 dest_texture->ApplyFormatWorkarounds(feature_info_.get());
16357 } else { 16451 } else {
16358 texture_manager()->SetLevelCleared(dest_texture_ref, dest_target, 0, 16452 texture_manager()->SetLevelCleared(dest_texture_ref, dest_target, 0, true);
16359 true);
16360 } 16453 }
16361 16454
16362 // Try using GLImage::CopyTexImage when possible. 16455 // Try using GLImage::CopyTexImage when possible.
16363 bool unpack_premultiply_alpha_change = 16456 bool unpack_premultiply_alpha_change =
16364 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; 16457 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0;
16365 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { 16458 if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) {
16366 glBindTexture(dest_target, dest_texture->service_id()); 16459 glBindTexture(dest_target, dest_texture->service_id());
16367 if (image->CopyTexImage(dest_target)) 16460 if (image->CopyTexImage(dest_target))
16368 return; 16461 return;
16369 } 16462 }
16370 16463
16371 DoCopyTexImageIfNeeded(source_texture, source_target); 16464 DoCopyTexImageIfNeeded(source_texture, source_target);
16372 16465
16373 // GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix 16466 // GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix
16374 // before presenting. 16467 // before presenting.
16375 if (source_target == GL_TEXTURE_EXTERNAL_OES) { 16468 if (source_target == GL_TEXTURE_EXTERNAL_OES) {
16376 if (GLStreamTextureImage* image = 16469 if (GLStreamTextureImage* image =
16377 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, 16470 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES,
16378 0)) { 16471 0)) {
16379 GLfloat transform_matrix[16]; 16472 GLfloat transform_matrix[16];
16380 image->GetTextureMatrix(transform_matrix); 16473 image->GetTextureMatrix(transform_matrix);
16381 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( 16474 copy_texture_CHROMIUM_->DoCopyTextureWithTransform(
16382 this, source_target, source_texture->service_id(), dest_target, 16475 this, source_target, source_texture->service_id(),
16383 dest_texture->service_id(), source_width, source_height, 16476 source_internal_format, dest_target, dest_texture->service_id(),
16477 internal_format, source_width, source_height,
16384 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE, 16478 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE,
16385 unpack_unmultiply_alpha == GL_TRUE, transform_matrix); 16479 unpack_unmultiply_alpha == GL_TRUE, transform_matrix);
16386 return; 16480 return;
16387 } 16481 }
16388 } 16482 }
16483
16389 copy_texture_CHROMIUM_->DoCopyTexture( 16484 copy_texture_CHROMIUM_->DoCopyTexture(
16390 this, source_target, source_texture->service_id(), source_internal_format, 16485 this, source_target, source_texture->service_id(), source_internal_format,
16391 dest_target, dest_texture->service_id(), internal_format, source_width, 16486 dest_target, dest_texture->service_id(), internal_format, source_width,
16392 source_height, unpack_flip_y == GL_TRUE, 16487 source_height, unpack_flip_y == GL_TRUE,
16393 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE); 16488 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE,
16489 method);
16394 } 16490 }
16395 16491
16396 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( 16492 void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(
16397 GLuint source_id, 16493 GLuint source_id,
16398 GLuint dest_id, 16494 GLuint dest_id,
16399 GLint xoffset, 16495 GLint xoffset,
16400 GLint yoffset, 16496 GLint yoffset,
16401 GLint x, 16497 GLint x,
16402 GLint y, 16498 GLint y,
16403 GLsizei width, 16499 GLsizei width,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
16485 "destination texture is not defined"); 16581 "destination texture is not defined");
16486 return; 16582 return;
16487 } 16583 }
16488 if (!dest_texture->ValidForTexture(dest_target, 0, xoffset, 16584 if (!dest_texture->ValidForTexture(dest_target, 0, xoffset,
16489 yoffset, 0, width, height, 1)) { 16585 yoffset, 0, width, height, 1)) {
16490 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName, 16586 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, kFunctionName,
16491 "destination texture bad dimensions."); 16587 "destination texture bad dimensions.");
16492 return; 16588 return;
16493 } 16589 }
16494 16590
16495 if (!ValidateCopyTextureCHROMIUMInternalFormats( 16591 CopyTextureMethod method = ValidateCopyTextureCHROMIUMInternalFormats(
16496 kFunctionName, source_texture_ref, dest_internal_format)) { 16592 kFunctionName, source_texture_ref, dest_internal_format);
16593 // INVALID_OPERATION is already generated by
16594 // ValidateCopyTextureCHROMIUMInternalFormats.
16595 if (NOT_COPYABLE == method) {
16497 return; 16596 return;
16498 } 16597 }
16499 16598
16599 if (feature_info_->feature_flags().desktop_srgb_support) {
16600 bool enable_framebuffer_srgb =
16601 GetColorEncodingFromInternalFormat(source_internal_format) == GL_SRGB ||
16602 GetColorEncodingFromInternalFormat(dest_internal_format) == GL_SRGB;
16603 state_.EnableDisableFramebufferSRGB(enable_framebuffer_srgb);
16604 }
16605
16500 // Clear the source texture if necessary. 16606 // Clear the source texture if necessary.
16501 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, 16607 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref,
16502 source_target, 0)) { 16608 source_target, 0)) {
16503 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName, 16609 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, kFunctionName,
16504 "source texture dimensions too big"); 16610 "source texture dimensions too big");
16505 return; 16611 return;
16506 } 16612 }
16507 16613
16508 if (!InitializeCopyTextureCHROMIUM(kFunctionName)) 16614 if (!InitializeCopyTextureCHROMIUM(kFunctionName))
16509 return; 16615 return;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
16568 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE, 16674 unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE,
16569 unpack_unmultiply_alpha == GL_TRUE, transform_matrix); 16675 unpack_unmultiply_alpha == GL_TRUE, transform_matrix);
16570 return; 16676 return;
16571 } 16677 }
16572 } 16678 }
16573 copy_texture_CHROMIUM_->DoCopySubTexture( 16679 copy_texture_CHROMIUM_->DoCopySubTexture(
16574 this, source_target, source_texture->service_id(), source_internal_format, 16680 this, source_target, source_texture->service_id(), source_internal_format,
16575 dest_target, dest_texture->service_id(), dest_internal_format, xoffset, 16681 dest_target, dest_texture->service_id(), dest_internal_format, xoffset,
16576 yoffset, x, y, width, height, dest_width, dest_height, source_width, 16682 yoffset, x, y, width, height, dest_width, dest_height, source_width,
16577 source_height, unpack_flip_y == GL_TRUE, 16683 source_height, unpack_flip_y == GL_TRUE,
16578 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE); 16684 unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE,
16685 method);
16579 } 16686 }
16580 16687
16581 bool GLES2DecoderImpl::InitializeCopyTexImageBlitter( 16688 bool GLES2DecoderImpl::InitializeCopyTexImageBlitter(
16582 const char* function_name) { 16689 const char* function_name) {
16583 if (!copy_tex_image_blit_.get()) { 16690 if (!copy_tex_image_blit_.get()) {
16584 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); 16691 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name);
16585 copy_tex_image_blit_.reset( 16692 copy_tex_image_blit_.reset(
16586 new CopyTexImageResourceManager(feature_info_.get())); 16693 new CopyTexImageResourceManager(feature_info_.get()));
16587 copy_tex_image_blit_->Initialize(this); 16694 copy_tex_image_blit_->Initialize(this);
16588 if (LOCAL_PEEK_GL_ERROR(function_name) != GL_NO_ERROR) 16695 if (LOCAL_PEEK_GL_ERROR(function_name) != GL_NO_ERROR)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
16743 16850
16744 texture_manager()->SetLevelInfo( 16851 texture_manager()->SetLevelInfo(
16745 dest_texture_ref, dest_texture->target(), 0, GL_RGBA, source_width, 16852 dest_texture_ref, dest_texture->target(), 0, GL_RGBA, source_width,
16746 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 16853 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
16747 gfx::Rect(source_width, source_height)); 16854 gfx::Rect(source_width, source_height));
16748 16855
16749 copy_texture_CHROMIUM_->DoCopyTexture( 16856 copy_texture_CHROMIUM_->DoCopyTexture(
16750 this, source_texture->target(), source_texture->service_id(), 16857 this, source_texture->target(), source_texture->service_id(),
16751 source_internal_format, dest_texture->target(), 16858 source_internal_format, dest_texture->target(),
16752 dest_texture->service_id(), GL_RGBA, source_width, source_height, false, 16859 dest_texture->service_id(), GL_RGBA, source_width, source_height, false,
16753 false, false); 16860 false, false, DIRECT_DRAW);
16754 } 16861 }
16755 16862
16756 void GLES2DecoderImpl::TexStorageImpl(GLenum target, 16863 void GLES2DecoderImpl::TexStorageImpl(GLenum target,
16757 GLsizei levels, 16864 GLsizei levels,
16758 GLenum internal_format, 16865 GLenum internal_format,
16759 GLsizei width, 16866 GLsizei width,
16760 GLsizei height, 16867 GLsizei height,
16761 GLsizei depth, 16868 GLsizei depth,
16762 ContextState::Dimension dimension, 16869 ContextState::Dimension dimension,
16763 const char* function_name) { 16870 const char* function_name) {
(...skipping 2231 matching lines...) Expand 10 before | Expand all | Expand 10 after
18995 } 19102 }
18996 19103
18997 // Include the auto-generated part of this file. We split this because it means 19104 // Include the auto-generated part of this file. We split this because it means
18998 // we can easily edit the non-auto generated parts right here in this file 19105 // we can easily edit the non-auto generated parts right here in this file
18999 // instead of having to edit some template or the code generator. 19106 // instead of having to edit some template or the code generator.
19000 #include "base/macros.h" 19107 #include "base/macros.h"
19001 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 19108 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
19002 19109
19003 } // namespace gles2 19110 } // namespace gles2
19004 } // namespace gpu 19111 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc ('k') | gpu/command_buffer/service/texture_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698