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

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: Created 5 years, 11 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 0d778f3570ed2ab036adb03d327847c825248b4c..9aeb7eb5323d8b3e3b42981e7c6710842a46e557 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";
+
+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(
@@ -10535,6 +10546,18 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
return;
}
+ if (level) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopyTextureCHROMIUM",
+ "level must be 0");
+ return;
+ }
piman 2015/01/21 00:01:32 Why do we disallow >0 levels?
dshwang 2015/01/21 13:36:38 CHROMIUM_copy_texture.txt defines like that. "
piman 2015/01/21 18:05:55 If we don't support level>0 we should remove level
+
+ if (source_texture_ref == dest_texture_ref) {
piman 2015/01/21 00:01:31 Actually what you want to check is if source_textu
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopyTextureCHROMIUM",
+ "source and destination textures are the same");
+ return;
+ }
+
Texture* source_texture = source_texture_ref->texture();
Texture* dest_texture = dest_texture_ref->texture();
if (dest_texture->target() != GL_TEXTURE_2D ||
@@ -10547,6 +10570,12 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
return;
}
+ if (dest_texture->IsImmutable()) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopyTextureCHROMIUM",
+ "texture is immutable");
+ return;
+ }
+
int source_width, source_height, dest_width, dest_height;
gfx::GLImage* image =
@@ -10674,36 +10703,196 @@ 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* dest_texture_ref = GetTexture(dest_id);
+ TextureRef* source_texture_ref = GetTexture(source_id);
+
+ if (!source_texture_ref || !dest_texture_ref) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM",
+ "unknown texture id");
+ return;
+ }
+
+ if (GL_TEXTURE_2D != target) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM",
+ "invalid texture target");
+ return;
+ }
+
+ if (level) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM",
+ "level must be 0");
piman 2015/01/21 00:01:31 Why?
dshwang 2015/01/21 13:36:38 same reason to above.
+ return;
+ }
+
+ if (source_texture_ref == dest_texture_ref) {
piman 2015/01/21 00:01:32 Same as above.
dshwang 2015/01/21 13:36:38 Done.
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopySubTextureCHROMIUM",
+ "source and destination textures are the same");
+ return;
+ }
+
+ Texture* source_texture = source_texture_ref->texture();
+ Texture* dest_texture = dest_texture_ref->texture();
+ 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, "glCopySubTextureCHROMIUM",
+ "invalid texture target binding");
+ return;
+ }
+
+ int source_width, source_height;
piman 2015/01/21 00:01:31 nit: please initialize.
dshwang 2015/01/21 13:36:38 Done.
+
+ 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;
+ }
+ }
+
+ // 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;
+ }
+
+ 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;
+ }
+
+ // 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;
piman 2015/01/21 00:01:31 nit: can this check be shared with the DoCopyTextu
dshwang 2015/01/21 13:36:38 Done.
+ if (!valid_source_format || !valid_dest_format) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopySubTextureCHROMIUM",
+ "invalid 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("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, dest_height;
+ 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());
@@ -11308,10 +11497,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;
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc ('k') | gpu/command_buffer/service/gles2_cmd_decoder_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698