From df36f0aebe453bdbe842c85b331f6f07a24255a2 Mon Sep 17 00:00:00 2001 From: "dongseong.hwang" Date: Fri, 21 Nov 2014 11:54:41 -0800 Subject: gpu: fix CopyTextureCHROMIUM for immutable texture. We cannot use glCopyTexImage2D on the texture which is allocated by glTexStorage2D [1] [1] https://www.opengl.org/registry/specs/ARB/texture_storage.txt The fast path uses glCopyTexSubImage2D instead of glCopyTexImage2D. In addition, optimize CopyTextureCHROMIUM for GL_TEXTURE_RECTANGLE_ARB, which is often used by the compositor, so make CopyTextureCHROMIUM use the fast path. Review URL: https://codereview.chromium.org/744713002 Cr-Commit-Position: refs/heads/master@{#305268} --- .../service/gles2_cmd_copy_texture_chromium.cc | 18 +++-------- .../tests/gl_copy_texture_CHROMIUM_unittest.cc | 37 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 13 deletions(-) (limited to 'gpu') diff --git a/gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc b/gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc index ffb9370..49bba9b 100644 --- a/gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc +++ b/gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc @@ -218,7 +218,6 @@ void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder, GLuint source_id, GLuint dest_id, GLint dest_level, - GLenum dest_internal_format, GLsizei width, GLsizei height, GLuint framebuffer) { @@ -231,14 +230,8 @@ void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder, glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glCopyTexImage2D(GL_TEXTURE_2D, - dest_level, - dest_internal_format, - 0 /* x */, - 0 /* y */, - width, - height, - 0 /* border */); + glCopyTexSubImage2D(GL_TEXTURE_2D, dest_level, 0 /* xoffset */, + 0 /* yoffset */, 0 /* x */, 0 /* y */, width, height); } decoder->RestoreTextureState(source_id); @@ -332,16 +325,15 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTexture( bool source_format_contain_superset_of_dest_format = source_internal_format == dest_internal_format || (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); - // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, - // so restrict this to GL_TEXTURE_2D. - if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && + bool source_target_allowed = source_target == GL_TEXTURE_2D || + source_target == GL_TEXTURE_RECTANGLE_ARB; + if (source_target_allowed && !flip_y && !premultiply_alpha_change && source_format_contain_superset_of_dest_format) { DoCopyTexImage2D(decoder, source_target, source_id, dest_id, dest_level, - dest_internal_format, width, height, framebuffer_); diff --git a/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc b/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc index 2c44e1a..a8cbb66 100644 --- a/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc +++ b/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc @@ -76,6 +76,43 @@ TEST_F(GLCopyTextureCHROMIUMTest, Basic) { EXPECT_TRUE(GL_NO_ERROR == glGetError()); } +TEST_F(GLCopyTextureCHROMIUMTest, ImmutableTexture) { + if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { + LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; + return; + } + + uint8 pixels[1 * 4] = {255u, 0u, 0u, 255u}; + + glBindTexture(GL_TEXTURE_2D, textures_[0]); + glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, + pixels); + + glBindTexture(GL_TEXTURE_2D, textures_[1]); + glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, + textures_[1], 0); + EXPECT_TRUE(glGetError() == GL_NO_ERROR); + + glCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, + GL_UNSIGNED_BYTE); + EXPECT_TRUE(glGetError() == GL_NO_ERROR); + + // Check the FB is still bound. + GLint value = 0; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); + GLuint fb_id = value; + EXPECT_EQ(framebuffer_id_, fb_id); + + // Check that FB is complete. + EXPECT_EQ(static_cast(GL_FRAMEBUFFER_COMPLETE), + glCheckFramebufferStatus(GL_FRAMEBUFFER)); + + GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); + EXPECT_TRUE(GL_NO_ERROR == glGetError()); +} + TEST_F(GLCopyTextureCHROMIUMTest, InternalFormat) { GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; -- cgit v1.1