Index: gpu/command_buffer/service/gles2_cmd_decoder.cc |
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
index 29d4d5d14e6925ecb99c98dca01097106bcc69b1..7be1648ce0392e790212c4ce5cf9268f08d66b0d 100644 |
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc |
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
@@ -969,6 +969,13 @@ class GLES2DecoderImpl : public GLES2Decoder, |
GLint xoffset, |
GLint yoffset); |
+ void DoCopyCompressedTextureCHROMIUM(GLenum target, |
+ GLuint source_id, |
+ GLuint dest_id, |
+ GLenum internal_format, |
+ GLenum dest_type, |
+ GLsizei source_size); |
+ |
// Wrapper for TexStorage2DEXT. |
void DoTexStorage2DEXT( |
GLenum target, |
@@ -1697,6 +1704,11 @@ class GLES2DecoderImpl : public GLES2Decoder, |
TextureRef* source_texture_ref, |
TextureRef* dest_texture_ref, |
GLenum dest_internal_format); |
+ bool ValidateCopyCompressedTextureCHROMIUM(const char* function_name, |
+ GLenum target, |
+ TextureRef* source_texture_ref, |
+ TextureRef* dest_texture_ref, |
+ GLenum dest_internal_format); |
void RenderWarning(const char* filename, int line, const std::string& msg); |
void PerformanceWarning( |
@@ -11523,6 +11535,65 @@ bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUM( |
return true; |
} |
+bool GLES2DecoderImpl::ValidateCopyCompressedTextureCHROMIUM( |
+ const char* function_name, |
+ GLenum target, |
+ TextureRef* source_texture_ref, |
+ TextureRef* dest_texture_ref, |
+ GLenum dest_internal_format) { |
+ if (!source_texture_ref || !dest_texture_ref) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); |
+ return false; |
+ } |
+ |
+ if (GL_TEXTURE_2D != target) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
+ "invalid texture target"); |
+ return false; |
+ } |
+ |
+ Texture* source_texture = source_texture_ref->texture(); |
+ Texture* dest_texture = dest_texture_ref->texture(); |
+ if (source_texture == dest_texture) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
+ "source and destination textures are the same"); |
+ return false; |
+ } |
+ |
+ if (dest_texture->target() != GL_TEXTURE_2D || |
+ (source_texture->target() != GL_TEXTURE_2D && |
+ source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && |
+ source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
+ "invalid texture target binding"); |
+ return false; |
+ } |
+ |
+ GLenum source_type = 0; |
+ GLenum source_internal_format = 0; |
+ source_texture->GetLevelType(source_texture->target(), 0, &source_type, |
+ &source_internal_format); |
+ |
+ bool valid_dest_format = |
+ dest_internal_format == GL_ATC_RGB_AMD || |
+ dest_internal_format == GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD || |
+ dest_internal_format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT || |
+ dest_internal_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT || |
+ dest_internal_format == GL_ETC1_RGB8_OES; |
+ bool valid_source_format = source_internal_format == GL_ALPHA || |
+ source_internal_format == GL_RGB || |
+ source_internal_format == GL_RGBA || |
+ source_internal_format == GL_LUMINANCE || |
+ source_internal_format == GL_LUMINANCE_ALPHA || |
+ 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.
|
+ if (!valid_source_format || !valid_dest_format) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
+ "invalid internal format"); |
+ return false; |
+ } |
+ return true; |
+} |
+ |
void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target, |
GLuint source_id, |
GLuint dest_id, |
@@ -11813,6 +11884,111 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(GLenum target, |
DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
} |
+void GLES2DecoderImpl::DoCopyCompressedTextureCHROMIUM(GLenum target, |
+ GLuint source_id, |
+ GLuint dest_id, |
+ GLenum internal_format, |
+ GLenum dest_type, |
+ GLsizei source_size) { |
+ TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyCompressedTextureCHROMIUM"); |
+ |
+ TextureRef* source_texture_ref = GetTexture(source_id); |
+ TextureRef* dest_texture_ref = GetTexture(dest_id); |
+ Texture* source_texture = source_texture_ref->texture(); |
+ Texture* dest_texture = dest_texture_ref->texture(); |
+ gfx::GLImage* image = |
+ source_texture->GetLevelImage(source_texture->target(), 0); |
+ if (!image) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopyCompressedTextureCHROMIUM", |
+ "no mage"); |
+ return; |
+ } |
+ |
+ gfx::Size size = image->GetSize(); |
+ int source_width = size.width(); |
+ int source_height = size.height(); |
+ if (source_width <= 0 || source_height <= 0) { |
+ LOCAL_SET_GL_ERROR( |
+ GL_INVALID_VALUE, |
+ "glCopyCompressedTextureCHROMIUM", "invalid image size"); |
+ return; |
+ } |
+ |
+ GLenum source_type = 0; |
+ GLenum source_internal_format = 0; |
+ source_texture->GetLevelType( |
+ source_texture->target(), 0, &source_type, &source_internal_format); |
+ |
+ if (dest_texture->IsImmutable()) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
+ "glCopyCompressedTextureCHROMIUM", |
+ "texture is immutable"); |
+ return; |
+ } |
+ |
+ if (!ValidateCopyCompressedTextureCHROMIUM( |
+ "glCopyCompressedTextureCHROMIUM", |
+ target, |
+ source_texture_ref, dest_texture_ref, |
+ internal_format)) { |
+ return; |
+ } |
+ |
+ // Clear the source texture if necessary. |
+ if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, |
+ source_texture->target(), 0)) { |
+ LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyCompressedTextureCHROMIUM", |
+ "dimensions too big"); |
+ return; |
+ } |
+ |
+ GLenum dest_type_previous = dest_type; |
+ GLenum dest_internal_format = internal_format; |
+ int dest_width = 0; |
+ int dest_height = 0; |
+ bool dest_level_defined = |
+ dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height); |
+ |
+ if (dest_level_defined) { |
+ dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type_previous, |
+ &dest_internal_format); |
+ } |
+ |
+ // Resize the destination texture to the dimensions of the source texture. |
+ if (!dest_level_defined || dest_width != source_width || |
+ dest_height != source_height || |
+ dest_internal_format != internal_format || |
+ dest_type_previous != dest_type) { |
+ // Ensure that the glCompressedTexImage2D succeeds. |
+ LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyCompressedTextureCHROMIUM"); |
+ glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
+ glCompressedTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, |
+ source_height, 0, source_size, NULL); |
+ GLenum error = LOCAL_PEEK_GL_ERROR("glCopyCompressedTextureCHROMIUM"); |
+ if (error != GL_NO_ERROR) { |
+ RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
+ return; |
+ } |
+ |
+ texture_manager()->SetLevelInfo( |
+ dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, |
+ source_height, 1, 0, internal_format, dest_type, true); |
+ } else { |
+ texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
+ true); |
+ } |
+ |
+ ScopedModifyPixels modify(dest_texture_ref); |
+ |
+ DCHECK(!unpack_flip_y_); |
+ DCHECK(!(unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_)); |
+ |
+ // Copying compressed textures is only supported using GLImage::CopyTexImage. |
+ glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
+ bool copy_result = image->CopyTexImage(GL_TEXTURE_2D); |
+ 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
|
+} |
+ |
static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
switch (internalformat) { |
case GL_RGB565: |