| 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 #ifndef GL_GLEXT_PROTOTYPES | 5 #ifndef GL_GLEXT_PROTOTYPES |
| 6 #define GL_GLEXT_PROTOTYPES | 6 #define GL_GLEXT_PROTOTYPES |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
| 10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
| 11 #include <GLES2/gl2extchromium.h> | 11 #include <GLES2/gl2extchromium.h> |
| 12 #include <stdint.h> | 12 #include <stdint.h> |
| 13 | 13 |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "gpu/command_buffer/tests/gl_manager.h" | 18 #include "gpu/command_buffer/tests/gl_manager.h" |
| 19 #include "gpu/command_buffer/tests/gl_test_utils.h" | 19 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 20 #include "gpu/config/gpu_switches.h" | 20 #include "gpu/config/gpu_switches.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "ui/gl/gl_context.h" |
| 24 #include "ui/gl/gl_version_info.h" |
| 23 | 25 |
| 24 namespace gpu { | 26 namespace gpu { |
| 25 | 27 |
| 26 // A collection of tests that exercise the glClear workaround. | 28 // A collection of tests that exercise the glClear workaround. |
| 27 class GLClearFramebufferTest : public testing::TestWithParam<bool> { | 29 class GLClearFramebufferTest : public testing::TestWithParam<bool> { |
| 28 public: | 30 public: |
| 29 GLClearFramebufferTest() : color_handle_(0u), depth_handle_(0u) {} | 31 GLClearFramebufferTest() : color_handle_(0u), depth_handle_(0u) {} |
| 30 | 32 |
| 31 protected: | 33 protected: |
| 32 void SetUp() override { | 34 void SetUp() override { |
| 33 if (GetParam()) { | 35 if (GetParam()) { |
| 34 // Force the glClear() workaround so we can test it here. | 36 // Force the glClear() workaround so we can test it here. |
| 35 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 37 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 36 command_line.AppendSwitchASCII(switches::kGpuDriverBugWorkarounds, | 38 command_line.AppendSwitchASCII(switches::kGpuDriverBugWorkarounds, |
| 37 base::IntToString(gpu::GL_CLEAR_BROKEN)); | 39 base::IntToString(gpu::GL_CLEAR_BROKEN)); |
| 38 gl_.InitializeWithCommandLine(GLManager::Options(), command_line); | 40 gl_.InitializeWithCommandLine(GLManager::Options(), command_line); |
| 39 DCHECK(gl_.workarounds().gl_clear_broken); | 41 DCHECK(gl_.workarounds().gl_clear_broken); |
| 40 } else { | 42 } else { |
| 41 gl_.Initialize(GLManager::Options()); | 43 gl_.Initialize(GLManager::Options()); |
| 42 DCHECK(!gl_.workarounds().gl_clear_broken); | 44 DCHECK(!gl_.workarounds().gl_clear_broken); |
| 43 } | 45 } |
| 44 } | 46 } |
| 45 | 47 |
| 48 bool IsApplicable() { |
| 49 // The workaround doesn't use VAOs which would cause a failure on a core |
| 50 // context and the hardware for each the workaround is necessary has a buggy |
| 51 // VAO implementation. So we skip testing the workaround on core profiles. |
| 52 return !GetParam() || |
| 53 !gl_.context()->GetVersionInfo()->is_desktop_core_profile; |
| 54 } |
| 55 |
| 46 void InitDraw(); | 56 void InitDraw(); |
| 47 void SetDrawColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a); | 57 void SetDrawColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a); |
| 48 void SetDrawDepth(GLfloat depth); | 58 void SetDrawDepth(GLfloat depth); |
| 49 void DrawQuad(); | 59 void DrawQuad(); |
| 50 | 60 |
| 51 void TearDown() override { | 61 void TearDown() override { |
| 52 GLTestHelper::CheckGLError("no errors", __LINE__); | 62 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 53 gl_.Destroy(); | 63 gl_.Destroy(); |
| 54 } | 64 } |
| 55 | 65 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 111 |
| 102 void GLClearFramebufferTest::DrawQuad() { | 112 void GLClearFramebufferTest::DrawQuad() { |
| 103 glDrawArrays(GL_TRIANGLES, 0, 6); | 113 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 104 } | 114 } |
| 105 | 115 |
| 106 INSTANTIATE_TEST_CASE_P(GLClearFramebufferTestWithParam, | 116 INSTANTIATE_TEST_CASE_P(GLClearFramebufferTestWithParam, |
| 107 GLClearFramebufferTest, | 117 GLClearFramebufferTest, |
| 108 ::testing::Values(true, false)); | 118 ::testing::Values(true, false)); |
| 109 | 119 |
| 110 TEST_P(GLClearFramebufferTest, ClearColor) { | 120 TEST_P(GLClearFramebufferTest, ClearColor) { |
| 121 if (!IsApplicable()) { |
| 122 return; |
| 123 } |
| 124 |
| 111 glClearColor(1.0f, 0.5f, 0.25f, 0.5f); | 125 glClearColor(1.0f, 0.5f, 0.25f, 0.5f); |
| 112 glClear(GL_COLOR_BUFFER_BIT); | 126 glClear(GL_COLOR_BUFFER_BIT); |
| 113 | 127 |
| 114 // Verify. | 128 // Verify. |
| 115 const uint8_t expected[] = {255, 128, 64, 128}; | 129 const uint8_t expected[] = {255, 128, 64, 128}; |
| 116 EXPECT_TRUE( | 130 EXPECT_TRUE( |
| 117 GLTestHelper::CheckPixels(0, 0, 1, 1, 1 /* tolerance */, expected)); | 131 GLTestHelper::CheckPixels(0, 0, 1, 1, 1 /* tolerance */, expected)); |
| 118 } | 132 } |
| 119 | 133 |
| 120 TEST_P(GLClearFramebufferTest, ClearColorWithMask) { | 134 TEST_P(GLClearFramebufferTest, ClearColorWithMask) { |
| 135 if (!IsApplicable()) { |
| 136 return; |
| 137 } |
| 138 |
| 121 glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); | 139 glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); |
| 122 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); | 140 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 123 glClear(GL_COLOR_BUFFER_BIT); | 141 glClear(GL_COLOR_BUFFER_BIT); |
| 124 | 142 |
| 125 // Verify. | 143 // Verify. |
| 126 const uint8_t expected[] = {255, 0, 0, 0}; | 144 const uint8_t expected[] = {255, 0, 0, 0}; |
| 127 EXPECT_TRUE( | 145 EXPECT_TRUE( |
| 128 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, expected)); | 146 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, expected)); |
| 129 } | 147 } |
| 130 | 148 |
| 131 // crbug.com/434094 | 149 // crbug.com/434094 |
| 132 #if !defined(OS_MACOSX) | 150 #if !defined(OS_MACOSX) |
| 133 TEST_P(GLClearFramebufferTest, ClearColorWithScissor) { | 151 TEST_P(GLClearFramebufferTest, ClearColorWithScissor) { |
| 152 if (!IsApplicable()) { |
| 153 return; |
| 154 } |
| 155 |
| 134 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); | 156 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 135 glClear(GL_COLOR_BUFFER_BIT); | 157 glClear(GL_COLOR_BUFFER_BIT); |
| 136 | 158 |
| 137 // Verify. | 159 // Verify. |
| 138 const uint8_t expected[] = {255, 255, 255, 255}; | 160 const uint8_t expected[] = {255, 255, 255, 255}; |
| 139 EXPECT_TRUE( | 161 EXPECT_TRUE( |
| 140 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, expected)); | 162 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, expected)); |
| 141 | 163 |
| 142 glScissor(0, 0, 0, 0); | 164 glScissor(0, 0, 0, 0); |
| 143 glEnable(GL_SCISSOR_TEST); | 165 glEnable(GL_SCISSOR_TEST); |
| 144 glClearColor(0, 0, 0, 0); | 166 glClearColor(0, 0, 0, 0); |
| 145 glClear(GL_COLOR_BUFFER_BIT); | 167 glClear(GL_COLOR_BUFFER_BIT); |
| 146 | 168 |
| 147 // Verify - no changes. | 169 // Verify - no changes. |
| 148 EXPECT_TRUE( | 170 EXPECT_TRUE( |
| 149 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, expected)); | 171 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, expected)); |
| 150 } | 172 } |
| 151 #endif | 173 #endif |
| 152 | 174 |
| 153 TEST_P(GLClearFramebufferTest, ClearDepthStencil) { | 175 TEST_P(GLClearFramebufferTest, ClearDepthStencil) { |
| 176 if (!IsApplicable()) { |
| 177 return; |
| 178 } |
| 179 |
| 154 const GLuint kStencilRef = 1 << 2; | 180 const GLuint kStencilRef = 1 << 2; |
| 155 InitDraw(); | 181 InitDraw(); |
| 156 SetDrawColor(1.0f, 0.0f, 0.0f, 1.0f); | 182 SetDrawColor(1.0f, 0.0f, 0.0f, 1.0f); |
| 157 DrawQuad(); | 183 DrawQuad(); |
| 158 // Verify. | 184 // Verify. |
| 159 const uint8_t kRed[] = {255, 0, 0, 255}; | 185 const uint8_t kRed[] = {255, 0, 0, 255}; |
| 160 const uint8_t kGreen[] = {0, 255, 0, 255}; | 186 const uint8_t kGreen[] = {0, 255, 0, 255}; |
| 161 EXPECT_TRUE( | 187 EXPECT_TRUE( |
| 162 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, kRed)); | 188 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, kRed)); |
| 163 | 189 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 192 | 218 |
| 193 glClearDepthf(0.9f); | 219 glClearDepthf(0.9f); |
| 194 glClear(GL_DEPTH_BUFFER_BIT); | 220 glClear(GL_DEPTH_BUFFER_BIT); |
| 195 DrawQuad(); | 221 DrawQuad(); |
| 196 // Verify - depth test should have passed, so red. | 222 // Verify - depth test should have passed, so red. |
| 197 EXPECT_TRUE( | 223 EXPECT_TRUE( |
| 198 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, kRed)); | 224 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, kRed)); |
| 199 } | 225 } |
| 200 | 226 |
| 201 } // namespace gpu | 227 } // namespace gpu |
| OLD | NEW |