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..ae92d65132e6664053c3984bc88594b2aa8c85d1 100644 |
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc |
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
@@ -969,6 +969,12 @@ class GLES2DecoderImpl : public GLES2Decoder, |
GLint xoffset, |
GLint yoffset); |
+ void DoCompressedCopyTextureCHROMIUM(GLenum target, |
+ GLuint source_id, |
+ GLuint dest_id, |
+ GLenum internal_format, |
+ GLsizei source_size); |
+ |
// Wrapper for TexStorage2DEXT. |
void DoTexStorage2DEXT( |
GLenum target, |
@@ -1697,6 +1703,11 @@ class GLES2DecoderImpl : public GLES2Decoder, |
TextureRef* source_texture_ref, |
TextureRef* dest_texture_ref, |
GLenum dest_internal_format); |
+ bool ValidateCompressedCopyTextureCHROMIUM(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 +11534,67 @@ bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUM( |
return true; |
} |
+bool GLES2DecoderImpl::ValidateCompressedCopyTextureCHROMIUM( |
+ 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); |
+ |
+ if (dest_internal_format != source_internal_format) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
+ "source and destination formats doesn't match"); |
+ return false; |
+ } |
+ |
+ bool valid_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; |
+ |
+ if (!valid_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 +11885,174 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(GLenum target, |
DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
} |
+void GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM(GLenum target, |
+ GLuint source_id, |
+ GLuint dest_id, |
+ GLenum internal_format, |
+ GLsizei source_size) { |
+ TRACE_EVENT0("gpu", "GLES2DecoderImpl::DCompressedCopyTextureCHROMIUM"); |
+ |
+ 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(); |
+ int source_width = 0; |
+ int source_height = 0; |
+ gfx::GLImage* image = |
+ source_texture->GetLevelImage(source_texture->target(), 0); |
+ if (image) { |
piman
2015/06/09 00:24:19
Do we need these 2 separate paths? Presumably the
christiank
2015/06/11 07:31:57
I think you might be right. However, CopyTextureCH
|
+ gfx::Size size = image->GetSize(); |
+ source_width = size.width(); |
+ source_height = size.height(); |
+ if (source_width <= 0 || source_height <= 0) { |
+ LOCAL_SET_GL_ERROR( |
+ GL_INVALID_VALUE, |
+ "glCompressedCopyTextureCHROMIUM", "invalid image size"); |
+ return; |
+ } |
+ } else { |
+ if (!source_texture->GetLevelSize( |
+ source_texture->target(), 0, &source_width, &source_height)) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
+ "glCompressedCopyTextureCHROMIUM", |
+ "source texture has no level 0"); |
+ return; |
+ } |
+ |
+ // Check that this type of texture is allowed. |
+ if (!texture_manager()->ValidForTarget(source_texture->target(), 0, |
+ source_width, source_height, 1)) { |
piman
2015/06/09 00:24:19
Is this needed? The validity should have been test
christiank
2015/06/11 07:31:57
I don't think so. But same thing here, CopyTexture
|
+ LOCAL_SET_GL_ERROR( |
+ GL_INVALID_VALUE, "glCompressedCopyTextureCHROMIUM", |
+ "Bad dimensions"); |
+ 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, |
+ "glCompressedCopyTextureCHROMIUM", |
+ "texture is immutable"); |
+ return; |
+ } |
+ |
+ if (!ValidateCompressedCopyTextureCHROMIUM( |
+ "glCompressedCopyTextureCHROMIUM", |
+ target, |
+ source_texture_ref, dest_texture_ref, |
+ internal_format)) { |
+ return; |
+ } |
+ |
+ // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
+ // needed because it takes 10s of milliseconds to initialize. |
+ if (!copy_texture_CHROMIUM_.get()) { |
+ LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
+ copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
+ copy_texture_CHROMIUM_->Initialize(this); |
+ RestoreCurrentFramebufferBindings(); |
+ if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) |
+ 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, "glCompressedCopyTextureCHROMIUM", |
+ "dimensions too big"); |
+ return; |
+ } |
+ |
+ int dest_width = 0; |
+ int dest_height = 0; |
+ bool dest_level_defined = |
+ dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height); |
+ |
+ // Resize the destination texture to the dimensions of the source texture. |
+ if (!dest_level_defined || dest_width != source_width || |
+ dest_height != source_height) { |
piman
2015/06/09 00:24:19
What if it was defined, but not as a compressed te
christiank
2015/06/11 07:31:56
Done.
|
+ // Ensure that the glCompressedTexImage2D succeeds. |
+ LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); |
+ glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
+ glCompressedTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, |
+ source_height, 0, source_size, NULL); |
piman
2015/06/09 00:24:19
Really, this is only useful if we have an image. I
christiank
2015/06/11 07:31:56
Done.
|
+ GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopyTextureCHROMIUM"); |
+ 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, source_type, true); |
+ } else { |
+ texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
+ true); |
+ } |
+ |
+ ScopedModifyPixels modify(dest_texture_ref); |
+ |
+ bool unpack_premultiply_alpha_change = |
+ unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_; |
+ if (unpack_flip_y_ || unpack_premultiply_alpha_change) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCompressedCopyTextureCHROMIUM", |
+ "pixel-storage multipliers are not supported"); |
+ } |
+ |
+ // Try using GLImage::CopyTexImage when possible. |
+ if (image) { |
+ glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
+ if (image->CopyTexImage(GL_TEXTURE_2D)) |
+ return; |
+ } |
+ |
+ TRACE_EVENT0( |
+ "gpu", |
+ "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); |
+ |
+ DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
+ |
+ // As a fallback, copy into a non-compressed GL_RGBA texture. |
+ LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); |
+ glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, source_width, source_height, |
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
+ GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopyTextureCHROMIUM"); |
+ if (error != GL_NO_ERROR) { |
+ RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
+ return; |
+ } |
+ |
+ texture_manager()->SetLevelInfo( |
+ dest_texture_ref, GL_TEXTURE_2D, 0, GL_RGBA, source_width, |
+ source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); |
+ |
+ // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
+ // before presenting. |
+ if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
+ // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
+ // instead of using kIdentityMatrix crbug.com/226218. |
+ copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
+ this, source_texture->target(), source_texture->service_id(), |
+ dest_texture->service_id(), source_width, source_height, |
+ unpack_flip_y_, unpack_premultiply_alpha_, |
+ unpack_unpremultiply_alpha_, kIdentityMatrix); |
+ } else { |
+ copy_texture_CHROMIUM_->DoCopyTexture( |
+ this, source_texture->target(), source_texture->service_id(), |
+ source_internal_format, dest_texture->service_id(), GL_RGBA, |
+ source_width, source_height, unpack_flip_y_, |
+ unpack_premultiply_alpha_, unpack_unpremultiply_alpha_); |
+ } |
+ |
+ DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
+} |
+ |
static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
switch (internalformat) { |
case GL_RGB565: |