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

Unified Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 864513004: gpu: introduce glCopySubTextureCHROMIUM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address concerns of owners Created 5 years, 10 months 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 side-by-side diff with in-line comments
Download patch
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 706b0a7f24b8f49b4cf303a83593032ed7f19c22..cd4033bd2bd75b4539a48d3cdf3b0446430e38ee 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,19 @@ 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,
+ GLint level,
+ GLenum internal_format,
+ GLenum dest_type);
+
+ void DoCopySubTextureCHROMIUM(GLenum target,
+ GLuint source_id,
+ GLuint dest_id,
+ GLint level,
+ GLint xoffset,
+ GLint yoffset);
// Wrapper for TexStorage2DEXT.
void DoTexStorage2DEXT(
@@ -1659,6 +1670,12 @@ 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,
+ GLint level,
+ GLenum dest_internal_format);
void RenderWarning(const char* filename, int line, const std::string& msg);
void PerformanceWarning(
@@ -10717,40 +10734,86 @@ 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,
+ GLint level,
+ 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;
+ }
+
+ // because glFramebufferTexture2D() doesn't support level > 0.
dshwang 2015/02/10 18:11:55 add comment why level > 0 is not supported.
piman 2015/02/25 21:32:17 If we won't ever support it, we should remove the
+ if (level) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "level must be 0");
+ 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,
+ GLint level,
+ 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) {
@@ -10781,35 +10844,28 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
}
}
- // 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, level,
+ 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;
}
@@ -10826,6 +10882,8 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
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, level, &dest_width, &dest_height);
@@ -10876,36 +10934,151 @@ 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(), level, 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(), level,
+ 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 level,
+ 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(), level,
+ 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(), level, &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(), level, xoffset,
+ 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, level,
+ 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, level, &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,
+ level)) {
+ 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, level,
+ 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(), level, 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(), level,
+ 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());
@@ -11510,10 +11683,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;

Powered by Google App Engine
This is Rietveld 408576698