Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/strings/stringprintf.h" | |
| 10 #include "gpu/command_buffer/tests/gl_manager.h" | 11 #include "gpu/command_buffer/tests/gl_manager.h" |
| 11 #include "gpu/command_buffer/tests/gl_test_utils.h" | 12 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 16 #define SHADER(Src) #Src | |
| 15 | 17 |
| 16 namespace gpu { | 18 namespace gpu { |
| 17 | 19 |
| 18 class CHROMIUMPathRenderingTest : public testing::Test { | 20 class CHROMIUMPathRenderingTest : public testing::Test { |
| 19 public: | 21 public: |
| 20 static const GLsizei kResolution = 100; | 22 static const GLsizei kResolution = 100; |
| 21 | 23 |
| 22 protected: | 24 protected: |
| 23 virtual void SetUp() { | 25 virtual void SetUp() { |
| 24 GLManager::Options options; | 26 GLManager::Options options; |
| 25 options.size = gfx::Size(kResolution, kResolution); | 27 options.size = gfx::Size(kResolution, kResolution); |
| 26 gl_.Initialize(options); | 28 gl_.Initialize(options); |
| 27 } | 29 } |
| 28 | 30 |
| 29 virtual void TearDown() { gl_.Destroy(); } | 31 virtual void TearDown() { gl_.Destroy(); } |
| 30 | 32 |
| 31 void ExpectEqualMatrix(const GLfloat* expected, const GLfloat* actual) { | 33 void ExpectEqualMatrix(const GLfloat* expected, const GLfloat* actual) { |
| 32 for (size_t i = 0; i < 16; ++i) { | 34 for (size_t i = 0; i < 16; ++i) { |
| 33 EXPECT_EQ(expected[i], actual[i]); | 35 EXPECT_EQ(expected[i], actual[i]); |
| 34 } | 36 } |
| 35 } | 37 } |
| 36 void ExpectEqualMatrix(const GLfloat* expected, const GLint* actual) { | 38 void ExpectEqualMatrix(const GLfloat* expected, const GLint* actual) { |
| 37 for (size_t i = 0; i < 16; ++i) { | 39 for (size_t i = 0; i < 16; ++i) { |
| 38 EXPECT_EQ(static_cast<GLint>(round(expected[i])), actual[i]); | 40 EXPECT_EQ(static_cast<GLint>(round(expected[i])), actual[i]); |
| 39 } | 41 } |
| 40 } | 42 } |
| 43 | |
| 44 void SetupStateForTestPattern() { | |
| 45 glViewport(0, 0, kResolution, kResolution); | |
| 46 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |
| 47 glStencilMask(0xffffffff); | |
| 48 glClearStencil(0); | |
| 49 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | |
| 50 | |
| 51 static const char* v_shader_src = | |
| 52 SHADER(void main() { gl_Position = vec4(1); }); | |
| 53 static const char* f_shader_src = | |
| 54 "#extension GL_CHROMIUM_path_rendering: require\n" SHADER( | |
| 55 precision mediump float; | |
| 56 void main() { gl_FragColor = gl_TexCoord[0] + gl_TexCoord[1]; }); | |
| 57 | |
| 58 GLuint program = GLTestHelper::LoadProgram(v_shader_src, f_shader_src); | |
| 59 glUseProgram(program); | |
| 60 glDeleteProgram(program); | |
| 61 | |
| 62 // Set up orthogonal projection with near/far plane distance of 2. | |
| 63 static GLfloat matrix[16] = { | |
| 64 2.0f / (kResolution - 1), 0.0f, 0.0f, 0.0f, | |
| 65 0.0f, 2.0f / (kResolution - 1), 0.0f, 0.0f, | |
| 66 0.0f, 0.0f, -1.0f, 0.0f, | |
| 67 -1.0f, -1.0f, 0.0f, 1.0f}; | |
| 68 glMatrixLoadfCHROMIUM(GL_PROJECTION_CHROMIUM, matrix); | |
| 69 glMatrixLoadIdentityCHROMIUM(GL_MODELVIEW_CHROMIUM); | |
| 70 | |
| 71 glEnable(GL_STENCIL_TEST); | |
| 72 | |
| 73 GLTestHelper::CheckGLError("no errors at state setup", __LINE__); | |
| 74 } | |
| 75 | |
| 76 void SetupPathStateForTestPattern(GLuint path) { | |
| 77 GLubyte commands[] = {GL_MOVE_TO_CHROMIUM, GL_LINE_TO_CHROMIUM, | |
| 78 GL_QUADRATIC_CURVE_TO_CHROMIUM, | |
| 79 GL_CUBIC_CURVE_TO_CHROMIUM, GL_CLOSE_PATH_CHROMIUM}; | |
| 80 | |
| 81 GLfloat coords[] = {50.0f, 50.0f, 75.0f, 75.0f, 100.0f, 62.5f, 50.0f, | |
| 82 25.5f, 0.0f, 62.5f, 50.0f, 50.0f, 25.0f, 75.0f}; | |
| 83 | |
| 84 glPathCommandsCHROMIUM(path, | |
| 85 arraysize(commands), | |
| 86 commands, | |
| 87 arraysize(coords), | |
| 88 GL_FLOAT, | |
| 89 coords); | |
| 90 | |
| 91 glPathParameterfCHROMIUM(path, GL_PATH_STROKE_WIDTH_CHROMIUM, 5.0f); | |
| 92 glPathParameterfCHROMIUM(path, GL_PATH_MITER_LIMIT_CHROMIUM, 1.0f); | |
| 93 glPathParameteriCHROMIUM( | |
| 94 path, GL_PATH_JOIN_STYLE_CHROMIUM, GL_ROUND_CHROMIUM); | |
| 95 glPathParameteriCHROMIUM( | |
| 96 path, GL_PATH_INITIAL_END_CAP_CHROMIUM, GL_SQUARE_CHROMIUM); | |
| 97 glPathParameteriCHROMIUM( | |
| 98 path, GL_PATH_TERMINAL_END_CAP_CHROMIUM, GL_FLAT_CHROMIUM); | |
| 99 } | |
| 100 | |
| 101 void VerifyTestPatternFill(float x, float y) { | |
| 102 // Inside the fill we should have color formed by the texture coordinate set | |
| 103 // coefficients. | |
| 104 const float fill_coords[] = {55.0f, 55.0f, 50.0f, 28.0f, 66.0f, 63.0f}; | |
| 105 | |
| 106 for (size_t i = 0; i < arraysize(fill_coords); i += 2) { | |
| 107 float fx = fill_coords[i]; | |
| 108 float fy = fill_coords[i + 1]; | |
| 109 uint8 expected_color[] = { | |
| 110 255 * (fx * 1.0f / kResolution - fx * 0.2f / kResolution), | |
| 111 255 * (fy * 1.0f / kResolution - fy * 0.2f / kResolution), | |
| 112 0, // The calculations cancel each other. | |
| 113 255}; | |
| 114 // Note: we compare with a bit of tolerance, since CPU float computation | |
| 115 // will not always match the shader computation. | |
| 116 EXPECT_TRUE( | |
| 117 GLTestHelper::CheckPixels(x + fx, y + fy, 1, 1, 2, expected_color)); | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 void VerifyTestPatternBg(float x, float y) { | |
| 122 const float bg_coords[] = {80.0f, 80.0f, 20.0f, 20.0f, 90.0f, 1.0f}; | |
| 123 uint8 expected_color[] = {0, 0, 0, 0}; | |
| 124 | |
| 125 for (size_t i = 0; i < arraysize(bg_coords); i += 2) { | |
| 126 float bx = bg_coords[i]; | |
| 127 float by = bg_coords[i + 1]; | |
| 128 | |
| 129 EXPECT_TRUE( | |
| 130 GLTestHelper::CheckPixels(x + bx, y + by, 1, 1, 0, expected_color)); | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 void VerifyTestPatternStroke(float x, float y) { | |
| 135 // Inside the stroke we should have green. | |
| 136 const uint8 green[] = {0, 255, 0, 255}; | |
| 137 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 50, y + 53, 1, 1, 0, green)); | |
| 138 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 26, y + 76, 1, 1, 0, green)); | |
| 139 | |
| 140 // Outside the path we should have black. | |
| 141 const uint8 black[] = {0, 0, 0, 0}; | |
| 142 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 10, y + 10, 1, 1, 0, black)); | |
| 143 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 80, y + 80, 1, 1, 0, black)); | |
| 144 } | |
| 145 | |
| 41 GLManager gl_; | 146 GLManager gl_; |
| 147 static GLfloat fill_coefficients_[3 * 3 * 2]; | |
| 148 static GLfloat stroke_coefficients_[3 * 3]; | |
| 149 }; | |
| 150 | |
| 151 GLfloat CHROMIUMPathRenderingTest::fill_coefficients_[] = { | |
| 152 1.0f / kResolution, 0.0f, 0.0f, | |
| 153 0.0f, 1.0f / kResolution, 0.0f, | |
| 154 1.0f / kResolution, 1.0f / kResolution, 0.0f, | |
| 155 -0.2f / kResolution, 0.0f, 0.0f, | |
| 156 0.0f, -0.2f / kResolution, 0.0f, | |
| 157 -1.0f / kResolution, -1.0f / kResolution, 0.0}; | |
| 158 | |
| 159 // Stroke should be constant green. | |
| 160 GLfloat CHROMIUMPathRenderingTest::stroke_coefficients_[] = { | |
| 161 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, | |
| 42 }; | 162 }; |
| 43 | 163 |
| 44 TEST_F(CHROMIUMPathRenderingTest, TestMatrix) { | 164 TEST_F(CHROMIUMPathRenderingTest, TestMatrix) { |
| 45 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { | 165 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { |
| 46 return; | 166 return; |
| 47 } | 167 } |
| 48 GLfloat identity_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, | 168 GLfloat identity_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, |
| 49 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, | 169 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, |
| 50 0.0f, 0.0f, 0.0f, 1.0f}; | 170 0.0f, 0.0f, 0.0f, 1.0f}; |
| 51 GLfloat seq_matrix[16] = {0.5f, -0.5f, -0.1f, -0.8f, 4.4f, 5.5f, | 171 GLfloat seq_matrix[16] = {0.5f, -0.5f, -0.1f, -0.8f, 4.4f, 5.5f, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 220 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 101 | 221 |
| 102 // This should fail. | 222 // This should fail. |
| 103 glMatrixLoadIdentityCHROMIUM(GL_PROJECTION_CHROMIUM + 1); | 223 glMatrixLoadIdentityCHROMIUM(GL_PROJECTION_CHROMIUM + 1); |
| 104 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); | 224 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); |
| 105 | 225 |
| 106 glMatrixLoadIdentityCHROMIUM(GL_PROJECTION_CHROMIUM); | 226 glMatrixLoadIdentityCHROMIUM(GL_PROJECTION_CHROMIUM); |
| 107 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 227 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 108 } | 228 } |
| 109 | 229 |
| 230 TEST_F(CHROMIUMPathRenderingTest, TestTexCoordShader) { | |
|
piman
2014/04/24 22:26:36
We'll have to skip those tests if the extension is
| |
| 231 static const char* fs_str = | |
| 232 "#extension GL_CHROMIUM_path_rendering: require\n" SHADER( | |
| 233 precision mediump float; | |
| 234 void main() { gl_FragColor = gl_TexCoord[0] + gl_TexCoord[% d]; }); | |
| 235 | |
| 236 GLint maxTextureCoords = -1; | |
| 237 glGetIntegerv(GL_MAX_TEXTURE_COORDS_CHROMIUM, &maxTextureCoords); | |
| 238 EXPECT_LT(static_cast<GLint>(0), maxTextureCoords); | |
| 239 | |
| 240 std::string fs_str_max = base::StringPrintf(fs_str, maxTextureCoords - 1); | |
| 241 | |
| 242 const char* shader_str = fs_str_max.c_str(); | |
| 243 GLuint fs = glCreateShader(GL_FRAGMENT_SHADER); | |
| 244 glShaderSource(fs, 1, &shader_str, NULL); | |
| 245 glCompileShader(fs); | |
| 246 GLint value = 0; | |
| 247 glGetShaderiv(fs, GL_COMPILE_STATUS, &value); | |
| 248 if (value == 0) { | |
| 249 char buffer[1024]; | |
| 250 GLsizei length = 0; | |
| 251 glGetShaderInfoLog(fs, sizeof(buffer), &length, buffer); | |
| 252 std::string log(buffer, length); | |
| 253 EXPECT_EQ(1, value) << "Error compiling shader: " << log; | |
| 254 } | |
| 255 | |
| 256 EXPECT_EQ(static_cast<GLint>(1), value); | |
| 257 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 258 glDeleteShader(fs); | |
| 259 } | |
| 260 | |
| 261 TEST_F(CHROMIUMPathRenderingTest, TooBigTexCoordShaderFails) { | |
| 262 static const char* fs_str = | |
| 263 "#extension GL_CHROMIUM_path_rendering: require\n" SHADER( | |
| 264 precision mediump float; | |
| 265 void main() { gl_FragColor = gl_TexCoord[0] + gl_TexCoord[% d]; }); | |
| 266 | |
| 267 GLint maxTextureCoords = -1; | |
| 268 glGetIntegerv(GL_MAX_TEXTURE_COORDS_CHROMIUM, &maxTextureCoords); | |
| 269 EXPECT_LT(static_cast<GLint>(0), maxTextureCoords); | |
| 270 | |
| 271 // Using too big TexCoord index should fail. | |
| 272 std::string fs_str_too_big = base::StringPrintf(fs_str, maxTextureCoords); | |
| 273 | |
| 274 const char* shader_str = fs_str_too_big.c_str(); | |
| 275 GLuint fs = glCreateShader(GL_FRAGMENT_SHADER); | |
| 276 GLint value = 0; | |
| 277 glShaderSource(fs, 1, &shader_str, NULL); | |
| 278 glCompileShader(fs); | |
| 279 glGetShaderiv(fs, GL_COMPILE_STATUS, &value); | |
| 280 EXPECT_EQ(static_cast<GLint>(0), value); | |
| 281 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 282 glDeleteShader(fs); | |
| 283 } | |
| 284 | |
| 285 TEST_F(CHROMIUMPathRenderingTest, NoExtensionTexCoordShaderFails) { | |
| 286 static const char* shader_str = SHADER( | |
| 287 precision mediump float; void main() { gl_FragColor = gl_TexCoord[0]; }); | |
| 288 GLuint fs = glCreateShader(GL_FRAGMENT_SHADER); | |
| 289 GLint value = 0; | |
| 290 glShaderSource(fs, 1, &shader_str, NULL); | |
| 291 glCompileShader(fs); | |
| 292 glGetShaderiv(fs, GL_COMPILE_STATUS, &value); | |
| 293 EXPECT_EQ(static_cast<GLint>(0), value); | |
| 294 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 295 glDeleteShader(fs); | |
| 296 } | |
| 297 | |
| 298 TEST_F(CHROMIUMPathRenderingTest, TestSimpleCalls) { | |
| 299 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { | |
| 300 return; | |
| 301 } | |
| 302 | |
| 303 GLuint path = glGenPathsCHROMIUM(1); | |
| 304 EXPECT_TRUE(path != 0); | |
| 305 glDeletePathsCHROMIUM(path, 1); | |
| 306 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 307 | |
| 308 GLuint firstPath = glGenPathsCHROMIUM(5); | |
| 309 EXPECT_TRUE(firstPath != 0); | |
| 310 glDeletePathsCHROMIUM(firstPath, 5); | |
| 311 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 312 | |
| 313 // Test deleting paths that are not actually allocated: | |
| 314 // "unused names in /paths/ are silently ignored" | |
| 315 firstPath = glGenPathsCHROMIUM(5); | |
| 316 EXPECT_TRUE(firstPath != 0); | |
| 317 glDeletePathsCHROMIUM(firstPath, 6); | |
| 318 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 319 | |
| 320 GLint maxTextureCoords = -1; | |
| 321 glGetIntegerv(GL_MAX_TEXTURE_COORDS_CHROMIUM, &maxTextureCoords); | |
| 322 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 323 EXPECT_LT(static_cast<GLint>(0), maxTextureCoords); | |
| 324 } | |
| 325 | |
| 326 TEST_F(CHROMIUMPathRenderingTest, TestErrors) { | |
| 327 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { | |
| 328 return; | |
| 329 } | |
| 330 | |
| 331 // This is unspecified. | |
| 332 EXPECT_EQ(static_cast<GLuint>(-1), glGenPathsCHROMIUM(0)); | |
| 333 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError()); | |
| 334 | |
| 335 // Using non-existing path object produces error. | |
| 336 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 337 glPathParameterfCHROMIUM(555, GL_PATH_STROKE_WIDTH_CHROMIUM, 5.0f); | |
| 338 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | |
| 339 | |
| 340 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 341 glPathParameteriCHROMIUM(555, GL_PATH_JOIN_STYLE_CHROMIUM, GL_ROUND_CHROMIUM); | |
| 342 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | |
| 343 | |
| 344 // Trying to create a path object with non-existing path name produces error. | |
| 345 // (Not a error in real NV_path_rendering). | |
| 346 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 347 GLubyte commands[] = {GL_MOVE_TO_CHROMIUM, GL_CLOSE_PATH_CHROMIUM}; | |
| 348 GLfloat coords[] = {50.0f, 50.0f}; | |
| 349 glPathCommandsCHROMIUM(555, arraysize(commands), commands, arraysize(coords), | |
| 350 GL_FLOAT, coords); | |
| 351 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | |
| 352 | |
| 353 // Try creating a path object with non-GLfloat coords | |
| 354 GLint path = glGenPathsCHROMIUM(1); | |
| 355 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 356 GLbyte coords_b[] = {0, 0}; | |
| 357 glPathCommandsCHROMIUM(path, arraysize(commands), commands, | |
| 358 arraysize(coords_b), GL_BYTE, coords_b); | |
| 359 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); | |
| 360 | |
| 361 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 362 GLshort coords_s[] = {0, 0}; | |
| 363 glPathCommandsCHROMIUM(path, arraysize(commands), commands, | |
| 364 arraysize(coords_s), GL_SHORT, coords_s); | |
| 365 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); | |
| 366 | |
| 367 // Test that using other pathNameType than GL_UNSIGNED_INT fails for Instanced | |
| 368 // functions. | |
| 369 glPathCommandsCHROMIUM(path, arraysize(commands), commands, arraysize(coords), | |
| 370 GL_FLOAT, coords); | |
| 371 | |
| 372 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 373 GLbyte pathsb[] = {1, 1, 1, 1, 1}; | |
| 374 glStencilStrokePathInstancedCHROMIUM(arraysize(pathsb), GL_BYTE, pathsb, | |
| 375 path - 1, 0x80, 0x80, GL_NONE, NULL); | |
| 376 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); | |
| 377 | |
| 378 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 379 GLint pathssi[] = {1, 1, 1, 1, 1}; | |
| 380 glStencilStrokePathInstancedCHROMIUM(arraysize(pathssi), GL_INT, pathssi, | |
| 381 path - 1, 0x80, 0x80, GL_NONE, NULL); | |
| 382 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); | |
| 383 | |
| 384 // Test that using pathNameType GL_UNSIGNED_INT succeeds. | |
| 385 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 386 GLuint pathsui[] = {1, 1, 1, 1, 1}; | |
| 387 glStencilStrokePathInstancedCHROMIUM(arraysize(pathsui), GL_UNSIGNED_INT, | |
| 388 pathsui, path - 1, 0x80, 0x80, GL_NONE, | |
| 389 NULL); | |
| 390 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 391 | |
| 392 // Test that using bogus transform enum (GL_FASTEST) fails. | |
| 393 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 394 glStencilStrokePathInstancedCHROMIUM(arraysize(pathsui), GL_UNSIGNED_INT, | |
| 395 pathsui, path - 1, 0x80, 0x80, | |
| 396 GL_FASTEST, | |
| 397 NULL); | |
| 398 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); | |
| 399 | |
| 400 | |
| 401 glDeletePathsCHROMIUM(path, 1); | |
| 402 } | |
| 403 | |
| 404 // Tests that drawing with CHROMIUM_path_rendering functions work. | |
| 405 TEST_F(CHROMIUMPathRenderingTest, TestPathRendering) { | |
| 406 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { | |
| 407 return; | |
| 408 } | |
| 409 | |
| 410 SetupStateForTestPattern(); | |
| 411 | |
| 412 GLuint path = glGenPathsCHROMIUM(1); | |
| 413 SetupPathStateForTestPattern(path); | |
| 414 | |
| 415 // Do the stencil fill, cover fill, stencil stroke, cover stroke | |
| 416 // in unconventional order: | |
| 417 // 1) stencil the stroke in stencil high bit | |
| 418 // 2) stencil the fill in low bits | |
| 419 // 3) cover the fill | |
| 420 // 4) cover the stroke | |
| 421 // This is done to check that glPathStencilFunc works, eg the mask | |
| 422 // goes through. Stencil func is not tested ATM, for simplicity. | |
| 423 | |
| 424 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0xFF); | |
| 425 glStencilStrokePathCHROMIUM(path, 0x80, 0x80); | |
| 426 | |
| 427 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0x7F); | |
| 428 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F); | |
| 429 | |
| 430 // TexCoord generation is tested by using the TexCoord values | |
| 431 // as pixel values. Transform object coords, eg. [0..width], to [0..1]. | |
| 432 // Setup two texture coordinate sets so that we check the support | |
| 433 // for multiple TexCoords. See the verification section on how the | |
| 434 // pixel color should look like. | |
| 435 glPathTexGenCHROMIUM( | |
| 436 GL_TEXTURE0, GL_OBJECT_LINEAR_CHROMIUM, 3, fill_coefficients_); | |
| 437 glPathTexGenCHROMIUM(GL_TEXTURE0 + 1, | |
| 438 GL_OBJECT_LINEAR_CHROMIUM, | |
| 439 3, | |
| 440 &fill_coefficients_[3 * 3]); | |
| 441 | |
| 442 glStencilFunc(GL_LESS, 0, 0x7F); | |
| 443 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); | |
| 444 glCoverFillPathCHROMIUM(path, GL_BOUNDING_BOX_CHROMIUM); | |
| 445 | |
| 446 glPathTexGenCHROMIUM( | |
| 447 GL_TEXTURE0, GL_OBJECT_LINEAR_CHROMIUM, 3, stroke_coefficients_); | |
| 448 glPathTexGenCHROMIUM( | |
| 449 GL_TEXTURE0 + 1, GL_OBJECT_LINEAR_CHROMIUM, 3, stroke_coefficients_); | |
| 450 glStencilFunc(GL_EQUAL, 0x80, 0x80); | |
| 451 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); | |
| 452 glCoverStrokePathCHROMIUM(path, GL_BOUNDING_BOX_CHROMIUM); | |
| 453 | |
| 454 glDeletePathsCHROMIUM(path, 1); | |
| 455 | |
| 456 // Verify the image. | |
| 457 VerifyTestPatternFill(0.f, 0.f); | |
| 458 VerifyTestPatternBg(0.f, 0.f); | |
| 459 VerifyTestPatternStroke(0.f, 0.f); | |
| 460 } | |
| 461 | |
| 462 // Tests that drawing with *Instanced functions work. | |
| 463 TEST_F(CHROMIUMPathRenderingTest, TestPathRenderingInstanced) { | |
| 464 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { | |
| 465 return; | |
| 466 } | |
| 467 | |
| 468 SetupStateForTestPattern(); | |
| 469 | |
| 470 GLuint path = glGenPathsCHROMIUM(1); | |
| 471 SetupPathStateForTestPattern(path); | |
| 472 | |
| 473 GLuint paths[] = {1, 1, 1, 1, 1}; | |
| 474 GLfloat transforms[] = { | |
| 475 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, | |
| 476 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 20.0f, 20.0f, 0.0f, | |
| 477 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 30.0f, 30.0f, 0.0f, | |
| 478 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 40.0f, 40.0f, 0.0f, | |
| 479 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 50.0f, 50.0f, 0.0f, | |
| 480 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 60.0f, 60.0f, 0.0f, | |
| 481 }; | |
| 482 | |
| 483 // The test pattern is the same as in the simple draw case above, | |
| 484 // except that the path is drawn 5 times with different offsets. | |
| 485 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0xFF); | |
| 486 glStencilStrokePathInstancedCHROMIUM(5, | |
| 487 GL_UNSIGNED_INT, | |
| 488 paths, | |
| 489 path - 1, | |
| 490 0x80, | |
| 491 0x80, | |
| 492 GL_AFFINE_3D_CHROMIUM, | |
| 493 transforms); | |
| 494 | |
| 495 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0x7F); | |
| 496 glStencilFillPathInstancedCHROMIUM(5, | |
| 497 GL_UNSIGNED_INT, | |
| 498 paths, | |
| 499 path - 1, | |
| 500 GL_COUNT_UP_CHROMIUM, | |
| 501 0x7F, | |
| 502 GL_AFFINE_3D_CHROMIUM, | |
| 503 transforms); | |
| 504 | |
| 505 glPathTexGenCHROMIUM( | |
| 506 GL_TEXTURE0, GL_OBJECT_LINEAR_CHROMIUM, 3, fill_coefficients_); | |
| 507 glPathTexGenCHROMIUM(GL_TEXTURE0 + 1, | |
| 508 GL_OBJECT_LINEAR_CHROMIUM, | |
| 509 3, | |
| 510 &fill_coefficients_[3 * 3]); | |
| 511 | |
| 512 glStencilFunc(GL_LESS, 0, 0x7F); | |
| 513 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); | |
| 514 glCoverFillPathInstancedCHROMIUM(5, | |
| 515 GL_UNSIGNED_INT, | |
| 516 paths, | |
| 517 path - 1, | |
| 518 GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM, | |
| 519 GL_AFFINE_3D_CHROMIUM, | |
| 520 transforms); | |
| 521 | |
| 522 glPathTexGenCHROMIUM( | |
| 523 GL_TEXTURE0, GL_OBJECT_LINEAR_CHROMIUM, 3, stroke_coefficients_); | |
| 524 glPathTexGenCHROMIUM( | |
| 525 GL_TEXTURE0 + 1, GL_OBJECT_LINEAR_CHROMIUM, 3, stroke_coefficients_); | |
| 526 glStencilFunc(GL_EQUAL, 0x80, 0x80); | |
| 527 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); | |
| 528 glCoverStrokePathInstancedCHROMIUM(5, | |
| 529 GL_UNSIGNED_INT, | |
| 530 paths, | |
| 531 path - 1, | |
| 532 GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM, | |
| 533 GL_AFFINE_3D_CHROMIUM, | |
| 534 transforms); | |
| 535 | |
| 536 glDeletePathsCHROMIUM(path, 1); | |
| 537 #if 0 | |
| 538 // FIXME: the instanced picture is not set up to be correct yet, | |
| 539 // and neither is the verification. | |
| 540 GLTestHelper::SaveBackbufferAsBMP("nvpr-unittest.bmp", kResolution, | |
| 541 kResolution); | |
| 542 // Verify the image. | |
| 543 VerifyTestPatternFill(0.f, 0.f); | |
| 544 VerifyTestPatternBg(0.f, 0.f); | |
| 545 VerifyTestPatternStroke(0.f, 0.f); | |
| 546 #endif | |
| 547 } | |
| 548 | |
| 110 } // namespace gpu | 549 } // namespace gpu |
| OLD | NEW |