| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
| 6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
| 7 #include <stdint.h> |
| 7 | 8 |
| 8 #include "gpu/command_buffer/service/feature_info.h" | 9 #include "gpu/command_buffer/service/feature_info.h" |
| 9 #include "gpu/command_buffer/tests/gl_manager.h" | 10 #include "gpu/command_buffer/tests/gl_manager.h" |
| 10 #include "gpu/command_buffer/tests/gl_test_utils.h" | 11 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace gpu { | 15 namespace gpu { |
| 15 | 16 |
| 16 class GLTest : public testing::Test { | 17 class GLTest : public testing::Test { |
| 17 protected: | 18 protected: |
| 18 void SetUp() override { gl_.Initialize(GLManager::Options()); } | 19 void SetUp() override { gl_.Initialize(GLManager::Options()); } |
| 19 | 20 |
| 20 void TearDown() override { gl_.Destroy(); } | 21 void TearDown() override { gl_.Destroy(); } |
| 21 | 22 |
| 22 GLManager gl_; | 23 GLManager gl_; |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 // Test that GL is at least minimally working. | 26 // Test that GL is at least minimally working. |
| 26 TEST_F(GLTest, Basic) { | 27 TEST_F(GLTest, Basic) { |
| 27 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | 28 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 28 glClear(GL_COLOR_BUFFER_BIT); | 29 glClear(GL_COLOR_BUFFER_BIT); |
| 29 uint8 expected[] = { 0, 255, 0, 255, }; | 30 uint8_t expected[] = { |
| 31 0, 255, 0, 255, |
| 32 }; |
| 30 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); | 33 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected)); |
| 31 GLTestHelper::CheckGLError("no errors", __LINE__); | 34 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 32 } | 35 } |
| 33 | 36 |
| 34 TEST_F(GLTest, BasicFBO) { | 37 TEST_F(GLTest, BasicFBO) { |
| 35 GLuint tex = 0; | 38 GLuint tex = 0; |
| 36 glGenTextures(1, &tex); | 39 glGenTextures(1, &tex); |
| 37 GLuint fbo = 0; | 40 GLuint fbo = 0; |
| 38 glGenFramebuffers(1, &fbo); | 41 glGenFramebuffers(1, &fbo); |
| 39 glBindTexture(GL_TEXTURE_2D, tex); | 42 glBindTexture(GL_TEXTURE_2D, tex); |
| 40 scoped_ptr<uint8[]> pixels(new uint8 [16*16*4]); | 43 scoped_ptr<uint8_t[]> pixels(new uint8_t[16 * 16 * 4]); |
| 41 memset(pixels.get(), 0, 16*16*4); | 44 memset(pixels.get(), 0, 16*16*4); |
| 42 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 45 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 43 pixels.get()); | 46 pixels.get()); |
| 44 glGenerateMipmap(GL_TEXTURE_2D); | 47 glGenerateMipmap(GL_TEXTURE_2D); |
| 45 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 48 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 46 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 49 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 47 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 48 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 49 glBindFramebuffer(GL_FRAMEBUFFER, fbo); | 52 glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 50 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 53 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 51 tex, 0); | 54 tex, 0); |
| 52 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 55 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 53 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 56 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 54 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | 57 glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 55 glClear(GL_COLOR_BUFFER_BIT); | 58 glClear(GL_COLOR_BUFFER_BIT); |
| 56 uint8 expected[] = { 0, 255, 0, 255, }; | 59 uint8_t expected[] = { |
| 60 0, 255, 0, 255, |
| 61 }; |
| 57 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 16, 16, 0, expected)); | 62 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 16, 16, 0, expected)); |
| 58 glDeleteFramebuffers(1, &fbo); | 63 glDeleteFramebuffers(1, &fbo); |
| 59 glDeleteTextures(1, &tex); | 64 glDeleteTextures(1, &tex); |
| 60 GLTestHelper::CheckGLError("no errors", __LINE__); | 65 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 61 } | 66 } |
| 62 | 67 |
| 63 TEST_F(GLTest, SimpleShader) { | 68 TEST_F(GLTest, SimpleShader) { |
| 64 static const char* v_shader_str = | 69 static const char* v_shader_str = |
| 65 "attribute vec4 a_Position;\n" | 70 "attribute vec4 a_Position;\n" |
| 66 "void main()\n" | 71 "void main()\n" |
| 67 "{\n" | 72 "{\n" |
| 68 " gl_Position = a_Position;\n" | 73 " gl_Position = a_Position;\n" |
| 69 "}\n"; | 74 "}\n"; |
| 70 static const char* f_shader_str = | 75 static const char* f_shader_str = |
| 71 "precision mediump float;\n" | 76 "precision mediump float;\n" |
| 72 "void main()\n" | 77 "void main()\n" |
| 73 "{\n" | 78 "{\n" |
| 74 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" | 79 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 75 "}\n"; | 80 "}\n"; |
| 76 | 81 |
| 77 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); | 82 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); |
| 78 glUseProgram(program); | 83 glUseProgram(program); |
| 79 GLuint position_loc = glGetAttribLocation(program, "a_Position"); | 84 GLuint position_loc = glGetAttribLocation(program, "a_Position"); |
| 80 | 85 |
| 81 GLTestHelper::SetupUnitQuad(position_loc); | 86 GLTestHelper::SetupUnitQuad(position_loc); |
| 82 | 87 |
| 83 uint8 expected_clear[] = { 127, 0, 255, 0, }; | 88 uint8_t expected_clear[] = { |
| 89 127, 0, 255, 0, |
| 90 }; |
| 84 glClearColor(0.5f, 0.0f, 1.0f, 0.0f); | 91 glClearColor(0.5f, 0.0f, 1.0f, 0.0f); |
| 85 glClear(GL_COLOR_BUFFER_BIT); | 92 glClear(GL_COLOR_BUFFER_BIT); |
| 86 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 1, expected_clear)); | 93 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 1, expected_clear)); |
| 87 uint8 expected_draw[] = { 0, 255, 0, 255, }; | 94 uint8_t expected_draw[] = { |
| 95 0, 255, 0, 255, |
| 96 }; |
| 88 glDrawArrays(GL_TRIANGLES, 0, 6); | 97 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 89 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_draw)); | 98 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_draw)); |
| 90 } | 99 } |
| 91 | 100 |
| 92 TEST_F(GLTest, FeatureFlagsMatchCapabilities) { | 101 TEST_F(GLTest, FeatureFlagsMatchCapabilities) { |
| 93 scoped_refptr<gles2::FeatureInfo> features = new gles2::FeatureInfo; | 102 scoped_refptr<gles2::FeatureInfo> features = new gles2::FeatureInfo; |
| 94 EXPECT_TRUE(features->InitializeForTesting()); | 103 EXPECT_TRUE(features->InitializeForTesting()); |
| 95 const auto& caps = gl_.GetCapabilities(); | 104 const auto& caps = gl_.GetCapabilities(); |
| 96 const auto& flags = features->feature_flags(); | 105 const auto& flags = features->feature_flags(); |
| 97 EXPECT_EQ(caps.egl_image_external, flags.oes_egl_image_external); | 106 EXPECT_EQ(caps.egl_image_external, flags.oes_egl_image_external); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 122 EXPECT_STREQ( | 131 EXPECT_STREQ( |
| 123 "Chromium", | 132 "Chromium", |
| 124 reinterpret_cast<const char*>(glGetString(GL_RENDERER))); | 133 reinterpret_cast<const char*>(glGetString(GL_RENDERER))); |
| 125 EXPECT_STREQ( | 134 EXPECT_STREQ( |
| 126 "Chromium", | 135 "Chromium", |
| 127 reinterpret_cast<const char*>(glGetString(GL_VENDOR))); | 136 reinterpret_cast<const char*>(glGetString(GL_VENDOR))); |
| 128 } | 137 } |
| 129 | 138 |
| 130 } // namespace gpu | 139 } // namespace gpu |
| 131 | 140 |
| OLD | NEW |