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 50ae103d860006ede0a77f697f8ff3afcba977a4..0af70c706503c2d5dcfc2e30a0f0e7faf38edcf8 100644 |
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc |
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
@@ -81,10 +81,15 @@ namespace gles2 { |
namespace { |
-static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
-static const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; |
-static const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; |
-static const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod"; |
+const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
+const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; |
+const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; |
+const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod"; |
+ |
+const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
+ 0.0f, 1.0f, 0.0f, 0.0f, |
+ 0.0f, 0.0f, 1.0f, 0.0f, |
+ 0.0f, 0.0f, 0.0f, 1.0f}; |
static bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, |
GLint rangeMax, |
@@ -936,13 +941,17 @@ class GLES2DecoderImpl : public GLES2Decoder, |
GLuint io_surface_id, |
GLuint plane); |
- void DoCopyTextureCHROMIUM( |
- GLenum target, |
- GLuint source_id, |
- GLuint target_id, |
- GLint level, |
- GLenum internal_format, |
- GLenum dest_type); |
+ void DoCopyTextureCHROMIUM(GLenum target, |
+ GLuint source_id, |
+ GLuint dest_id, |
+ GLenum internal_format, |
+ GLenum dest_type); |
+ |
+ void DoCopySubTextureCHROMIUM(GLenum target, |
+ GLuint source_id, |
+ GLuint dest_id, |
+ GLint xoffset, |
+ GLint yoffset); |
// Wrapper for TexStorage2DEXT. |
void DoTexStorage2DEXT( |
@@ -1659,6 +1668,11 @@ class GLES2DecoderImpl : public GLES2Decoder, |
GLenum target, GLint level, GLint xoffset, GLint yoffset, |
GLsizei width, GLsizei height, GLenum format, |
Texture* texture); |
+ bool ValidateCopyTextureCHROMIUM(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( |
@@ -10934,40 +10948,78 @@ static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { |
} |
} |
-void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
- GLenum target, GLuint source_id, GLuint dest_id, GLint level, |
- GLenum internal_format, GLenum dest_type) { |
- TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); |
- |
- TextureRef* dest_texture_ref = GetTexture(dest_id); |
- TextureRef* source_texture_ref = GetTexture(source_id); |
- |
+bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUM( |
+ 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, "glCopyTextureCHROMIUM", "unknown texture id"); |
- return; |
+ 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, "glCopyTextureCHROMIUM", "invalid texture target"); |
- return; |
+ 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, |
- "glCopyTextureCHROMIUM", |
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
"invalid texture target binding"); |
- return; |
+ return false; |
+ } |
+ |
+ GLenum source_type = 0; |
+ GLenum source_internal_format = 0; |
+ source_texture->GetLevelType(source_texture->target(), 0, &source_type, |
+ &source_internal_format); |
+ |
+ // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, |
+ // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not |
+ // renderable on some platforms. |
+ bool valid_dest_format = dest_internal_format == GL_RGB || |
+ dest_internal_format == GL_RGBA || |
+ dest_internal_format == GL_BGRA_EXT; |
+ 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; |
+ if (!valid_source_format || !valid_dest_format) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
+ "invalid internal format"); |
+ return false; |
} |
+ return true; |
+} |
- int source_width, source_height, dest_width, dest_height; |
+void GLES2DecoderImpl::DoCopyTextureCHROMIUM(GLenum target, |
+ GLuint source_id, |
+ GLuint dest_id, |
+ GLenum internal_format, |
+ GLenum dest_type) { |
+ TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); |
+ 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) { |
@@ -10990,43 +11042,36 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
} |
// Check that this type of texture is allowed. |
- if (!texture_manager()->ValidForTarget( |
- source_texture->target(), level, source_width, source_height, 1)) { |
+ if (!texture_manager()->ValidForTarget(source_texture->target(), 0, |
+ source_width, source_height, 1)) { |
LOCAL_SET_GL_ERROR( |
GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); |
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, "glCopyTextureCHROMIUM", "dimensions too big"); |
- return; |
- } |
- |
GLenum source_type = 0; |
GLenum source_internal_format = 0; |
source_texture->GetLevelType( |
source_texture->target(), 0, &source_type, &source_internal_format); |
- // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, |
- // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not |
- // renderable on some platforms. |
- bool valid_dest_format = internal_format == GL_RGB || |
- internal_format == GL_RGBA || |
- internal_format == GL_BGRA_EXT; |
- 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; |
- if (!valid_source_format || !valid_dest_format) { |
- LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
- "glCopyTextureCHROMIUM", |
- "invalid internal format"); |
+ if (dest_texture->IsImmutable()) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopyTextureCHROMIUM", |
+ "texture is immutable"); |
+ return; |
+ } |
+ |
+ if (!ValidateCopyTextureCHROMIUM("glCopyTextureCHROMIUM", 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, "glCopyTextureCHROMIUM", |
+ "dimensions too big"); |
return; |
} |
@@ -11043,11 +11088,13 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
GLenum dest_type_previous = dest_type; |
GLenum dest_internal_format = internal_format; |
- bool dest_level_defined = dest_texture->GetLevelSize( |
- GL_TEXTURE_2D, level, &dest_width, &dest_height); |
+ 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, level, &dest_type_previous, |
+ dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type_previous, |
&dest_internal_format); |
} |
@@ -11059,9 +11106,8 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
// Ensure that the glTexImage2D succeeds. |
LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
- glTexImage2D( |
- GL_TEXTURE_2D, level, internal_format, source_width, source_height, |
- 0, internal_format, dest_type, NULL); |
+ glTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, source_height, |
+ 0, internal_format, dest_type, NULL); |
GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); |
if (error != GL_NO_ERROR) { |
RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
@@ -11069,11 +11115,11 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
} |
texture_manager()->SetLevelInfo( |
- dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, |
+ 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, level, true); |
+ texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
+ true); |
} |
ScopedModifyPixels modify(dest_texture_ref); |
@@ -11081,7 +11127,7 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
// Try using GLImage::CopyTexImage when possible. |
bool unpack_premultiply_alpha_change = |
unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_; |
- if (image && !unpack_flip_y_ && !unpack_premultiply_alpha_change && !level) { |
+ if (image && !unpack_flip_y_ && !unpack_premultiply_alpha_change) { |
glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
if (image->CopyTexImage(GL_TEXTURE_2D)) |
return; |
@@ -11093,36 +11139,149 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
// before presenting. |
if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
// TODO(hkuang): get the StreamTexture transform matrix in GPU process |
- // instead of using default matrix crbug.com/226218. |
- const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
- 0.0f, 1.0f, 0.0f, 0.0f, |
- 0.0f, 0.0f, 1.0f, 0.0f, |
- 0.0f, 0.0f, 0.0f, 1.0f}; |
+ // instead of using kIdentityMatrix crbug.com/226218. |
copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
- this, |
- source_texture->target(), |
- source_texture->service_id(), |
- dest_texture->service_id(), |
- level, |
- source_width, |
- source_height, |
- unpack_flip_y_, |
- unpack_premultiply_alpha_, |
- unpack_unpremultiply_alpha_, |
- default_matrix); |
+ 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(), |
- level, |
- internal_format, |
- source_width, |
- source_height, |
- unpack_flip_y_, |
- unpack_premultiply_alpha_, |
- unpack_unpremultiply_alpha_); |
+ copy_texture_CHROMIUM_->DoCopyTexture( |
+ this, source_texture->target(), source_texture->service_id(), |
+ source_internal_format, dest_texture->service_id(), internal_format, |
+ source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, |
+ unpack_unpremultiply_alpha_); |
+ } |
+ |
+ DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
+} |
+ |
+void GLES2DecoderImpl::DoCopySubTextureCHROMIUM(GLenum target, |
+ GLuint source_id, |
+ GLuint dest_id, |
+ GLint xoffset, |
+ GLint yoffset) { |
+ TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopySubTextureCHROMIUM"); |
+ |
+ 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) { |
+ 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, "glCopySubTextureCHROMIUM", |
+ "invalid image size"); |
+ return; |
+ } |
+ } else { |
+ if (!source_texture->GetLevelSize(source_texture->target(), 0, |
+ &source_width, &source_height)) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
+ "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)) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
+ "source texture bad dimensions"); |
+ return; |
+ } |
+ } |
+ |
+ GLenum source_type = 0; |
+ GLenum source_internal_format = 0; |
+ source_texture->GetLevelType(source_texture->target(), 0, &source_type, |
+ &source_internal_format); |
+ GLenum dest_type = 0; |
+ GLenum dest_internal_format = 0; |
+ bool dest_level_defined = dest_texture->GetLevelType( |
+ dest_texture->target(), 0, &dest_type, &dest_internal_format); |
+ if (!dest_level_defined) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopySubTextureCHROMIUM", |
+ "destination texture is not defined"); |
+ return; |
+ } |
+ if (!dest_texture->ValidForTexture(dest_texture->target(), 0, xoffset, |
dshwang
2015/02/27 11:56:41
Here.
|
+ yoffset, source_width, source_height, |
+ dest_type)) { |
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
+ "destination texture bad dimensions."); |
+ return; |
+ } |
+ |
+ if (!ValidateCopyTextureCHROMIUM("glCopySubTextureCHROMIUM", target, |
+ source_texture_ref, dest_texture_ref, |
+ dest_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, "glCopySubTextureCHROMIUM", |
+ "source texture dimensions too big"); |
+ 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("glCopySubTextureCHROMIUM"); |
+ copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
+ copy_texture_CHROMIUM_->Initialize(this); |
+ RestoreCurrentFramebufferBindings(); |
+ if (LOCAL_PEEK_GL_ERROR("glCopySubTextureCHROMIUM") != GL_NO_ERROR) |
+ return; |
+ } |
+ |
+ int dest_width = 0; |
+ int dest_height = 0; |
+ bool ok = |
+ dest_texture->GetLevelSize(GL_TEXTURE_2D, 0, &dest_width, &dest_height); |
+ DCHECK(ok); |
+ if (xoffset != 0 || yoffset != 0 || source_width != dest_width || |
+ source_height != dest_height) { |
+ if (!texture_manager()->ClearTextureLevel(this, dest_texture_ref, target, |
+ 0)) { |
+ LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM", |
+ "destination texture dimensions too big"); |
+ return; |
+ } |
+ } else { |
+ texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
+ true); |
+ } |
+ |
+ ScopedModifyPixels modify(dest_texture_ref); |
+ |
+ DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
+ |
+ // 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_->DoCopySubTextureWithTransform( |
+ this, source_texture->target(), source_texture->service_id(), |
+ dest_texture->service_id(), xoffset, yoffset, dest_width, dest_height, |
+ source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, |
+ unpack_unpremultiply_alpha_, kIdentityMatrix); |
+ } else { |
+ copy_texture_CHROMIUM_->DoCopySubTexture( |
+ this, source_texture->target(), source_texture->service_id(), |
+ source_internal_format, dest_texture->service_id(), |
+ dest_internal_format, xoffset, yoffset, dest_width, dest_height, |
+ source_width, source_height, unpack_flip_y_, unpack_premultiply_alpha_, |
+ unpack_unpremultiply_alpha_); |
} |
DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
@@ -11727,10 +11886,6 @@ void GLES2DecoderImpl::DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode) { |
return; |
} |
- static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, |
- 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, |
- 0.0f, 0.0f, 0.0f, 1.0f}; |
- |
GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM |
? state_.projection_matrix |
: state_.modelview_matrix; |