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

Unified Diff: gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc

Issue 2589613002: Revert of Extend CopyTextureCHROMIUM to more ES 3.0 texture formats. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc
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 5d6ace6b587fa862c3261f10c529b59e7b7dd782..44701c96b195fc0fedef0472d198686c8a72464e 100644
--- a/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc
+++ b/gpu/command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc
@@ -9,7 +9,6 @@
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2extchromium.h>
-#include <GLES3/gl3.h>
#include <stddef.h>
#include <stdint.h>
@@ -17,173 +16,16 @@
#include "gpu/command_buffer/tests/gl_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gl/gl_version_info.h"
namespace gpu {
namespace {
-
enum CopyType { TexImage, TexSubImage };
const CopyType kCopyTypes[] = {
TexImage,
TexSubImage,
};
-
-static const char* kSimpleVertexShaderES3 =
- "#version 300 es\n"
- "in vec2 a_position;\n"
- "out vec2 v_texCoord;\n"
- "void main() {\n"
- " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n"
- " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n"
- "}\n";
-
-std::string GetFragmentShaderSource(GLenum format) {
- std::string source;
- source += std::string(
- "#version 300 es\n"
- "precision mediump float;\n");
- if (gles2::GLES2Util::IsSignedIntegerFormat(format)) {
- source += std::string("#define SamplerType isampler2D\n");
- source += std::string("#define TextureType ivec4\n");
- source += std::string("#define ScaleValue 255.0\n");
- } else if (gles2::GLES2Util::IsUnsignedIntegerFormat(format)) {
- source += std::string("#define SamplerType usampler2D\n");
- source += std::string("#define TextureType uvec4\n");
- source += std::string("#define ScaleValue 255.0\n");
- } else {
- source += std::string("#define SamplerType sampler2D\n");
- source += std::string("#define TextureType vec4\n");
- source += std::string("#define ScaleValue 1.0\n");
- }
-
- source += std::string(
- "uniform mediump SamplerType u_texture;\n"
- "in vec2 v_texCoord;\n"
- "out vec4 fragData;\n"
- "void main() {\n"
- " TextureType color = texture(u_texture, v_texCoord);\n"
- " fragData = vec4(color) / ScaleValue;\n"
- "}\n");
- return source;
-}
-
-void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t* color) {
- color[0] = r;
- color[1] = g;
- color[2] = b;
- color[3] = a;
-}
-
-void getExpectedColor(GLenum src_internal_format,
- GLenum dest_internal_format,
- uint8_t* color,
- uint8_t* expected_color,
- uint8_t* mask) {
- uint8_t adjusted_color[4];
- switch (src_internal_format) {
- case GL_ALPHA:
- setColor(0, 0, 0, color[0], adjusted_color);
- break;
- case GL_R8:
- setColor(color[0], 0, 0, 255, adjusted_color);
- break;
- case GL_LUMINANCE:
- setColor(color[0], color[0], color[0], 255, adjusted_color);
- break;
- case GL_LUMINANCE_ALPHA:
- setColor(color[0], color[0], color[0], color[1], adjusted_color);
- break;
- case GL_RGB:
- case GL_RGB8:
- case GL_RGB_YCBCR_420V_CHROMIUM:
- case GL_RGB_YCBCR_422_CHROMIUM:
- setColor(color[0], color[1], color[2], 255, adjusted_color);
- break;
- case GL_RGBA:
- case GL_RGBA8:
- setColor(color[0], color[1], color[2], color[3], adjusted_color);
- break;
- case GL_BGRA_EXT:
- case GL_BGRA8_EXT:
- setColor(color[2], color[1], color[0], color[3], adjusted_color);
- break;
- default:
- NOTREACHED();
- break;
- }
-
- switch (dest_internal_format) {
- case GL_ALPHA:
- setColor(0, 0, 0, adjusted_color[3], expected_color);
- setColor(0, 0, 0, 1, mask);
- break;
- case GL_R8:
- case GL_R16F:
- case GL_R32F:
- case GL_R8UI:
- setColor(adjusted_color[0], 0, 0, 0, expected_color);
- setColor(1, 0, 0, 0, mask);
- break;
- case GL_LUMINANCE:
- setColor(adjusted_color[0], 0, 0, 0, expected_color);
- setColor(1, 0, 0, 0, mask);
- break;
- case GL_LUMINANCE_ALPHA:
- setColor(adjusted_color[0], 0, 0, adjusted_color[3], expected_color);
- setColor(1, 0, 0, 1, mask);
- break;
- case GL_RG8:
- case GL_RG16F:
- case GL_RG32F:
- case GL_RG8UI:
- setColor(adjusted_color[0], adjusted_color[1], 0, 0, expected_color);
- setColor(1, 1, 0, 0, mask);
- break;
- case GL_RGB:
- case GL_RGB8:
- case GL_SRGB_EXT:
- case GL_SRGB8:
- case GL_RGB565:
- case GL_R11F_G11F_B10F:
- case GL_RGB9_E5:
- case GL_RGB16F:
- case GL_RGB32F:
- case GL_RGB8UI:
- setColor(adjusted_color[0], adjusted_color[1], adjusted_color[2], 0,
- expected_color);
- setColor(1, 1, 1, 0, mask);
- break;
- case GL_RGBA:
- case GL_RGBA8:
- case GL_BGRA_EXT:
- case GL_BGRA8_EXT:
- case GL_SRGB_ALPHA_EXT:
- case GL_SRGB8_ALPHA8:
- case GL_RGBA4:
- case GL_RGBA16F:
- case GL_RGBA32F:
- case GL_RGBA8UI:
- setColor(adjusted_color[0], adjusted_color[1], adjusted_color[2],
- adjusted_color[3], expected_color);
- setColor(1, 1, 1, 1, mask);
- break;
- case GL_RGB5_A1:
- setColor(adjusted_color[0], adjusted_color[1], adjusted_color[2],
- (adjusted_color[3] >> 7) ? 0xFF : 0x0, expected_color);
- // TODO(qiankun.miao@intel.com): On some Windows platforms, the alpha
- // channel of expected color is the source alpha value other than 255.
- // This should be wrong. Skip the alpha channel check and revisit this in
- // future.
- setColor(1, 1, 1, 0, mask);
- break;
- default:
- NOTREACHED();
- break;
- }
-}
-
-} // namespace
+}
// A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
class GLCopyTextureCHROMIUMTest
@@ -250,59 +92,8 @@
GLuint framebuffer_id_;
};
-class GLCopyTextureCHROMIUMES3Test : public GLCopyTextureCHROMIUMTest {
- protected:
- void SetUp() override {
- GLManager::Options options;
- options.context_type = gles2::CONTEXT_TYPE_OPENGLES3;
- options.size = gfx::Size(64, 64);
- gl_.Initialize(options);
- }
-
- void TearDown() override { gl_.Destroy(); }
-
- // If a driver isn't capable of supporting ES3 context, creating
- // ContextGroup will fail. Just skip the test.
- bool ShouldSkipTest() const {
- return (!gl_.decoder() || !gl_.decoder()->GetContextGroup());
- }
-
- // RGB9_E5 isn't accepted by glCopyTexImage2D if underlying context is ES.
- // TODO(qiankun.miao@intel.com): we should support RGB9_E5 in ES context.
- // Maybe, we can add a readback path for RGB9_E5 format in ES context.
- bool ShouldSkipRGB9_E5() const {
- DCHECK(!ShouldSkipTest());
- const gl::GLVersionInfo& gl_version_info =
- gl_.decoder()->GetFeatureInfo()->gl_version_info();
- return gl_version_info.is_es;
- }
-
- // If EXT_color_buffer_float isn't available, float format isn't supported.
- bool ShouldSkipFloatFormat() const {
- DCHECK(!ShouldSkipTest());
- return !gl_.decoder()->GetFeatureInfo()->ext_color_buffer_float_available();
- }
-
- bool ShouldSkipBGRA() const {
- DCHECK(!ShouldSkipTest());
- return !gl_.decoder()
- ->GetFeatureInfo()
- ->feature_flags()
- .ext_texture_format_bgra8888;
- }
-
- bool ShouldSkipSRGBEXT() const {
- DCHECK(!ShouldSkipTest());
- return !gl_.decoder()->GetFeatureInfo()->feature_flags().ext_srgb;
- }
-};
-
INSTANTIATE_TEST_CASE_P(CopyType,
GLCopyTextureCHROMIUMTest,
- ::testing::ValuesIn(kCopyTypes));
-
-INSTANTIATE_TEST_CASE_P(CopyType,
- GLCopyTextureCHROMIUMES3Test,
::testing::ValuesIn(kCopyTypes));
// Test to ensure that the basic functionality of the extension works.
@@ -339,207 +130,6 @@
GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels);
EXPECT_TRUE(GL_NO_ERROR == glGetError());
-}
-
-TEST_P(GLCopyTextureCHROMIUMES3Test, FormatCombinations) {
- if (ShouldSkipTest())
- return;
- CopyType copy_type = GetParam();
-
- struct FormatType {
- GLenum internal_format;
- GLenum format;
- GLenum type;
- };
-
- FormatType src_format_types[] = {
- {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE},
- {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE},
- {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE},
- {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE},
- {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
- {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE},
- {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
- {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
- };
-
- FormatType dest_format_types[] = {
- // TODO(qiankun.miao@intel.com): ALPHA and LUMINANCE formats have bug on
- // GL core profile. See crbug.com/577144. Enable these formats after
- // using workaround in gles2_cmd_copy_tex_image.cc.
- // {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE},
- // {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE},
- // {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE},
-
- {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE},
- {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
- {GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE},
- {GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE},
- {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
- {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
- {GL_R8, GL_RED, GL_UNSIGNED_BYTE},
- {GL_R16F, GL_RED, GL_HALF_FLOAT},
- {GL_R16F, GL_RED, GL_FLOAT},
- {GL_R32F, GL_RED, GL_FLOAT},
- {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE},
- {GL_RG8, GL_RG, GL_UNSIGNED_BYTE},
- {GL_RG16F, GL_RG, GL_HALF_FLOAT},
- {GL_RG16F, GL_RG, GL_FLOAT},
- {GL_RG32F, GL_RG, GL_FLOAT},
- {GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE},
- {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE},
- {GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE},
- {GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE},
- {GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT},
- {GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT},
- {GL_RGB9_E5, GL_RGB, GL_FLOAT},
- {GL_RGB16F, GL_RGB, GL_HALF_FLOAT},
- {GL_RGB16F, GL_RGB, GL_FLOAT},
- {GL_RGB32F, GL_RGB, GL_FLOAT},
- {GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE},
- {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE},
- {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE},
- {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE},
- {GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE},
- {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT},
- {GL_RGBA16F, GL_RGBA, GL_FLOAT},
- {GL_RGBA32F, GL_RGBA, GL_FLOAT},
- {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE},
- };
-
- for (auto src_format_type : src_format_types) {
- for (auto dest_format_type : dest_format_types) {
- if (dest_format_type.internal_format == GL_RGB9_E5 && ShouldSkipRGB9_E5())
- continue;
- if ((src_format_type.internal_format == GL_BGRA_EXT ||
- src_format_type.internal_format == GL_BGRA8_EXT ||
- dest_format_type.internal_format == GL_BGRA_EXT ||
- dest_format_type.internal_format == GL_BGRA8_EXT) &&
- ShouldSkipBGRA()) {
- continue;
- }
- if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) &&
- ShouldSkipFloatFormat())
- continue;
- if ((dest_format_type.internal_format == GL_SRGB_EXT ||
- dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) &&
- ShouldSkipSRGBEXT())
- continue;
-
- const GLsizei kWidth = 8, kHeight = 8;
- const int src_channel_count = gles2::GLES2Util::ElementsPerGroup(
- src_format_type.format, src_format_type.type);
- uint8_t color[4] = {1, 63, 127, 255};
- uint8_t pixels[8 * 8 * 4];
- for (int i = 0; i < kWidth * kHeight * src_channel_count;
- i += src_channel_count)
- for (int j = 0; j < src_channel_count; ++j)
- pixels[i + j] = color[j];
- uint8_t expected_color[4];
- uint8_t mask[4];
- getExpectedColor(src_format_type.internal_format,
- dest_format_type.internal_format, color, expected_color,
- mask);
-
- CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, textures_[0]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, src_format_type.internal_format, kWidth,
- kHeight, 0, src_format_type.format, src_format_type.type,
- pixels);
-
- EXPECT_TRUE(glGetError() == GL_NO_ERROR);
- if (copy_type == TexImage) {
- glCopyTextureCHROMIUM(textures_[0], textures_[1],
- dest_format_type.internal_format,
- dest_format_type.type, false, false, false);
- } else {
- glBindTexture(GL_TEXTURE_2D, textures_[1]);
- glTexImage2D(GL_TEXTURE_2D, 0, dest_format_type.internal_format, kWidth,
- kHeight, 0, dest_format_type.format, dest_format_type.type,
- nullptr);
-
- glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, kWidth,
- kHeight, false, false, false);
- }
- EXPECT_TRUE(glGetError() == GL_NO_ERROR)
- << " src_internal_format: "
- << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format)
- << " dest_internal_format: "
- << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format);
-
- // Draw destination texture to a fbo with attachment in RGBA format.
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- GLuint framebuffer = 0;
- glGenFramebuffers(1, &framebuffer);
- glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
- GLuint texture = 0;
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, texture, 0);
- EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
- glCheckFramebufferStatus(GL_FRAMEBUFFER));
- glViewport(0, 0, kWidth, kHeight);
-
- std::string fragment_shader_source =
- GetFragmentShaderSource(dest_format_type.internal_format);
- GLuint program = GLTestHelper::LoadProgram(
- kSimpleVertexShaderES3, fragment_shader_source.c_str());
- EXPECT_NE(program, 0u);
- GLint position_loc = glGetAttribLocation(program, "a_position");
- GLint texture_loc = glGetUniformLocation(program, "u_texture");
- ASSERT_NE(position_loc, -1);
- ASSERT_NE(texture_loc, -1);
- glUseProgram(program);
-
- GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
- ASSERT_NE(vbo, 0u);
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, textures_[1]);
-
- glDrawArrays(GL_TRIANGLES, 0, 6);
-
- EXPECT_TRUE(GL_NO_ERROR == glGetError());
-
- GLsizei size = kWidth * kHeight * 4;
- std::unique_ptr<uint8_t[]> result(new uint8_t[size]);
- glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
- result.get());
- uint8_t tolerance = dest_format_type.internal_format == GL_RGBA4 ? 20 : 7;
- for (GLint yy = 0; yy < kHeight; ++yy) {
- for (GLint xx = 0; xx < kWidth; ++xx) {
- int offset = yy * kWidth * 4 + xx * 4;
- for (int jj = 0; jj < 4; ++jj) {
- uint8_t actual = result[offset + jj];
- uint8_t expected = expected_color[jj];
- int diff = actual - expected;
- diff = diff < 0 ? -diff : diff;
- if (mask[jj] && diff > tolerance) {
- EXPECT_EQ(expected, actual)
- << " at " << xx << ", " << yy << " channel " << jj
- << " src_internal_format: "
- << gles2::GLES2Util::GetStringEnum(
- src_format_type.internal_format)
- << " dest_internal_format: "
- << gles2::GLES2Util::GetStringEnum(
- dest_format_type.internal_format);
- }
- }
- }
- }
-
- glDeleteTextures(1, &texture);
- glDeleteFramebuffers(1, &framebuffer);
- glDeleteTextures(2, textures_);
- glDeleteFramebuffers(1, &framebuffer_id_);
- }
- }
}
TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) {
@@ -640,7 +230,8 @@
EXPECT_TRUE(GL_NO_ERROR == glGetError());
// Check unsupported format reports error.
- GLint unsupported_dest_formats[] = {GL_RED, GL_RG};
+ GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE,
+ GL_LUMINANCE_ALPHA};
for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats);
dest_index++) {
if (copy_type == TexImage) {
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698